=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sudo/Attic/logging.c,v retrieving revision 1.3.2.1 retrieving revision 1.4 diff -u -r1.3.2.1 -r1.4 --- src/usr.bin/sudo/Attic/logging.c 2002/01/18 17:20:23 1.3.2.1 +++ src/usr.bin/sudo/Attic/logging.c 2001/08/23 21:45:03 1.4 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994-1996,1998-2001 Todd C. Miller + * Copyright (c) 1994-1996,1998-1999 Todd C. Miller * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,38 +34,32 @@ #include "config.h" -#include -#include -#include -#include #include #ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STDLIB_H -# include -# endif +#include #endif /* STDC_HEADERS */ -#ifdef HAVE_STRING_H -# include -#else -# ifdef HAVE_STRINGS_H -# include -# endif -#endif /* HAVE_STRING_H */ #ifdef HAVE_UNISTD_H -# include +#include #endif /* HAVE_UNISTD_H */ +#ifdef HAVE_STRING_H +#include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H +#include +#endif /* HAVE_STRINGS_H */ #include #include #include #include +#include +#include +#include +#include #include "sudo.h" #ifndef lint -static const char rcsid[] = "$Sudo: logging.c,v 1.153 2002/01/16 21:28:25 millert Exp $"; +static const char rcsid[] = "$Sudo: logging.c,v 1.140 2000/03/13 16:05:05 millert Exp $"; #endif /* lint */ static void do_syslog __P((int, char *)); @@ -73,60 +67,33 @@ static void send_mail __P((char *)); static void mail_auth __P((int, char *)); static char *get_timestr __P((void)); -static void mysyslog __P((int, const char *, ...)); -#define MAXSYSLOGTRIES 16 /* num of retries for broken syslogs */ +#ifdef BROKEN_SYSLOG +# define MAXSYSLOGTRIES 16 /* num of retries for broken syslogs */ +# define SYSLOG syslog_wrapper +static void syslog_wrapper __P((int, char *, char *, char *)); + /* - * We do an openlog(3)/closelog(3) for each message because some - * authentication methods (notably PAM) use syslog(3) for their - * own nefarious purposes and may call openlog(3) and closelog(3). - * Note that because we don't want to assume that all systems have - * vsyslog(3) (HP-UX doesn't) "%m" will not be expanded. - * Sadly this is a maze of #ifdefs. + * Some versions of syslog(3) don't guarantee success and return + * an int (notably HP-UX < 10.0). So, if at first we don't succeed, + * try, try again... */ static void -#ifdef __STDC__ -mysyslog(int pri, const char *fmt, ...) -#else -mysyslog(pri, fmt, va_alist) +syslog_wrapper(pri, fmt, ap) int pri; const char *fmt; - va_dcl -#endif + va_list ap; { -#ifdef BROKEN_SYSLOG int i; -#endif - char buf[MAXSYSLOGLEN+1]; - va_list ap; -#ifdef __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif -#ifdef LOG_NFACILITIES - openlog(Argv[0], 0, def_ival(I_LOGFAC)); -#else - openlog(Argv[0], 0); -#endif - vsnprintf(buf, sizeof(buf), fmt, ap); -#ifdef BROKEN_SYSLOG - /* - * Some versions of syslog(3) don't guarantee success and return - * an int (notably HP-UX < 10.0). So, if at first we don't succeed, - * try, try again... - */ for (i = 0; i < MAXSYSLOGTRIES; i++) - if (syslog(pri, "%s", buf) == 0) + if (vsyslog(pri, fmt, ap) == 0) break; +} #else - syslog(pri, "%s", buf); +# define SYSLOG syslog #endif /* BROKEN_SYSLOG */ - va_end(ap); - closelog(); -} /* * Log a message to syslog, pre-pending the username and splitting the @@ -162,9 +129,9 @@ *tmp = '\0'; if (count == 0) - mysyslog(pri, "%8.8s : %s", user_name, p); + SYSLOG(pri, "%8.8s : %s", user_name, p); else - mysyslog(pri, "%8.8s : (command continued) %s", user_name, p); + SYSLOG(pri, "%8.8s : (command continued) %s", user_name, p); *tmp = save; /* restore saved character */ @@ -173,9 +140,9 @@ ; } else { if (count == 0) - mysyslog(pri, "%8.8s : %s", user_name, p); + SYSLOG(pri, "%8.8s : %s", user_name, p); else - mysyslog(pri, "%8.8s : (command continued) %s", user_name, p); + SYSLOG(pri, "%8.8s : (command continued) %s", user_name, p); } } } @@ -188,7 +155,7 @@ char *beg, *oldend, *end; FILE *fp; mode_t oldmask; - int maxlen = def_ival(I_LOGLINELEN); + int maxlen = def_ival(I_LOGLEN); oldmask = umask(077); fp = fopen(def_str(I_LOGFILE), "a"); @@ -204,7 +171,7 @@ send_mail(full_line); free(full_line); } else { - if (def_ival(I_LOGLINELEN) == 0) { + if (def_ival(I_LOGLEN) == 0) { /* Don't pretty-print long log file lines (hard to grep) */ if (def_flag(I_LOG_HOST)) (void) fprintf(fp, "%s : %s : HOST=%s : %s\n", get_timestr(), @@ -332,7 +299,7 @@ /* * Log via syslog and/or a file. */ - if (def_str(I_SYSLOG)) + if (def_str(I_LOGFACSTR)) do_syslog(pri, logline); if (def_str(I_LOGFILE)) do_logfile(logline); @@ -413,14 +380,14 @@ /* * Log to syslog and/or a file. */ - if (def_str(I_SYSLOG)) + if (def_str(I_LOGFACSTR)) do_syslog(def_ival(I_BADPRI), logline); if (def_str(I_LOGFILE)) do_logfile(logline); - free(message); - if (logline != message) - free(logline); + free(logline); + if (message != logline) + free(message); if (!(flags & NO_EXIT)) exit(1); @@ -438,24 +405,23 @@ FILE *mail; char *p; int pfd[2], pid, status; +#ifdef POSIX_SIGNALS sigset_t set, oset; -#ifndef NO_ROOT_MAILER - static char *root_envp[] = { - "HOME=/", - "PATH=/usr/bin:/bin", - "LOGNAME=root", - "USER=root", - NULL - }; -#endif +#else + int omask; +#endif /* POSIX_SIGNALS */ /* Just return if mailer is disabled. */ if (!def_str(I_MAILERPATH) || !def_str(I_MAILTO)) return; +#ifdef POSIX_SIGNALS (void) sigemptyset(&set); (void) sigaddset(&set, SIGCHLD); (void) sigprocmask(SIG_BLOCK, &set, &oset); +#else + omask = sigblock(sigmask(SIGCHLD)); +#endif /* POSIX_SIGNALS */ if (pipe(pfd) == -1) { (void) fprintf(stderr, "%s: cannot open pipe: %s\n", @@ -476,12 +442,10 @@ char *mpath, *mflags; int i; - /* Child, set stdin to output side of the pipe */ - if (pfd[0] != STDIN_FILENO) { - (void) dup2(pfd[0], STDIN_FILENO); - (void) close(pfd[0]); - } + /* Child. */ (void) close(pfd[1]); + (void) dup2(pfd[0], STDIN_FILENO); + (void) close(pfd[0]); /* Build up an argv based the mailer path and flags */ mflags = estrdup(def_str(I_MAILERFLAGS)); @@ -499,27 +463,16 @@ } argv[i] = NULL; - /* Close password file so we don't leak the fd. */ - endpwent(); - - /* - * Depending on the config, either run the mailer as root - * (so user cannot kill it) or as the user (for the paranoid). - */ -#ifndef NO_ROOT_MAILER - set_perms(PERM_FULL_ROOT, 0); - execve(mpath, argv, root_envp); -#else - set_perms(PERM_FULL_USER, 0); + /* Run mailer as root so user cannot kill it. */ + set_perms(PERM_ROOT, 0); execv(mpath, argv); -#endif /* NO_ROOT_MAILER */ _exit(127); } break; } - (void) close(pfd[0]); mail = fdopen(pfd[1], "w"); + (void) close(pfd[0]); /* Pipes are all setup, send message via sendmail. */ (void) fprintf(mail, "To: %s\nFrom: %s\nSubject: ", @@ -549,7 +502,11 @@ #ifdef sudo_waitpid (void) sudo_waitpid(pid, &status, WNOHANG); #endif +#ifdef POSIX_SIGNALS (void) sigprocmask(SIG_SETMASK, &oset, NULL); +#else + (void) sigsetmask(omask); +#endif /* POSIX_SIGNALS */ } /* @@ -568,11 +525,11 @@ VALIDATE_ERROR|VALIDATE_OK|FLAG_NO_USER|FLAG_NO_HOST|VALIDATE_NOT_OK; else { mail_mask = VALIDATE_ERROR; - if (def_flag(I_MAIL_NO_USER)) + if (def_flag(I_MAIL_NOUSER)) mail_mask |= FLAG_NO_USER; - if (def_flag(I_MAIL_NO_HOST)) + if (def_flag(I_MAIL_NOHOST)) mail_mask |= FLAG_NO_HOST; - if (def_flag(I_MAIL_NO_PERMS)) + if (def_flag(I_MAIL_NOPERMS)) mail_mask |= VALIDATE_NOT_OK; } @@ -595,6 +552,9 @@ #else (void) wait(&status); #endif +#ifndef POSIX_SIGNALS + (void) signal(SIGCHLD, reapchild); +#endif /* POSIX_SIGNALS */ errno = serrno; }