📄 cspace_config.c
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */#include "apr_tables.h"#include "apr_strings.h"#include "ap_config.h"#include "httpd.h"#include "http_config.h"#include "http_core.h"#include "http_request.h"#include "http_protocol.h"#include "http_log.h"#include "http_main.h"#include "mod_cspace.h"#include "cspace_utils.h"#define DEF_IGNORE_LIST_SIZE 1#define OUTPUT_LEN 120/*TODO: use strncpy where ever possible*//*TODO: s/login_page/exempt_uri*/void cfg_svr_printf_fn(const char* st, cspace_svr_cfg *cfg, const char* nl){ if (cfg) printf("%s\t%p, key:%s, sess_file:%s, sess_expire:%ld%s", st, (void*)cfg, cfg->key_file, cfg->session_file, cfg->session_expire, nl);}void cfg_dir_printf_fn(const char* st, cspace_dir_cfg *cfg, const char* nl){ if (cfg) printf("%s\t%p, cspace:%s, dir:%s, sess:%s, sess_ovr:%s, sso:%s, " "sess_file:%s, %s", st, (void*)cfg, cfg->use_cspace_auth?"true":"false", cfg->dirspec, cfg->session?"true":"false", cfg->session_overridden?"true":"false", cfg->sso?"true":"false", cfg->session_file, nl);}static const char *cmd_use_cspace_auth(cmd_parms *cmd, void *mconfig){ cspace_dir_cfg *cfg = (cspace_dir_cfg *)mconfig; cfg->use_cspace_auth = 1; return NULL;}static const char *cmd_sso(cmd_parms *cmd, void *mconfig, int arg){ cspace_dir_cfg *cfg = (cspace_dir_cfg *)mconfig; cfg->sso = arg ? 1 : 0; return NULL;}static const char *cmd_session_manage(cmd_parms *cmd, void *mconfig, int arg){ cspace_dir_cfg *cfg = (cspace_dir_cfg *)mconfig; cfg->session = arg ? 1 : 0; return NULL;}static const char *cmd_session_manage_override(cmd_parms *cmd, void *mconfig, int arg){ cspace_dir_cfg *cfg = (cspace_dir_cfg *)mconfig; cfg->session_overridden = arg ? 1 : 0; return NULL;}static const char *cmd_cspace_xml_token(cmd_parms *cmd, void *mconfig, const char *arg){ cspace_dir_cfg *cfg = (cspace_dir_cfg *)mconfig; strcpy(cfg->xml_token, arg); return NULL;}static const char *cmd_cspace_exempt_uri(cmd_parms *cmd, void *mconfig, const char *arg){ cspace_dir_cfg *cfg = (cspace_dir_cfg *)mconfig; /*strcpy(cfg->login_page, arg);*/ const char *path = (const char *)arg; *(const char **)apr_array_push((cfg->login_page)) = apr_pstrdup(cfg->pool, path);#ifdef CSPACE_DEBUG /*cfg_dir_printf("LOGIN_PAGE set on config:", cfg, "\n");*/#endif return NULL;}static const char *cmd_cspace_redir_uri(cmd_parms *cmd, void *mconfig, const char *arg){ cspace_dir_cfg *cfg = (cspace_dir_cfg *)mconfig; strcpy(cfg->redir_uri, arg); return NULL;}static const char *cmd_key_file(cmd_parms *cmd, void *mconfig, const char *arg){ cspace_svr_cfg *cfg = ap_get_module_config(cmd->server->module_config, &cspace_module); cfg->key_file = (char *)arg; return NULL;}static const char *cmd_ca_file(cmd_parms *cmd, void *mconfig, const char *arg){ cspace_svr_cfg *cfg = ap_get_module_config(cmd->server->module_config, &cspace_module); cfg->ca_file = (char *)arg; return NULL;}static const char *cmd_sdbm_file(cmd_parms *cmd, void *mconfig, const char *arg){ cspace_dir_cfg *cfg = (cspace_dir_cfg *)mconfig; /*cfg->session_file = (char *)arg;*/ /*cfg->session_file = apr_pstrdup(cmd->pool, (char *)arg);*/ strcpy(cfg->session_file, arg); /*cfg->session_ctx = session_ctx_create(cmd->pool, arg, NULL);*/ return NULL;}static const char *cmd_global_sdbm_file(cmd_parms *cmd, void *mconfig, const char *arg){ cspace_svr_cfg *cfg = ap_get_module_config(cmd->server->module_config, &cspace_module); cfg->session_file = (char *)arg; /*if (cfg->session_file) { cfg->session_ctx = session_ctx_create(cmd->pool, cfg->session_file, &(cfg->session_expire)); }*/ return NULL;}static const char *cmd_expire_time(cmd_parms *cmd, void *mconfig, const char *arg){ long int expire; cspace_svr_cfg *cfg = ap_get_module_config(cmd->server->module_config, &cspace_module); expire = atol(arg); cfg->session_expire = ((expire > 0) ? expire : DEF_SESS_EXPIRE_TIME); return NULL;}static const char *cmd_validator_data(cmd_parms *cmd, void *mconfig, const char *arg){ cspace_svr_cfg *cfg = ap_get_module_config(cmd->server->module_config, &cspace_module); cfg->validator_data = (char *)arg; return NULL;}static const char *cmd_validator(cmd_parms *cmd, void *mconfig, const char *arg){ cspace_svr_cfg *cfg = ap_get_module_config(cmd->server->module_config, &cspace_module); cfg->validator = (char *)arg; return NULL;}const command_rec cspace_cmds[] = { AP_INIT_NO_ARGS("UseCardSpaceAuth", cmd_use_cspace_auth, NULL, OR_ALL, "should be used only if you want cardspace auth for the " "directory"), AP_INIT_FLAG("CardSpaceSessionManage", cmd_session_manage, NULL, OR_ALL, "whether to enable session management or not"), AP_INIT_FLAG("CardSpaceSessionManageOverride", cmd_session_manage_override, NULL, OR_ALL, "enable this to override session management" "enabled using CardSpaceSessionManage"), AP_INIT_TAKE1("CardSpaceXmlToken", cmd_cspace_xml_token, NULL, OR_ALL, "Name of the XML token sent"), AP_INIT_TAKE1("CardSpaceExemptURI", cmd_cspace_exempt_uri, NULL, OR_ALL, "URI of login page in session managed case"), AP_INIT_TAKE1("CardSpaceRedirectURI", cmd_cspace_redir_uri, NULL, OR_ALL, "URI of login page in session managed case"), /* SSLCertificateKeyFile cannot be used in 2.0 because that will make * mod_ssl not to read that configuration directive.*/ /*AP_INIT_TAKE1("CardSpaceSSLKeyFile", cmd_key_file, NULL, RSRC_CONF, "SSL Server Private Key file"),*/ AP_INIT_TAKE1("SSLCertificateKeyFile", cmd_key_file, NULL, RSRC_CONF, "SSL Server Private Key file"), AP_INIT_TAKE1("CardSpaceCAFile", cmd_ca_file, NULL, RSRC_CONF, "CardSpace CA file"), AP_INIT_TAKE1("CardSpaceGlobalSessionCache", cmd_global_sdbm_file, NULL, RSRC_CONF, "Path to global session cache sdbm file"), AP_INIT_TAKE1("CardSpaceSessionCache", cmd_sdbm_file, NULL, OR_ALL, "Path to session cache sdbm file"), AP_INIT_TAKE1("CardSpaceSessionExpireTime", cmd_expire_time, NULL, RSRC_CONF, "Time in seconds for a session to be expired"), AP_INIT_FLAG("CardSpaceSingleSignOn", cmd_sso, NULL, OR_ALL, "Enable Single Sign-On"), AP_INIT_TAKE1("CardSpaceValidator", cmd_validator, NULL, OR_ALL, "Certificate Validator Type"), AP_INIT_TAKE1("CardSpaceValidatorData", cmd_validator_data, NULL, OR_ALL, "Data input for the validator"), {NULL}};void *cspace_svr_cfg_create(apr_pool_t *p, server_rec *s){ cspace_svr_cfg *cfg = (cspace_svr_cfg *)apr_palloc(p, sizeof(cspace_svr_cfg)); cfg->pool = p; cfg->key_file = NULL; cfg->session_file = NULL; cfg->session_expire = -1; cfg->ca_file = NULL; cfg->validator = NULL; cfg->validator_data = NULL; /*cfg->session_ctx = session_ctx_create(p, NULL, &(cfg->session_expire));*/#ifdef CSPACE_DEBUG cfg_svr_printf("CREATED svr cfg:\t", cfg, "\n\n");#endif return (void *)cfg;}void *cspace_svr_cfg_merge(apr_pool_t *p, void *parent_cfg, void *own_cfg){ char *temp_char; int temp_int; cspace_svr_cfg *merged_cfg = (cspace_svr_cfg *)apr_palloc(p, sizeof(cspace_svr_cfg)); cspace_svr_cfg *pcfg = (cspace_svr_cfg *)(parent_cfg); cspace_svr_cfg *ocfg = (cspace_svr_cfg *)(own_cfg); temp_char = (ocfg->key_file) ? ocfg->key_file : pcfg->key_file; /*would a shallow copy be fine?*/ merged_cfg->key_file = temp_char; temp_char = NULL; temp_char = (ocfg->ca_file) ? ocfg->ca_file : pcfg->ca_file; merged_cfg->ca_file = temp_char; temp_char = NULL; temp_char = (ocfg->session_file) ? ocfg->session_file : pcfg->session_file; /*would a shallow copy be fine?*/ merged_cfg->session_file = temp_char; temp_char = NULL; temp_char = (ocfg->validator_data) ? ocfg->validator_data : pcfg->validator_data; /*would a shallow copy be fine?*/ merged_cfg->validator_data = temp_char; temp_char = NULL; temp_char = (ocfg->validator) ? ocfg->validator : pcfg->validator; /*would a shallow copy be fine?*/ merged_cfg->validator = temp_char; temp_char = NULL; temp_int = (ocfg->session_expire > 0) ? ocfg->session_expire : pcfg->session_expire; merged_cfg->session_expire = temp_int;#ifdef CSPACE_DEBUG cfg_svr_printf("MERGING SVR CONFIG:\n\tparent svr config:", pcfg, "\n"); cfg_svr_printf("\town svr config:\t", ocfg, "\n"); cfg_svr_printf("\tmerged svr config:", merged_cfg, "\n\n");#endif return merged_cfg;}void *cspace_dir_cfg_create(apr_pool_t *p, char *dirspec){ cspace_dir_cfg *cfg = (cspace_dir_cfg *)apr_palloc(p, sizeof(cspace_dir_cfg)); cfg->pool = p; cfg->redir_uri[0] = '\0'; cfg->dirspec[0] = '\0'; cfg->use_cspace_auth = 0; /*use apr_strncpy*/ strncpy(cfg->xml_token, CSPACE_XML_TOKEN, CSPACE_XML_TOKEN_LEN_MAX); /*cfg->login_page[0] = '\0';*/ cfg->login_page = apr_array_make(p, DEF_IGNORE_LIST_SIZE, sizeof(const char *)); cfg->session = 0; cfg->session_overridden = 0; cfg->sso = 0; if (dirspec) { strcpy(cfg->dirspec, dirspec); cfg->dirspec[strlen(dirspec)] = '\0'; } /*cfg->session_ctx = NULL;*/#ifdef CSPACE_DEBUG cfg_dir_printf("CREATED dir config:\t", cfg, "\n\n");#endif return (void *)cfg;}void *cspace_dir_cfg_merge(apr_pool_t *p, void *parent_cfg, void *own_cfg){ char *temp_char; cspace_dir_cfg *merged_cfg = (cspace_dir_cfg *)apr_palloc(p, sizeof(cspace_dir_cfg)); cspace_dir_cfg *pcfg = (cspace_dir_cfg *) parent_cfg; cspace_dir_cfg *ocfg = (cspace_dir_cfg *) own_cfg; merged_cfg->use_cspace_auth = pcfg->use_cspace_auth | ocfg->use_cspace_auth; strcpy(merged_cfg->dirspec, ocfg->dirspec); strcpy(merged_cfg->xml_token, ocfg->xml_token); /*strcpy(merged_cfg->login_page, ocfg->login_page);*/ if ((!ocfg->login_page) && (pcfg->login_page) && (!apr_is_empty_array(pcfg->login_page))) merged_cfg->login_page = pcfg->login_page; else merged_cfg->login_page = ocfg->login_page; merged_cfg->session = pcfg->session | ocfg->session; merged_cfg->session_overridden = pcfg->session_overridden | ocfg->session_overridden; merged_cfg->sso = pcfg->sso | ocfg->sso; temp_char = (ocfg->session_file) ? ocfg->session_file : pcfg->session_file; /*would a shallow copy be fine?*/ strcpy(merged_cfg->session_file, temp_char); temp_char = NULL; temp_char = (ocfg->redir_uri) ? ocfg->redir_uri : pcfg->redir_uri; strcpy(merged_cfg->redir_uri, temp_char); temp_char = NULL; /*merged_cfg->session_ctx = ((ocfg->session_ctx) ? ocfg->session_ctx : pcfg->session_ctx);*/ #ifdef CSPACE_DEBUG cfg_dir_printf("MERGING DIR CONFIG:\n\tparent dir config:", pcfg, "\n"); cfg_dir_printf("\town dir config:\t", ocfg, "\n"); cfg_dir_printf("\tmerged dir config:", merged_cfg, "\n\n");#endif return (void *)merged_cfg;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -