This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Data Structures | |
| struct | _cfgitem |
Typedefs | |
| typedef _cfgitem | cfgitem_t |
Enumerations | |
| enum | { false = 0, true } |
| enum | ci_type { ci_pathname, ci_integer, ci_boolean, ci_logpri, ci_logfac, ci_text, ci_flist } |
Functions | |
| int | readConfig (char *file, char *ebuf, size_t ebsiz) |
| char * | confVarPath (char *name, int *eptr) |
| char * | confVarText (char *name, int *eptr) |
| int | confVarSyslog (char *name, int *eptr) |
| int | confVarBool (char *name, int *eptr) |
| int | confVarInt (char *name, int *eptr) |
| char ** | confVarFlist (char *name, int *eptr) |
| char * | fixupPathName (char *val, char *path) |
| int | getBooleanValue (char *s, int *v) |
Variables | |
| cfgitem_t | config [] |
|
|
configuration item structure |
|
|
Definition at line 9 of file configfile.h.
|
|
|
define ci_type values for use in the config[] array Definition at line 14 of file configfile.h. 00014 {ci_pathname, ci_integer,ci_boolean, ci_logpri, ci_logfac, ci_text,ci_flist} ci_type;
|
|
||||||||||||
|
confVarBool returns a boolean (0 or 1) value for a config variable. If an error occurs *eptr is set to errno and -1 is returned. Definition at line 43 of file configfile.c. References ci_boolean, config, and _cfgitem::name. 00043 { 00044 int i; 00045 *eptr = 0; 00046 for(i = 0; config[i].name != NULL; i++) { 00047 if(strcmp(config[i].name,name) == 0) { 00048 if(config[i].type != ci_boolean) { 00049 *eptr = EINVAL; 00050 return -1; 00051 } 00052 return config[i].val.i; 00053 } 00054 } 00055 *eptr = ENOENT; 00056 return -1; 00057 }
|
|
||||||||||||
|
confVarFlist returns an aray of firewall rules held in a config variable or NULL if it cannot be found or name is of the wrong type Definition at line 119 of file configfile.c. References ci_flist, config, and _cfgitem::name. Referenced by dropIp(), and undropIp(). 00119 { 00120 int i; 00121 *eptr = 0; 00122 for(i = 0; config[i].name != NULL; i++) { 00123 if(strcmp(config[i].name,name) == 0) { 00124 if(config[i].type != ci_flist) { 00125 *eptr = EINVAL; 00126 return NULL; 00127 } 00128 return config[i].val.a; 00129 } 00130 } 00131 *eptr = ENOENT; 00132 return NULL; 00133 }
|
|
||||||||||||
|
confVarInf returns an integer configuration variable. If an error occurs *eptr is set to errno and -1 is returned. Definition at line 23 of file configfile.c. References ci_integer, config, and _cfgitem::name. Referenced by ipManage(), and usage(). 00023 { 00024 int i; 00025 *eptr = 0; 00026 for(i = 0; config[i].name != NULL; i++) { 00027 if(strcmp(config[i].name,name) == 0) { 00028 if(config[i].type != ci_integer) { 00029 *eptr = EINVAL; 00030 return -1; 00031 } 00032 return config[i].val.i; 00033 } 00034 } 00035 *eptr = ENOENT; 00036 return -1; 00037 }
|
|
||||||||||||
|
confVarPath returns a pathname config variable. If an error occurs *eptr is set to errno and -1 is returned. Definition at line 100 of file configfile.c. References ci_pathname, config, and _cfgitem::name. Referenced by inform(), loadIpList(), main(), usage(), and writeIpList(). 00100 { 00101 int i; 00102 *eptr = 0; 00103 for(i = 0; config[i].name != NULL; i++) { 00104 if(strcmp(config[i].name,name) == 0) { 00105 if(config[i].type != ci_pathname) { 00106 *eptr = EINVAL; 00107 return NULL; 00108 } 00109 return config[i].val.s; 00110 } 00111 } 00112 *eptr = ENOENT; 00113 return NULL; 00114 }
|
|
||||||||||||
|
confVarSyslog returns an integer representing a syslog facility of a config variable. If an error occurs *eptr is set to errno and -1 is returned. Definition at line 63 of file configfile.c. References ci_logfac, ci_logpri, config, _cfgitem::i, and _cfgitem::name. Referenced by writeLog(). 00063 { 00064 int i; 00065 *eptr = 0; 00066 for(i = 0; config[i].name != NULL; i++) { 00067 if(strcmp(config[i].name,name) == 0) { 00068 if(config[i].type == ci_logpri || config[i].type == ci_logfac) 00069 return config[i].val.i; 00070 *eptr = EINVAL; 00071 return -1; 00072 } 00073 } 00074 *eptr = ENOENT; 00075 return -1; 00076 }
|
|
||||||||||||
|
confVarText returns a string for a text config variable. If an error occurs *eptr is set to errno and -1 is returned. Definition at line 81 of file configfile.c. References ci_text, config, and _cfgitem::name. Referenced by dropIp(), inform(), main(), undropIp(), and usage(). 00081 { 00082 int i; 00083 *eptr = 0; 00084 for(i = 0; config[i].name != NULL; i++) { 00085 if(strcmp(config[i].name,name) == 0) { 00086 if(config[i].type != ci_text) { 00087 *eptr = EINVAL; 00088 return NULL; 00089 } 00090 return config[i].val.s; 00091 } 00092 } 00093 *eptr = ENOENT; 00094 return NULL; 00095 }
|
|
||||||||||||
|
fixupPathName modifies the path in *val with the path in *path (usually workdir) so it is a FQPN. If memory cannot be allocated errno is set and NULL is returned. Definition at line 139 of file configfile.c. 00139 { 00140 size_t sz; 00141 char *tb, *tb1 = "", *tb2 = "/", tmp[2049]; 00142 00143 if(*val == '/') 00144 return val; 00145 00146 if(path[strlen(path)-1] != '/') 00147 tb = tb2; 00148 else 00149 tb = tb1; 00150 00151 sprintf(tmp,"%s%s%s",path,tb,val); 00152 sz = strlen(tmp)+5; 00153 if((val = realloc(val,sz)) == NULL) 00154 return NULL; 00155 strcpy(val,tmp); 00156 return val; 00157 }
|
|
||||||||||||
|
_getBooleanValue() evaluates s for true or false statemnts and sets *v accordingly. return value is 0 on successful match and -1 on no match. Definition at line 162 of file configfile.c. Referenced by main(), and readConfig(). 00162 { 00163 LOCAL char * bools[2][3] = {{"false","off","no"},{"true","on","yes"}}; 00164 int i, j; 00165 *v = -1; 00166 for(i = 0; i < 2; i++) { 00167 for(j = 0; j < 3; j++) { 00168 if(strcasecmp(s,bools[i][j]) == 0) { 00169 *v = i; 00170 return 0; 00171 } 00172 } 00173 } 00174 return -1; 00175 }
|
|
||||||||||||||||
|
readConfig reads the config file specified. If any errors occur readConfig will return non-zero and the error message will be stored in ebuf Definition at line 194 of file configfile.c. References _configTabEntry(), _cfgitem::a, ci_boolean, ci_flist, ci_integer, ci_logfac, ci_logpri, ci_pathname, ci_text, getBooleanValue(), _cfgitem::i, loadModule(), _cfgitem::s, split(), sysLogFac(), sysLogPri(), trim(), _cfgitem::type, and _cfgitem::val. Referenced by main(). 00194 { 00195 char buf[1024], _name[1024], _val[1024], *name, *val; 00196 char cbuf[1024]; 00197 char *p, *ep, *p1; 00198 int i, line = 0; 00199 cfgitem_t *c; 00200 FILE *f; 00201 00202 if((f = fopen(file,"r")) == NULL) { 00203 snprintf(ebuf,ebsiz,"%s(%d) Cannot open config file \"%s\": %m",file,line,file); 00204 return -1; 00205 } 00206 while((p = fgets(buf,sizeof(buf)-1,f)) != NULL) { 00207 line++; 00208 if(*p == '#') continue; 00209 if((p = strchr(buf,'#')) != NULL) 00210 *p = '\0'; 00211 if((p = strchr(buf,'=')) == NULL) 00212 continue; 00213 *p++ = '\0'; 00214 strcpy(_name,buf); 00215 strcpy(_val,p); 00216 name = trim(_name); 00217 val = trim(_val); 00218 if(strcmp(name,"loadmodule") == 0) { 00219 if(loadModule(val,cbuf,sizeof(cbuf))) { 00220 snprintf(ebuf,ebsiz,"%s(%d): Error loading module: %s",file,line,cbuf); 00221 return -1; 00222 } 00223 printf("module %s loaded\n",val); 00224 continue; 00225 } 00226 if((c = _configTabEntry(name)) == NULL) { 00227 snprintf(ebuf,ebsiz,"%s(%d): invalid configuration item %s",file,line,name); 00228 fclose(f); 00229 return -1; 00230 } 00231 switch(c->type) { 00232 case ci_pathname: 00233 if((c->val.s = strdup(val)) == NULL) { 00234 snprintf(ebuf,ebsiz,"%s(%d): Could not alloc space for %s: %m",file,line,name); 00235 fclose(f); 00236 return -1; 00237 } 00238 break; 00239 case ci_integer: 00240 c->val.i = atoi(val); 00241 break; 00242 case ci_boolean: 00243 if(getBooleanValue(val,&c->val.i)) { 00244 snprintf(ebuf,ebsiz,"%s(%d): Cannot evaluate boolen from %s",file,line,val); 00245 return -1; 00246 } 00247 break; 00248 case ci_text: 00249 if((c->val.s = strdup(val)) == NULL) { 00250 snprintf(ebuf,ebsiz,"%s(%d): Could not alloc space for %s: %m",file,line,name); 00251 fclose(f); 00252 return -1; 00253 } 00254 break; 00255 case ci_logpri: 00256 if((c->val.i = sysLogPri(val)) == -1) { 00257 snprintf(ebuf,ebsiz,"%s(%d): Cannot parse log priority from \"%s\"\n",file,line,val); 00258 return -1; 00259 } 00260 break; 00261 case ci_logfac: 00262 if((c->val.i = sysLogFac(val)) == -1) { 00263 snprintf(ebuf,ebsiz,"%s(%d): Cannot parse log facility from \"%s\"\n",file,line,val); 00264 return -1; 00265 } 00266 break; 00267 case ci_flist: 00268 if((c->val.a = split(",",trim(val))) == NULL) { 00269 snprintf(ebuf,ebsiz,"%s(%d): Cannot split flist \"%s\": %m",file,line,name); 00270 return -1; 00271 } 00272 break; 00273 } 00274 } 00275 fclose(f); 00276 return 0; 00277 }
Here is the call graph for this function: ![]() |
|
|
don't define extern config for modules Definition at line 4 of file dummymod.c. Referenced by _configTabEntry(), confVarBool(), confVarFlist(), confVarInt(), confVarPath(), confVarSyslog(), confVarText(), dumpConfig(), main(), secwmodinit(), and usage(). |
1.4.6