Page MenuHomeFreeBSD

D47015.diff
No OneTemporary

D47015.diff

diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c
--- a/usr.sbin/mountd/mountd.c
+++ b/usr.sbin/mountd/mountd.c
@@ -3614,21 +3614,14 @@
char *name;
char *names;
struct passwd *pw;
- struct group *gr;
gid_t groups[NGROUPS_MAX + 1];
int ngroups;
unsigned long name_ul;
char *end = NULL;
/*
- * Set up the unprivileged user.
- */
- cr->cr_groups = cr->cr_smallgrps;
- cr->cr_uid = UID_NOBODY;
- cr->cr_groups[0] = nogroup();
- cr->cr_ngroups = 1;
- /*
- * Get the user's password table entry.
+ * Parse the user and if possible get its password table entry.
+ * 'cr_uid' is filled when exiting this block.
*/
names = namelist;
name = strsep_quote(&names, ":");
@@ -3637,13 +3630,25 @@
pw = getpwnam(name);
else
pw = getpwuid((uid_t)name_ul);
+ if (pw != NULL) {
+ cr->cr_uid = pw->pw_uid;
+ } else if (*end != '\0' || end == name) {
+ syslog(LOG_ERR, "unknown user: %s", name);
+ cr->cr_uid = UID_NOBODY;
+ goto nogroup;
+ } else {
+ cr->cr_uid = name_ul;
+ }
+
/*
- * Credentials specified as those of a user.
+ * Credentials specified as those of a user (i.e., use its associated
+ * groups as specified in the password database).
*/
if (names == NULL) {
if (pw == NULL) {
- syslog(LOG_ERR, "unknown user: %s", name);
- return;
+ syslog(LOG_ERR, "no passwd entry for user: %s, "
+ "can't determine groups", name);
+ goto nogroup;
}
cr->cr_uid = pw->pw_uid;
ngroups = NGROUPS_MAX + 1;
@@ -3658,20 +3663,14 @@
memcpy(cr->cr_groups, groups, ngroups * sizeof(gid_t));
return;
}
+
/*
- * Explicit credential specified as a colon separated list:
+ * Explicit credentials specified as a colon separated list:
* uid:gid:gid:...
*/
- if (pw != NULL) {
- cr->cr_uid = pw->pw_uid;
- } else if (*end != '\0' || end == name) {
- syslog(LOG_ERR, "unknown user: %s", name);
- return;
- } else {
- cr->cr_uid = name_ul;
- }
cr->cr_ngroups = 0;
while (names != NULL && *names != '\0') {
+ const struct group *gr;
gid_t group;
name = strsep_quote(&names, ":");
@@ -3691,14 +3690,16 @@
}
groups[cr->cr_ngroups++] = group;
}
- if (cr->cr_ngroups == 0) {
- /* cr->cr_groups[0] filled at start with nogroup(). */
- cr->cr_ngroups = 1;
- return;
- }
+ if (cr->cr_ngroups == 0)
+ goto nogroup;
if (cr->cr_ngroups > SMALLNGROUPS)
cr->cr_groups = malloc(cr->cr_ngroups * sizeof(gid_t));
memcpy(cr->cr_groups, groups, cr->cr_ngroups * sizeof(gid_t));
+ return;
+
+nogroup:
+ cr->cr_ngroups = 1;
+ cr->cr_groups[0] = nogroup();
}
#define STRSIZ (MNTNAMLEN+MNTPATHLEN+50)

File Metadata

Mime Type
text/plain
Expires
Thu, Jul 16, 12:57 AM (45 s ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35120745
Default Alt Text
D47015.diff (2 KB)

Event Timeline