1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Add exported functions to set uid, gid and mode. [Bastian Blank]

This commit is contained in:
Alasdair Kergon 2006-02-03 14:23:22 +00:00
parent f0c9fe0105
commit b5d8ff1014
6 changed files with 61 additions and 1 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.03 - Version 1.02.03 -
============================ ============================
Add exported functions to set uid, gid and mode.
Rename _log to dm_log and export. Rename _log to dm_log and export.
Add dm_tree_skip_lockfs. Add dm_tree_skip_lockfs.
Fix dm_strdup debug definition. Fix dm_strdup debug definition.

View File

@ -23,6 +23,9 @@ dm_task_set_major
dm_task_set_minor dm_task_set_minor
dm_task_set_sector dm_task_set_sector
dm_task_set_message dm_task_set_message
dm_task_set_uid
dm_task_set_gid
dm_task_set_mode
dm_task_suppress_identical_reload dm_task_suppress_identical_reload
dm_task_add_target dm_task_add_target
dm_task_no_open_count dm_task_no_open_count

View File

@ -1311,6 +1311,9 @@ static int _create_and_load_v4(struct dm_task *dmt)
task->major = dmt->major; task->major = dmt->major;
task->minor = dmt->minor; task->minor = dmt->minor;
task->uid = dmt->uid;
task->gid = dmt->gid;
task->mode = dmt->mode;
r = dm_task_run(task); r = dm_task_run(task);
dm_task_destroy(task); dm_task_destroy(task);

View File

@ -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_newname(struct dm_task *dmt, const char *newname);
int dm_task_set_minor(struct dm_task *dmt, int minor); 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_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_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_message(struct dm_task *dmt, const char *message);
int dm_task_set_sector(struct dm_task *dmt, uint64_t sector); int dm_task_set_sector(struct dm_task *dmt, uint64_t sector);

View File

@ -181,6 +181,27 @@ int dm_task_set_minor(struct dm_task *dmt, int minor)
return 1; 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, int dm_task_add_target(struct dm_task *dmt, uint64_t start, uint64_t size,
const char *ttype, const char *params) const char *ttype, const char *params)
{ {

View File

@ -86,8 +86,10 @@ enum {
READ_ONLY = 0, READ_ONLY = 0,
COLS_ARG, COLS_ARG,
EXEC_ARG, EXEC_ARG,
GID_ARG,
MAJOR_ARG, MAJOR_ARG,
MINOR_ARG, MINOR_ARG,
MODE_ARG,
NOHEADINGS_ARG, NOHEADINGS_ARG,
NOLOCKFS_ARG, NOLOCKFS_ARG,
NOOPENCOUNT_ARG, NOOPENCOUNT_ARG,
@ -95,6 +97,7 @@ enum {
OPTIONS_ARG, OPTIONS_ARG,
TARGET_ARG, TARGET_ARG,
TREE_ARG, TREE_ARG,
UID_ARG,
UUID_ARG, UUID_ARG,
VERBOSE_ARG, VERBOSE_ARG,
VERSION_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])) if (_switches[MINOR_ARG] && !dm_task_set_minor(dmt, _values[MINOR_ARG]))
goto out; 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)) if (_switches[NOOPENCOUNT_ARG] && !dm_task_no_open_count(dmt))
goto out; goto out;
@ -1293,6 +1305,7 @@ struct command {
static struct command _commands[] = { static struct command _commands[] = {
{"create", "<dev_name> [-j|--major <major> -m|--minor <minor>]\n" {"create", "<dev_name> [-j|--major <major> -m|--minor <minor>]\n"
"\t [-U|--uid <uid>] [-G|--gid <gid>] [-M|--mode <octal_mode>]\n"
"\t [-u|uuid <uuid>] [--notable] [<table_file>]", "\t [-u|uuid <uuid>] [--notable] [<table_file>]",
1, 2, _create}, 1, 2, _create},
{"remove", "<device>", 0, 1, _remove}, {"remove", "<device>", 0, 1, _remove},
@ -1419,8 +1432,10 @@ static int _process_switches(int *argc, char ***argv)
{"readonly", 0, &ind, READ_ONLY}, {"readonly", 0, &ind, READ_ONLY},
{"columns", 0, &ind, COLS_ARG}, {"columns", 0, &ind, COLS_ARG},
{"exec", 1, &ind, EXEC_ARG}, {"exec", 1, &ind, EXEC_ARG},
{"gid", 1, &ind, GID_ARG},
{"major", 1, &ind, MAJOR_ARG}, {"major", 1, &ind, MAJOR_ARG},
{"minor", 1, &ind, MINOR_ARG}, {"minor", 1, &ind, MINOR_ARG},
{"mode", 1, &ind, MODE_ARG},
{"noheadings", 0, &ind, NOHEADINGS_ARG}, {"noheadings", 0, &ind, NOHEADINGS_ARG},
{"nolockfs", 0, &ind, NOLOCKFS_ARG}, {"nolockfs", 0, &ind, NOLOCKFS_ARG},
{"noopencount", 0, &ind, NOOPENCOUNT_ARG}, {"noopencount", 0, &ind, NOOPENCOUNT_ARG},
@ -1428,6 +1443,7 @@ static int _process_switches(int *argc, char ***argv)
{"options", 1, &ind, OPTIONS_ARG}, {"options", 1, &ind, OPTIONS_ARG},
{"target", 1, &ind, TARGET_ARG}, {"target", 1, &ind, TARGET_ARG},
{"tree", 0, &ind, TREE_ARG}, {"tree", 0, &ind, TREE_ARG},
{"uid", 1, &ind, UID_ARG},
{"uuid", 1, &ind, UUID_ARG}, {"uuid", 1, &ind, UUID_ARG},
{"verbose", 1, &ind, VERBOSE_ARG}, {"verbose", 1, &ind, VERBOSE_ARG},
{"version", 0, &ind, VERSION_ARG}, {"version", 0, &ind, VERSION_ARG},
@ -1479,7 +1495,7 @@ static int _process_switches(int *argc, char ***argv)
optarg = 0; optarg = 0;
optind = OPTIND_INIT; 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) { long_options, NULL)) != -1) {
if (c == 'c' || c == 'C' || ind == COLS_ARG) if (c == 'c' || c == 'C' || ind == COLS_ARG)
_switches[COLS_ARG]++; _switches[COLS_ARG]++;
@ -1505,6 +1521,19 @@ static int _process_switches(int *argc, char ***argv)
_switches[UUID_ARG]++; _switches[UUID_ARG]++;
_uuid = optarg; _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)) { if ((ind == EXEC_ARG)) {
_switches[EXEC_ARG]++; _switches[EXEC_ARG]++;
_command = optarg; _command = optarg;