version 1.1.2.7, 2010/10/18 12:18:21
|
version 1.1.2.8, 2010/10/18 15:06:10
|
Line 9
|
Line 9
|
#include "global.h" |
#include "global.h" |
|
|
|
|
int Verbose, Kill; | int Verbose, Kill, Log; |
extern char compiled[], compiledby[], compilehost[]; |
extern char compiled[], compiledby[], compilehost[]; |
|
|
|
|
Line 24 Usage()
|
Line 24 Usage()
|
"\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" |
"\t-P\t\tInfinit loop, bypass penalty timeout\n" |
|
"\t-S\t\tDisable send log events to syslog\n" |
"\n", compiled, compiledby, compilehost); |
"\n", compiled, compiledby, compilehost); |
} |
} |
|
|
Line 42 sigHand(int sig)
|
Line 43 sigHand(int sig)
|
} |
} |
} |
} |
|
|
|
static void |
|
logmsg(int prio, const char *fmt, ...) |
|
{ |
|
va_list lst; |
|
|
|
va_start(lst, fmt); |
|
if (!Log) |
|
vsyslog(prio, fmt, lst); |
|
else |
|
vprintf(fmt, lst); |
|
va_end(lst); |
|
} |
|
|
|
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
Line 53 main(int argc, char **argv)
|
Line 67 main(int argc, char **argv)
|
u_int penalty = 1; |
u_int penalty = 1; |
uid_t uid = getuid(); |
uid_t uid = getuid(); |
|
|
while ((ch = getopt(argc, argv, "vhPc:u:")) != -1) | while ((ch = getopt(argc, argv, "vhSPc:u:")) != -1) |
switch (ch) { |
switch (ch) { |
case 'v': |
case 'v': |
Verbose++; |
Verbose++; |
Line 61 main(int argc, char **argv)
|
Line 75 main(int argc, char **argv)
|
case 'P': |
case 'P': |
bypass = 1; |
bypass = 1; |
break; |
break; |
|
case 'S': |
|
Log = 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 98 main(int argc, char **argv)
|
Line 115 main(int argc, char **argv)
|
if (!argc || !argv || !*argv) { |
if (!argc || !argv || !*argv) { |
Usage(); |
Usage(); |
goto end; |
goto end; |
} else | } |
VERB(2) printf("Info:: Chroot=%s Run=%s\n", szChroot, *argv); | |
|
|
|
if (!Log) |
|
openlog("wdog", LOG_PID, LOG_USER); |
|
|
|
VERB(2) logmsg(LOG_NOTICE, "Info:: Chroot=%s Run=%s\n", szChroot, *argv); |
|
|
memset(&sa, 0, sizeof sa); |
memset(&sa, 0, sizeof sa); |
sa.sa_handler = sigHand; |
sa.sa_handler = sigHand; |
sigemptyset(&sa.sa_mask); |
sigemptyset(&sa.sa_mask); |
Line 113 main(int argc, char **argv)
|
Line 134 main(int argc, char **argv)
|
sigaction(SIGPIPE, &sa, NULL); |
sigaction(SIGPIPE, &sa, NULL); |
sigaction(SIGTSTP, &sa, NULL); |
sigaction(SIGTSTP, &sa, NULL); |
sigaction(SIGSTOP, &sa, NULL); |
sigaction(SIGSTOP, &sa, NULL); |
VERB(5) printf("Info:: Catched signals ...\n"); | VERB(5) logmsg(LOG_NOTICE, "Info:: Catched signals ...\n"); |
|
|
if (status & 1 && (ret = chroot(szChroot)) == -1) { |
if (status & 1 && (ret = chroot(szChroot)) == -1) { |
printf("Error:: error in chroot to %s #%d - %s\n", szChroot, errno, strerror(errno)); |
printf("Error:: error in chroot to %s #%d - %s\n", szChroot, errno, strerror(errno)); |
ret = 3; |
ret = 3; |
goto end; |
goto end; |
} else |
} else |
VERB(1) printf("Info:: chrooted to %s\n", szChroot); | VERB(1) logmsg(LOG_NOTICE, "Info:: chrooted to %s\n", szChroot); |
|
|
if (status & 2 && setuid(uid) == -1) { |
if (status & 2 && setuid(uid) == -1) { |
printf("Error:: error in setuid to %u #%d - %s\n", uid, errno, strerror(errno)); |
printf("Error:: error in setuid to %u #%d - %s\n", uid, errno, strerror(errno)); |
ret = 4; |
ret = 4; |
goto end; |
goto end; |
} else |
} else |
VERB(1) printf("Info:: setuid to %u\n", uid); | VERB(1) logmsg(LOG_NOTICE, "Info:: setuid to %u\n", uid); |
|
|
status ^= status; |
status ^= status; |
while (!Kill && penalty) { |
while (!Kill && penalty) { |
switch ((ret = fork())) { |
switch ((ret = fork())) { |
case -1: |
case -1: |
printf("Error:: error in fork #%d - %s\n", errno, strerror(errno)); | logmsg(LOG_ERR, "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"); | VERB(3) logmsg(LOG_NOTICE, "Info:: I`m child of shadows ...\n"); |
if (execvp(*argv, argv) == -1) { |
if (execvp(*argv, argv) == -1) { |
printf("Error:: error in exec %s #%d - %s\n", | logmsg(LOG_ERR, "Error:: error in exec %s #%d - %s\n", |
*argv, errno, strerror(errno)); |
*argv, errno, strerror(errno)); |
ret = 6; |
ret = 6; |
goto end; |
goto end; |
Line 155 main(int argc, char **argv)
|
Line 176 main(int argc, char **argv)
|
usleep(penalty); |
usleep(penalty); |
if (!bypass) { |
if (!bypass) { |
penalty <<= 1; |
penalty <<= 1; |
VERB(2) printf("Info:: penalty timeout %u microseconds\n", penalty); | VERB(2) logmsg(LOG_NOTICE, "Info:: penalty timeout %u microseconds\n", penalty); |
} |
} |
} |
} |
if (!penalty) |
if (!penalty) |
ret = 9; |
ret = 9; |
end: |
end: |
|
if (!Log) |
|
closelog(); |
return ret; |
return ret; |
} |
} |