1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

When adding a new user, do not move a potential yp line (+:*:::0:0::::) to the

end of the file, for this would make logins coming after the yp line (such
as nomadic or fallback accounts) to come back before the yp line and take
precedence. Found the hard way installing packages needing a user to be created.

ok deraadt@
This commit is contained in:
miod 2008-10-09 21:10:08 +00:00
parent bb771d1732
commit 4c200ecfe7

View File

@ -1,4 +1,4 @@
/* $OpenBSD: user.c,v 1.72 2007/08/02 16:18:05 deraadt Exp $ */
/* $OpenBSD: user.c,v 1.73 2008/10/09 21:10:08 miod Exp $ */
/* $NetBSD: user.c,v 1.69 2003/04/14 17:40:07 agc Exp $ */
/*
@ -985,9 +985,14 @@ adduser(char *login_name, user_t *up)
}
while (fgets(buf, sizeof(buf), fp) != NULL) {
cc = strlen(buf);
/*
* Stop copying the file at the yp entry; we want to
* put the new user before it, and preserve entries
* after the yp entry.
*/
if (cc > 1 && buf[0] == '+' && buf[1] == ':') {
yp = 1;
continue;
break;
}
if (write(ptmpfd, buf, (size_t)(cc)) != cc) {
(void) fclose(fp);
@ -1129,6 +1134,7 @@ adduser(char *login_name, user_t *up)
err(EXIT_FAILURE, "can't add `%s'", buf);
}
if (yp) {
/* put back the + line */
cc = snprintf(buf, sizeof(buf), "+:*::::::::\n");
if (cc == -1 || cc >= sizeof(buf)) {
(void) close(ptmpfd);
@ -1140,6 +1146,22 @@ adduser(char *login_name, user_t *up)
pw_abort();
err(EXIT_FAILURE, "can't add `%s'", buf);
}
/* copy the entries following it, if any */
while (fgets(buf, sizeof(buf), fp) != NULL) {
cc = strlen(buf);
if (write(ptmpfd, buf, (size_t)(cc)) != cc) {
(void) fclose(fp);
(void) close(ptmpfd);
pw_abort();
err(EXIT_FAILURE, "short write to /etc/ptmp (not %d chars)", cc);
}
}
if (ferror(fp)) {
(void) fclose(fp);
(void) close(ptmpfd);
pw_abort();
err(EXIT_FAILURE, "read error on %s", _PATH_MASTERPASSWD);
}
}
if (up->u_flags & F_MKDIR) {
if (lstat(home, &st) == 0) {