diff options
author | Ryan Bloom <rbb@apache.org> | 2002-10-08 01:15:46 +0000 |
---|---|---|
committer | Ryan Bloom <rbb@apache.org> | 2002-10-08 01:15:46 +0000 |
commit | edd2f9990541840248761a5c63d611b7d7341d71 (patch) | |
tree | 64aef3a4494122593a7e1f7ebfcbba7458719f61 | |
parent | 03b8f85c882fd365fad90721691d003326574267 (diff) | |
download | httpd-edd2f9990541840248761a5c63d611b7d7341d71.tar.gz |
We can't just create the temporary file in the current directory. If that
directory isn't writable, htpasswd won't work. This adds a function
whose responsibility it is to find a valid directory for temporary files.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97136 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | support/htpasswd.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/support/htpasswd.c b/support/htpasswd.c index 34e6219cfd..d34063e3a2 100644 --- a/support/htpasswd.c +++ b/support/htpasswd.c @@ -407,6 +407,18 @@ static void check_args(apr_pool_t *pool, int argc, const char *const argv[], } } +static const char *get_tempname(apr_pool_t *p) +{ + char tn[] = "htpasswd.tmp.XXXXXX"; + char *dirname; + + if (!(dirname = getenv("TEMP")) && !(dirname = getenv("TMPDIR"))) { + dirname = P_tmpdir; + } + dirname = apr_psprintf(p, "%s/%s", dirname, tn); + return dirname; +} + /* * Let's do it. We end up doing a lot of file opening and closing, * but what do we care? This application isn't run constantly. @@ -419,7 +431,7 @@ int main(int argc, const char * const argv[]) char *password = NULL; char *pwfilename = NULL; char *user = NULL; - char tn[] = "htpasswd.tmp.XXXXXX"; + const char *tn; char scratch[MAX_STRING_LEN]; int found = 0; int i; @@ -533,6 +545,7 @@ int main(int argc, const char * const argv[]) * We can access the files the right way, and we have a record * to add or update. Let's do it.. */ + tn = get_tempname(pool); if (apr_file_mktemp(&ftemp, tn, 0, pool) != APR_SUCCESS) { apr_file_printf(errfile, "%s: unable to create temporary file %s\n", argv[0], tn); |