]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/nss-util.h
nss: block various signals while running NSS lookups
[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_SIGNALS_BLOCK SIGALRM,SIGVTALRM,SIGPIPE,SIGCHLD,SIGTSTP,SIGIO,SIGHUP,SIGUSR1,SIGUSR2,SIGPROF,SIGURG,SIGWINCH
31
32 #define NSS_GETHOSTBYNAME_PROTOTYPES(module) \
33 enum nss_status _nss_##module##_gethostbyname4_r( \
34 const char *name, \
35 struct gaih_addrtuple **pat, \
36 char *buffer, size_t buflen, \
37 int *errnop, int *h_errnop, \
38 int32_t *ttlp) _public_; \
39 enum nss_status _nss_##module##_gethostbyname3_r( \
40 const char *name, \
41 int af, \
42 struct hostent *host, \
43 char *buffer, size_t buflen, \
44 int *errnop, int *h_errnop, \
45 int32_t *ttlp, \
46 char **canonp) _public_; \
47 enum nss_status _nss_##module##_gethostbyname2_r( \
48 const char *name, \
49 int af, \
50 struct hostent *host, \
51 char *buffer, size_t buflen, \
52 int *errnop, int *h_errnop) _public_; \
53 enum nss_status _nss_##module##_gethostbyname_r( \
54 const char *name, \
55 struct hostent *host, \
56 char *buffer, size_t buflen, \
57 int *errnop, int *h_errnop) _public_
58
59 #define NSS_GETHOSTBYADDR_PROTOTYPES(module) \
60 enum nss_status _nss_##module##_gethostbyaddr2_r( \
61 const void* addr, socklen_t len, \
62 int af, \
63 struct hostent *host, \
64 char *buffer, size_t buflen, \
65 int *errnop, int *h_errnop, \
66 int32_t *ttlp) _public_; \
67 enum nss_status _nss_##module##_gethostbyaddr_r( \
68 const void* addr, socklen_t len, \
69 int af, \
70 struct hostent *host, \
71 char *buffer, size_t buflen, \
72 int *errnop, int *h_errnop) _public_
73
74 #define NSS_GETHOSTBYNAME_FALLBACKS(module) \
75 enum nss_status _nss_##module##_gethostbyname2_r( \
76 const char *name, \
77 int af, \
78 struct hostent *host, \
79 char *buffer, size_t buflen, \
80 int *errnop, int *h_errnop) { \
81 return _nss_##module##_gethostbyname3_r( \
82 name, \
83 af, \
84 host, \
85 buffer, buflen, \
86 errnop, h_errnop, \
87 NULL, \
88 NULL); \
89 } \
90 enum nss_status _nss_##module##_gethostbyname_r( \
91 const char *name, \
92 struct hostent *host, \
93 char *buffer, size_t buflen, \
94 int *errnop, int *h_errnop) { \
95 enum nss_status ret = NSS_STATUS_NOTFOUND; \
96 \
97 if (_res.options & RES_USE_INET6) \
98 ret = _nss_##module##_gethostbyname3_r( \
99 name, \
100 AF_INET6, \
101 host, \
102 buffer, buflen, \
103 errnop, h_errnop, \
104 NULL, \
105 NULL); \
106 if (ret == NSS_STATUS_NOTFOUND) \
107 ret = _nss_##module##_gethostbyname3_r( \
108 name, \
109 AF_INET, \
110 host, \
111 buffer, buflen, \
112 errnop, h_errnop, \
113 NULL, \
114 NULL); \
115 return ret; \
116 } \
117 struct __useless_struct_to_allow_trailing_semicolon__
118
119 #define NSS_GETHOSTBYADDR_FALLBACKS(module) \
120 enum nss_status _nss_##module##_gethostbyaddr_r( \
121 const void* addr, socklen_t len, \
122 int af, \
123 struct hostent *host, \
124 char *buffer, size_t buflen, \
125 int *errnop, int *h_errnop) { \
126 return _nss_##module##_gethostbyaddr2_r( \
127 addr, len, \
128 af, \
129 host, \
130 buffer, buflen, \
131 errnop, h_errnop, \
132 NULL); \
133 } \
134 struct __useless_struct_to_allow_trailing_semicolon__
135
136 #define NSS_GETPW_PROTOTYPES(module) \
137 enum nss_status _nss_##module##_getpwnam_r( \
138 const char *name, \
139 struct passwd *pwd, \
140 char *buffer, size_t buflen, \
141 int *errnop) _public_; \
142 enum nss_status _nss_mymachines_getpwuid_r( \
143 uid_t uid, \
144 struct passwd *pwd, \
145 char *buffer, size_t buflen, \
146 int *errnop) _public_
147
148 #define NSS_GETGR_PROTOTYPES(module) \
149 enum nss_status _nss_##module##_getgrnam_r( \
150 const char *name, \
151 struct group *gr, \
152 char *buffer, size_t buflen, \
153 int *errnop) _public_; \
154 enum nss_status _nss_##module##_getgrgid_r( \
155 gid_t gid, \
156 struct group *gr, \
157 char *buffer, size_t buflen, \
158 int *errnop) _public_