allows the character `"' in the program argument like the shell.

some bugfixes.
This commit is contained in:
Stefan Luethje 1997-04-15 22:37:20 +00:00
parent 51fd9cc41b
commit e052bd91b3
6 changed files with 264 additions and 18 deletions

View File

@ -19,6 +19,9 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
## $Log$
## Revision 1.12 1997/04/15 00:19:53 luethje
## replace variables: some bugfixes, README comleted
##
## Revision 1.11 1997/04/10 23:32:04 luethje
## Added the feature, that environment variables are allowed in the config files.
##
@ -166,7 +169,7 @@ SERVICEFILE = /etc/services
# DON'T EDIT BELOW THIS LINE
######################################################################
VERSION = 2.99.8
VERSION = 2.99.9
ifeq ($(POSTGRES),1)
DEFS += -DPOSTGRES

View File

@ -807,6 +807,30 @@ eine Variable verwendet werden soll, so muss diese mit "\$" geqoutet werden:
ALIAS = \$PATH # -> "$PATH"
...
Wenn eine Variable mehrfach gesetzt wird, so wird sie ueberschrieben. Die
Regel fuer das ueberschreiben entspricht der Reihenfolge, in der die
Konfigurationsdateien gelesen werden:
1. isdn.conf
2. callerid.conf
3. ~/.isdn
Wenn eine Variable "FRED" in "isdn.conf" und "~/.isdn" gesetzt werden, so wird
der Wert von "isdn.conf" durch den Wert der zweiten Datei ueberschrieben.
Die Variablen werden zuerst aus allen drei Dateien gelesen, bevor die
Ersetzung stattfindet. Das bedeutet also, das z. B. eine Variable, die
in "~/.isdn" gesetzt wurde, in der isdn.conf verwendet werden kann.
Dieses mag im ersten Augenblick als ein Sicherheitsloch erscheinen, aber
wenn als root ein Programm gestartet wurde, muessen alle drei Dateien
auf readonly fuer group und world gesetzt sein. Andersherum kann ein Benutzer,
der ein Programm startet auf diese Dateien nur lesend zugreifen.
ACHTUNG:
Es ist allerdings davon abzuraten, weder den isdnlog, noch den isdnrep oder den
isdnconf mit dem sticky-Bit auszustatten!!!!
Es gibt bestimmte Regeln, nachdem Eintraege aus der Datei "~/.isdn" die
Eintraege der "callerid.conf" ueberschreiben:

View File

@ -20,17 +20,20 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
## $Log$
## Revision 1.2 1997/04/08 21:20:02 luethje
## primitive changes
##
## Revision 1.1 1997/04/08 21:18:50 luethje
## File to generate the config file `isdn.conf'
##
CONFFILE=$1
RESFILE=/tmp/`basename $0`.res.$$
setentry() {
SECTION=$1
ENTRY=$2
VALUE=$3
RESFILE=/tmp/`basename $0`.res.$$
AWKFILE=/tmp/`basename $0`.$$
grep $ENTRY $CONFFILE >/dev/null 2>&1
@ -82,4 +85,8 @@ setentry "[ISDNLOG]" "OLABEL" "$OLABEL"
setentry "[ISDNLOG]" "ILABEL" "$ILABEL"
setentry "[ISDNLOG]" "LOGFILE" "$LOGFILE"
sed -e "s/\([^\]\)\$\([0-9][ ]\)/\1\\\\$\2/g" $CONFFILE >$RESFILE
cp $RESFILE $CONFFILE
rm -f $RESFILE
echo " Ready."

View File

@ -20,6 +20,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.3 1997/04/10 23:32:19 luethje
* Added the feature, that environment variables are allowed in the config files.
*
* Revision 1.2 1997/04/03 22:58:34 luethje
* some primitve changes.
*
@ -42,6 +45,18 @@
/*************************************************************************/
#define C_SET_TAB 1
#define C_SET_SPACE 2
#define SET_BEGIN_VAR 1
/*************************************************************************/
#define C_TAB '\t'
#define C_SPACE ' '
/*************************************************************************/
static interval *RootIntervall = NULL;
/** Prototypes ***********************************************************/
@ -51,6 +66,8 @@ static int GetArgs(char *, char *[], char *[], int);
static interval *Next_Interval(void);
static int set_user(char *User);
static int set_group(char *Group);
static char *StrToArg(char* string);
static char *Replace_Opts(char *String, char *Opts[], int MaxOpts);
/****************************************************************************/
@ -146,10 +163,7 @@ int Ring(info_args *Cmd, char *Opts[], int Die, int Async)
case -1: print_msg(PRT_ERR, "%s\n", "Can't start fork()!");
return 0;
break;
case 0: if (paranoia_check(Args[0]) < 0)
exit(-1);
if (set_group(Cmd->group) < 0)
case 0: if (set_group(Cmd->group) < 0)
{
print_msg(PRT_ERR, "Can not set group %s: %s\n",Cmd->group,strerror(errno));
exit(-1);
@ -161,6 +175,9 @@ int Ring(info_args *Cmd, char *Opts[], int Die, int Async)
exit(-1);
}
if (paranoia_check(Args[0]) < 0)
exit(-1);
dup2(filedes[1],STDOUT_FILENO);
dup2(filedes[1],STDERR_FILENO);
@ -221,7 +238,6 @@ static int GetArgs(char *Line, char *Args[], char *Opts[], int MaxArgs)
int MaxOpts= 0;
int i = 0;
int j = 0;
int Num = 0;
char HelpString[SHORT_STRING_SIZE];
static char **MemPtr = NULL;
@ -238,10 +254,19 @@ static int GetArgs(char *Line, char *Args[], char *Opts[], int MaxArgs)
while (Opts[MaxOpts] != NULL)
MaxOpts++;
while ((Org_Arg = Arg = strtok(Use, " \t")))
while ((Org_Arg = Arg = StrToArg(Use)))
{
Use = NULL;
if ((Ptr = Replace_Opts(Arg,Opts,MaxOpts)) != NULL)
{
Arg = strdup(Ptr);
MemPtr = (char**) realloc(MemPtr,sizeof(char*)*(j+2));
MemPtr[j++] = Arg;
MemPtr[j] = NULL;
}
if (*Arg == '@')
{
FILE *fp = fopen(Arg+1,"r");
@ -263,9 +288,6 @@ static int GetArgs(char *Line, char *Args[], char *Opts[], int MaxArgs)
else
Arg = NULL;
}
else
if (*Arg == '$' && Opts != NULL && (Num = atoi(Arg+1)) > 0 && Num <= MaxOpts)
Arg = Opts[Num-1];
if (Arg == NULL || *Arg == '\0')
{
@ -275,9 +297,11 @@ static int GetArgs(char *Line, char *Args[], char *Opts[], int MaxArgs)
Arg = "?";
}
/*
Ptr = Arg;
while((Ptr = Check_Quote(Ptr, S_QUOTES, QUOTE_DELETE)) != NULL && Ptr[0] != '\0')
Ptr++;
*/
if (i < MaxArgs) Args[i++] = Arg;
}
@ -287,6 +311,180 @@ static int GetArgs(char *Line, char *Args[], char *Opts[], int MaxArgs)
return(i);
}
/*************************************************************************/
static char *StrToArg(char* string)
{
static char *Ptr = NULL;
int in = 0;
int begin = 1;
char *Start;
if (string != NULL)
{
Ptr = string;
begin = 1;
}
Start = Ptr;
if (Ptr == NULL)
return NULL;
while(*Ptr != '\0')
{
if (*Ptr == '\"')
{
if (begin != 1 && Ptr[-1] == C_QUOTE_CHAR)
{
memmove(Ptr-1,Ptr,strlen(Ptr)+1);
Ptr--;
}
else
{
in = !in;
memmove(Ptr,Ptr+1,strlen(Ptr));
Ptr--;
}
}
else
if (!in && isspace(*Ptr))
{
*Ptr++ = '\0';
break;
}
begin = 0;
Ptr++;
}
if (in)
print_msg(PRT_WARN,"Warning: Missing second char `\"'! in string `%s'!\n",Start);
if (*Start == '\0')
Start = NULL;
return Start;
}
/****************************************************************************/
static char *Replace_Opts(char *String, char *Opts[], int MaxOpts)
{
static char *RetCode = NULL;
char *Begin = NULL;
char *Var = NULL;
char *End = NULL;
char *Value = NULL;
char *Ptr = String;
int cnt = 0;
int num = 0;
int Num = 0;
if (Opts == NULL)
return String;
while ((Ptr = strchr(Ptr,C_BEGIN_VAR)) != NULL)
{
cnt++;
Ptr++;
}
if (!cnt)
return String;
if (RetCode != NULL)
free(RetCode);
if ((RetCode = strdup(String)) == NULL ||
(Var = strdup(RetCode)) == NULL ||
(End = strdup(RetCode)) == NULL )
{
print_msg(PRT_ERR,"%s!\n","Error: Can not allocate memory!\n");
return NULL;
}
while ((Ptr = strchr(RetCode,C_BEGIN_VAR)) != NULL)
{
if (Ptr != RetCode && Ptr[-1] == C_QUOTE_CHAR)
{
*Ptr = SET_BEGIN_VAR;
memmove(Ptr-1,Ptr,strlen(RetCode)-(Ptr-RetCode-1));
cnt--;
}
else
if ((num = sscanf(Ptr+1,"%[0-9]%[^\n]",Var,End)) >= 1 ||
(num = sscanf(Ptr+1,"{%[0-9]}%[^\n]",Var,End)) >= 1 )
{
if ((Num = atoi(Var)) > 0 && Num <= MaxOpts)
{
free(Begin);
if ((Begin = strdup(RetCode)) == NULL)
{
print_msg(PRT_ERR,"%s!\n","Error: Can not allocate memory!\n");
return NULL;
}
Begin[Ptr-RetCode] = '\0';
if ((RetCode = (char*) realloc(RetCode,sizeof(char)*strlen(RetCode)+strlen(Value)-strlen(Var))) == NULL)
{
print_msg(PRT_ERR,"%s!\n","Error: Can not allocate memory!\n");
return NULL;
}
if (num == 1)
*End = '\0';
sprintf(RetCode,"%s%s%s",Begin,Opts[Num-1],End);
free(Var);
free(End);
if ((Var = strdup(RetCode)) == NULL ||
(End = strdup(RetCode)) == NULL )
{
print_msg(PRT_ERR,"%s!\n","Error: Can not allocate memory!\n");
return NULL;
}
cnt--;
}
else
{
*Ptr = SET_BEGIN_VAR;
cnt--;
print_msg(PRT_WARN,"Warning: Unknown variable `%s'!\n",Var);
}
}
else
*Ptr = SET_BEGIN_VAR;
}
if (cnt)
print_msg(PRT_WARN,"Warning: Invalid token in string `%s'!\n",String);
free(Begin);
free(Var);
free(End);
if ((Ptr = RetCode) != NULL)
{
while (*Ptr != '\0')
{
if (*Ptr == SET_BEGIN_VAR)
*Ptr = C_BEGIN_VAR;
Ptr++;
}
}
return RetCode;
}
/*************************************************************************
** KillCommand(-) - Beendet ein Programm anhand seiner PID. **
*************************************************************************/

View File

@ -20,6 +20,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.9 1997/04/03 22:40:21 luethje
* some bugfixes.
*
* Revision 1.8 1997/03/31 22:43:18 luethje
* Improved performance of the isdnrep, made some changes of README
*
@ -528,6 +531,7 @@ typedef struct {
double duration;
double dm;
char num[2][NUMSIZE];
char who[2][NUMSIZE];
long ibytes;
long obytes;
char version[10];

View File

@ -19,6 +19,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.14 1997/04/15 00:20:13 luethje
* replace variables: some bugfixes, README comleted
*
* Revision 1.13 1997/04/10 23:41:26 luethje
* some bug fixes
*
@ -1544,17 +1547,24 @@ int Replace_Variables(section *Section)
while(Entry != NULL)
{
if (Entry->value != NULL && (Ptr = Replace_Variable(Entry->value)) != NULL)
if (Entry->value != NULL)
{
if ((Ptr = strdup(Ptr)) == NULL)
if ((Ptr = Replace_Variable(Entry->value)) != NULL)
{
print_msg("%s","Can not allocate memory!\n");
return -1;
}
if ((Ptr = strdup(Ptr)) == NULL)
{
print_msg("%s","Can not allocate memory!\n");
return -1;
}
free(Entry->value);
Entry->value = Ptr;
free(Entry->value);
Entry->value = Ptr;
}
}
else
if (Entry->subsection != NULL)
if (Replace_Variables(Entry->subsection) != 0)
return -1;
Entry = Entry->next;
}