]>
Commit | Line | Data |
---|---|---|
6679571b MT |
1 | Check if we can use thread-local storage, and if we can, use one to avoid a |
2 | self-deadlock if we recurse into our own host resolution routines from inside | |
3 | of another lookup attempt. Revised from patch originally submitted for #340. | |
4 | ||
5 | diff -up nss_ldap-265/config.h.in nss_ldap-265/config.h.in | |
6 | --- nss_ldap-265/config.h.in 2009-11-06 05:28:08.000000000 -0500 | |
7 | +++ nss_ldap-265/config.h.in 2010-01-08 17:29:49.000000000 -0500 | |
8 | @@ -304,6 +304,11 @@ | |
9 | /* Define to 1 if you have the <thread.h> header file. */ | |
10 | #undef HAVE_THREAD_H | |
11 | ||
12 | +/* Define if your toolchain supports thread-local storage, which can be used | |
13 | + for detecting self- and mutual-recursion problems when performing | |
14 | + host/address lookups. */ | |
15 | +#undef HAVE_THREAD_LOCAL_STORAGE | |
16 | + | |
17 | /* Define to 1 if you have the <unistd.h> header file. */ | |
18 | #undef HAVE_UNISTD_H | |
19 | ||
20 | diff -up nss_ldap-265/configure.in nss_ldap-265/configure.in | |
21 | --- nss_ldap-265/configure.in 2009-11-06 05:28:08.000000000 -0500 | |
22 | +++ nss_ldap-265/configure.in 2010-01-08 17:29:49.000000000 -0500 | |
23 | @@ -27,6 +27,14 @@ dnl | |
24 | ||
25 | AC_ARG_ENABLE(debugging, [ --enable-debugging enable debug code ], [AC_DEFINE(DEBUG)]) | |
26 | ||
27 | +AC_MSG_CHECKING(for thread-local storage) | |
28 | +AC_TRY_COMPILE([],[static __thread int _nss_ldap_recursion_count;], | |
29 | + [ | |
30 | + AC_MSG_RESULT(yes) | |
31 | + AC_DEFINE(HAVE_THREAD_LOCAL_STORAGE,1,[Define if your toolchain supports thread-local storage, which can be used for detecting self- and mutual-recursion problems when performing host/address lookups.]) | |
32 | + ], | |
33 | + AC_MSG_RESULT(no)) | |
34 | + | |
35 | dnl | |
36 | dnl --enable-paged-results is now deprecated; if this option is set, | |
37 | dnl then paged results will be enabled by default. However, it can | |
38 | diff -up nss_ldap-265/depth.c nss_ldap-265/depth.c | |
39 | --- nss_ldap-265/depth.c 2010-01-08 17:29:49.000000000 -0500 | |
40 | +++ nss_ldap-265/depth.c 2010-01-08 17:29:49.000000000 -0500 | |
41 | @@ -0,0 +1,24 @@ | |
42 | +#include "config.h" | |
43 | +#include "depth.h" | |
44 | + | |
45 | +#ifdef HAVE_THREAD_LOCAL_STORAGE | |
46 | +static __thread int depth = 0; | |
47 | + | |
48 | +int | |
49 | +_nss_ldap_get_depth (void) | |
50 | +{ | |
51 | + return depth; | |
52 | +} | |
53 | + | |
54 | +int | |
55 | +_nss_ldap_inc_depth (void) | |
56 | +{ | |
57 | + return ++depth; | |
58 | +} | |
59 | + | |
60 | +int | |
61 | +_nss_ldap_dec_depth (void) | |
62 | +{ | |
63 | + return --depth; | |
64 | +} | |
65 | +#endif | |
66 | diff -up nss_ldap-265/depth.h nss_ldap-265/depth.h | |
67 | --- nss_ldap-265/depth.h 2010-01-08 17:29:49.000000000 -0500 | |
68 | +++ nss_ldap-265/depth.h 2010-01-08 17:29:49.000000000 -0500 | |
69 | @@ -0,0 +1,3 @@ | |
70 | +int _nss_ldap_get_depth (void); | |
71 | +int _nss_ldap_inc_depth (void); | |
72 | +int _nss_ldap_dec_depth (void); | |
73 | diff -up nss_ldap-265/ldap-hosts.c nss_ldap-265/ldap-hosts.c | |
74 | --- nss_ldap-265/ldap-hosts.c 2009-11-06 05:28:08.000000000 -0500 | |
75 | +++ nss_ldap-265/ldap-hosts.c 2010-01-08 17:33:38.000000000 -0500 | |
76 | @@ -66,6 +66,7 @@ static char rcsId[] = | |
77 | #include "ldap-nss.h" | |
78 | #include "ldap-hosts.h" | |
79 | #include "util.h" | |
80 | +#include "depth.h" | |
81 | ||
82 | #ifdef HAVE_PORT_AFTER_H | |
83 | #include <port_after.h> | |
84 | @@ -280,6 +281,11 @@ _nss_ldap_gethostbyname2_r (const char * | |
85 | } | |
86 | #endif | |
87 | ||
88 | +#ifdef HAVE_THREAD_LOCAL_STORAGE | |
89 | + if (_nss_ldap_get_depth() > 0) | |
90 | + return NSS_STATUS_UNAVAIL; | |
91 | +#endif | |
92 | + | |
93 | LA_INIT (a); | |
94 | LA_STRING (a) = name; | |
95 | LA_TYPE (a) = LA_TYPE_STRING; | |
96 | @@ -355,6 +361,11 @@ _nss_ldap_gethostbyaddr_r (struct in_add | |
97 | NSS_STATUS status; | |
98 | ldap_args_t a; | |
99 | ||
100 | +#ifdef HAVE_THREAD_LOCAL_STORAGE | |
101 | + if (_nss_ldap_get_depth() > 0) | |
102 | + return NSS_STATUS_UNAVAIL; | |
103 | +#endif | |
104 | + | |
105 | /* if querying by IPv6 address, make sure the address is "normalized" -- | |
106 | * it should contain no leading zeros and all components of the address. | |
107 | * still we can't fit an IPv6 address in an int, so who cares for now. | |
108 | @@ -391,6 +402,11 @@ _nss_ldap_sethostent_r (nss_backend_t * | |
109 | #endif | |
110 | #if defined(HAVE_NSS_H) || defined(HAVE_NSSWITCH_H) | |
111 | { | |
112 | +#ifdef HAVE_THREAD_LOCAL_STORAGE | |
113 | + if (_nss_ldap_get_depth() > 0) | |
114 | + return NSS_STATUS_UNAVAIL; | |
115 | +#endif | |
116 | + | |
117 | LOOKUP_SETENT (hosts_context); | |
118 | } | |
119 | #endif | |
120 | @@ -403,6 +419,11 @@ _nss_ldap_endhostent_r (nss_backend_t * | |
121 | #endif | |
122 | #if defined(HAVE_NSS_H) || defined(HAVE_NSSWITCH_H) | |
123 | { | |
124 | +#ifdef HAVE_THREAD_LOCAL_STORAGE | |
125 | + if (_nss_ldap_get_depth() > 0) | |
126 | + return NSS_STATUS_UNAVAIL; | |
127 | +#endif | |
128 | + | |
129 | LOOKUP_ENDENT (hosts_context); | |
130 | } | |
131 | #endif | |
132 | @@ -435,6 +456,11 @@ _nss_ldap_gethostent_r (struct hostent * | |
133 | { | |
134 | NSS_STATUS status; | |
135 | ||
136 | +#ifdef HAVE_THREAD_LOCAL_STORAGE | |
137 | + if (_nss_ldap_get_depth() > 0) | |
138 | + return NSS_STATUS_UNAVAIL; | |
139 | +#endif | |
140 | + | |
141 | status = _nss_ldap_getent (&hosts_context, | |
142 | result, | |
143 | buffer, | |
144 | diff -up nss_ldap-265/ldap-nss.c nss_ldap-265/ldap-nss.c | |
145 | --- nss_ldap-265/ldap-nss.c 2009-11-06 05:28:08.000000000 -0500 | |
146 | +++ nss_ldap-265/ldap-nss.c 2010-01-08 17:29:49.000000000 -0500 | |
147 | @@ -93,6 +93,7 @@ static char rcsId[] = | |
148 | #include "util.h" | |
149 | #include "dnsconfig.h" | |
150 | #include "pagectrl.h" | |
151 | +#include "depth.h" | |
152 | ||
153 | #if defined(HAVE_THREAD_H) && !defined(_AIX) | |
154 | #ifdef HAVE_PTHREAD_ATFORK | |
155 | @@ -578,6 +579,9 @@ _nss_ldap_enter (void) | |
156 | debug ("==> _nss_ldap_enter"); | |
157 | ||
158 | NSS_LDAP_LOCK (__lock); | |
159 | +#ifdef HAVE_THREAD_LOCAL_STORAGE | |
160 | + _nss_ldap_inc_depth(); | |
161 | +#endif | |
162 | ||
163 | /* | |
164 | * Patch for Debian Bug 130006: | |
165 | @@ -623,6 +627,9 @@ _nss_ldap_leave (void) | |
166 | } | |
167 | #endif /* HAVE_SIGACTION */ | |
168 | ||
169 | +#ifdef HAVE_THREAD_LOCAL_STORAGE | |
170 | + _nss_ldap_dec_depth(); | |
171 | +#endif | |
172 | NSS_LDAP_UNLOCK (__lock); | |
173 | ||
174 | debug ("<== _nss_ldap_leave"); | |
175 | diff -up nss_ldap-265/Makefile.am nss_ldap-265/Makefile.am | |
176 | --- nss_ldap-265/Makefile.am 2009-11-06 05:28:08.000000000 -0500 | |
177 | +++ nss_ldap-265/Makefile.am 2010-01-08 17:31:45.000000000 -0500 | |
178 | @@ -23,7 +23,7 @@ nss_ldap_so_SOURCES = ldap-nss.c ldap-pw | |
179 | ldap-alias.c ldap-service.c ldap-schema.c ldap-ethers.c \ | |
180 | ldap-bp.c ldap-automount.c util.c ltf.c snprintf.c resolve.c \ | |
181 | dnsconfig.c irs-nss.c pagectrl.c ldap-sldap.c ldap-init-krb5-cache.c \ | |
182 | - vers.c | |
183 | + vers.c depth.c | |
184 | ||
185 | nss_ldap_so_LDFLAGS = @nss_ldap_so_LDFLAGS@ | |
186 |