nd 2003/03/09 08:58:16
Modified: . Tag: APACHE_2_0_BRANCH CHANGES STATUS
support Tag: APACHE_2_0_BRANCH htdigest.c
Log:
Restore the ability of htdigest.exe to create files that contain
more than one user. On win32 we cannot system("copy") a file, while
it's open.
PR: 12910
Reviewed by: Will Rowe, Jeff Trawick
Revision Changes Path
No revision
No revision
1.988.2.57 +3 -0 httpd-2.0/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/httpd-2.0/CHANGES,v
retrieving revision 1.988.2.56
retrieving revision 1.988.2.57
diff -u -r1.988.2.56 -r1.988.2.57
--- CHANGES 9 Mar 2003 00:27:14 -0000 1.988.2.56
+++ CHANGES 9 Mar 2003 16:58:15 -0000 1.988.2.57
@@ -1,5 +1,8 @@
Changes with Apache 2.0.45
+ *) Restore the ability of htdigest.exe to create files that contain
+ more than one user. PR 12910. [André Malo]
+
*) Improve binary compatibility of the core between debug (aka
maintainer-mode) and a non-debug compile.
[Sander Striker]
1.751.2.166 +1 -6 httpd-2.0/STATUS
Index: STATUS
===================================================================
RCS file: /home/cvs/httpd-2.0/STATUS,v
retrieving revision 1.751.2.165
retrieving revision 1.751.2.166
diff -u -r1.751.2.165 -r1.751.2.166
--- STATUS 9 Mar 2003 00:27:15 -0000 1.751.2.165
+++ STATUS 9 Mar 2003 16:58:16 -0000 1.751.2.166
@@ -175,11 +175,6 @@
modules/generators/mod_autoindex.c: r1.119
+1: nd, wrowe, trawick
- * Restore the ability of htdigest.exe to create files that contain
- more than one user. PR 12910.
- support/htdigest.c: r1.35
- +1: nd, wrowe, trawick
-
* Allow builds to work with out of tree apr and apr-util
buildconf: r1.30
configure.in: r1.239, r1.240
No revision
No revision
1.33.2.2 +53 -11 httpd-2.0/support/htdigest.c
Index: htdigest.c
===================================================================
RCS file: /home/cvs/httpd-2.0/support/htdigest.c,v
retrieving revision 1.33.2.1
retrieving revision 1.33.2.2
diff -u -r1.33.2.1 -r1.33.2.2
--- htdigest.c 3 Feb 2003 17:32:09 -0000 1.33.2.1
+++ htdigest.c 9 Mar 2003 16:58:16 -0000 1.33.2.2
@@ -70,6 +70,7 @@
#include "apr_lib.h" /* for apr_getpass() */
#include "apr_general.h"
#include "apr_signal.h"
+#include "apr_strings.h" /* for apr_pstrdup() */
#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
@@ -97,12 +98,45 @@
#define MAX_STRING_LEN 256
+/* DELONCLOSE is quite cool, but:
+ * we need to close the file before we can copy it.
+ * otherwise it's locked by the system ;-(
+ *
+ * XXX: Other systems affected? (Netware?, OS2?)
+ */
+#if (defined(WIN32))
+#define OMIT_DELONCLOSE 1
+#endif
+
apr_file_t *tfp = NULL;
apr_pool_t *cntxt;
#if APR_CHARSET_EBCDIC
apr_xlate_t *to_ascii;
#endif
+static void cleanup_tempfile_and_exit(int rc)
+{
+ if (tfp) {
+#ifdef OMIT_DELONCLOSE
+ const char *cfilename;
+ char *filename = NULL;
+
+ if (apr_file_name_get(&cfilename, tfp) == APR_SUCCESS) {
+ filename = apr_pstrdup(cntxt, cfilename);
+ }
+#endif
+ apr_file_close(tfp);
+
+#ifdef OMIT_DELONCLOSE
+ if (filename) {
+ apr_file_remove(filename, cntxt);
+ }
+#endif
+ }
+
+ exit(rc);
+}
+
static void getword(char *word, char *line, char stop)
{
int x = 0, y;
@@ -160,16 +194,13 @@
if (apr_password_get("New password: ", pwin, &len) != APR_SUCCESS) {
fprintf(stderr, "password too long");
- exit(5);
+ cleanup_tempfile_and_exit(5);
}
len = sizeof(pwin);
apr_password_get("Re-type new password: ", pwv, &len);
if (strcmp(pwin, pwv) != 0) {
fprintf(stderr, "They don't match, sorry.\n");
- if (tfp) {
- apr_file_close(tfp);
- }
- exit(1);
+ cleanup_tempfile_and_exit(1);
}
pw = pwin;
apr_file_printf(f, "%s:%s:", user, realm);
@@ -200,10 +231,7 @@
static void interrupted(void)
{
fprintf(stderr, "Interrupted.\n");
- if (tfp) {
- apr_file_close(tfp);
- }
- exit(1);
+ cleanup_tempfile_and_exit(1);
}
static void terminate(void)
@@ -262,7 +290,13 @@
else if (argc != 4)
usage();
- if (apr_file_mktemp(&tfp, tn, 0, cntxt) != APR_SUCCESS) {
+ if (apr_file_mktemp(&tfp, tn,
+#ifdef OMIT_DELONCLOSE
+ APR_CREATE | APR_READ | APR_WRITE | APR_EXCL
+#else
+ 0
+#endif
+ , cntxt) != APR_SUCCESS) {
fprintf(stderr, "Could not open temp file.\n");
exit(1);
}
@@ -271,7 +305,7 @@
fprintf(stderr,
"Could not open passwd file %s for reading.\n", argv[1]);
fprintf(stderr, "Use -c option to create new one.\n");
- exit(1);
+ cleanup_tempfile_and_exit(1);
}
strcpy(user, argv[3]);
strcpy(realm, argv[2]);
@@ -305,7 +339,15 @@
#else
sprintf(command, "cp %s %s", tn, argv[1]);
#endif
+
+#ifdef OMIT_DELONCLOSE
+ apr_file_close(tfp);
+ system(command);
+ apr_file_remove(tn, cntxt);
+#else
system(command);
apr_file_close(tfp);
+#endif
+
return 0;
}
|