diff options
author | Karel Zak <kzak@redhat.com> | 2010-09-27 12:14:41 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2011-01-03 12:28:43 +0100 |
commit | 4796b46d69f30237db0a0788b4df511d3112a0b8 (patch) | |
tree | 39d0a13b79f1392f24ee245dc75abba8a2b05ba8 /shlibs | |
parent | 66b8b8cd774978f1c885464a51ca1492e6459f2d (diff) | |
download | util-linux-old-4796b46d69f30237db0a0788b4df511d3112a0b8.tar.gz |
libmount: add mnt_optstr_fix_user
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs')
-rw-r--r-- | shlibs/mount/src/mount.h.in | 1 | ||||
-rw-r--r-- | shlibs/mount/src/mount.sym | 1 | ||||
-rw-r--r-- | shlibs/mount/src/optstr.c | 42 |
3 files changed, 43 insertions, 1 deletions
diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in index ac69ac55..37ff3366 100644 --- a/shlibs/mount/src/mount.h.in +++ b/shlibs/mount/src/mount.h.in @@ -177,6 +177,7 @@ extern int mnt_optstr_apply_flags(char **optstr, unsigned long flags, extern int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next); extern int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next); extern int mnt_optstr_fix_secontext(char **optstr, char *value, size_t valsz, char **next); +extern int mnt_optstr_fix_user(char **optstr, char *value, size_t valsz, char **next); /* iter.c */ enum { diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym index 308abcde..bb3ac242 100644 --- a/shlibs/mount/src/mount.sym +++ b/shlibs/mount/src/mount.sym @@ -82,6 +82,7 @@ global: mnt_optstr_fix_gid; mnt_optstr_fix_selinux; mnt_optstr_fix_uid; + mnt_optstr_fix_user; mnt_optstr_apply_flags; mnt_optstr_get_flags; mnt_parse_version_string; diff --git a/shlibs/mount/src/optstr.c b/shlibs/mount/src/optstr.c index 0cfcd513..dd8b5451 100644 --- a/shlibs/mount/src/optstr.c +++ b/shlibs/mount/src/optstr.c @@ -849,6 +849,43 @@ int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next) return rc; } +/** + * mnt_optstr_fix_user: + * @optstr: string with comma separated list of options + * @value: pointer to place where has to start the value + * @valsz: size of the value or zero if value not define + * @next: returns pointer to the next option (optional argument) + + * Add/replace username. This is usually used to convert "user" (without value) + * to to "user=<username>" -- in this case the @value has to pointer behind the + * "user" option name; in case you want to replace already defined <username> + * then the @valsz must be greater than zero. + * + * Returns: 0 on success, negative number in case of error. + */ +int mnt_optstr_fix_user(char **optstr, char *value, size_t valsz, char **next) +{ + char *username; + int rc = 0; + + if (!optstr || !value) + return -EINVAL; + + username = mnt_get_username(getuid()); + if (!username) + return -ENOMEM; + + if (!valsz || strncmp(value, username, valsz)) { + if (valsz) + /* remove old value */ + mnt_optstr_remove_option_at(optstr, value, value + valsz); + + rc = insert_substring(optstr, value, username, next); + } + + free(username); + return rc; +} #ifdef TEST_PROGRAM @@ -1061,6 +1098,9 @@ int test_fix(struct mtest *ts, int argc, char *argv[]) rc = mnt_optstr_fix_gid(&optstr, val, valsz, &next); else if (!strncmp(name, "context", 7)) rc = mnt_optstr_fix_secontext(&optstr, val, valsz, &next); + else if (!strncmp(name, "user", 4)) + rc = mnt_optstr_fix_user(&optstr, + val ? val : name + namesz, valsz, &next); if (rc) break; } @@ -1083,7 +1123,7 @@ int main(int argc, char *argv[]) { "--split", test_split, "<optstr> split into FS, VFS and userspace" }, { "--flags", test_flags, "<optstr> convert options to MS_* flags" }, { "--apply", test_apply, "--{linux,user} <optstr> <mask> apply mask to optstr" }, - { "--fix", test_fix, "<optstr> fix uid=, gid= and context=" }, + { "--fix", test_fix, "<optstr> fix uid=, gid=, user, and context=" }, { NULL } }; |