summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShirish Pargaonkar <shirishpargaonkar@gmail.com>2009-02-05 14:18:36 -0500
committerJeff Layton <jlayton@redhat.com>2009-02-05 14:18:36 -0500
commitdf341bd2b83cc67e31d5b91ae39b4f4f7619ffd0 (patch)
tree5ee76ba4a340b6ebf4130744829c6af819e239a2
parent7a1408f89f1addff993d1e2dfb7462d12d0a2f48 (diff)
downloadsamba-df341bd2b83cc67e31d5b91ae39b4f4f7619ffd0.tar.gz
samba-df341bd2b83cc67e31d5b91ae39b4f4f7619ffd0.tar.xz
samba-df341bd2b83cc67e31d5b91ae39b4f4f7619ffd0.zip
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.
-rw-r--r--source/client/umount.cifs.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/source/client/umount.cifs.c b/source/client/umount.cifs.c
index 8f2f37702b6..6bed410d576 100644
--- a/source/client/umount.cifs.c
+++ b/source/client/umount.cifs.c
@@ -34,6 +34,7 @@
#include <errno.h>
#include <string.h>
#include <mntent.h>
+#include <limits.h>
#include "mount.h"
#define UNMOUNT_CIFS_VERSION_MAJOR "0"
@@ -232,6 +233,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;
@@ -305,7 +337,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");