diff options
author | Andrew Stone <a@stne.dev> | 2021-11-11 13:45:47 -0800 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-23 09:44:35 +0100 |
commit | 7c5cef22115c1898cce8d501d912e2685c83e16e (patch) | |
tree | 1c9104060060327a70d8210965e211327e5dc8ac /src/core/automount.c | |
parent | f2ec9d2955da1e8631ad6c53e7076f963463f149 (diff) | |
download | systemd-7c5cef22115c1898cce8d501d912e2685c83e16e.tar.gz |
core/automount: Add ExtraOptions field
Diffstat (limited to 'src/core/automount.c')
-rw-r--r-- | src/core/automount.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/core/automount.c b/src/core/automount.c index 0bb58fdcd1..02089aed4e 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -19,6 +19,7 @@ #include "dbus-unit.h" #include "fd-util.h" #include "format-util.h" +#include "fstab-util.h" #include "io-util.h" #include "label.h" #include "mkdir-label.h" @@ -109,6 +110,7 @@ static void automount_done(Unit *u) { unmount_autofs(a); a->where = mfree(a->where); + a->extra_options = mfree(a->extra_options); a->tokens = set_free(a->tokens); a->expire_tokens = set_free(a->expire_tokens); @@ -168,6 +170,15 @@ static int automount_add_default_dependencies(Automount *a) { } static int automount_verify(Automount *a) { + static const char *const reserved_options[] = { + "fd\0", + "pgrp\0", + "minproto\0", + "maxproto\0", + "direct\0", + "indirect\0", + }; + _cleanup_free_ char *e = NULL; int r; @@ -184,6 +195,14 @@ static int automount_verify(Automount *a) { if (!unit_has_name(UNIT(a), e)) return log_unit_error_errno(UNIT(a), SYNTHETIC_ERRNO(ENOEXEC), "Where= setting doesn't match unit name. Refusing."); + for (size_t i = 0; i < ELEMENTSOF(reserved_options); i++) + if (fstab_test_option(a->extra_options, reserved_options[i])) + return log_unit_error_errno( + UNIT(a), + SYNTHETIC_ERRNO(ENOEXEC), + "ExtraOptions= setting may not contain reserved option %s.", + reserved_options[i]); + return 0; } @@ -313,11 +332,13 @@ static void automount_dump(Unit *u, FILE *f, const char *prefix) { "%sAutomount State: %s\n" "%sResult: %s\n" "%sWhere: %s\n" + "%sExtraOptions: %s\n" "%sDirectoryMode: %04o\n" "%sTimeoutIdleUSec: %s\n", prefix, automount_state_to_string(a->state), prefix, automount_result_to_string(a->result), prefix, a->where, + prefix, a->extra_options, prefix, a->directory_mode, prefix, FORMAT_TIMESPAN(a->timeout_idle_usec, USEC_PER_SEC)); } @@ -552,8 +573,7 @@ static void automount_enter_waiting(Automount *a) { _cleanup_close_ int ioctl_fd = -1; int p[2] = { -1, -1 }; char name[STRLEN("systemd-") + DECIMAL_STR_MAX(pid_t) + 1]; - char options[STRLEN("fd=,pgrp=,minproto=5,maxproto=5,direct") - + DECIMAL_STR_MAX(int) + DECIMAL_STR_MAX(gid_t) + 1]; + _cleanup_free_ char *options = NULL; bool mounted = false; int r, dev_autofs_fd; struct stat st; @@ -586,7 +606,17 @@ static void automount_enter_waiting(Automount *a) { if (r < 0) goto fail; - xsprintf(options, "fd=%i,pgrp="PID_FMT",minproto=5,maxproto=5,direct", p[1], getpgrp()); + if (asprintf( + &options, + "fd=%i,pgrp="PID_FMT",minproto=5,maxproto=5,direct%s%s", + p[1], + getpgrp(), + isempty(a->extra_options) ? "" : ",", + strempty(a->extra_options)) < 0) { + r = -ENOMEM; + goto fail; + } + xsprintf(name, "systemd-"PID_FMT, getpid_cached()); r = mount_nofollow(name, a->where, "autofs", 0, options); if (r < 0) |