Lines 66-74
Link Here
|
66 |
|
66 |
|
67 |
#ifdef APU_HAS_LDAP |
67 |
#ifdef APU_HAS_LDAP |
68 |
|
68 |
|
69 |
#define MODLDAP_SHMEM_CACHE "/tmp/mod_ldap_cache" |
|
|
70 |
|
71 |
|
72 |
/* ------------------------------------------------------------------ */ |
69 |
/* ------------------------------------------------------------------ */ |
73 |
|
70 |
|
74 |
unsigned long util_ldap_url_node_hash(void *n) |
71 |
unsigned long util_ldap_url_node_hash(void *n) |
Lines 85-98
Link Here
|
85 |
return(strcmp(na->url, nb->url) == 0); |
82 |
return(strcmp(na->url, nb->url) == 0); |
86 |
} |
83 |
} |
87 |
|
84 |
|
88 |
void *util_ldap_url_node_copy(void *c) |
85 |
void *util_ldap_url_node_copy(util_ldap_state_t *st, void *c) |
89 |
{ |
86 |
{ |
90 |
util_url_node_t *n = (util_url_node_t *)c; |
87 |
util_url_node_t *n = (util_url_node_t *)c; |
91 |
util_url_node_t *node = (util_url_node_t *)util_ald_alloc(sizeof(util_url_node_t)); |
88 |
util_url_node_t *node = (util_url_node_t *)util_ald_alloc(st, sizeof(util_url_node_t)); |
92 |
|
89 |
|
93 |
if (node) { |
90 |
if (node) { |
94 |
if (!(node->url = util_ald_strdup(n->url))) { |
91 |
if (!(node->url = util_ald_strdup(st, n->url))) { |
95 |
util_ald_free(node->url); |
92 |
util_ald_free(st, node->url); |
96 |
return NULL; |
93 |
return NULL; |
97 |
} |
94 |
} |
98 |
node->search_cache = n->search_cache; |
95 |
node->search_cache = n->search_cache; |
Lines 105-119
Link Here
|
105 |
} |
102 |
} |
106 |
} |
103 |
} |
107 |
|
104 |
|
108 |
void util_ldap_url_node_free(void *n) |
105 |
void util_ldap_url_node_free(util_ldap_state_t *st, void *n) |
109 |
{ |
106 |
{ |
110 |
util_url_node_t *node = (util_url_node_t *)n; |
107 |
util_url_node_t *node = (util_url_node_t *)n; |
111 |
|
108 |
|
112 |
util_ald_free(node->url); |
109 |
util_ald_free(st, node->url); |
113 |
util_ald_destroy_cache(node->search_cache); |
110 |
util_ald_destroy_cache(st, node->search_cache); |
114 |
util_ald_destroy_cache(node->compare_cache); |
111 |
util_ald_destroy_cache(st, node->compare_cache); |
115 |
util_ald_destroy_cache(node->dn_compare_cache); |
112 |
util_ald_destroy_cache(st, node->dn_compare_cache); |
116 |
util_ald_free(node); |
113 |
util_ald_free(st, node); |
117 |
} |
114 |
} |
118 |
|
115 |
|
119 |
/* ------------------------------------------------------------------ */ |
116 |
/* ------------------------------------------------------------------ */ |
Lines 131-140
Link Here
|
131 |
((util_search_node_t *)b)->username) == 0); |
128 |
((util_search_node_t *)b)->username) == 0); |
132 |
} |
129 |
} |
133 |
|
130 |
|
134 |
void *util_ldap_search_node_copy(void *c) |
131 |
void *util_ldap_search_node_copy(util_ldap_state_t *st, void *c) |
135 |
{ |
132 |
{ |
136 |
util_search_node_t *node = (util_search_node_t *)c; |
133 |
util_search_node_t *node = (util_search_node_t *)c; |
137 |
util_search_node_t *newnode = util_ald_alloc(sizeof(util_search_node_t)); |
134 |
util_search_node_t *newnode = util_ald_alloc(st, sizeof(util_search_node_t)); |
138 |
|
135 |
|
139 |
/* safety check */ |
136 |
/* safety check */ |
140 |
if (newnode) { |
137 |
if (newnode) { |
Lines 144-156
Link Here
|
144 |
int k = 0; |
141 |
int k = 0; |
145 |
int i = 0; |
142 |
int i = 0; |
146 |
while (node->vals[k++]); |
143 |
while (node->vals[k++]); |
147 |
if (!(newnode->vals = util_ald_alloc(sizeof(char *) * (k+1)))) { |
144 |
if (!(newnode->vals = util_ald_alloc(st, sizeof(char *) * (k+1)))) { |
148 |
util_ldap_search_node_free(newnode); |
145 |
util_ldap_search_node_free(st, newnode); |
149 |
return NULL; |
146 |
return NULL; |
150 |
} |
147 |
} |
151 |
while (node->vals[i]) { |
148 |
while (node->vals[i]) { |
152 |
if (!(newnode->vals[i] = util_ald_strdup(node->vals[i]))) { |
149 |
if (!(newnode->vals[i] = util_ald_strdup(st, node->vals[i]))) { |
153 |
util_ldap_search_node_free(newnode); |
150 |
util_ldap_search_node_free(st, newnode); |
154 |
return NULL; |
151 |
return NULL; |
155 |
} |
152 |
} |
156 |
i++; |
153 |
i++; |
Lines 159-168
Link Here
|
159 |
else { |
156 |
else { |
160 |
newnode->vals = NULL; |
157 |
newnode->vals = NULL; |
161 |
} |
158 |
} |
162 |
if (!(newnode->username = util_ald_strdup(node->username)) || |
159 |
if (!(newnode->username = util_ald_strdup(st, node->username)) || |
163 |
!(newnode->dn = util_ald_strdup(node->dn)) || |
160 |
!(newnode->dn = util_ald_strdup(st, node->dn)) || |
164 |
!(newnode->bindpw = util_ald_strdup(node->bindpw)) ) { |
161 |
!(newnode->bindpw = util_ald_strdup(st, node->bindpw)) ) { |
165 |
util_ldap_search_node_free(newnode); |
162 |
util_ldap_search_node_free(st, newnode); |
166 |
return NULL; |
163 |
return NULL; |
167 |
} |
164 |
} |
168 |
newnode->lastbind = node->lastbind; |
165 |
newnode->lastbind = node->lastbind; |
Lines 171-190
Link Here
|
171 |
return (void *)newnode; |
168 |
return (void *)newnode; |
172 |
} |
169 |
} |
173 |
|
170 |
|
174 |
void util_ldap_search_node_free(void *n) |
171 |
void util_ldap_search_node_free(util_ldap_state_t *st, void *n) |
175 |
{ |
172 |
{ |
176 |
int i = 0; |
173 |
int i = 0; |
177 |
util_search_node_t *node = (util_search_node_t *)n; |
174 |
util_search_node_t *node = (util_search_node_t *)n; |
178 |
if (node->vals) { |
175 |
if (node->vals) { |
179 |
while (node->vals[i]) { |
176 |
while (node->vals[i]) { |
180 |
util_ald_free(node->vals[i++]); |
177 |
util_ald_free(st, node->vals[i++]); |
181 |
} |
178 |
} |
182 |
util_ald_free(node->vals); |
179 |
util_ald_free(st, node->vals); |
183 |
} |
180 |
} |
184 |
util_ald_free(node->username); |
181 |
util_ald_free(st, node->username); |
185 |
util_ald_free(node->dn); |
182 |
util_ald_free(st, node->dn); |
186 |
util_ald_free(node->bindpw); |
183 |
util_ald_free(st, node->bindpw); |
187 |
util_ald_free(node); |
184 |
util_ald_free(st, node); |
188 |
} |
185 |
} |
189 |
|
186 |
|
190 |
/* ------------------------------------------------------------------ */ |
187 |
/* ------------------------------------------------------------------ */ |
Lines 204-219
Link Here
|
204 |
strcmp(na->value, nb->value) == 0); |
201 |
strcmp(na->value, nb->value) == 0); |
205 |
} |
202 |
} |
206 |
|
203 |
|
207 |
void *util_ldap_compare_node_copy(void *c) |
204 |
void *util_ldap_compare_node_copy(util_ldap_state_t *st, void *c) |
208 |
{ |
205 |
{ |
209 |
util_compare_node_t *n = (util_compare_node_t *)c; |
206 |
util_compare_node_t *n = (util_compare_node_t *)c; |
210 |
util_compare_node_t *node = (util_compare_node_t *)util_ald_alloc(sizeof(util_compare_node_t)); |
207 |
util_compare_node_t *node = (util_compare_node_t *)util_ald_alloc(st, sizeof(util_compare_node_t)); |
211 |
|
208 |
|
212 |
if (node) { |
209 |
if (node) { |
213 |
if (!(node->dn = util_ald_strdup(n->dn)) || |
210 |
if (!(node->dn = util_ald_strdup(st, n->dn)) || |
214 |
!(node->attrib = util_ald_strdup(n->attrib)) || |
211 |
!(node->attrib = util_ald_strdup(st, n->attrib)) || |
215 |
!(node->value = util_ald_strdup(n->value))) { |
212 |
!(node->value = util_ald_strdup(st, n->value))) { |
216 |
util_ldap_compare_node_free(node); |
213 |
util_ldap_compare_node_free(st, node); |
217 |
return NULL; |
214 |
return NULL; |
218 |
} |
215 |
} |
219 |
node->lastcompare = n->lastcompare; |
216 |
node->lastcompare = n->lastcompare; |
Lines 225-237
Link Here
|
225 |
} |
222 |
} |
226 |
} |
223 |
} |
227 |
|
224 |
|
228 |
void util_ldap_compare_node_free(void *n) |
225 |
void util_ldap_compare_node_free(util_ldap_state_t *st, void *n) |
229 |
{ |
226 |
{ |
230 |
util_compare_node_t *node = (util_compare_node_t *)n; |
227 |
util_compare_node_t *node = (util_compare_node_t *)n; |
231 |
util_ald_free(node->dn); |
228 |
util_ald_free(st, node->dn); |
232 |
util_ald_free(node->attrib); |
229 |
util_ald_free(st, node->attrib); |
233 |
util_ald_free(node->value); |
230 |
util_ald_free(st, node->value); |
234 |
util_ald_free(node); |
231 |
util_ald_free(st, node); |
235 |
} |
232 |
} |
236 |
|
233 |
|
237 |
/* ------------------------------------------------------------------ */ |
234 |
/* ------------------------------------------------------------------ */ |
Lines 247-260
Link Here
|
247 |
((util_dn_compare_node_t *)b)->reqdn) == 0); |
244 |
((util_dn_compare_node_t *)b)->reqdn) == 0); |
248 |
} |
245 |
} |
249 |
|
246 |
|
250 |
void *util_ldap_dn_compare_node_copy(void *c) |
247 |
void *util_ldap_dn_compare_node_copy(util_ldap_state_t *st, void *c) |
251 |
{ |
248 |
{ |
252 |
util_dn_compare_node_t *n = (util_dn_compare_node_t *)c; |
249 |
util_dn_compare_node_t *n = (util_dn_compare_node_t *)c; |
253 |
util_dn_compare_node_t *node = (util_dn_compare_node_t *)util_ald_alloc(sizeof(util_dn_compare_node_t)); |
250 |
util_dn_compare_node_t *node = (util_dn_compare_node_t *)util_ald_alloc(st, sizeof(util_dn_compare_node_t)); |
254 |
if (node) { |
251 |
if (node) { |
255 |
if (!(node->reqdn = util_ald_strdup(n->reqdn)) || |
252 |
if (!(node->reqdn = util_ald_strdup(st, n->reqdn)) || |
256 |
!(node->dn = util_ald_strdup(n->dn))) { |
253 |
!(node->dn = util_ald_strdup(st, n->dn))) { |
257 |
util_ldap_dn_compare_node_free(node); |
254 |
util_ldap_dn_compare_node_free(st, node); |
258 |
return NULL; |
255 |
return NULL; |
259 |
} |
256 |
} |
260 |
return node; |
257 |
return node; |
Lines 264-275
Link Here
|
264 |
} |
261 |
} |
265 |
} |
262 |
} |
266 |
|
263 |
|
267 |
void util_ldap_dn_compare_node_free(void *n) |
264 |
void util_ldap_dn_compare_node_free(util_ldap_state_t *st, void *n) |
268 |
{ |
265 |
{ |
269 |
util_dn_compare_node_t *node = (util_dn_compare_node_t *)n; |
266 |
util_dn_compare_node_t *node = (util_dn_compare_node_t *)n; |
270 |
util_ald_free(node->reqdn); |
267 |
util_ald_free(st, node->reqdn); |
271 |
util_ald_free(node->dn); |
268 |
util_ald_free(st, node->dn); |
272 |
util_ald_free(node); |
269 |
util_ald_free(st, node); |
273 |
} |
270 |
} |
274 |
|
271 |
|
275 |
|
272 |
|
Lines 279-324
Link Here
|
279 |
|
276 |
|
280 |
apr_status_t util_ldap_cache_module_kill(void *data) |
277 |
apr_status_t util_ldap_cache_module_kill(void *data) |
281 |
{ |
278 |
{ |
|
|
279 |
util_ldap_state_t *st = (util_ldap_state_t *) data; |
280 |
|
281 |
if (!st) { |
282 |
return -1; |
283 |
} |
284 |
|
282 |
#if APR_HAS_SHARED_MEMORY |
285 |
#if APR_HAS_SHARED_MEMORY |
283 |
if (util_ldap_shm != NULL) { |
286 |
if (st->util_ldap_shm != NULL) { |
284 |
apr_status_t result = apr_shm_destroy(util_ldap_shm); |
287 |
apr_status_t result = apr_shm_destroy(st->util_ldap_shm); |
285 |
util_ldap_shm = NULL; |
288 |
st->util_ldap_shm = NULL; |
|
|
289 |
|
290 |
/* Remove cache file */ |
291 |
unlink(st->shm_file); |
286 |
return result; |
292 |
return result; |
287 |
} |
293 |
} |
288 |
#endif |
294 |
#endif |
289 |
util_ald_destroy_cache(util_ldap_cache); |
295 |
util_ald_destroy_cache(st, st->ldap_cache); |
290 |
return APR_SUCCESS; |
296 |
return APR_SUCCESS; |
291 |
} |
297 |
} |
292 |
|
298 |
|
293 |
apr_status_t util_ldap_cache_init(apr_pool_t *pool, apr_size_t reqsize) |
299 |
apr_status_t util_ldap_cache_init(void *data) |
294 |
{ |
300 |
{ |
|
|
301 |
util_ldap_state_t *st = (util_ldap_state_t *) data; |
302 |
|
303 |
if (!st) { |
304 |
return -1; |
305 |
} |
306 |
|
295 |
#if APR_HAS_SHARED_MEMORY |
307 |
#if APR_HAS_SHARED_MEMORY |
296 |
apr_status_t result; |
308 |
apr_status_t result; |
|
|
309 |
char *filename = NULL; |
310 |
|
311 |
/* if no cache file specified - create default */ |
312 |
if (!st->shm_file) { |
313 |
filename = (char *)apr_psprintf(st->pool, "logs/ldap_cache"); |
314 |
} |
315 |
|
316 |
filename = st->shm_file; |
317 |
st->shm_file = ap_server_root_relative(st->pool, filename); |
318 |
|
319 |
result = apr_shm_create(&(st->util_ldap_shm), st->cache_bytes, st->shm_file, st->pool); |
297 |
|
320 |
|
298 |
result = apr_shm_create(&util_ldap_shm, reqsize, MODLDAP_SHMEM_CACHE, pool); |
|
|
299 |
if (result == EEXIST) { |
300 |
/* |
301 |
* The cache could have already been created (i.e. we may be a child process). See |
302 |
* if we can attach to the existing shared memory |
303 |
*/ |
304 |
result = apr_shm_attach(&util_ldap_shm, MODLDAP_SHMEM_CACHE, pool); |
305 |
} |
306 |
if (result != APR_SUCCESS) { |
321 |
if (result != APR_SUCCESS) { |
307 |
return result; |
322 |
return result; |
308 |
} |
323 |
} |
309 |
|
324 |
|
310 |
/* This will create a rmm "handler" to get into the shared memory area */ |
325 |
/* This will create a rmm "handler" to get into the shared memory area */ |
311 |
apr_rmm_init(&util_ldap_rmm, NULL, |
326 |
apr_rmm_init(&(st->util_ldap_rmm), NULL, |
312 |
(void *)apr_shm_baseaddr_get(util_ldap_shm), reqsize, pool); |
327 |
(void *)apr_shm_baseaddr_get(st->util_ldap_shm), st->cache_bytes, st->pool); |
313 |
#endif |
328 |
#endif |
314 |
|
329 |
|
315 |
apr_pool_cleanup_register(pool, NULL, util_ldap_cache_module_kill, apr_pool_cleanup_null); |
330 |
apr_pool_cleanup_register(st->pool, NULL, util_ldap_cache_module_kill, apr_pool_cleanup_null); |
316 |
|
331 |
|
317 |
util_ldap_cache = util_ald_create_cache(50, |
332 |
st->ldap_cache = (util_ald_cache_t *) util_ald_create_cache(st, |
318 |
util_ldap_url_node_hash, |
333 |
50, |
319 |
util_ldap_url_node_compare, |
334 |
util_ldap_url_node_hash, |
320 |
util_ldap_url_node_copy, |
335 |
util_ldap_url_node_compare, |
321 |
util_ldap_url_node_free); |
336 |
util_ldap_url_node_copy, |
|
|
337 |
util_ldap_url_node_free); |
322 |
return APR_SUCCESS; |
338 |
return APR_SUCCESS; |
323 |
} |
339 |
} |
324 |
|
340 |
|