]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/nss-util.h
Merge pull request #1359 from jengelh/ue
[thirdparty/systemd.git] / src / basic / nss-util.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6 This file is part of systemd.
7
8 Copyright 2014 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <grp.h>
25 #include <netdb.h>
26 #include <nss.h>
27 #include <pwd.h>
28 #include <resolv.h>
29
30 #define NSS_GETHOSTBYNAME_PROTOTYPES(module) \
31 enum nss_status _nss_##module##_gethostbyname4_r( \
32 const char *name, \
33 struct gaih_addrtuple **pat, \
34 char *buffer, size_t buflen, \
35 int *errnop, int *h_errnop, \
36 int32_t *ttlp) _public_; \
37 enum nss_status _nss_##module##_gethostbyname3_r( \
38 const char *name, \
39 int af, \
40 struct hostent *host, \
41 char *buffer, size_t buflen, \
42 int *errnop, int *h_errnop, \
43 int32_t *ttlp, \
44 char **canonp) _public_; \
45 enum nss_status _nss_##module##_gethostbyname2_r( \
46 const char *name, \
47 int af, \
48 struct hostent *host, \
49 char *buffer, size_t buflen, \
50 int *errnop, int *h_errnop) _public_; \
51 enum nss_status _nss_##module##_gethostbyname_r( \
52 const char *name, \
53 struct hostent *host, \
54 char *buffer, size_t buflen, \
55 int *errnop, int *h_errnop) _public_
56
57 #define NSS_GETHOSTBYADDR_PROTOTYPES(module) \
58 enum nss_status _nss_##module##_gethostbyaddr2_r( \
59 const void* addr, socklen_t len, \
60 int af, \
61 struct hostent *host, \
62 char *buffer, size_t buflen, \
63 int *errnop, int *h_errnop, \
64 int32_t *ttlp) _public_; \
65 enum nss_status _nss_##module##_gethostbyaddr_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) _public_
71
72 #define NSS_GETHOSTBYNAME_FALLBACKS(module) \
73 enum nss_status _nss_##module##_gethostbyname2_r( \
74 const char *name, \
75 int af, \
76 struct hostent *host, \
77 char *buffer, size_t buflen, \
78 int *errnop, int *h_errnop) { \
79 return _nss_##module##_gethostbyname3_r( \
80 name, \
81 af, \
82 host, \
83 buffer, buflen, \
84 errnop, h_errnop, \
85 NULL, \
86 NULL); \
87 } \
88 enum nss_status _nss_##module##_gethostbyname_r( \
89 const char *name, \
90 struct hostent *host, \
91 char *buffer, size_t buflen, \
92 int *errnop, int *h_errnop) { \
93 enum nss_status ret = NSS_STATUS_NOTFOUND; \
94 \
95 if (_res.options & RES_USE_INET6) \
96 ret = _nss_##module##_gethostbyname3_r( \
97 name, \
98 AF_INET6, \
99 host, \
100 buffer, buflen, \
101 errnop, h_errnop, \
102 NULL, \
103 NULL); \
104 if (ret == NSS_STATUS_NOTFOUND) \
105 ret = _nss_##module##_gethostbyname3_r( \
106 name, \
107 AF_INET, \
108 host, \
109 buffer, buflen, \
110 errnop, h_errnop, \
111 NULL, \
112 NULL); \
113 return ret; \
114 } \
115 struct __useless_struct_to_allow_trailing_semicolon__
116
117 #define NSS_GETHOSTBYADDR_FALLBACKS(module) \
118 enum nss_status _nss_##module##_gethostbyaddr_r( \
119 const void* addr, socklen_t len, \
120 int af, \
121 struct hostent *host, \
122 char *buffer, size_t buflen, \
123 int *errnop, int *h_errnop) { \
124 return _nss_##module##_gethostbyaddr2_r( \
125 addr, len, \
126 af, \
127 host, \
128 buffer, buflen, \
129 errnop, h_errnop, \
130 NULL); \
131 } \
132 struct __useless_struct_to_allow_trailing_semicolon__
133
134 #define NSS_GETPW_PROTOTYPES(module) \
135 enum nss_status _nss_##module##_getpwnam_r( \
136 const char *name, \
137 struct passwd *pwd, \
138 char *buffer, size_t buflen, \
139 int *errnop) _public_; \
140 enum nss_status _nss_mymachines_getpwuid_r( \
141 uid_t uid, \
142 struct passwd *pwd, \
143 char *buffer, size_t buflen, \
144 int *errnop) _public_
145
146 #define NSS_GETGR_PROTOTYPES(module) \
147 enum nss_status _nss_##module##_getgrnam_r( \
148 const char *name, \
149 struct group *gr, \
150 char *buffer, size_t buflen, \
151 int *errnop) _public_; \
152 enum nss_status _nss_##module##_getgrgid_r( \
153 gid_t gid, \
154 struct group *gr, \
155 char *buffer, size_t buflen, \
156 int *errnop) _public_