From 4029d99a6ed58d3ace6e1bb67602b1a69271368b Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 3 Feb 2006 14:23:22 +0000 Subject: [PATCH] Add exported functions to set uid, gid and mode. [Bastian Blank] --- WHATS_NEW | 1 + dmsetup/dmsetup.c | 31 ++++++++++++++++++++++++++++++- lib/.exported_symbols | 3 +++ lib/ioctl/libdm-iface.c | 3 +++ lib/libdevmapper.h | 3 +++ lib/libdm-common.c | 21 +++++++++++++++++++++ 6 files changed, 61 insertions(+), 1 deletion(-) diff --git a/WHATS_NEW b/WHATS_NEW index 13ff876..f599a57 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 1.02.03 - ============================ + Add exported functions to set uid, gid and mode. Rename _log to dm_log and export. Add dm_tree_skip_lockfs. Fix dm_strdup debug definition. diff --git a/dmsetup/dmsetup.c b/dmsetup/dmsetup.c index 90c4b46..60421f8 100644 --- a/dmsetup/dmsetup.c +++ b/dmsetup/dmsetup.c @@ -86,8 +86,10 @@ enum { READ_ONLY = 0, COLS_ARG, EXEC_ARG, + GID_ARG, MAJOR_ARG, MINOR_ARG, + MODE_ARG, NOHEADINGS_ARG, NOLOCKFS_ARG, NOOPENCOUNT_ARG, @@ -95,6 +97,7 @@ enum { OPTIONS_ARG, TARGET_ARG, TREE_ARG, + UID_ARG, UUID_ARG, VERBOSE_ARG, VERSION_ARG, @@ -390,6 +393,15 @@ static int _create(int argc, char **argv, void *data) if (_switches[MINOR_ARG] && !dm_task_set_minor(dmt, _values[MINOR_ARG])) goto out; + if (_switches[UID_ARG] && !dm_task_set_uid(dmt, _values[UID_ARG])) + goto out; + + if (_switches[GID_ARG] && !dm_task_set_gid(dmt, _values[GID_ARG])) + goto out; + + if (_switches[MODE_ARG] && !dm_task_set_mode(dmt, _values[MODE_ARG])) + goto out; + if (_switches[NOOPENCOUNT_ARG] && !dm_task_no_open_count(dmt)) goto out; @@ -1293,6 +1305,7 @@ struct command { static struct command _commands[] = { {"create", " [-j|--major -m|--minor ]\n" + "\t [-U|--uid ] [-G|--gid ] [-M|--mode ]\n" "\t [-u|uuid ] [--notable] []", 1, 2, _create}, {"remove", "", 0, 1, _remove}, @@ -1419,8 +1432,10 @@ static int _process_switches(int *argc, char ***argv) {"readonly", 0, &ind, READ_ONLY}, {"columns", 0, &ind, COLS_ARG}, {"exec", 1, &ind, EXEC_ARG}, + {"gid", 1, &ind, GID_ARG}, {"major", 1, &ind, MAJOR_ARG}, {"minor", 1, &ind, MINOR_ARG}, + {"mode", 1, &ind, MODE_ARG}, {"noheadings", 0, &ind, NOHEADINGS_ARG}, {"nolockfs", 0, &ind, NOLOCKFS_ARG}, {"noopencount", 0, &ind, NOOPENCOUNT_ARG}, @@ -1428,6 +1443,7 @@ static int _process_switches(int *argc, char ***argv) {"options", 1, &ind, OPTIONS_ARG}, {"target", 1, &ind, TARGET_ARG}, {"tree", 0, &ind, TREE_ARG}, + {"uid", 1, &ind, UID_ARG}, {"uuid", 1, &ind, UUID_ARG}, {"verbose", 1, &ind, VERBOSE_ARG}, {"version", 0, &ind, VERSION_ARG}, @@ -1479,7 +1495,7 @@ static int _process_switches(int *argc, char ***argv) optarg = 0; optind = OPTIND_INIT; - while ((ind = -1, c = GETOPTLONG_FN(*argc, *argv, "cCj:m:no:ru:v", + while ((ind = -1, c = GETOPTLONG_FN(*argc, *argv, "cCGj:m:Mno:ru:Uv", long_options, NULL)) != -1) { if (c == 'c' || c == 'C' || ind == COLS_ARG) _switches[COLS_ARG]++; @@ -1505,6 +1521,19 @@ static int _process_switches(int *argc, char ***argv) _switches[UUID_ARG]++; _uuid = optarg; } + if (c == 'G' || ind == GID_ARG) { + _switches[GID_ARG]++; + _values[GID_ARG] = atoi(optarg); + } + if (c == 'U' || ind == UID_ARG) { + _switches[UID_ARG]++; + _values[UID_ARG] = atoi(optarg); + } + if (c == 'M' || ind == MODE_ARG) { + _switches[MODE_ARG]++; + /* FIXME Accept modes as per chmod */ + _values[MODE_ARG] = (int) strtol(optarg, NULL, 8); + } if ((ind == EXEC_ARG)) { _switches[EXEC_ARG]++; _command = optarg; diff --git a/lib/.exported_symbols b/lib/.exported_symbols index a513d6b..9b398f2 100644 --- a/lib/.exported_symbols +++ b/lib/.exported_symbols @@ -23,6 +23,9 @@ dm_task_set_major dm_task_set_minor dm_task_set_sector dm_task_set_message +dm_task_set_uid +dm_task_set_gid +dm_task_set_mode dm_task_suppress_identical_reload dm_task_add_target dm_task_no_open_count diff --git a/lib/ioctl/libdm-iface.c b/lib/ioctl/libdm-iface.c index 79f9d6f..31359b9 100644 --- a/lib/ioctl/libdm-iface.c +++ b/lib/ioctl/libdm-iface.c @@ -1311,6 +1311,9 @@ static int _create_and_load_v4(struct dm_task *dmt) task->major = dmt->major; task->minor = dmt->minor; + task->uid = dmt->uid; + task->gid = dmt->gid; + task->mode = dmt->mode; r = dm_task_run(task); dm_task_destroy(task); diff --git a/lib/libdevmapper.h b/lib/libdevmapper.h index e19c1f9..543cb7d 100644 --- a/lib/libdevmapper.h +++ b/lib/libdevmapper.h @@ -141,6 +141,9 @@ int dm_task_set_ro(struct dm_task *dmt); int dm_task_set_newname(struct dm_task *dmt, const char *newname); int dm_task_set_minor(struct dm_task *dmt, int minor); int dm_task_set_major(struct dm_task *dmt, int major); +int dm_task_set_uid(struct dm_task *dmt, uid_t uid); +int dm_task_set_gid(struct dm_task *dmt, gid_t gid); +int dm_task_set_mode(struct dm_task *dmt, mode_t mode); int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr); int dm_task_set_message(struct dm_task *dmt, const char *message); int dm_task_set_sector(struct dm_task *dmt, uint64_t sector); diff --git a/lib/libdm-common.c b/lib/libdm-common.c index df4eb78..c27c077 100644 --- a/lib/libdm-common.c +++ b/lib/libdm-common.c @@ -181,6 +181,27 @@ int dm_task_set_minor(struct dm_task *dmt, int minor) return 1; } +int dm_task_set_uid(struct dm_task *dmt, uid_t uid) +{ + dmt->uid = uid; + + return 1; +} + +int dm_task_set_gid(struct dm_task *dmt, gid_t gid) +{ + dmt->gid = gid; + + return 1; +} + +int dm_task_set_mode(struct dm_task *dmt, mode_t mode) +{ + dmt->mode = mode; + + return 1; +} + int dm_task_add_target(struct dm_task *dmt, uint64_t start, uint64_t size, const char *ttype, const char *params) { -- 2.43.5