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