Created
May 10, 2014 06:27
-
-
Save ergoz/a4f12193a6cac9563731 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
int stracat(char **target, char *source) | |
{ | |
char *tmp; | |
if (target == NULL) { | |
errno = -EINVAL; | |
return -1; | |
} | |
if (*target == NULL) | |
tmp = calloc(strlen(source) + 1, sizeof(char)); | |
else | |
tmp = realloc(*target, ((strlen(*target)+strlen(source) + 1) * sizeof(char))); | |
if (tmp == NULL) { | |
perror("Failure allocating memory for command"); | |
errno = -ENOMEM; | |
return -1; | |
} | |
strcat(tmp, source); | |
*target = tmp; | |
return 0; | |
} | |
int main(char *argv[]) | |
{ | |
char *str = NULL; | |
int i, result = 0; | |
printf("Real UID\t= %d\n", getuid()); | |
printf("Effective UID\t= %d\n", geteuid()); | |
printf("Real GID\t= %d\n", getgid()); | |
printf("Effective GID\t= %d\n", getegid()); | |
if( setgid(getegid()) ) perror( "set setgid" ); | |
if( setuid(geteuid()) ) perror( "set setuid" ); | |
for (i = 1; i < argc; i++) { | |
if (stracat(&str, argv[i]) != 0) { | |
perror("stracat failed"); | |
result = errno; | |
break; | |
} | |
if (stracat(&str, " ") != 0) { | |
perror("stracat failed"); | |
result = errno; | |
break; | |
} | |
} | |
printf("Try to run: %s", str); | |
//return system(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment