summaryrefslogtreecommitdiff
path: root/source3/client/mount.cifs.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2008-11-06 15:07:07 -0500
committerJeff Layton <jlayton@redhat.com>2008-11-06 15:07:07 -0500
commit32695912dd3ed7c02da68209328d630c89d395ba (patch)
tree9fe8734a10f5a2a79980dff0578db12de0288530 /source3/client/mount.cifs.c
parentdb26f7b7c49b6d4254ce5da7097e062b7dbd0409 (diff)
downloadsamba-32695912dd3ed7c02da68209328d630c89d395ba.tar.gz
samba-32695912dd3ed7c02da68209328d630c89d395ba.tar.bz2
samba-32695912dd3ed7c02da68209328d630c89d395ba.zip
mount.cifs: use lock/unlock_mtab scheme from util-linux-ng mount prog
The util-linux-ng sources have a good, but rather complex scheme for locking the mtab before updating it. Mount helpers need to follow the same scheme. Advisory locking only works if everyone is using the same locking scheme. Copy the routines we need from util-linux-ng into a separate source file and then have mount.cifs and umount.cifs link in this object. The long term goal is to have these routines in a separate helper library (libmount). Mount helpers can then dynamically link in that lib. Until that happens, this should serve as a suitable stopgap solution. Signed-off-by: Jeff Layton <jlayton@redhat.com>
Diffstat (limited to 'source3/client/mount.cifs.c')
-rw-r--r--source3/client/mount.cifs.c97
1 files changed, 49 insertions, 48 deletions
diff --git a/source3/client/mount.cifs.c b/source3/client/mount.cifs.c
index 2a9c2b7304..da2f98bff8 100644
--- a/source3/client/mount.cifs.c
+++ b/source3/client/mount.cifs.c
@@ -39,9 +39,10 @@
#include <mntent.h>
#include <fcntl.h>
#include <limits.h>
+#include "mount.h"
#define MOUNT_CIFS_VERSION_MAJOR "1"
-#define MOUNT_CIFS_VERSION_MINOR "11"
+#define MOUNT_CIFS_VERSION_MINOR "12"
#ifndef MOUNT_CIFS_VENDOR_SUFFIX
#ifdef _SAMBA_BUILD_
@@ -79,15 +80,6 @@
#define MOUNT_PASSWD_SIZE 64
#define DOMAIN_SIZE 64
-/* exit status - bits below are ORed */
-#define EX_USAGE 1 /* incorrect invocation or permission */
-#define EX_SYSERR 2 /* out of memory, cannot fork, ... */
-#define EX_SOFTWARE 4 /* internal mount bug or wrong version */
-#define EX_USER 8 /* user interrupt */
-#define EX_FILEIO 16 /* problems writing, locking, ... mtab/fstab */
-#define EX_FAIL 32 /* mount failure */
-#define EX_SOMEOK 64 /* some mount succeeded */
-
const char *thisprogram;
int verboseflag = 0;
static int got_password = 0;
@@ -1424,48 +1416,57 @@ mount_retry:
printf("Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n");
rc = EX_FAIL;
} else {
+ atexit(unlock_mtab);
+ rc = lock_mtab();
+ if (rc) {
+ printf("cannot lock mtab");
+ goto mount_exit;
+ }
pmntfile = setmntent(MOUNTED, "a+");
- if(pmntfile) {
- mountent.mnt_fsname = dev_name;
- mountent.mnt_dir = mountpoint;
- mountent.mnt_type = CONST_DISCARD(char *,"cifs");
- mountent.mnt_opts = (char *)malloc(220);
- if(mountent.mnt_opts) {
- char * mount_user = getusername();
- memset(mountent.mnt_opts,0,200);
- if(flags & MS_RDONLY)
- strlcat(mountent.mnt_opts,"ro",220);
- else
- strlcat(mountent.mnt_opts,"rw",220);
- if(flags & MS_MANDLOCK)
- strlcat(mountent.mnt_opts,",mand",220);
- if(flags & MS_NOEXEC)
- strlcat(mountent.mnt_opts,",noexec",220);
- if(flags & MS_NOSUID)
- strlcat(mountent.mnt_opts,",nosuid",220);
- if(flags & MS_NODEV)
- strlcat(mountent.mnt_opts,",nodev",220);
- if(flags & MS_SYNCHRONOUS)
- strlcat(mountent.mnt_opts,",synch",220);
- if(mount_user) {
- if(getuid() != 0) {
- strlcat(mountent.mnt_opts,",user=",220);
- strlcat(mountent.mnt_opts,mount_user,220);
- }
- /* free(mount_user); do not free static mem */
- }
- }
- mountent.mnt_freq = 0;
- mountent.mnt_passno = 0;
- rc = addmntent(pmntfile,&mountent);
- endmntent(pmntfile);
- SAFE_FREE(mountent.mnt_opts);
- if (rc)
- rc = EX_FILEIO;
- } else {
+ if (!pmntfile) {
printf("could not update mount table\n");
+ unlock_mtab();
rc = EX_FILEIO;
+ goto mount_exit;
}
+ mountent.mnt_fsname = dev_name;
+ mountent.mnt_dir = mountpoint;
+ mountent.mnt_type = CONST_DISCARD(char *,"cifs");
+ mountent.mnt_opts = (char *)malloc(220);
+ if(mountent.mnt_opts) {
+ char * mount_user = getusername();
+ memset(mountent.mnt_opts,0,200);
+ if(flags & MS_RDONLY)
+ strlcat(mountent.mnt_opts,"ro",220);
+ else
+ strlcat(mountent.mnt_opts,"rw",220);
+ if(flags & MS_MANDLOCK)
+ strlcat(mountent.mnt_opts,",mand",220);
+ if(flags & MS_NOEXEC)
+ strlcat(mountent.mnt_opts,",noexec",220);
+ if(flags & MS_NOSUID)
+ strlcat(mountent.mnt_opts,",nosuid",220);
+ if(flags & MS_NODEV)
+ strlcat(mountent.mnt_opts,",nodev",220);
+ if(flags & MS_SYNCHRONOUS)
+ strlcat(mountent.mnt_opts,",sync",220);
+ if(mount_user) {
+ if(getuid() != 0) {
+ strlcat(mountent.mnt_opts,
+ ",user=", 220);
+ strlcat(mountent.mnt_opts,
+ mount_user, 220);
+ }
+ }
+ }
+ mountent.mnt_freq = 0;
+ mountent.mnt_passno = 0;
+ rc = addmntent(pmntfile,&mountent);
+ endmntent(pmntfile);
+ unlock_mtab();
+ SAFE_FREE(mountent.mnt_opts);
+ if (rc)
+ rc = EX_FILEIO;
}
mount_exit:
if(mountpassword) {