From: Todd C. Miller Date: Wed, 4 Nov 1998 01:39:40 +0000 (+0000) Subject: kill perror("malloc") since we already have a good error messages X-Git-Tag: SUDO_1_5_7~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f461199af03da5da037c3c5917d260494886806;p=sudo kill perror("malloc") since we already have a good error messages pw_ent -> pw for brevity when checking if %group matches, look up user in password file so that %groups works in a RunAs spec. --- diff --git a/parse.c b/parse.c index 15e053bd6..d4f780fde 100644 --- a/parse.c +++ b/parse.c @@ -355,23 +355,27 @@ int usergr_matches(group, user) char *group; char *user; { - struct group *grpent; + struct group *grp; + struct passwd *pw; char **cur; /* make sure we have a valid usergroup, sudo style */ if (*group++ != '%') return(FALSE); - if ((grpent = getgrnam(group)) == NULL) + if ((grp = getgrnam(group)) == NULL) return(FALSE); /* * Check against user's real gid as well as group's user list */ - if (grpent->gr_gid == user_gid) + if ((pw = getpwnam(user)) == NULL) + return(FALSE); + + if (grp->gr_gid == pw->pw_gid) return(TRUE); - for (cur=grpent->gr_mem; *cur; cur++) { + for (cur=grp->gr_mem; *cur; cur++) { if (strcmp(*cur, user) == 0) return(TRUE); } @@ -405,7 +409,6 @@ int netgr_matches(netgr, host, user) /* get the domain name (if any) */ if (domain == (char *) -1) { if ((domain = (char *) malloc(MAXHOSTNAMELEN)) == NULL) { - perror("malloc"); (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); exit(1); }