4 * Copyright (C) 1995-1998 by Volker Lendecke
13 #include <sys/socket.h>
14 #include <sys/param.h>
15 #include <netinet/in.h>
18 #include <sys/types.h>
19 /* #include <sys/wait.h> */ /* generates a warning here */
20 extern pid_t waitpid(pid_t, int *, int);
21 #include <sys/errno.h>
27 #include <sys/mount.h>
30 #include <sys/ioctl.h>
32 #include <linux/smb.h>
33 #include <linux/smb_mount.h>
34 #include <linux/smb_fs.h>
36 static char *progname;
41 printf("usage: %s mount-point\n", progname);
45 umount_ok(const char *mount_point)
47 int fid = open(mount_point, O_RDONLY, 0);
51 fprintf(stderr, "Could not open %s: %s\n",
52 mount_point, strerror(errno));
56 if (ioctl(fid, SMB_IOC_GETMOUNTUID, &mount_uid) != 0) {
57 fprintf(stderr, "%s probably not smb-filesystem\n",
63 && (mount_uid != getuid())) {
64 fprintf(stderr, "You are not allowed to umount %s\n",
73 /* Make a canonical pathname from PATH. Returns a freshly malloced string.
74 It is up the *caller* to ensure that the PATH is sensible. i.e.
75 canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
76 is not a legal pathname for ``/dev/fd0.'' Anything we cannot parse
77 we return unmodified. */
79 canonicalize (const char *path)
81 char *canonical = malloc (PATH_MAX + 1);
83 if (strlen(path) > PATH_MAX)
85 fprintf(stderr, "Mount point string too long\n");
92 if (realpath (path, canonical))
95 pstrcpy (canonical, path);
101 main(int argc, char *argv[])
118 if (geteuid() != 0) {
119 fprintf(stderr, "%s must be installed suid root\n", progname);
123 mount_point = canonicalize(argv[1]);
125 if (mount_point == NULL)
130 if (umount_ok(mount_point) != 0) {
134 if (umount(mount_point) != 0) {
135 fprintf(stderr, "Could not umount %s: %s\n",
136 mount_point, strerror(errno));
140 if ((fd = open(MOUNTED"~", O_RDWR|O_CREAT|O_EXCL, 0600)) == -1)
142 fprintf(stderr, "Can't get "MOUNTED"~ lock file");
147 if ((mtab = setmntent(MOUNTED, "r")) == NULL) {
148 fprintf(stderr, "Can't open " MOUNTED ": %s\n",
153 #define MOUNTED_TMP MOUNTED".tmp"
155 if ((new_mtab = setmntent(MOUNTED_TMP, "w")) == NULL) {
156 fprintf(stderr, "Can't open " MOUNTED_TMP ": %s\n",
162 while ((mnt = getmntent(mtab)) != NULL) {
163 if (strcmp(mnt->mnt_dir, mount_point) != 0) {
164 addmntent(new_mtab, mnt);
170 if (fchmod (fileno (new_mtab), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) {
171 fprintf(stderr, "Error changing mode of %s: %s\n",
172 MOUNTED_TMP, strerror(errno));
178 if (rename(MOUNTED_TMP, MOUNTED) < 0) {
179 fprintf(stderr, "Cannot rename %s to %s: %s\n",
180 MOUNTED, MOUNTED_TMP, strerror(errno));
184 if (unlink(MOUNTED"~") == -1)
186 fprintf(stderr, "Can't remove "MOUNTED"~");