diff options
| author | svn2git <svn2git@FreeBSD.org> | 1994-05-01 08:00:00 +0000 | 
|---|---|---|
| committer | svn2git <svn2git@FreeBSD.org> | 1994-05-01 08:00:00 +0000 | 
| commit | a16f65c7d117419bd266c28a1901ef129a337569 (patch) | |
| tree | 2626602f66dc3551e7a7c7bc9ad763c3bc7ab40a /usr.sbin/inetd/inetd.c | |
| parent | 8503f4f13f77abf7adc8f7e329c6f9c1d52b6a20 (diff) | |
Diffstat (limited to 'usr.sbin/inetd/inetd.c')
| -rw-r--r-- | usr.sbin/inetd/inetd.c | 132 | 
1 files changed, 40 insertions, 92 deletions
| diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c index 2d6c0ee741f8..6dac72a0fc57 100644 --- a/usr.sbin/inetd/inetd.c +++ b/usr.sbin/inetd/inetd.c @@ -39,7 +39,7 @@ char copyright[] =  #ifndef lint  /*static char sccsid[] = "from: @(#)inetd.c	5.30 (Berkeley) 6/3/91";*/ -static char rcsid[] = "$Id: inetd.c,v 1.4 1993/10/18 23:03:20 rgrimes Exp $"; +static char rcsid[] = "$Id: inetd.c,v 1.7 1994/02/05 09:46:42 wollman Exp $";  #endif /* not lint */  /* @@ -110,7 +110,7 @@ static char rcsid[] = "$Id: inetd.c,v 1.4 1993/10/18 23:03:20 rgrimes Exp $";  #include <rpc/rpc.h>  #include "pathnames.h" -#define	TOOMANY		40		/* don't start more than TOOMANY */ +#define	TOOMANY		256		/* don't start more than TOOMANY */  #define	CNT_INTVL	60		/* servers in CNT_INTVL sec. */  #define	RETRYTIME	(60*10)		/* retry after bind or server fail */ @@ -155,6 +155,10 @@ int pmap_set(u_long prognum,u_long versnum,int protocol,u_short port);  /* comes from -lutil ?? */  void daemon(); +char * config_open(const char *filename,int contlines); +void config_close(); +char * config_next(); +char * config_skip(char **p);  /* Prototypes */  void reapchild(); @@ -163,12 +167,8 @@ void unregisterrpc(struct servtab *sep);  void retry();  void setup(struct servtab *sep);  struct servtab * enter(struct servtab *cp); -int setconfig(); -void endconfig();  struct servtab * getconfigent();  void freeconfig(struct servtab *cp); -char * skip(char **cpp); -char * nextline(FILE *fd);  char * newstr(char *cp);  void setproctitle(char *a, int s);  void echo_stream(int s,struct servtab *sep); @@ -249,7 +249,7 @@ main(int argc, char **argv, char **envp)  			break;  		case '?':  		default: -			fprintf(stderr, "usage: inetd [-d]"); +			fprintf(stderr, "usage: inetd [-dl]");  			exit(1);  		}  	argc -= optind; @@ -359,6 +359,11 @@ main(int argc, char **argv, char **envp)  						timingout = 1;  						alarm(RETRYTIME);  					} +					/* +					 * DON'T fork! +					 */ +					sigsetmask(0L); +					continue;  				}  			    }  			    pid = fork(); @@ -456,9 +461,11 @@ config()  {  	struct servtab *sep, *cp, **sepp;  	long omask; +	char *p; -	if (!setconfig()) { -		syslog(LOG_ERR, "%s: %m", CONFIG); +	p = config_open(CONFIG,1); /* 1 means allow continuation lines */ +	if(p) { +		syslog(LOG_ERR, "%s on %s: %m", p, CONFIG);  		return;  	}  	for (sep = servtab; sep; sep = sep->se_next) @@ -538,7 +545,7 @@ config()  		if (sep->se_fd == -1)  			setup(sep);  	} -	endconfig(); +	config_close();  	/*  	 * Purge anything not looked at above.  	 */ @@ -634,7 +641,8 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on))  		return;  	}          if (sep->se_rpc) { -                int i, len; +                int i, len = sizeof(struct sockaddr); +                  if (getsockname(sep->se_fd, (struct sockaddr *)&sep->se_ctrladdr,                                  &len) < 0) {                          syslog(LOG_ERR, "%s/%s: getsockname: %m", @@ -682,30 +690,7 @@ enter(struct servtab *cp)  	return (sep);  } -FILE	*fconfig = NULL;  struct	servtab serv; -char	line[256]; - -int -setconfig() -{ - -	if (fconfig != NULL) { -		fseek(fconfig, 0L, L_SET); -		return (1); -	} -	fconfig = fopen(CONFIG, "r"); -	return (fconfig != NULL); -} - -void -endconfig() -{ -	if (fconfig) { -		(void) fclose(fconfig); -		fconfig = NULL; -	} -}  struct servtab *  getconfigent() @@ -715,16 +700,13 @@ getconfigent()  	char *cp, *arg;          char *versp; -more: -	while ((cp = nextline(fconfig)) && *cp == '#') -		; -	if (cp == NULL) -		return ((struct servtab *)0); -	arg = skip(&cp); -	if (arg == NULL) -		goto more; -	sep->se_service = newstr(arg); -	arg = skip(&cp); +    more: +	cp = config_next(); +	if(!cp)  +		return 0; +	fprintf(stderr,"<%s>\n",cp); +	sep->se_service = newstr(config_skip(&cp)); +	arg = config_skip(&cp);  	if (strcmp(arg, "stream") == 0)  		sep->se_socktype = SOCK_STREAM;  	else if (strcmp(arg, "dgram") == 0) @@ -737,7 +719,7 @@ more:  		sep->se_socktype = SOCK_RAW;  	else  		sep->se_socktype = -1; -	sep->se_proto = newstr(skip(&cp)); +	sep->se_proto = newstr(config_skip(&cp));          sep->se_rpc = 0;          if (strncmp(sep->se_proto, "rpc/", 4) == 0) {                  sep->se_proto += 4; @@ -768,10 +750,18 @@ more:                                  sep->se_rpc_highvers = 1;                  }          } -	arg = skip(&cp); -	sep->se_wait = strcmp(arg, "wait") == 0; -	sep->se_user = newstr(skip(&cp)); -	sep->se_server = newstr(skip(&cp)); +	arg = config_skip(&cp); +	if(!strcmp(arg,"wait")) +		sep->se_wait = 1; +	else if(!strcmp(arg,"nowait")) +		sep->se_wait = 0; +	else { +		syslog(LOG_ERR, "should be wait or nowait: %s unknown\n", arg); +		goto more; +	} +		 +	sep->se_user = newstr(config_skip(&cp)); +	sep->se_server = newstr(config_skip(&cp));  	if (strcmp(sep->se_server, "internal") == 0) {  		struct biltin *bi; @@ -789,7 +779,7 @@ more:  	} else  		sep->se_bi = NULL;  	argc = 0; -	for (arg = skip(&cp); cp; arg = skip(&cp)) +	for (arg = config_skip(&cp); arg; arg = config_skip(&cp))  		if (argc < MAXARGV)  			sep->se_argv[argc++] = newstr(arg);  	while (argc <= MAXARGV) @@ -816,48 +806,6 @@ freeconfig(struct servtab *cp)  }  char * -skip(char **cpp) -{ -	char *cp = *cpp; -	char *start; - -again: -	while (*cp == ' ' || *cp == '\t') -		cp++; -	if (*cp == '\0') { -		int c; - -		c = getc(fconfig); -		(void) ungetc(c, fconfig); -		if (c == ' ' || c == '\t') -			if ((cp = nextline(fconfig))) -				goto again; -		*cpp = (char *)0; -		return ((char *)0); -	} -	start = cp; -	while (*cp && *cp != ' ' && *cp != '\t') -		cp++; -	if (*cp != '\0') -		*cp++ = '\0'; -	*cpp = cp; -	return (start); -} - -char * -nextline(FILE *fd) -{ -	char *cp; - -	if (fgets(line, sizeof (line), fd) == NULL) -		return ((char *)0); -	cp = index(line, '\n'); -	if (cp) -		*cp = '\0'; -	return (line); -} - -char *  newstr(char *cp)  {  	if ((cp = strdup(cp ? cp : ""))) | 
