Back to index

wims  3.65+svn20090927
wrap.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018        /* Wrap uid and exec */
00019 
00020 #include <unistd.h>
00021 #include <string.h>
00022 
00023 int main(int argc,char *argv[])
00024 {
00025     char *args[1024];
00026     int i, uid1, uid2, gid1, gid2;
00027     
00028     if(argc<2) return 0;
00029     for(i=0;i<1000 && i<argc; i++) args[i]=argv[i+1];
00030     args[i]=NULL;
00031     uid1=geteuid(); uid2=getuid(); gid1=getegid(); gid2=getgid();
00032     if(strchr(args[0],'/')) {
00033        setreuid(uid1,uid2); setregid(gid1,gid2); 
00034        execv(args[0],args);
00035     }
00036     else {
00037        setreuid(uid1,uid1); setregid(gid1,gid1); 
00038        execvp(args[0],args);
00039     }
00040     return 127;
00041 }
00042