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 {
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
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;
}
{ "--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 }
};