summaryrefslogtreecommitdiff
path: root/usr/src/cmd/bnu/limits.c
blob: f1cce97ba7bec7069dbdffee1e58f76c678402ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
/*	  All Rights Reserved  	*/


#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include "uucp.h"

/* add sitedep() and sysmatch() to list when ifdefs are removed below */
static int get_tokens(), siteindep();

/*  field array indexes for LIMIT parameters */

#define U_SERVICE	0
#define U_MAX		1
#define U_SYSTEM	2
#define U_MODE		3

static char * _Lwords[] = {"service", "max", "system", "mode"};

#define NUMFLDS		4

struct name_value
{
	char *name;
	char *value;
};

/*
 * manage limits file.
 */

/*
 * scan the Limits file and get the limit for the given service.
 * return SUCCESS if the limit was found, else return FAIL.
 */
int
scanlimit(service, limitval)
char *service;
struct limits *limitval;
{
	char buf[BUFSIZ];
	char *tokens[NUMFLDS];	/* fields found in LIMITS */
	char msgbuf[BUFSIZ];	/* place to build messages */
	FILE *Fp = NULL;	/* file pointer for LIMITS */
	int SIflag, SDflag;

	if ((Fp = fopen(LIMITS, "r")) == NULL) {
	    DEBUG(5, "cannot open %s\n", LIMITS);
	    sprintf(msgbuf, "fopen of %s failed with errno=%%d\n", LIMITS);
	    DEBUG(5, msgbuf, errno);
	    return(FAIL);
	}

	SIflag = FALSE;
	SDflag = TRUE;

/* The following #if (0 == 1) and #endif lines should be deleted when 
 * we expand the functionality of the Limits file to include the 
 * limit per site, and the mode for uucico.
 */
#if (0 == 1)
	if (strcmp(service, "uucico") == SAME)
	    SDflag = FALSE;
#endif

	while ((getuline(Fp, buf) > 0) && ((SIflag && SDflag) == FALSE)) {
	    if (get_tokens(buf, tokens) == FAIL)
		continue;

	    if (SIflag == FALSE) {
		if (siteindep(tokens, service, limitval) == SUCCESS)
		    SIflag = TRUE;
	    }

/* The following #if (0 == 1) and #endif lines should be deleted when 
 * we expand the functionality of the Limits file to include the 
 * limit per site, and the mode for uucico.
 */
#if (0 == 1)
	    if (SDflag == FALSE) {
		if (sitedep(tokens, limitval) == SUCCESS)
		    SDflag = TRUE;
	    }
#endif
	}

	fclose(Fp);
	if ((SIflag && SDflag) == TRUE)
	    return(SUCCESS);
	else return(FAIL);
}

/*
 * parse a line in LIMITS and return a vector
 * of fields (flds)
 *
 * return:
 *	SUCCESS - token pairs name match with the key words
 */
static int
get_tokens (line,flds)
char *line;
char *flds[];
{
	int i;
	char *p;
	struct name_value pair;

	/* initialize defaults  in case parameter is not specified */
	for (i=0;i<NUMFLDS;i++)
		flds[i] = CNULL;

	for (p=line;p && *p;) {
		p = next_token (p, &pair);

		for (i=0; i<NUMFLDS; i++) {
			if (EQUALS(pair.name, _Lwords[i])) {
				flds[i] = pair.value;
				break;
			}
			if (i == NUMFLDS-1) /* pair.name is not key */
				return FAIL;
		}
	}
	return(SUCCESS);
}
/*
 * this function can only handle the following format
 *
 *	service=uucico max=5
 *
 * return:
 *	SUCCESS - OK
 *	FAIL - service's value does not match or wrong format
 */
static int
siteindep(flds, service, limitval)
char *flds[];
char *service;
struct limits *limitval;
{

	if (!EQUALS(flds[U_SERVICE], service) || (flds[U_MAX] == CNULL))
		return(FAIL);
	if (sscanf(flds[U_MAX],"%d",&limitval->totalmax)==0)
		limitval->totalmax = -1; /* type conflict*/
	return(SUCCESS);
}

/* The following #if (0 == 1) and #endif lines should be deleted when 
 * we expand the functionality of the Limits file to include the 
 * limit per site, and the mode for uucico.
 */
#if (0 == 1)
/*
 * this function can only handle the following format
 *
 *	service=uucico system=ihnp1:ihnp3 [max=5] [mode=master]
 *
 * return:
 *	SUCCESS - OK
 *	FAIL - not uucico, no system name in Limits, 
 *		system's name does not match
 */
static int
sitedep(flds, limitval)
char *flds[];
struct limits *limitval;
{

	if (!EQUALS(flds[U_SERVICE],"uucico"))
		return FAIL; 
	if ((flds[U_SYSTEM] == CNULL) || (sysmatch(flds[U_SYSTEM]) != 0))
		return FAIL;
	if (flds[U_MAX] == CNULL)
		limitval->sitemax = 1; /* default value */
	else if (sscanf(flds[U_MAX],"%d",&limitval->sitemax)==0)
			limitval->sitemax = -1; /* type conflict*/

	if (flds[U_MODE] == CNULL)
		strcpy(limitval->mode,"master:slave");
	else
		strncpy(limitval->mode,flds[U_MODE],strlen(flds[U_MODE]));
	return(SUCCESS);
}

/*
 * this function checks if system in system's list
 * system=ihnp1:ihnp3:...
 *
 * return:
 *	SUCCESS - OK
 */
static int
sysmatch(p)
char *p;
{
	char *arg;

	while (p && *p) {
		p = nextarg(p, &arg);
	    	if (EQUALS(arg, Rmtname)) 
			return(SUCCESS);
	}
	return FAIL;
}

#endif