]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - auth.c
Remove the line number from a message
[thirdparty/sarg.git] / auth.c
diff --git a/auth.c b/auth.c
index 35dd7003ef598a2266e396006576d8ba171b35d6..5a5481415ff159caf1efafb24961e385a63e16c4 100644 (file)
--- a/auth.c
+++ b/auth.c
@@ -1,10 +1,11 @@
 /*
- * AUTHOR: Pedro Lineu Orso                         pedro.orso@gmail.com
- *                                                            1998, 2010
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
+ *                                                            1998, 2010
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
+ * Support:
+ *     http://sourceforge.net/projects/sarg/forums/forum/363374
  * ---------------------------------------------------------------------
  *
  *  This program is free software; you can redistribute it and/or modify
 #include "include/conf.h"
 #include "include/defs.h"
 
-void htaccess(const char *name)
+void htaccess(const struct userinfostruct *uinfo)
 {
    char htname[MAXLEN];
+   char line[MAXLEN];
+   FILE *fp_in;
    FILE *fp_auth;
-   int i;
+   size_t i,nread;
 
    if(!UserAuthentication)
       return;
 
-   sprintf(htname,"%s/%s/.htaccess",dirname,name);
+   if (snprintf(htname,sizeof(htname),"%s/%s/.htaccess",outdirname,uinfo->filename)>=sizeof(htname)) {
+      debuga(_("File name too long: %s/%s/.htaccess\n"),outdirname,uinfo->filename);
+      exit(EXIT_FAILURE);
+   }
    if((fp_auth=fopen(htname,"w"))==NULL) {
-      fprintf(stderr, "SARG: (auth) %s: %s - %s\n",text[45],htname,strerror(errno));
-      exit(1);
+      debuga(_("(auth) Cannot open file: %s - %s\n"),htname,strerror(errno));
+      exit(EXIT_FAILURE);
    }
 
-   fprintf(fp_auth,"AuthUserFile %s\n",AuthUserFile);
-   if(strchr(AuthName,'\"') == 0)
-      fprintf(fp_auth,"AuthName \"%s\"\n",AuthName);
-   else
-      fprintf(fp_auth,"AuthName %s\n",AuthName);
-   fprintf(fp_auth,"AuthType %s\n",AuthType);
-   fputs("<Limit GET POST>\nRequire ",fp_auth);
-   for (i=0 ; Require[i] ; i++)
-      if (Require[i]=='%' && Require[i+1]=='u') {
-         fputs(name,fp_auth);
-         i++;
-      } else {
-         fputc(Require[i],fp_auth);
+   if ((fp_in=fopen(AuthUserTemplateFile,"r"))==NULL) {
+      debuga(_("(auth) Cannot open template file: %s - %s\n"),AuthUserTemplateFile,strerror(errno));
+      exit(EXIT_FAILURE);
    }
-   fputs("\n</LIMIT>\n",fp_auth);
 
+   while((nread=fread(line,1,sizeof(line),fp_in))!=0) {
+      for (i=0 ; i<nread ; i++)
+         if (line[i]=='%' && i+2<nread && line[i+1]=='u' && !isalpha(line[i+2])) {
+            fputs(uinfo->id,fp_auth);
+            i++;
+         } else {
+            fputc(line[i],fp_auth);
+      }
+   }
    fclose(fp_auth);
+   fclose(fp_in);
 
    return;
 }