]> granicus.if.org Git - apache/commitdiff
We can't just create the temporary file in the current directory. If that
authorRyan Bloom <rbb@apache.org>
Tue, 8 Oct 2002 01:15:46 +0000 (01:15 +0000)
committerRyan Bloom <rbb@apache.org>
Tue, 8 Oct 2002 01:15:46 +0000 (01:15 +0000)
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

support/htpasswd.c

index 34e6219cfd2a1e30494928ff40f2e61e1eb390f9..d34063e3a235795d5dce3c2243462916a9922580 100644 (file)
@@ -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);