1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 typedef struct Home Home
;
6 #include "homed-manager.h"
7 #include "homed-operation.h"
9 #include "ordered-set.h"
10 #include "user-record.h"
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_DIRTY
, /* like HOME_INACTIVE, but the home directory wasn't cleanly deactivated */
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 */
21 HOME_ACTIVATING_FOR_ACQUIRE
, /* activating because Acquire() was called */
23 HOME_ACTIVE
, /* logged in right now */
27 HOME_UNLOCKING_FOR_ACQUIRE
, /* unlocking because Acquire() was called */
31 HOME_UPDATING_WHILE_ACTIVE
,
33 HOME_RESIZING_WHILE_ACTIVE
,
35 HOME_PASSWD_WHILE_ACTIVE
,
37 HOME_AUTHENTICATING_WHILE_ACTIVE
,
38 HOME_AUTHENTICATING_FOR_ACQUIRE
, /* authenticating because Acquire() was called */
40 _HOME_STATE_INVALID
= -1
43 static inline bool HOME_STATE_IS_ACTIVE(HomeState state
) {
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
);
53 static inline bool HOME_STATE_IS_EXECUTING_OPERATION(HomeState state
) {
56 HOME_FIXATING_FOR_ACTIVATION
,
57 HOME_FIXATING_FOR_ACQUIRE
,
59 HOME_ACTIVATING_FOR_ACQUIRE
,
63 HOME_UNLOCKING_FOR_ACQUIRE
,
67 HOME_UPDATING_WHILE_ACTIVE
,
69 HOME_RESIZING_WHILE_ACTIVE
,
71 HOME_PASSWD_WHILE_ACTIVE
,
73 HOME_AUTHENTICATING_WHILE_ACTIVE
,
74 HOME_AUTHENTICATING_FOR_ACQUIRE
);
82 char *sysfs
; /* When found via plugged in device, the sysfs path to it */
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.*/
89 int signed_locally
; /* signed only by us */
95 sd_event_source
*worker_event_source
;
96 int worker_error_code
;
98 /* The message we are currently processing, and thus need to reply to on completion */
99 Operation
*current_operation
;
101 /* Stores the raw, plaintext passwords, but only for short periods of time */
104 /* When we create a home area and that fails, we should possibly unregister the record altogether
105 * again, which is remembered in this boolean. */
106 bool unregister_on_failure
;
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
;
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
;
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
;
124 /* Did we send out a D-Bus notification about this entry? */
127 /* Used to coalesce bus PropertiesChanged events */
128 sd_event_source
*deferred_change_event_source
;
131 int home_new(Manager
*m
, UserRecord
*hr
, const char *sysfs
, Home
**ret
);
132 Home
*home_free(Home
*h
);
134 DEFINE_TRIVIAL_CLEANUP_FUNC(Home
*, home_free
);
136 int home_set_record(Home
*h
, UserRecord
*hr
);
137 int home_save_record(Home
*h
);
138 int home_unlink_record(Home
*h
);
140 int home_fixate(Home
*h
, UserRecord
*secret
, sd_bus_error
*error
);
141 int home_activate(Home
*h
, UserRecord
*secret
, sd_bus_error
*error
);
142 int home_authenticate(Home
*h
, UserRecord
*secret
, sd_bus_error
*error
);
143 int home_deactivate(Home
*h
, bool force
, sd_bus_error
*error
);
144 int home_create(Home
*h
, UserRecord
*secret
, sd_bus_error
*error
);
145 int home_remove(Home
*h
, sd_bus_error
*error
);
146 int home_update(Home
*h
, UserRecord
*new_record
, sd_bus_error
*error
);
147 int home_resize(Home
*h
, uint64_t disk_size
, UserRecord
*secret
, sd_bus_error
*error
);
148 int home_passwd(Home
*h
, UserRecord
*new_secret
, UserRecord
*old_secret
, sd_bus_error
*error
);
149 int home_unregister(Home
*h
, sd_bus_error
*error
);
150 int home_lock(Home
*h
, sd_bus_error
*error
);
151 int home_unlock(Home
*h
, UserRecord
*secret
, sd_bus_error
*error
);
153 HomeState
home_get_state(Home
*h
);
155 void home_process_notify(Home
*h
, char **l
);
157 int home_killall(Home
*h
);
159 int home_augment_status(Home
*h
, UserRecordLoadFlags flags
, UserRecord
**ret
);
161 int home_create_fifo(Home
*h
, bool please_suspend
);
162 int home_schedule_operation(Home
*h
, Operation
*o
, sd_bus_error
*error
);
164 int home_auto_login(Home
*h
, char ***ret_seats
);
166 int home_set_current_message(Home
*h
, sd_bus_message
*m
);
168 int home_wait_for_worker(Home
*h
);
170 const char *home_state_to_string(HomeState state
);
171 HomeState
home_state_from_string(const char *s
);