예제 #1
0
int main (void)
{
    apr_pool_t *pool;
    const apr_strmatch_pattern *pattern;
    const apr_strmatch_pattern *pattern_nocase;
    const apr_strmatch_pattern *pattern_onechar;
    const apr_strmatch_pattern *pattern_zero;
    const char *input1 = "string that contains a patterN...";
    const char *input2 = "string that contains a pattern...";
    const char *input3 = "pattern at the start of a string";
    const char *input4 = "string that ends with a pattern";
    const char *input5 = "patter\200n not found, negative chars in input";
    const char *input6 = "patter\200n, negative chars, contains pattern...";

    (void) apr_initialize();
    apr_pool_create(&pool, NULL);

    printf("testing pattern precompilation...");
    pattern = apr_strmatch_precompile(pool, "pattern", 1);
    if (!pattern) {
        printf("FAILED\n");
        exit(1);
    }
    pattern_nocase = apr_strmatch_precompile(pool, "pattern", 0);
    if (!pattern_nocase) {
        printf("FAILED\n");
        exit(1);
    }
    pattern_onechar = apr_strmatch_precompile(pool, "g", 0);
    if (!pattern_onechar) {
        printf("FAILED\n");
        exit(1);
    }
    pattern_zero = apr_strmatch_precompile(pool, "", 0);
    if (!pattern_zero) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    printf("testing invalid match...");
    if (apr_strmatch(pattern, input1, strlen(input1)) != NULL) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    printf("testing valid match...");
    if (apr_strmatch(pattern, input2, strlen(input2)) != input2 + 23) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    printf("testing single-character match...");
    if (apr_strmatch(pattern_onechar, input1, strlen(input1)) != input1 + 5) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    printf("testing zero-length pattern...");
    if (apr_strmatch(pattern_zero, input1, strlen(input1)) != input1) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    printf("testing inexact-case match...");
    if (apr_strmatch(pattern_nocase, input1, strlen(input1)) != input1 + 23) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    printf("testing match at start of string...");
    if (apr_strmatch(pattern, input3, strlen(input3)) != input3) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    printf("testing match at end of string...");
    if (apr_strmatch(pattern, input4, strlen(input4)) != input4 + 24) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    printf("testing invalid match with negative chars in input string...");
    if (apr_strmatch(pattern, input5, strlen(input5)) != NULL) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    printf("testing valid match with negative chars in input string...");
    if (apr_strmatch(pattern, input6, strlen(input6)) != input6 + 35) {
        printf("FAILED\n");
        exit(1);
    }
    printf("OK\n");

    exit(0);
}
예제 #2
0
파일: mirror.c 프로젝트: DJEX93/dsploit
apr_status_t dav_svn__location_in_filter(ap_filter_t *f,
                                         apr_bucket_brigade *bb,
                                         ap_input_mode_t mode,
                                         apr_read_type_e block,
                                         apr_off_t readbytes)
{
    request_rec *r = f->r;
    locate_ctx_t *ctx = f->ctx;
    apr_status_t rv;
    apr_bucket *bkt;
    const char *master_uri, *root_dir, *canonicalized_uri;
    apr_uri_t uri;

    /* Don't filter if we're in a subrequest or we aren't setup to
       proxy anything. */
    master_uri = dav_svn__get_master_uri(r);
    if (r->main || !master_uri) {
        ap_remove_input_filter(f);
        return ap_get_brigade(f->next, bb, mode, block, readbytes);
    }

    /* And don't filter if our search-n-replace would be a noop anyway
       (that is, if our root path matches that of the master server). */
    apr_uri_parse(r->pool, master_uri, &uri);
    root_dir = dav_svn__get_root_dir(r);
    canonicalized_uri = svn_urlpath__canonicalize(uri.path, r->pool);
    if (strcmp(canonicalized_uri, root_dir) == 0) {
        ap_remove_input_filter(f);
        return ap_get_brigade(f->next, bb, mode, block, readbytes);
    }

    /* ### FIXME: While we want to fix up any locations in proxied XML
       ### requests, we do *not* want to be futzing with versioned (or
       ### to-be-versioned) data, such as the file contents present in
       ### PUT requests and properties in PROPPATCH requests.
       ### See issue #3445 for details. */

    /* We are url encoding the current url and the master url
       as incoming(from client) request body has it encoded already. */
    canonicalized_uri = svn_path_uri_encode(canonicalized_uri, r->pool);
    root_dir = svn_path_uri_encode(root_dir, r->pool);
    if (!f->ctx) {
        ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx));
        ctx->remotepath = canonicalized_uri;
        ctx->remotepath_len = strlen(ctx->remotepath);
        ctx->localpath = root_dir;
        ctx->localpath_len = strlen(ctx->localpath);
        ctx->pattern = apr_strmatch_precompile(r->pool, ctx->localpath, 1);
        ctx->pattern_len = ctx->localpath_len;
    }

    rv = ap_get_brigade(f->next, bb, mode, block, readbytes);
    if (rv) {
        return rv;
    }

    bkt = APR_BRIGADE_FIRST(bb);
    while (bkt != APR_BRIGADE_SENTINEL(bb)) {

        const char *data, *match;
        apr_size_t len;

        if (APR_BUCKET_IS_METADATA(bkt)) {
            bkt = APR_BUCKET_NEXT(bkt);
            continue;
        }

        /* read */
        apr_bucket_read(bkt, &data, &len, APR_BLOCK_READ);
        match = apr_strmatch(ctx->pattern, data, len);
        if (match) {
            apr_bucket *next_bucket;
            apr_bucket_split(bkt, match - data);
            next_bucket = APR_BUCKET_NEXT(bkt);
            apr_bucket_split(next_bucket, ctx->pattern_len);
            bkt = APR_BUCKET_NEXT(next_bucket);
            apr_bucket_delete(next_bucket);
            next_bucket = apr_bucket_pool_create(ctx->remotepath,
                                                 ctx->remotepath_len,
                                                 r->pool, bb->bucket_alloc);
            APR_BUCKET_INSERT_BEFORE(bkt, next_bucket);
        }
        else {
            bkt = APR_BUCKET_NEXT(bkt);
        }
    }
    return APR_SUCCESS;
}
예제 #3
0
static const char *set_pattern(cmd_parms *cmd, void *cfg, const char *line)
{
    char *from = NULL;
    char *to = NULL;
    char *flags = NULL;
    char *ourline;
    char delim;
    subst_pattern_t *nscript;
    int is_pattern = 0;
    int ignore_case = 0;
    int flatten = 1;
    ap_regex_t *r = NULL;

    if (apr_tolower(*line) != 's') {
        return "Bad Substitute format, must be an s/// pattern";
    }
    ourline = apr_pstrdup(cmd->pool, line);
    delim = *++ourline;
    if (delim)
        from = ++ourline;
    if (from) {
        if (*ourline != delim) {
            while (*++ourline && *ourline != delim);
        }
        if (*ourline) {
            *ourline = '\0';
            to = ++ourline;
        }
    }
    if (to) {
        if (*ourline != delim) {
            while (*++ourline && *ourline != delim);
        }
        if (*ourline) {
            *ourline = '\0';
            flags = ++ourline;
        }
    }

    if (!delim || !from || !*from || !to) {
        return "Bad Substitute format, must be a complete s/// pattern";
    }

    if (flags) {
        while (*flags) {
            delim = apr_tolower(*flags);    /* re-use */
            if (delim == 'i')
                ignore_case = 1;
            else if (delim == 'n')
                is_pattern = 1;
            else if (delim == 'f')
                flatten = 1;
            else if (delim == 'q')
                flatten = 0;
            else
                return "Bad Substitute flag, only s///[infq] are supported";
            flags++;
        }
    }

    /* first see if we can compile the regex */
    if (!is_pattern) {
        r = ap_pregcomp(cmd->pool, from, AP_REG_EXTENDED |
                        (ignore_case ? AP_REG_ICASE : 0));
        if (!r)
            return "Substitute could not compile regex";
    }
    nscript = apr_array_push(((subst_dir_conf *) cfg)->patterns);
    /* init the new entries */
    nscript->pattern = NULL;
    nscript->regexp = NULL;
    nscript->replacement = NULL;
    nscript->patlen = 0;

    if (is_pattern) {
        nscript->patlen = strlen(from);
        nscript->pattern = apr_strmatch_precompile(cmd->pool, from,
                                                   !ignore_case);
    }
    else {
        nscript->regexp = r;
    }

    nscript->replacement = to;
    nscript->replen = strlen(to);
    nscript->flatten = flatten;

    return NULL;
}