summaryrefslogtreecommitdiffstats
path: root/src/pwcache.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-11-09 11:14:12 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-11-09 12:08:20 -0500
commitb41dca52762c5188638236ae81b9f4597bb29ac9 (patch)
tree4d503f6dcee1b1ed15ef61df3c8ccb9b92533546 /src/pwcache.h
parentdd6808539013061a3113e45c7267430e56749f2c (diff)
downloadbfs-b41dca52762c5188638236ae81b9f4597bb29ac9.tar.xz
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.
Diffstat (limited to 'src/pwcache.h')
-rw-r--r--src/pwcache.h52
1 files changed, 28 insertions, 24 deletions
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 <pwd.h>
/**
- * 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);