--- client.orig/umount.cifs.c 2008-02-22 05:58:37.000000000 -0600 +++ client/umount.cifs.c 2008-02-25 08:15:29.000000000 -0600 @@ -34,6 +34,7 @@ #include #include #include +#include #define UNMOUNT_CIFS_VERSION_MAJOR "0" #define UNMOUNT_CIFS_VERSION_MINOR "5" @@ -69,6 +70,8 @@ #define CIFS_IOC_CHECKUMOUNT _IO(0xCF, 2) #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDU */ +#define streq(s, t)(strcmp ((s), (t)) == 0) + static struct option longopts[] = { { "all", 0, NULL, 'a' }, { "help",0, NULL, 'h' }, @@ -248,6 +251,46 @@ static int remove_from_mtab(char * mount return rc; } +char * +xstrdup(const char *s) { + char *t; + + if (s == NULL) + return NULL; + + t = strdup(s); + + if (t == NULL) { + fprintf(stderr, "not enough memory"); + exit(1); + } + + return t; +} + +/* 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. */ +char * +canonicalize(const char *path) { + char canonical[PATH_MAX+2]; + + if (path == NULL) + return NULL; +#if 1 + if (streq(path, "null") || + streq(path, "proc") || + streq(path, "devpts")) + return (xstrdup(path)); +#endif + if (realpath(path, canonical)) + return xstrdup(canonical); + + return xstrdup(path); +} + int main(int argc, char ** argv) { int c; @@ -321,7 +364,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");