src/server/daemon/ldap_resource.c

changeset 462
72848970541a
parent 461
9b20b8f3582b
child 463
4fd523fff13b
equal deleted inserted replaced
461:9b20b8f3582b 462:72848970541a
118 */ 118 */
119 void * ldap_resourcepool_init(pool_handle_t *pool, const char *rpname, pblock *pb) { 119 void * ldap_resourcepool_init(pool_handle_t *pool, const char *rpname, pblock *pb) {
120 char *ldap_uri = pblock_findval("Uri", pb); 120 char *ldap_uri = pblock_findval("Uri", pb);
121 char *host = pblock_findval("Host", pb); 121 char *host = pblock_findval("Host", pb);
122 char *port = pblock_findval("Port", pb); 122 char *port = pblock_findval("Port", pb);
123 char *binddn = pblock_findval("Binddn", pb);
124 char *bindpw = pblock_findval("Bindpw", pb);
125 char *bind = pblock_findval("Bind", pb);
123 126
124 if(!ldap_uri || !host) { 127 if(!ldap_uri || !host) {
125 log_ereport(LOG_MISCONFIG, "Resource pool %s: No host or ldap uri specified", rpname); 128 log_ereport(LOG_MISCONFIG, "Resource pool %s: No host or ldap uri specified", rpname);
126 return NULL; 129 return NULL;
127 } 130 }
153 ldap_pool->name = rpname; 156 ldap_pool->name = rpname;
154 ldap_pool->pool = pool; 157 ldap_pool->pool = pool;
155 ldap_pool->ldap_uri = ldap_uri; 158 ldap_pool->ldap_uri = ldap_uri;
156 ldap_pool->host = host; 159 ldap_pool->host = host;
157 ldap_pool->port = (int)port_i; 160 ldap_pool->port = (int)port_i;
161 ldap_pool->binddn = binddn;
162 ldap_pool->bindpw = bindpw;
163 ldap_pool->bind = util_getboolean(bind, ldap_pool->binddn != NULL);
158 164
159 return ldap_pool; 165 return ldap_pool;
160 } 166 }
161 167
162 void ldap_resourcepool_destroy(LDAPResourcePool *pool) { 168 void ldap_resourcepool_destroy(LDAPResourcePool *pool) {
178 respool->name, 184 respool->name,
179 respool->ldap_uri ? respool->ldap_uri : respool->host); 185 respool->ldap_uri ? respool->ldap_uri : respool->host);
180 return NULL; 186 return NULL;
181 } 187 }
182 188
189 if(respool->bind) {
190 struct berval *server_cred;
191 if(ldap_resource_bind(respool, ldap, &server_cred) != LDAP_SUCCESS) {
192 log_ereport(LOG_FAILURE, "Resource pool %s: bind failed", respool->name);
193 ws_ldap_close(ldap);
194 return NULL;
195 }
196 }
197
183 LDAPResource *res = pool_malloc(respool->pool, sizeof(LDAPResource)); 198 LDAPResource *res = pool_malloc(respool->pool, sizeof(LDAPResource));
184 if(!res) { 199 if(!res) {
185 ws_ldap_close(ldap); 200 ws_ldap_close(ldap);
186 log_ereport(LOG_CATASTROPHE, "ldap_resourcepool_createresource: OOM"); 201 log_ereport(LOG_CATASTROPHE, "ldap_resourcepool_createresource: OOM");
187 return NULL; 202 return NULL;
188 } 203 }
189 res->ldap = ldap; 204 res->ldap = ldap;
205 res->res_pool = respool;
190 206
191 return res; 207 return res;
192 } 208 }
193 209
194 void ldap_resourcepool_freeresource(LDAPResourcePool *pool, LDAPResource *res) { 210 void ldap_resourcepool_freeresource(LDAPResourcePool *pool, LDAPResource *res) {
209 } 225 }
210 226
211 void * ldap_resourcepool_getresourcedata(LDAPResource *res) { 227 void * ldap_resourcepool_getresourcedata(LDAPResource *res) {
212 return res->ldap; 228 return res->ldap;
213 } 229 }
230
231
232 int ldap_resource_bind(LDAPResourcePool *respool, LDAP *ldap, struct berval **server_cred) {
233 if(!respool->binddn) {
234 return -1;
235 }
236
237 struct berval cred;
238 cred.bv_val = respool->bindpw;
239 cred.bv_len = strlen(cred.bv_val);
240 return ldap_sasl_bind_s(
241 ldap,
242 respool->binddn,
243 LDAP_SASL_SIMPLE,
244 &cred,
245 NULL,
246 NULL,
247 server_cred);
248 }

mercurial