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>
18 static char *progname;
23 printf("usage: %s mount-point\n", progname);
27 umount_ok(const char *mount_point)
29 int fid = open(mount_point, O_RDONLY, 0);
33 fprintf(stderr, "Could not open %s: %s\n",
34 mount_point, strerror(errno));
38 if (ioctl(fid, SMB_IOC_GETMOUNTUID, &mount_uid) != 0) {
39 fprintf(stderr, "%s probably not smb-filesystem\n",
45 && (mount_uid != getuid())) {
46 fprintf(stderr, "You are not allowed to umount %s\n",
55 /* Make a canonical pathname from PATH. Returns a freshly malloced string.
56 It is up the *caller* to ensure that the PATH is sensible. i.e.
57 canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
58 is not a legal pathname for ``/dev/fd0.'' Anything we cannot parse
59 we return unmodified. */
61 canonicalize (char *path)
63 char *canonical = malloc (PATH_MAX + 1);
65 if (strlen(path) > PATH_MAX)
67 fprintf(stderr, "Mount point string too long\n");
74 if (realpath (path, canonical))
77 pstrcpy (canonical, path);
83 main(int argc, char *argv[])
100 if (geteuid() != 0) {
101 fprintf(stderr, "%s must be installed suid root\n", progname);
105 mount_point = canonicalize(argv[1]);
107 if (mount_point == NULL)
112 if (umount_ok(mount_point) != 0) {
116 if (umount(mount_point) != 0) {
117 fprintf(stderr, "Could not umount %s: %s\n",
118 mount_point, strerror(errno));
122 if ((fd = open(MOUNTED"~", O_RDWR|O_CREAT|O_EXCL, 0600)) == -1)
124 fprintf(stderr, "Can't get "MOUNTED"~ lock file");
129 if ((mtab = setmntent(MOUNTED, "r")) == NULL) {
130 fprintf(stderr, "Can't open " MOUNTED ": %s\n",
135 #define MOUNTED_TMP MOUNTED".tmp"
137 if ((new_mtab = setmntent(MOUNTED_TMP, "w")) == NULL) {
138 fprintf(stderr, "Can't open " MOUNTED_TMP ": %s\n",
144 while ((mnt = getmntent(mtab)) != NULL) {
145 if (strcmp(mnt->mnt_dir, mount_point) != 0) {
146 addmntent(new_mtab, mnt);
152 if (fchmod (fileno (new_mtab), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) {
153 fprintf(stderr, "Error changing mode of %s: %s\n",
154 MOUNTED_TMP, strerror(errno));
160 if (rename(MOUNTED_TMP, MOUNTED) < 0) {
161 fprintf(stderr, "Cannot rename %s to %s: %s\n",
162 MOUNTED, MOUNTED_TMP, strerror(errno));
166 if (unlink(MOUNTED"~") == -1)
168 fprintf(stderr, "Can't remove "MOUNTED"~");