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