1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:limits.c 1.4 */ 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #include "uucp.h" 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* add sitedep() and sysmatch() to list when ifdefs are removed below */ 31*7c478bd9Sstevel@tonic-gate static int get_tokens(), siteindep(); 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate /* field array indexes for LIMIT parameters */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #define U_SERVICE 0 36*7c478bd9Sstevel@tonic-gate #define U_MAX 1 37*7c478bd9Sstevel@tonic-gate #define U_SYSTEM 2 38*7c478bd9Sstevel@tonic-gate #define U_MODE 3 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate static char * _Lwords[] = {"service", "max", "system", "mode"}; 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #define NUMFLDS 4 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate struct name_value 45*7c478bd9Sstevel@tonic-gate { 46*7c478bd9Sstevel@tonic-gate char *name; 47*7c478bd9Sstevel@tonic-gate char *value; 48*7c478bd9Sstevel@tonic-gate }; 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate /* 51*7c478bd9Sstevel@tonic-gate * manage limits file. 52*7c478bd9Sstevel@tonic-gate */ 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate /* 55*7c478bd9Sstevel@tonic-gate * scan the Limits file and get the limit for the given service. 56*7c478bd9Sstevel@tonic-gate * return SUCCESS if the limit was found, else return FAIL. 57*7c478bd9Sstevel@tonic-gate */ 58*7c478bd9Sstevel@tonic-gate int 59*7c478bd9Sstevel@tonic-gate scanlimit(service, limitval) 60*7c478bd9Sstevel@tonic-gate char *service; 61*7c478bd9Sstevel@tonic-gate struct limits *limitval; 62*7c478bd9Sstevel@tonic-gate { 63*7c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 64*7c478bd9Sstevel@tonic-gate char *tokens[NUMFLDS]; /* fields found in LIMITS */ 65*7c478bd9Sstevel@tonic-gate char msgbuf[BUFSIZ]; /* place to build messages */ 66*7c478bd9Sstevel@tonic-gate FILE *Fp = NULL; /* file pointer for LIMITS */ 67*7c478bd9Sstevel@tonic-gate int SIflag, SDflag; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate if ((Fp = fopen(LIMITS, "r")) == NULL) { 70*7c478bd9Sstevel@tonic-gate DEBUG(5, "cannot open %s\n", LIMITS); 71*7c478bd9Sstevel@tonic-gate sprintf(msgbuf, "fopen of %s failed with errno=%%d\n", LIMITS); 72*7c478bd9Sstevel@tonic-gate DEBUG(5, msgbuf, errno); 73*7c478bd9Sstevel@tonic-gate return(FAIL); 74*7c478bd9Sstevel@tonic-gate } 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate SIflag = FALSE; 77*7c478bd9Sstevel@tonic-gate SDflag = TRUE; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* The following #if (0 == 1) and #endif lines should be deleted when 80*7c478bd9Sstevel@tonic-gate * we expand the functionality of the Limits file to include the 81*7c478bd9Sstevel@tonic-gate * limit per site, and the mode for uucico. 82*7c478bd9Sstevel@tonic-gate */ 83*7c478bd9Sstevel@tonic-gate #if (0 == 1) 84*7c478bd9Sstevel@tonic-gate if (strcmp(service, "uucico") == SAME) 85*7c478bd9Sstevel@tonic-gate SDflag = FALSE; 86*7c478bd9Sstevel@tonic-gate #endif 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate while ((getuline(Fp, buf) > 0) && ((SIflag && SDflag) == FALSE)) { 89*7c478bd9Sstevel@tonic-gate if (get_tokens(buf, tokens) == FAIL) 90*7c478bd9Sstevel@tonic-gate continue; 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate if (SIflag == FALSE) { 93*7c478bd9Sstevel@tonic-gate if (siteindep(tokens, service, limitval) == SUCCESS) 94*7c478bd9Sstevel@tonic-gate SIflag = TRUE; 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* The following #if (0 == 1) and #endif lines should be deleted when 98*7c478bd9Sstevel@tonic-gate * we expand the functionality of the Limits file to include the 99*7c478bd9Sstevel@tonic-gate * limit per site, and the mode for uucico. 100*7c478bd9Sstevel@tonic-gate */ 101*7c478bd9Sstevel@tonic-gate #if (0 == 1) 102*7c478bd9Sstevel@tonic-gate if (SDflag == FALSE) { 103*7c478bd9Sstevel@tonic-gate if (sitedep(tokens, limitval) == SUCCESS) 104*7c478bd9Sstevel@tonic-gate SDflag = TRUE; 105*7c478bd9Sstevel@tonic-gate } 106*7c478bd9Sstevel@tonic-gate #endif 107*7c478bd9Sstevel@tonic-gate } 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate fclose(Fp); 110*7c478bd9Sstevel@tonic-gate if ((SIflag && SDflag) == TRUE) 111*7c478bd9Sstevel@tonic-gate return(SUCCESS); 112*7c478bd9Sstevel@tonic-gate else return(FAIL); 113*7c478bd9Sstevel@tonic-gate } 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate /* 116*7c478bd9Sstevel@tonic-gate * parse a line in LIMITS and return a vector 117*7c478bd9Sstevel@tonic-gate * of fields (flds) 118*7c478bd9Sstevel@tonic-gate * 119*7c478bd9Sstevel@tonic-gate * return: 120*7c478bd9Sstevel@tonic-gate * SUCCESS - token pairs name match with the key words 121*7c478bd9Sstevel@tonic-gate */ 122*7c478bd9Sstevel@tonic-gate static int 123*7c478bd9Sstevel@tonic-gate get_tokens (line,flds) 124*7c478bd9Sstevel@tonic-gate char *line; 125*7c478bd9Sstevel@tonic-gate char *flds[]; 126*7c478bd9Sstevel@tonic-gate { 127*7c478bd9Sstevel@tonic-gate register i; 128*7c478bd9Sstevel@tonic-gate register char *p; 129*7c478bd9Sstevel@tonic-gate struct name_value pair; 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate /* initialize defaults in case parameter is not specified */ 132*7c478bd9Sstevel@tonic-gate for (i=0;i<NUMFLDS;i++) 133*7c478bd9Sstevel@tonic-gate flds[i] = CNULL; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate for (p=line;p && *p;) { 136*7c478bd9Sstevel@tonic-gate p = next_token (p, &pair); 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate for (i=0; i<NUMFLDS; i++) { 139*7c478bd9Sstevel@tonic-gate if (EQUALS(pair.name, _Lwords[i])) { 140*7c478bd9Sstevel@tonic-gate flds[i] = pair.value; 141*7c478bd9Sstevel@tonic-gate break; 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate if (i == NUMFLDS-1) /* pair.name is not key */ 144*7c478bd9Sstevel@tonic-gate return FAIL; 145*7c478bd9Sstevel@tonic-gate } 146*7c478bd9Sstevel@tonic-gate } 147*7c478bd9Sstevel@tonic-gate return(SUCCESS); 148*7c478bd9Sstevel@tonic-gate } 149*7c478bd9Sstevel@tonic-gate /* 150*7c478bd9Sstevel@tonic-gate * this function can only handle the following format 151*7c478bd9Sstevel@tonic-gate * 152*7c478bd9Sstevel@tonic-gate * service=uucico max=5 153*7c478bd9Sstevel@tonic-gate * 154*7c478bd9Sstevel@tonic-gate * return: 155*7c478bd9Sstevel@tonic-gate * SUCCESS - OK 156*7c478bd9Sstevel@tonic-gate * FAIL - service's value does not match or wrong format 157*7c478bd9Sstevel@tonic-gate */ 158*7c478bd9Sstevel@tonic-gate static int 159*7c478bd9Sstevel@tonic-gate siteindep(flds, service, limitval) 160*7c478bd9Sstevel@tonic-gate char *flds[]; 161*7c478bd9Sstevel@tonic-gate char *service; 162*7c478bd9Sstevel@tonic-gate struct limits *limitval; 163*7c478bd9Sstevel@tonic-gate { 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate if (!EQUALS(flds[U_SERVICE], service) || (flds[U_MAX] == CNULL)) 166*7c478bd9Sstevel@tonic-gate return(FAIL); 167*7c478bd9Sstevel@tonic-gate if (sscanf(flds[U_MAX],"%d",&limitval->totalmax)==0) 168*7c478bd9Sstevel@tonic-gate limitval->totalmax = -1; /* type conflict*/ 169*7c478bd9Sstevel@tonic-gate return(SUCCESS); 170*7c478bd9Sstevel@tonic-gate } 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate /* The following #if (0 == 1) and #endif lines should be deleted when 173*7c478bd9Sstevel@tonic-gate * we expand the functionality of the Limits file to include the 174*7c478bd9Sstevel@tonic-gate * limit per site, and the mode for uucico. 175*7c478bd9Sstevel@tonic-gate */ 176*7c478bd9Sstevel@tonic-gate #if (0 == 1) 177*7c478bd9Sstevel@tonic-gate /* 178*7c478bd9Sstevel@tonic-gate * this function can only handle the following format 179*7c478bd9Sstevel@tonic-gate * 180*7c478bd9Sstevel@tonic-gate * service=uucico system=ihnp1:ihnp3 [max=5] [mode=master] 181*7c478bd9Sstevel@tonic-gate * 182*7c478bd9Sstevel@tonic-gate * return: 183*7c478bd9Sstevel@tonic-gate * SUCCESS - OK 184*7c478bd9Sstevel@tonic-gate * FAIL - not uucico, no system name in Limits, 185*7c478bd9Sstevel@tonic-gate * system's name does not match 186*7c478bd9Sstevel@tonic-gate */ 187*7c478bd9Sstevel@tonic-gate static int 188*7c478bd9Sstevel@tonic-gate sitedep(flds, limitval) 189*7c478bd9Sstevel@tonic-gate char *flds[]; 190*7c478bd9Sstevel@tonic-gate struct limits *limitval; 191*7c478bd9Sstevel@tonic-gate { 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate if (!EQUALS(flds[U_SERVICE],"uucico")) 194*7c478bd9Sstevel@tonic-gate return FAIL; 195*7c478bd9Sstevel@tonic-gate if ((flds[U_SYSTEM] == CNULL) || (sysmatch(flds[U_SYSTEM]) != 0)) 196*7c478bd9Sstevel@tonic-gate return FAIL; 197*7c478bd9Sstevel@tonic-gate if (flds[U_MAX] == CNULL) 198*7c478bd9Sstevel@tonic-gate limitval->sitemax = 1; /* default value */ 199*7c478bd9Sstevel@tonic-gate else if (sscanf(flds[U_MAX],"%d",&limitval->sitemax)==0) 200*7c478bd9Sstevel@tonic-gate limitval->sitemax = -1; /* type conflict*/ 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate if (flds[U_MODE] == CNULL) 203*7c478bd9Sstevel@tonic-gate strcpy(limitval->mode,"master:slave"); 204*7c478bd9Sstevel@tonic-gate else 205*7c478bd9Sstevel@tonic-gate strncpy(limitval->mode,flds[U_MODE],strlen(flds[U_MODE])); 206*7c478bd9Sstevel@tonic-gate return(SUCCESS); 207*7c478bd9Sstevel@tonic-gate } 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate /* 210*7c478bd9Sstevel@tonic-gate * this function checks if system in system's list 211*7c478bd9Sstevel@tonic-gate * system=ihnp1:ihnp3:... 212*7c478bd9Sstevel@tonic-gate * 213*7c478bd9Sstevel@tonic-gate * return: 214*7c478bd9Sstevel@tonic-gate * SUCCESS - OK 215*7c478bd9Sstevel@tonic-gate */ 216*7c478bd9Sstevel@tonic-gate static int 217*7c478bd9Sstevel@tonic-gate sysmatch(p) 218*7c478bd9Sstevel@tonic-gate char *p; 219*7c478bd9Sstevel@tonic-gate { 220*7c478bd9Sstevel@tonic-gate char *arg; 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate while (p && *p) { 223*7c478bd9Sstevel@tonic-gate p = nextarg(p, &arg); 224*7c478bd9Sstevel@tonic-gate if (EQUALS(arg, Rmtname)) 225*7c478bd9Sstevel@tonic-gate return(SUCCESS); 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate return FAIL; 228*7c478bd9Sstevel@tonic-gate } 229*7c478bd9Sstevel@tonic-gate 230*7c478bd9Sstevel@tonic-gate #endif 231