]> git.ipfire.org Git - thirdparty/sarg.git/blame - getconf.c
Fix uninitialized variables.
[thirdparty/sarg.git] / getconf.c
CommitLineData
25697a35 1/*
c37945ed 2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
a1de61fe 3 * 1998, 2009
94ff9470 4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
25697a35
GS
5 *
6 * SARG donations:
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
23 *
24 */
25
26#include "include/conf.h"
5f3cfd1d 27#include "include/defs.h"
25697a35
GS
28
29extern numlist hours, weekdays;
30
6e792ade 31static int is_param(const char *param,const char *buf)
0a4e18e1
FM
32{
33 int plen;
34
35 plen=strlen(param);
36 if (strncmp(buf,param,plen) != 0) return(0);
37 buf+=plen;
38 if ((unsigned char)*buf>' ') return(0);
39 return(1);
40}
41
4af2f8ff
FM
42static int getparam_string(const char *param,char *buf,char *value,int value_size)
43{
44 int plen;
45
46 plen=strlen(param);
47 if (strncmp(buf,param,plen) != 0) return(0);
48 buf+=plen;
49 if ((unsigned char)*buf>' ') return(0);
50 while (*buf && (unsigned char)*buf<=' ') buf++;
51
52 if (strlen(buf)>=value_size) {
53 printf("SARG: Maybe you have a broken record or garbage in %s parameter.\n",param);
54 exit(1);
55 }
56 strcpy(value,buf);
57 fixnone(value);
58 return(1);
59}
25697a35 60
4af2f8ff 61static int getparam_quoted(const char *param,char *buf,char *value,int value_size)
25697a35 62{
4af2f8ff
FM
63 int plen;
64 int i;
25697a35 65
4af2f8ff
FM
66 plen=strlen(param);
67 if (strncmp(buf,param,plen) != 0) return(0);
68 buf+=plen;
69 if ((unsigned char)*buf>' ') return(0);
70 while (*buf && (unsigned char)*buf<=' ') buf++;
25697a35 71
4af2f8ff 72 if (*buf != '\"') {
f29e90f8 73 printf("SARG: %s %s.\n",text[139],param);
4af2f8ff
FM
74 exit(1);
75 }
76 buf++;
25697a35 77
4af2f8ff
FM
78 value_size--;
79 for (i=0 ; i<value_size && *buf && *buf!='\"' ; i++) {
80 value[i]=*buf++;
81 }
82 value[i]='\0';
25697a35 83
4af2f8ff
FM
84 if (*buf != '\"') {
85 printf("SARG: Missing double quote after parameter %s or value is more than %d bytes long.\n",param,value_size);
86 exit(1);
87 }
88 fixnone(value);
89 return(1);
90}
25697a35 91
4af2f8ff
FM
92static int getparam_2words(const char *param,char *buf,char *word1,int word1_size,char *word2,int word2_size)
93{
94 int plen;
95 int i;
96
97 plen=strlen(param);
98 if (strncmp(buf,param,plen) != 0) return(0);
99 buf+=plen;
100 if ((unsigned char)*buf>' ') return(0);
101 while (*buf && (unsigned char)*buf<=' ') buf++;
102
103 for (i=0 ; i<word1_size && *buf && (unsigned char)*buf>' ' ; i++)
104 word1[i]=*buf++;
105 if (i>=word1_size) {
106 printf("SARG: The first word of parameter %s is more than %d bytes long.\n",param,word1_size-1);
107 exit(1);
108 }
109 if (*buf!=' ') {
110 printf("SARG: Missing second word for parameter %s.\n",param);
111 exit(1);
112 }
113 word1[i]=0;
25697a35 114
4af2f8ff 115 while (*buf && (unsigned char)*buf<=' ') buf++;
25697a35 116
4af2f8ff
FM
117 for (i=0 ; i<word2_size && *buf && (unsigned char)*buf>' ' ; i++)
118 word2[i]=*buf++;
119 if (i>=word2_size) {
120 printf("SARG: The second word of parameter %s is more than %d bytes long.\n",param,word2_size-1);
121 exit(1);
122 }
123 word2[i]=0;
25697a35 124
4af2f8ff
FM
125 fixnone(word1);
126 fixnone(word2);
127 return(1);
128}
25697a35 129
4af2f8ff
FM
130static int getparam_int(const char *param,char *buf,int *value)
131{
132 int plen;
133 int next;
134
135 plen=strlen(param);
136 if (strncmp(buf,param,plen) != 0) return(0);
137 buf+=plen;
138 if ((unsigned char)*buf>' ') return(0);
139 while (*buf && (unsigned char)*buf<=' ') buf++;
140
141 next=0;
142 if (sscanf(buf,"%d%n",value,&next) != 1 || (unsigned char)buf[next] > ' ') {
143 printf("SARG: Maybe you have a broken record or garbage in %s parameter.\n",param);
144 exit(1);
145 }
146 return(1);
147}
25697a35 148
4af2f8ff
FM
149static void parmtest(char *buf)
150{
151 char wbuf[50];
9c7c6346 152 struct getwordstruct gwarea;
25697a35 153
4af2f8ff 154 while (*buf && (unsigned char)*buf<=' ') buf++;
25697a35 155
4af2f8ff
FM
156 if(*buf == '#' || *buf == '\0')
157 return;
25697a35 158
4af2f8ff
FM
159 if(debugz)
160 printf("SARG: TAG: %s\n",buf);
25697a35 161
4af2f8ff 162 if (getparam_string("background_color",buf,BgColor,sizeof(BgColor))>0) return;
25697a35 163
4af2f8ff 164 if (getparam_string("text_color",buf,TxColor,sizeof(TxColor))>0) return;
25697a35 165
4af2f8ff 166 if (getparam_string("text_bgcolor",buf,TxBgColor,sizeof(TxBgColor))>0) return;
25697a35 167
4af2f8ff 168 if (getparam_string("title_color",buf,TiColor,sizeof(TiColor))>0) return;
25697a35 169
4af2f8ff 170 if (getparam_string("logo_image",buf,LogoImage,sizeof(LogoImage))>0) return;
25697a35 171
4af2f8ff 172 if (getparam_quoted("logo_text",buf,LogoText,sizeof(LogoText))>0) return;
25697a35 173
4af2f8ff 174 if (getparam_string("logo_text_color",buf,LogoTextColor,sizeof(LogoTextColor))>0) return;
25697a35 175
4af2f8ff 176 if (getparam_string("background_image",buf,BgImage,sizeof(BgImage))>0) return;
25697a35 177
4af2f8ff 178 if (getparam_string("show_sarg_info",buf,ShowSargInfo,sizeof(ShowSargInfo))>0) return;
25697a35 179
4af2f8ff 180 if (getparam_string("show_sarg_logo",buf,ShowSargLogo,sizeof(ShowSargLogo))>0) return;
25697a35 181
4af2f8ff 182 if (getparam_string("font_face",buf,FontFace,sizeof(FontFace))>0) return;
25697a35 183
4af2f8ff 184 if (getparam_string("header_color",buf,HeaderColor,sizeof(HeaderColor))>0) return;
25697a35 185
4af2f8ff 186 if (getparam_string("header_bgcolor",buf,HeaderBgColor,sizeof(HeaderBgColor))>0) return;
25697a35 187
4af2f8ff 188 if (getparam_string("font_size",buf,FontSize,sizeof(FontSize))>0) return;
25697a35 189
4af2f8ff 190 if (getparam_string("header_font_size",buf,HeaderFontSize,sizeof(HeaderFontSize))>0) return;
25697a35 191
4af2f8ff 192 if (getparam_string("title_font_size",buf,TitleFontSize,sizeof(TitleFontSize))>0) return;
25697a35 193
4af2f8ff 194 if (getparam_2words("image_size",buf,Width,sizeof(Width),Height,sizeof(Height))>0) return;
25697a35 195
4af2f8ff 196 if (getparam_quoted("title",buf,Title,sizeof(Title))>0) return;
25697a35 197
4af2f8ff 198 if (getparam_string("resolve_ip",buf,Ip2Name,sizeof(Ip2Name))>0) return;
25697a35 199
4af2f8ff
FM
200 if (getparam_string("user_ip",buf,UserIp,sizeof(UserIp))>0) return;
201
202 if (getparam_string("max_elapsed",buf,MaxElapsed,sizeof(MaxElapsed))>0) return;
25697a35 203
4af2f8ff 204 if(strstr(buf,"date_format") != 0) {
9c7c6346
FM
205 getword_start(&gwarea,buf);
206 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
4af2f8ff
FM
207 printf("SARG: Maybe you have a broken record or garbage in date_format parameter.\n");
208 exit(1);
25697a35 209 }
9c7c6346 210 strncpy(DateFormat,gwarea.current,1);
4af2f8ff
FM
211 fixnone(DateFormat);
212 return;
213 }
25697a35 214
4af2f8ff
FM
215 if( strstr( buf, "hours" ) != 0 ) {
216 if( getnumlist( buf, &hours, 24, 24 ) ) {
217 fprintf( stderr, "Error: Invalid syntax in hours tag!\n" );
218 exit( 1 );
25697a35 219 }
4af2f8ff 220 }
25697a35 221
4af2f8ff
FM
222 if( strstr( buf, "weekdays" ) != 0 ) {
223 if( getnumlist( buf, &weekdays, 7, 7 ) ) {
224 fprintf( stderr, "Error: Invalid syntax in weekdays tag!\n" );
225 exit( 1 );
25697a35 226 }
4af2f8ff 227 }
25697a35 228
4af2f8ff 229 if (getparam_2words("topuser_sort_field",buf,TopuserSortField,sizeof(TopuserSortField),TopuserSortOrder,sizeof(TopuserSortOrder))>0) return;
25697a35 230
4af2f8ff 231 if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return;
25697a35 232
6e792ade 233 if (is_param("access_log",buf)>0) {
0a4e18e1
FM
234 if (AccessLogFromCmdLine==0) {
235 if (NAccessLog>=MAXLOGS) {
236 fprintf(stderr,"SARG: Too many log files.\n");
237 exit(1);
238 }
239 getparam_string("access_log",buf,AccessLog[NAccessLog],MAXLEN);
240 NAccessLog++;
241 }
242 return;
243 }
25697a35 244
4af2f8ff 245 if (getparam_string("useragent_log",buf,UserAgentLog,sizeof(UserAgentLog))>0) return;
25697a35 246
4af2f8ff 247 if (getparam_string("exclude_hosts",buf,ExcludeHosts,sizeof(ExcludeHosts))>0) return;
25697a35 248
4af2f8ff 249 if (getparam_string("exclude_codes",buf,ExcludeCodes,sizeof(ExcludeCodes))>0) return;
25697a35 250
4af2f8ff 251 if (getparam_string("exclude_users",buf,ExcludeUsers,sizeof(ExcludeUsers))>0) return;
25697a35 252
4af2f8ff 253 if (getparam_string("password",buf,PasswdFile,sizeof(PasswdFile))>0) return;
25697a35 254
4af2f8ff 255 if (getparam_string("temporary_dir",buf,TempDir,sizeof(TempDir))>0) return;
25697a35 256
4af2f8ff 257 if (getparam_string("report_type",buf,ReportType,sizeof(ReportType))>0) return;
25697a35 258
4af2f8ff 259 if (getparam_string("output_dir",buf,OutputDir,sizeof(OutputDir))>0) return;
25697a35 260
4af2f8ff 261 if (getparam_string("output_email",buf,OutputEmail,sizeof(OutputEmail))>0) return;
25697a35 262
4af2f8ff 263 if (getparam_2words("per_user_limit",buf,PerUserLimitFile,sizeof(PerUserLimitFile),PerUserLimit,sizeof(PerUserLimit))>0) return;
25697a35 264
4af2f8ff 265 if (getparam_string("lastlog",buf,LastLog,sizeof(LastLog))>0) return;
25697a35 266
4af2f8ff 267 if (getparam_string("remove_temp_files",buf,RemoveTempFiles,sizeof(RemoveTempFiles))>0) return;
25697a35 268
4af2f8ff 269 if (getparam_string("replace_index",buf,ReplaceIndex,sizeof(ReplaceIndex))>0) return;
25697a35 270
4af2f8ff 271 if (getparam_string("index_tree",buf,IndexTree,sizeof(IndexTree))>0) return;
25697a35 272
4af2f8ff 273 if (getparam_string("index",buf,Index,sizeof(Index))>0) return;
25697a35 274
4af2f8ff 275 if (getparam_string("overwrite_report",buf,OverwriteReport,sizeof(OverwriteReport))>0) return;
25697a35 276
4af2f8ff 277 if (getparam_string("records_without_userid",buf,RecordsWithoutUser,sizeof(RecordsWithoutUser))>0) return;
25697a35 278
4af2f8ff 279 if (getparam_string("use_comma",buf,UseComma,sizeof(UseComma))>0) return;
25697a35 280
4af2f8ff 281 if (getparam_string("mail_utility",buf,MailUtility,sizeof(MailUtility))>0) return;
25697a35 282
4af2f8ff 283 if (getparam_string("topsites_num",buf,TopSitesNum,sizeof(TopSitesNum))>0) return;
25697a35 284
fb7c5f27 285 if (getparam_int("topuser_num",buf,&TopUsersNum)>0) return;
25697a35 286
4af2f8ff 287 if (getparam_string("usertab",buf,UserTabFile,sizeof(UserTabFile))>0) return;
25697a35 288
4af2f8ff 289 if (getparam_string("index_sort_order",buf,IndexSortOrder,sizeof(IndexSortOrder))>0) return;
25697a35 290
4af2f8ff 291 if (getparam_2words("topsites_sort_order",buf,TopsitesSortField,sizeof(TopsitesSortField),TopsitesSortType,sizeof(TopsitesSortType))>0) return;
25697a35 292
4af2f8ff 293 if (getparam_string("long_url",buf,LongUrl,sizeof(LongUrl))>0) return;
25697a35 294
4af2f8ff 295 if (getparam_string("language",buf,language,sizeof(language))>0) return;
d6e703cc 296
4af2f8ff 297 if (getparam_string("dansguardian_conf",buf,DansGuardianConf,sizeof(DansGuardianConf))>0) return;
25697a35 298
4af2f8ff 299 if (getparam_string("squidguard_conf",buf,SquidGuardConf,sizeof(SquidGuardConf))>0) return;
25697a35 300
4af2f8ff 301 if (getparam_string("date_time_by",buf,datetimeby,sizeof(datetimeby))>0) return;
25697a35 302
4af2f8ff
FM
303 if (getparam_string("charset",buf,CharSet,sizeof(CharSet))>0) {
304 ccharset(CharSet);
305 return;
306 }
25697a35 307
4af2f8ff 308 if (getparam_quoted("user_invalid_char",buf,UserInvalidChar,sizeof(UserInvalidChar))>0) return;
25697a35 309
4af2f8ff
FM
310 if (getparam_quoted("include_users",buf,IncludeUsers+1,sizeof(IncludeUsers)-2)>0) {
311 IncludeUsers[0]=':';
312 strcat(IncludeUsers,":");
313 return;
314 }
491b862f 315
4af2f8ff 316 if (getparam_quoted("exclude_string",buf,ExcludeString,sizeof(ExcludeString))>0) return;
25697a35 317
4af2f8ff 318 if (getparam_string("privacy",buf,Privacy,sizeof(Privacy))>0) return;
25697a35 319
78015ea0 320 if (getparam_quoted("privacy_string",buf,PrivacyString,sizeof(PrivacyString))>0) return;
25697a35 321
4af2f8ff 322 if (getparam_string("privacy_string_color",buf,PrivacyStringColor,sizeof(PrivacyStringColor))>0) return;
25697a35 323
4af2f8ff 324 if (getparam_string("show_successful_message",buf,SuccessfulMsg,sizeof(SuccessfulMsg))>0) return;
25697a35 325
4af2f8ff 326 if (getparam_string("show_read_statistics",buf,ShowReadStatistics,sizeof(ShowReadStatistics))>0) return;
25697a35 327
4af2f8ff 328 if (getparam_string("topuser_fields",buf,TopUserFields,sizeof(TopUserFields))>0) return;
25697a35 329
4af2f8ff 330 if (getparam_string("bytes_in_sites_users_report",buf,BytesInSitesUsersReport,sizeof(BytesInSitesUsersReport))>0) return;
25697a35 331
4af2f8ff 332 if (getparam_string("user_report_fields",buf,UserReportFields,sizeof(UserReportFields))>0) return;
25697a35 333
4af2f8ff 334 if (getparam_string("bytes_in_sites_users_report",buf,BytesInSitesUsersReport,sizeof(BytesInSitesUsersReport))>0) return;
94ff9470 335
4af2f8ff 336 if (getparam_string("datafile",buf,DataFile,sizeof(DataFile))>0) return;
25697a35 337
4af2f8ff 338 if (getparam_quoted("datafile_delimiter",buf,DataFileDelimiter,sizeof(DataFileDelimiter))>0) return;
25697a35 339
4af2f8ff 340 if (getparam_string("datafile_fields",buf,DataFileFields,sizeof(DataFileFields))>0) return;
25697a35 341
4af2f8ff 342 if (getparam_string("datafile_url",buf,DataFileUrl,sizeof(DataFileUrl))>0) return;
25697a35 343
4af2f8ff 344 if (getparam_string("parsed_output_log",buf,ParsedOutputLog,sizeof(ParsedOutputLog))>0) return;
25697a35 345
4af2f8ff 346 if (getparam_string("parsed_output_log_compress",buf,ParsedOutputLogCompress,sizeof(ParsedOutputLogCompress))>0) return;
25697a35 347
4af2f8ff 348 if (getparam_string("displayed_values",buf,DisplayedValues,sizeof(DisplayedValues))>0) return;
25697a35 349
4af2f8ff 350 if (getparam_int("authfail_report_limit",buf,&AuthfailReportLimit)>0) return;
25697a35 351
4af2f8ff 352 if (getparam_int("denied_report_limit",buf,&DeniedReportLimit)>0) return;
25697a35 353
4af2f8ff 354 if (getparam_int("siteusers_report_limit",buf,&SiteUsersReportLimit)>0) return;
25697a35 355
4af2f8ff 356 if (getparam_int("dansguardian_report_limit",buf,&DansGuardianReportLimit)>0) return;
25697a35 357
4af2f8ff 358 if (getparam_int("squidguard_report_limit",buf,&SquidGuardReportLimit)>0) return;
25697a35 359
4af2f8ff 360 if (getparam_int("user_report_limit",buf,&UserReportLimit)>0) return;
491b862f 361
4af2f8ff 362 if (getparam_int("download_report_limit",buf,&DownloadReportLimit)>0) return;
491b862f 363
4af2f8ff 364 if (getparam_string("www_document_root",buf,wwwDocumentRoot,sizeof(wwwDocumentRoot))>0) return;
25697a35 365
4af2f8ff 366 if (getparam_string("block_it",buf,BlockIt,sizeof(BlockIt))>0) return;
491b862f 367
4af2f8ff 368 if (getparam_string("external_css_file",buf,ExternalCSSFile,sizeof(ExternalCSSFile))>0) return;
491b862f 369
4af2f8ff 370 if (getparam_string("user_authentication",buf,UserAuthentication,sizeof(UserAuthentication))>0) return;
491b862f 371
4af2f8ff 372 if (getparam_string("AuthUserFile",buf,AuthUserFile,sizeof(AuthUserFile))>0) return;
491b862f 373
4af2f8ff 374 if (getparam_string("AuthName",buf,AuthName,sizeof(AuthName))>0) return;
491b862f 375
4af2f8ff
FM
376 if (getparam_string("AuthType",buf,AuthType,sizeof(AuthType))>0) return;
377
378 if (getparam_string("Require",buf,Require,sizeof(Require))>0) return;
379
6e792ade
FM
380 if (is_param("download_suffix",buf)) {
381 char warea[MAXLEN];
382
383 getparam_quoted("download_suffix",buf,warea,sizeof(warea));
384 set_download_suffix(warea);
385 }
d6e703cc 386
4af2f8ff
FM
387 if (getparam_string("graphs",buf,Graphs,sizeof(Graphs))>0) return;
388
389 if (getparam_string("graph_days_bytes_bar_color",buf,GraphDaysBytesBarColor,sizeof(GraphDaysBytesBarColor))>0) return;
390
391 if (getparam_string("squidguard_log_format",buf,SquidGuardLogFormat,sizeof(SquidGuardLogFormat))>0) return;
392
393 if (getparam_string("squidguard_ignore_date",buf,SquidguardIgnoreDate,sizeof(SquidguardIgnoreDate))>0) return;
394
395 if (getparam_string("dansguardian_ignore_date",buf,DansguardianIgnoreDate,sizeof(DansguardianIgnoreDate))>0) return;
396
397 if (getparam_string("ulimit",buf,Ulimit,sizeof(Ulimit))>0) return;
398
399 if (getparam_string("ntlm_user_format",buf,NtlmUserFormat,sizeof(NtlmUserFormat))>0) return;
400
401 if (getparam_string("realtime_types",buf,RealtimeTypes,sizeof(RealtimeTypes))>0) return;
402
403 if (getparam_string("realtime_unauthenticated_records",buf,RealtimeUnauthRec,sizeof(RealtimeUnauthRec))>0) return;
404
405 if (getparam_int("realtime_refresh_time",buf,&realtime_refresh)>0) return;
406
407 if (getparam_int("realtime_access_log_lines",buf,&realtime_access_log_lines)>0) return;
408
409 if(strstr(buf,"squid24") != 0) {
410 squid24++;
411 return;
412 }
413
414 if(strstr(buf,"byte_cost") != 0) {
9c7c6346
FM
415 getword_start(&gwarea,buf);
416 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
4af2f8ff
FM
417 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
418 exit(1);
419 }
9c7c6346
FM
420 cost=atol(gwarea.current);
421 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
4af2f8ff
FM
422 printf("SARG: Maybe you have a broken record or garbage in byte_cost parameter.\n");
423 exit(1);
491b862f 424 }
9c7c6346 425 nocost=my_atoll(gwarea.current);
4af2f8ff
FM
426 return;
427 }
428
f29e90f8 429 printf("SARG: %s %s\n",text[140],buf);
d6e703cc
FM
430}
431
32e71fa4 432void getconf(void)
d6e703cc
FM
433{
434
435 FILE *fp_in;
436 char buf[MAXLEN];
437
d2fe0c32
FM
438 if(debug)
439 debuga("Loading configuration from: %s",ConfigFile);
d6e703cc
FM
440
441 if ((fp_in = fopen(ConfigFile, "r")) == NULL) {
442 fprintf(stderr, "SARG: (getconf) Cannot open file: %s\n",ConfigFile);
443 exit(1);
444 }
445
4af2f8ff
FM
446 while (fgets(buf, sizeof(buf), fp_in) != NULL) {
447 fixendofline(buf);
d6e703cc
FM
448
449 if(debugm)
3103300b 450 printf("SYSCONFDIR %s\n",buf);
d6e703cc 451
d6e703cc
FM
452 parmtest(buf);
453
454 }
455
456 fclose(fp_in);
457 language_load(language);
458 return;
25697a35 459}