--- suX/src/sux.c 2011/05/20 16:41:31 1.1.1.1.2.4 +++ suX/src/sux.c 2011/10/09 21:45:44 1.2.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: sux.c,v 1.1.1.1.2.4 2011/05/20 16:41:31 misho Exp $ + * $Id: sux.c,v 1.2.2.2 2011/10/09 21:45:44 misho Exp $ * *************************************************************************/ #include "global.h" @@ -18,27 +18,31 @@ FILE *lf; static inline void Log(int lvl, const char *fmt, ...) { - va_list lst; + va_list lst, cp; if (lvl <= Verbose) { va_start(lst, fmt); + va_copy(cp, lst); vfprintf(lf, fmt, lst); - fprintf(lf, "\n"); - vsyslog(LOG_WARNING, fmt, lst); va_end(lst); + fprintf(lf, "\n"); + vsyslog(LOG_WARNING, fmt, cp); + va_end(cp); } } static inline void Err(const char *fmt, ...) { - va_list lst; + va_list lst, cp; va_start(lst, fmt); + va_copy(cp, lst); vfprintf(lf, fmt, lst); - fprintf(lf, "\n"); - vsyslog(LOG_ERR, fmt, lst); va_end(lst); + fprintf(lf, "\n"); + vsyslog(LOG_ERR, fmt, cp); + va_end(cp); } static void @@ -49,11 +53,13 @@ initProg() proc.proc_prio = getpriority(PRIO_PROCESS, 0); getcwd(proc.proc_dir, sizeof proc.proc_dir); +#if 0 lf = fopen(DEFAULT_LOG, "a"); if (!lf) +#endif lf = stdout; - openlog(PACKAGE_NAME, LOG_CONS | LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_USER); + openlog(PACKAGE_NAME, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER); } static void @@ -66,6 +72,8 @@ Usage() "\t-g \t\t\tGroup for suID\n" "\t-p \t\tExecute with priority\n" "\t-d \t\t\tDirectory for suID\n" + "\t-C \t\t\tChroot to directory\n" + "\t-c \t\t\tConfig file\n" "\t-l \t\t\tLog file path (default:/var/log/suX.log)\n" "\t-v\t\t\t\tVerbose, (more -v, more verbosity)\n" "\t-h\t\t\t\tThis help screen!\n\n", PACKAGE_NAME); @@ -222,6 +230,7 @@ Run(char **argv) return -1; } + /* if (setgid(proc.proc_gid) == -1) { Err("Error:: setgid #%d - %s\n", errno, strerror(errno)); if (args) @@ -240,9 +249,11 @@ Run(char **argv) free(args); return -1; } + */ - Log(0, "UID:GID=%d:%d Prio=%d Class=%s Name=%s Dir=%s Cmd=%s", proc.proc_uid, proc.proc_gid, - proc.proc_prio, proc.proc_class, proc.proc_name, proc.proc_dir, proc.proc_cmd); + Log(0, "UID:GID=%d:%d Prio=%d Class=%s Name=%s Dir=%s Cmd=%s Script=%s", + proc.proc_uid, proc.proc_gid, proc.proc_prio, proc.proc_class, + proc.proc_name, proc.proc_dir, proc.proc_cmd, getenv("PATH_TRANSLATED")); if (3 <= Verbose) { char **el = args - 1; @@ -263,7 +274,7 @@ Run(char **argv) int main(int argc, char **argv) { - char ch, *str, szCfg[MAXPATHLEN], flg = 0; + char ch, *str, *wrk, szCfg[MAXPATHLEN], **pp, flg = 0; struct passwd *pass; struct group *grp; FILE *f; @@ -271,7 +282,7 @@ main(int argc, char **argv) initProg(); strlcpy(szCfg, DEFAULT_CONFIG, sizeof szCfg); - while ((ch = getopt(argc, argv, "hvc:u:g:p:d:l:")) != -1) + while ((ch = getopt(argc, argv, "hvC:c:u:g:p:d:l:")) != -1) switch (ch) { case 'l': f = fopen(optarg, "a"); @@ -314,6 +325,13 @@ main(int argc, char **argv) case 'c': strlcpy(szCfg, optarg, sizeof szCfg); break; + case 'C': + if (chroot(optarg) == -1) + Err("Error:: chroot to dir"); + if ((str = getenv("PATH_TRANSLATED"))) + if ((wrk = strstr(str, optarg))) + setenv("PATH_TRANSLATED", str + strlen(optarg), 42); + break; case 'v': Verbose++; break; @@ -326,6 +344,14 @@ main(int argc, char **argv) } argc -= optind; argv += optind; + + if (2 <= Verbose) { + for (pp = argv; *pp; pp++) + Log(2, "Args=%s\n", *pp); + for (pp = environ; *pp; pp++) + Log(2, "Envs=%s\n", *pp); + } + if (!argc) { if (!(str = getenv("PATH_TRANSLATED"))) { Usage();