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

📄 util_ldap.c

📁 linux网络服务器工具
💻 C
📖 第 1 页 / 共 5 页
字号:
        cert->path = ap_server_root_relative(cmd->pool, file);        if (cert->path &&            ((rv = apr_stat (&finfo, cert->path, APR_FINFO_MIN, cmd->pool))                != APR_SUCCESS))        {            ap_log_error(APLOG_MARK, APLOG_ERR, rv, cmd->server,                         "LDAP: Could not open SSL trusted certificate "                         "authority file - %s",                         cert->path == NULL ? file : cert->path);            return "Invalid global certificate file path";        }    }    return(NULL);}/** * Set LDAPTrustedClientCert. * * This directive takes either two or three arguments: * - certificate type * - certificate file / directory / nickname * - certificate password (optional) */static const char *util_ldap_set_trusted_client_cert(cmd_parms *cmd,                                                     void *config,                                                     const char *type,                                                     const char *file,                                                     const char *password){    util_ldap_state_t *st =        (util_ldap_state_t *)ap_get_module_config(cmd->server->module_config,                                                  &ldap_module);    apr_finfo_t finfo;    apr_status_t rv;    int cert_type = 0;    apr_ldap_opt_tls_cert_t *cert;    /* handle the certificate type */    if (type) {        cert_type = util_ldap_parse_cert_type(type);        if (APR_LDAP_CA_TYPE_UNKNOWN == cert_type) {            return apr_psprintf(cmd->pool, "The certificate type \"%s\" is "                                           "not recognised. It should be one "                                           "of CERT_DER, CERT_BASE64, "                                           "CERT_NICKNAME, CERT_PFX,"                                           "KEY_DER, KEY_BASE64, KEY_PFX",                                           type);        }        else if (APR_LDAP_CA_TYPE_DER == cert_type ||                 APR_LDAP_CA_TYPE_BASE64 == cert_type ||                 APR_LDAP_CA_TYPE_CERT7_DB == cert_type ||                 APR_LDAP_CA_TYPE_SECMOD == cert_type ||                 APR_LDAP_CERT_TYPE_PFX == cert_type ||                 APR_LDAP_CERT_TYPE_KEY3_DB == cert_type) {            return apr_psprintf(cmd->pool, "The certificate type \"%s\" is "                                           "only valid within a "                                           "LDAPTrustedGlobalCert directive. "                                           "Only CERT_DER, CERT_BASE64, "                                           "CERT_NICKNAME, KEY_DER, and "                                           "KEY_BASE64 may be used.", type);        }    }    else {        return "Certificate type was not specified.";    }    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,                      "LDAP: SSL trusted client cert - %s (type %s)",                       file, type);    /* add the certificate to the global array */    cert = (apr_ldap_opt_tls_cert_t *)apr_array_push(st->global_certs);    cert->type = cert_type;    cert->path = file;    cert->password = password;    /* if file is a file or path, fix the path */    if (cert_type != APR_LDAP_CA_TYPE_UNKNOWN &&        cert_type != APR_LDAP_CERT_TYPE_NICKNAME) {        cert->path = ap_server_root_relative(cmd->pool, file);        if (cert->path &&            ((rv = apr_stat (&finfo, cert->path, APR_FINFO_MIN, cmd->pool))                != APR_SUCCESS))        {            ap_log_error(APLOG_MARK, APLOG_ERR, rv, cmd->server,                         "LDAP: Could not open SSL client certificate "                         "file - %s",                         cert->path == NULL ? file : cert->path);            return "Invalid client certificate file path";        }    }    return(NULL);}/** * Set LDAPTrustedMode. * * This directive sets what encryption mode to use on a connection: * - None (No encryption) * - SSL (SSL encryption) * - STARTTLS (TLS encryption) */static const char *util_ldap_set_trusted_mode(cmd_parms *cmd, void *dummy,                                              const char *mode){    util_ldap_state_t *st =    (util_ldap_state_t *)ap_get_module_config(cmd->server->module_config,                                              &ldap_module);    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,                      "LDAP: SSL trusted mode - %s",                       mode);    if (0 == strcasecmp("NONE", mode)) {        st->secure = APR_LDAP_NONE;    }    else if (0 == strcasecmp("SSL", mode)) {        st->secure = APR_LDAP_SSL;    }    else if (   (0 == strcasecmp("TLS", mode))             || (0 == strcasecmp("STARTTLS", mode))) {        st->secure = APR_LDAP_STARTTLS;    }    else {        return "Invalid LDAPTrustedMode setting: must be one of NONE, "               "SSL, or TLS/STARTTLS";    }    st->secure_set = 1;    return(NULL);}static const char *util_ldap_set_verify_srv_cert(cmd_parms *cmd,                                                 void *dummy,                                                 int mode){    util_ldap_state_t *st =    (util_ldap_state_t *)ap_get_module_config(cmd->server->module_config,                                              &ldap_module);    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,                      "LDAP: SSL verify server certificate - %s",                      mode?"TRUE":"FALSE");    st->verify_svr_cert = mode;    return(NULL);}static const char *util_ldap_set_connection_timeout(cmd_parms *cmd,                                                    void *dummy,                                                    const char *ttl){#ifdef LDAP_OPT_NETWORK_TIMEOUT    util_ldap_state_t *st =        (util_ldap_state_t *)ap_get_module_config(cmd->server->module_config,                                                  &ldap_module);#endif    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }#ifdef LDAP_OPT_NETWORK_TIMEOUT    st->connectionTimeout = atol(ttl);    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,                 "[%" APR_PID_T_FMT "] ldap connection: Setting connection timeout to "                 "%ld seconds.", getpid(), st->connectionTimeout);#else    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, cmd->server,                 "LDAP: Connection timout option not supported by the "                 "LDAP SDK in use." );#endif    return NULL;}static void *util_ldap_create_config(apr_pool_t *p, server_rec *s){    util_ldap_state_t *st =        (util_ldap_state_t *)apr_pcalloc(p, sizeof(util_ldap_state_t));    /* Create a per vhost pool for mod_ldap to use, serialized with      * st->mutex (also one per vhost)      */    apr_pool_create(&st->pool, p);#if APR_HAS_THREADS    apr_thread_mutex_create(&st->mutex, APR_THREAD_MUTEX_DEFAULT, st->pool);#endif    st->cache_bytes = 100000;    st->search_cache_ttl = 600000000;    st->search_cache_size = 1024;    st->compare_cache_ttl = 600000000;    st->compare_cache_size = 1024;    st->connections = NULL;    st->ssl_supported = 0;    st->global_certs = apr_array_make(p, 10, sizeof(apr_ldap_opt_tls_cert_t));    st->client_certs = apr_array_make(p, 10, sizeof(apr_ldap_opt_tls_cert_t));    st->secure = APR_LDAP_NONE;    st->secure_set = 0;    st->connectionTimeout = 10;    st->verify_svr_cert = 1;    return st;}static void *util_ldap_merge_config(apr_pool_t *p, void *basev,                                    void *overridesv){    util_ldap_state_t *st = apr_pcalloc(p, sizeof(util_ldap_state_t));    util_ldap_state_t *base = (util_ldap_state_t *) basev;    util_ldap_state_t *overrides = (util_ldap_state_t *) overridesv;    st->pool = overrides->pool;#if APR_HAS_THREADS    st->mutex = overrides->mutex;#endif    /* The cache settings can not be modified in a         virtual host since all server use the same        shared memory cache. */    st->cache_bytes = base->cache_bytes;    st->search_cache_ttl = base->search_cache_ttl;    st->search_cache_size = base->search_cache_size;    st->compare_cache_ttl = base->compare_cache_ttl;    st->compare_cache_size = base->compare_cache_size;    st->util_ldap_cache_lock = base->util_ldap_cache_lock;     st->connections = NULL;    st->ssl_supported = 0;    st->global_certs = apr_array_append(p, base->global_certs,                                           overrides->global_certs);    st->client_certs = apr_array_append(p, base->client_certs,                                           overrides->client_certs);    st->secure = (overrides->secure_set == 0) ? base->secure                                              : overrides->secure;    /* These LDAP connection settings can not be overwritten in         a virtual host. Once set in the base server, they must         remain the same. None of the LDAP SDKs seem to be able        to handle setting the verify_svr_cert flag on a         per-connection basis.  The OpenLDAP client appears to be        able to handle the connection timeout per-connection        but the Novell SDK cannot.  Allowing the timeout to        be set by each vhost is of little value so rather than        trying to make special expections for one LDAP SDK, GLOBAL_ONLY         is being enforced on this setting as well. */    st->connectionTimeout = base->connectionTimeout;    st->verify_svr_cert = base->verify_svr_cert;    return st;}static apr_status_t util_ldap_cleanup_module(void *data){    server_rec *s = data;    util_ldap_state_t *st = (util_ldap_state_t *)ap_get_module_config(        s->module_config, &ldap_module);    if (st->ssl_supported) {        apr_ldap_ssl_deinit();    }    return APR_SUCCESS;}static int util_ldap_post_config(apr_pool_t *p, apr_pool_t *plog,                                 apr_pool_t *ptemp, server_rec *s){    apr_status_t result;    server_rec *s_vhost;    util_ldap_state_t *st_vhost;    util_ldap_state_t *st = (util_ldap_state_t *)                            ap_get_module_config(s->module_config,                                                 &ldap_module);    void *data;    const char *userdata_key = "util_ldap_init";    apr_ldap_err_t *result_err = NULL;    int rc;    /* util_ldap_post_config() will be called twice. Don't bother     * going through all of the initialization on the first call     * because it will just be thrown away.*/    apr_pool_userdata_get(&data, userdata_key, s->process->pool);    if (!data) {        apr_pool_userdata_set((const void *)1, userdata_key,                               apr_pool_cleanup_null, s->process->pool);#if APR_HAS_SHARED_MEMORY        /* If the cache file already exists then delete it.  Otherwise we are         * going to run into problems creating the shared memory. */        if (st->cache_file) {            char *lck_file = apr_pstrcat(ptemp, st->cache_file, ".lck",                                         NULL);            apr_file_remove(lck_file, ptemp);        }#endif        return OK;    }#if APR_HAS_SHARED_MEMORY    /* initializing cache if shared memory size is not zero and we already     * don't have shm address     */    if (!st->cache_shm && st->cache_bytes > 0) {#endif        result = util_ldap_cache_init(p, st);        if (result != APR_SUCCESS) {            ap_log_error(APLOG_MARK, APLOG_ERR, result, s,                         "LDAP cache: could not create shared memory segment");            return DONE;        }#if APR_HAS_SHARED_MEMORY        if (st->cache_file) {            st->lock_file = apr_pstrcat(st->pool, st->cache_file, ".lck",                                        NULL);        }#endif        result = apr_global_mutex_create(&st->util_ldap_cache_lock,                                         st->lock_file, APR_LOCK_DEFAULT,                                         st->pool);        if (result != APR_SUCCESS) {            return result;        }#ifdef AP_NEED_SET_MUTEX_PERMS        result = unixd_set_global_mutex_perms(st->util_ldap_cache_lock);        if (result != APR_SUCCESS) {            ap_log_error(APLOG_MARK, APLOG_CRIT, result, s,                         "LDAP cache: failed to set mutex permissions");            return result;        }#endif        /* merge config in all vhost */        s_vhost = s->next;        while (s_vhost) {            st_vhost = (util_ldap_state_t *)                       ap_get_module_config(s_vhost->module_config,                                            &ldap_module);#if APR_HAS_SHARED_MEMORY            st_vhost->cache_shm = st->cache_shm;            st_vhost->cache_rmm = st->cache_rmm;            st_vhost->cache_file = st->cache_file;            ap_log_error(APLOG_MARK, APLOG_DEBUG, result, s,                         "LDAP merging Shared Cache conf: shm=0x%pp rmm=0x%pp "                         "for VHOST: %s", st->cache_shm, st->cache_rmm,                         s_vhost->server_hostname);#endif            st_vhost->lock_file = st->lock_file;            s_vhost = s_vhost->next;        }#if APR_HAS_SHARED_MEMORY    }    else {        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                     "LDAP cache: LDAPSharedCacheSize is zero, disabling "                     "shared memory cache");    }#endif    /* log the LDAP SDK used     */    {        apr_ldap_err_t *result = NULL;        apr_ldap_info(p, &(result));        if (result != NULL) {            ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, "%s", result->reason);        }    }    apr_pool_cleanup_register(p, s, util_ldap_cleanup_module,                              util_ldap_cleanup_module);    /*     * Initialize SSL support, and log the result for the benefit of the admin.     *     * If SSL is not supp

⌨️ 快捷键说明

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