4 * Copyright (C) 1995-1998 by Volker Lendecke
12 #include <asm/types.h>
13 #include <asm/posix_types.h>
14 #include <linux/smb.h>
15 #include <linux/smb_mount.h>
16 #include <linux/smb_fs.h>
20 static char *progname;
25 printf("usage: %s mount-point\n", progname);
29 umount_ok(const char *mount_point)
31 int fid = open(mount_point, O_RDONLY, 0);
35 fprintf(stderr, "Could not open %s: %s\n",
36 mount_point, strerror(errno));
40 if (ioctl(fid, SMB_IOC_GETMOUNTUID, &mount_uid) != 0) {
41 fprintf(stderr, "%s probably not smb-filesystem\n",
47 && (mount_uid != getuid())) {
48 fprintf(stderr, "You are not allowed to umount %s\n",
57 /* Make a canonical pathname from PATH. Returns a freshly malloced string.
58 It is up the *caller* to ensure that the PATH is sensible. i.e.
59 canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
60 is not a legal pathname for ``/dev/fd0.'' Anything we cannot parse
61 we return unmodified. */
63 canonicalize (const char *path)
65 char *canonical = malloc (PATH_MAX + 1);
67 if (strlen(path) > PATH_MAX)
69 fprintf(stderr, "Mount point string too long\n");
76 if (realpath (path, canonical))
79 pstrcpy (canonical, path);
85 main(int argc, char *argv[])
102 if (geteuid() != 0) {
103 fprintf(stderr, "%s must be installed suid root\n", progname);
107 mount_point = canonicalize(argv[1]);
109 if (mount_point == NULL)
114 if (umount_ok(mount_point) != 0) {
118 if (umount(mount_point) != 0) {
119 fprintf(stderr, "Could not umount %s: %s\n",
120 mount_point, strerror(errno));
124 if ((fd = open(MOUNTED"~", O_RDWR|O_CREAT|O_EXCL, 0600)) == -1)
126 fprintf(stderr, "Can't get "MOUNTED"~ lock file");
131 if ((mtab = setmntent(MOUNTED, "r")) == NULL) {
132 fprintf(stderr, "Can't open " MOUNTED ": %s\n",
137 #define MOUNTED_TMP MOUNTED".tmp"
139 if ((new_mtab = setmntent(MOUNTED_TMP, "w")) == NULL) {
140 fprintf(stderr, "Can't open " MOUNTED_TMP ": %s\n",
146 while ((mnt = getmntent(mtab)) != NULL) {
147 if (strcmp(mnt->mnt_dir, mount_point) != 0) {
148 addmntent(new_mtab, mnt);
154 if (fchmod (fileno (new_mtab), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) {
155 fprintf(stderr, "Error changing mode of %s: %s\n",
156 MOUNTED_TMP, strerror(errno));
162 if (rename(MOUNTED_TMP, MOUNTED) < 0) {
163 fprintf(stderr, "Cannot rename %s to %s: %s\n",
164 MOUNTED, MOUNTED_TMP, strerror(errno));
168 if (unlink(MOUNTED"~") == -1)
170 fprintf(stderr, "Can't remove "MOUNTED"~");