From ea1498bf601a9046f29a3ce276585202b23ba278 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 26 Jun 2009 09:49:40 +0200 Subject: umount: clean up help output Addresses-Debian-Bug: #320500 Signed-off-by: Karel Zak --- mount/umount.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mount/umount.c') diff --git a/mount/umount.c b/mount/umount.c index 9901a809..0468cb44 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -393,9 +393,9 @@ static struct option longopts[] = static void usage (FILE *fp, int n) { - fprintf (fp, _("Usage: umount [-hV]\n" - " umount -a [-f] [-r] [-n] [-v] [-t vfstypes] [-O opts]\n" - " umount [-f] [-r] [-n] [-v] special | node...\n")); + fprintf (fp, _("Usage: umount -h | -V\n" + " umount -a [-d] [-f] [-r] [-n] [-v] [-t vfstypes] [-O opts]\n" + " umount [-d] [-f] [-r] [-n] [-v] special | node...\n")); exit (n); } -- cgit v1.2.3 From 78c777c6baaa9fbb581562983d6ccc6eba7b92c6 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 29 Jun 2009 21:43:01 +0200 Subject: mount: allow loop suid umount Addresses-Suse-Bug: #461732 Signed-off-by: Kay Sievers Signed-off-by: Karel Zak --- mount/umount.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'mount/umount.c') diff --git a/mount/umount.c b/mount/umount.c index 0468cb44..0e5934fd 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -406,7 +406,7 @@ static int contains(const char *list, const char *s) { int n = strlen(s); - while (*list) { + while (list && *list) { if (strncmp(list, s, n) == 0 && (list[n] == 0 || list[n] == ',')) return 1; @@ -423,7 +423,7 @@ get_value(const char *list, const char *s) { const char *t; int n = strlen(s); - while (*list) { + while (list && *list) { if (strncmp(list, s, n) == 0) { s = t = list+n; while (*s && *s != ',') @@ -432,6 +432,43 @@ get_value(const char *list, const char *s) { } while (*list && *list++ != ',') ; } + return NULL; +} + +/* check if @mc contains a loop device which is associated + * with the @file in fs + */ +static int +is_valid_loop(struct mntentchn *mc, struct mntentchn *fs) +{ + unsigned long long offset = 0; + char *p; + + /* check if it begins with /dev/loop */ + if (strncmp(mc->m.mnt_fsname, "/dev/loop", 9)) + return 0; + + /* check for loop option in fstab */ + if (!contains(fs->m.mnt_opts, "loop")) + return 0; + + /* check for offset option in fstab */ + p = get_value(fs->m.mnt_opts, "offset="); + if (p) + offset = strtoull(p, NULL, 10); + + /* check association */ + if (loopfile_used_with((char *) mc->m.mnt_fsname, + fs->m.mnt_fsname, offset) == 1) { + if (verbose > 1) + printf(_("device %s is associated with %s\n"), + mc->m.mnt_fsname, fs->m.mnt_fsname); + return 1; + } + + if (verbose > 1) + printf(_("device %s is not associated with %s\n"), + mc->m.mnt_fsname, fs->m.mnt_fsname); return 0; } @@ -516,12 +553,15 @@ umount_file (char *arg) { the pair (dev,file) in fstab. */ fs = getfs_by_devdir(mc->m.mnt_fsname, mc->m.mnt_dir); if (!fs) { - if (!getfs_by_spec (file) && !getfs_by_dir (file)) + fs = getfs_by_dir(file); + if (!fs && !getfs_by_spec(file)) die (2, _("umount: %s is not in the fstab " "(and you are not root)"), file); - else + + /* spec could be a file which is loop mounted */ + if (fs && !is_valid_loop(mc, fs)) die (2, _("umount: %s mount disagrees with " "the fstab"), file); } -- cgit v1.2.3 From c74c0daffffbecf1299055fb35908721bcc853b2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 30 Jun 2009 01:13:42 +0200 Subject: include: clean up _PATH_DEV_* macros Signed-off-by: Karel Zak --- include/pathnames.h | 8 +++++++- login-utils/login.c | 4 ++-- misc-utils/script.c | 2 +- mount/lomount.c | 14 ++++++-------- mount/umount.c | 4 +++- tests/expected/paths/built-in | 3 ++- tests/helpers/test_pathnames.c | 3 ++- 7 files changed, 23 insertions(+), 15 deletions(-) (limited to 'mount/umount.c') diff --git a/include/pathnames.h b/include/pathnames.h index 0060a756..12170f9d 100644 --- a/include/pathnames.h +++ b/include/pathnames.h @@ -19,7 +19,6 @@ #undef _PATH_DEFPATH_ROOT #define _PATH_DEFPATH_ROOT "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" -#define _PATH_TTY "/dev/tty" #define _PATH_SECURETTY "/etc/securetty" #define _PATH_WTMPLOCK "/etc/wtmplock" @@ -94,6 +93,13 @@ #define _PATH_MOUNTED_LOCK _PATH_MOUNTED "~" #define _PATH_MOUNTED_TMP _PATH_MOUNTED ".tmp" +#ifndef _PATH_DEV +# define _PATH_DEV "/dev" +#endif + +#define _PATH_DEV_LOOP "/dev/loop" +#define _PATH_DEV_TTY "/dev/tty" + /* udev paths */ #define _PATH_DEV_BYLABEL "/dev/disk/by-label" #define _PATH_DEV_BYUUID "/dev/disk/by-uuid" diff --git a/login-utils/login.c b/login-utils/login.c index f3154259..7328edeb 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -378,7 +378,7 @@ main(int argc, char **argv) int ask, fflag, hflag, pflag, cnt, errsv; int quietlog, passwd_req; char *domain, *ttyn; - char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; + char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_DEV_TTY) + 10]; char *termenv; char *childArgv[10]; char *buff; @@ -499,7 +499,7 @@ main(int argc, char **argv) if (ttyn == NULL || *ttyn == '\0') { /* no snprintf required - see definition of tname */ - sprintf(tname, "%s??", _PATH_TTY); + snprintf(tname, sizeof(tname), "%s??", _PATH_DEV_TTY); ttyn = tname; } diff --git a/misc-utils/script.c b/misc-utils/script.c index 12ea43a8..b877c312 100644 --- a/misc-utils/script.c +++ b/misc-utils/script.c @@ -371,7 +371,7 @@ doshell() { #if 0 int t; - t = open(_PATH_TTY, O_RDWR); + t = open(_PATH_DEV_TTY, O_RDWR); if (t >= 0) { (void) ioctl(t, TIOCNOTTY, (char *)0); (void) close(t); diff --git a/mount/lomount.c b/mount/lomount.c index f0f81ed6..c6e0c929 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -60,8 +60,6 @@ loop_info64_to_old(const struct loop_info64 *info64, struct loop_info *info) return 0; } -#define DEV_LOOP_PATH "/dev/loop" -#define DEV_PATH "/dev" #define LOOPMAJOR 7 #define NLOOPS_DEFAULT 8 /* /dev/loop[0-7] */ @@ -143,10 +141,10 @@ looplist_open(struct looplist *ll, int flag) ll->flag = flag; ll->ncur = -1; - if (stat(DEV_PATH, &st) == -1 || (!S_ISDIR(st.st_mode))) + if (stat(_PATH_DEV, &st) == -1 || (!S_ISDIR(st.st_mode))) return -1; /* /dev doesn't exist */ - if (stat(DEV_LOOP_PATH, &st) == 0 && S_ISDIR(st.st_mode)) + if (stat(_PATH_DEV_LOOP, &st) == 0 && S_ISDIR(st.st_mode)) ll->flag |= LLFLG_SUBDIR; /* /dev/loop/ exists */ if ((ll->flag & LLFLG_USEDONLY) && @@ -179,8 +177,8 @@ looplist_open_dev(struct looplist *ll, int lnum) /* create a full device path */ snprintf(ll->name, sizeof(ll->name), ll->flag & LLFLG_SUBDIR ? - DEV_LOOP_PATH "/%d" : - DEV_PATH "/loop%d", + _PATH_DEV_LOOP "/%d" : + _PATH_DEV "/loop%d", lnum); fd = open(ll->name, O_RDONLY); @@ -331,8 +329,8 @@ looplist_next(struct looplist *ll) */ if (!ll->minors) { ll->nminors = (ll->flag & LLFLG_SUBDIR) ? - loop_scandir(DEV_LOOP_PATH, &ll->minors, 0) : - loop_scandir(DEV_PATH, &ll->minors, 1); + loop_scandir(_PATH_DEV_LOOP, &ll->minors, 0) : + loop_scandir(_PATH_DEV, &ll->minors, 1); ll->ncur = -1; } for (++ll->ncur; ll->ncur < ll->nminors; ll->ncur++) { diff --git a/mount/umount.c b/mount/umount.c index 0e5934fd..a695f0c6 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -14,6 +14,7 @@ #include "mount_constants.h" #include "sundries.h" #include "getusername.h" +#include "pathnames.h" #include "lomount.h" #include "loop.h" #include "fstab.h" @@ -445,7 +446,8 @@ is_valid_loop(struct mntentchn *mc, struct mntentchn *fs) char *p; /* check if it begins with /dev/loop */ - if (strncmp(mc->m.mnt_fsname, "/dev/loop", 9)) + if (strncmp(mc->m.mnt_fsname, _PATH_DEV_LOOP, + sizeof(_PATH_DEV_LOOP) - 1)) return 0; /* check for loop option in fstab */ diff --git a/tests/expected/paths/built-in b/tests/expected/paths/built-in index 318f44e5..51372de3 100644 --- a/tests/expected/paths/built-in +++ b/tests/expected/paths/built-in @@ -1,6 +1,7 @@ _PATH_DEFPATH /usr/local/bin:/bin:/usr/bin _PATH_DEFPATH_ROOT /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin - _PATH_TTY /dev/tty + _PATH_DEV_TTY /dev/tty + _PATH_DEV_LOOP /dev/loop _PATH_SECURETTY /etc/securetty _PATH_WTMPLOCK /etc/wtmplock _PATH_HUSHLOGIN .hushlogin diff --git a/tests/helpers/test_pathnames.c b/tests/helpers/test_pathnames.c index 1accedec..5cc6efd7 100644 --- a/tests/helpers/test_pathnames.c +++ b/tests/helpers/test_pathnames.c @@ -33,7 +33,8 @@ struct hlpPath paths[] = { DEF_HLPPATH(_PATH_DEFPATH), DEF_HLPPATH(_PATH_DEFPATH_ROOT), - DEF_HLPPATH(_PATH_TTY), + DEF_HLPPATH(_PATH_DEV_TTY), + DEF_HLPPATH(_PATH_DEV_LOOP), DEF_HLPPATH(_PATH_SECURETTY), DEF_HLPPATH(_PATH_WTMPLOCK), DEF_HLPPATH(_PATH_HUSHLOGIN), -- cgit v1.2.3