httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n.@apache.org
Subject cvs commit: httpd-2.0/modules/mappers mod_rewrite.c
Date Tue, 29 Jul 2003 22:19:56 GMT
nd          2003/07/29 15:19:56

  Modified:    modules/mappers mod_rewrite.c
  Log:
  cleanup expand_tildepath function to use the pool and be more
  readable.
  
  Revision  Changes    Path
  1.203     +25 -32    httpd-2.0/modules/mappers/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v
  retrieving revision 1.202
  retrieving revision 1.203
  diff -u -r1.202 -r1.203
  --- mod_rewrite.c	29 Jul 2003 21:37:59 -0000	1.202
  +++ mod_rewrite.c	29 Jul 2003 22:19:55 -0000	1.203
  @@ -196,10 +196,6 @@
   #define RAND_MAX 32767
   #endif
   
  -#ifndef LONG_STRING_LEN
  -#define LONG_STRING_LEN 2048
  -#endif
  -
   #define MAX_ENV_FLAGS 15
   #define MAX_COOKIE_FLAGS 15
   /* max cookie size in rfc 2109 */
  @@ -2203,39 +2199,36 @@
    */
   static char *expand_tildepaths(request_rec *r, char *uri)
   {
  -    char user[LONG_STRING_LEN];
  -    char *newuri;
  -    int i, j;
  -    char *homedir;
  -
  -    newuri = uri;
  -    if (uri != NULL && strlen(uri) > 2 && uri[0] == '/' && uri[1]
== '~') {
  -        /* cut out the username */
  -        for (j = 0, i = 2; j < sizeof(user)-1
  -               && uri[i] != '\0'
  -               && uri[i] != '/'  ; ) {
  -            user[j++] = uri[i++];
  -        }
  -        user[j] = '\0';
  -
  -        /* lookup username in systems passwd file */
  -        if (apr_get_home_directory(&homedir, user, r->pool) == APR_SUCCESS) {
  -            /* ok, user was found, so expand the ~user string */
  -            if (uri[i] != '\0') {
  -                /* ~user/anything...  has to be expanded */
  -                if (homedir[strlen(homedir)-1] == '/') {
  -                    homedir[strlen(homedir)-1] = '\0';
  +    if (uri && *uri == '/' && uri[1] == '~') {
  +        char *p, *user;
  +
  +        p = user = uri + 2;
  +        while (*p && *p != '/') {
  +            ++p;
  +        }
  +
  +        if (p > user) {
  +            char *homedir;
  +
  +            user = apr_pstrmemdup(r->pool, user, p-user);
  +            if (apr_uid_homepath_get(&homedir, user, r->pool) == APR_SUCCESS) {
  +                if (*p) {
  +                    /* reuse of user variable */
  +                    user = homedir + strlen(homedir) - 1;
  +                    if (user >= homedir && *user == '/') {
  +                        *user = '\0';
  +                    }
  +
  +                    return apr_pstrcat(r->pool, homedir, p, NULL);
  +                }
  +                else {
  +                    return homedir;
                   }
  -                newuri = apr_pstrcat(r->pool, homedir, uri+i, NULL);
  -            }
  -            else {
  -                /* only ~user has to be expanded */
  -                newuri = homedir;
               }
           }
       }
   
  -    return newuri;
  +    return uri;
   }
   #endif  /* if APR_HAS_USER */
   
  
  
  

Mime
View raw message