xref: /freebsd/lib/libcasper/services/cap_grp/cap_grp.h (revision 5c2bc3db201a4fe8d7911cf816bea104d5dc2138)
1c501d73cSMariusz Zaborski /*-
2c501d73cSMariusz Zaborski  * Copyright (c) 2013 The FreeBSD Foundation
3c501d73cSMariusz Zaborski  *
4c501d73cSMariusz Zaborski  * This software was developed by Pawel Jakub Dawidek under sponsorship from
5c501d73cSMariusz Zaborski  * the FreeBSD Foundation.
6c501d73cSMariusz Zaborski  *
7c501d73cSMariusz Zaborski  * Redistribution and use in source and binary forms, with or without
8c501d73cSMariusz Zaborski  * modification, are permitted provided that the following conditions
9c501d73cSMariusz Zaborski  * are met:
10c501d73cSMariusz Zaborski  * 1. Redistributions of source code must retain the above copyright
11c501d73cSMariusz Zaborski  *    notice, this list of conditions and the following disclaimer.
12c501d73cSMariusz Zaborski  * 2. Redistributions in binary form must reproduce the above copyright
13c501d73cSMariusz Zaborski  *    notice, this list of conditions and the following disclaimer in the
14c501d73cSMariusz Zaborski  *    documentation and/or other materials provided with the distribution.
15c501d73cSMariusz Zaborski  *
16c501d73cSMariusz Zaborski  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17c501d73cSMariusz Zaborski  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18c501d73cSMariusz Zaborski  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19c501d73cSMariusz Zaborski  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20c501d73cSMariusz Zaborski  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21c501d73cSMariusz Zaborski  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22c501d73cSMariusz Zaborski  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23c501d73cSMariusz Zaborski  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24c501d73cSMariusz Zaborski  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25c501d73cSMariusz Zaborski  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26c501d73cSMariusz Zaborski  * SUCH DAMAGE.
27c501d73cSMariusz Zaborski  */
28c501d73cSMariusz Zaborski 
29c501d73cSMariusz Zaborski #ifndef	_CAP_GRP_H_
30c501d73cSMariusz Zaborski #define	_CAP_GRP_H_
31c501d73cSMariusz Zaborski 
32ceb36bc9SMariusz Zaborski #ifdef HAVE_CASPER
33ceb36bc9SMariusz Zaborski #define WITH_CASPER
34ceb36bc9SMariusz Zaborski #endif
35ceb36bc9SMariusz Zaborski 
36*b30c6ac9SConrad Meyer #include <sys/cdefs.h>
37*b30c6ac9SConrad Meyer 
38ceb36bc9SMariusz Zaborski #ifdef WITH_CASPER
39*b30c6ac9SConrad Meyer __BEGIN_DECLS
40*b30c6ac9SConrad Meyer 
41c501d73cSMariusz Zaborski struct group *cap_getgrent(cap_channel_t *chan);
42c501d73cSMariusz Zaborski struct group *cap_getgrnam(cap_channel_t *chan, const char *name);
43c501d73cSMariusz Zaborski struct group *cap_getgrgid(cap_channel_t *chan, gid_t gid);
44c501d73cSMariusz Zaborski 
45c501d73cSMariusz Zaborski int cap_getgrent_r(cap_channel_t *chan, struct group *grp, char *buffer,
46c501d73cSMariusz Zaborski     size_t bufsize, struct group **result);
47c501d73cSMariusz Zaborski int cap_getgrnam_r(cap_channel_t *chan, const char *name, struct group *grp,
48c501d73cSMariusz Zaborski     char *buffer, size_t bufsize, struct group **result);
49c501d73cSMariusz Zaborski int cap_getgrgid_r(cap_channel_t *chan, gid_t gid, struct group *grp,
50c501d73cSMariusz Zaborski     char *buffer, size_t bufsize, struct group **result);
51c501d73cSMariusz Zaborski 
52c501d73cSMariusz Zaborski int cap_setgroupent(cap_channel_t *chan, int stayopen);
53c501d73cSMariusz Zaborski int cap_setgrent(cap_channel_t *chan);
54c501d73cSMariusz Zaborski void cap_endgrent(cap_channel_t *chan);
55c501d73cSMariusz Zaborski 
56c501d73cSMariusz Zaborski int cap_grp_limit_cmds(cap_channel_t *chan, const char * const *cmds,
57c501d73cSMariusz Zaborski     size_t ncmds);
58c501d73cSMariusz Zaborski int cap_grp_limit_fields(cap_channel_t *chan, const char * const *fields,
59c501d73cSMariusz Zaborski     size_t nfields);
60c501d73cSMariusz Zaborski int cap_grp_limit_groups(cap_channel_t *chan, const char * const *names,
614468cd1aSMariusz Zaborski     size_t nnames, const gid_t *gids, size_t ngids);
62*b30c6ac9SConrad Meyer 
63*b30c6ac9SConrad Meyer __END_DECLS
64*b30c6ac9SConrad Meyer 
65ceb36bc9SMariusz Zaborski #else
66ceb36bc9SMariusz Zaborski #define	cap_getgrent(chan)		getgrent()
67ceb36bc9SMariusz Zaborski #define	cap_getgrnam(chan, name)	getgrnam(name)
68ceb36bc9SMariusz Zaborski #define	cap_getgrgid(chan, gid)		getgrgid(gid)
69ceb36bc9SMariusz Zaborski 
70ceb36bc9SMariusz Zaborski #define	cap_setgroupent(chan, stayopen) etgroupent(stayopen)
71ceb36bc9SMariusz Zaborski #define endgrent(chan)			endgrent()
72ca28b8eeSEnji Cooper static inline int
73ceb36bc9SMariusz Zaborski cap_setgrent(cap_channel_t *chan __unused)
74ceb36bc9SMariusz Zaborski {
75ceb36bc9SMariusz Zaborski 
76ceb36bc9SMariusz Zaborski 	setgrent();
77ceb36bc9SMariusz Zaborski 	return(0);
78ceb36bc9SMariusz Zaborski }
79ceb36bc9SMariusz Zaborski 
80ceb36bc9SMariusz Zaborski #define	cap_getgrent_r(chan, grp, buffer, bufsize, result)			\
81ceb36bc9SMariusz Zaborski 	getgrent_r(grp, buffer, bufsize, result)
82ceb36bc9SMariusz Zaborski #define	cap_getgrnam_r(chan, name, grp, buffer, bufsize, result)		\
83ceb36bc9SMariusz Zaborski 	getgrnam_r(name, grp, buffer, bufsize, result)
84ceb36bc9SMariusz Zaborski #define	cap_getgrgid_r(chan, gid, grp, buffer, bufsize, result)			\
85ceb36bc9SMariusz Zaborski 	getgrgid_r(gid, grp, buffer, bufsize, result)
86ceb36bc9SMariusz Zaborski 
87ceb36bc9SMariusz Zaborski #define	cap_grp_limit_cmds(chan, cmds, ncmds)			(0)
88ceb36bc9SMariusz Zaborski #define	cap_grp_limit_fields(chan, fields, nfields)		(0)
89ceb36bc9SMariusz Zaborski #define	cap_grp_limit_groups(chan, names, nnames, gids, ngids)	(0)
90ceb36bc9SMariusz Zaborski 
91ceb36bc9SMariusz Zaborski #endif
92c501d73cSMariusz Zaborski 
93c501d73cSMariusz Zaborski #endif	/* !_CAP_GRP_H_ */
94