diff options
author | Jeff Trawick <trawick@apache.org> | 2000-11-13 04:12:28 +0000 |
---|---|---|
committer | Jeff Trawick <trawick@apache.org> | 2000-11-13 04:12:28 +0000 |
commit | 30fbbe1cc49dfff92992be0c515c630e10ee4430 (patch) | |
tree | ccce050d2ddd9f4ee4ceacfb69535cd4168929ea /modules/mappers/mod_rewrite.c | |
parent | 85815fec742ddfd5066e0443b19c2b0eb03208bd (diff) | |
download | httpd-30fbbe1cc49dfff92992be0c515c630e10ee4430.tar.gz |
Change mod_rewrite's tilde expansion to use apr_get_home_directory().
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86935 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules/mappers/mod_rewrite.c')
-rw-r--r-- | modules/mappers/mod_rewrite.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 53c0c83b9a..822ed1b23a 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -97,6 +97,7 @@ #include "http_protocol.h" #include "mod_rewrite.h" #include "apr_strings.h" +#include "apr_user.h" #if !defined(OS2) && !defined(WIN32) #include "unixd.h" @@ -1257,7 +1258,7 @@ static int hook_uri2file(request_rec *r) /* it was finally rewritten to a local path */ /* expand "/~user" prefix */ -#if !defined(WIN32) && !defined(NETWARE) +#if APR_HAS_USER r->filename = expand_tildepaths(r, r->filename); #endif rewritelog(r, 2, "local path result: %s", r->filename); @@ -2619,22 +2620,17 @@ static int is_absolute_uri(char *uri) /* ** -** Expand tilde-paths (/~user) through -** Unix /etc/passwd database information +** Expand tilde-paths (/~user) through Unix /etc/passwd +** database information (or other OS-specific database) ** */ -#if !defined(WIN32) && !defined(NETWARE) +#if APR_HAS_USER static char *expand_tildepaths(request_rec *r, char *uri) { char user[LONG_STRING_LEN]; - struct passwd *pw; char *newuri; int i, j; -#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) - struct passwd pwd; - size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX); - char *buf = apr_pcalloc(r->pool, buflen); -#endif + char *homedir; newuri = uri; if (uri != NULL && strlen(uri) > 2 && uri[0] == '/' && uri[1] == '~') { @@ -2647,28 +2643,24 @@ static char *expand_tildepaths(request_rec *r, char *uri) user[j] = '\0'; /* lookup username in systems passwd file */ -#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) - if (!getpwnam_r(user, &pwd, buf, buflen, &pw)) { -#else - if ((pw = getpwnam(user)) != NULL) { -#endif + 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 (pw->pw_dir[strlen(pw->pw_dir)-1] == '/') { - pw->pw_dir[strlen(pw->pw_dir)-1] = '\0'; + if (homedir[strlen(homedir)-1] == '/') { + homedir[strlen(homedir)-1] = '\0'; } - newuri = apr_pstrcat(r->pool, pw->pw_dir, uri+i, NULL); + newuri = apr_pstrcat(r->pool, homedir, uri+i, NULL); } else { /* only ~user has to be expanded */ - newuri = apr_pstrdup(r->pool, pw->pw_dir); + newuri = homedir; } } } return newuri; } -#endif +#endif /* if APR_HAS_USER */ |