17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
22462be471Sceastha /*
23462be471Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24462be471Sceastha * Use is subject to license terms.
25462be471Sceastha */
26462be471Sceastha
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include "uucp.h"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate /* add sitedep() and sysmatch() to list when ifdefs are removed below */
337c478bd9Sstevel@tonic-gate static int get_tokens(), siteindep();
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /* field array indexes for LIMIT parameters */
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #define U_SERVICE 0
387c478bd9Sstevel@tonic-gate #define U_MAX 1
397c478bd9Sstevel@tonic-gate #define U_SYSTEM 2
407c478bd9Sstevel@tonic-gate #define U_MODE 3
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate static char * _Lwords[] = {"service", "max", "system", "mode"};
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #define NUMFLDS 4
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate struct name_value
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate char *name;
497c478bd9Sstevel@tonic-gate char *value;
507c478bd9Sstevel@tonic-gate };
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate * manage limits file.
547c478bd9Sstevel@tonic-gate */
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate * scan the Limits file and get the limit for the given service.
587c478bd9Sstevel@tonic-gate * return SUCCESS if the limit was found, else return FAIL.
597c478bd9Sstevel@tonic-gate */
607c478bd9Sstevel@tonic-gate int
scanlimit(service,limitval)617c478bd9Sstevel@tonic-gate scanlimit(service, limitval)
627c478bd9Sstevel@tonic-gate char *service;
637c478bd9Sstevel@tonic-gate struct limits *limitval;
647c478bd9Sstevel@tonic-gate {
657c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
667c478bd9Sstevel@tonic-gate char *tokens[NUMFLDS]; /* fields found in LIMITS */
677c478bd9Sstevel@tonic-gate char msgbuf[BUFSIZ]; /* place to build messages */
687c478bd9Sstevel@tonic-gate FILE *Fp = NULL; /* file pointer for LIMITS */
697c478bd9Sstevel@tonic-gate int SIflag, SDflag;
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate if ((Fp = fopen(LIMITS, "r")) == NULL) {
727c478bd9Sstevel@tonic-gate DEBUG(5, "cannot open %s\n", LIMITS);
737c478bd9Sstevel@tonic-gate sprintf(msgbuf, "fopen of %s failed with errno=%%d\n", LIMITS);
747c478bd9Sstevel@tonic-gate DEBUG(5, msgbuf, errno);
757c478bd9Sstevel@tonic-gate return(FAIL);
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate SIflag = FALSE;
797c478bd9Sstevel@tonic-gate SDflag = TRUE;
807c478bd9Sstevel@tonic-gate
81*2a8bcb4eSToomas Soome /* The following #if (0 == 1) and #endif lines should be deleted when
82*2a8bcb4eSToomas Soome * we expand the functionality of the Limits file to include the
837c478bd9Sstevel@tonic-gate * limit per site, and the mode for uucico.
847c478bd9Sstevel@tonic-gate */
857c478bd9Sstevel@tonic-gate #if (0 == 1)
867c478bd9Sstevel@tonic-gate if (strcmp(service, "uucico") == SAME)
877c478bd9Sstevel@tonic-gate SDflag = FALSE;
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate while ((getuline(Fp, buf) > 0) && ((SIflag && SDflag) == FALSE)) {
917c478bd9Sstevel@tonic-gate if (get_tokens(buf, tokens) == FAIL)
927c478bd9Sstevel@tonic-gate continue;
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate if (SIflag == FALSE) {
957c478bd9Sstevel@tonic-gate if (siteindep(tokens, service, limitval) == SUCCESS)
967c478bd9Sstevel@tonic-gate SIflag = TRUE;
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate
99*2a8bcb4eSToomas Soome /* The following #if (0 == 1) and #endif lines should be deleted when
100*2a8bcb4eSToomas Soome * we expand the functionality of the Limits file to include the
1017c478bd9Sstevel@tonic-gate * limit per site, and the mode for uucico.
1027c478bd9Sstevel@tonic-gate */
1037c478bd9Sstevel@tonic-gate #if (0 == 1)
1047c478bd9Sstevel@tonic-gate if (SDflag == FALSE) {
1057c478bd9Sstevel@tonic-gate if (sitedep(tokens, limitval) == SUCCESS)
1067c478bd9Sstevel@tonic-gate SDflag = TRUE;
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate #endif
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate fclose(Fp);
1127c478bd9Sstevel@tonic-gate if ((SIflag && SDflag) == TRUE)
1137c478bd9Sstevel@tonic-gate return(SUCCESS);
1147c478bd9Sstevel@tonic-gate else return(FAIL);
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate * parse a line in LIMITS and return a vector
1197c478bd9Sstevel@tonic-gate * of fields (flds)
1207c478bd9Sstevel@tonic-gate *
1217c478bd9Sstevel@tonic-gate * return:
1227c478bd9Sstevel@tonic-gate * SUCCESS - token pairs name match with the key words
1237c478bd9Sstevel@tonic-gate */
1247c478bd9Sstevel@tonic-gate static int
get_tokens(line,flds)1257c478bd9Sstevel@tonic-gate get_tokens (line,flds)
1267c478bd9Sstevel@tonic-gate char *line;
1277c478bd9Sstevel@tonic-gate char *flds[];
1287c478bd9Sstevel@tonic-gate {
129462be471Sceastha int i;
130462be471Sceastha char *p;
1317c478bd9Sstevel@tonic-gate struct name_value pair;
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate /* initialize defaults in case parameter is not specified */
1347c478bd9Sstevel@tonic-gate for (i=0;i<NUMFLDS;i++)
1357c478bd9Sstevel@tonic-gate flds[i] = CNULL;
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate for (p=line;p && *p;) {
1387c478bd9Sstevel@tonic-gate p = next_token (p, &pair);
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate for (i=0; i<NUMFLDS; i++) {
1417c478bd9Sstevel@tonic-gate if (EQUALS(pair.name, _Lwords[i])) {
1427c478bd9Sstevel@tonic-gate flds[i] = pair.value;
1437c478bd9Sstevel@tonic-gate break;
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate if (i == NUMFLDS-1) /* pair.name is not key */
1467c478bd9Sstevel@tonic-gate return FAIL;
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate return(SUCCESS);
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate * this function can only handle the following format
1537c478bd9Sstevel@tonic-gate *
1547c478bd9Sstevel@tonic-gate * service=uucico max=5
1557c478bd9Sstevel@tonic-gate *
1567c478bd9Sstevel@tonic-gate * return:
1577c478bd9Sstevel@tonic-gate * SUCCESS - OK
1587c478bd9Sstevel@tonic-gate * FAIL - service's value does not match or wrong format
1597c478bd9Sstevel@tonic-gate */
1607c478bd9Sstevel@tonic-gate static int
siteindep(flds,service,limitval)1617c478bd9Sstevel@tonic-gate siteindep(flds, service, limitval)
1627c478bd9Sstevel@tonic-gate char *flds[];
1637c478bd9Sstevel@tonic-gate char *service;
1647c478bd9Sstevel@tonic-gate struct limits *limitval;
1657c478bd9Sstevel@tonic-gate {
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate if (!EQUALS(flds[U_SERVICE], service) || (flds[U_MAX] == CNULL))
1687c478bd9Sstevel@tonic-gate return(FAIL);
1697c478bd9Sstevel@tonic-gate if (sscanf(flds[U_MAX],"%d",&limitval->totalmax)==0)
1707c478bd9Sstevel@tonic-gate limitval->totalmax = -1; /* type conflict*/
1717c478bd9Sstevel@tonic-gate return(SUCCESS);
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate
174*2a8bcb4eSToomas Soome /* The following #if (0 == 1) and #endif lines should be deleted when
175*2a8bcb4eSToomas Soome * we expand the functionality of the Limits file to include the
1767c478bd9Sstevel@tonic-gate * limit per site, and the mode for uucico.
1777c478bd9Sstevel@tonic-gate */
1787c478bd9Sstevel@tonic-gate #if (0 == 1)
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate * this function can only handle the following format
1817c478bd9Sstevel@tonic-gate *
1827c478bd9Sstevel@tonic-gate * service=uucico system=ihnp1:ihnp3 [max=5] [mode=master]
1837c478bd9Sstevel@tonic-gate *
1847c478bd9Sstevel@tonic-gate * return:
1857c478bd9Sstevel@tonic-gate * SUCCESS - OK
186*2a8bcb4eSToomas Soome * FAIL - not uucico, no system name in Limits,
1877c478bd9Sstevel@tonic-gate * system's name does not match
1887c478bd9Sstevel@tonic-gate */
1897c478bd9Sstevel@tonic-gate static int
sitedep(flds,limitval)1907c478bd9Sstevel@tonic-gate sitedep(flds, limitval)
1917c478bd9Sstevel@tonic-gate char *flds[];
1927c478bd9Sstevel@tonic-gate struct limits *limitval;
1937c478bd9Sstevel@tonic-gate {
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate if (!EQUALS(flds[U_SERVICE],"uucico"))
196*2a8bcb4eSToomas Soome return FAIL;
1977c478bd9Sstevel@tonic-gate if ((flds[U_SYSTEM] == CNULL) || (sysmatch(flds[U_SYSTEM]) != 0))
1987c478bd9Sstevel@tonic-gate return FAIL;
1997c478bd9Sstevel@tonic-gate if (flds[U_MAX] == CNULL)
2007c478bd9Sstevel@tonic-gate limitval->sitemax = 1; /* default value */
2017c478bd9Sstevel@tonic-gate else if (sscanf(flds[U_MAX],"%d",&limitval->sitemax)==0)
2027c478bd9Sstevel@tonic-gate limitval->sitemax = -1; /* type conflict*/
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate if (flds[U_MODE] == CNULL)
2057c478bd9Sstevel@tonic-gate strcpy(limitval->mode,"master:slave");
2067c478bd9Sstevel@tonic-gate else
2077c478bd9Sstevel@tonic-gate strncpy(limitval->mode,flds[U_MODE],strlen(flds[U_MODE]));
2087c478bd9Sstevel@tonic-gate return(SUCCESS);
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate /*
2127c478bd9Sstevel@tonic-gate * this function checks if system in system's list
2137c478bd9Sstevel@tonic-gate * system=ihnp1:ihnp3:...
2147c478bd9Sstevel@tonic-gate *
2157c478bd9Sstevel@tonic-gate * return:
2167c478bd9Sstevel@tonic-gate * SUCCESS - OK
2177c478bd9Sstevel@tonic-gate */
2187c478bd9Sstevel@tonic-gate static int
sysmatch(p)2197c478bd9Sstevel@tonic-gate sysmatch(p)
2207c478bd9Sstevel@tonic-gate char *p;
2217c478bd9Sstevel@tonic-gate {
2227c478bd9Sstevel@tonic-gate char *arg;
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate while (p && *p) {
2257c478bd9Sstevel@tonic-gate p = nextarg(p, &arg);
226*2a8bcb4eSToomas Soome if (EQUALS(arg, Rmtname))
2277c478bd9Sstevel@tonic-gate return(SUCCESS);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate return FAIL;
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate #endif
233