Created
October 13, 2014 15:38
-
-
Save z4yx/37451ac85e3d05ff251d to your computer and use it in GitHub Desktop.
fix LD_LIBRARY_PATH and set user id
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
#include <sys/types.h> | |
#include <sys/types.h> | |
#include <pwd.h> | |
#include <limits.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
int main(int argc, char **argv_src) | |
{ | |
char exe[PATH_MAX+10]; | |
char *argv[256] = {0}; | |
readlink("/proc/self/exe",exe,PATH_MAX); | |
strcat(exe, "_p"); | |
memcpy(argv, argv_src, argc*sizeof(char*)); | |
//char *argv[]={"./gogs","web",NULL}; | |
//char *envp[]={"USER=git","PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin","HOME=/home/git","LD_LIBRARY_PATH=/usr/local/glibc2_14/lib/",NULL}; | |
struct passwd *pwd = getpwnam("git"); | |
if(getuid()==0 && pwd){ | |
// fprintf(stderr,"uid: %d, gid: %d", pwd->pw_uid, pwd->pw_gid); | |
setgid(pwd->pw_gid); | |
setuid(pwd->pw_uid); | |
} | |
putenv("USER=git"); | |
putenv("HOME=/home/git"); | |
putenv("LD_LIBRARY_PATH=/usr/local/glibc2_14/lib/"); | |
extern char **environ; | |
execve(exe,argv,environ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment