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

📄 jk_urimap.c

📁 Tomcat 4.1与WebServer集成组件的源代码包.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ========================================================================= * *                                                                           * *                 The Apache Software License,  Version 1.1                 * *                                                                           * *          Copyright (c) 1999-2002 The Apache Software Foundation.          * *                           All rights reserved.                            * *                                                                           * * ========================================================================= * *                                                                           * * Redistribution and use in source and binary forms,  with or without modi- * * fication, are permitted provided that the following conditions are met:   * *                                                                           * * 1. Redistributions of source code  must retain the above copyright notice * *    notice, this list of conditions and the following disclaimer.          * *                                                                           * * 2. Redistributions  in binary  form  must  reproduce the  above copyright * *    notice,  this list of conditions  and the following  disclaimer in the * *    documentation and/or other materials provided with the distribution.   * *                                                                           * * 3. The end-user documentation  included with the redistribution,  if any, * *    must include the following acknowlegement:                             * *                                                                           * *       "This product includes  software developed  by the Apache  Software * *        Foundation <http://www.apache.org/>."                              * *                                                                           * *    Alternately, this acknowlegement may appear in the software itself, if * *    and wherever such third-party acknowlegements normally appear.         * *                                                                           * * 4. The names  "The  Jakarta  Project",  "Jk",  and  "Apache  Software     * *    Foundation"  must not be used  to endorse or promote  products derived * *    from this  software without  prior  written  permission.  For  written * *    permission, please contact <apache@apache.org>.                        * *                                                                           * * 5. Products derived from this software may not be called "Apache" nor may * *    "Apache" appear in their names without prior written permission of the * *    Apache Software Foundation.                                            * *                                                                           * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL * * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY * * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL * * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, * * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE * * POSSIBILITY OF SUCH DAMAGE.                                               * *                                                                           * * ========================================================================= * *                                                                           * * This software  consists of voluntary  contributions made  by many indivi- * * duals on behalf of the  Apache Software Foundation.  For more information * * on the Apache Software Foundation, please see <http://www.apache.org/>.   * *                                                                           * * ========================================================================= *//** * Description: URI to worker map object.                           * Maps can be                                                      *                                                                  * Exact Context -> /exact/uri=worker e.g. /examples/do[STAR]=ajp12 * Context Based -> /context/[STAR]=worker e.g. /examples/[STAR]=ajp12 * Context and suffix ->/context/[STAR].suffix=worker e.g. /examples/[STAR].jsp=ajp12 *                                                                          * This lets us either partition the work among the web server and the      * servlet container.                                                       *                                                                          * @author: Gal Shachor <shachor@il.ibm.com> * @author: Costin Manolache */#include "jk_pool.h"#include "jk_env.h"#include "jk_uriMap.h"#include "jk_registry.h"#ifdef HAS_PCRE#include "pcre.h"#include "pcreposix.h"#endifstatic INLINE const char *jk2_findExtension(jk_env_t *env, const char *uri);static int jk2_uriMap_checkUri(jk_env_t *env, jk_uriMap_t *uriMap,                                const char *uri);/* * We are now in a security nightmare, it maybe that somebody sent  * us a uri that looks like /top-secret.jsp. and the web server will  * fumble and return the jsp content.  * * To solve that we will check for path info following the suffix, we  * will also check that the end of the uri is not ".suffix.", * ".suffix/", or ".suffix ". * * Was: check_security_fraud */static int jk2_uriMap_checkUri(jk_env_t *env, jk_uriMap_t *uriMap,                                const char *uri){    int i;        for(i = 0 ; i < uriMap->maps->size( env, uriMap->maps ) ; i++) {        jk_uriEnv_t *uriEnv=uriMap->maps->valueAt( env, uriMap->maps, i );                if(MATCH_TYPE_SUFFIX == uriEnv->match_type) {            char *suffix_start;            for(suffix_start = strstr(uri, uriEnv->suffix) ;                suffix_start ;                suffix_start =                    strstr(suffix_start + 1, uriEnv->suffix)) {                                if('.' != *(suffix_start - 1)) {                    continue;                } else {                    char *after_suffix = suffix_start +                        strlen(uriEnv->suffix);                                    if((('.' == *after_suffix) ||                        ('/' == *after_suffix) ||                        (' ' == *after_suffix)) &&                       (0 == strncmp(uriEnv->prefix, uri,                                     uriEnv->prefix_len))) {                        /*                          * Security violation !!!                         * this is a fraud.                         */                        return JK_ERR;                    }                }            }        }    }    return JK_OK;}/** Add a uri mapping. Called during uri: initialization. Will just copy the    uri in the table ( XXX use a map keyed on name ). In init() we process this    and set the right structures. */static int jk2_uriMap_addUriEnv(jk_env_t *env, jk_uriMap_t *uriMap,                                jk_uriEnv_t *uriEnv){    uriMap->maps->put(env, uriMap->maps, uriEnv->name, uriEnv, NULL);    if (uriMap->mbean->debug > 0)         env->l->jkLog(env, env->l, JK_LOG_DEBUG,                      "uriMap.addUriEnv() %s %s %s\n", uriEnv->name,                      uriEnv->virtual, uriEnv->uri);    return JK_OK;}static int JK_METHOD jk2_uriMap_setProperty(jk_env_t *env, jk_bean_t *mbean,                                            char *name, void *valueP){    jk_uriMap_t *uriMap = mbean->object;    char *value = valueP;        return JK_OK;}static jk_uriEnv_t *jk2_uriMap_prefixMap(jk_env_t *env, jk_uriMap_t *uriMap,                                         jk_map_t *mapTable, const char *uri,                                          int uriLen){    int best_match = 0;    jk_uriEnv_t *match = NULL;    int i;        int sz = mapTable->size(env, mapTable);    for (i = 0; i < sz; i++) {        jk_uriEnv_t *uwr = mapTable->valueAt(env, mapTable, i);        if (uriLen < uwr->prefix_len)            continue;        if (strncmp(uri, uwr->prefix, uwr->prefix_len) == 0) {            if (uwr->prefix_len > best_match) {                best_match=uwr->prefix_len;                match=uwr;            }        }    }    return match;}static jk_uriEnv_t *jk2_uriMap_contextMap(jk_env_t *env, jk_uriMap_t *uriMap,                                          jk_map_t *mapTable, const char *uri,                                           int uriLen){    int i;        int sz = mapTable->size(env, mapTable);    for (i = 0; i < sz; i++) {        jk_uriEnv_t *uwr = mapTable->valueAt(env, mapTable, i);        if (uriLen != uwr->prefix_len - 1)            continue;        if (strncmp(uri, uwr->prefix, uriLen) == 0) {            return uwr;        }    }    return NULL;}static jk_uriEnv_t *jk2_uriMap_exactMap(jk_env_t *env, jk_uriMap_t *uriMap,                                        jk_map_t *mapTable, const char *uri,                                         int uriLen){    int i;    int sz = mapTable->size(env, mapTable);    jk_uriEnv_t *match=NULL;        for (i = 0; i < sz; i++) {        jk_uriEnv_t *uwr = mapTable->valueAt( env, mapTable, i);                if (uriLen != uwr->prefix_len)            continue;        if (strncmp(uri, uwr->prefix, uriLen) == 0) {            return uwr;        }    }    return NULL;}static jk_uriEnv_t *jk2_uriMap_suffixMap(jk_env_t *env, jk_uriMap_t *uriMap,                                         jk_map_t *mapTable, const char *suffix,                                          int suffixLen){    int i;    int sz = mapTable->size( env, mapTable);    for (i = 0; i < sz; i++) {        jk_uriEnv_t *uwr = mapTable->valueAt(env, mapTable, i);        /* for WinXX, fix the JsP != jsp problems */#ifdef WIN32                                if (strcasecmp(suffix, uwr->suffix) == 0)  {#else            if (strcmp(suffix, uwr->suffix) == 0) {#endif                if (uriMap->mbean->debug > 0) {                    env->l->jkLog(env, env->l,JK_LOG_DEBUG,                                  "uriMap.mapUri() suffix match %s\n",                                  uwr->suffix);                }                return uwr;            /* indentation trick */#ifdef WIN32                                    }#else        }#endif    }    return NULL;}/* Find the vhost */static jk_uriEnv_t *jk2_uriMap_hostMap(jk_env_t *env, jk_uriMap_t *uriMap,                                       const char *vhost, int port){    int i, j, n;    char *name;    char hostname[1024] = {0};    if (port) {        if (vhost) {            if (strchr(vhost, ':'))                strcpy(hostname, vhost);            else               sprintf(hostname, "%s:%d", vhost, port);        }        else            sprintf(hostname, "*:%d", port);    }    else if (vhost)        strcpy(hostname, vhost);     else /* Return default host if vhost and port wasn't suplied */        return uriMap->vhosts->get(env, uriMap->vhosts, "*");        n = uriMap->vhosts->size(env, uriMap->vhosts);    /* Check the exact hostname:port first */    for (i = 0 ; i < n ; i++) {        jk_uriEnv_t *uriEnv = uriMap->vhosts->valueAt(env, uriMap->vhosts, i);        name = uriMap->vhosts->nameAt(env, uriMap->vhosts, i);        /* Host name is not case sensitive */        if (strcasecmp(name, hostname) == 0 && port == uriEnv->port)            return uriEnv;    }    if (vhost) {        /* Check the hostname */        for (i = 0 ; i < n ; i++) {            jk_uriEnv_t *uriEnv = uriMap->vhosts->valueAt(env, uriMap->vhosts, i);            name = uriMap->vhosts->nameAt(env, uriMap->vhosts, i);            /* Host name is not case sensitive */            if (strcasecmp(name, vhost) == 0)                return uriEnv;        }        /* Then for each vhost, check the aliases */        for (i = 0 ; i < n ; i++) {            jk_uriEnv_t *uriEnv = uriMap->vhosts->valueAt(env, uriMap->vhosts, i);            if (uriEnv->aliases) {                int m = uriEnv->aliases->size(env, uriEnv->aliases);                for (j = 0; j < m; j++) {                    name = uriEnv->aliases->nameAt(env, uriEnv->aliases, j);                    if (strcasecmp(name, hostname) == 0)                        return uriEnv;                }            }        }    }    /* Finally, check aginst *:port hostname */    if (port) {        for (i = 0 ; i < n ; i++) {            jk_uriEnv_t *uriEnv = uriMap->vhosts->valueAt(env, uriMap->vhosts, i);            name = uriMap->vhosts->nameAt(env, uriMap->vhosts, i);            if ((strncmp(name, "*:", 2) == 0) && uriEnv->port == port) {                return uriEnv;            }        }    }    /* Return default host if none found */    return uriMap->vhosts->get(env, uriMap->vhosts, "*");}#ifdef HAS_PCREstatic jk_uriEnv_t *jk2_uriMap_regexpMap(jk_env_t *env, jk_uriMap_t *uriMap,                                         jk_map_t *mapTable, const char *uri) {    int i;        int sz = mapTable->size(env, mapTable);        for (i = 0; i < sz; i++) {        jk_uriEnv_t *uwr = mapTable->valueAt(env, mapTable, i);        if (uwr->regexp) {            regex_t *r = (regex_t *)uwr->regexp;            regmatch_t regm[10];            if (!regexec(r, uri, r->re_nsub + 1, regm, 0)) {                return uwr;            }        }    }    return NULL;}#elsestatic jk_uriEnv_t *jk2_uriMap_regexpMap(jk_env_t *env, jk_uriMap_t *uriMap,                                         jk_map_t *mapTable, const char *uri) {    return NULL;}#endifstatic void jk2_uriMap_createHosts(jk_env_t *env, jk_uriMap_t *uriMap){

⌨️ 快捷键说明

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