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