| 1 |
|
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "homed-forward.h" |
| 5 |
#include "pidref.h" |
| 6 |
#include "stat-util.h" |
| 7 |
|
| 8 |
typedef enum HomeState { |
| 9 |
HOME_UNFIXATED, |
| 10 |
HOME_ABSENT, |
| 11 |
HOME_INACTIVE, |
| 12 |
HOME_DIRTY, |
| 13 |
HOME_FIXATING, |
| 14 |
HOME_FIXATING_FOR_ACTIVATION, |
| 15 |
HOME_FIXATING_FOR_ACQUIRE, |
| 16 |
HOME_ACTIVATING, |
| 17 |
HOME_ACTIVATING_FOR_ACQUIRE, |
| 18 |
HOME_DEACTIVATING, |
| 19 |
HOME_ACTIVE, |
| 20 |
HOME_LINGERING, |
| 21 |
HOME_LOCKING, |
| 22 |
HOME_LOCKED, |
| 23 |
HOME_UNLOCKING, |
| 24 |
HOME_UNLOCKING_FOR_ACQUIRE, |
| 25 |
HOME_CREATING, |
| 26 |
HOME_REMOVING, |
| 27 |
HOME_UPDATING, |
| 28 |
HOME_UPDATING_WHILE_ACTIVE, |
| 29 |
HOME_RESIZING, |
| 30 |
HOME_RESIZING_WHILE_ACTIVE, |
| 31 |
HOME_PASSWD, |
| 32 |
HOME_PASSWD_WHILE_ACTIVE, |
| 33 |
HOME_AUTHENTICATING, |
| 34 |
HOME_AUTHENTICATING_WHILE_ACTIVE, |
| 35 |
HOME_AUTHENTICATING_FOR_ACQUIRE, |
| 36 |
_HOME_STATE_MAX, |
| 37 |
_HOME_STATE_INVALID = -EINVAL, |
| 38 |
} HomeState; |
| 39 |
|
| 40 |
static inline bool HOME_STATE_IS_ACTIVE(HomeState state) { |
| 41 |
return IN_SET(state, |
| 42 |
HOME_ACTIVE, |
| 43 |
HOME_LINGERING, |
| 44 |
HOME_UPDATING_WHILE_ACTIVE, |
| 45 |
HOME_RESIZING_WHILE_ACTIVE, |
| 46 |
HOME_PASSWD_WHILE_ACTIVE, |
| 47 |
HOME_AUTHENTICATING_WHILE_ACTIVE, |
| 48 |
HOME_AUTHENTICATING_FOR_ACQUIRE); |
| 49 |
} |
| 50 |
|
| 51 |
static inline bool HOME_STATE_IS_EXECUTING_OPERATION(HomeState state) { |
| 52 |
return IN_SET(state, |
| 53 |
HOME_FIXATING, |
| 54 |
HOME_FIXATING_FOR_ACTIVATION, |
| 55 |
HOME_FIXATING_FOR_ACQUIRE, |
| 56 |
HOME_ACTIVATING, |
| 57 |
HOME_ACTIVATING_FOR_ACQUIRE, |
| 58 |
HOME_DEACTIVATING, |
| 59 |
HOME_LOCKING, |
| 60 |
HOME_UNLOCKING, |
| 61 |
HOME_UNLOCKING_FOR_ACQUIRE, |
| 62 |
HOME_CREATING, |
| 63 |
HOME_REMOVING, |
| 64 |
HOME_UPDATING, |
| 65 |
HOME_UPDATING_WHILE_ACTIVE, |
| 66 |
HOME_RESIZING, |
| 67 |
HOME_RESIZING_WHILE_ACTIVE, |
| 68 |
HOME_PASSWD, |
| 69 |
HOME_PASSWD_WHILE_ACTIVE, |
| 70 |
HOME_AUTHENTICATING, |
| 71 |
HOME_AUTHENTICATING_WHILE_ACTIVE, |
| 72 |
HOME_AUTHENTICATING_FOR_ACQUIRE); |
| 73 |
} |
| 74 |
|
| 75 |
static inline bool HOME_STATE_SHALL_PIN(HomeState state) { |
| 76 |
*/ |
| 77 |
return IN_SET(state, |
| 78 |
HOME_ACTIVE, |
| 79 |
HOME_UPDATING_WHILE_ACTIVE, |
| 80 |
HOME_RESIZING_WHILE_ACTIVE, |
| 81 |
HOME_PASSWD_WHILE_ACTIVE, |
| 82 |
HOME_AUTHENTICATING_WHILE_ACTIVE, |
| 83 |
HOME_AUTHENTICATING_FOR_ACQUIRE); |
| 84 |
} |
| 85 |
|
| 86 |
#define HOME_STATE_SHALL_REBALANCE(state) HOME_STATE_SHALL_PIN(state) |
| 87 |
|
| 88 |
static inline bool HOME_STATE_MAY_RETRY_DEACTIVATE(HomeState state) { |
| 89 |
|
| 90 |
return IN_SET(state, |
| 91 |
HOME_ACTIVE, |
| 92 |
HOME_LINGERING, |
| 93 |
HOME_DEACTIVATING, |
| 94 |
HOME_LOCKING, |
| 95 |
HOME_UNLOCKING, |
| 96 |
HOME_UNLOCKING_FOR_ACQUIRE, |
| 97 |
HOME_UPDATING_WHILE_ACTIVE, |
| 98 |
HOME_RESIZING_WHILE_ACTIVE, |
| 99 |
HOME_PASSWD_WHILE_ACTIVE, |
| 100 |
HOME_AUTHENTICATING_WHILE_ACTIVE, |
| 101 |
HOME_AUTHENTICATING_FOR_ACQUIRE); |
| 102 |
} |
| 103 |
|
| 104 |
typedef struct Home { |
| 105 |
Manager *manager; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
char *user_name; |
| 111 |
char **aliases; |
| 112 |
uid_t uid; |
| 113 |
|
| 114 |
char *sysfs; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
HomeState state; |
| 121 |
int signed_locally; |
| 122 |
|
| 123 |
UserRecord *record; |
| 124 |
|
| 125 |
PidRef worker_pid; |
| 126 |
int worker_stdout_fd; |
| 127 |
sd_event_source *worker_event_source; |
| 128 |
int worker_error_code; |
| 129 |
|
| 130 |
|
| 131 |
Operation *current_operation; |
| 132 |
|
| 133 |
|
| 134 |
UserRecord *secret; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
bool unregister_on_failure; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
sd_event_source *ref_event_source_please_suspend; |
| 146 |
sd_event_source *ref_event_source_dont_suspend; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
OrderedSet *pending_operations; |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
sd_event_source *pending_event_source; |
| 155 |
|
| 156 |
|
| 157 |
bool announced; |
| 158 |
|
| 159 |
|
| 160 |
sd_event_source *deferred_change_event_source; |
| 161 |
|
| 162 |
|
| 163 |
int pin_fd; |
| 164 |
|
| 165 |
|
| 166 |
sd_event_source *retry_deactivate_event_source; |
| 167 |
|
| 168 |
|
| 169 |
int luks_lock_fd; |
| 170 |
|
| 171 |
|
| 172 |
uint64_t rebalance_size, rebalance_usage, rebalance_free, rebalance_min, rebalance_weight, rebalance_goal; |
| 173 |
|
| 174 |
|
| 175 |
bool rebalance_pending; |
| 176 |
} Home; |
| 177 |
|
| 178 |
int home_new(Manager *m, UserRecord *hr, const char *sysfs, Home **ret); |
| 179 |
Home *home_free(Home *h); |
| 180 |
|
| 181 |
DEFINE_TRIVIAL_CLEANUP_FUNC(Home*, home_free); |
| 182 |
|
| 183 |
int home_set_record(Home *h, UserRecord *hr); |
| 184 |
int home_save_record(Home *h); |
| 185 |
int home_unlink_record(Home *h); |
| 186 |
|
| 187 |
int home_fixate(Home *h, UserRecord *secret, sd_bus_error *error); |
| 188 |
int home_activate(Home *h, bool if_referenced, UserRecord *secret, sd_bus_error *error); |
| 189 |
int home_authenticate(Home *h, UserRecord *secret, sd_bus_error *error); |
| 190 |
int home_deactivate(Home *h, bool force, sd_bus_error *error); |
| 191 |
int home_create(Home *h, UserRecord *secret, Hashmap *blobs, uint64_t flags, sd_bus_error *error); |
| 192 |
int home_remove(Home *h, sd_bus_error *error); |
| 193 |
int home_update(Home *h, UserRecord *hr, Hashmap *blobs, uint64_t flags, sd_bus_error *error); |
| 194 |
int home_resize(Home *h, uint64_t disk_size, UserRecord *secret, sd_bus_error *error); |
| 195 |
int home_passwd(Home *h, UserRecord *new_secret, UserRecord *old_secret, sd_bus_error *error); |
| 196 |
int home_unregister(Home *h, sd_bus_error *error); |
| 197 |
int home_lock(Home *h, sd_bus_error *error); |
| 198 |
int home_unlock(Home *h, UserRecord *secret, sd_bus_error *error); |
| 199 |
|
| 200 |
bool home_is_referenced(Home *h); |
| 201 |
bool home_shall_suspend(Home *h); |
| 202 |
HomeState home_get_state(Home *h); |
| 203 |
|
| 204 |
int home_get_disk_status( |
| 205 |
Home *h, |
| 206 |
uint64_t *ret_disk_size, |
| 207 |
uint64_t *ret_disk_usage, |
| 208 |
uint64_t *ret_disk_free, |
| 209 |
uint64_t *ret_disk_ceiling, |
| 210 |
uint64_t *ret_disk_floor, |
| 211 |
statfs_f_type_t *ret_fstype, |
| 212 |
mode_t *ret_access_mode); |
| 213 |
|
| 214 |
void home_process_notify(Home *h, char **l, int fd); |
| 215 |
|
| 216 |
int home_killall(Home *h); |
| 217 |
|
| 218 |
int home_augment_status(Home *h, UserRecordLoadFlags flags, UserRecord **ret); |
| 219 |
|
| 220 |
int home_create_fifo(Home *h, bool please_suspend); |
| 221 |
int home_schedule_operation(Home *h, Operation *o, sd_bus_error *error); |
| 222 |
|
| 223 |
int home_auto_login(Home *h, char ***ret_seats); |
| 224 |
|
| 225 |
int home_set_current_message(Home *h, sd_bus_message *m); |
| 226 |
|
| 227 |
int home_wait_for_worker(Home *h); |
| 228 |
|
| 229 |
bool home_shall_rebalance(Home *h); |
| 230 |
|
| 231 |
bool home_is_busy(Home *h); |
| 232 |
|
| 233 |
DECLARE_STRING_TABLE_LOOKUP(home_state, HomeState); |