-/* $OpenBSD: inetd.c,v 1.60 2000/02/01 03:23:58 deraadt Exp $ */
+/* $OpenBSD: inetd.c,v 1.61 2000/03/04 01:10:06 deraadt Exp $ */
/* $NetBSD: inetd.c,v 1.11 1996/02/22 11:14:41 mycroft Exp $ */
/*
* Copyright (c) 1983,1991 The Regents of the University of California.
#ifndef lint
/*static char sccsid[] = "from: @(#)inetd.c 5.30 (Berkeley) 6/3/91";*/
-static char rcsid[] = "$OpenBSD: inetd.c,v 1.60 2000/02/01 03:23:58 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: inetd.c,v 1.61 2000/03/04 01:10:06 deraadt Exp $";
#endif /* not lint */
/*
break;
}
syslog(LOG_ERR,
- "-R %s: bad value for service invocation rate",
+ "-R %s: bad value for service invocation rate",
optarg);
break;
}
cp = cp->se_next;
free(tmp);
} else {
- free (cp);
+ free(cp);
cp = getconfigent();
}
if (debug)
FILE *fconfig = NULL;
char line[1024];
char *defhost;
-char *skip __P((char **));
+char *skip __P((char **, int));
char *nextline __P((FILE *));
char *newstr __P((char *));
struct servtab *dupconfig __P((struct servtab *));
{
register struct servtab *sep;
int argc;
- char *cp, *arg;
+ char *cp, *arg, *s;
char *hostdelim;
struct servtab *nsep;
struct servtab *psep;
exit(-1);
}
+ memset(sep, 0, sizeof *sep);
more:
+ freeconfig(sep);
+
#ifdef MULOG
while ((cp = nextline(fconfig)) && *cp == '#') {
/* Avoid use of `skip' if there is a danger of it looking
} while (*cp == ' ' || *cp == '\t');
if (*cp == '\0')
continue;
- if ((arg = skip(&cp)) == NULL)
+ if ((arg = skip(&cp, 0)) == NULL)
continue;
if (strcmp(arg, "DOMAIN"))
continue;
while ((cp = nextline(fconfig)) && *cp == '#')
;
#endif
- if (cp == NULL)
+ if (cp == NULL) {
+ free(sep);
return (NULL);
+ }
+
memset((char *)sep, 0, sizeof *sep);
- arg = skip(&cp);
+ arg = skip(&cp, 0);
if (arg == NULL) {
/* A blank line. */
goto more;
* default host for the following lines.
*/
if (*arg == '\0') {
- arg = skip(&cp);
+ arg = skip(&cp, 0);
if (cp == NULL) {
free(defhost);
- defhost = sep->se_hostaddr;
+ defhost = newstr(sep->se_hostaddr);
goto more;
}
}
sep->se_hostaddr = newstr(defhost);
sep->se_service = newstr(arg);
- arg = skip(&cp);
+ if ((arg = skip(&cp, 1)) == NULL)
+ goto more;
if (strcmp(arg, "stream") == 0)
sep->se_socktype = SOCK_STREAM;
else
sep->se_socktype = -1;
- sep->se_proto = newstr(skip(&cp));
+ if ((arg = skip(&cp, 1)) == NULL)
+ goto more;
+
+ sep->se_proto = newstr(arg);
+
if (strcmp(sep->se_proto, "unix") == 0) {
sep->se_family = AF_UNIX;
} else {
goto badafterall;
}
}
- arg = skip(&cp);
+ arg = skip(&cp, 1);
if (arg == NULL)
goto more;
- {
- char *s = strchr(arg, '.');
- if (s) {
- *s++ = '\0';
- sep->se_max = atoi(s);
- } else
- sep->se_max = toomany;
- }
+
+ s = strchr(arg, '.');
+ if (s) {
+ *s++ = '\0';
+ sep->se_max = atoi(s);
+ } else
+ sep->se_max = toomany;
+
sep->se_wait = strcmp(arg, "wait") == 0;
- sep->se_user = newstr(skip(&cp));
+ if ((arg = skip(&cp, 1)) == NULL)
+ goto more;
+ sep->se_user = newstr(arg);
arg = strchr(sep->se_user, '.');
if (arg == NULL)
arg = strchr(sep->se_user, ':');
*arg++ = '\0';
sep->se_group = newstr(arg);
}
- sep->se_server = newstr(skip(&cp));
+ if ((arg = skip(&cp, 1)) == NULL)
+ goto more;
+
+ sep->se_server = newstr(arg);
if (strcmp(sep->se_server, "internal") == 0) {
- register struct biltin *bi;
+ struct biltin *bi;
for (bi = biltins; bi->bi_service; bi++)
if (bi->bi_socktype == sep->se_socktype &&
} else
sep->se_bi = NULL;
argc = 0;
- for (arg = skip(&cp); cp; arg = skip(&cp)) {
+ for (arg = skip(&cp, 0); cp; arg = skip(&cp, 0)) {
#if MULOG
char *colon;
}
char *
-skip(cpp)
+skip(cpp, report)
char **cpp;
+ int report;
{
- register char *cp = *cpp;
+ char *cp = *cpp;
char *start;
- if (*cpp == NULL)
- return (NULL);
-
+erp:
+ if (*cpp == NULL) {
+ if (report)
+ syslog(LOG_ERR, "syntax error in inetd config file");
+ return (NULL);
+ }
+
again:
while (*cp == ' ' || *cp == '\t')
cp++;
if ((cp = nextline(fconfig)))
goto again;
*cpp = NULL;
- return (NULL);
+ goto erp;
}
start = cp;
while (*cp && *cp != ' ' && *cp != '\t')
cp++;
if (*cp != '\0')
*cp++ = '\0';
- *cpp = cp;
+ if ((*cpp = cp) == NULL)
+ goto erp;
+
return (start);
}