]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/nss-util.h
Merge pull request #6910 from ssahani/issue-6359
[thirdparty/systemd.git] / src / basic / nss-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2014 Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include <grp.h>
24 #include <netdb.h>
25 #include <nss.h>
26 #include <pwd.h>
27 #include <resolv.h>
28
29 #define NSS_SIGNALS_BLOCK SIGALRM,SIGVTALRM,SIGPIPE,SIGCHLD,SIGTSTP,SIGIO,SIGHUP,SIGUSR1,SIGUSR2,SIGPROF,SIGURG,SIGWINCH
30
31 #ifndef DEPRECATED_RES_USE_INET6
32 # define DEPRECATED_RES_USE_INET6 0x00002000
33 #endif
34
35 #define NSS_GETHOSTBYNAME_PROTOTYPES(module) \
36 enum nss_status _nss_##module##_gethostbyname4_r( \
37 const char *name, \
38 struct gaih_addrtuple **pat, \
39 char *buffer, size_t buflen, \
40 int *errnop, int *h_errnop, \
41 int32_t *ttlp) _public_; \
42 enum nss_status _nss_##module##_gethostbyname3_r( \
43 const char *name, \
44 int af, \
45 struct hostent *host, \
46 char *buffer, size_t buflen, \
47 int *errnop, int *h_errnop, \
48 int32_t *ttlp, \
49 char **canonp) _public_; \
50 enum nss_status _nss_##module##_gethostbyname2_r( \
51 const char *name, \
52 int af, \
53 struct hostent *host, \
54 char *buffer, size_t buflen, \
55 int *errnop, int *h_errnop) _public_; \
56 enum nss_status _nss_##module##_gethostbyname_r( \
57 const char *name, \
58 struct hostent *host, \
59 char *buffer, size_t buflen, \
60 int *errnop, int *h_errnop) _public_
61
62 #define NSS_GETHOSTBYADDR_PROTOTYPES(module) \
63 enum nss_status _nss_##module##_gethostbyaddr2_r( \
64 const void* addr, socklen_t len, \
65 int af, \
66 struct hostent *host, \
67 char *buffer, size_t buflen, \
68 int *errnop, int *h_errnop, \
69 int32_t *ttlp) _public_; \
70 enum nss_status _nss_##module##_gethostbyaddr_r( \
71 const void* addr, socklen_t len, \
72 int af, \
73 struct hostent *host, \
74 char *buffer, size_t buflen, \
75 int *errnop, int *h_errnop) _public_
76
77 #define NSS_GETHOSTBYNAME_FALLBACKS(module) \
78 enum nss_status _nss_##module##_gethostbyname2_r( \
79 const char *name, \
80 int af, \
81 struct hostent *host, \
82 char *buffer, size_t buflen, \
83 int *errnop, int *h_errnop) { \
84 return _nss_##module##_gethostbyname3_r( \
85 name, \
86 af, \
87 host, \
88 buffer, buflen, \
89 errnop, h_errnop, \
90 NULL, \
91 NULL); \
92 } \
93 enum nss_status _nss_##module##_gethostbyname_r( \
94 const char *name, \
95 struct hostent *host, \
96 char *buffer, size_t buflen, \
97 int *errnop, int *h_errnop) { \
98 enum nss_status ret = NSS_STATUS_NOTFOUND; \
99 \
100 if (_res.options & DEPRECATED_RES_USE_INET6) \
101 ret = _nss_##module##_gethostbyname3_r( \
102 name, \
103 AF_INET6, \
104 host, \
105 buffer, buflen, \
106 errnop, h_errnop, \
107 NULL, \
108 NULL); \
109 if (ret == NSS_STATUS_NOTFOUND) \
110 ret = _nss_##module##_gethostbyname3_r( \
111 name, \
112 AF_INET, \
113 host, \
114 buffer, buflen, \
115 errnop, h_errnop, \
116 NULL, \
117 NULL); \
118 return ret; \
119 } \
120 struct __useless_struct_to_allow_trailing_semicolon__
121
122 #define NSS_GETHOSTBYADDR_FALLBACKS(module) \
123 enum nss_status _nss_##module##_gethostbyaddr_r( \
124 const void* addr, socklen_t len, \
125 int af, \
126 struct hostent *host, \
127 char *buffer, size_t buflen, \
128 int *errnop, int *h_errnop) { \
129 return _nss_##module##_gethostbyaddr2_r( \
130 addr, len, \
131 af, \
132 host, \
133 buffer, buflen, \
134 errnop, h_errnop, \
135 NULL); \
136 } \
137 struct __useless_struct_to_allow_trailing_semicolon__
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_GETGR_PROTOTYPES(module) \
152 enum nss_status _nss_##module##_getgrnam_r( \
153 const char *name, \
154 struct group *gr, \
155 char *buffer, size_t buflen, \
156 int *errnop) _public_; \
157 enum nss_status _nss_##module##_getgrgid_r( \
158 gid_t gid, \
159 struct group *gr, \
160 char *buffer, size_t buflen, \
161 int *errnop) _public_
162
163 typedef enum nss_status (*_nss_gethostbyname4_r_t)(
164 const char *name,
165 struct gaih_addrtuple **pat,
166 char *buffer, size_t buflen,
167 int *errnop, int *h_errnop,
168 int32_t *ttlp);
169
170 typedef enum nss_status (*_nss_gethostbyname3_r_t)(
171 const char *name,
172 int af,
173 struct hostent *result,
174 char *buffer, size_t buflen,
175 int *errnop, int *h_errnop,
176 int32_t *ttlp,
177 char **canonp);
178
179 typedef enum nss_status (*_nss_gethostbyname2_r_t)(
180 const char *name,
181 int af,
182 struct hostent *result,
183 char *buffer, size_t buflen,
184 int *errnop, int *h_errnop);
185
186 typedef enum nss_status (*_nss_gethostbyname_r_t)(
187 const char *name,
188 struct hostent *result,
189 char *buffer, size_t buflen,
190 int *errnop, int *h_errnop);
191
192 typedef enum nss_status (*_nss_gethostbyaddr2_r_t)(
193 const void* addr, socklen_t len,
194 int af,
195 struct hostent *result,
196 char *buffer, size_t buflen,
197 int *errnop, int *h_errnop,
198 int32_t *ttlp);
199 typedef enum nss_status (*_nss_gethostbyaddr_r_t)(
200 const void* addr, socklen_t len,
201 int af,
202 struct hostent *host,
203 char *buffer, size_t buflen,
204 int *errnop, int *h_errnop);