1 /* ============================================================
2 * Copyright (c) 2003-2004, Ondrej Sury
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * mod_vhost_ldap.c --- read virtual host config from LDAP directory
28 #include "http_config.h"
29 #include "http_core.h"
31 #include "http_request.h"
32 #include "apr_version.h"
34 #include "apr_reslist.h"
35 #include "apr_strings.h"
36 #include "apr_tables.h"
37 #include "util_ldap.h"
38 #include "util_script.h"
40 #if !defined(APU_HAS_LDAP) && !defined(APR_HAS_LDAP)
41 #error mod_vhost_ldap requires APR-util to have LDAP support built in
44 #if !defined(WIN32) && !defined(OS2) && !defined(BEOS) && !defined(NETWARE)
45 #define HAVE_UNIX_SUEXEC
48 #ifdef HAVE_UNIX_SUEXEC
49 #include "unixd.h" /* Contains the suexec_identity hook used on Unix */
54 const char USERDIR[] = "web_scripts";
56 #define MAX_FAILURES 5
58 module AP_MODULE_DECLARE_DATA vhost_ldap_module;
61 MVL_UNSET, MVL_DISABLED, MVL_ENABLED
62 } mod_vhost_ldap_status_e;
64 typedef struct mod_vhost_ldap_config_t {
65 mod_vhost_ldap_status_e enabled; /* Is vhost_ldap enabled? */
67 /* These parameters are all derived from the VhostLDAPURL directive */
68 char *url; /* String representation of LDAP URL */
70 char *host; /* Name of the LDAP server (or space separated list) */
71 int port; /* Port of the LDAP server */
72 char *basedn; /* Base DN to do all searches from */
73 int scope; /* Scope of the search */
74 char *filter; /* Filter to further limit the search */
75 deref_options deref; /* how to handle alias dereferening */
77 char *binddn; /* DN to bind to server (can be NULL) */
78 char *bindpw; /* Password to bind to server (can be NULL) */
80 int have_deref; /* Set if we have found an Deref option */
81 int have_ldap_url; /* Set if we have found an LDAP url */
83 int secure; /* True if SSL connections are requested */
85 char *fallback; /* Fallback virtual host */
87 } mod_vhost_ldap_config_t;
89 typedef struct mod_vhost_ldap_request_t {
90 char *dn; /* The saved dn from a successful search */
91 char *name; /* ServerName */
92 char *admin; /* ServerAdmin */
93 char *docroot; /* DocumentRoot */
94 char *cgiroot; /* ScriptAlias */
95 char *uid; /* Suexec Uid */
96 char *gid; /* Suexec Gid */
97 } mod_vhost_ldap_request_t;
100 { "apacheServerName", "apacheDocumentRoot", "apacheScriptAlias", "apacheSuexecUid", "apacheSuexecGid", "apacheServerAdmin", 0 };
102 static int total_modules;
104 #if (APR_MAJOR_VERSION >= 1)
105 static APR_OPTIONAL_FN_TYPE(uldap_connection_close) *util_ldap_connection_close;
106 static APR_OPTIONAL_FN_TYPE(uldap_connection_find) *util_ldap_connection_find;
107 static APR_OPTIONAL_FN_TYPE(uldap_cache_comparedn) *util_ldap_cache_comparedn;
108 static APR_OPTIONAL_FN_TYPE(uldap_cache_compare) *util_ldap_cache_compare;
109 static APR_OPTIONAL_FN_TYPE(uldap_cache_checkuserid) *util_ldap_cache_checkuserid;
110 static APR_OPTIONAL_FN_TYPE(uldap_cache_getuserdn) *util_ldap_cache_getuserdn;
111 static APR_OPTIONAL_FN_TYPE(uldap_ssl_supported) *util_ldap_ssl_supported;
113 static void ImportULDAPOptFn(void)
115 util_ldap_connection_close = APR_RETRIEVE_OPTIONAL_FN(uldap_connection_close);
116 util_ldap_connection_find = APR_RETRIEVE_OPTIONAL_FN(uldap_connection_find);
117 util_ldap_cache_comparedn = APR_RETRIEVE_OPTIONAL_FN(uldap_cache_comparedn);
118 util_ldap_cache_compare = APR_RETRIEVE_OPTIONAL_FN(uldap_cache_compare);
119 util_ldap_cache_checkuserid = APR_RETRIEVE_OPTIONAL_FN(uldap_cache_checkuserid);
120 util_ldap_cache_getuserdn = APR_RETRIEVE_OPTIONAL_FN(uldap_cache_getuserdn);
121 util_ldap_ssl_supported = APR_RETRIEVE_OPTIONAL_FN(uldap_ssl_supported);
125 static int mod_vhost_ldap_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
129 /* Stolen from modules/generators/mod_cgid.c */
131 for (m = ap_preloaded_modules; *m != NULL; m++)
134 /* make sure that mod_ldap (util_ldap) is loaded */
135 if (ap_find_linked_module("util_ldap.c") == NULL) {
136 ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
137 "Module mod_ldap missing. Mod_ldap (aka. util_ldap) "
138 "must be loaded in order for mod_vhost_ldap to function properly");
139 return HTTP_INTERNAL_SERVER_ERROR;
143 ap_add_version_component(p, MOD_VHOST_LDAP_VERSION);
149 mod_vhost_ldap_create_server_config (apr_pool_t *p, server_rec *s)
151 mod_vhost_ldap_config_t *conf =
152 (mod_vhost_ldap_config_t *)apr_pcalloc(p, sizeof (mod_vhost_ldap_config_t));
154 conf->enabled = MVL_UNSET;
155 conf->have_ldap_url = 0;
156 conf->have_deref = 0;
159 conf->deref = always;
160 conf->fallback = NULL;
166 mod_vhost_ldap_merge_server_config(apr_pool_t *p, void *parentv, void *childv)
168 mod_vhost_ldap_config_t *parent = (mod_vhost_ldap_config_t *) parentv;
169 mod_vhost_ldap_config_t *child = (mod_vhost_ldap_config_t *) childv;
170 mod_vhost_ldap_config_t *conf =
171 (mod_vhost_ldap_config_t *)apr_pcalloc(p, sizeof(mod_vhost_ldap_config_t));
173 if (child->enabled == MVL_UNSET) {
174 conf->enabled = parent->enabled;
176 conf->enabled = child->enabled;
179 if (child->have_ldap_url) {
180 conf->have_ldap_url = child->have_ldap_url;
181 conf->url = child->url;
182 conf->host = child->host;
183 conf->port = child->port;
184 conf->basedn = child->basedn;
185 conf->scope = child->scope;
186 conf->filter = child->filter;
187 conf->secure = child->secure;
189 conf->have_ldap_url = parent->have_ldap_url;
190 conf->url = parent->url;
191 conf->host = parent->host;
192 conf->port = parent->port;
193 conf->basedn = parent->basedn;
194 conf->scope = parent->scope;
195 conf->filter = parent->filter;
196 conf->secure = parent->secure;
198 if (child->have_deref) {
199 conf->have_deref = child->have_deref;
200 conf->deref = child->deref;
202 conf->have_deref = parent->have_deref;
203 conf->deref = parent->deref;
206 conf->binddn = (child->binddn ? child->binddn : parent->binddn);
207 conf->bindpw = (child->bindpw ? child->bindpw : parent->bindpw);
209 conf->fallback = (child->fallback ? child->fallback : parent->fallback);
215 * Use the ldap url parsing routines to break up the ldap url into
218 static const char *mod_vhost_ldap_parse_url(cmd_parms *cmd,
223 apr_ldap_url_desc_t *urld;
224 #if (APR_MAJOR_VERSION >= 1)
225 apr_ldap_err_t *result_err;
228 mod_vhost_ldap_config_t *conf =
229 (mod_vhost_ldap_config_t *)ap_get_module_config(cmd->server->module_config,
232 ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0,
233 cmd->server, "[mod_vhost_ldap.c] url parse: `%s'",
236 #if (APR_MAJOR_VERSION >= 1) /* for apache >= 2.2 */
237 result = apr_ldap_url_parse(cmd->pool, url, &(urld), &(result_err));
238 if (result != LDAP_SUCCESS) {
239 return result_err->reason;
242 result = apr_ldap_url_parse(url, &(urld));
243 if (result != LDAP_SUCCESS) {
245 case LDAP_URL_ERR_NOTLDAP:
246 return "LDAP URL does not begin with ldap://";
247 case LDAP_URL_ERR_NODN:
248 return "LDAP URL does not have a DN";
249 case LDAP_URL_ERR_BADSCOPE:
250 return "LDAP URL has an invalid scope";
251 case LDAP_URL_ERR_MEM:
252 return "Out of memory parsing LDAP URL";
254 return "Could not parse LDAP URL";
258 conf->url = apr_pstrdup(cmd->pool, url);
260 ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0,
261 cmd->server, "[mod_vhost_ldap.c] url parse: Host: %s", urld->lud_host);
262 ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0,
263 cmd->server, "[mod_vhost_ldap.c] url parse: Port: %d", urld->lud_port);
264 ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0,
265 cmd->server, "[mod_vhost_ldap.c] url parse: DN: %s", urld->lud_dn);
266 ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0,
267 cmd->server, "[mod_vhost_ldap.c] url parse: attrib: %s", urld->lud_attrs? urld->lud_attrs[0] : "(null)");
268 ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0,
269 cmd->server, "[mod_vhost_ldap.c] url parse: scope: %s",
270 (urld->lud_scope == LDAP_SCOPE_SUBTREE? "subtree" :
271 urld->lud_scope == LDAP_SCOPE_BASE? "base" :
272 urld->lud_scope == LDAP_SCOPE_ONELEVEL? "onelevel" : "unknown"));
273 ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0,
274 cmd->server, "[mod_vhost_ldap.c] url parse: filter: %s", urld->lud_filter);
276 /* Set all the values, or at least some sane defaults */
278 char *p = apr_palloc(cmd->pool, strlen(conf->host) + strlen(urld->lud_host) + 2);
279 strcpy(p, urld->lud_host);
281 strcat(p, conf->host);
285 conf->host = urld->lud_host? apr_pstrdup(cmd->pool, urld->lud_host) : "localhost";
287 conf->basedn = urld->lud_dn? apr_pstrdup(cmd->pool, urld->lud_dn) : "";
289 conf->scope = urld->lud_scope == LDAP_SCOPE_ONELEVEL ?
290 LDAP_SCOPE_ONELEVEL : LDAP_SCOPE_SUBTREE;
292 if (urld->lud_filter) {
293 if (urld->lud_filter[0] == '(') {
295 * Get rid of the surrounding parens; later on when generating the
296 * filter, they'll be put back.
298 conf->filter = apr_pstrdup(cmd->pool, urld->lud_filter+1);
299 conf->filter[strlen(conf->filter)-1] = '\0';
302 conf->filter = apr_pstrdup(cmd->pool, urld->lud_filter);
306 conf->filter = "objectClass=apacheConfig";
309 /* "ldaps" indicates secure ldap connections desired
311 if (strncasecmp(url, "ldaps", 5) == 0)
314 conf->port = urld->lud_port? urld->lud_port : LDAPS_PORT;
315 ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, cmd->server,
316 "LDAP: vhost_ldap using SSL connections");
321 conf->port = urld->lud_port? urld->lud_port : LDAP_PORT;
322 ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, cmd->server,
323 "LDAP: vhost_ldap not using SSL connections");
326 conf->have_ldap_url = 1;
327 #if (APR_MAJOR_VERSION < 1) /* free only required for older apr */
328 apr_ldap_free_urldesc(urld);
333 static const char *mod_vhost_ldap_set_enabled(cmd_parms *cmd, void *dummy, int enabled)
335 mod_vhost_ldap_config_t *conf =
336 (mod_vhost_ldap_config_t *)ap_get_module_config(cmd->server->module_config,
339 conf->enabled = (enabled) ? MVL_ENABLED : MVL_DISABLED;
344 static const char *mod_vhost_ldap_set_binddn(cmd_parms *cmd, void *dummy, const char *binddn)
346 mod_vhost_ldap_config_t *conf =
347 (mod_vhost_ldap_config_t *)ap_get_module_config(cmd->server->module_config,
350 conf->binddn = apr_pstrdup(cmd->pool, binddn);
354 static const char *mod_vhost_ldap_set_bindpw(cmd_parms *cmd, void *dummy, const char *bindpw)
356 mod_vhost_ldap_config_t *conf =
357 (mod_vhost_ldap_config_t *)ap_get_module_config(cmd->server->module_config,
360 conf->bindpw = apr_pstrdup(cmd->pool, bindpw);
364 static const char *mod_vhost_ldap_set_deref(cmd_parms *cmd, void *dummy, const char *deref)
366 mod_vhost_ldap_config_t *conf =
367 (mod_vhost_ldap_config_t *)ap_get_module_config (cmd->server->module_config,
370 if (strcmp(deref, "never") == 0 || strcasecmp(deref, "off") == 0) {
372 conf->have_deref = 1;
374 else if (strcmp(deref, "searching") == 0) {
375 conf->deref = searching;
376 conf->have_deref = 1;
378 else if (strcmp(deref, "finding") == 0) {
379 conf->deref = finding;
380 conf->have_deref = 1;
382 else if (strcmp(deref, "always") == 0 || strcasecmp(deref, "on") == 0) {
383 conf->deref = always;
384 conf->have_deref = 1;
387 return "Unrecognized value for VhostLDAPAliasDereference directive";
392 static const char *mod_vhost_ldap_set_fallback(cmd_parms *cmd, void *dummy, const char *fallback)
394 mod_vhost_ldap_config_t *conf =
395 (mod_vhost_ldap_config_t *)ap_get_module_config(cmd->server->module_config,
398 conf->fallback = apr_pstrdup(cmd->pool, fallback);
402 static int reconfigure_directive(apr_pool_t *p,
407 ap_directive_t dir_s = { .directive = dir, .args = args, .next = NULL,
408 .line_num = 0, .filename = "VhostLDAPConf" };
409 return ap_process_config_tree(s, &dir_s, p, p);
412 command_rec mod_vhost_ldap_cmds[] = {
413 AP_INIT_TAKE1("VhostLDAPURL", mod_vhost_ldap_parse_url, NULL, RSRC_CONF,
414 "URL to define LDAP connection. This should be an RFC 2255 compliant\n"
415 "URL of the form ldap://host[:port]/basedn[?attrib[?scope[?filter]]].\n"
417 "<li>Host is the name of the LDAP server. Use a space separated list of hosts \n"
418 "to specify redundant servers.\n"
419 "<li>Port is optional, and specifies the port to connect to.\n"
420 "<li>basedn specifies the base DN to start searches from\n"
423 AP_INIT_TAKE1 ("VhostLDAPBindDN", mod_vhost_ldap_set_binddn, NULL, RSRC_CONF,
424 "DN to use to bind to LDAP server. If not provided, will do an anonymous bind."),
426 AP_INIT_TAKE1("VhostLDAPBindPassword", mod_vhost_ldap_set_bindpw, NULL, RSRC_CONF,
427 "Password to use to bind to LDAP server. If not provided, will do an anonymous bind."),
429 AP_INIT_FLAG("VhostLDAPEnabled", mod_vhost_ldap_set_enabled, NULL, RSRC_CONF,
430 "Set to off to disable vhost_ldap, even if it's been enabled in a higher tree"),
432 AP_INIT_TAKE1("VhostLDAPDereferenceAliases", mod_vhost_ldap_set_deref, NULL, RSRC_CONF,
433 "Determines how aliases are handled during a search. Can be one of the"
434 "values \"never\", \"searching\", \"finding\", or \"always\". "
435 "Defaults to always."),
437 AP_INIT_TAKE1("VhostLDAPFallback", mod_vhost_ldap_set_fallback, NULL, RSRC_CONF,
438 "Set default virtual host which will be used when requested hostname"
439 "is not found in LDAP database. This option can be used to display"
440 "\"virtual host not found\" type of page."),
445 #define FILTER_LENGTH MAX_STRING_LEN
446 static int mod_vhost_ldap_translate_name(request_rec *r)
451 mod_vhost_ldap_request_t *reqc;
453 const char **vals = NULL;
454 char filtbuf[FILTER_LENGTH];
455 mod_vhost_ldap_config_t *conf =
456 (mod_vhost_ldap_config_t *)ap_get_module_config(r->server->module_config, &vhost_ldap_module);
457 util_ldap_connection_t *ldc = NULL;
459 const char *dn = NULL;
460 const char *hostname = NULL;
465 struct berval hostnamebv, shostnamebv;
468 if ((error = ap_init_virtual_host(r->pool, "", r->server, &server)) != NULL) {
469 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
470 "[mod_vhost_ldap.c]: Could not initialize a new VirtualHost: %s",
472 return HTTP_INTERNAL_SERVER_ERROR;
476 (mod_vhost_ldap_request_t *)apr_pcalloc(r->pool, sizeof(mod_vhost_ldap_request_t));
477 memset(reqc, 0, sizeof(mod_vhost_ldap_request_t));
479 ap_set_module_config(r->request_config, &vhost_ldap_module, reqc);
481 // mod_vhost_ldap is disabled or we don't have LDAP Url
482 if ((conf->enabled != MVL_ENABLED)||(!conf->have_ldap_url)) {
489 ldc = util_ldap_connection_find(r, conf->host, conf->port,
490 conf->binddn, conf->bindpw, conf->deref,
494 ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r,
495 "[mod_vhost_ldap.c] translate: no conf->host - weird...?");
496 return HTTP_INTERNAL_SERVER_ERROR;
499 hostname = r->hostname;
500 if (hostname == NULL || hostname[0] == '\0')
505 ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
506 "[mod_vhost_ldap.c]: translating hostname [%s], uri [%s]",
509 ber_str2bv(hostname, 0, 0, &hostnamebv);
510 if (ldap_bv2escaped_filter_value(&hostnamebv, &shostnamebv) != 0)
512 apr_snprintf(filtbuf, FILTER_LENGTH, "(&(%s)(|(apacheServerName=%s)(apacheServerAlias=%s)))", conf->filter, shostnamebv.bv_val, shostnamebv.bv_val);
513 ber_memfree(shostnamebv.bv_val);
515 result = util_ldap_cache_getuserdn(r, ldc, conf->url, conf->basedn, conf->scope,
516 attributes, filtbuf, &dn, &vals);
518 util_ldap_connection_close(ldc);
520 /* sanity check - if server is down, retry it up to 5 times */
521 if (AP_LDAP_IS_SERVER_DOWN(result) ||
522 (result == LDAP_TIMEOUT) ||
523 (result == LDAP_CONNECT_ERROR)) {
524 sleep = sleep0 + sleep1;
525 ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r,
526 "[mod_vhost_ldap.c]: lookup failure, retry number #[%d], sleeping for [%d] seconds",
528 if (failures++ < MAX_FAILURES) {
529 /* Back-off exponentially */
530 apr_sleep(apr_time_from_sec(sleep));
535 return HTTP_GATEWAY_TIME_OUT;
539 if (result == LDAP_NO_SUCH_OBJECT) {
540 if (strcmp(hostname, "*") != 0) {
541 if (strncmp(hostname, "*.", 2) == 0)
543 hostname += strcspn(hostname, ".");
544 hostname = apr_pstrcat(r->pool, "*", hostname, (const char *)NULL);
545 ap_log_rerror(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r,
546 "[mod_vhost_ldap.c] translate: "
547 "virtual host not found, trying wildcard %s",
553 if (conf->fallback && (is_fallback++ <= 0)) {
554 ap_log_rerror(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r,
555 "[mod_vhost_ldap.c] translate: "
556 "virtual host %s not found, trying fallback %s",
557 hostname, conf->fallback);
558 hostname = conf->fallback;
562 ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r,
563 "[mod_vhost_ldap.c] translate: "
564 "virtual host %s not found",
567 return HTTP_BAD_REQUEST;
570 /* handle bind failure */
571 if (result != LDAP_SUCCESS) {
572 ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r,
573 "[mod_vhost_ldap.c] translate: "
574 "translate failed; virtual host %s; URI %s [%s]",
575 hostname, r->uri, ldap_err2string(result));
576 return HTTP_INTERNAL_SERVER_ERROR;
579 /* mark the user and DN */
580 reqc->dn = apr_pstrdup(r->pool, dn);
585 for (i = 0; attributes[i]; i++) {
587 const char *directive;
588 char *val = apr_pstrdup (r->pool, vals[i]);
589 /* These do not correspond to any real directives */
590 if (strcasecmp (attributes[i], "apacheSuexecUid") == 0) {
594 else if (strcasecmp (attributes[i], "apacheSuexecGid") == 0) {
599 if (strcasecmp (attributes[i], "apacheServerName") == 0) {
601 directive = "ServerName";
603 else if (strcasecmp (attributes[i], "apacheServerAdmin") == 0) {
605 directive = "ServerAdmin";
607 else if (strcasecmp (attributes[i], "apacheDocumentRoot") == 0) {
609 directive = "DocumentRoot";
611 else if (strcasecmp (attributes[i], "apacheScriptAlias") == 0) {
613 /* Hack to deal with current apacheScriptAlias lagout */
614 if (strlen(val) > 0 && val[strlen(val) - 1] == '/')
615 val = apr_pstrcat(r->pool, "/cgi-bin/ ", val, (const char *)NULL);
617 val = apr_pstrcat(r->pool, "/cgi-bin/ ", val, "/", (const char *)NULL);
618 directive = "ScriptAlias";
626 if ((code = reconfigure_directive(r->pool, server, directive, val)) != 0)
631 ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r,
632 "[mod_vhost_ldap.c]: loaded from ldap: "
633 "apacheServerName: %s, "
634 "apacheServerAdmin: %s, "
635 "apacheDocumentRoot: %s, "
636 "apacheScriptAlias: %s, "
637 "apacheSuexecUid: %s, "
638 "apacheSuexecGid: %s",
639 reqc->name, reqc->admin, reqc->docroot, reqc->cgiroot, reqc->uid, reqc->gid);
641 if ((reqc->name == NULL)||(reqc->docroot == NULL)) {
642 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
643 "[mod_vhost_ldap.c] translate: "
644 "translate failed; ServerName or DocumentRoot not defined");
645 return HTTP_INTERNAL_SERVER_ERROR;
648 if (reqc->uid != NULL) {
651 uid_t uid = (uid_t) atoll(reqc->uid);
653 if ((code = reconfigure_directive(r->pool, server, "UserDir", USERDIR)) != 0)
656 /* Deal with ~ expansion */
657 if ((code = reconfigure_directive(r->pool, server, "UserDir", "disabled")) != 0)
660 if (apr_uid_name_get(&username, uid, r->pool) != APR_SUCCESS) {
661 ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
662 "could not get username for uid %d", uid);
663 return HTTP_INTERNAL_SERVER_ERROR;
666 userdir_val = apr_pstrcat(r->pool, "enabled ", username, (const char *)NULL);
668 if ((code = reconfigure_directive(r->pool, server, "UserDir", userdir_val)) != 0)
672 ap_fixup_virtual_host(r->pool, r->server, server);
675 /* Hack to allow post-processing by other modules (mod_rewrite, mod_alias) */
679 #ifdef HAVE_UNIX_SUEXEC
680 static ap_unix_identity_t *mod_vhost_ldap_get_suexec_id_doer(const request_rec * r)
682 ap_unix_identity_t *ugid = NULL;
683 mod_vhost_ldap_config_t *conf =
684 (mod_vhost_ldap_config_t *)ap_get_module_config(r->server->module_config,
686 mod_vhost_ldap_request_t *req =
687 (mod_vhost_ldap_request_t *)ap_get_module_config(r->request_config,
693 // mod_vhost_ldap is disabled or we don't have LDAP Url
694 if ((conf->enabled != MVL_ENABLED)||(!conf->have_ldap_url)) {
698 if ((req == NULL)||(req->uid == NULL)||(req->gid == NULL)) {
702 if ((ugid = apr_palloc(r->pool, sizeof(ap_unix_identity_t))) == NULL) {
706 uid = (uid_t)atoll(req->uid);
707 gid = (gid_t)atoll(req->gid);
709 if ((uid < MIN_UID)||(gid < MIN_GID)) {
722 mod_vhost_ldap_register_hooks (apr_pool_t * p)
726 * Run before mod_rewrite
728 static const char * const aszRewrite[]={ "mod_rewrite.c", NULL };
730 ap_hook_post_config(mod_vhost_ldap_post_config, NULL, NULL, APR_HOOK_MIDDLE);
731 ap_hook_translate_name(mod_vhost_ldap_translate_name, NULL, aszRewrite, APR_HOOK_FIRST);
732 #ifdef HAVE_UNIX_SUEXEC
733 ap_hook_get_suexec_identity(mod_vhost_ldap_get_suexec_id_doer, NULL, NULL, APR_HOOK_MIDDLE);
735 #if (APR_MAJOR_VERSION >= 1)
736 ap_hook_optional_fn_retrieve(ImportULDAPOptFn,NULL,NULL,APR_HOOK_MIDDLE);
740 module AP_MODULE_DECLARE_DATA vhost_ldap_module = {
741 STANDARD20_MODULE_STUFF,
744 mod_vhost_ldap_create_server_config,
745 mod_vhost_ldap_merge_server_config,
747 mod_vhost_ldap_register_hooks,