Changeset 2760 for trunk/server


Ignore:
Timestamp:
Feb 27, 2016, 2:16:45 AM (7 years ago)
Author:
andersk
Message:
mod_vhost_ldap: Quote configuration arguments for ap_getword_conf
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/common/oursrc/httpdmods/mod_vhost_ldap.c

    r2755 r2760  
    399399}
    400400
     401static const char *escape(apr_pool_t *p, const char *input)
     402{
     403    static const char *const to_escape = "'\\";
     404
     405    const char *x = input + strcspn(input, to_escape);
     406    if (*x == '\0')
     407        return input;
     408    const char *y = x;
     409    size_t extra = 0;
     410    while (*y != '\0') {
     411        extra++;
     412        size_t k = strcspn(y + 1, to_escape) + 1;
     413        y += k;
     414    }
     415
     416    char *output = apr_palloc(p, y - input + extra + 1);
     417
     418    memcpy(output, input, x - input);
     419    char *z = output + (x - input);
     420    while (*x != '\0') {
     421        *z++ = '\\';
     422        size_t k = strcspn(x + 1, to_escape) + 1;
     423        memcpy(z, x, k);
     424        x += k;
     425        z += k;
     426    }
     427    *z = '\0';
     428
     429    return output;
     430}
     431
    401432static int reconfigure_directive(apr_pool_t *p,
    402433                                 server_rec *s,
     
    583614        for (i = 0; attributes[i]; i++) {
    584615
    585             const char *directive;
    586616            char *val = apr_pstrdup (r->pool, vals[i]);
    587617            /* These do not correspond to any real directives */
     
    602632                continue;
    603633            }
    604 
    605             if (strcasecmp (attributes[i], "scriptsVhostName") == 0) {
     634            else if (strcasecmp (attributes[i], "scriptsVhostName") == 0) {
    606635                reqc->name = val;
    607                 directive = "ServerName";
     636                continue;
    608637            }
    609638            else {
     
    614643                continue;
    615644            }
    616 
    617             if (val == NULL)
    618                 continue;
    619 
    620             if ((code = reconfigure_directive(r->pool, server, directive, val)) != 0)
    621                 return code;
    622645        }
    623646    }
     
    639662    }
    640663
     664    if ((code = reconfigure_directive(
     665             r->pool, server, "ServerName",
     666             apr_pstrcat(r->pool, "'", escape(r->pool, reqc->name), "'", (const char *)NULL))) != 0)
     667        return code;
     668
    641669    char *docroot =
    642670        strcmp(reqc->directory, ".") == 0 ?
    643671        apr_pstrcat(r->pool, reqc->home, "/web_scripts", (const char *)NULL) :
    644672        apr_pstrcat(r->pool, reqc->home, "/web_scripts/", reqc->directory, (const char *)NULL);
    645     if ((code = reconfigure_directive(r->pool, server, "DocumentRoot", docroot)) != 0)
     673    if ((code = reconfigure_directive(
     674             r->pool, server, "DocumentRoot",
     675             apr_pstrcat(r->pool, "'", escape(r->pool, docroot), "'", (const char *)NULL))) != 0)
    646676        return code;
    647677
     
    651681        uid_t uid = (uid_t) atoll(reqc->uid);
    652682
    653         if ((code = reconfigure_directive(r->pool, server, "UserDir", USERDIR)) != 0)
     683        if ((code = reconfigure_directive(
     684                 r->pool, server, "UserDir",
     685                 apr_pstrcat(r->pool, "'", escape(r->pool, USERDIR), "'", (const char *)NULL))) != 0)
    654686            return code;
    655687
     
    664696        }
    665697
    666         userdir_val = apr_pstrcat(r->pool, "enabled ", username, (const char *)NULL);
     698        userdir_val = apr_pstrcat(r->pool, "enabled '", escape(r->pool, username), "'", (const char *)NULL);
    667699
    668700        if ((code = reconfigure_directive(r->pool, server, "UserDir", userdir_val)) != 0)
Note: See TracChangeset for help on using the changeset viewer.