]> granicus.if.org Git - sudo/blob - plugins/sudoers/pwutil.h
Add SPDX-License-Identifier to files.
[sudo] / plugins / sudoers / pwutil.h
1 /*
2  * SPDX-License-Identifier: ISC
3  *
4  * Copyright (c) 2010-2013, 2015-2017 Todd C. Miller <Todd.Miller@sudo.ws>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18
19 #ifndef SUDOERS_PWUTIL_H
20 #define SUDOERS_PWUTIL_H
21
22 #define ptr_to_item(p) ((struct cache_item *)((char *)p - offsetof(struct cache_item_##p, p)))
23
24 /*
25  * Generic cache element.
26  */
27 struct cache_item {
28     unsigned int refcnt;
29     unsigned int type;  /* only used for gidlist */
30     char registry[16];  /* AIX-specific, empty otherwise */
31     /* key */
32     union {
33         uid_t uid;
34         gid_t gid;
35         char *name;
36     } k;
37     /* datum */
38     union {
39         struct passwd *pw;
40         struct group *gr;
41         struct group_list *grlist;
42         struct gid_list *gidlist;
43     } d;
44 };
45
46 /*
47  * Container structs to simpify size and offset calculations and guarantee
48  * proper aligment of struct passwd, group, gid_list and group_list.
49  */
50 struct cache_item_pw {
51     struct cache_item cache;
52     struct passwd pw;
53 };
54
55 struct cache_item_gr {
56     struct cache_item cache;
57     struct group gr;
58 };
59
60 struct cache_item_grlist {
61     struct cache_item cache;
62     struct group_list grlist;
63     /* actually bigger */
64 };
65
66 struct cache_item_gidlist {
67     struct cache_item cache;
68     struct gid_list gidlist;
69     /* actually bigger */
70 };
71
72 struct cache_item *sudo_make_gritem(gid_t gid, const char *group);
73 struct cache_item *sudo_make_grlist_item(const struct passwd *pw, char * const *groups);
74 struct cache_item *sudo_make_gidlist_item(const struct passwd *pw, char * const *gids, unsigned int type);
75 struct cache_item *sudo_make_pwitem(uid_t uid, const char *user);
76
77 #endif /* SUDOERS_PWUTIL_H */