]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/nss-util.h
Merge pull request #8106 from dqminh/route-expires-kernel
[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
121 #define NSS_GETHOSTBYADDR_FALLBACKS(module) \
122 enum nss_status _nss_##module##_gethostbyaddr_r( \
123 const void* addr, socklen_t len, \
124 int af, \
125 struct hostent *host, \
126 char *buffer, size_t buflen, \
127 int *errnop, int *h_errnop) { \
128 return _nss_##module##_gethostbyaddr2_r( \
129 addr, len, \
130 af, \
131 host, \
132 buffer, buflen, \
133 errnop, h_errnop, \
134 NULL); \
135 }
136
137 #define NSS_GETPW_PROTOTYPES(module) \
138 enum nss_status _nss_##module##_getpwnam_r( \
139 const char *name, \
140 struct passwd *pwd, \
141 char *buffer, size_t buflen, \
142 int *errnop) _public_; \
143 enum nss_status _nss_##module##_getpwuid_r( \
144 uid_t uid, \
145 struct passwd *pwd, \
146 char *buffer, size_t buflen, \
147 int *errnop) _public_
148
149 #define NSS_GETGR_PROTOTYPES(module) \
150 enum nss_status _nss_##module##_getgrnam_r( \
151 const char *name, \
152 struct group *gr, \
153 char *buffer, size_t buflen, \
154 int *errnop) _public_; \
155 enum nss_status _nss_##module##_getgrgid_r( \
156 gid_t gid, \
157 struct group *gr, \
158 char *buffer, size_t buflen, \
159 int *errnop) _public_
160
161 typedef enum nss_status (*_nss_gethostbyname4_r_t)(
162 const char *name,
163 struct gaih_addrtuple **pat,
164 char *buffer, size_t buflen,
165 int *errnop, int *h_errnop,
166 int32_t *ttlp);
167
168 typedef enum nss_status (*_nss_gethostbyname3_r_t)(
169 const char *name,
170 int af,
171 struct hostent *result,
172 char *buffer, size_t buflen,
173 int *errnop, int *h_errnop,
174 int32_t *ttlp,
175 char **canonp);
176
177 typedef enum nss_status (*_nss_gethostbyname2_r_t)(
178 const char *name,
179 int af,
180 struct hostent *result,
181 char *buffer, size_t buflen,
182 int *errnop, int *h_errnop);
183
184 typedef enum nss_status (*_nss_gethostbyname_r_t)(
185 const char *name,
186 struct hostent *result,
187 char *buffer, size_t buflen,
188 int *errnop, int *h_errnop);
189
190 typedef enum nss_status (*_nss_gethostbyaddr2_r_t)(
191 const void* addr, socklen_t len,
192 int af,
193 struct hostent *result,
194 char *buffer, size_t buflen,
195 int *errnop, int *h_errnop,
196 int32_t *ttlp);
197 typedef enum nss_status (*_nss_gethostbyaddr_r_t)(
198 const void* addr, socklen_t len,
199 int af,
200 struct hostent *host,
201 char *buffer, size_t buflen,
202 int *errnop, int *h_errnop);