Message ID | 1354634204-21602-2-git-send-email-jlayton@samba.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Dec 4, 2012 at 10:16 AM, Jeff Layton <jlayton@samba.org> wrote: > Sergio Conrad reported a problem trying to set up an autofs map to do > a krb5 mount. In his environment, many users have usernames that are > comprised entirely of numbers. While that's a bit odd, POSIX apparently > allows for it. > > The current code assumes that when a numeric argument is passed to one > of the above options, that it's a uid or gid. Instead, try to treat the > argument as a user or group name first, and only try to treat it as a > number if that fails. > > Signed-off-by: Jeff Layton <jlayton@samba.org> Yuck. What happens when a number is both a valid user name and uid? IE, I add a user named "0" (uid=5001). Does getpwnam() return root (uid=0) or 0 (uid=5001)?
On Tue, 4 Dec 2012 10:45:19 -0500 Scott Lovenberg <scott.lovenberg@gmail.com> wrote: > On Tue, Dec 4, 2012 at 10:16 AM, Jeff Layton <jlayton@samba.org> wrote: > > Sergio Conrad reported a problem trying to set up an autofs map to do > > a krb5 mount. In his environment, many users have usernames that are > > comprised entirely of numbers. While that's a bit odd, POSIX apparently > > allows for it. > > > > The current code assumes that when a numeric argument is passed to one > > of the above options, that it's a uid or gid. Instead, try to treat the > > argument as a user or group name first, and only try to treat it as a > > number if that fails. > > > > Signed-off-by: Jeff Layton <jlayton@samba.org> > > Yuck. What happens when a number is both a valid user name and uid? > IE, I add a user named "0" (uid=5001). Does getpwnam() return root > (uid=0) or 0 (uid=5001)? > You'd get back uid=5001: The getpwnam() function returns a pointer to a structure containing the broken-out fields of the record in the password database (e.g., the local password file /etc/passwd, NIS, and LDAP) that matches the user? name name. If you wanted to get back a struct passwd for uid=0 then you'd need to use getpwuid() there.
On Tue, Dec 4, 2012 at 1:27 PM, Jeff Layton <jlayton@samba.org> wrote: > On Tue, 4 Dec 2012 10:45:19 -0500 > Scott Lovenberg <scott.lovenberg@gmail.com> wrote: > >> On Tue, Dec 4, 2012 at 10:16 AM, Jeff Layton <jlayton@samba.org> wrote: >> > Sergio Conrad reported a problem trying to set up an autofs map to do >> > a krb5 mount. In his environment, many users have usernames that are >> > comprised entirely of numbers. While that's a bit odd, POSIX apparently >> > allows for it. >> > >> > The current code assumes that when a numeric argument is passed to one >> > of the above options, that it's a uid or gid. Instead, try to treat the >> > argument as a user or group name first, and only try to treat it as a >> > number if that fails. >> > >> > Signed-off-by: Jeff Layton <jlayton@samba.org> >> >> Yuck. What happens when a number is both a valid user name and uid? >> IE, I add a user named "0" (uid=5001). Does getpwnam() return root >> (uid=0) or 0 (uid=5001)? >> > > You'd get back uid=5001: > > The getpwnam() function returns a pointer to a structure containing the > broken-out fields of the record in the password database (e.g., the > local password file /etc/passwd, NIS, and LDAP) that matches the user? > name name. > > If you wanted to get back a struct passwd for uid=0 then you'd need to > use getpwuid() there. > > -- > Jeff Layton <jlayton@samba.org> I missed that; thanks for clarifying.
diff --git a/mount.cifs.c b/mount.cifs.c index a9632b4..9760d1f 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -1003,57 +1003,55 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info) goto nocopy; got_uid = 1; + pw = getpwnam(value); + if (pw) { + uid = pw->pw_uid; + goto nocopy; + } + errno = 0; uid = strtoul(value, &ep, 10); if (errno == 0 && *ep == '\0') goto nocopy; - pw = getpwnam(value); - if (pw == NULL) { - fprintf(stderr, "bad user name \"%s\"\n", value); - return EX_USAGE; - } - - uid = pw->pw_uid; - goto nocopy; - + fprintf(stderr, "bad option uid=\"%s\"\n", value); + return EX_USAGE; case OPT_CRUID: if (!value || !*value) goto nocopy; got_cruid = 1; + pw = getpwnam(value); + if (pw) { + cruid = pw->pw_uid; + goto nocopy; + } + errno = 0; cruid = strtoul(value, &ep, 10); if (errno == 0 && *ep == '\0') goto nocopy; - pw = getpwnam(value); - if (pw == NULL) { - fprintf(stderr, "bad user name \"%s\"\n", value); - return EX_USAGE; - } - cruid = pw->pw_uid; - goto nocopy; - + fprintf(stderr, "bad option: cruid=\"%s\"\n", value); + return EX_USAGE; case OPT_GID: if (!value || !*value) goto nocopy; got_gid = 1; + gr = getgrnam(value); + if (gr) { + gid = gr->gr_gid; + goto nocopy; + } + errno = 0; gid = strtoul(value, &ep, 10); if (errno == 0 && *ep == '\0') goto nocopy; - gr = getgrnam(value); - if (gr == NULL) { - fprintf(stderr, "bad group name \"%s\"\n", value); - return EX_USAGE; - } - - gid = gr->gr_gid; - goto nocopy; - + fprintf(stderr, "bad option: gid=\"%s\"\n", value); + return EX_USAGE; /* fmask fall through to file_mode */ case OPT_FMASK: fprintf(stderr,
Sergio Conrad reported a problem trying to set up an autofs map to do a krb5 mount. In his environment, many users have usernames that are comprised entirely of numbers. While that's a bit odd, POSIX apparently allows for it. The current code assumes that when a numeric argument is passed to one of the above options, that it's a uid or gid. Instead, try to treat the argument as a user or group name first, and only try to treat it as a number if that fails. Signed-off-by: Jeff Layton <jlayton@samba.org> --- mount.cifs.c | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-)