/**************************************************
OpengateM - MAC address authentication system
- module for getting parameters from conf file
+ module for getting parameters from conf file in XML form
+ ezxml library(by Aaron Voisine) is used for handling XML
Copyright (C) 2006 Opengate Project Team
Written by Yoshiaki Watanabe
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
#include "opengatemmng.h"
#include "../ezxml/ezxml.h"
-#define CONFIG_VERSION "0.7.5"
-#define SEPARATOR "/"
+#define CONFIG_VERSION "0.7.5" /* compared to the value in conf file */
+#define SEPARATOR "/" /* separator used in XML tree description */
int debug=0;
static ezxml_t xmlRoot=NULL;
/* Prepare Conf file to use */
/* this is called before syslog setup */
/**************************************************/
-int openConfFile(void)
-{
+int openConfFile(void){
char buff[BUFFMAXLN];
char *s;
char *errMsg;
/* if failed, show error message */
errMsg=(char *)ezxml_error(xmlRoot);
-
if(*errMsg!='\0'){
+
/* as the syslog is not prepared, error is send to web*/
strlcpy(buff, "<H3>Error: Opengate configuration file ",BUFFMAXLN);
strlcat(buff, CONFIGFILE,BUFFMAXLN);
return -1;
}
- /* check the config file version */
+ /* check compatibility between conf file and this program (compare version number) */
if(isNull(ezxml_attr(xmlRoot, "ConfigVersion"))||
(strcmp(CONFIG_VERSION, ezxml_attr(xmlRoot, "ConfigVersion"))!=0)){
strlcpy(buff, "<H3>Error: Opengate configuration file ",BUFFMAXLN);
return -1;
}
- /* check the syslog */
+ /* check the syslog setting */
if(atoi(GetConfValue("Syslog/Enable")) &&
atoi(GetConfValue("Syslog/Facility"))==0){
/**************************************************/
/* initialize the Config */
/**************************************************/
-void initConf(void)
-{
- /* as debug flag is used many times, put it in gloval variable */
+void initConf(void){
+
+ /* as debug flag is used many times, put it in static variable */
debug=atoi(getConfValue("Debug"));
}
/**************************************************/
-/* Finish Conf file usage */
+/* Finish Config file usage */
/**************************************************/
-void closeConfFile(void)
-{
+void closeConfFile(void){
if(xmlRoot!=NULL)ezxml_free(xmlRoot);
}
/**************************************************/
/* Setup pointer to the matched ExtraSet */
/**************************************************/
-void setupConfExtra(char * userId,char *extraId)
-{
+void setupConfExtra(char *userId, char *extraId){
char* progName;
char useridfull[USERMAXLN]; /* userid@extraid */
/* setup long userid (userid@extraid) */
ConcatUserId(useridfull, userId, extraId);
- /* init as no ExtraSet */
+ /* init as non-ExtraSet */
xmlExtraSet=NULL;
/* search the matching extra set (first match is employed) */
InitConf();
}
-/***********************************************/
-/* regular expression matching */
-/* inStr : string to match */
-/* regEx : regular expression */
-/* caseSensitive : 0=ignore case, 1=sensitive */
-/***********************************************/
-int regExMatch(const char *inStr, const char *regEx, int caseSensitive)
-{
+/****************************************************/
+/* regular expression matching */
+/* inStr : (in) string to match */
+/* regEx : (in) regular expression */
+/* caseSensitive : (in) 0=ignore case, 1=sensitive */
+/* return value : TRUE=match, FALSE=unmatch */
+/****************************************************/
+int regExMatch(const char *inStr, const char *regEx, int caseSensitive){
regex_t reg;
int errcode;
int match;
else match=FALSE;
}
+ /* free memory for the compiled regex */
regfree(®);
return match;
/**************************************************/
/* get a value for name from Conf file */
-/* the name[aa/bb/cc] means the path */
-/* if ID is set, extraSet value is overlayed */
+/* the name[aa/bb/cc] means the path in xml */
+/* extraSet value is overlayed, if exists */
/**************************************************/
-char *getConfValue(char *name)
-{
+char *getConfValue(char *name){
char *pValue;
char *pValueExtra;
char *pStr;
err_msg("ERR at %s#%d: cannot get %s from conf file",__FILE__,__LINE__,name);
}
- /* get value in extra set matched to ID */
+ /* get value in extra set matched to name */
/* if name is matched in first level, reset all child setting */
- /* in this section, many parameters are not set */
+ /*****************************************************************
+ in the following, <CmdPath> and <Timing> for 'user1' is NOT defined
+ <Mail>
+ <CmdPath>/bin/rmail</CmdPath>
+ <Content>/etc/opengate/warningmail</Content>
+ <Timing>date(now())=date(........)</Timing>
+ </Mail>
+ <ExtraSet ExtraId="default" UserIdPattern="^user1$|^user2$">
+ <Mail>
+ <Content>/etc/opengate/warningmail-special</Content>
+ </Mail>
+ </ExtraSet>
+ *****************************************************************/
if(!isNull(pValueExtra=getConfValueExtra(name))){
pValue=pValueExtra;
}
}
/************************************************/
-/* get the value in extra set matched to ID */
+/* get the value in extra set matched to name */
/************************************************/
-char *getConfValueExtra(char *name)
-{
+char *getConfValueExtra(char *name){
char *pStr;
char buff[BUFFMAXLN];
ezxml_t xml;
/* get a first level matched node in extra set */
/* the first level is not included in the following loop */
/* as to prevent partial overlay of sub level value */
+ /* (see 40-lines above) */
xml=ezxml_child(xmlExtraSet, pStr);
if(xml==NULL) return "";
/***************************************************/
/* get a value for AuthServer param from Conf file*/
-/* the name[AuthServer/bb/cc] means the path */
+/* the name[AuthServer/bb/cc] means the xml path */
/***************************************************/
char *getConfAuthServer(char *name)
{
return pValue;
}
-/**********************************/
-/* select next authserver setting */
-/**********************************/
+/*****************************************************************/
+/* select next authserver setting */
+/* at first call, this selects the first server setting */
+/* and form second call, this selects the next server setting */
+/* ResetAuthServerPointer() returns the pointer to first setting */
+/*****************************************************************/
int selectNextAuthServer(void){
ezxml_t xmlTmp; /* temporary variable */
}
}
-/**********************************************
-reset pointer for auth server list
-**********************************************/
+/*********************************************/
+/* reset pointer for auth server list */
+/*********************************************/
void resetAuthServerPointer(void){
xmlAuthServer=NULL;
}
-/***********************************************/
-/* Convart the syslog facility id to raw value */
-/***********************************************/
-char *convertToFacilityRaw(char *pValue)
-{
+/************************************************************/
+/* Convart the syslog facility id(string) to raw value(int) */
+/************************************************************/
+char *convertToFacilityRaw(char *pValue){
static char facility[WORDMAXLN];
int rawValue;
}
/**************************************************/
-/* get the first value as previous call */
-/* (next node of the lowest level of tree) */
+/* get the first value matched to name */
+/* (first node of matched lowest level of tree) */
/**************************************************/
-char *getFirstConfValue(char* name)
-{
+char *getFirstConfValue(char* name){
char *pValue;
pValue=GetConfValue(name);
}
/**************************************************/
-/* get the next value as previous call */
+/* get the value in sibling of previous get */
/* (next node of the lowest level of tree) */
/**************************************************/
-char *getNextConfValue(void)
-{
+char *getNextConfValue(void){
char *pValue;
/* recover previous pointer */