1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 typedef struct ExecStatus ExecStatus
;
5 typedef struct ExecCommand ExecCommand
;
6 typedef struct ExecContext ExecContext
;
7 typedef struct ExecRuntime ExecRuntime
;
8 typedef struct ExecParameters ExecParameters
;
9 typedef struct Manager Manager
;
14 #include <sys/capability.h>
16 #include "cgroup-util.h"
20 #include "namespace.h"
23 #define EXEC_STDIN_DATA_MAX (64U*1024U*1024U)
25 typedef enum ExecUtmpMode
{
30 _EXEC_UTMP_MODE_INVALID
= -1
33 typedef enum ExecInput
{
43 _EXEC_INPUT_INVALID
= -1
46 typedef enum ExecOutput
{
51 EXEC_OUTPUT_SYSLOG_AND_CONSOLE
,
53 EXEC_OUTPUT_KMSG_AND_CONSOLE
,
55 EXEC_OUTPUT_JOURNAL_AND_CONSOLE
,
60 _EXEC_OUTPUT_INVALID
= -1
63 typedef enum ExecPreserveMode
{
66 EXEC_PRESERVE_RESTART
,
67 _EXEC_PRESERVE_MODE_MAX
,
68 _EXEC_PRESERVE_MODE_INVALID
= -1
71 typedef enum ExecKeyringMode
{
75 _EXEC_KEYRING_MODE_MAX
,
76 _EXEC_KEYRING_MODE_INVALID
= -1,
80 dual_timestamp start_timestamp
;
81 dual_timestamp exit_timestamp
;
83 int code
; /* as in siginfo_t::si_code */
84 int status
; /* as in sigingo_t::si_status */
87 typedef enum ExecCommandFlags
{
88 EXEC_COMMAND_IGNORE_FAILURE
= 1,
89 EXEC_COMMAND_FULLY_PRIVILEGED
= 2,
90 EXEC_COMMAND_NO_SETUID
= 4,
91 EXEC_COMMAND_AMBIENT_MAGIC
= 8,
97 ExecStatus exec_status
;
98 ExecCommandFlags flags
;
99 LIST_FIELDS(ExecCommand
, command
); /* useful for chaining commands */
107 /* unit id of the owner */
113 /* An AF_UNIX socket pair, that contains a datagram containing a file descriptor referring to the network
115 int netns_storage_socket
[2];
118 typedef enum ExecDirectoryType
{
119 EXEC_DIRECTORY_RUNTIME
= 0,
120 EXEC_DIRECTORY_STATE
,
121 EXEC_DIRECTORY_CACHE
,
123 EXEC_DIRECTORY_CONFIGURATION
,
124 _EXEC_DIRECTORY_TYPE_MAX
,
125 _EXEC_DIRECTORY_TYPE_INVALID
= -1,
128 typedef struct ExecDirectory
{
135 char **environment_files
;
136 char **pass_environment
;
137 char **unset_environment
;
139 struct rlimit
*rlimit
[_RLIMIT_MAX
];
140 char *working_directory
, *root_directory
, *root_image
;
141 bool working_directory_missing_ok
;
142 bool working_directory_home
;
145 int oom_score_adjust
;
148 int cpu_sched_policy
;
149 int cpu_sched_priority
;
152 unsigned cpuset_ncpus
;
155 ExecOutput std_output
;
156 ExecOutput std_error
;
157 char *stdio_fdname
[3];
161 size_t stdin_data_size
;
163 nsec_t timer_slack_nsec
;
171 bool tty_vt_disallocate
;
175 /* Since resolving these names might involve socket
176 * connections and we don't want to deadlock ourselves these
177 * names are resolved on execution only and in the child
181 char **supplementary_groups
;
186 ExecUtmpMode utmp_mode
;
188 bool selinux_context_ignore
;
189 char *selinux_context
;
191 bool apparmor_profile_ignore
;
192 char *apparmor_profile
;
194 bool smack_process_label_ignore
;
195 char *smack_process_label
;
197 ExecKeyringMode keyring_mode
;
199 char **read_write_paths
, **read_only_paths
, **inaccessible_paths
;
200 unsigned long mount_flags
;
201 BindMount
*bind_mounts
;
202 size_t n_bind_mounts
;
203 TemporaryFileSystem
*temporary_filesystems
;
204 size_t n_temporary_filesystems
;
206 uint64_t capability_bounding_set
;
207 uint64_t capability_ambient_set
;
211 char *syslog_identifier
;
212 bool syslog_level_prefix
;
216 struct iovec
* log_extra_fields
;
217 size_t n_log_extra_fields
;
219 bool cpu_sched_reset_on_fork
;
222 bool private_network
;
223 bool private_devices
;
226 ProtectSystem protect_system
;
227 ProtectHome protect_home
;
228 bool protect_kernel_tunables
;
229 bool protect_kernel_modules
;
230 bool protect_control_groups
;
233 bool no_new_privileges
;
238 /* This is not exposed to the user but available
239 * internally. We need it to make sure that whenever we spawn
240 * /usr/bin/mount it is run in the same process group as us so
241 * that the autofs logic detects that it belongs to us and we
242 * don't enter a trigger loop. */
245 unsigned long personality
;
246 bool lock_personality
;
248 unsigned long restrict_namespaces
; /* The CLONE_NEWxyz flags permitted to the unit's processes */
250 Hashmap
*syscall_filter
;
253 bool syscall_whitelist
:1;
255 Set
*address_families
;
256 bool address_families_whitelist
:1;
258 ExecPreserveMode runtime_directory_preserve_mode
;
259 ExecDirectory directories
[_EXEC_DIRECTORY_TYPE_MAX
];
261 bool memory_deny_write_execute
;
262 bool restrict_realtime
;
264 bool oom_score_adjust_set
:1;
267 bool cpu_sched_set
:1;
270 static inline bool exec_context_restrict_namespaces_set(const ExecContext
*c
) {
273 return (c
->restrict_namespaces
& NAMESPACE_FLAGS_ALL
) != NAMESPACE_FLAGS_ALL
;
276 typedef enum ExecFlags
{
277 EXEC_APPLY_SANDBOXING
= 1 << 0,
278 EXEC_APPLY_CHROOT
= 1 << 1,
279 EXEC_APPLY_TTY_STDIN
= 1 << 2,
280 EXEC_NEW_KEYRING
= 1 << 3,
281 EXEC_PASS_LOG_UNIT
= 1 << 4, /* Whether to pass the unit name to the service's journal stream connection */
282 EXEC_CHOWN_DIRECTORIES
= 1 << 5, /* chown() the runtime/state/cache/log directories to the user we run as, under all conditions */
283 EXEC_NSS_BYPASS_BUS
= 1 << 6, /* Set the SYSTEMD_NSS_BYPASS_BUS environment variable, to disable nss-systemd for dbus */
284 EXEC_CGROUP_DELEGATE
= 1 << 7,
286 /* The following are not used by execute.c, but by consumers internally */
287 EXEC_PASS_FDS
= 1 << 8,
288 EXEC_IS_CONTROL
= 1 << 9,
289 EXEC_SETENV_RESULT
= 1 << 10,
290 EXEC_SET_WATCHDOG
= 1 << 11,
293 struct ExecParameters
{
299 size_t n_storage_fds
;
303 bool selinux_context_net
:1;
305 CGroupMask cgroup_supported
;
306 const char *cgroup_path
;
310 const char *confirm_spawn
;
312 usec_t watchdog_usec
;
322 #include "dynamic-user.h"
324 int exec_spawn(Unit
*unit
,
325 ExecCommand
*command
,
326 const ExecContext
*context
,
327 const ExecParameters
*exec_params
,
328 ExecRuntime
*runtime
,
329 DynamicCreds
*dynamic_creds
,
332 void exec_command_done_array(ExecCommand
*c
, size_t n
);
334 ExecCommand
* exec_command_free_list(ExecCommand
*c
);
335 void exec_command_free_array(ExecCommand
**c
, size_t n
);
337 void exec_command_dump_list(ExecCommand
*c
, FILE *f
, const char *prefix
);
338 void exec_command_append_list(ExecCommand
**l
, ExecCommand
*e
);
339 int exec_command_set(ExecCommand
*c
, const char *path
, ...);
340 int exec_command_append(ExecCommand
*c
, const char *path
, ...);
342 void exec_context_init(ExecContext
*c
);
343 void exec_context_done(ExecContext
*c
);
344 void exec_context_dump(const ExecContext
*c
, FILE* f
, const char *prefix
);
346 int exec_context_destroy_runtime_directory(const ExecContext
*c
, const char *runtime_root
);
348 const char* exec_context_fdname(const ExecContext
*c
, int fd_index
);
350 bool exec_context_may_touch_console(const ExecContext
*c
);
351 bool exec_context_maintains_privileges(const ExecContext
*c
);
353 int exec_context_get_effective_ioprio(const ExecContext
*c
);
355 void exec_context_free_log_extra_fields(ExecContext
*c
);
357 void exec_status_start(ExecStatus
*s
, pid_t pid
);
358 void exec_status_exit(ExecStatus
*s
, const ExecContext
*context
, pid_t pid
, int code
, int status
);
359 void exec_status_dump(const ExecStatus
*s
, FILE *f
, const char *prefix
);
361 int exec_runtime_acquire(Manager
*m
, const ExecContext
*c
, const char *name
, bool create
, ExecRuntime
**ret
);
362 ExecRuntime
*exec_runtime_unref(ExecRuntime
*r
, bool destroy
);
364 int exec_runtime_serialize(const Manager
*m
, FILE *f
, FDSet
*fds
);
365 int exec_runtime_deserialize_compat(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
);
366 void exec_runtime_deserialize_one(Manager
*m
, const char *value
, FDSet
*fds
);
367 void exec_runtime_vacuum(Manager
*m
);
369 const char* exec_output_to_string(ExecOutput i
) _const_
;
370 ExecOutput
exec_output_from_string(const char *s
) _pure_
;
372 const char* exec_input_to_string(ExecInput i
) _const_
;
373 ExecInput
exec_input_from_string(const char *s
) _pure_
;
375 const char* exec_utmp_mode_to_string(ExecUtmpMode i
) _const_
;
376 ExecUtmpMode
exec_utmp_mode_from_string(const char *s
) _pure_
;
378 const char* exec_preserve_mode_to_string(ExecPreserveMode i
) _const_
;
379 ExecPreserveMode
exec_preserve_mode_from_string(const char *s
) _pure_
;
381 const char* exec_keyring_mode_to_string(ExecKeyringMode i
) _const_
;
382 ExecKeyringMode
exec_keyring_mode_from_string(const char *s
) _pure_
;
384 const char* exec_directory_type_to_string(ExecDirectoryType i
) _const_
;
385 ExecDirectoryType
exec_directory_type_from_string(const char *s
) _pure_
;