Created
February 14, 2014 12:12
-
-
Save ergoz/9000008 to your computer and use it in GitHub Desktop.
run phpunit as another unit (suid)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This tool used to run PHPUnit tests by apache user | |
*/ | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <errno.h> | |
#define KNRM "\x1B[0m" | |
#define KRED "\x1B[31m" | |
#define KGRN "\x1B[32m" | |
#define KYEL "\x1B[33m" | |
#define KBLU "\x1B[34m" | |
#define KMAG "\x1B[35m" | |
#define KCYN "\x1B[36m" | |
#define KWHT "\x1B[37m" | |
char* concat(char *s1, char *s2) | |
{ | |
char *result = malloc(strlen(s1)+strlen(s2)+1);//+1 for the zero-terminator | |
strcpy(result, s1); | |
strcat(result, s2); | |
return result; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
char *command = "phpunit"; | |
int i, result = 0; | |
printf("\n"); | |
printf("Effective UID\t= %d\n", geteuid()); | |
//printf("Real GID\t= %d\n", getgid()); | |
printf("Effective GID\t= %d\n\n", getegid()); | |
if( setgid(getegid()) ) perror( "set setgid" ); | |
if( setuid(geteuid()) ) perror( "set setuid" ); | |
for (i = 1; i < argc; i++) { | |
printf("Param #%d is %s\n", i, argv[i]); | |
command = concat(command, " "); | |
command = concat(command, argv[i]); | |
} | |
printf("%sFinal command line: %s%s\n\n", KGRN, command, KNRM); | |
return system(command); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment