diff options
author | Jeff Layton <jlayton@samba.org> | 2012-11-18 20:38:38 -0500 |
---|---|---|
committer | Jeff Layton <jlayton@samba.org> | 2012-12-03 09:58:57 -0500 |
commit | 8b6e0cc242fc62436b0dd073e393bbdd62f39a83 (patch) | |
tree | 1a124ca3bc7557f9fb38b5deb30a4b772492da67 | |
parent | 92e12ecc28ac1a41eb48f693837be0ba070dc8af (diff) | |
download | cifs-utils-8b6e0cc242fc62436b0dd073e393bbdd62f39a83.tar.gz cifs-utils-8b6e0cc242fc62436b0dd073e393bbdd62f39a83.tar.bz2 cifs-utils-8b6e0cc242fc62436b0dd073e393bbdd62f39a83.zip |
mount.cifs: treat uid=,gid=,cruid= options as name before assuming they're a number
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>
-rw-r--r-- | mount.cifs.c | 50 |
1 files changed, 24 insertions, 26 deletions
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, |