From 16d2fdf5750dbb344b19df23fb741fc8e0b43d10 Mon Sep 17 00:00:00 2001 From: Shirish Pargaonkar Date: Thu, 5 Feb 2009 14:12:42 -0500 Subject: umount.cifs: clean-up entries in /etc/mtab after unmount This patch removes the remaining entry in /etc/mtab after a filesystem is unmounted by canonicalizing the mountpoint supplied on the command line. Please refer to bug 4370 in samba bugzilla. --- source3/client/umount.cifs.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'source3/client') diff --git a/source3/client/umount.cifs.c b/source3/client/umount.cifs.c index aff7cea3974..81925eda275 100644 --- a/source3/client/umount.cifs.c +++ b/source3/client/umount.cifs.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "mount.h" #define UNMOUNT_CIFS_VERSION_MAJOR "0" @@ -231,6 +232,37 @@ static int remove_from_mtab(char * mountpoint) return rc; } +/* Make a canonical pathname from PATH. Returns a freshly malloced string. + It is up the *caller* to ensure that the PATH is sensible. i.e. + canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.'' + is not a legal pathname for ``/dev/fd0'' Anything we cannot parse + we return unmodified. */ +static char * +canonicalize(char *path) +{ + char *canonical = malloc (PATH_MAX + 1); + + if (!canonical) { + fprintf(stderr, "Error! Not enough memory!\n"); + return NULL; + } + + if (strlen(path) > PATH_MAX) { + fprintf(stderr, "Mount point string too long\n"); + return NULL; + } + + if (path == NULL) + return NULL; + + if (realpath (path, canonical)) + return canonical; + + strncpy (canonical, path, PATH_MAX); + canonical[PATH_MAX] = '\0'; + return canonical; +} + int main(int argc, char ** argv) { int c; @@ -304,7 +336,7 @@ int main(int argc, char ** argv) argv += optind; argc -= optind; - mountpoint = argv[0]; + mountpoint = canonicalize(argv[0]); if((argc < 1) || (argv[0] == NULL)) { printf("\nMissing name of unmount directory\n"); -- cgit From ea8bd81b6eaf2d2ca005d30c1580e7a45d3b3c5d Mon Sep 17 00:00:00 2001 From: Shirish Pargaonkar Date: Fri, 6 Feb 2009 08:13:38 -0500 Subject: mount.cifs: add fakemount (-f) and nomtab (-n) flags to mount.cifs ...so that these options work correctly when passed in by mount(8). --- source3/client/mount.cifs.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source3/client') diff --git a/source3/client/mount.cifs.c b/source3/client/mount.cifs.c index 9f4d1d3fd06..df5be846f1b 100644 --- a/source3/client/mount.cifs.c +++ b/source3/client/mount.cifs.c @@ -85,6 +85,7 @@ const char *thisprogram; int verboseflag = 0; +int fakemnt = 0; static int got_password = 0; static int got_user = 0; static int got_domain = 0; @@ -1103,8 +1104,8 @@ int main(int argc, char ** argv) mount_cifs_usage (); exit(EX_USAGE); case 'n': - ++nomtab; - break; + ++nomtab; + break; case 'b': #ifdef MS_BIND flags |= MS_BIND; @@ -1209,6 +1210,9 @@ int main(int argc, char ** argv) break; case 't': break; + case 'f': + ++fakemnt; + break; default: printf("unknown mount option %c\n",c); mount_cifs_usage(); @@ -1410,7 +1414,7 @@ mount_retry: } } - if (mount(dev_name, mountpoint, "cifs", flags, options)) { + if (!fakemnt && mount(dev_name, mountpoint, "cifs", flags, options)) { switch (errno) { case ECONNREFUSED: case EHOSTUNREACH: @@ -1440,6 +1444,8 @@ mount_retry: goto mount_exit; } + if (nomtab) + goto mount_exit; atexit(unlock_mtab); rc = lock_mtab(); if (rc) { -- cgit From d895ca505f7f9c4edf476a0c966e93917e35575c Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Fri, 6 Feb 2009 08:29:58 -0500 Subject: mount.cifs: initialize rc to 0 in main The value of rc in main() isn't initialized in the declaration. This wasn't a problem before, but Shirish's fakemount patch can make it so that we return the uninitialized variable if the -n flag is used. Fix this by initializing rc to 0. Signed-off-by: Jeff Layton --- source3/client/mount.cifs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client') diff --git a/source3/client/mount.cifs.c b/source3/client/mount.cifs.c index df5be846f1b..a7366095805 100644 --- a/source3/client/mount.cifs.c +++ b/source3/client/mount.cifs.c @@ -1031,7 +1031,7 @@ int main(int argc, char ** argv) char * resolved_path = NULL; char * temp; char * dev_name; - int rc; + int rc = 0; int rsize = 0; int wsize = 0; int nomtab = 0; -- cgit