Package: cfingerd
Version: 1.4.3-1.2
Followup-For: Bug #381611
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
In attachment there is a patch with rewritten code - this resolves
problem with too long lines.
- -- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'stable')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.17-ck1
Locale: LANG=pl_PL, LC_CTYPE=pl_PL (charmap=ISO-8859-2) (ignored: LC_ALL set to
pl_PL)
Versions of packages cfingerd depends on:
ii libc6 2.3.6-18 GNU C Library: Shared libraries
ii netbase 4.25 Basic TCP/IP networking system
cfingerd recommends no packages.
- -- no debconf information
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
iD8DBQFE1eEnKW0DB9D0o0kRAmwmAJ9is4UBQAAAtPjBisHIQozynvOzawCfb68E
x4xJeMOudHoGKBmwfrExa0Y=
=zzQH
-----END PGP SIGNATURE-----
Sun Aug 6 14:19:59 CEST 2006 [EMAIL PROTECTED]
* New configuration reading with getline - closes Debian Bug #381611
--- old-cfingerd/src/configure.c 2006-08-06 14:27:08.477099064 +0200
+++ new-cfingerd/src/configure.c 2006-08-06 14:27:08.486097696 +0200
@@ -13,6 +13,8 @@
* GNU General Public License for more details.
*/
+#define _GNU_SOURCE
+#include <stdio.h>
#include "cfingerd.h"
#include "proto.h"
#include "privs.h"
@@ -165,6 +167,65 @@
FILE *file, *logfile;
+struct Field
+{
+ const char *name;
+ char **target;
+ size_t len;
+}
+display_files_fields[]={
+ {"PLAN",&prog_config.plan_file,4},
+ {"PROJECT",&prog_config.project_file,7},
+ {"PGP_KEY",&prog_config.pgpkey_file,7},
+ {"XFACE",&prog_config.xface_file,5},
+ {"NO_FINGER",&prog_config.no_finger_file,9},
+ {"LOGFILE",&prog_config.log_file,7},
+ {"HEADER_DISPLAY",&prog_config.top_display_file,14},
+ {"FOOTER_DISPLAY",&prog_config.bottom_display_file,14},
+ {"NO_NAME_BANNER",&prog_config.no_name_banner_file,14},
+ {"NO_USER_BANNER",&prog_config.no_user_banner_file,14},
+ {"REJECTED_BANNER",&prog_config.rejected_file,15},
+ {"USERLOG",&prog_config.userlog_file,7},
+ {"MAILBOX",&prog_config.mailbox_file,7},
+ {NULL,NULL}
+},
+finger_programs_fields[]={
+ {"FINGER",&prog_config.finger_program,6},
+ {"WHOIS",&prog_config.whois_program,5},
+ {NULL,NULL}
+};
+
+struct Type
+{
+ const char *name;
+ int type;
+ size_t len;
+}
+files_types[]={
+ {"display_files",DISPLAY_FILES,13},
+ {"finger_programs",FINGER_PROGRAMS,15},
+ {"finger_fakeusers",FINGER_FAKEUSERS,16},
+ {NULL,0,0}
+},
+hosts_types[]={
+ {"trusted",TRUSTED,7},
+ {"rejected",REJECTED,8},
+ {"finger_forward",FORWARD,14},
+ {NULL,0,0}
+},
+config_types[]={
+ {"finger_display",FINGER_DISPLAY,14},
+ {"internal_config",INTERNAL_CONFIG,15},
+ {"system_list_sites",SYSTEM_LIST_SITES,17},
+ {"finger_strings",FINGER_STRINGS,14},
+ {"internal_strings",INTERNAL_STRINGS,16},
+ {"services_header",SERVICES_HEADER,15},
+ {"services_positions",SERVICES_POSITIONS,18},
+ {"signal_strings",SIGNAL_STRINGS,14},
+ {NULL,0,0}
+};
+;
+
/*
* DO_FILES
*
@@ -173,163 +234,103 @@
*/
void do_files(char *str)
{
- char *line;
- int done = 0, type = 0, errors = 0;
-
- line = (char *) malloc(80);
- sscanf(str, "FILES %[^ =] = {\r\n", line);
-
- if (!(strncasecmp(line, "display_files", 13)))
- type = DISPLAY_FILES;
- else if (!(strncasecmp(line, "finger_programs", 15)))
- type = FINGER_PROGRAMS;
- else if (!(strncasecmp(line, "finger_fakeusers", 16)))
- type = FINGER_FAKEUSERS;
-
- free(line);
-
- while(!done) {
- line = (char *) malloc(80);
-
- fscanf(file, "%[^\r\n]\r\n", line);
- if (!(strncmp(line, "}", 1)))
- done++;
- else if (line[0] != '#') {
- if (type == DISPLAY_FILES) {
- char *element, *filename;
-
- element = (char *) malloc(80);
- filename = (char *) malloc(80);
-
- sscanf(line, "\t%[^\t]\t= \"%[^\",]\",\r\n", element, filename);
-
- /* Erk - this needs to be optimized... :/ */
- if (!(strncasecmp(element, "PLAN", 4)))
- strmcpy(&prog_config.plan_file, (char *) filename);
- else if (!(strncasecmp(element, "PROJECT", 7)))
- strmcpy(&prog_config.project_file, (char *) filename);
- else if (!(strncasecmp(element, "PGP_KEY", 7)))
- strmcpy(&prog_config.pgpkey_file, (char *) filename);
- else if (!(strncasecmp(element, "XFACE", 5)))
- strmcpy(&prog_config.xface_file, (char *) filename);
- else if (!(strncasecmp(element, "NO_FINGER", 9)))
- strmcpy(&prog_config.no_finger_file, (char *) filename);
- else if (!(strncasecmp(element, "LOGFILE", 7))) {
- strmcpy(&prog_config.log_file, (char *) filename);
-
- PRIV_ROOT_START
- logfile = fopen(filename, "a+");
- PRIV_ROOT_END
-
- if (logfile)
- can_log = TRUE;
- else {
- syslog(LOG_ERR, "Cannot log to %s: %s", filename, strerror(errno));
- can_log = FALSE;
- }
- } else if (!(strncasecmp(element, "HEADER_DISPLAY", 14)))
- strmcpy(&prog_config.top_display_file, (char *) filename);
- else if (!(strncasecmp(element, "FOOTER_DISPLAY", 14)))
- strmcpy(&prog_config.bottom_display_file, (char *) filename);
- else if (!(strncasecmp(element, "NO_NAME_BANNER", 14)))
- strmcpy(&prog_config.no_name_banner_file, (char *) filename);
- else if (!(strncasecmp(element, "NO_USER_BANNER", 14)))
- strmcpy(&prog_config.no_user_banner_file, (char *) filename);
- else if (!(strncasecmp(element, "REJECTED_BANNER", 15)))
- strmcpy(&prog_config.rejected_file, (char *) filename);
- else if (!(strncasecmp(element, "USERLOG", 7)))
- strmcpy(&prog_config.userlog_file, (char *) filename);
- else if (!(strncasecmp(element, "MAILBOX", 7)))
- strmcpy(&prog_config.mailbox_file, (char *) filename);
- else if (element[0] == '#') {
- /* Ignore commented out lines */
- } else {
- errors++;
- printf("Option %s unknown in display_files.\n", element);
- }
-
- free(element);
- free(filename);
- } else if (type == FINGER_PROGRAMS) {
- char *element, *filename;
-
- if (line[0] != '#') {
- element = (char *) malloc(80);
- filename = (char *) malloc(80);
-
- sscanf(line, "\t%[^\t]\t= \"%[^\",]\",\r\n", element, filename);
-
- if (!(strncasecmp(element, "FINGER", 6)))
- strmcpy(&prog_config.finger_program, (char *) filename);
- else if (!(strncasecmp(element, "WHOIS", 5)))
- strmcpy(&prog_config.whois_program, (char *) filename);
- else {
- errors++;
- printf("Option %s unknown in finger_programs.\n", element);
- }
-
- free(element);
- free(filename);
- }
- } else if (type == FINGER_FAKEUSERS) {
- char *element, *fakename, *boolean, *filename;
-
- element = (char *) malloc(80);
- fakename = (char *) malloc(80);
- boolean = (char *) malloc(80);
- filename = (char *) malloc(80);
-
- sscanf(line, "\t\"%[^\"]\", \"%[^\"]\", %[^,], \"%[^\"]\",\r\n",
- element, fakename, boolean, filename);
-
- strmcpy(&prog_config.fusers[fakeuser_num].user, (char *) element);
- strmcpy(&prog_config.fusers[fakeuser_num].script, (char *) filename);
- strmcpy(&prog_config.fusers[fakeuser_num].description, (char *) fakename);
- if (!(strncasecmp(boolean, "TRUE", 4)))
- prog_config.fusers[fakeuser_num].searchable = TRUE;
- else if (!(strncasecmp(boolean, "FALSE", 5)))
- prog_config.fusers[fakeuser_num].searchable = FALSE;
- else {
- printf("Wrong boolean in FAKEUSERS!\n");
- fflush(stdout);
- exit(-1);
- }
-
- fakeuser_num++;
-
- free(element);
- free(fakename);
- free(boolean);
- free(filename);
- }
+ char *line=NULL;
+ size_t linelen;
+ int type=0,errors=0,ok;
+ char *element=NULL, *filename=NULL, *fakename=NULL, *boolean=NULL;
+ struct Field *f;
+ struct Type *t;
+
+ linelen=strlen(str)+1;
+ line = malloc(linelen);
+ sscanf(str,"FILES %[^ =] = {",line);
+ for(t=files_types;t->name;++t)
+ if(strncasecmp(line,t->name,t->len)==0)
+ type=t->type;
+ if(type==0)
+ {
+ printf("Unknown FILES type: %s\n",line);
+ exit(1);
}
-
+ for(;;)
+ {
+ getline(&line,&linelen,file);
+ if(line[0]=='#')
+ continue;
+ if(line[0]=='}')
+ break;
+ element=realloc(element,linelen);
+ filename=realloc(filename,linelen);
+ fakename=realloc(fakename,linelen);
+ boolean=realloc(boolean,linelen);
+ if(type==DISPLAY_FILES)
+ {
+ sscanf(line, "\t%[^\t]\t= \"%[^\",]\",\r\n", element, filename);
+ ok=0;
+ for(f=display_files_fields;f->name;++f)
+ if(strncasecmp(f->name,element,f->len)==0)
+ {
+ strmcpy(f->target,filename);
+ ok=1;
+ }
+ if(ok==0)
+ {
+ errors++;
+ printf("Option %s unknown in display_files.\n", element);
+ }
+ continue;
+ }
+ if(type==FINGER_PROGRAMS)
+ {
+ sscanf(line, "\t%[^\t]\t= \"%[^\",]\",\r\n", element, filename);
+ ok=0;
+ for(f=finger_programs_fields;f->name;++f)
+ if(strncasecmp(f->name,element,f->len)==0)
+ {
+ strmcpy(f->target,filename);
+ ok=1;
+ }
+ if(ok==0)
+ {
+ errors++;
+ printf("Option %s unknown in finger_programs.\n", element);
+ }
+ continue;
+ }
+ if(type==FINGER_FAKEUSERS)
+ {
+ sscanf(line, "\t\"%[^\"]\", \"%[^\"]\", %[^,], \"%[^\"]\",\r\n",
+ element, fakename, boolean, filename);
+ strmcpy(&prog_config.fusers[fakeuser_num].user, element);
+ strmcpy(&prog_config.fusers[fakeuser_num].script, filename);
+ strmcpy(&prog_config.fusers[fakeuser_num].description, fakename);
+ prog_config.fusers[fakeuser_num].searchable=strncasecmp(boolean, "TRUE", 4)?TRUE:FALSE;
+ fakeuser_num++;
+ }
+ }
+ PRIV_ROOT_START;
+ logfile = fopen(filename, "a+");
+ PRIV_ROOT_END;
+ if(!logfile)
+ {
+ syslog(LOG_ERR, "Cannot log to %s: %s", prog_config.userlog_file, strerror(errno));
+ can_log=FALSE;
+ }
+ else
+ can_log=TRUE;
free(line);
- }
-
- if (errors != 0) {
- printf("%d error%sw%s found in FILES section. Please fix %s.\n\n",
- errors, (errors == 1) ? " " : "s ", (errors == 1) ? "as" : "ere",
- (errors == 1) ? "it" : "them");
- exit(0);
- }
-}
-
-/*
- * HAS
- *
- * This routine simply returns a TRUE or FALSE as to whether or not the
- * specified STRing has the SEARCH character in it.
- */
-int has(char *str, char search)
-{
- while(*str) {
- if (*str == search)
- return 1;
- str++;
- }
-
- return 0;
+ free(element);
+ free(fakename);
+ free(filename);
+ free(boolean);
+
+ if(errors)
+ {
+ printf("%d error%sw%s found in FILES section. Please fix %s.\n\n",
+ errors, (errors == 1) ? " " : "s ", (errors == 1) ? "as" : "ere",
+ (errors == 1) ? "it" : "them");
+ exit(1);
+ }
}
/*
@@ -341,48 +342,47 @@
*/
void do_hosts(char *str)
{
- char *line;
- int done = 0, type = 0;
- char *cp;
-
- line = (char *) malloc(80);
- sscanf(str, "HOSTS %[^ =] = {\r\n", line);
-
- if (!(strncmp(line, "trusted", 7)))
- type = TRUSTED;
- else if (!(strncmp(line, "rejected", 8)))
- type = REJECTED;
- else if (!(strncmp(line, "finger_forward", 14)))
- type = FORWARD;
-
- free(line);
-
- while(!done) {
- line = (char *) malloc(80);
-
- fscanf(file, "%[^\r\n]\r\n", line);
- if (!(strncmp(line, "}", 1)))
- done++;
- else if (line[0] != '#') {
- char *host;
-
- host = (char *) malloc(80);
- sscanf(line, "\t%[^,\r\n],\r\n", host);
-
- for (cp=host; *cp; cp++)
- if (isupper(*cp))
- *cp = tolower (*cp);
-
- if (type == TRUSTED)
- strmcpy(&prog_config.trusted[trusted_host_num++], host);
- else if (type == REJECTED)
- strmcpy(&prog_config.rejected[rejected_host_num++], host);
- else if (type == FORWARD)
- strmcpy(&prog_config.forward[forward_host_num++], host);
-
- free(host);
+ char *line=NULL,*host=NULL;
+ size_t linelen=0;
+ int type=0;
+ struct Type *t;
+
+ linelen=strlen(str)+1;
+ line=malloc(linelen);
+ sscanf(str,"HOSTS %[^ =] = {\r\n",line);
+ for(t=hosts_types;t->name;++t)
+ if(strncasecmp(line,t->name,t->len)==0)
+ type=t->type;
+ if(type==0)
+ {
+ printf("Unknown HOSTS type: %s\n",line);
+ exit(1);
}
- }
+ for(;;)
+ {
+ if(getline(&line,&linelen,file)<=0)
+ break;
+ if(line[0]=='#')
+ continue;
+ if(line[0]=='}')
+ break;
+ host=realloc(host,linelen);
+ sscanf(line,"\t%[^,\r\n],\r\n", host);
+ switch(type)
+ {
+ case TRUSTED:
+ strmcpy(&prog_config.trusted[trusted_host_num++], host);
+ break;
+ case REJECTED:
+ strmcpy(&prog_config.rejected[rejected_host_num++], host);
+ break;
+ case FORWARD:
+ strmcpy(&prog_config.forward[forward_host_num++], host);
+ break;
+ }
+ }
+ free(line);
+ free(host);
}
/*
@@ -393,286 +393,195 @@
*/
void do_config(char *str)
{
- char *line;
- int done = 0, type = 0, errors = 0;
-
- line = (char *) malloc(80);
- sscanf(str, "CONFIG %[^ =] = {\r\n", line);
-
- /* Argh - I need to optimize THIS too! */
- if (!(strncasecmp(line, "finger_display", 14)))
- type = FINGER_DISPLAY;
- else if (!(strncasecmp(line, "internal_config", 15)))
- type = INTERNAL_CONFIG;
- else if (!(strncasecmp(line, "system_list_sites", 17)))
- type = SYSTEM_LIST_SITES;
- else if (!(strncasecmp(line, "finger_strings", 14)))
- type = FINGER_STRINGS;
- else if (!(strncasecmp(line, "internal_strings", 16)))
- type = INTERNAL_STRINGS;
- else if (!(strncasecmp(line, "services_header", 15)))
- type = SERVICES_HEADER;
- else if (!(strncasecmp(line, "services_positions", 18)))
- type = SERVICES_POSITIONS;
- else if (!(strncasecmp(line, "signal_strings", 14)))
- type = SIGNAL_STRINGS;
-
- free(line);
-
- while(!done) {
- line = (char *) malloc(80);
-
- fgets(line, 80, file);
- if (!(strncmp(line, "}", 1)))
- done++;
- else if (line[0] != '#') {
- if (type == FINGER_DISPLAY) {
- char *element, *opt1, *opt2, *opt3;
- int x, found = FALSE;
-
- element = (char *) malloc(80);
- opt1 = (char *) malloc(80);
- opt2 = (char *) malloc(80);
- opt3 = (char *) malloc(80);
-
- sscanf(line, "\t%[+-]%[^\t =]\t = \133%[^,], %[^\135,]\135,",
- opt3, element, opt1, opt2);
-
- for (x = 0; ((finger_display[x].item != NULL) &&
- (!found)); x++) {
- if (!(strncasecmp(element, finger_display[x].item,
- strlen(finger_display[x].item)))) {
- if (!(strncasecmp(opt1, "TRUE", 4))) {
- if (finger_display[x].section == 1)
- prog_config.config_bits1 |= finger_display[x].value;
- else if (finger_display[x].section == 2)
- prog_config.config_bits2 |= finger_display[x].value;
- else
- prog_config.config_bits3 |= finger_display[x].value;
-
- found = TRUE;
- }
-
- if (!(strncasecmp(opt2, "TRUE", 4))) {
- if (finger_display[x].section == 1)
- prog_config.local_config_bits1 |= finger_display[x].value;
- else if (finger_display[x].section == 2)
- prog_config.local_config_bits2 |= finger_display[x].value;
- else
- prog_config.local_config_bits3 |= finger_display[x].value;
-
- found = TRUE;
+ char *line=NULL,*element=NULL,*opt1=NULL,*opt2=NULL,*opt3=NULL;
+ size_t linelen=0;
+ int type=0,x=0,found,errors=0;
+ struct Type *t;
+
+ linelen=strlen(str)+1;
+ line=malloc(linelen);
+ sscanf(str, "CONFIG %[^ =] = {\r\n", line);
+
+ for(t=config_types;t->name;++t)
+ if(strncasecmp(line,t->name,t->len)==0)
+ type=t->type;
+ if(type==0)
+ {
+ printf("Unknown CONFIG type: %s\n",line);
+ exit(1);
+ }
+ for(;;)
+ {
+ if(getline(&line,&linelen,file)<=0)
+ break;
+ if(line[0]=='#')
+ continue;
+ if(line[0]=='}')
+ break;
+ element=realloc(element,linelen);
+ opt1=realloc(opt1,linelen);
+ opt2=realloc(opt2,linelen);
+ opt3=realloc(opt3,linelen);
+ found=FALSE;
+ if(type==FINGER_DISPLAY)
+ {
+ sscanf(line, "\t%[+-]%[^\t =]\t = \133%[^,], %[^\135,]\135,", opt3, element, opt1, opt2);
+ for(x=0; finger_display[x].item!=NULL; ++x)
+ {
+ if(strncasecmp(element, finger_display[x].item,strlen(finger_display[x].item))==0)
+ {
+ found=TRUE;
+ if(strncasecmp(opt1,"TRUE",4)==0)
+ {
+ if(finger_display[x].section == 1)
+ prog_config.config_bits1 |= finger_display[x].value;
+ else if (finger_display[x].section == 2)
+ prog_config.config_bits2 |= finger_display[x].value;
+ else
+ prog_config.config_bits3 |= finger_display[x].value;
+ }
+ if(strncasecmp(opt2,"TRUE",4)==0)
+ {
+ if(finger_display[x].section == 1)
+ prog_config.local_config_bits1 |= finger_display[x].value;
+ else if (finger_display[x].section == 2)
+ prog_config.local_config_bits2 |= finger_display[x].value;
+ else
+ prog_config.local_config_bits3 |= finger_display[x].value;
+ }
+ if(opt3[0]=='+')
+ {
+ if(finger_display[x].section == 1)
+ prog_config.override_bits1 |= finger_display[x].value;
+ else if (finger_display[x].section == 2)
+ prog_config.override_bits2 |= finger_display[x].value;
+ else
+ prog_config.override_bits3 |= finger_display[x].value;
+ }
+ break;
+ }
}
-
- if (!(strncasecmp(opt1, "FALSE", 5)))
- found = TRUE;
-
- if (!(strncasecmp(opt2, "FALSE", 5)))
- found = TRUE;
-
- if (opt3[0] == '+') {
- if (finger_display[x].section == 1)
- prog_config.override_bits1 |= finger_display[x].value;
- else if (finger_display[x].section == 2)
- prog_config.override_bits2 |= finger_display[x].value;
- else
- prog_config.override_bits3 |= finger_display[x].value;
-
- found = TRUE;
+ if(!found)
+ {
+ errors++;
+ printf("Option %s unknown in finger_display.\n", element);
}
- }
+ continue;
}
-
- if (!found) {
- errors++;
- printf("Option %s unknown in finger_display.\n", element);
- }
-
- free(element);
- free(opt1);
- free(opt2);
- free(opt3);
- } else if (type == INTERNAL_CONFIG) {
- char *element, *opt;
- int x, found = FALSE;
-
- element = (char *) malloc(80);
- opt = (char *) malloc(2);
-
- sscanf(line, "\t%[+-]%[^,\r\n],\r\n", opt, element);
-
- for (x = 0; ((internal_config[x].item != NULL) &&
- (!found)); x++) {
- if (!(strncasecmp(element, internal_config[x].item,
- strlen(internal_config[x].item)))) {
- if (opt[0] == '+') {
- if (internal_config[x].section == 1)
- prog_config.config_bits1 |= internal_config[x].value;
- else if (internal_config[x].section == 2)
- prog_config.config_bits2 |= internal_config[x].value;
- else if (internal_config[x].section == 3)
- prog_config.config_bits3 |= internal_config[x].value;
+ if(type==INTERNAL_CONFIG)
+ {
+ sscanf(line, "\t%[+-]%[^,\r\n],\r\n", opt1, element);
+ for(x=0; internal_config[x].item!=NULL; ++x)
+ if(strncasecmp(element, internal_config[x].item,strlen(internal_config[x].item))==0)
+ {
+ found=TRUE;
+ if(opt1[0]=='+')
+ {
+ if (internal_config[x].section == 1)
+ prog_config.config_bits1 |= internal_config[x].value;
+ else if (internal_config[x].section == 2)
+ prog_config.config_bits2 |= internal_config[x].value;
+ else
+ prog_config.config_bits3 |= internal_config[x].value;
+ }
+ break;
+ }
+ if(!found)
+ {
+ errors++;
+ printf("Option %s unknown in internal_config.\n", element);
}
+ continue;
- found = TRUE;
- }
- }
-
- if (!found) {
- errors++;
- printf("Option %s unknown in internal_config.\n", element);
- }
-
- free(element);
- free(opt);
- } else if (type == SYSTEM_LIST_SITES) {
- char *element;
-
- element = (char *) malloc(80);
-
- sscanf(line, "\t%[^,\r\n],\r\n", element);
-
- strmcpy(&prog_config.finger_sites[num_finger_sites++], element);
-
- free(element);
- } else if (type == FINGER_STRINGS) {
- char *element, *string;
- int x, found = FALSE;
-
- element = (char *) malloc(80);
- string = (char *) malloc(80);
-
- sscanf(line, "\t%[^\t=] = \"%[^\",\r\n]\",\r\n",
- element, string);
-
- for (x = 0; ((finger_strings[x].item != NULL) &&
- (!found)); x++) {
- if (!(strncasecmp(element, finger_strings[x].item,
- strlen(finger_strings[x].item)))) {
- strmcpy(&prog_config.p_strings[finger_strings[x].value],
- string);
-
- found = TRUE;
- }
}
+ if(type==SYSTEM_LIST_SITES)
+ {
+ sscanf(line, "\t%[^,\r\n],\r\n", element);
+ strmcpy(&prog_config.finger_sites[num_finger_sites++], element);
+ continue;
+ }
+ if(type==FINGER_STRINGS)
+ {
+ sscanf(line, "\t%[^\t=] = \"%[^\",\r\n]\",\r\n",element,opt1);
+ for(x=0; finger_strings[x].item!=NULL; ++x)
+ {
+ if(strncasecmp(element, finger_strings[x].item,strlen(finger_strings[x].item))==0)
+ {
+ strmcpy(&prog_config.p_strings[finger_strings[x].value],opt1);
+ found=TRUE;
+ }
+ }
+ if(!found)
+ {
+ errors++;
+ printf("Option %s unknown in internal_strings.\n", element);
+ }
+ continue;
- if (!found) {
- errors++;
- printf("Option %s unknown in finger_strings.\n", element);
- }
-
- free(element);
- free(string);
- } else if (type == INTERNAL_STRINGS) {
- char *element, *string;
- int x, found = FALSE;
-
- element = (char *) malloc(80);
- string = (char *) malloc(80);
-
- sscanf(line, "\t%[^\t=] = \"%[^\",\r\n]\",\r\n",
- element, string);
-
- for (x = 0; ((internal_strings[x].item != NULL) &&
- (!found)); x++) {
- if (!(strncasecmp(element, internal_strings[x].item,
- strlen(internal_strings[x].item)))) {
- strmcpy(&prog_config.p_strings[internal_strings[x].value],
- string);
-
- found = TRUE;
- }
}
-
- if (!found) {
- errors++;
- printf("Option %s unknown in internal_strings.\n", element);
+ if(type==SERVICES_HEADER)
+ {
+ sscanf(line, "%[^\r\n]\r\n", element);
+ x=strlen(element);
+ if(x>3)
+ {
+ if(strchr(element,'%')==NULL)
+ {
+ element[x++]='\n';
+ element[x]='\0';
+ if(element[0]!=0)
+ strmcpy(&prog_config.services.header[num_headers++], element);
+ else
+ strmcpy(&prog_config.services.header[num_headers++], " ");
+ }
+ else
+ strmcpy(&prog_config.services.display_string, element);
+ }
+ else
+ prog_config.services.header[num_headers++] = " \n";
+ continue;
}
-
- free(element);
- free(string);
- } else if (type == SERVICES_HEADER) {
- char *element;
- int counter;
-
- element = (char *) malloc(80);
-
- sscanf(line, "%[^\r\n]\r\n", element);
-
- if (strlen(element) > 3) {
- counter = strlen(element);
- if (!has(element, '%')) {
- element[counter++] = '\n';
- element[counter] = '\0';
- }
-
- if (!has(element, '%')) {
- if (element[0] != 0)
- strmcpy(&prog_config.services.header[num_headers++], element);
+ if(type==SERVICES_POSITIONS)
+ {
+ sscanf(line, "\t%[^\t=] = %[^,\r\n],\r\n", element, opt1);
+ if(strncasecmp(element, "USER", 4)==0)
+ prog_config.services.name_pos = atoi(opt1);
+ else if(strncasecmp(element, "SERVICE", 7)==0)
+ prog_config.services.service_pos = atoi(opt1);
+ else if(strncasecmp(element, "SEARCH", 6)==0)
+ prog_config.services.search_pos = atoi(opt1);
else
- strmcpy(&prog_config.services.header[num_headers++], " ");
- } else
- strmcpy(&prog_config.services.display_string, element);
-
- free(element);
- } else
- prog_config.services.header[num_headers++] = " \n";
- } else if (type == SERVICES_POSITIONS) {
- char *element, *num;
-
- element = (char *) malloc(80);
- num = (char *) malloc(80);
-
- sscanf(line, "\t%[^\t=] = %[^,\r\n],\r\n", element, num);
-
- if (!(strncasecmp(element, "USER", 4)))
- prog_config.services.name_pos = atoi(num);
- else if (!(strncasecmp(element, "SERVICE", 7)))
- prog_config.services.service_pos = atoi(num);
- else if (!(strncasecmp(element, "SEARCH", 6)))
- prog_config.services.search_pos = atoi(num);
- else {
- errors++;
- printf("Option %s unknown in services_positions.\n", element);
- }
-
- free(element);
- free(num);
- } else if (type == SIGNAL_STRINGS) {
- char *element, *string;
- int x, found = FALSE;
-
- element = (char *) malloc(80);
- string = (char *) malloc(80);
-
- sscanf(line, "\t%[^\t=] = \"%[^\",\r\n]\",\r\n",
- element, string);
-
- for (x = 0; ((signal_strings[x].item != NULL) &&
- (!found)); x++) {
- if (!(strncasecmp(element, signal_strings[x].item,
- strlen(signal_strings[x].item)))) {
- strmcpy(&prog_config.siglist[signal_strings[x].value],
- string);
-
- found = TRUE;
- }
- }
-
- if (!found) {
- errors++;
- printf("Option %s unknown in signal_strings.\n", element);
+ {
+ errors++;
+ printf("Option %s unknown in services_positions.\n", element);
+ }
+ continue;
+ }
+ if(type==SIGNAL_STRINGS)
+ {
+ sscanf(line, "\t%[^\t=] = \"%[^\",\r\n]\",\r\n",element,opt1);
+ for(x=0; signal_strings[x].item!=NULL; ++x)
+ if(strncasecmp(element, signal_strings[x].item,strlen(signal_strings[x].item))==0)
+ {
+ strmcpy(&prog_config.siglist[signal_strings[x].value],opt1);
+ found=TRUE;
+ break;
+ }
+ if(!found)
+ {
+ errors++;
+ printf("Option %s unknown in signal_strings.\n", element);
+ }
+ continue;
}
- }
}
- }
-
- if (errors != 0) {
- printf("%d error%sw%s found in CONFIG section. Please fix %s.\n\n",
- errors, (errors == 1) ? " " : "s ", (errors == 1) ? "as" : "ere",
- (errors == 1) ? "it" : "them");
- exit(0);
- }
+ if(errors)
+ {
+ printf("%d error%sw%s found in CONFIG section. Please fix %s.\n\n",
+ errors, (errors == 1) ? " " : "s ", (errors == 1) ? "as" : "ere",
+ (errors == 1) ? "it" : "them");
+ exit(1);
+ }
}
/*
@@ -682,43 +591,35 @@
*/
void read_configuration(void)
{
- PRIV_ROOT_START
- file = fopen(CFINGERD_CONF, "r");
- PRIV_ROOT_END
-
- trusted_host_num = rejected_host_num = fakeuser_num = num_finger_sites = 0;
- forward_host_num = 0;
- num_headers = 1;
-
- if (file)
- while(!feof(file)) {
- char *line;
- int ch = fgetc(file);
-
- /* Patch by Kevin Rosenberg 10/21/95 */
- if (ch == EOF)
- break;
-
- ungetc(ch, file);
- line = (char *) malloc(80);
- if ((ch != '#') && (ch != '\'')) {
- fgets(line, 80, file);
- if (!(strncasecmp(line, "FILES ", 6))) {
- do_files(line);
- } else if (!(strncasecmp(line, "HOSTS ", 6))) {
- do_hosts(line);
- } else if (!(strncasecmp(line, "CONFIG ", 7))) {
- do_config(line);
- }
- } else
- fgets(line, 80, file);
-
- free(line);
- }
- else {
- printf("No cfingerd.conf file present. Check your setup.\n");
- exit(1);
- }
+ char *line=NULL;
+ size_t linelen=0;
+
+ PRIV_ROOT_START;
+ file = fopen(CFINGERD_CONF, "r");
+ PRIV_ROOT_END;
+
+ trusted_host_num = rejected_host_num = fakeuser_num = num_finger_sites = forward_host_num = 0;
+ num_headers = 1;
+
+ if(!file)
+ {
+ printf("No cfingerd.conf file present. Check your setup.\n");
+ exit(1);
+ }
+ for(;;)
+ {
+ if(getline(&line,&linelen,file)<=0)
+ break;
+ if(line[0]=='#' || line[0]=='\'')
+ continue;
+ if(strncasecmp(line,"FILES ",6)==0)
+ do_files(line);
+ else if(strncasecmp(line,"HOSTS ",6)==0)
+ do_hosts(line);
+ else if(strncasecmp(line,"CONFIG ",7)==0)
+ do_config(line);
+ }
+ fclose(file);
}
void check_blank_configurations(void)