]> git.ipfire.org Git - thirdparty/sarg.git/blame - auth.c
Rename configure.in as configure.ac
[thirdparty/sarg.git] / auth.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
110ce984 3 * 1998, 2015
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
9 * ---------------------------------------------------------------------
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
24 *
25 */
26
27#include "include/conf.h"
5f3cfd1d 28#include "include/defs.h"
25697a35 29
d25d4e6a 30void htaccess(const struct userinfostruct *uinfo)
25697a35 31{
9bd92830
FM
32 char htname[MAXLEN];
33 char line[MAXLEN];
34 FILE *fp_in;
35 FILE *fp_auth;
36 size_t i,nread;
25697a35 37
9bd92830
FM
38 if(!UserAuthentication)
39 return;
25697a35 40
9bd92830 41 if (snprintf(htname,sizeof(htname),"%s/%s/.htaccess",outdirname,uinfo->filename)>=sizeof(htname)) {
af961877 42 debuga(__FILE__,__LINE__,_("Path too long: "));
041018b6 43 debuga_more("%s/%s/.htaccess\n",outdirname,uinfo->filename);
9bd92830
FM
44 exit(EXIT_FAILURE);
45 }
46 if((fp_auth=fopen(htname,"w"))==NULL) {
af961877 47 debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),htname,strerror(errno));
9bd92830
FM
48 exit(EXIT_FAILURE);
49 }
25697a35 50
9bd92830 51 if ((fp_in=fopen(AuthUserTemplateFile,"r"))==NULL) {
af961877 52 debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),AuthUserTemplateFile,strerror(errno));
9bd92830
FM
53 exit(EXIT_FAILURE);
54 }
25697a35 55
9bd92830
FM
56 while((nread=fread(line,1,sizeof(line),fp_in))!=0) {
57 for (i=0 ; i<nread ; i++)
58 if (line[i]=='%' && i+2<nread && line[i+1]=='u' && !isalpha(line[i+2])) {
59 fputs(uinfo->id,fp_auth);
60 i++;
61 } else {
62 fputc(line[i],fp_auth);
007905af 63 }
9bd92830 64 }
507460ae 65 if (fclose(fp_auth)==EOF) {
af961877 66 debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),htname,strerror(errno));
507460ae
FM
67 exit(EXIT_FAILURE);
68 }
204781f4 69 if (fclose(fp_in)==EOF) {
af961877 70 debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),AuthUserTemplateFile,strerror(errno));
204781f4
FM
71 exit(EXIT_FAILURE);
72 }
25697a35 73
9bd92830 74 return;
25697a35 75}