1 /* SPDX-License-Identifier: LGPL-2.1+ */
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_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 */
20 HOME_ACTIVATING_FOR_ACQUIRE
, /* activating because Acquire() was called */
22 HOME_ACTIVE
, /* logged in right now */
26 HOME_UNLOCKING_FOR_ACQUIRE
, /* unlocking because Acquire() was called */
30 HOME_UPDATING_WHILE_ACTIVE
,
32 HOME_RESIZING_WHILE_ACTIVE
,
34 HOME_PASSWD_WHILE_ACTIVE
,
36 HOME_AUTHENTICATING_WHILE_ACTIVE
,
37 HOME_AUTHENTICATING_FOR_ACQUIRE
, /* authenticating because Acquire() was called */
39 _HOME_STATE_INVALID
= -1
42 static inline bool HOME_STATE_IS_ACTIVE(HomeState state
) {
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
);
52 static inline bool HOME_STATE_IS_EXECUTING_OPERATION(HomeState state
) {
55 HOME_FIXATING_FOR_ACTIVATION
,
56 HOME_FIXATING_FOR_ACQUIRE
,
58 HOME_ACTIVATING_FOR_ACQUIRE
,
62 HOME_UNLOCKING_FOR_ACQUIRE
,
66 HOME_UPDATING_WHILE_ACTIVE
,
68 HOME_RESIZING_WHILE_ACTIVE
,
70 HOME_PASSWD_WHILE_ACTIVE
,
72 HOME_AUTHENTICATING_WHILE_ACTIVE
,
73 HOME_AUTHENTICATING_FOR_ACQUIRE
);
81 char *sysfs
; /* When found via plugged in device, the sysfs path to it */
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.*/
88 int signed_locally
; /* signed only by us */
94 sd_event_source
*worker_event_source
;
95 int worker_error_code
;
97 /* The message we are currently processing, and thus need to reply to on completion */
98 Operation
*current_operation
;
100 /* Stores the raw, plaintext passwords, but only for short periods of time */
103 /* When we create a home and that fails, we should possibly unregister the record altogether
104 * again, which is remembered in this boolean. */
105 bool unregister_on_failure
;
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
;
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
;
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
;
123 /* Did we send out a D-Bus notification about this entry? */
126 /* Used to coalesce bus PropertiesChanged events */
127 sd_event_source
*deferred_change_event_source
;
130 int home_new(Manager
*m
, UserRecord
*hr
, const char *sysfs
, Home
**ret
);
131 Home
*home_free(Home
*h
);
133 DEFINE_TRIVIAL_CLEANUP_FUNC(Home
*, home_free
);
135 int home_set_record(Home
*h
, UserRecord
*hr
);
136 int home_save_record(Home
*h
);
137 int home_unlink_record(Home
*h
);
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
);
152 HomeState
home_get_state(Home
*h
);
154 void home_process_notify(Home
*h
, char **l
);
156 int home_killall(Home
*h
);
158 int home_augment_status(Home
*h
, UserRecordLoadFlags flags
, UserRecord
**ret
);
160 int home_create_fifo(Home
*h
, bool please_suspend
);
161 int home_schedule_operation(Home
*h
, Operation
*o
, sd_bus_error
*error
);
163 int home_auto_login(Home
*h
, char ***ret_seats
);
165 int home_set_current_message(Home
*h
, sd_bus_message
*m
);
167 const char *home_state_to_string(HomeState state
);
168 HomeState
home_state_from_string(const char *s
);