]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/nss-util.h
Merge pull request #8575 from keszybz/non-absolute-paths
[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
10 #include <grp.h>
11 #include <netdb.h>
12 #include <nss.h>
13 #include <pwd.h>
14 #include <resolv.h>
15
16 #define NSS_SIGNALS_BLOCK SIGALRM,SIGVTALRM,SIGPIPE,SIGCHLD,SIGTSTP,SIGIO,SIGHUP,SIGUSR1,SIGUSR2,SIGPROF,SIGURG,SIGWINCH
17
18 #ifndef DEPRECATED_RES_USE_INET6
19 # define DEPRECATED_RES_USE_INET6 0x00002000
20 #endif
21
22 #define NSS_GETHOSTBYNAME_PROTOTYPES(module) \
23 enum nss_status _nss_##module##_gethostbyname4_r( \
24 const char *name, \
25 struct gaih_addrtuple **pat, \
26 char *buffer, size_t buflen, \
27 int *errnop, int *h_errnop, \
28 int32_t *ttlp) _public_; \
29 enum nss_status _nss_##module##_gethostbyname3_r( \
30 const char *name, \
31 int af, \
32 struct hostent *host, \
33 char *buffer, size_t buflen, \
34 int *errnop, int *h_errnop, \
35 int32_t *ttlp, \
36 char **canonp) _public_; \
37 enum nss_status _nss_##module##_gethostbyname2_r( \
38 const char *name, \
39 int af, \
40 struct hostent *host, \
41 char *buffer, size_t buflen, \
42 int *errnop, int *h_errnop) _public_; \
43 enum nss_status _nss_##module##_gethostbyname_r( \
44 const char *name, \
45 struct hostent *host, \
46 char *buffer, size_t buflen, \
47 int *errnop, int *h_errnop) _public_
48
49 #define NSS_GETHOSTBYADDR_PROTOTYPES(module) \
50 enum nss_status _nss_##module##_gethostbyaddr2_r( \
51 const void* addr, socklen_t len, \
52 int af, \
53 struct hostent *host, \
54 char *buffer, size_t buflen, \
55 int *errnop, int *h_errnop, \
56 int32_t *ttlp) _public_; \
57 enum nss_status _nss_##module##_gethostbyaddr_r( \
58 const void* addr, socklen_t len, \
59 int af, \
60 struct hostent *host, \
61 char *buffer, size_t buflen, \
62 int *errnop, int *h_errnop) _public_
63
64 #define NSS_GETHOSTBYNAME_FALLBACKS(module) \
65 enum nss_status _nss_##module##_gethostbyname2_r( \
66 const char *name, \
67 int af, \
68 struct hostent *host, \
69 char *buffer, size_t buflen, \
70 int *errnop, int *h_errnop) { \
71 return _nss_##module##_gethostbyname3_r( \
72 name, \
73 af, \
74 host, \
75 buffer, buflen, \
76 errnop, h_errnop, \
77 NULL, \
78 NULL); \
79 } \
80 enum nss_status _nss_##module##_gethostbyname_r( \
81 const char *name, \
82 struct hostent *host, \
83 char *buffer, size_t buflen, \
84 int *errnop, int *h_errnop) { \
85 enum nss_status ret = NSS_STATUS_NOTFOUND; \
86 \
87 if (_res.options & DEPRECATED_RES_USE_INET6) \
88 ret = _nss_##module##_gethostbyname3_r( \
89 name, \
90 AF_INET6, \
91 host, \
92 buffer, buflen, \
93 errnop, h_errnop, \
94 NULL, \
95 NULL); \
96 if (ret == NSS_STATUS_NOTFOUND) \
97 ret = _nss_##module##_gethostbyname3_r( \
98 name, \
99 AF_INET, \
100 host, \
101 buffer, buflen, \
102 errnop, h_errnop, \
103 NULL, \
104 NULL); \
105 return ret; \
106 }
107
108 #define NSS_GETHOSTBYADDR_FALLBACKS(module) \
109 enum nss_status _nss_##module##_gethostbyaddr_r( \
110 const void* addr, socklen_t len, \
111 int af, \
112 struct hostent *host, \
113 char *buffer, size_t buflen, \
114 int *errnop, int *h_errnop) { \
115 return _nss_##module##_gethostbyaddr2_r( \
116 addr, len, \
117 af, \
118 host, \
119 buffer, buflen, \
120 errnop, h_errnop, \
121 NULL); \
122 }
123
124 #define NSS_GETPW_PROTOTYPES(module) \
125 enum nss_status _nss_##module##_getpwnam_r( \
126 const char *name, \
127 struct passwd *pwd, \
128 char *buffer, size_t buflen, \
129 int *errnop) _public_; \
130 enum nss_status _nss_##module##_getpwuid_r( \
131 uid_t uid, \
132 struct passwd *pwd, \
133 char *buffer, size_t buflen, \
134 int *errnop) _public_
135
136 #define NSS_GETGR_PROTOTYPES(module) \
137 enum nss_status _nss_##module##_getgrnam_r( \
138 const char *name, \
139 struct group *gr, \
140 char *buffer, size_t buflen, \
141 int *errnop) _public_; \
142 enum nss_status _nss_##module##_getgrgid_r( \
143 gid_t gid, \
144 struct group *gr, \
145 char *buffer, size_t buflen, \
146 int *errnop) _public_
147
148 typedef enum nss_status (*_nss_gethostbyname4_r_t)(
149 const char *name,
150 struct gaih_addrtuple **pat,
151 char *buffer, size_t buflen,
152 int *errnop, int *h_errnop,
153 int32_t *ttlp);
154
155 typedef enum nss_status (*_nss_gethostbyname3_r_t)(
156 const char *name,
157 int af,
158 struct hostent *result,
159 char *buffer, size_t buflen,
160 int *errnop, int *h_errnop,
161 int32_t *ttlp,
162 char **canonp);
163
164 typedef enum nss_status (*_nss_gethostbyname2_r_t)(
165 const char *name,
166 int af,
167 struct hostent *result,
168 char *buffer, size_t buflen,
169 int *errnop, int *h_errnop);
170
171 typedef enum nss_status (*_nss_gethostbyname_r_t)(
172 const char *name,
173 struct hostent *result,
174 char *buffer, size_t buflen,
175 int *errnop, int *h_errnop);
176
177 typedef enum nss_status (*_nss_gethostbyaddr2_r_t)(
178 const void* addr, socklen_t len,
179 int af,
180 struct hostent *result,
181 char *buffer, size_t buflen,
182 int *errnop, int *h_errnop,
183 int32_t *ttlp);
184 typedef enum nss_status (*_nss_gethostbyaddr_r_t)(
185 const void* addr, socklen_t len,
186 int af,
187 struct hostent *host,
188 char *buffer, size_t buflen,
189 int *errnop, int *h_errnop);