Debian Codegraph @

src/shared/nss-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <grp.h>
5 #include <gshadow.h>
6 #include <netdb.h>
7 #include <nss.h>
8 #include <pwd.h>
9 #include <resolv.h>
10
11 #include "shared-forward.h"
12 #include "signal-util.h"
13
14 extern sd_json_dispatch_flags_t nss_json_dispatch_flags;
15
16 void log_setup_nss(void);
17
18 #define NSS_ENTRYPOINT_BEGIN \
19 log_setup_nss(); \
20 BLOCK_SIGNALS(SIGALRM, \
21 SIGVTALRM, \
22 SIGPIPE, \
23 SIGCHLD, \
24 SIGTSTP, \
25 SIGIO, \
26 SIGHUP, \
27 SIGUSR1, \
28 SIGUSR2, \
29 SIGPROF, \
30 SIGURG, \
31 SIGWINCH)
32
33 #ifndef DEPRECATED_RES_USE_INET6
34 # define DEPRECATED_RES_USE_INET6 0x00002000
35 #endif
36
37 #define NSS_GETHOSTBYNAME_PROTOTYPES(module) \
38 enum nss_status _nss_##module##_gethostbyname4_r( \
39 const char *name, \
40 struct gaih_addrtuple **pat, \
41 char *buffer, size_t buflen, \
42 int *errnop, int *h_errnop, \
43 int32_t *ttlp) _public_; \
44 enum nss_status _nss_##module##_gethostbyname3_r( \
45 const char *name, \
46 int af, \
47 struct hostent *host, \
48 char *buffer, size_t buflen, \
49 int *errnop, int *h_errnop, \
50 int32_t *ttlp, \
51 char **canonp) _public_; \
52 enum nss_status _nss_##module##_gethostbyname2_r( \
53 const char *name, \
54 int af, \
55 struct hostent *host, \
56 char *buffer, size_t buflen, \
57 int *errnop, int *h_errnop) _public_; \
58 enum nss_status _nss_##module##_gethostbyname_r( \
59 const char *name, \
60 struct hostent *host, \
61 char *buffer, size_t buflen, \
62 int *errnop, int *h_errnop) _public_
63
64 #define NSS_GETHOSTBYADDR_PROTOTYPES(module) \
65 enum nss_status _nss_##module##_gethostbyaddr2_r( \
66 const void* addr, socklen_t len, \
67 int af, \
68 struct hostent *host, \
69 char *buffer, size_t buflen, \
70 int *errnop, int *h_errnop, \
71 int32_t *ttlp) _public_; \
72 enum nss_status _nss_##module##_gethostbyaddr_r( \
73 const void* addr, socklen_t len, \
74 int af, \
75 struct hostent *host, \
76 char *buffer, size_t buflen, \
77 int *errnop, int *h_errnop) _public_
78
79 #define NSS_GETHOSTBYNAME_FALLBACKS(module) \
80 enum nss_status _nss_##module##_gethostbyname2_r( \
81 const char *name, \
82 int af, \
83 struct hostent *host, \
84 char *buffer, size_t buflen, \
85 int *errnop, int *h_errnop) { \
86 return _nss_##module##_gethostbyname3_r( \
87 name, \
88 af, \
89 host, \
90 buffer, buflen, \
91 errnop, h_errnop, \
92 NULL, \
93 NULL); \
94 } \
95 enum nss_status _nss_##module##_gethostbyname_r( \
96 const char *name, \
97 struct hostent *host, \
98 char *buffer, size_t buflen, \
99 int *errnop, int *h_errnop) { \
100 enum nss_status ret = NSS_STATUS_NOTFOUND; \
101 \
102 if (_res.options & DEPRECATED_RES_USE_INET6) \
103 ret = _nss_##module##_gethostbyname3_r( \
104 name, \
105 AF_INET6, \
106 host, \
107 buffer, buflen, \
108 errnop, h_errnop, \
109 NULL, \
110 NULL); \
111 if (ret == NSS_STATUS_NOTFOUND) \
112 ret = _nss_##module##_gethostbyname3_r( \
113 name, \
114 AF_INET, \
115 host, \
116 buffer, buflen, \
117 errnop, h_errnop, \
118 NULL, \
119 NULL); \
120 return ret; \
121 }
122
123 #define NSS_GETHOSTBYADDR_FALLBACKS(module) \
124 enum nss_status _nss_##module##_gethostbyaddr_r( \
125 const void* addr, socklen_t len, \
126 int af, \
127 struct hostent *host, \
128 char *buffer, size_t buflen, \
129 int *errnop, int *h_errnop) { \
130 return _nss_##module##_gethostbyaddr2_r( \
131 addr, len, \
132 af, \
133 host, \
134 buffer, buflen, \
135 errnop, h_errnop, \
136 NULL); \
137 }
138
139 #define NSS_GETPW_PROTOTYPES(module) \
140 enum nss_status _nss_##module##_getpwnam_r( \
141 const char *name, \
142 struct passwd *pwd, \
143 char *buffer, size_t buflen, \
144 int *errnop) _public_; \
145 enum nss_status _nss_##module##_getpwuid_r( \
146 uid_t uid, \
147 struct passwd *pwd, \
148 char *buffer, size_t buflen, \
149 int *errnop) _public_
150
151 #define NSS_GETSP_PROTOTYPES(module) \
152 enum nss_status _nss_##module##_getspnam_r( \
153 const char *name, \
154 struct spwd *spwd, \
155 char *buffer, size_t buflen, \
156 int *errnop) _public_
157
158 #define NSS_GETSG_PROTOTYPES(module) \
159 enum nss_status _nss_##module##_getsgnam_r( \
160 const char *name, \
161 struct sgrp *sgrp, \
162 char *buffer, size_t buflen, \
163 int *errnop) _public_
164
165 #define NSS_GETGR_PROTOTYPES(module) \
166 enum nss_status _nss_##module##_getgrnam_r( \
167 const char *name, \
168 struct group *gr, \
169 char *buffer, size_t buflen, \
170 int *errnop) _public_; \
171 enum nss_status _nss_##module##_getgrgid_r( \
172 gid_t gid, \
173 struct group *gr, \
174 char *buffer, size_t buflen, \
175 int *errnop) _public_
176
177 #define NSS_PWENT_PROTOTYPES(module) \
178 enum nss_status _nss_##module##_endpwent( \
179 void) _public_; \
180 enum nss_status _nss_##module##_setpwent( \
181 int stayopen) _public_; \
182 enum nss_status _nss_##module##_getpwent_r( \
183 struct passwd *result, \
184 char *buffer, \
185 size_t buflen, \
186 int *errnop) _public_;
187
188 #define NSS_SPENT_PROTOTYPES(module) \
189 enum nss_status _nss_##module##_endspent( \
190 void) _public_; \
191 enum nss_status _nss_##module##_setspent( \
192 int stayopen) _public_; \
193 enum nss_status _nss_##module##_getspent_r( \
194 struct spwd *spwd, \
195 char *buffer, \
196 size_t buflen, \
197 int *errnop) _public_;
198
199 #define NSS_GRENT_PROTOTYPES(module) \
200 enum nss_status _nss_##module##_endgrent( \
201 void) _public_; \
202 enum nss_status _nss_##module##_setgrent( \
203 int stayopen) _public_; \
204 enum nss_status _nss_##module##_getgrent_r( \
205 struct group *result, \
206 char *buffer, \
207 size_t buflen, \
208 int *errnop) _public_;
209
210 #define NSS_SGENT_PROTOTYPES(module) \
211 enum nss_status _nss_##module##_endsgent( \
212 void) _public_; \
213 enum nss_status _nss_##module##_setsgent( \
214 int stayopen) _public_; \
215 enum nss_status _nss_##module##_getsgent_r( \
216 struct sgrp *sgrp, \
217 char *buffer, \
218 size_t buflen, \
219 int *errnop) _public_;
220
221 #define NSS_INITGROUPS_PROTOTYPE(module) \
222 enum nss_status _nss_##module##_initgroups_dyn( \
223 const char *user, \
224 gid_t group, \
225 long *start, \
226 long *size, \
227 gid_t **groupsp, \
228 long limit, \
229 int *errnop) _public_;
230
231 typedef enum nss_status (*_nss_gethostbyname4_r_t)(
232 const char *name,
233 struct gaih_addrtuple **pat,
234 char *buffer, size_t buflen,
235 int *errnop, int *h_errnop,
236 int32_t *ttlp);
237
238 typedef enum nss_status (*_nss_gethostbyname3_r_t)(
239 const char *name,
240 int af,
241 struct hostent *result,
242 char *buffer, size_t buflen,
243 int *errnop, int *h_errnop,
244 int32_t *ttlp,
245 char **canonp);
246
247 typedef enum nss_status (*_nss_gethostbyname2_r_t)(
248 const char *name,
249 int af,
250 struct hostent *result,
251 char *buffer, size_t buflen,
252 int *errnop, int *h_errnop);
253
254 typedef enum nss_status (*_nss_gethostbyname_r_t)(
255 const char *name,
256 struct hostent *result,
257 char *buffer, size_t buflen,
258 int *errnop, int *h_errnop);
259
260 typedef enum nss_status (*_nss_gethostbyaddr2_r_t)(
261 const void* addr, socklen_t len,
262 int af,
263 struct hostent *result,
264 char *buffer, size_t buflen,
265 int *errnop, int *h_errnop,
266 int32_t *ttlp);
267 typedef enum nss_status (*_nss_gethostbyaddr_r_t)(
268 const void* addr, socklen_t len,
269 int af,
270 struct hostent *host,
271 char *buffer, size_t buflen,
272 int *errnop, int *h_errnop);
273
274 typedef enum nss_status (*_nss_getpwnam_r_t)(
275 const char *name,
276 struct passwd *pwd,
277 char *buffer, size_t buflen,
278 int *errnop);
279 typedef enum nss_status (*_nss_getpwuid_r_t)(
280 uid_t uid,
281 struct passwd *pwd,
282 char *buffer, size_t buflen,
283 int *errnop);
284
285 typedef enum nss_status (*_nss_getgrnam_r_t)(
286 const char *name,
287 struct group *gr,
288 char *buffer, size_t buflen,
289 int *errnop);
290 typedef enum nss_status (*_nss_getgrgid_r_t)(
291 gid_t gid,
292 struct group *gr,
293 char *buffer, size_t buflen,
294 int *errnop);
295
296 typedef enum nss_status (*_nss_getsgnam_r_t)(
297 const char *name,
298 struct sgrp *sg,
299 char *buffer, size_t buflen,
300 int *errnop);