Apache HTTPD
util_ldap_cache.h
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef APU_LDAP_CACHE_H
18#define APU_LDAP_CACHE_H
19
25/* this whole thing disappears if LDAP is not enabled */
26#if APR_HAS_LDAP
27
28
29/*
30 * LDAP Cache Manager
31 */
32
33#include "util_ldap.h"
34
35typedef struct util_cache_node_t {
36 void *payload; /* Pointer to the payload */
37 apr_time_t add_time; /* Time node was added to cache */
38 struct util_cache_node_t *next;
40
41typedef struct util_ald_cache util_ald_cache_t;
42
43struct util_ald_cache {
44 unsigned long size; /* Size of cache array */
45 unsigned long maxentries; /* Maximum number of cache entries */
46 unsigned long numentries; /* Current number of cache entries */
47 unsigned long fullmark; /* Used to keep track of when cache becomes 3/4 full */
48 apr_time_t marktime; /* Time that the cache became 3/4 full */
49 unsigned long ttl; /* Time to live for items in cache */
50 unsigned long (*hash)(void *); /* Func to hash the payload */
51 int (*compare)(void *, void *); /* Func to compare two payloads */
52 void * (*copy)(util_ald_cache_t *cache, void *); /* Func to alloc mem and copy payload to new mem */
53 void (*free)(util_ald_cache_t *cache, void *); /* Func to free mem used by the payload */
54 void (*display)(request_rec *r, util_ald_cache_t *cache, void *); /* Func to display the payload contents */
56
57 unsigned long numpurges; /* No. of times the cache has been purged */
58 double avg_purgetime; /* Average time to purge the cache */
59 apr_time_t last_purge; /* Time of the last purge */
60 unsigned long npurged; /* Number of elements purged in last purge. This is not
61 obvious: it won't be 3/4 the size of the cache if
62 there were a lot of expired entries. */
63
64 unsigned long fetches; /* Number of fetches */
65 unsigned long hits; /* Number of cache hits */
66 unsigned long inserts; /* Number of inserts */
67 unsigned long removes; /* Number of removes */
68
69#if APR_HAS_SHARED_MEMORY
72#endif
73
74};
75
76#ifndef WIN32
77#define ALD_MM_FILE_MODE ( S_IRUSR|S_IWUSR )
78#else
79#define ALD_MM_FILE_MODE ( _S_IREAD|_S_IWRITE )
80#endif
81
82
83/*
84 * LDAP Cache
85 */
86
87/*
88 * Maintain a cache of LDAP URLs that the server handles. Each node in
89 * the cache contains the search cache for that URL, and a compare cache
90 * for the URL. The compare cash is populated when doing require group
91 * compares.
92 */
93typedef struct util_url_node_t {
94 const char *url;
99
100/*
101 * When a group is found, subgroups are stored in the group's cache entry.
102 */
103typedef struct util_compare_subgroup_t {
104 const char **subgroupDNs;
105 int len;
107
108/*
109 * We cache every successful search and bind operation, using the username
110 * as the key. Each node in the cache contains the returned DN, plus the
111 * password used to bind.
112 */
113typedef struct util_search_node_t {
114 const char *username; /* Cache key */
115 const char *dn; /* DN returned from search */
116 const char *bindpw; /* The most recently used bind password;
117 NULL if the bind failed */
118 apr_time_t lastbind; /* Time of last successful bind */
119 const char **vals; /* Values of queried attributes */
120 int numvals; /* Number of queried attributes */
122
123/*
124 * We cache every successful compare operation, using the DN, attrib, and
125 * value as the key.
126 */
127typedef struct util_compare_node_t {
128 const char *dn; /* DN, attrib and value combine to be the key */
129 const char *attrib;
130 const char *value;
132 int result;
133 int sgl_processed; /* 0 if no sgl processing yet. 1 if sgl has been processed (even if SGL is NULL). Saves repeat work on leaves. */
136
137/*
138 * We cache every successful compare dn operation, using the dn in the require
139 * statement and the dn fetched based on the client-provided username.
140 */
141typedef struct util_dn_compare_node_t {
142 const char *reqdn; /* The DN in the require dn statement */
143 const char *dn; /* The DN found in the search */
145
146
147/*
148 * Function prototypes for LDAP cache
149 */
150
151/* util_ldap_cache.c */
152unsigned long util_ldap_url_node_hash(void *n);
153int util_ldap_url_node_compare(void *a, void *b);
157
158unsigned long util_ldap_search_node_hash(void *n);
159int util_ldap_search_node_compare(void *a, void *b);
163
164unsigned long util_ldap_compare_node_hash(void *n);
165int util_ldap_compare_node_compare(void *a, void *b);
169
170unsigned long util_ldap_dn_compare_node_hash(void *n);
171int util_ldap_dn_compare_node_compare(void *a, void *b);
175
176
177/* util_ldap_cache_mgr.c */
178
179/* Cache alloc and free function, dealing or not with shm */
180void util_ald_free(util_ald_cache_t *cache, const void *ptr);
181void *util_ald_alloc(util_ald_cache_t *cache, unsigned long size);
182const char *util_ald_strdup(util_ald_cache_t *cache, const char *s);
185
186/* Cache managing function */
187unsigned long util_ald_hash_string(int nstr, ...);
191 long cache_size,
192 long cache_ttl,
193 unsigned long (*hashfunc)(void *),
194 int (*comparefunc)(void *, void *),
195 void * (*copyfunc)(util_ald_cache_t *cache, void *),
196 void (*freefunc)(util_ald_cache_t *cache, void *),
197 void (*displayfunc)(request_rec *r, util_ald_cache_t *cache, void *));
198
204
205#endif /* APR_HAS_LDAP */
206#endif /* APU_LDAP_CACHE_H */
int n
Definition ap_regex.h:278
const char apr_size_t len
Definition ap_regex.h:187
#define hash(h, r, b, n)
Definition apr_random.c:51
request_rec * r
apr_bucket apr_bucket_brigade * a
const char * url
Definition apr_escape.h:120
apr_size_t size
const char * value
Definition apr_env.h:51
apr_array_header_t ** result
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_byte_t ttl
apr_pool_t * b
Definition apr_pools.h:529
const char * s
Definition apr_strings.h:95
const char * username
apr_int64_t apr_time_t
Definition apr_time.h:45
char * name
A structure that represents the current request.
Definition httpd.h:845
Apache LDAP library.
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray