⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_authnz_ldap.c

📁 Apache官方在今天放出产品系列2.2的最新版本2.2.11的源码包 最流行的HTTP服务器软件之一
💻 C
📖 第 1 页 / 共 4 页
字号:
    if (urld->lud_filter) {        if (urld->lud_filter[0] == '(') {            /*             * Get rid of the surrounding parens; later on when generating the             * filter, they'll be put back.             */            sec->filter = apr_pstrdup(cmd->pool, urld->lud_filter+1);            sec->filter[strlen(sec->filter)-1] = '\0';        }        else {            sec->filter = apr_pstrdup(cmd->pool, urld->lud_filter);        }    }    else {        sec->filter = "objectclass=*";    }    if (mode) {        if (0 == strcasecmp("NONE", mode)) {            sec->secure = APR_LDAP_NONE;        }        else if (0 == strcasecmp("SSL", mode)) {            sec->secure = APR_LDAP_SSL;        }        else if (0 == strcasecmp("TLS", mode) || 0 == strcasecmp("STARTTLS", mode)) {            sec->secure = APR_LDAP_STARTTLS;        }        else {            return "Invalid LDAP connection mode setting: must be one of NONE, "                   "SSL, or TLS/STARTTLS";        }    }      /* "ldaps" indicates secure ldap connections desired      */    if (strncasecmp(url, "ldaps", 5) == 0)    {        sec->secure = APR_LDAP_SSL;        sec->port = urld->lud_port? urld->lud_port : LDAPS_PORT;        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,                     "LDAP: auth_ldap using SSL connections");    }    else    {        sec->port = urld->lud_port? urld->lud_port : LDAP_PORT;        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,                     "LDAP: auth_ldap not using SSL connections");    }    sec->have_ldap_url = 1;    return NULL;}static const char *mod_auth_ldap_set_deref(cmd_parms *cmd, void *config, const char *arg){    authn_ldap_config_t *sec = config;    if (strcmp(arg, "never") == 0 || strcasecmp(arg, "off") == 0) {        sec->deref = never;    }    else if (strcmp(arg, "searching") == 0) {        sec->deref = searching;    }    else if (strcmp(arg, "finding") == 0) {        sec->deref = finding;    }    else if (strcmp(arg, "always") == 0 || strcasecmp(arg, "on") == 0) {        sec->deref = always;    }    else {        return "Unrecognized value for AuthLDAPAliasDereference directive";    }    return NULL;}static const char *mod_auth_ldap_add_group_attribute(cmd_parms *cmd, void *config, const char *arg){    struct mod_auth_ldap_groupattr_entry_t *new;    authn_ldap_config_t *sec = config;    if (sec->groupattr->nelts > GROUPATTR_MAX_ELTS)        return "Too many AuthLDAPGroupAttribute directives";    new = apr_array_push(sec->groupattr);    new->name = apr_pstrdup(cmd->pool, arg);    return NULL;}static const char *set_charset_config(cmd_parms *cmd, void *config, const char *arg){    ap_set_module_config(cmd->server->module_config, &authnz_ldap_module,                         (void *)arg);    return NULL;}static const command_rec authnz_ldap_cmds[] ={    AP_INIT_TAKE12("AuthLDAPURL", mod_auth_ldap_parse_url, NULL, OR_AUTHCFG,                  "URL to define LDAP connection. This should be an RFC 2255 complaint\n"                  "URL of the form ldap://host[:port]/basedn[?attrib[?scope[?filter]]].\n"                  "<ul>\n"                  "<li>Host is the name of the LDAP server. Use a space separated list of hosts \n"                  "to specify redundant servers.\n"                  "<li>Port is optional, and specifies the port to connect to.\n"                  "<li>basedn specifies the base DN to start searches from\n"                  "<li>Attrib specifies what attribute to search for in the directory. If not "                  "provided, it defaults to <b>uid</b>.\n"                  "<li>Scope is the scope of the search, and can be either <b>sub</b> or "                  "<b>one</b>. If not provided, the default is <b>sub</b>.\n"                  "<li>Filter is a filter to use in the search. If not provided, "                  "defaults to <b>(objectClass=*)</b>.\n"                  "</ul>\n"                  "Searches are performed using the attribute and the filter combined. "                  "For example, assume that the\n"                  "LDAP URL is <b>ldap://ldap.airius.com/ou=People, o=Airius?uid?sub?(posixid=*)</b>. "                  "Searches will\n"                  "be done using the filter <b>(&((posixid=*))(uid=<i>username</i>))</b>, "                  "where <i>username</i>\n"                  "is the user name passed by the HTTP client. The search will be a subtree "                  "search on the branch <b>ou=People, o=Airius</b>."),    AP_INIT_TAKE1("AuthLDAPBindDN", ap_set_string_slot,                  (void *)APR_OFFSETOF(authn_ldap_config_t, binddn), OR_AUTHCFG,                  "DN to use to bind to LDAP server. If not provided, will do an anonymous bind."),    AP_INIT_TAKE1("AuthLDAPBindPassword", ap_set_string_slot,                  (void *)APR_OFFSETOF(authn_ldap_config_t, bindpw), OR_AUTHCFG,                  "Password to use to bind to LDAP server. If not provided, will do an anonymous bind."),    AP_INIT_FLAG("AuthLDAPRemoteUserIsDN", ap_set_flag_slot,                 (void *)APR_OFFSETOF(authn_ldap_config_t, user_is_dn), OR_AUTHCFG,                 "Set to 'on' to set the REMOTE_USER environment variable to be the full "                 "DN of the remote user. By default, this is set to off, meaning that "                 "the REMOTE_USER variable will contain whatever value the remote user sent."),    AP_INIT_TAKE1("AuthLDAPRemoteUserAttribute", ap_set_string_slot,                 (void *)APR_OFFSETOF(authn_ldap_config_t,                                       remote_user_attribute), OR_AUTHCFG,                 "Override the user supplied username and place the "                 "contents of this attribute in the REMOTE_USER "                 "environment variable."),    AP_INIT_FLAG("AuthzLDAPAuthoritative", ap_set_flag_slot,                 (void *)APR_OFFSETOF(authn_ldap_config_t, auth_authoritative), OR_AUTHCFG,                 "Set to 'off' to allow access control to be passed along to lower modules if "                 "the UserID and/or group is not known to this module"),    AP_INIT_FLAG("AuthLDAPCompareDNOnServer", ap_set_flag_slot,                 (void *)APR_OFFSETOF(authn_ldap_config_t, compare_dn_on_server), OR_AUTHCFG,                 "Set to 'on' to force auth_ldap to do DN compares (for the \"require dn\" "                 "directive) using the server, and set it 'off' to do the compares locally "                 "(at the expense of possible false matches). See the documentation for "                 "a complete description of this option."),    AP_INIT_ITERATE("AuthLDAPGroupAttribute", mod_auth_ldap_add_group_attribute, NULL, OR_AUTHCFG,                    "A list of attributes used to define group membership - defaults to "                    "member and uniquemember"),    AP_INIT_FLAG("AuthLDAPGroupAttributeIsDN", ap_set_flag_slot,                 (void *)APR_OFFSETOF(authn_ldap_config_t, group_attrib_is_dn), OR_AUTHCFG,                 "If set to 'on', auth_ldap uses the DN that is retrieved from the server for"                 "subsequent group comparisons. If set to 'off', auth_ldap uses the string"                 "provided by the client directly. Defaults to 'on'."),    AP_INIT_TAKE1("AuthLDAPDereferenceAliases", mod_auth_ldap_set_deref, NULL, OR_AUTHCFG,                  "Determines how aliases are handled during a search. Can bo one of the"                  "values \"never\", \"searching\", \"finding\", or \"always\". "                  "Defaults to always."),/*    AP_INIT_FLAG("AuthLDAPAuthzEnabled", ap_set_flag_slot,                 (void *)APR_OFFSETOF(authn_ldap_config_t, authz_enabled), OR_AUTHCFG,                 "Set to off to disable the LDAP authorization handler, even if it's been enabled in a higher tree"),*/    AP_INIT_TAKE1("AuthLDAPCharsetConfig", set_charset_config, NULL, RSRC_CONF,                  "Character set conversion configuration file. If omitted, character set"                  "conversion is disabled."),    {NULL}};static int authnz_ldap_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s){    ap_configfile_t *f;    char l[MAX_STRING_LEN];    const char *charset_confname = ap_get_module_config(s->module_config,                                                      &authnz_ldap_module);    apr_status_t status;    /*    authn_ldap_config_t *sec = (authn_ldap_config_t *)                                    ap_get_module_config(s->module_config,                                                         &authnz_ldap_module);    if (sec->secure)    {        if (!util_ldap_ssl_supported(s))        {            ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s,                     "LDAP: SSL connections (ldaps://) not supported by utilLDAP");            return(!OK);        }    }    */    /* make sure that mod_ldap (util_ldap) is loaded */    if (ap_find_linked_module("util_ldap.c") == NULL) {        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,                     "Module mod_ldap missing. Mod_ldap (aka. util_ldap) "                     "must be loaded in order for mod_auth_ldap to function properly");        return HTTP_INTERNAL_SERVER_ERROR;    }    if (!charset_confname) {        return OK;    }    charset_confname = ap_server_root_relative(p, charset_confname);    if (!charset_confname) {        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EBADPATH, s,                     "Invalid charset conversion config path %s",                     (const char *)ap_get_module_config(s->module_config,                                                        &authnz_ldap_module));        return HTTP_INTERNAL_SERVER_ERROR;    }    if ((status = ap_pcfg_openfile(&f, ptemp, charset_confname))                != APR_SUCCESS) {        ap_log_error(APLOG_MARK, APLOG_ERR, status, s,                     "could not open charset conversion config file %s.",                     charset_confname);        return HTTP_INTERNAL_SERVER_ERROR;    }    charset_conversions = apr_hash_make(p);    while (!(ap_cfg_getline(l, MAX_STRING_LEN, f))) {        const char *ll = l;        char *lang;        if (l[0] == '#') {            continue;        }        lang = ap_getword_conf(p, &ll);        ap_str_tolower(lang);        if (ll[0]) {            char *charset = ap_getword_conf(p, &ll);            apr_hash_set(charset_conversions, lang, APR_HASH_KEY_STRING, charset);        }    }    ap_cfg_closefile(f);    to_charset = derive_codepage_from_lang (p, "utf-8");    if (to_charset == NULL) {        ap_log_error(APLOG_MARK, APLOG_ERR, status, s,                     "could not find the UTF-8 charset in the file %s.",                     charset_confname);        return HTTP_INTERNAL_SERVER_ERROR;    }    return OK;}static const authn_provider authn_ldap_provider ={    &authn_ldap_check_password,};static void ImportULDAPOptFn(void){    util_ldap_connection_close  = APR_RETRIEVE_OPTIONAL_FN(uldap_connection_close);    util_ldap_connection_find   = APR_RETRIEVE_OPTIONAL_FN(uldap_connection_find);    util_ldap_cache_comparedn   = APR_RETRIEVE_OPTIONAL_FN(uldap_cache_comparedn);    util_ldap_cache_compare     = APR_RETRIEVE_OPTIONAL_FN(uldap_cache_compare);    util_ldap_cache_checkuserid = APR_RETRIEVE_OPTIONAL_FN(uldap_cache_checkuserid);    util_ldap_cache_getuserdn   = APR_RETRIEVE_OPTIONAL_FN(uldap_cache_getuserdn);    util_ldap_ssl_supported     = APR_RETRIEVE_OPTIONAL_FN(uldap_ssl_supported);}static void register_hooks(apr_pool_t *p){    static const char * const aszPost[]={ "mod_authz_user.c", NULL };    ap_register_provider(p, AUTHN_PROVIDER_GROUP, "ldap", "0",                         &authn_ldap_provider);    ap_hook_post_config(authnz_ldap_post_config,NULL,NULL,APR_HOOK_MIDDLE);    ap_hook_auth_checker(authz_ldap_check_user_access, NULL, aszPost, APR_HOOK_MIDDLE);    ap_hook_optional_fn_retrieve(ImportULDAPOptFn,NULL,NULL,APR_HOOK_MIDDLE);}module AP_MODULE_DECLARE_DATA authnz_ldap_module ={    STANDARD20_MODULE_STUFF,    create_authnz_ldap_dir_config,   /* dir config creater */    NULL,                            /* dir merger --- default is to override */    NULL,                            /* server config */    NULL,                            /* merge server config */    authnz_ldap_cmds,                /* command apr_table_t */    register_hooks                   /* register hooks */};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -