version 1.1.2.3, 2010/10/18 08:47:31
|
version 1.1.2.7, 2010/10/18 12:18:21
|
Line 23 Usage()
|
Line 23 Usage()
|
"\t-v\t\tVerbose ...\n" |
"\t-v\t\tVerbose ...\n" |
"\t-c <dir>\tBefore execute chroot to dir [default=/]\n" |
"\t-c <dir>\tBefore execute chroot to dir [default=/]\n" |
"\t-u <user>\tBefore execute change user\n" |
"\t-u <user>\tBefore execute change user\n" |
|
"\t-P\t\tInfinit loop, bypass penalty timeout\n" |
"\n", compiled, compiledby, compilehost); |
"\n", compiled, compiledby, compilehost); |
} |
} |
|
|
Line 45 sigHand(int sig)
|
Line 46 sigHand(int sig)
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
char ch, szRun[MAXPATHLEN], szChroot[MAXPATHLEN] = "/"; | char ch, bypass = 0, szChroot[MAXPATHLEN] = DEFAULT_CHROOT; |
int status = 0, ret = 1; |
int status = 0, ret = 1; |
struct sigaction sa; |
struct sigaction sa; |
struct passwd *pass = NULL; |
struct passwd *pass = NULL; |
|
u_int penalty = 1; |
uid_t uid = getuid(); |
uid_t uid = getuid(); |
|
|
while ((ch = getopt(argc, argv, "vhc:u:")) != -1) | while ((ch = getopt(argc, argv, "vhPc:u:")) != -1) |
switch (ch) { |
switch (ch) { |
case 'v': |
case 'v': |
Verbose++; |
Verbose++; |
break; |
break; |
|
case 'P': |
|
bypass = 1; |
|
break; |
case 'c': |
case 'c': |
if (uid) { |
if (uid) { |
printf("Error:: can`t chroot, please run as root!\n"); |
printf("Error:: can`t chroot, please run as root!\n"); |
Line 94 main(int argc, char **argv)
|
Line 99 main(int argc, char **argv)
|
Usage(); |
Usage(); |
goto end; |
goto end; |
} else |
} else |
strlcpy(szRun, *argv, MAXPATHLEN); | VERB(2) printf("Info:: Chroot=%s Run=%s\n", szChroot, *argv); |
VERB(2) printf("Info:: Chroot=%s Run=%s\n", szChroot, szRun); | |
|
|
memset(&sa, 0, sizeof sa); |
memset(&sa, 0, sizeof sa); |
sa.sa_handler = sigHand; |
sa.sa_handler = sigHand; |
Line 125 main(int argc, char **argv)
|
Line 129 main(int argc, char **argv)
|
} else |
} else |
VERB(1) printf("Info:: setuid to %u\n", uid); |
VERB(1) printf("Info:: setuid to %u\n", uid); |
|
|
// while (!Kill) | status ^= status; |
| while (!Kill && penalty) { |
switch ((ret = fork())) { |
switch ((ret = fork())) { |
case -1: |
case -1: |
printf("Error:: error in fork #%d - %s\n", errno, strerror(errno)); |
printf("Error:: error in fork #%d - %s\n", errno, strerror(errno)); |
ret = 5; |
ret = 5; |
goto end; |
goto end; |
case 0: |
case 0: |
|
VERB(3) printf("Info:: I`m child of shadows ...\n"); |
|
if (execvp(*argv, argv) == -1) { |
|
printf("Error:: error in exec %s #%d - %s\n", |
|
*argv, errno, strerror(errno)); |
|
ret = 6; |
|
goto end; |
|
} |
|
/* never reached !!! */ |
break; |
break; |
default: |
default: |
waitpid(ret, &status, 0); | wait(&status); |
| kill(ret, SIGTERM); |
| ret = status; |
} |
} |
| /* penalty timeout retry */ |
ret = 0; | usleep(penalty); |
| if (!bypass) { |
| penalty <<= 1; |
| VERB(2) printf("Info:: penalty timeout %u microseconds\n", penalty); |
| } |
| } |
| if (!penalty) |
| ret = 9; |
end: |
end: |
return ret; |
return ret; |
} |
} |