summaryrefslogtreecommitdiffstats
path: root/libutil
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>1999-04-24 17:17:42 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>1999-04-24 17:17:42 +0000
commit30cef967236e71e58d04e008d53d82db5d4361d9 (patch)
tree27e24e000436f08866e673ce5953e0b7e4081743 /libutil
parent23bd0535f2a4c1caf758c194ea275546b253e57f (diff)
downloadpw-darwin-30cef967236e71e58d04e008d53d82db5d4361d9.tar.gz
pw-darwin-30cef967236e71e58d04e008d53d82db5d4361d9.tar.zst
pw-darwin-30cef967236e71e58d04e008d53d82db5d4361d9.zip
oops, add pwd!=NULL check to previous fix
Diffstat (limited to 'libutil')
-rw-r--r--libutil/login_cap.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/libutil/login_cap.c b/libutil/login_cap.c
index 8fee8dd..0e113aa 100644
--- a/libutil/login_cap.c
+++ b/libutil/login_cap.c
@@ -25,7 +25,7 @@
*
* Low-level routines relating to the user capabilities database
*
- * $Id: login_cap.c,v 1.14 1997/06/13 22:26:41 davidn Exp $
+ * $Id: login_cap.c,v 1.15 1999/04/24 17:01:58 ache Exp $
*/
#include <stdio.h>
@@ -184,8 +184,8 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
if ((lc = malloc(sizeof(login_cap_t))) != NULL) {
int r, i = 0;
- uid_t euid;
- gid_t egid;
+ uid_t euid = 0;
+ gid_t egid = 0;
const char *msg = NULL;
const char *dir = (pwd == NULL) ? NULL : pwd->pw_dir;
char userpath[MAXPATHLEN];
@@ -194,10 +194,12 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
/* Switch to user mode before checking/reading its ~/.login_conf */
/* - some NFSes have root read access disabled. */
- euid = geteuid();
- egid = getegid();
- (void)setegid(pwd->pw_gid);
- (void)seteuid(pwd->pw_uid);
+ if (dir) {
+ euid = geteuid();
+ egid = getegid();
+ (void)setegid(pwd->pw_gid);
+ (void)seteuid(pwd->pw_uid);
+ }
if (dir && snprintf(userpath, MAXPATHLEN, "%s/%s", dir,
_FILE_LOGIN_CONF) < MAXPATHLEN) {
@@ -238,8 +240,10 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
/* Fallthru - just return system defaults */
case 0: /* success! */
if ((lc->lc_class = strdup(name)) != NULL) {
- (void)seteuid(euid);
- (void)setegid(egid);
+ if (dir) {
+ (void)seteuid(euid);
+ (void)setegid(egid);
+ }
++lc_object_count;
return lc;
}
@@ -258,8 +262,10 @@ login_getclassbyname(char const *name, const struct passwd *pwd)
msg = "%s: unexpected cgetent() error '%s': %m";
break;
}
- (void)seteuid(euid);
- (void)setegid(egid);
+ if (dir) {
+ (void)seteuid(euid);
+ (void)setegid(egid);
+ }
if (msg != NULL)
syslog(LOG_ERR, msg, "login_getclass", name);
free(lc);