Skip to content

Commit

Permalink
[CIFS] UID/GID override on CIFS mounts to Samba
Browse files Browse the repository at this point in the history
When CIFS Unix Extensions are negotiated we get the Unix uid and gid
owners of the file from the server (on the Unix Query Path Info
levels), but if the server's uids don't match the client uid's users
were having to disable the Unix Extensions (which turned off features
they still wanted).   The changeset patch allows users to override uid
and/or gid for file/directory owner with a default uid and/or gid
specified at mount (as is often done when mounting from Linux cifs
client to Windows server).  This changeset also displays the uid
and gid used by default in /proc/mounts (if applicable).

Also cleans up code by adding some of the missing spaces after
"if" keywords per-kernel style guidelines (as suggested by Randy Dunlap
when he reviewed the patch).

Signed-off-by: Steve French <sfrench@us.ibm.com>
  • Loading branch information
Steve French committed Apr 30, 2007
1 parent 984acfe commit 4523cc3
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 171 deletions.
6 changes: 5 additions & 1 deletion fs/cifs/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ Version 1.49
------------
IPv6 support. Enable ipv6 addresses to be passed on mount (put the ipv6
address after the "ip=" mount option, at least until mount.cifs is fixed to
handle DNS host to ipv6 name translation).
handle DNS host to ipv6 name translation). Accept override of uid or gid
on mount even when Unix Extensions are negotiated (it used to be ignored
when Unix Extensions were ignored). This allows users to override the
default uid and gid for files when they are certain that the uids or
gids on the server do not match those of the client.

Version 1.48
------------
Expand Down
23 changes: 14 additions & 9 deletions fs/cifs/README
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,19 @@ A partial list of the supported mount options follows:
mount.
domain Set the SMB/CIFS workgroup name prepended to the
username during CIFS session establishment
uid If CIFS Unix extensions are not supported by the server
this overrides the default uid for inodes. For mounts to
servers which do support the CIFS Unix extensions, such
as a properly configured Samba server, the server provides
the uid, gid and mode. For servers which do not support
the Unix extensions, the default uid (and gid) returned on
lookup of existing files is the uid (gid) of the person
uid Set the default uid for inodes. For mounts to servers
which do support the CIFS Unix extensions, such as a
properly configured Samba server, the server provides
the uid, gid and mode so this parameter should not be
specified unless the server and clients uid and gid
numbering differ. If the server and client are in the
same domain (e.g. running winbind or nss_ldap) and
the server supports the Unix Extensions then the uid
and gid can be retrieved from the server (and uid
and gid would not have to be specifed on the mount.
For servers which do not support the CIFS Unix
extensions, the default uid (and gid) returned on lookup
of existing files will be the uid (gid) of the person
who executed the mount (root, except when mount.cifs
is configured setuid for user mounts) unless the "uid="
(gid) mount option is specified. For the uid (gid) of newly
Expand All @@ -281,8 +287,7 @@ A partial list of the supported mount options follows:
the client. Note that the mount.cifs helper must be
at version 1.10 or higher to support specifying the uid
(or gid) in non-numberic form.
gid If CIFS Unix extensions are not supported by the server
this overrides the default gid for inodes.
gid Set the default gid for inodes (similar to above).
file_mode If CIFS Unix extensions are not supported by the server
this overrides the default mode for file inodes.
dir_mode If CIFS Unix extensions are not supported by the server
Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ need to add ability to set time to server (utimes command)

u) DOS attrs - returned as pseudo-xattr in Samba format (check VFAT and NTFS for this too)

v) mount check for unmatched uids - and uid override
v) mount check for unmatched uids

w) Add mount option for Linux extension disable per mount, and partial
disable per mount (uid off, symlink/fifo/mknod on but what about posix acls?)
Expand Down
14 changes: 8 additions & 6 deletions fs/cifs/cifs_fs_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
#define CIFS_MOUNT_SET_UID 2 /* set current->euid in create etc. */
#define CIFS_MOUNT_SERVER_INUM 4 /* inode numbers from uniqueid from server */
#define CIFS_MOUNT_DIRECT_IO 8 /* do not write nor read through page cache */
#define CIFS_MOUNT_NO_XATTR 0x10 /* if set - disable xattr support */
#define CIFS_MOUNT_MAP_SPECIAL_CHR 0x20 /* remap illegal chars in filenames */
#define CIFS_MOUNT_POSIX_PATHS 0x40 /* Negotiate posix pathnames if possible. */
#define CIFS_MOUNT_UNX_EMUL 0x80 /* Network compat with SFUnix emulation */
#define CIFS_MOUNT_NO_BRL 0x100 /* No sending byte range locks to srv */
#define CIFS_MOUNT_CIFS_ACL 0x200 /* send ACL requests to non-POSIX srv */
#define CIFS_MOUNT_NO_XATTR 0x10 /* if set - disable xattr support */
#define CIFS_MOUNT_MAP_SPECIAL_CHR 0x20 /* remap illegal chars in filenames */
#define CIFS_MOUNT_POSIX_PATHS 0x40 /* Negotiate posix pathnames if possible*/
#define CIFS_MOUNT_UNX_EMUL 0x80 /* Network compat with SFUnix emulation */
#define CIFS_MOUNT_NO_BRL 0x100 /* No sending byte range locks to srv */
#define CIFS_MOUNT_CIFS_ACL 0x200 /* send ACL requests to non-POSIX srv */
#define CIFS_MOUNT_OVERR_UID 0x400 /* override uid returned from server */
#define CIFS_MOUNT_OVERR_GID 0x800 /* override gid returned from server */

struct cifs_sb_info {
struct cifsTconInfo *tcon; /* primary mount */
Expand Down
76 changes: 42 additions & 34 deletions fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cifs_read_super(struct super_block *sb, void *data,
sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info),GFP_KERNEL);
cifs_sb = CIFS_SB(sb);
if(cifs_sb == NULL)
if (cifs_sb == NULL)
return -ENOMEM;

rc = cifs_mount(sb, cifs_sb, data, devname);
Expand All @@ -115,10 +115,10 @@ cifs_read_super(struct super_block *sb, void *data,
sb->s_magic = CIFS_MAGIC_NUMBER;
sb->s_op = &cifs_super_ops;
#ifdef CONFIG_CIFS_EXPERIMENTAL
if(experimEnabled != 0)
if (experimEnabled != 0)
sb->s_export_op = &cifs_export_ops;
#endif /* EXPERIMENTAL */
/* if(cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
/* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
sb->s_blocksize = cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
#ifdef CONFIG_CIFS_QUOTA
sb->s_qcop = &cifs_quotactl_ops;
Expand Down Expand Up @@ -147,8 +147,8 @@ cifs_read_super(struct super_block *sb, void *data,
iput(inode);

out_mount_failed:
if(cifs_sb) {
if(cifs_sb->local_nls)
if (cifs_sb) {
if (cifs_sb->local_nls)
unload_nls(cifs_sb->local_nls);
kfree(cifs_sb);
}
Expand All @@ -163,7 +163,7 @@ cifs_put_super(struct super_block *sb)

cFYI(1, ("In cifs_put_super"));
cifs_sb = CIFS_SB(sb);
if(cifs_sb == NULL) {
if (cifs_sb == NULL) {
cFYI(1,("Empty cifs superblock info passed to unmount"));
return;
}
Expand Down Expand Up @@ -208,14 +208,14 @@ cifs_statfs(struct dentry *dentry, struct kstatfs *buf)

/* Only need to call the old QFSInfo if failed
on newer one */
if(rc)
if(pTcon->ses->capabilities & CAP_NT_SMBS)
if (rc)
if (pTcon->ses->capabilities & CAP_NT_SMBS)
rc = CIFSSMBQFSInfo(xid, pTcon, buf); /* not supported by OS2 */

/* Some old Windows servers also do not support level 103, retry with
older level one if old server failed the previous call or we
bypassed it because we detected that this was an older LANMAN sess */
if(rc)
if (rc)
rc = SMBOldQFSInfo(xid, pTcon, buf);
/*
int f_type;
Expand Down Expand Up @@ -301,11 +301,19 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m)
if (cifs_sb->tcon->ses->userName)
seq_printf(s, ",username=%s",
cifs_sb->tcon->ses->userName);
if(cifs_sb->tcon->ses->domainName)
if (cifs_sb->tcon->ses->domainName)
seq_printf(s, ",domain=%s",
cifs_sb->tcon->ses->domainName);
}
}
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
seq_printf(s, ",posixpaths");
if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) ||
!(cifs_sb->tcon->ses->capabilities & CAP_UNIX))
seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) ||
!(cifs_sb->tcon->ses->capabilities & CAP_UNIX))
seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
seq_printf(s, ",rsize=%d",cifs_sb->rsize);
seq_printf(s, ",wsize=%d",cifs_sb->wsize);
}
Expand All @@ -321,14 +329,14 @@ int cifs_xquota_set(struct super_block * sb, int quota_type, qid_t qid,
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
struct cifsTconInfo *pTcon;

if(cifs_sb)
if (cifs_sb)
pTcon = cifs_sb->tcon;
else
return -EIO;


xid = GetXid();
if(pTcon) {
if (pTcon) {
cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
} else {
return -EIO;
Expand All @@ -346,13 +354,13 @@ int cifs_xquota_get(struct super_block * sb, int quota_type, qid_t qid,
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
struct cifsTconInfo *pTcon;

if(cifs_sb)
if (cifs_sb)
pTcon = cifs_sb->tcon;
else
return -EIO;

xid = GetXid();
if(pTcon) {
if (pTcon) {
cFYI(1,("set type: 0x%x id: %d",quota_type,qid));
} else {
rc = -EIO;
Expand All @@ -369,13 +377,13 @@ int cifs_xstate_set(struct super_block * sb, unsigned int flags, int operation)
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
struct cifsTconInfo *pTcon;

if(cifs_sb)
if (cifs_sb)
pTcon = cifs_sb->tcon;
else
return -EIO;

xid = GetXid();
if(pTcon) {
if (pTcon) {
cFYI(1,("flags: 0x%x operation: 0x%x",flags,operation));
} else {
rc = -EIO;
Expand All @@ -392,13 +400,13 @@ int cifs_xstate_get(struct super_block * sb, struct fs_quota_stat *qstats)
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
struct cifsTconInfo *pTcon;

if(cifs_sb) {
if (cifs_sb) {
pTcon = cifs_sb->tcon;
} else {
return -EIO;
}
xid = GetXid();
if(pTcon) {
if (pTcon) {
cFYI(1,("pqstats %p",qstats));
} else {
rc = -EIO;
Expand All @@ -424,11 +432,11 @@ static void cifs_umount_begin(struct vfsmount * vfsmnt, int flags)
if (!(flags & MNT_FORCE))
return;
cifs_sb = CIFS_SB(vfsmnt->mnt_sb);
if(cifs_sb == NULL)
if (cifs_sb == NULL)
return;

tcon = cifs_sb->tcon;
if(tcon == NULL)
if (tcon == NULL)
return;
down(&tcon->tconSem);
if (atomic_read(&tcon->useCount) == 1)
Expand All @@ -437,7 +445,7 @@ static void cifs_umount_begin(struct vfsmount * vfsmnt, int flags)

/* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
/* cancel_notify_requests(tcon); */
if(tcon->ses && tcon->ses->server)
if (tcon->ses && tcon->ses->server)
{
cFYI(1,("wake up tasks now - umount begin not complete"));
wake_up_all(&tcon->ses->server->request_q);
Expand Down Expand Up @@ -723,7 +731,7 @@ cifs_destroy_inodecache(void)
static int
cifs_init_request_bufs(void)
{
if(CIFSMaxBufSize < 8192) {
if (CIFSMaxBufSize < 8192) {
/* Buffer size can not be smaller than 2 * PATH_MAX since maximum
Unicode path name has to fit in any SMB/CIFS path based frames */
CIFSMaxBufSize = 8192;
Expand All @@ -740,7 +748,7 @@ cifs_init_request_bufs(void)
if (cifs_req_cachep == NULL)
return -ENOMEM;

if(cifs_min_rcv < 1)
if (cifs_min_rcv < 1)
cifs_min_rcv = 1;
else if (cifs_min_rcv > 64) {
cifs_min_rcv = 64;
Expand All @@ -750,7 +758,7 @@ cifs_init_request_bufs(void)
cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
cifs_req_cachep);

if(cifs_req_poolp == NULL) {
if (cifs_req_poolp == NULL) {
kmem_cache_destroy(cifs_req_cachep);
return -ENOMEM;
}
Expand All @@ -771,7 +779,7 @@ cifs_init_request_bufs(void)
return -ENOMEM;
}

if(cifs_min_small < 2)
if (cifs_min_small < 2)
cifs_min_small = 2;
else if (cifs_min_small > 256) {
cifs_min_small = 256;
Expand All @@ -781,7 +789,7 @@ cifs_init_request_bufs(void)
cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
cifs_sm_req_cachep);

if(cifs_sm_req_poolp == NULL) {
if (cifs_sm_req_poolp == NULL) {
mempool_destroy(cifs_req_poolp);
kmem_cache_destroy(cifs_req_cachep);
kmem_cache_destroy(cifs_sm_req_cachep);
Expand Down Expand Up @@ -811,7 +819,7 @@ cifs_init_mids(void)

/* 3 is a reasonable minimum number of simultaneous operations */
cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
if(cifs_mid_poolp == NULL) {
if (cifs_mid_poolp == NULL) {
kmem_cache_destroy(cifs_mid_cachep);
return -ENOMEM;
}
Expand Down Expand Up @@ -849,14 +857,14 @@ static int cifs_oplock_thread(void * dummyarg)
continue;

spin_lock(&GlobalMid_Lock);
if(list_empty(&GlobalOplock_Q)) {
if (list_empty(&GlobalOplock_Q)) {
spin_unlock(&GlobalMid_Lock);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(39*HZ);
} else {
oplock_item = list_entry(GlobalOplock_Q.next,
struct oplock_q_entry, qhead);
if(oplock_item) {
if (oplock_item) {
cFYI(1,("found oplock item to write out"));
pTcon = oplock_item->tcon;
inode = oplock_item->pinode;
Expand All @@ -870,7 +878,7 @@ static int cifs_oplock_thread(void * dummyarg)
/* mutex_lock(&inode->i_mutex);*/
if (S_ISREG(inode->i_mode)) {
rc = filemap_fdatawrite(inode->i_mapping);
if(CIFS_I(inode)->clientCanCacheRead == 0) {
if (CIFS_I(inode)->clientCanCacheRead == 0) {
filemap_fdatawait(inode->i_mapping);
invalidate_remote_inode(inode);
}
Expand All @@ -887,7 +895,7 @@ static int cifs_oplock_thread(void * dummyarg)
not bother sending an oplock release if session
to server still is disconnected since oplock
already released by the server in that case */
if(pTcon->tidStatus != CifsNeedReconnect) {
if (pTcon->tidStatus != CifsNeedReconnect) {
rc = CIFSSMBLock(0, pTcon, netfid,
0 /* len */ , 0 /* offset */, 0,
0, LOCKING_ANDX_OPLOCK_RELEASE,
Expand Down Expand Up @@ -921,7 +929,7 @@ static int cifs_dnotify_thread(void * dummyarg)
list_for_each(tmp, &GlobalSMBSessionList) {
ses = list_entry(tmp, struct cifsSesInfo,
cifsSessionList);
if(ses && ses->server &&
if (ses && ses->server &&
atomic_read(&ses->server->inFlight))
wake_up_all(&ses->server->response_q);
}
Expand Down Expand Up @@ -970,10 +978,10 @@ init_cifs(void)
rwlock_init(&GlobalSMBSeslock);
spin_lock_init(&GlobalMid_Lock);

if(cifs_max_pending < 2) {
if (cifs_max_pending < 2) {
cifs_max_pending = 2;
cFYI(1,("cifs_max_pending set to min of 2"));
} else if(cifs_max_pending > 256) {
} else if (cifs_max_pending > 256) {
cifs_max_pending = 256;
cFYI(1,("cifs_max_pending set to max of 256"));
}
Expand Down
Loading

0 comments on commit 4523cc3

Please sign in to comment.