diff --git a/ChangeLog b/ChangeLog index ff4ea399..bb97bac2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-01-22 Nicolas François + + * NEWS, src/newgrp.c: Fix segfault when an user returns to an + unknown GID (either the user was deleted during the user's newgrp + session or the user's passwd entry referenced an invalid group). + Add a syslog warning in that case. + * src/newgrp.c: Add an end of line when reporting an invalid + password. + 2008-01-12 Nicolas François * NEWS, src/useradd.c: Fix the handling of the --defaults option diff --git a/NEWS b/NEWS index 03f84b62..d0c89296 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,10 @@ shadow-4.1.0 -> shadow-4.1.1 UNRELEASED - lastlog * Accept users specified as a numerical UID, or ranges of users (-user, user-, user1-user2). +- newgrp + * Fix segfault when an user returns to an unknown GID (either the user + was deleted during the user's newgrp session or the user's passwd + entry referenced an invalid group). Add a syslog warning in that case. - newusers * The new users are no more added to the list of members of their groups because the membership is already set by their primary group. diff --git a/src/newgrp.c b/src/newgrp.c index 5cc65fd1..de06dbed 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -169,7 +169,7 @@ static void check_perms (const struct group *grp, "Invalid password for group `%s' from `%s'", groupname, pwd->pw_name)); sleep (1); - fputs (_("Invalid password."), stderr); + fputs (_("Invalid password.\n"), stderr); goto failure; } } @@ -252,6 +252,8 @@ static void syslog_sg (const char *name, const char *group) } else if (child) { /* parent - wait for child to finish, then log session close */ int cst = 0; + gid_t gid = getgid(); + struct group *grp = getgrgid (gid); do { errno = 0; @@ -265,10 +267,22 @@ static void syslog_sg (const char *name, const char *group) } while ((pid == child && WIFSTOPPED (cst)) || (pid != child && errno == EINTR)); /* local, no need for xgetgrgid */ - SYSLOG ((LOG_INFO, - "user `%s' (login `%s' on %s) returned to group `%s'", - name, loginname, tty, - getgrgid (gid)->gr_name)); + if (NULL != grp) { + SYSLOG ((LOG_INFO, + "user `%s' (login `%s' on %s) returned to group `%s'", + name, loginname, tty, grp->gr_name)); + } else { + SYSLOG ((LOG_INFO, + "user `%s' (login `%s' on %s) returned to group `%d'", + name, loginname, tty, gid)); + /* Either the user's passwd entry has a + * GID that does not match with any group, + * or the group was deleted while the user + * was in a newgrp session.*/ + SYSLOG ((LOG_WARN, + "unknown GID `%u' used by user `%s'", + gid, name)); + } closelog (); exit (0); }