From b41dca52762c5188638236ae81b9f4597bb29ac9 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 9 Nov 2022 11:14:12 -0500 Subject: pwcache: Fill the user/group caches lazily Iterating all the users/groups can be expensive, especially with NSS. Android has so many that it doesn't even return them all from get{pw,gr}ent() for performance reasons, leading to incorrect behaviour of -user/-group/etc. --- src/pwcache.h | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'src/pwcache.h') diff --git a/src/pwcache.h b/src/pwcache.h index f1a1db3..6ae8bea 100644 --- a/src/pwcache.h +++ b/src/pwcache.h @@ -25,92 +25,96 @@ #include /** - * The user table. + * A user cache. */ struct bfs_users; /** - * Parse the user table. + * Create a user cache. * * @return - * The parsed user table, or NULL on failure. + * A new user cache, or NULL on failure. */ -struct bfs_users *bfs_users_parse(void); +struct bfs_users *bfs_users_new(void); /** * Get a user entry by name. * * @param users - * The user table. + * The user cache. * @param name * The username to look up. * @return - * The matching user, or NULL if not found. + * The matching user, or NULL if not found (errno == 0) or an error + * occurred (errno != 0). */ -const struct passwd *bfs_getpwnam(const struct bfs_users *users, const char *name); +const struct passwd *bfs_getpwnam(struct bfs_users *users, const char *name); /** * Get a user entry by ID. * * @param users - * The user table. + * The user cache. * @param uid * The ID to look up. * @return - * The matching user, or NULL if not found. + * The matching user, or NULL if not found (errno == 0) or an error + * occurred (errno != 0). */ -const struct passwd *bfs_getpwuid(const struct bfs_users *users, uid_t uid); +const struct passwd *bfs_getpwuid(struct bfs_users *users, uid_t uid); /** - * Free a user table. + * Free a user cache. * * @param users - * The user table to free. + * The user cache to free. */ void bfs_users_free(struct bfs_users *users); /** - * The group table. + * A group cache. */ struct bfs_groups; /** - * Parse the group table. + * Create a group cache. * * @return - * The parsed group table, or NULL on failure. + * A new group cache, or NULL on failure. */ -struct bfs_groups *bfs_groups_parse(void); +struct bfs_groups *bfs_groups_new(void); /** * Get a group entry by name. * * @param groups - * The group table. + * The group cache. * @param name * The group name to look up. * @return - * The matching group, or NULL if not found. + * The matching group, or NULL if not found (errno == 0) or an error + * occurred (errno != 0). */ -const struct group *bfs_getgrnam(const struct bfs_groups *groups, const char *name); +const struct group *bfs_getgrnam(struct bfs_groups *groups, const char *name); /** * Get a group entry by ID. * * @param groups - * The group table. + * The group cache. * @param uid * The ID to look up. * @return - * The matching group, or NULL if not found. + * The matching group, or NULL if not found (errno == 0) or an error + * occurred (errno != 0). */ -const struct group *bfs_getgrgid(const struct bfs_groups *groups, gid_t gid); +const struct group *bfs_getgrgid(struct bfs_groups *groups, gid_t gid); /** - * Free a group table. + * Free a group cache. * * @param groups - * The group table to free. + * The group cache to free. */ void bfs_groups_free(struct bfs_groups *groups); -- cgit v1.2.3