httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guenter Knauf <efl...@gmx.net>
Subject [PATCH] htdigest.c - move output to apr_file_printf()
Date Sun, 14 Mar 2004 19:12:25 GMT
Hi,
this patch does:
- replace the printf/fprintf with apr_file_printf(), as htpasswd also uses.
- remove now obsolete command[] var (sorry, I know this belongs to patch 2, please forgive!)

--- htdigest.c.orig-3   Sun Mar 14 19:33:42 2004
+++ htdigest.c          Sun Mar 14 19:59:54 2004
@@ -70,6 +70,7 @@
 #endif
 
 apr_file_t *tfp = NULL;
+apr_file_t *errfile;
 apr_pool_t *cntxt;
 #if APR_CHARSET_EBCDIC
 apr_xlate_t *to_ascii;
@@ -154,13 +155,13 @@
     apr_size_t len = sizeof(pwin);
 
     if (apr_password_get("New password: ", pwin, &len) != APR_SUCCESS) {
-        fprintf(stderr, "password too long");
+        apr_file_printf(errfile, "password too long");
         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");
+        apr_file_printf(errfile, "They don't match, sorry.\n");
         cleanup_tempfile_and_exit(1);
     }
     pw = pwin;
@@ -184,14 +185,14 @@
 
 static void usage(void)
 {
-    fprintf(stderr, "Usage: htdigest [-c] passwordfile realm username\n");
-    fprintf(stderr, "The -c flag creates a new file.\n");
+    apr_file_printf(errfile, "Usage: htdigest [-c] passwordfile realm username\n");
+    apr_file_printf(errfile, "The -c flag creates a new file.\n");
     exit(1);
 }
 
 static void interrupted(void)
 {
-    fprintf(stderr, "Interrupted.\n");
+    apr_file_printf(errfile, "Interrupted.\n");
     cleanup_tempfile_and_exit(1);
 }
 
@@ -215,17 +216,17 @@
     char l[MAX_STRING_LEN];
     char w[MAX_STRING_LEN];
     char x[MAX_STRING_LEN];
-    char command[MAX_STRING_LEN];
     int found;
    
     apr_app_initialize(&argc, &argv, NULL);
     atexit(terminate); 
     apr_pool_create(&cntxt, NULL);
+    apr_file_open_stderr(&errfile, cntxt);
 
 #if APR_CHARSET_EBCDIC
     rv = apr_xlate_open(&to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, cntxt);
     if (rv) {
-        fprintf(stderr, "apr_xlate_open(): %s (%d)\n",
+        apr_file_printf(errfile, "apr_xlate_open(): %s (%d)\n",
                 apr_strerror(rv, line, sizeof(line)), rv);
         exit(1);
     }
@@ -239,12 +240,13 @@
         if (rv != APR_SUCCESS) {
             char errmsg[120];
 
-            fprintf(stderr, "Could not open passwd file %s for writing: %s\n",
+            apr_file_printf(errfile, "Could not open passwd file %s for writing: %s\n",
                     argv[2],
                     apr_strerror(rv, errmsg, sizeof errmsg));
             exit(1);
         }
-        printf("Adding password for %s in realm %s.\n", argv[4], argv[3]);
+        apr_file_printf(errfile, "Adding password for %s in realm %s.\n", 
+                    argv[4], argv[3]);
         add_password(argv[4], argv[3], f);
         apr_file_close(f);
         exit(0);
@@ -253,7 +255,7 @@
         usage();
 
     if (apr_temp_dir_get((const char**)&dirname, cntxt) != APR_SUCCESS) {
-        fprintf(stderr, "%s: could not determine temp dir\n",
+        apr_file_printf(errfile, "%s: could not determine temp dir\n",
                         argv[0]);
         exit(1);
     }
@@ -266,14 +268,14 @@
     0
 #endif
     , cntxt) != APR_SUCCESS) {
-        fprintf(stderr, "Could not open temp file.\n");
+        apr_file_printf(errfile, "Could not open temp file %s.\n", dirname);
         exit(1);
     }
 
     if (apr_file_open(&f, argv[1], APR_READ, -1, cntxt) != APR_SUCCESS) {
-        fprintf(stderr,
+        apr_file_printf(errfile,
                 "Could not open passwd file %s for reading.\n", argv[1]);
-        fprintf(stderr, "Use -c option to create new one.\n");
+        apr_file_printf(errfile, "Use -c option to create new one.\n");
         cleanup_tempfile_and_exit(1);
     }
     apr_cpystrn(user, argv[3], sizeof(user));
@@ -293,13 +295,14 @@
             continue;
         }
         else {
-            printf("Changing password for user %s in realm %s\n", user, realm);
+            apr_file_printf(errfile, "Changing password for user %s in realm %s\n", 
+                    user, realm);
             add_password(user, realm, tfp);
             found = 1;
         }
     }
     if (!found) {
-        printf("Adding user %s in realm %s\n", user, realm);
+        apr_file_printf(errfile, "Adding user %s in realm %s\n", user, realm);
         add_password(user, realm, tfp);
     }
     apr_file_close(f);
@@ -310,7 +313,7 @@
      */
     if (apr_file_copy(dirname, argv[1], APR_FILE_SOURCE_PERMS, cntxt) !=
                 APR_SUCCESS) {
-        fprintf(stderr, "%s: unable to update file %s\n", 
+        apr_file_printf(errfile, "%s: unable to update file %s\n", 
                         argv[0], argv[1]);
     }
 #ifdef OMIT_DELONCLOSE


Guenter.

Mime
View raw message