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 */
22*462be471Sceastha /*
23*462be471Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24*462be471Sceastha * Use is subject to license terms.
25*462be471Sceastha */
26*462be471Sceastha
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
31*462be471Sceastha #pragma ident "%Z%%M% %I% %E% SMI"
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include "uucp.h"
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /* add sitedep() and sysmatch() to list when ifdefs are removed below */
367c478bd9Sstevel@tonic-gate static int get_tokens(), siteindep();
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate /* field array indexes for LIMIT parameters */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #define U_SERVICE 0
417c478bd9Sstevel@tonic-gate #define U_MAX 1
427c478bd9Sstevel@tonic-gate #define U_SYSTEM 2
437c478bd9Sstevel@tonic-gate #define U_MODE 3
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate static char * _Lwords[] = {"service", "max", "system", "mode"};
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate #define NUMFLDS 4
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate struct name_value
507c478bd9Sstevel@tonic-gate {
517c478bd9Sstevel@tonic-gate char *name;
527c478bd9Sstevel@tonic-gate char *value;
537c478bd9Sstevel@tonic-gate };
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate * manage limits file.
577c478bd9Sstevel@tonic-gate */
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate * scan the Limits file and get the limit for the given service.
617c478bd9Sstevel@tonic-gate * return SUCCESS if the limit was found, else return FAIL.
627c478bd9Sstevel@tonic-gate */
637c478bd9Sstevel@tonic-gate int
scanlimit(service,limitval)647c478bd9Sstevel@tonic-gate scanlimit(service, limitval)
657c478bd9Sstevel@tonic-gate char *service;
667c478bd9Sstevel@tonic-gate struct limits *limitval;
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
697c478bd9Sstevel@tonic-gate char *tokens[NUMFLDS]; /* fields found in LIMITS */
707c478bd9Sstevel@tonic-gate char msgbuf[BUFSIZ]; /* place to build messages */
717c478bd9Sstevel@tonic-gate FILE *Fp = NULL; /* file pointer for LIMITS */
727c478bd9Sstevel@tonic-gate int SIflag, SDflag;
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate if ((Fp = fopen(LIMITS, "r")) == NULL) {
757c478bd9Sstevel@tonic-gate DEBUG(5, "cannot open %s\n", LIMITS);
767c478bd9Sstevel@tonic-gate sprintf(msgbuf, "fopen of %s failed with errno=%%d\n", LIMITS);
777c478bd9Sstevel@tonic-gate DEBUG(5, msgbuf, errno);
787c478bd9Sstevel@tonic-gate return(FAIL);
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate SIflag = FALSE;
827c478bd9Sstevel@tonic-gate SDflag = TRUE;
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate /* The following #if (0 == 1) and #endif lines should be deleted when
857c478bd9Sstevel@tonic-gate * we expand the functionality of the Limits file to include the
867c478bd9Sstevel@tonic-gate * limit per site, and the mode for uucico.
877c478bd9Sstevel@tonic-gate */
887c478bd9Sstevel@tonic-gate #if (0 == 1)
897c478bd9Sstevel@tonic-gate if (strcmp(service, "uucico") == SAME)
907c478bd9Sstevel@tonic-gate SDflag = FALSE;
917c478bd9Sstevel@tonic-gate #endif
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate while ((getuline(Fp, buf) > 0) && ((SIflag && SDflag) == FALSE)) {
947c478bd9Sstevel@tonic-gate if (get_tokens(buf, tokens) == FAIL)
957c478bd9Sstevel@tonic-gate continue;
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate if (SIflag == FALSE) {
987c478bd9Sstevel@tonic-gate if (siteindep(tokens, service, limitval) == SUCCESS)
997c478bd9Sstevel@tonic-gate SIflag = TRUE;
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate /* The following #if (0 == 1) and #endif lines should be deleted when
1037c478bd9Sstevel@tonic-gate * we expand the functionality of the Limits file to include the
1047c478bd9Sstevel@tonic-gate * limit per site, and the mode for uucico.
1057c478bd9Sstevel@tonic-gate */
1067c478bd9Sstevel@tonic-gate #if (0 == 1)
1077c478bd9Sstevel@tonic-gate if (SDflag == FALSE) {
1087c478bd9Sstevel@tonic-gate if (sitedep(tokens, limitval) == SUCCESS)
1097c478bd9Sstevel@tonic-gate SDflag = TRUE;
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate #endif
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate fclose(Fp);
1157c478bd9Sstevel@tonic-gate if ((SIflag && SDflag) == TRUE)
1167c478bd9Sstevel@tonic-gate return(SUCCESS);
1177c478bd9Sstevel@tonic-gate else return(FAIL);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate * parse a line in LIMITS and return a vector
1227c478bd9Sstevel@tonic-gate * of fields (flds)
1237c478bd9Sstevel@tonic-gate *
1247c478bd9Sstevel@tonic-gate * return:
1257c478bd9Sstevel@tonic-gate * SUCCESS - token pairs name match with the key words
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate static int
get_tokens(line,flds)1287c478bd9Sstevel@tonic-gate get_tokens (line,flds)
1297c478bd9Sstevel@tonic-gate char *line;
1307c478bd9Sstevel@tonic-gate char *flds[];
1317c478bd9Sstevel@tonic-gate {
132*462be471Sceastha int i;
133*462be471Sceastha char *p;
1347c478bd9Sstevel@tonic-gate struct name_value pair;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate /* initialize defaults in case parameter is not specified */
1377c478bd9Sstevel@tonic-gate for (i=0;i<NUMFLDS;i++)
1387c478bd9Sstevel@tonic-gate flds[i] = CNULL;
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate for (p=line;p && *p;) {
1417c478bd9Sstevel@tonic-gate p = next_token (p, &pair);
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate for (i=0; i<NUMFLDS; i++) {
1447c478bd9Sstevel@tonic-gate if (EQUALS(pair.name, _Lwords[i])) {
1457c478bd9Sstevel@tonic-gate flds[i] = pair.value;
1467c478bd9Sstevel@tonic-gate break;
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate if (i == NUMFLDS-1) /* pair.name is not key */
1497c478bd9Sstevel@tonic-gate return FAIL;
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate return(SUCCESS);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate * this function can only handle the following format
1567c478bd9Sstevel@tonic-gate *
1577c478bd9Sstevel@tonic-gate * service=uucico max=5
1587c478bd9Sstevel@tonic-gate *
1597c478bd9Sstevel@tonic-gate * return:
1607c478bd9Sstevel@tonic-gate * SUCCESS - OK
1617c478bd9Sstevel@tonic-gate * FAIL - service's value does not match or wrong format
1627c478bd9Sstevel@tonic-gate */
1637c478bd9Sstevel@tonic-gate static int
siteindep(flds,service,limitval)1647c478bd9Sstevel@tonic-gate siteindep(flds, service, limitval)
1657c478bd9Sstevel@tonic-gate char *flds[];
1667c478bd9Sstevel@tonic-gate char *service;
1677c478bd9Sstevel@tonic-gate struct limits *limitval;
1687c478bd9Sstevel@tonic-gate {
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate if (!EQUALS(flds[U_SERVICE], service) || (flds[U_MAX] == CNULL))
1717c478bd9Sstevel@tonic-gate return(FAIL);
1727c478bd9Sstevel@tonic-gate if (sscanf(flds[U_MAX],"%d",&limitval->totalmax)==0)
1737c478bd9Sstevel@tonic-gate limitval->totalmax = -1; /* type conflict*/
1747c478bd9Sstevel@tonic-gate return(SUCCESS);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate /* The following #if (0 == 1) and #endif lines should be deleted when
1787c478bd9Sstevel@tonic-gate * we expand the functionality of the Limits file to include the
1797c478bd9Sstevel@tonic-gate * limit per site, and the mode for uucico.
1807c478bd9Sstevel@tonic-gate */
1817c478bd9Sstevel@tonic-gate #if (0 == 1)
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate * this function can only handle the following format
1847c478bd9Sstevel@tonic-gate *
1857c478bd9Sstevel@tonic-gate * service=uucico system=ihnp1:ihnp3 [max=5] [mode=master]
1867c478bd9Sstevel@tonic-gate *
1877c478bd9Sstevel@tonic-gate * return:
1887c478bd9Sstevel@tonic-gate * SUCCESS - OK
1897c478bd9Sstevel@tonic-gate * FAIL - not uucico, no system name in Limits,
1907c478bd9Sstevel@tonic-gate * system's name does not match
1917c478bd9Sstevel@tonic-gate */
1927c478bd9Sstevel@tonic-gate static int
sitedep(flds,limitval)1937c478bd9Sstevel@tonic-gate sitedep(flds, limitval)
1947c478bd9Sstevel@tonic-gate char *flds[];
1957c478bd9Sstevel@tonic-gate struct limits *limitval;
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate if (!EQUALS(flds[U_SERVICE],"uucico"))
1997c478bd9Sstevel@tonic-gate return FAIL;
2007c478bd9Sstevel@tonic-gate if ((flds[U_SYSTEM] == CNULL) || (sysmatch(flds[U_SYSTEM]) != 0))
2017c478bd9Sstevel@tonic-gate return FAIL;
2027c478bd9Sstevel@tonic-gate if (flds[U_MAX] == CNULL)
2037c478bd9Sstevel@tonic-gate limitval->sitemax = 1; /* default value */
2047c478bd9Sstevel@tonic-gate else if (sscanf(flds[U_MAX],"%d",&limitval->sitemax)==0)
2057c478bd9Sstevel@tonic-gate limitval->sitemax = -1; /* type conflict*/
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate if (flds[U_MODE] == CNULL)
2087c478bd9Sstevel@tonic-gate strcpy(limitval->mode,"master:slave");
2097c478bd9Sstevel@tonic-gate else
2107c478bd9Sstevel@tonic-gate strncpy(limitval->mode,flds[U_MODE],strlen(flds[U_MODE]));
2117c478bd9Sstevel@tonic-gate return(SUCCESS);
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate /*
2157c478bd9Sstevel@tonic-gate * this function checks if system in system's list
2167c478bd9Sstevel@tonic-gate * system=ihnp1:ihnp3:...
2177c478bd9Sstevel@tonic-gate *
2187c478bd9Sstevel@tonic-gate * return:
2197c478bd9Sstevel@tonic-gate * SUCCESS - OK
2207c478bd9Sstevel@tonic-gate */
2217c478bd9Sstevel@tonic-gate static int
sysmatch(p)2227c478bd9Sstevel@tonic-gate sysmatch(p)
2237c478bd9Sstevel@tonic-gate char *p;
2247c478bd9Sstevel@tonic-gate {
2257c478bd9Sstevel@tonic-gate char *arg;
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate while (p && *p) {
2287c478bd9Sstevel@tonic-gate p = nextarg(p, &arg);
2297c478bd9Sstevel@tonic-gate if (EQUALS(arg, Rmtname))
2307c478bd9Sstevel@tonic-gate return(SUCCESS);
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate return FAIL;
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate #endif
236