xref: /freebsd/lib/libcasper/services/cap_pwd/cap_pwd.h (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
1 /*-
2  * Copyright (c) 2013 The FreeBSD Foundation
3  * All rights reserved.
4  *
5  * This software was developed by Pawel Jakub Dawidek under sponsorship from
6  * the FreeBSD Foundation.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef	_CAP_PWD_H_
31 #define	_CAP_PWD_H_
32 
33 #ifdef HAVE_CASPER
34 #define WITH_CASPER
35 #endif
36 
37 #include <sys/cdefs.h>
38 
39 #ifdef WITH_CASPER
40 __BEGIN_DECLS
41 
42 struct passwd *cap_getpwent(cap_channel_t *chan);
43 struct passwd *cap_getpwnam(cap_channel_t *chan, const char *login);
44 struct passwd *cap_getpwuid(cap_channel_t *chan, uid_t uid);
45 
46 int cap_getpwent_r(cap_channel_t *chan, struct passwd *pwd, char *buffer,
47     size_t bufsize, struct passwd **result);
48 int cap_getpwnam_r(cap_channel_t *chan, const char *name, struct passwd *pwd,
49     char *buffer, size_t bufsize, struct passwd **result);
50 int cap_getpwuid_r(cap_channel_t *chan, uid_t uid, struct passwd *pwd,
51     char *buffer, size_t bufsize, struct passwd **result);
52 
53 int cap_setpassent(cap_channel_t *chan, int stayopen);
54 void cap_setpwent(cap_channel_t *chan);
55 void cap_endpwent(cap_channel_t *chan);
56 
57 int cap_pwd_limit_cmds(cap_channel_t *chan, const char * const *cmds,
58     size_t ncmds);
59 int cap_pwd_limit_fields(cap_channel_t *chan, const char * const *fields,
60     size_t nfields);
61 int cap_pwd_limit_users(cap_channel_t *chan, const char * const *names,
62     size_t nnames, uid_t *uids, size_t nuids);
63 
64 __END_DECLS
65 
66 #else
67 
68 static inline struct passwd *
69 cap_getpwent(cap_channel_t *chan __unused)
70 {
71 
72 	return (getpwent());
73 }
74 
75 static inline struct passwd *
76 cap_getpwnam(cap_channel_t *chan __unused, const char *login)
77 {
78 
79 	return (getpwnam(login));
80 }
81 
82 static inline struct passwd *
83 cap_getpwuid(cap_channel_t *chan __unused, uid_t uid)
84 {
85 
86 	return (getpwuid(uid));
87 }
88 
89 static inline int
90 cap_getpwent_r(cap_channel_t *chan __unused, struct passwd *pwd, char *buffer,
91     size_t bufsize, struct passwd **result)
92 {
93 
94 	return (getpwent_r(pwd, buffer, bufsize, result));
95 }
96 
97 static inline int
98 cap_getpwnam_r(cap_channel_t *chan __unused, const char *name,
99     struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
100 {
101 
102 	return (getpwnam_r(name, pwd, buffer, bufsize, result));
103 }
104 
105 static inline int
106 cap_getpwuid_r(cap_channel_t *chan __unused, uid_t uid, struct passwd *pwd,
107     char *buffer, size_t bufsize, struct passwd **result)
108 {
109 
110 	return (getpwuid_r(uid, pwd, buffer, bufsize, result));
111 }
112 
113 static inline int
114 cap_setpassent(cap_channel_t *chan __unused, int stayopen)
115 {
116 
117 	return (setpassent(stayopen));
118 }
119 
120 static inline void
121 cap_setpwent(cap_channel_t *chan __unused)
122 {
123 
124 	return (setpwent());
125 }
126 
127 static inline void
128 cap_endpwent(cap_channel_t *chan __unused)
129 {
130 
131 	return (endpwent());
132 }
133 
134 static inline int
135 cap_pwd_limit_cmds(cap_channel_t *chan __unused,
136     const char * const *cmds __unused, size_t ncmds __unused)
137 {
138 
139 	return (0);
140 }
141 
142 static inline int
143 cap_pwd_limit_fields(cap_channel_t *chan __unused,
144     const char * const *fields __unused, size_t nfields __unused)
145 {
146 
147 	return (0);
148 }
149 
150 static inline int
151 cap_pwd_limit_users(cap_channel_t *chan __unused,
152     const char * const *names __unused, size_t nnames __unused,
153     uid_t *uids __unused, size_t nuids __unused)
154 {
155 
156 	return (0);
157 }
158 #endif
159 
160 #endif	/* !_CAP_PWD_H_ */
161