2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1989 - 1992, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2001 - 2005, Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2008 - 2010, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2007-10-07 17:14:14 +05:30
|
|
|
#include "prototypes.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "defines.h"
|
|
|
|
#include "getdef.h"
|
2008-05-26 05:39:24 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* sulog - log a SU command execution result
|
|
|
|
*/
|
2008-05-26 05:39:24 +05:30
|
|
|
void sulog (const char *tty, bool success, const char *oldname, const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
* libmisc/console.c, libmisc/motd.c, libmisc/setupenv.c,
libmisc/sulog.c, libmisc/hushed.c, libmisc/failure.c,
libmisc/loginprompt.c, libmisc/ttytype.c,
libmisc/pam_pass_non_interractive.c, src/userdel.c, src/login.c,
lib/commonio.c, lib/commonio.h: Fix some const issues.
* libmisc/motd.c: Avoid multi-statements lines.
* libmisc/motd.c: Support long MOTD_FILE.
* libmisc/list.c, lib/prototypes.h: Revert previous change.
dup_list and is_on_list are used with members as defined for the
group structure, and thus even if the list is not modified, the
list elements cannot be constant strings.
* libmisc/system.c: Avoid C++ comments.
* src/vipw.c: WITH_TCB cannot be tested inside a gettextized
string. Split the Usage string.
* lib/commonio.h: Re-indent.
2010-08-21 21:02:53 +05:30
|
|
|
const char *sulog_file;
|
2007-10-07 17:14:02 +05:30
|
|
|
time_t now;
|
|
|
|
struct tm *tm;
|
|
|
|
FILE *fp;
|
|
|
|
mode_t oldmask;
|
2008-04-27 05:57:59 +05:30
|
|
|
gid_t oldgid = 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:11 +05:30
|
|
|
if (success) {
|
|
|
|
SYSLOG ((LOG_INFO,
|
|
|
|
"Successful su for %s by %s",name,oldname));
|
|
|
|
} else {
|
|
|
|
SYSLOG ((LOG_NOTICE,
|
|
|
|
"FAILED su for %s by %s",name,oldname));
|
|
|
|
}
|
|
|
|
|
* libmisc/console.c, libmisc/motd.c, libmisc/setupenv.c,
libmisc/sulog.c, libmisc/hushed.c, libmisc/failure.c,
libmisc/loginprompt.c, libmisc/ttytype.c,
libmisc/pam_pass_non_interractive.c, src/userdel.c, src/login.c,
lib/commonio.c, lib/commonio.h: Fix some const issues.
* libmisc/motd.c: Avoid multi-statements lines.
* libmisc/motd.c: Support long MOTD_FILE.
* libmisc/list.c, lib/prototypes.h: Revert previous change.
dup_list and is_on_list are used with members as defined for the
group structure, and thus even if the list is not modified, the
list elements cannot be constant strings.
* libmisc/system.c: Avoid C++ comments.
* src/vipw.c: WITH_TCB cannot be tested inside a gettextized
string. Split the Usage string.
* lib/commonio.h: Re-indent.
2010-08-21 21:02:53 +05:30
|
|
|
sulog_file = getdef_str ("SULOG_FILE");
|
|
|
|
if (NULL == sulog_file) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return;
|
* libmisc/console.c, libmisc/motd.c, libmisc/setupenv.c,
libmisc/sulog.c, libmisc/hushed.c, libmisc/failure.c,
libmisc/loginprompt.c, libmisc/ttytype.c,
libmisc/pam_pass_non_interractive.c, src/userdel.c, src/login.c,
lib/commonio.c, lib/commonio.h: Fix some const issues.
* libmisc/motd.c: Avoid multi-statements lines.
* libmisc/motd.c: Support long MOTD_FILE.
* libmisc/list.c, lib/prototypes.h: Revert previous change.
dup_list and is_on_list are used with members as defined for the
group structure, and thus even if the list is not modified, the
list elements cannot be constant strings.
* libmisc/system.c: Avoid C++ comments.
* src/vipw.c: WITH_TCB cannot be tested inside a gettextized
string. Split the Usage string.
* lib/commonio.h: Re-indent.
2010-08-21 21:02:53 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-04-27 05:57:59 +05:30
|
|
|
oldgid = getgid ();
|
2007-10-07 17:15:23 +05:30
|
|
|
oldmask = umask (077);
|
2008-04-27 05:57:59 +05:30
|
|
|
/* Switch to group root to avoid creating the sulog file with
|
|
|
|
* the wrong group ownership. */
|
|
|
|
if ((oldgid != 0) && (setgid (0) != 0)) {
|
|
|
|
SYSLOG ((LOG_INFO,
|
|
|
|
"su session not logged to %s", sulog_file));
|
|
|
|
/* Continue, but do not switch back to oldgid later */
|
|
|
|
oldgid = 0;
|
|
|
|
}
|
2007-10-07 17:15:23 +05:30
|
|
|
fp = fopen (sulog_file, "a+");
|
2008-06-14 01:22:58 +05:30
|
|
|
(void) umask (oldmask);
|
2008-04-27 05:57:59 +05:30
|
|
|
if ((oldgid != 0) && (setgid (oldgid) != 0)) {
|
|
|
|
perror ("setgid");
|
|
|
|
SYSLOG ((LOG_ERR,
|
|
|
|
"can't switch back to group `%d' in sulog",
|
|
|
|
oldgid));
|
|
|
|
/* Do not return if the group permission were raised. */
|
* lib/exitcodes.h: Define E_SUCCESS as EXIT_SUCCESS. Added FIXMEs.
* libmisc/chowntty.c, libmisc/rlogin.c, libmisc/sub.c,
src/newusers.c, libmisc/sulog.c, libmisc/system.c, src/logoutd.c,
src/groups.c, src/id.c, lib/encrypt.c, libmisc/audit_help.c,
libmisc/limits.c: Return EXIT_FAILURE instead of 1, and
EXIT_SUCCESS instead of 0.
* libmisc/audit_help.c: Replace an fprintf() by fputs().
* libmisc/audit_help.c: Remove documentation of the audit_logger
returned values. The function returns void.
* libmisc/system.c: Only return status if waitpid succeeded.
Return -1 otherwise.
2009-05-01 02:38:49 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2008-04-27 05:57:59 +05:30
|
|
|
}
|
2023-02-01 07:20:14 +05:30
|
|
|
if (fp == NULL) {
|
2007-10-07 17:15:23 +05:30
|
|
|
return; /* can't open or create logfile */
|
2008-06-14 01:22:58 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-14 01:22:58 +05:30
|
|
|
(void) time (&now);
|
2007-10-07 17:15:23 +05:30
|
|
|
tm = localtime (&now);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
fprintf (fp, "SU %.02d/%.02d %.02d:%.02d %c %s %s-%s\n",
|
|
|
|
tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min,
|
|
|
|
success ? '+' : '-', tty, oldname, name);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 05:39:24 +05:30
|
|
|
(void) fflush (fp);
|
2009-03-22 01:02:14 +05:30
|
|
|
fsync (fileno (fp));
|
2007-10-07 17:15:23 +05:30
|
|
|
fclose (fp);
|
2008-05-26 05:39:24 +05:30
|
|
|
/* TODO: log if failure */
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-05-26 05:39:24 +05:30
|
|
|
|