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
,
59 EXEC_OUTPUT_FILE_APPEND
,
61 _EXEC_OUTPUT_INVALID
= -1
64 typedef enum ExecPreserveMode
{
67 EXEC_PRESERVE_RESTART
,
68 _EXEC_PRESERVE_MODE_MAX
,
69 _EXEC_PRESERVE_MODE_INVALID
= -1
72 typedef enum ExecKeyringMode
{
76 _EXEC_KEYRING_MODE_MAX
,
77 _EXEC_KEYRING_MODE_INVALID
= -1,
81 dual_timestamp start_timestamp
;
82 dual_timestamp exit_timestamp
;
84 int code
; /* as in siginfo_t::si_code */
85 int status
; /* as in sigingo_t::si_status */
88 typedef enum ExecCommandFlags
{
89 EXEC_COMMAND_IGNORE_FAILURE
= 1 << 0,
90 EXEC_COMMAND_FULLY_PRIVILEGED
= 1 << 1,
91 EXEC_COMMAND_NO_SETUID
= 1 << 2,
92 EXEC_COMMAND_AMBIENT_MAGIC
= 1 << 3,
98 ExecStatus exec_status
;
99 ExecCommandFlags flags
;
100 LIST_FIELDS(ExecCommand
, command
); /* useful for chaining commands */
108 /* unit id of the owner */
114 /* An AF_UNIX socket pair, that contains a datagram containing a file descriptor referring to the network
116 int netns_storage_socket
[2];
119 typedef enum ExecDirectoryType
{
120 EXEC_DIRECTORY_RUNTIME
= 0,
121 EXEC_DIRECTORY_STATE
,
122 EXEC_DIRECTORY_CACHE
,
124 EXEC_DIRECTORY_CONFIGURATION
,
125 _EXEC_DIRECTORY_TYPE_MAX
,
126 _EXEC_DIRECTORY_TYPE_INVALID
= -1,
129 typedef struct ExecDirectory
{
136 char **environment_files
;
137 char **pass_environment
;
138 char **unset_environment
;
140 struct rlimit
*rlimit
[_RLIMIT_MAX
];
141 char *working_directory
, *root_directory
, *root_image
;
142 bool working_directory_missing_ok
;
143 bool working_directory_home
;
146 int oom_score_adjust
;
149 int cpu_sched_policy
;
150 int cpu_sched_priority
;
153 unsigned cpuset_ncpus
;
156 ExecOutput std_output
;
157 ExecOutput std_error
;
158 char *stdio_fdname
[3];
162 size_t stdin_data_size
;
164 nsec_t timer_slack_nsec
;
172 bool tty_vt_disallocate
;
176 /* Since resolving these names might involve socket
177 * connections and we don't want to deadlock ourselves these
178 * names are resolved on execution only and in the child
182 char **supplementary_groups
;
187 ExecUtmpMode utmp_mode
;
189 bool selinux_context_ignore
;
190 char *selinux_context
;
192 bool apparmor_profile_ignore
;
193 char *apparmor_profile
;
195 bool smack_process_label_ignore
;
196 char *smack_process_label
;
198 ExecKeyringMode keyring_mode
;
200 char **read_write_paths
, **read_only_paths
, **inaccessible_paths
;
201 unsigned long mount_flags
;
202 BindMount
*bind_mounts
;
203 size_t n_bind_mounts
;
204 TemporaryFileSystem
*temporary_filesystems
;
205 size_t n_temporary_filesystems
;
207 uint64_t capability_bounding_set
;
208 uint64_t capability_ambient_set
;
212 char *syslog_identifier
;
213 bool syslog_level_prefix
;
217 struct iovec
* log_extra_fields
;
218 size_t n_log_extra_fields
;
220 bool cpu_sched_reset_on_fork
;
223 bool private_network
;
224 bool private_devices
;
227 ProtectSystem protect_system
;
228 ProtectHome protect_home
;
229 bool protect_kernel_tunables
;
230 bool protect_kernel_modules
;
231 bool protect_control_groups
;
234 bool no_new_privileges
;
239 /* This is not exposed to the user but available
240 * internally. We need it to make sure that whenever we spawn
241 * /usr/bin/mount it is run in the same process group as us so
242 * that the autofs logic detects that it belongs to us and we
243 * don't enter a trigger loop. */
246 unsigned long personality
;
247 bool lock_personality
;
249 unsigned long restrict_namespaces
; /* The CLONE_NEWxyz flags permitted to the unit's processes */
251 Hashmap
*syscall_filter
;
254 bool syscall_whitelist
:1;
256 Set
*address_families
;
257 bool address_families_whitelist
:1;
259 ExecPreserveMode runtime_directory_preserve_mode
;
260 ExecDirectory directories
[_EXEC_DIRECTORY_TYPE_MAX
];
262 bool memory_deny_write_execute
;
263 bool restrict_realtime
;
265 bool oom_score_adjust_set
:1;
268 bool cpu_sched_set
:1;
271 static inline bool exec_context_restrict_namespaces_set(const ExecContext
*c
) {
274 return (c
->restrict_namespaces
& NAMESPACE_FLAGS_ALL
) != NAMESPACE_FLAGS_ALL
;
277 typedef enum ExecFlags
{
278 EXEC_APPLY_SANDBOXING
= 1 << 0,
279 EXEC_APPLY_CHROOT
= 1 << 1,
280 EXEC_APPLY_TTY_STDIN
= 1 << 2,
281 EXEC_NEW_KEYRING
= 1 << 3,
282 EXEC_PASS_LOG_UNIT
= 1 << 4, /* Whether to pass the unit name to the service's journal stream connection */
283 EXEC_CHOWN_DIRECTORIES
= 1 << 5, /* chown() the runtime/state/cache/log directories to the user we run as, under all conditions */
284 EXEC_NSS_BYPASS_BUS
= 1 << 6, /* Set the SYSTEMD_NSS_BYPASS_BUS environment variable, to disable nss-systemd for dbus */
285 EXEC_CGROUP_DELEGATE
= 1 << 7,
287 /* The following are not used by execute.c, but by consumers internally */
288 EXEC_PASS_FDS
= 1 << 8,
289 EXEC_IS_CONTROL
= 1 << 9,
290 EXEC_SETENV_RESULT
= 1 << 10,
291 EXEC_SET_WATCHDOG
= 1 << 11,
294 struct ExecParameters
{
301 size_t n_storage_fds
;
304 bool selinux_context_net
:1;
306 CGroupMask cgroup_supported
;
307 const char *cgroup_path
;
311 const char *confirm_spawn
;
313 usec_t watchdog_usec
;
321 /* An fd that is closed by the execve(), and thus will result in EOF when the execve() is done */
326 #include "dynamic-user.h"
328 int exec_spawn(Unit
*unit
,
329 ExecCommand
*command
,
330 const ExecContext
*context
,
331 const ExecParameters
*exec_params
,
332 ExecRuntime
*runtime
,
333 DynamicCreds
*dynamic_creds
,
336 void exec_command_done_array(ExecCommand
*c
, size_t n
);
338 ExecCommand
* exec_command_free_list(ExecCommand
*c
);
339 void exec_command_free_array(ExecCommand
**c
, size_t n
);
341 void exec_command_dump_list(ExecCommand
*c
, FILE *f
, const char *prefix
);
342 void exec_command_append_list(ExecCommand
**l
, ExecCommand
*e
);
343 int exec_command_set(ExecCommand
*c
, const char *path
, ...);
344 int exec_command_append(ExecCommand
*c
, const char *path
, ...);
346 void exec_context_init(ExecContext
*c
);
347 void exec_context_done(ExecContext
*c
);
348 void exec_context_dump(const ExecContext
*c
, FILE* f
, const char *prefix
);
350 int exec_context_destroy_runtime_directory(const ExecContext
*c
, const char *runtime_root
);
352 const char* exec_context_fdname(const ExecContext
*c
, int fd_index
);
354 bool exec_context_may_touch_console(const ExecContext
*c
);
355 bool exec_context_maintains_privileges(const ExecContext
*c
);
357 int exec_context_get_effective_ioprio(const ExecContext
*c
);
359 void exec_context_free_log_extra_fields(ExecContext
*c
);
361 void exec_status_start(ExecStatus
*s
, pid_t pid
);
362 void exec_status_exit(ExecStatus
*s
, const ExecContext
*context
, pid_t pid
, int code
, int status
);
363 void exec_status_dump(const ExecStatus
*s
, FILE *f
, const char *prefix
);
365 int exec_runtime_acquire(Manager
*m
, const ExecContext
*c
, const char *name
, bool create
, ExecRuntime
**ret
);
366 ExecRuntime
*exec_runtime_unref(ExecRuntime
*r
, bool destroy
);
368 int exec_runtime_serialize(const Manager
*m
, FILE *f
, FDSet
*fds
);
369 int exec_runtime_deserialize_compat(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
);
370 void exec_runtime_deserialize_one(Manager
*m
, const char *value
, FDSet
*fds
);
371 void exec_runtime_vacuum(Manager
*m
);
373 const char* exec_output_to_string(ExecOutput i
) _const_
;
374 ExecOutput
exec_output_from_string(const char *s
) _pure_
;
376 const char* exec_input_to_string(ExecInput i
) _const_
;
377 ExecInput
exec_input_from_string(const char *s
) _pure_
;
379 const char* exec_utmp_mode_to_string(ExecUtmpMode i
) _const_
;
380 ExecUtmpMode
exec_utmp_mode_from_string(const char *s
) _pure_
;
382 const char* exec_preserve_mode_to_string(ExecPreserveMode i
) _const_
;
383 ExecPreserveMode
exec_preserve_mode_from_string(const char *s
) _pure_
;
385 const char* exec_keyring_mode_to_string(ExecKeyringMode i
) _const_
;
386 ExecKeyringMode
exec_keyring_mode_from_string(const char *s
) _pure_
;
388 const char* exec_directory_type_to_string(ExecDirectoryType i
) _const_
;
389 ExecDirectoryType
exec_directory_type_from_string(const char *s
) _pure_
;