]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/home/homed-home.h
homed: make sure our worker processes finish before we exit
[thirdparty/systemd.git] / src / home / homed-home.h
CommitLineData
70a5db58
LP
1/* SPDX-License-Identifier: LGPL-2.1+ */
2#pragma once
3
4typedef struct Home Home;
5
6#include "homed-manager.h"
7#include "homed-operation.h"
8#include "list.h"
9#include "ordered-set.h"
10#include "user-record.h"
11
12typedef enum HomeState {
13 HOME_UNFIXATED, /* home exists, but local record does not */
14 HOME_ABSENT, /* local record exists, but home does not */
15 HOME_INACTIVE, /* record and home exist, but is not logged in */
9be99f81 16 HOME_DIRTY, /* like HOME_INACTIVE, but the home directory wasn't cleanly deactivated */
70a5db58
LP
17 HOME_FIXATING, /* generating local record from home */
18 HOME_FIXATING_FOR_ACTIVATION, /* fixating in order to activate soon */
19 HOME_FIXATING_FOR_ACQUIRE, /* fixating because Acquire() was called */
20 HOME_ACTIVATING,
21 HOME_ACTIVATING_FOR_ACQUIRE, /* activating because Acquire() was called */
22 HOME_DEACTIVATING,
23 HOME_ACTIVE, /* logged in right now */
24 HOME_LOCKING,
25 HOME_LOCKED,
26 HOME_UNLOCKING,
27 HOME_UNLOCKING_FOR_ACQUIRE, /* unlocking because Acquire() was called */
28 HOME_CREATING,
29 HOME_REMOVING,
30 HOME_UPDATING,
31 HOME_UPDATING_WHILE_ACTIVE,
32 HOME_RESIZING,
33 HOME_RESIZING_WHILE_ACTIVE,
34 HOME_PASSWD,
35 HOME_PASSWD_WHILE_ACTIVE,
36 HOME_AUTHENTICATING,
37 HOME_AUTHENTICATING_WHILE_ACTIVE,
38 HOME_AUTHENTICATING_FOR_ACQUIRE, /* authenticating because Acquire() was called */
39 _HOME_STATE_MAX,
40 _HOME_STATE_INVALID = -1
41} HomeState;
42
43static inline bool HOME_STATE_IS_ACTIVE(HomeState state) {
44 return IN_SET(state,
45 HOME_ACTIVE,
46 HOME_UPDATING_WHILE_ACTIVE,
47 HOME_RESIZING_WHILE_ACTIVE,
48 HOME_PASSWD_WHILE_ACTIVE,
49 HOME_AUTHENTICATING_WHILE_ACTIVE,
50 HOME_AUTHENTICATING_FOR_ACQUIRE);
51}
52
53static inline bool HOME_STATE_IS_EXECUTING_OPERATION(HomeState state) {
54 return IN_SET(state,
55 HOME_FIXATING,
56 HOME_FIXATING_FOR_ACTIVATION,
57 HOME_FIXATING_FOR_ACQUIRE,
58 HOME_ACTIVATING,
59 HOME_ACTIVATING_FOR_ACQUIRE,
60 HOME_DEACTIVATING,
61 HOME_LOCKING,
62 HOME_UNLOCKING,
63 HOME_UNLOCKING_FOR_ACQUIRE,
64 HOME_CREATING,
65 HOME_REMOVING,
66 HOME_UPDATING,
67 HOME_UPDATING_WHILE_ACTIVE,
68 HOME_RESIZING,
69 HOME_RESIZING_WHILE_ACTIVE,
70 HOME_PASSWD,
71 HOME_PASSWD_WHILE_ACTIVE,
72 HOME_AUTHENTICATING,
73 HOME_AUTHENTICATING_WHILE_ACTIVE,
74 HOME_AUTHENTICATING_FOR_ACQUIRE);
75}
76
77struct Home {
78 Manager *manager;
79 char *user_name;
80 uid_t uid;
81
82 char *sysfs; /* When found via plugged in device, the sysfs path to it */
83
84 /* Note that the 'state' field is only set to a state while we are doing something (i.e. activating,
85 * deactivating, creating, removing, and such), or when the home is an "unfixated" one. When we are
86 * done with an operation we invalidate the state. This is hint for home_get_state() to check the
87 * state on request as needed from the mount table and similar.*/
88 HomeState state;
89 int signed_locally; /* signed only by us */
90
91 UserRecord *record;
92
93 pid_t worker_pid;
94 int worker_stdout_fd;
95 sd_event_source *worker_event_source;
96 int worker_error_code;
97
98 /* The message we are currently processing, and thus need to reply to on completion */
99 Operation *current_operation;
100
101 /* Stores the raw, plaintext passwords, but only for short periods of time */
102 UserRecord *secret;
103
18143cd7 104 /* When we create a home area and that fails, we should possibly unregister the record altogether
70a5db58
LP
105 * again, which is remembered in this boolean. */
106 bool unregister_on_failure;
107
108 /* The reading side of a FIFO stored in /run/systemd/home/, the writing side being used for reference
109 * counting. The references dropped to zero as soon as we see EOF. This concept exists twice: once
110 * for clients that are fine if we suspend the home directory on system suspend, and once for cliets
111 * that are not ok with that. This allows us to determine for each home whether there are any clients
112 * that support unsuspend. */
113 sd_event_source *ref_event_source_please_suspend;
114 sd_event_source *ref_event_source_dont_suspend;
115
116 /* Any pending operations we still need to execute. These are for operations we want to queue if we
117 * can't execute them right-away. */
118 OrderedSet *pending_operations;
119
120 /* A defer event source that processes pending acquire/release/eof events. We have a common
121 * dispatcher that processes all three kinds of events. */
122 sd_event_source *pending_event_source;
123
124 /* Did we send out a D-Bus notification about this entry? */
125 bool announced;
126
127 /* Used to coalesce bus PropertiesChanged events */
128 sd_event_source *deferred_change_event_source;
129};
130
131int home_new(Manager *m, UserRecord *hr, const char *sysfs, Home **ret);
132Home *home_free(Home *h);
133
134DEFINE_TRIVIAL_CLEANUP_FUNC(Home*, home_free);
135
136int home_set_record(Home *h, UserRecord *hr);
137int home_save_record(Home *h);
138int home_unlink_record(Home *h);
139
140int home_fixate(Home *h, UserRecord *secret, sd_bus_error *error);
141int home_activate(Home *h, UserRecord *secret, sd_bus_error *error);
142int home_authenticate(Home *h, UserRecord *secret, sd_bus_error *error);
143int home_deactivate(Home *h, bool force, sd_bus_error *error);
144int home_create(Home *h, UserRecord *secret, sd_bus_error *error);
145int home_remove(Home *h, sd_bus_error *error);
146int home_update(Home *h, UserRecord *new_record, sd_bus_error *error);
147int home_resize(Home *h, uint64_t disk_size, UserRecord *secret, sd_bus_error *error);
148int home_passwd(Home *h, UserRecord *new_secret, UserRecord *old_secret, sd_bus_error *error);
149int home_unregister(Home *h, sd_bus_error *error);
150int home_lock(Home *h, sd_bus_error *error);
151int home_unlock(Home *h, UserRecord *secret, sd_bus_error *error);
152
153HomeState home_get_state(Home *h);
154
155void home_process_notify(Home *h, char **l);
156
157int home_killall(Home *h);
158
159int home_augment_status(Home *h, UserRecordLoadFlags flags, UserRecord **ret);
160
161int home_create_fifo(Home *h, bool please_suspend);
162int home_schedule_operation(Home *h, Operation *o, sd_bus_error *error);
163
164int home_auto_login(Home *h, char ***ret_seats);
165
166int home_set_current_message(Home *h, sd_bus_message *m);
167
9796a9fb
LP
168int home_wait_for_worker(Home *h);
169
70a5db58
LP
170const char *home_state_to_string(HomeState state);
171HomeState home_state_from_string(const char *s);