summaryrefslogtreecommitdiffstats
path: root/source3/client/umount.cifs.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-02-09 16:51:46 +0100
committerJelmer Vernooij <jelmer@samba.org>2009-02-09 16:51:46 +0100
commit9b366d703210b493aa1389bbdd288a2b00958766 (patch)
tree12acaf89af2c6bd2610018d267e2d8030d9b4bd6 /source3/client/umount.cifs.c
parent6d139ca4680abcbda5110f2f0886aa038ff62088 (diff)
parent1dadf17be847e3f93b72988bcc7e8620a8d5908c (diff)
downloadsamba-9b366d703210b493aa1389bbdd288a2b00958766.tar.gz
samba-9b366d703210b493aa1389bbdd288a2b00958766.tar.xz
samba-9b366d703210b493aa1389bbdd288a2b00958766.zip
Merge branch 'master' of ssh://git.samba.org/data/git/samba
Diffstat (limited to 'source3/client/umount.cifs.c')
-rw-r--r--source3/client/umount.cifs.c34
1 files changed, 33 insertions, 1 deletions
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 <errno.h>
#include <string.h>
#include <mntent.h>
+#include <limits.h>
#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");