=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/session.c,v retrieving revision 1.250 retrieving revision 1.251 diff -u -r1.250 -r1.251 --- src/usr.bin/ssh/session.c 2010/01/12 01:31:05 1.250 +++ src/usr.bin/ssh/session.c 2010/01/12 08:33:17 1.251 @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.250 2010/01/12 01:31:05 dtucker Exp $ */ +/* $OpenBSD: session.c,v 1.251 2010/01/12 08:33:17 dtucker Exp $ */ /* * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland * All rights reserved @@ -1100,22 +1100,27 @@ do_nologin(struct passwd *pw) { FILE *f = NULL; - char buf[1024]; + char buf[1024], *nl, *def_nl = _PATH_NOLOGIN; + struct stat sb; - if (!login_getcapbool(lc, "ignorenologin", 0) && pw->pw_uid) - f = fopen(login_getcapstr(lc, "nologin", _PATH_NOLOGIN, - _PATH_NOLOGIN), "r"); - if (f != NULL || errno == EPERM) { - /* /etc/nologin exists. Print its contents and exit. */ - logit("User %.100s not allowed because %s exists", - pw->pw_name, _PATH_NOLOGIN); - if (f == NULL) - exit(254); + if (login_getcapbool(lc, "ignorenologin", 0) && pw->pw_uid) + return; + nl = login_getcapstr(lc, "nologin", def_nl, def_nl); + + if (stat(nl, &sb) == -1) { + if (nl != def_nl) + xfree(nl); + return; + } + + /* /etc/nologin exists. Print its contents if we can and exit. */ + logit("User %.100s not allowed because %s exists", pw->pw_name, nl); + if ((f = fopen(nl, "r")) != NULL) { while (fgets(buf, sizeof(buf), f)) fputs(buf, stderr); fclose(f); - exit(254); } + exit(254); } /*