| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "core-forward.h" |
| 5 |
|
| 6 |
/* Note that this object always allocates a pair of user and group under the same name, even if one of them isn't |
| 7 |
* used. This means, if you want to allocate a group and user pair, and they might have two different names, then you |
| 8 |
* need to allocated two of these objects. DynamicCreds below makes that easy. */ |
| 9 |
typedef struct DynamicUser { |
| 10 |
Manager *manager; |
| 11 |
unsigned n_ref; |
| 12 |
|
| 13 |
/* An AF_UNIX socket pair that contains a datagram containing both the numeric ID assigned, as well as a lock |
| 14 |
* file fd locking the user ID we picked. */ |
| 15 |
int storage_socket[2]; |
| 16 |
|
| 17 |
char name[]; |
| 18 |
} DynamicUser; |
| 19 |
|
| 20 |
typedef struct DynamicCreds { |
| 21 |
/* A combination of a dynamic user and group */ |
| 22 |
DynamicUser *user; |
| 23 |
DynamicUser *group; |
| 24 |
} DynamicCreds; |
| 25 |
|
| 26 |
int dynamic_user_serialize(Manager *m, FILE *f, FDSet *fds); |
| 27 |
int dynamic_user_serialize_one(DynamicUser *d, const char *key, FILE *f, FDSet *fds); |
| 28 |
void dynamic_user_deserialize_one(Manager *m, const char *value, FDSet *fds, DynamicUser **ret); |
| 29 |
DynamicUser* dynamic_user_free(DynamicUser *d); |
| 30 |
void dynamic_user_vacuum(Manager *m, bool close_user); |
| 31 |
|
| 32 |
int dynamic_user_current(DynamicUser *d, uid_t *ret); |
| 33 |
int dynamic_user_lookup_uid(Manager *m, uid_t uid, char **ret); |
| 34 |
int dynamic_user_lookup_name(Manager *m, const char *name, uid_t *ret); |
| 35 |
|
| 36 |
int dynamic_creds_make(Manager *m, const char *user, const char *group, DynamicCreds **ret); |
| 37 |
int dynamic_creds_realize(DynamicCreds *creds, char **suggested_paths, uid_t *uid, gid_t *gid); |
| 38 |
|
| 39 |
DynamicCreds *dynamic_creds_unref(DynamicCreds *creds); |
| 40 |
DynamicCreds *dynamic_creds_destroy(DynamicCreds *creds); |
| 41 |
void dynamic_creds_done(DynamicCreds *creds); |
| 42 |
void dynamic_creds_close(DynamicCreds *creds); |
| 43 |
|
| 44 |
DEFINE_TRIVIAL_CLEANUP_FUNC(DynamicCreds*, dynamic_creds_unref); |
| 45 |
DEFINE_TRIVIAL_CLEANUP_FUNC(DynamicCreds*, dynamic_creds_destroy); |
| 46 |
|
| 47 |
DECLARE_TRIVIAL_REF_FUNC(DynamicUser, dynamic_user); |