From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/client/smbumount.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'source3/client/smbumount.c') diff --git a/source3/client/smbumount.c b/source3/client/smbumount.c index bc8999d765..dacf4ab67d 100644 --- a/source3/client/smbumount.c +++ b/source3/client/smbumount.c @@ -23,20 +23,24 @@ #undef SMB_IOC_GETMOUNTUID #define SMB_IOC_GETMOUNTUID _IOR('u', 1, __kernel_uid_t) -static char *progname; +#ifndef O_NOFOLLOW +#define O_NOFOLLOW 0400000 +#endif static void usage(void) { - printf("usage: %s mount-point\n", progname); + printf("usage: smbumount mountpoint\n"); } static int umount_ok(const char *mount_point) { - int fid = open(mount_point, O_RDONLY, 0); + /* we set O_NOFOLLOW to prevent users playing games with symlinks to + umount filesystems they don't own */ + int fid = open(mount_point, O_RDONLY|O_NOFOLLOW, 0); __kernel_uid_t mount_uid; - + if (fid == -1) { fprintf(stderr, "Could not open %s: %s\n", mount_point, strerror(errno)); @@ -49,7 +53,7 @@ umount_ok(const char *mount_point) return -1; } - if ( (getuid() != 0) + if ((getuid() != 0) && (mount_uid != getuid())) { fprintf(stderr, "You are not allowed to umount %s\n", mount_point); @@ -63,15 +67,14 @@ umount_ok(const char *mount_point) /* 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 + is not a legal pathname for ``/dev/fd0'' Anything we cannot parse we return unmodified. */ -char * +static char * canonicalize (char *path) { char *canonical = malloc (PATH_MAX + 1); - if (strlen(path) > PATH_MAX) - { + if (strlen(path) > PATH_MAX) { fprintf(stderr, "Mount point string too long\n"); return NULL; } @@ -91,22 +94,18 @@ int main(int argc, char *argv[]) { int fd; - char* mount_point; - struct mntent *mnt; FILE* mtab; FILE* new_mtab; - progname = argv[0]; - if (argc != 2) { usage(); exit(1); } if (geteuid() != 0) { - fprintf(stderr, "%s must be installed suid root\n", progname); + fprintf(stderr, "smbumount must be installed suid root\n"); exit(1); } -- cgit