From b0bb8fb6f9c3d54d230b785695a5bceab7e3f320 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 23 Nov 2010 20:39:55 +0100 Subject: libmount: fix utab file and dir modes, add new debug messages Signed-off-by: Karel Zak --- shlibs/mount/src/context.c | 18 ++++++++++++++---- shlibs/mount/src/context_mount.c | 4 ++++ shlibs/mount/src/tab_parse.c | 7 +++++-- shlibs/mount/src/tab_update.c | 3 ++- shlibs/mount/src/utils.c | 9 +++++++-- 5 files changed, 32 insertions(+), 9 deletions(-) (limited to 'shlibs/mount') diff --git a/shlibs/mount/src/context.c b/shlibs/mount/src/context.c index 2cc76a0ad..6ee68c16a 100644 --- a/shlibs/mount/src/context.c +++ b/shlibs/mount/src/context.c @@ -46,7 +46,7 @@ mnt_context *mnt_new_context() if (!cxt->mtab_writable) /* use /dev/.mount/utab if /etc/mtab is useless */ - mnt_has_regular_mtab(&cxt->utab_path, &cxt->utab_writable); + mnt_has_regular_utab(&cxt->utab_path, &cxt->utab_writable); return cxt; } @@ -1054,11 +1054,18 @@ int mnt_context_prepare_update(mnt_context *cxt) /* Don't try to touch mtab if umounting root FS */ cxt->flags |= MNT_FL_NOMTAB; - if ((cxt->flags & MNT_FL_NOMTAB) || cxt->helper) + if (cxt->flags & MNT_FL_NOMTAB) { + DBG(CXT, mnt_debug_h(cxt, "skip update: NOMTAB flag")); return 0; - if (!cxt->mtab_writable && !cxt->utab_writable) + } + if (cxt->helper) { + DBG(CXT, mnt_debug_h(cxt, "skip update: external helper")); return 0; - + } + if (!cxt->mtab_writable && !cxt->utab_writable) { + DBG(CXT, mnt_debug_h(cxt, "skip update: no writable destination")); + return 0; + } if (!cxt->update) { cxt->update = mnt_new_update(!cxt->mtab_writable); if (!cxt->update) @@ -1386,6 +1393,9 @@ int main(int argc, char *argv[]) { "--umount", test_umount, "[-t ] [-f][-l][-r] |" }, { NULL }}; + + umask(S_IWGRP|S_IWOTH); /* to be compatible with mount(8) */ + return mnt_run_test(tss, argc, argv); } diff --git a/shlibs/mount/src/context_mount.c b/shlibs/mount/src/context_mount.c index 7b0a9c126..960126d68 100644 --- a/shlibs/mount/src/context_mount.c +++ b/shlibs/mount/src/context_mount.c @@ -385,6 +385,8 @@ static int do_mount_by_pattern(mnt_context *cxt, const char *pattern) */ char *p, *p0; + DBG(CXT, mnt_debug_h(cxt, "tring mount by FS pattern list")); + p0 = p = strdup(pattern); if (!p) return -ENOMEM; @@ -405,6 +407,8 @@ static int do_mount_by_pattern(mnt_context *cxt, const char *pattern) /* * try /etc/filesystems and /proc/filesystems */ + DBG(CXT, mnt_debug_h(cxt, "tring mount by filesystems lists")); + rc = mnt_get_filesystems(&filesystems, neg ? pattern : NULL); if (rc) return rc; diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c index af5008328..21f64336c 100644 --- a/shlibs/mount/src/tab_parse.c +++ b/shlibs/mount/src/tab_parse.c @@ -631,6 +631,9 @@ int mnt_tab_parse_mtab(mnt_tab *tb, const char *filename) const char *utab = NULL; if (mnt_has_regular_mtab(&filename, NULL)) { + + DBG(TAB, mnt_debug_h(tb, "force %s usage", filename)); + rc = mnt_tab_parse_file(tb, filename); if (!rc) return 0; @@ -647,11 +650,11 @@ int mnt_tab_parse_mtab(mnt_tab *tb, const char *filename) return mnt_tab_parse_file(tb, _PATH_PROC_MOUNTS); /* - * try to read userspace specific information from /dev/.mount/utabs/ + * try to read userspace specific information from /dev/.mount/utabs */ utab = mnt_get_utab_path(); if (utab) { - mnt_tab *u_tb = mnt_new_tab_from_dir(utab); + mnt_tab *u_tb = mnt_new_tab_from_file(utab); if (u_tb) { mnt_fs *u_fs; diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c index 4b4f0addd..f9d4e5f06 100644 --- a/shlibs/mount/src/tab_update.c +++ b/shlibs/mount/src/tab_update.c @@ -458,7 +458,8 @@ static int utab_lock(const char *filename) DBG(UPDATE, mnt_debug("%s: locking", lfile)); - fd = open(lfile, O_RDONLY|O_CREAT|O_CLOEXEC, S_IRUSR|S_IWUSR); + fd = open(lfile, O_RDONLY|O_CREAT|O_CLOEXEC, S_IWUSR| + S_IRUSR|S_IRGRP|S_IROTH); free(lfile); if (fd < 0) diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c index 6af8d14f4..468b0bb3d 100644 --- a/shlibs/mount/src/utils.c +++ b/shlibs/mount/src/utils.c @@ -37,6 +37,8 @@ char *mnt_getenv_safe(const char *arg) { + return getenv(arg); + if ((getuid() != geteuid()) || (getgid() != getegid())) return NULL; #if HAVE_PRCTL @@ -510,7 +512,8 @@ static int try_write(const char *filename) if (!filename) return -EINVAL; - fd = open(filename, O_RDWR, 0644); + fd = open(filename, O_RDWR|O_CREAT, S_IWUSR| \ + S_IRUSR|S_IRGRP|S_IROTH); if (fd >= 0) { close(fd); return 0; @@ -612,7 +615,9 @@ int mnt_has_regular_utab(const char **utab, int *writable) stripoff_last_component(dirname); /* remove filename */ - rc = mkdir(dirname, 755); + rc = mkdir(dirname, S_IWUSR| + S_IRUSR|S_IRGRP|S_IROTH| + S_IXUSR|S_IXGRP|S_IXOTH); free(dirname); if (rc && errno != EEXIST) goto done; /* probably EACCES */ -- cgit v1.2.3-55-g7522