--- suX/src/sux.c 2013/04/09 08:56:57 1.3.2.3 +++ suX/src/sux.c 2013/04/09 15:51:11 1.3.2.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: sux.c,v 1.3.2.3 2013/04/09 08:56:57 misho Exp $ + * $Id: sux.c,v 1.3.2.6 2013/04/09 15:51:11 misho Exp $ * *************************************************************************/ #include "global.h" @@ -45,6 +45,18 @@ Err(const char *fmt, ...) va_end(cp); } +static inline void +DumpProc(const char *txt) +{ + Log(0, "%s:: UID:GID=%d:%d Prio=%d Class=%s Name=%s Dir=%s Cmd=%s Script=%s From=%s:%s%s", + txt ? txt : __func__, AIT_GET_I16(&proc.proc_uid), + AIT_GET_I16(&proc.proc_gid), AIT_GET_I32(&proc.proc_prio), + AIT_GET_STR(&proc.proc_class), AIT_GET_STR(&proc.proc_name), + AIT_GET_STR(&proc.proc_dir), AIT_GET_STR(&proc.proc_cmd), + getenv("PATH_TRANSLATED"), getenv("REMOTE_ADDR"), + getenv("REMOTE_PORT"), getenv("REQUEST_URI")); +} + static void initProg() { @@ -53,8 +65,11 @@ initProg() AIT_SET_I16(&proc.proc_uid, getuid()); AIT_SET_I16(&proc.proc_gid, getgid()); AIT_SET_I32(&proc.proc_prio, getpriority(PRIO_PROCESS, 0)); + AIT_INIT_VAL2(&proc.proc_class, string); getcwd(d, sizeof d); AIT_SET_STR(&proc.proc_dir, d); + AIT_INIT_VAL2(&proc.proc_name, string); + AIT_INIT_VAL2(&proc.proc_cmd, string); #if 0 lf = fopen(DEFAULT_LOG, "a"); @@ -116,8 +131,8 @@ setUIDGID(char flg, const char *name) static inline int SetClass() { - login_cap_t *cap; struct passwd *pass; + int ret = 0; pass = getpwuid(AIT_GET_I16(&proc.proc_uid)); if (!pass) { @@ -127,23 +142,15 @@ SetClass() } else AIT_SET_STR(&proc.proc_class, pass->pw_class); - cap = login_getclass(AIT_GET_STR(&proc.proc_class)); - if (!cap) { - Err("Error:: Cant get login class %s", AIT_GET_STR(&proc.proc_class)); - endpwent(); - return -1; - } - - if (setusercontext(cap, pass, AIT_GET_I16(&proc.proc_uid), LOGIN_SETALL)) { + if (setusercontext(NULL, pass, AIT_GET_I16(&proc.proc_uid), + LOGIN_SETRESOURCES | LOGIN_SETGROUP | LOGIN_SETLOGIN | + LOGIN_SETPRIORITY)) { Err("Error:: Cant set login class %s", AIT_GET_STR(&proc.proc_class)); - login_close(cap); - endpwent(); - return -1; + ret = -1; } - login_close(cap); endpwent(); - return 0; + return ret; } static int @@ -246,30 +253,17 @@ Run(char **argv, char flg) } if (flg & SUX_GET_FORCE) { - if (setgid(AIT_GET_I16(&proc.proc_gid)) == -1) { - ESYSERR(0); - if (args) - free(args); - return -1; - } - if (setuid(AIT_GET_I16(&proc.proc_uid)) == -1) { - ESYSERR(0); - if (args) - free(args); - return -1; - } - if (setpriority(PRIO_PROCESS, 0, AIT_GET_I32(&proc.proc_prio)) == -1) { - ESYSERR(0); - if (args) - free(args); - return -1; - } + /* + if (setegid(AIT_GET_I16(&proc.proc_gid)) == -1) + goto err; + if (seteuid(AIT_GET_I16(&proc.proc_uid)) == -1) + goto err; + */ + if (setpriority(PRIO_PROCESS, 0, AIT_GET_I32(&proc.proc_prio)) == -1) + goto err; } - 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, AIT_GET_STR(&proc.proc_class), - AIT_GET_STR(&proc.proc_name), AIT_GET_STR(&proc.proc_dir), - AIT_GET_STR(&proc.proc_cmd), getenv("PATH_TRANSLATED")); + DumpProc(__func__); EVERBS(3) { char **el = args - 1; @@ -280,9 +274,10 @@ Run(char **argv, char flg) fflush(lf); execve(cmd, args, environ); - if (args) - free(args); +err: ESYSERR(0); + if (args) + e_free(args); return -1; }