1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 #pragma once 3 4 #include <sys/socket.h> 5 #include <sys/un.h> 6 7 #include "group-record.h" 8 #include "user-record.h" 9 10 /* Inquire local services for user/group records */ 11 12 typedef struct UserDBIterator UserDBIterator; 13 14 UserDBIterator *userdb_iterator_free(UserDBIterator *iterator); 15 DEFINE_TRIVIAL_CLEANUP_FUNC(UserDBIterator*, userdb_iterator_free); 16 17 typedef enum UserDBFlags { 18 /* The main sources */ 19 USERDB_EXCLUDE_NSS = 1 << 0, /* don't do client-side nor server-side NSS */ 20 USERDB_EXCLUDE_VARLINK = 1 << 1, /* don't talk to any varlink services */ 21 USERDB_EXCLUDE_DROPIN = 1 << 2, /* don't load drop-in user/group definitions */ 22 23 /* Modifications */ 24 USERDB_SUPPRESS_SHADOW = 1 << 3, /* don't do client-side shadow calls (server side might happen though) */ 25 USERDB_EXCLUDE_DYNAMIC_USER = 1 << 4, /* exclude looking up in io.systemd.DynamicUser */ 26 USERDB_AVOID_MULTIPLEXER = 1 << 5, /* exclude looking up via io.systemd.Multiplexer */ 27 USERDB_DONT_SYNTHESIZE = 1 << 6, /* don't synthesize root/nobody */ 28 29 /* Combinations */ 30 USERDB_NSS_ONLY = USERDB_EXCLUDE_VARLINK|USERDB_EXCLUDE_DROPIN|USERDB_DONT_SYNTHESIZE, 31 USERDB_DROPIN_ONLY = USERDB_EXCLUDE_NSS|USERDB_EXCLUDE_VARLINK|USERDB_DONT_SYNTHESIZE, 32 } UserDBFlags; 33 34 /* Well-known errors we'll return here: 35 * 36 * -ESRCH: No such user/group 37 * -ELINK: Varlink logic turned off (and no other source available) 38 * -EOPNOTSUPP: Enumeration not supported 39 * -ETIMEDOUT: Time-out 40 */ 41 42 int userdb_by_name(const char *name, UserDBFlags flags, UserRecord **ret); 43 int userdb_by_uid(uid_t uid, UserDBFlags flags, UserRecord **ret); 44 int userdb_all(UserDBFlags flags, UserDBIterator **ret); 45 int userdb_iterator_get(UserDBIterator *iterator, UserRecord **ret); 46 47 int groupdb_by_name(const char *name, UserDBFlags flags, GroupRecord **ret); 48 int groupdb_by_gid(gid_t gid, UserDBFlags flags, GroupRecord **ret); 49 int groupdb_all(UserDBFlags flags, UserDBIterator **ret); 50 int groupdb_iterator_get(UserDBIterator *iterator, GroupRecord **ret); 51 52 int membershipdb_by_user(const char *name, UserDBFlags flags, UserDBIterator **ret); 53 int membershipdb_by_group(const char *name, UserDBFlags flags, UserDBIterator **ret); 54 int membershipdb_all(UserDBFlags flags, UserDBIterator **ret); 55 int membershipdb_iterator_get(UserDBIterator *iterator, char **user, char **group); 56 int membershipdb_by_group_strv(const char *name, UserDBFlags flags, char ***ret); 57 58 int userdb_block_nss_systemd(int b); 59