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