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