diff options
Diffstat (limited to 'src/pwcache.h')
-rw-r--r-- | src/pwcache.h | 85 |
1 files changed, 46 insertions, 39 deletions
diff --git a/src/pwcache.h b/src/pwcache.h index f1a1db3..b6c0b67 100644 --- a/src/pwcache.h +++ b/src/pwcache.h @@ -1,18 +1,5 @@ -/**************************************************************************** - * bfs * - * Copyright (C) 2020 Tavian Barnes <tavianator@tavianator.com> * - * * - * Permission to use, copy, modify, and/or distribute this software for any * - * purpose with or without fee is hereby granted. * - * * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - ****************************************************************************/ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD /** * A caching wrapper for /etc/{passwd,group}. @@ -25,92 +12,112 @@ #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. + * Flush a user cache. * * @param users - * The user table to free. + * The cache to flush. + */ +void bfs_users_flush(struct bfs_users *users); + +/** + * Free a user cache. + * + * @param users + * 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(struct bfs_groups *groups, gid_t gid); + +/** + * Flush a group cache. + * + * @param groups + * The cache to flush. */ -const struct group *bfs_getgrgid(const struct bfs_groups *groups, gid_t gid); +void bfs_groups_flush(struct bfs_groups *groups); /** - * 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); |