summaryrefslogtreecommitdiff
path: root/usr.sbin/user
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-06-10 20:03:57 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-06-10 20:03:57 +0000
commiteb00cb1406191bae0b74b48487afa344c28cce88 (patch)
treee1991e0993a9440c0ea19b16c6ea7e4e9ba07205 /usr.sbin/user
parent4586185ee7138d72ec33f3be63ab1984db430914 (diff)
Use syslog(3) to log new users and groups, deletions of users and groups,
and modification of user and group information. Syslog priority is LOG_INFO, facility is LOG_USER (there is no need to do this via LOG_AUTH, since the password and group files are world readable). From NetBSD (agc)
Diffstat (limited to 'usr.sbin/user')
-rw-r--r--usr.sbin/user/user.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c
index db7d4ad9915..cde7c882772 100644
--- a/usr.sbin/user/user.c
+++ b/usr.sbin/user/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.47 2003/06/10 19:51:22 millert Exp $ */
+/* $OpenBSD: user.c,v 1.48 2003/06/10 20:03:56 millert Exp $ */
/* $NetBSD: user.c,v 1.69 2003/04/14 17:40:07 agc Exp $ */
/*
@@ -47,6 +47,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include <util.h>
@@ -364,6 +365,7 @@ creategid(char *group, gid_t gid, const char *name)
return 0;
}
(void) chmod(_PATH_GROUP, st.st_mode & 07777);
+ syslog(LOG_INFO, "new group added: name=%s, gid=%d", group, gid);
return 1;
}
@@ -443,6 +445,11 @@ modify_gid(char *group, char *newent)
return 0;
}
(void) chmod(_PATH_GROUP, st.st_mode & 07777);
+ if (newent == NULL) {
+ syslog(LOG_INFO, "group deleted: name=%s", group);
+ } else {
+ syslog(LOG_INFO, "group information modified: name=%s", group);
+ }
return 1;
}
@@ -1018,6 +1025,8 @@ adduser(char *login_name, user_t *up)
pw_abort();
err(EXIT_FAILURE, "pw_mkdb failed");
}
+ syslog(LOG_INFO, "new user added: name=%s, uid=%d, gid=%d, home=%s, shell=%s",
+ login_name, up->u_uid, gid, home, up->u_shell);
return 1;
}
@@ -1336,7 +1345,15 @@ moduser(char *login_name, char *newlogin, user_t *up)
pw_abort();
err(EXIT_FAILURE, "pw_mkdb failed");
}
-
+ if (up == NULL) {
+ syslog(LOG_INFO, "user removed: name=%s", login_name);
+ } else if (strcmp(login_name, newlogin) == 0) {
+ syslog(LOG_INFO, "user information modified: name=%s, uid=%d, gid=%d, home=%s, shell=%s",
+ login_name, pwp->pw_uid, pwp->pw_gid, pwp->pw_dir, pwp->pw_shell);
+ } else {
+ syslog(LOG_INFO, "user information modified: name=%s, new name=%s, uid=%d, gid=%d, home=%s, shell=%s",
+ login_name, newlogin, pwp->pw_uid, pwp->pw_gid, pwp->pw_dir, pwp->pw_shell);
+ }
return 1;
}
@@ -1562,6 +1579,7 @@ useradd(int argc, char **argv)
usermgmt_usage("useradd");
}
checkeuid();
+ openlog("useradd", LOG_PID, LOG_USER);
return adduser(*argv, &u) ? EXIT_SUCCESS : EXIT_FAILURE;
}
@@ -1673,6 +1691,7 @@ usermod(int argc, char **argv)
usermgmt_usage("usermod");
}
checkeuid();
+ openlog("usermod", LOG_PID, LOG_USER);
return moduser(*argv, (have_new_user) ? newuser : *argv, &u) ?
EXIT_SUCCESS : EXIT_FAILURE;
}
@@ -1753,11 +1772,13 @@ userdel(int argc, char **argv)
(void) strlcpy(password, "*", sizeof(password));
memsave(&u.u_password, password, PasswordLength);
u.u_flags |= F_PASSWORD;
+ openlog("userdel", LOG_PID, LOG_USER);
return moduser(*argv, *argv, &u) ? EXIT_SUCCESS : EXIT_FAILURE;
}
if (!rm_user_from_groups(*argv)) {
return 0;
}
+ openlog("userdel", LOG_PID, LOG_USER);
return moduser(*argv, *argv, NULL) ? EXIT_SUCCESS : EXIT_FAILURE;
}
@@ -1813,6 +1834,7 @@ groupadd(int argc, char **argv)
if (!dupgid && getgrgid((gid_t) gid) != NULL) {
errx(EXIT_FAILURE, "can't add group: gid %d is a duplicate", gid);
}
+ openlog("groupadd", LOG_PID, LOG_USER);
if (!creategid(*argv, gid, "")) {
errx(EXIT_FAILURE, "can't add group: problems with %s file",
_PATH_GROUP);
@@ -1839,6 +1861,9 @@ groupdel(int argc, char **argv)
verbose = 1;
break;
#endif
+ default:
+ usermgmt_usage("groupdel");
+ /* NOTREACHED */
}
}
argc -= optind;
@@ -1847,6 +1872,7 @@ groupdel(int argc, char **argv)
usermgmt_usage("groupdel");
}
checkeuid();
+ openlog("groupdel", LOG_PID, LOG_USER);
if (getgrnam(*argv) == NULL) {
warnx("No such group: `%s'", *argv);
return EXIT_FAILURE;
@@ -1899,9 +1925,6 @@ groupmod(int argc, char **argv)
break;
#endif
default:
- usermgmt_usage("groupdel");
- /* NOTREACHED */
- default:
usermgmt_usage("groupmod");
/* NOTREACHED */
}
@@ -1946,6 +1969,7 @@ groupmod(int argc, char **argv)
if (cc >= sizeof(buf))
errx(EXIT_FAILURE, "group `%s' entry too long", grp->gr_name);
+ openlog("groupmod", LOG_PID, LOG_USER);
if (!modify_gid(*argv, buf))
err(EXIT_FAILURE, "can't change %s file", _PATH_GROUP);
return EXIT_SUCCESS;
@@ -1971,6 +1995,9 @@ userinfo(int argc, char **argv)
case 'v':
verbose = 1;
break;
+ default:
+ usermgmt_usage("userinfo");
+ /* NOTREACHED */
}
}
argc -= optind;
@@ -2031,9 +2058,6 @@ groupinfo(int argc, char **argv)
verbose = 1;
break;
default:
- usermgmt_usage("userinfo");
- /* NOTREACHED */
- default:
usermgmt_usage("groupinfo");
/* NOTREACHED */
}