version 1.1, 2011/05/20 16:02:05
|
version 1.1.1.1.2.4, 2011/05/20 16:41:31
|
Line 12
|
Line 12
|
sl_config cfg; |
sl_config cfg; |
int Verbose; |
int Verbose; |
struct tagProc proc; |
struct tagProc proc; |
|
FILE *lf; |
|
|
|
|
static inline void |
static inline void |
Line 21 Log(int lvl, const char *fmt, ...)
|
Line 22 Log(int lvl, const char *fmt, ...)
|
|
|
if (lvl <= Verbose) { |
if (lvl <= Verbose) { |
va_start(lst, fmt); |
va_start(lst, fmt); |
|
vfprintf(lf, fmt, lst); |
|
fprintf(lf, "\n"); |
vsyslog(LOG_WARNING, fmt, lst); |
vsyslog(LOG_WARNING, fmt, lst); |
va_end(lst); |
va_end(lst); |
} |
} |
Line 32 Err(const char *fmt, ...)
|
Line 35 Err(const char *fmt, ...)
|
va_list lst; |
va_list lst; |
|
|
va_start(lst, fmt); |
va_start(lst, fmt); |
|
vfprintf(lf, fmt, lst); |
|
fprintf(lf, "\n"); |
vsyslog(LOG_ERR, fmt, lst); |
vsyslog(LOG_ERR, fmt, lst); |
va_end(lst); |
va_end(lst); |
} |
} |
Line 44 initProg()
|
Line 49 initProg()
|
proc.proc_prio = getpriority(PRIO_PROCESS, 0); |
proc.proc_prio = getpriority(PRIO_PROCESS, 0); |
getcwd(proc.proc_dir, sizeof proc.proc_dir); |
getcwd(proc.proc_dir, sizeof proc.proc_dir); |
|
|
|
lf = fopen(DEFAULT_LOG, "a"); |
|
if (!lf) |
|
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_PERROR, LOG_USER); |
} |
} |
|
|
Line 57 Usage()
|
Line 66 Usage()
|
"\t-g <group>\t\t\tGroup for suID\n" |
"\t-g <group>\t\t\tGroup for suID\n" |
"\t-p <priority (-20..20)>\t\tExecute with priority\n" |
"\t-p <priority (-20..20)>\t\tExecute with priority\n" |
"\t-d <directory>\t\t\tDirectory for suID\n" |
"\t-d <directory>\t\t\tDirectory for suID\n" |
|
"\t-l <logfile>\t\t\tLog file path (default:/var/log/suX.log)\n" |
"\t-v\t\t\t\tVerbose, (more -v, more verbosity)\n" |
"\t-v\t\t\t\tVerbose, (more -v, more verbosity)\n" |
"\t-h\t\t\t\tThis help screen!\n\n", PACKAGE_NAME); |
"\t-h\t\t\t\tThis help screen!\n\n", PACKAGE_NAME); |
} |
} |
Line 231 Run(char **argv)
|
Line 241 Run(char **argv)
|
return -1; |
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); |
|
|
if (3 <= Verbose) { |
if (3 <= Verbose) { |
char **el = args - 1; |
char **el = args - 1; |
while (*++el) |
while (*++el) |
Log(3, "args: %s", *el); |
Log(3, "args: %s", *el); |
} |
} |
|
|
|
fflush(lf); |
|
|
execve(cmd, args, environ); |
execve(cmd, args, environ); |
if (args) |
if (args) |
free(args); |
free(args); |
Line 251 main(int argc, char **argv)
|
Line 266 main(int argc, char **argv)
|
char ch, *str, szCfg[MAXPATHLEN], flg = 0; |
char ch, *str, szCfg[MAXPATHLEN], flg = 0; |
struct passwd *pass; |
struct passwd *pass; |
struct group *grp; |
struct group *grp; |
|
FILE *f; |
|
|
initProg(*argv); | initProg(); |
strlcpy(szCfg, DEFAULT_CONFIG, sizeof szCfg); |
strlcpy(szCfg, DEFAULT_CONFIG, sizeof szCfg); |
|
|
while ((ch = getopt(argc, argv, "hvc:u:g:p:d:")) != -1) | while ((ch = getopt(argc, argv, "hvc:u:g:p:d:l:")) != -1) |
switch (ch) { |
switch (ch) { |
|
case 'l': |
|
f = fopen(optarg, "a"); |
|
if (!f) { |
|
Err("Error:: logfile #%d - %s", errno, strerror(errno)); |
|
return 1; |
|
} else |
|
if (fileno(lf) > 2) |
|
fclose(lf); |
|
lf = f; |
|
break; |
case 'd': |
case 'd': |
strlcpy(proc.proc_dir, optarg, sizeof proc.proc_dir); |
strlcpy(proc.proc_dir, optarg, sizeof proc.proc_dir); |
flg |= 8; |
flg |= 8; |
Line 287 main(int argc, char **argv)
|
Line 313 main(int argc, char **argv)
|
break; |
break; |
case 'c': |
case 'c': |
strlcpy(szCfg, optarg, sizeof szCfg); |
strlcpy(szCfg, optarg, sizeof szCfg); |
flg++; |
|
break; |
break; |
case 'v': |
case 'v': |
Verbose++; |
Verbose++; |
Line 295 main(int argc, char **argv)
|
Line 320 main(int argc, char **argv)
|
case 'h': |
case 'h': |
default: |
default: |
Usage(); |
Usage(); |
|
if (fileno(lf) > 2) |
|
fclose(lf); |
return 1; |
return 1; |
} |
} |
argc -= optind; |
argc -= optind; |
Line 302 main(int argc, char **argv)
|
Line 329 main(int argc, char **argv)
|
if (!argc) { |
if (!argc) { |
if (!(str = getenv("PATH_TRANSLATED"))) { |
if (!(str = getenv("PATH_TRANSLATED"))) { |
Usage(); |
Usage(); |
|
if (fileno(lf) > 2) |
|
fclose(lf); |
return 1; |
return 1; |
} else |
} else |
strlcpy(proc.proc_name, str, sizeof proc.proc_name); |
strlcpy(proc.proc_name, str, sizeof proc.proc_name); |
Line 310 main(int argc, char **argv)
|
Line 339 main(int argc, char **argv)
|
Log(2, "Try to load config %s", szCfg); |
Log(2, "Try to load config %s", szCfg); |
if (LoadConfig(szCfg, &cfg)) { |
if (LoadConfig(szCfg, &cfg)) { |
Err("Error:: can`t load config #%d - %s\n", cfg_GetErrno(), cfg_GetError()); |
Err("Error:: can`t load config #%d - %s\n", cfg_GetErrno(), cfg_GetError()); |
|
if (fileno(lf) > 2) |
|
fclose(lf); |
return 2; |
return 2; |
} else |
} else |
if (LoadCfgData(flg) == -1) { |
if (LoadCfgData(flg) == -1) { |
UnloadConfig(&cfg); |
UnloadConfig(&cfg); |
|
if (fileno(lf) > 2) |
|
fclose(lf); |
closelog(); |
closelog(); |
return 3; |
return 3; |
} |
} |
UnloadConfig(&cfg); |
UnloadConfig(&cfg); |
|
|
Log(1, "UID:GID=%d:%d Prio=%d Class=%s Name=%s Dir=%s Cmd=%s\n", proc.proc_uid, proc.proc_gid, |
|
proc.proc_prio, proc.proc_class, proc.proc_name, proc.proc_dir, proc.proc_cmd); |
|
|
|
if (Run(argv) == -1) { |
if (Run(argv) == -1) { |
|
if (fileno(lf) > 2) |
|
fclose(lf); |
closelog(); |
closelog(); |
return 4; |
return 4; |
} |
} |
|
|
|
if (fileno(lf) > 2) |
|
fclose(lf); |
closelog(); |
closelog(); |
return 0; |
return 0; |
} |
} |