mount.cifs: add cruid= mount option
authorJeff Layton <jlayton@samba.org>
Fri, 14 Jan 2011 20:37:14 +0000 (15:37 -0500)
committerJeff Layton <jlayton@samba.org>
Fri, 14 Jan 2011 20:37:14 +0000 (15:37 -0500)
Allow admins to pass in a username for the cruid= mount option.

Signed-off-by: Jeff Layton <jlayton@samba.org>
Reviewed-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
mount.cifs.8
mount.cifs.c

index 5f82ac9249919bda96e673c0b62a68961a8cf082..469440d7e37723d5d7204d9b7a3d5211996d5767 100644 (file)
@@ -120,6 +120,11 @@ forceuid
 instructs the client to ignore any uid provided by the server for files and directories and to always assign the owner to be the value of the uid= option\&. See the section on FILE AND DIRECTORY OWNERSHIP AND PERMISSIONS below for more information\&.
 .RE
 .PP
+cruid=\fIarg\fR
+.RS 4
+sets the uid of the owner of the credentials cache\&. This is primarily useful with sec=krb5\&. The default is the real uid of the process performing the mount\&. Setting this parameter directs the upcall to look for a credentials cache owned by that user\&.
+.RE
+.PP
 gid=\fIarg\fR
 .RS 4
 sets the gid that will own all files or directories on the mounted filesystem when the server does not provide ownership information\&. It may be specified as either a groupname or a numeric gid\&. When not specified, the default is gid 0\&. The mount\&.cifs helper must be at version 1\&.10 or higher to support specifying the gid in non\-numeric form\&. See the section on FILE AND DIRECTORY OWNERSHIP AND PERMISSIONS below for more information\&.
index 3b1ffc61541e6472427a90bcbc9c8588950c2d00..f537a071e89642a16789ceb1590c7955a48adeaa 100644 (file)
 #define OPT_REMOUNT    26
 #define OPT_MAND       27
 #define OPT_NOMAND     28
+#define OPT_CRUID      29
 
 
 /* struct for holding parsed mount info for use by privleged process */
@@ -802,6 +803,8 @@ static int parse_opt_token(const char *token)
                return OPT_CRED;
        if (strncmp(token, "uid", 3) == 0)
                return OPT_UID;
+       if (strncmp(token, "cruid", 5) == 0)
+               return OPT_CRUID;
        if (strncmp(token, "gid", 3) == 0)
                return OPT_GID;
        if (strncmp(token, "fmask", 5) == 0)
@@ -856,8 +859,9 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info)
        int word_len;
        int rc = 0;
        int got_uid = 0;
+       int got_cruid = 0;
        int got_gid = 0;
-       uid_t uid;
+       uid_t uid, cruid;
        gid_t gid;
        char *ep;
        struct passwd *pw;
@@ -1040,6 +1044,23 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info)
                        uid = pw->pw_uid;
                        goto nocopy;
 
+               case OPT_CRUID:
+                       if (!value || !*value)
+                               goto nocopy;
+
+                       got_cruid = 1;
+                       cruid = strtoul(value, &ep, 10);
+                       if (errno != EINVAL && *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;
+
                case OPT_GID:
                        if (!value || !*value)
                                goto nocopy;
@@ -1191,6 +1212,22 @@ nocopy:
                snprintf(out + out_len, word_len + 5, "uid=%s", txtbuf);
                out_len = strlen(out);
        }
+       if (got_cruid) {
+               word_len = snprintf(txtbuf, sizeof(txtbuf), "%u", cruid);
+
+               /* comma + "cruid=" + terminating NULL == 6 */
+               if (out_len + word_len + 8 > MAX_OPTIONS_LEN) {
+                       fprintf(stderr, "Options string too long\n");
+                       return EX_USAGE;
+               }
+
+               if (out_len) {
+                       strlcat(out, ",", MAX_OPTIONS_LEN);
+                       out_len++;
+               }
+               snprintf(out + out_len, word_len + 7, "cruid=%s", txtbuf);
+               out_len = strlen(out);
+       }
        if (got_gid) {
                word_len = snprintf(txtbuf, sizeof(txtbuf), "%u", gid);
 
@@ -1206,7 +1243,6 @@ nocopy:
                }
                snprintf(out + out_len, word_len + 5, "gid=%s", txtbuf);
        }
-
        return 0;
 }