On Tue, Feb 20, 2007 at 10:50:51AM +0100, Robert Millan [ackstorm] wrote:
> 
> Or maybe this one instead, which adds 'x' to the fopen call to prevent
> webalizer from overwriting existing .htaccess files.

And actualy this means we don't want to abort when errno==EEXIST.

New patch attached, with proper gettext'ed strings.

-- 
Robert Millan

ACK STORM, S.L.  -  http://www.ackstorm.es/
--- webalizer-2.01.10.old/output.c	2007-02-20 11:58:05.000000000 +0100
+++ webalizer-2.01.10/output.c	2007-02-20 12:16:54.000000000 +0100
@@ -30,6 +30,7 @@
 /* STANDARD INCLUDES                         */
 /*********************************************/
 
+#include <errno.h>
 #include <time.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -2590,6 +2591,23 @@
    /* now do html stuff... */
    snprintf(index_fname,sizeof(index_fname),"index.%s",html_ext);
 
+   if ((out_fp=fopen(".htaccess","wx")) != NULL)
+   {
+      fprintf(out_fp,"DirectoryIndex %s\n",index_fname);
+      fclose(out_fp);
+   }
+   else if (errno == EEXIST)
+   {
+      if (verbose)
+      fprintf(stderr,_("Refusing to overwrite file %s\n"),".htaccess");
+   }
+   else
+   {
+      if (verbose)
+      fprintf(stderr,_("Error: Unable to open file %s: %s\n"),".htaccess",strerror(errno));
+      return 1;
+   }
+
    if ( (out_fp=open_out_file(index_fname)) == NULL)
    {
       if (verbose)

Reply via email to