xref: /titanic_44/usr/src/cmd/bnu/uucheck.c (revision bd335c6465ddbafe543900df4b03247bfa288eff)
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 1993 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 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #define UUCHECK
34 int Uerrors = 0;	/* error count */
35 
36 /* This unusual include (#include "permission.c") is done because
37  * uucheck wants to use the global static variable in permission.c
38  */
39 
40 #include "uucp.h"
41 #include "permission.c"
42 #include "sysfiles.h"
43 
44 /* These are here because uucpdefs.c is not used, and
45  * some routines are referenced (never called within uucheck execution)
46  * and not included.
47  */
48 
49 #define USAGE	"[-v] [-xNUM]"
50 
51 int Debug=0;
52 mkdirs(){}
53 canPath(){}
54 char RemSpool[] = SPOOL; /* this is a dummy for chkpth() -- never used here */
55 char *Spool = SPOOL;
56 char *Pubdir = PUBDIR;
57 char *Bnptr;
58 char	Progname[NAMESIZE];
59 /* used for READANY and READSOME macros */
60 struct stat __s_;
61 
62 /* This is stuff for uucheck */
63 
64 struct tab
65    {
66     char *name;
67     char *value;
68    } tab[] =
69    {
70 #ifdef	CORRUPTDIR
71     "CORRUPT",	CORRUPTDIR,
72 #endif
73     "LOGUUCP",	LOGUUCP,
74     "LOGUUX",	LOGUUX,
75     "LOGUUXQT",	LOGUUXQT,
76     "LOGCICO",	LOGCICO,
77     "SEQDIR",	SEQDIR,
78     "STATDIR",	STATDIR,
79     "PERMISSIONS",	PERMISSIONS,
80     "SYSTEMS",	SYSTEMS,
81     "DEVICES",	DEVICES	,
82     "DIALCODES",	DIALCODES,
83     "DIALERS",	DIALERS,
84 #ifdef	USRSPOOLLOCKS
85     "USRSPOOLLOCKS",	"/var/spool/locks",
86 #endif
87 #ifdef	NOSTRANGERS
88     "NOSTRANGERS",	NOSTRANGERS,
89 #endif
90     "LIMITS",	LIMITS, /* if not defined we'll stat NULL, it's not a bug */
91     "XQTDIR",	XQTDIR,
92     "WORKSPACE",	WORKSPACE,
93     "admin directory",	ADMIN,
94     NULL,
95    };
96 
97 extern char *nextarg();
98 int verbose = 0;	/* fsck-like verbosity */
99 
100 main(argc, argv)
101 char *argv[];
102 {
103     struct stat statbuf;
104     struct tab *tabptr;
105     int i;
106 
107 	(void) strcpy(Progname, "uucheck");
108 	while ((i = getopt(argc, argv, "vx:")) != EOF) {
109 		switch(i){
110 
111 		case 'v':
112 			verbose++;
113 			break;
114 
115 		case 'x':
116 			Debug = atoi(optarg);
117 			if (Debug <= 0)
118 				Debug = 1;
119 #ifdef SMALL
120 			fprintf(stderr,
121 			"WARNING: uucheck built with SMALL flag defined -- no debug info available\n");
122 #endif /* SMALL */
123 			break;
124 
125 		default:
126 			(void) fprintf(stderr, "\tusage: %s %s\n",
127 			    Progname, USAGE);
128 			exit(1);
129 		}
130 	}
131 	if (argc != optind) {
132 		(void) fprintf(stderr, "\tusage: %s %s\n", Progname, USAGE);
133 		exit(1);
134 	}
135 
136     if (verbose) printf("*** uucheck:  Check Required Files and Directories\n");
137     for (tabptr = tab; tabptr->name != NULL; tabptr++) {
138         if (stat(tabptr->value, &statbuf) < 0) {
139 	    fprintf(stderr, "%s - ", tabptr->name);
140 	    perror(tabptr->value);
141 	    Uerrors++;
142 	}
143     }
144 
145     if (verbose) printf("*** uucheck:  Directories Check Complete\n\n");
146 
147     /* check the permissions file */
148 
149     if (verbose) printf("*** uucheck:  Check %s file\n", PERMISSIONS);
150     Uerrors += checkPerm();
151     if (verbose) printf("*** uucheck:  %s Check Complete\n\n", PERMISSIONS);
152 
153     exit(Uerrors);
154 
155 
156 	/* NOTREACHED */
157 }
158 
159 int
160 checkPerm ()
161 {
162     int type;
163     int error=0;
164     char defaults[BUFSIZ];
165 
166     for (type=0; type<2; type++) {
167 	/* type = 0 for LOGNAME, 1 for MACHINE */
168 
169 	if (verbose) printf("** %s \n\n",
170 	    type == U_MACHINE
171 		?"MACHINE PHASE (when we call or execute their uux requests)"
172 		:"LOGNAME PHASE (when they call us)" );
173 
174 	Fp = fopen(PERMISSIONS, "r");
175 	if (Fp == NULL) {
176 		if (verbose) printf("can't open %s\n", PERMISSIONS);
177 		exit(1);
178 	}
179 
180 	for (;;) {
181 	    if (parse_tokens(_Flds, NULL) != 0) {
182 		fclose(Fp);
183 		break;
184 	    }
185 	    if (_Flds[type] == NULL)
186 	        continue;
187 
188 	    /* XXX - need to reset defaults here */
189 	    fillFlds();
190 	    /* if no ReadPath set num to 1--Path already set */
191 	    fillList(U_READPATH, _RPaths);
192 	    fillList(U_WRITEPATH, _WPaths);
193 	    fillList(U_NOREADPATH, _NoRPaths);
194 	    fillList(U_NOWRITEPATH, _NoWPaths);
195 	    if (_Flds[U_COMMANDS] == NULL) {
196 		strcpy(defaults, DEFAULTCMDS);
197 		_Flds[U_COMMANDS] = defaults;
198 	    }
199 	    fillList(U_COMMANDS, _Commands);
200 	    error += outLine(type);
201 	}
202     if (verbose) printf("\n");
203     }
204     return(error);
205 }
206 
207 int
208 outLine(type)
209 int type;
210 {
211 	register int i;
212 	register char *p;
213 	char *arg, cmd[BUFSIZ];
214 	int error = 0;
215 	char myname[MAXBASENAME+1];
216 
217 	if (_Flds[type][0] == 0)
218 	    return(0);
219 
220 	if (type == U_LOGNAME) { /* for LOGNAME */
221 	    p = _Flds[U_LOGNAME];
222 	    if (verbose) printf("When a system logs in as: ");
223 	    while (*p != '\0') {
224 		p = nextarg(p, &arg);
225 		if (verbose) 	printf("(%s) ", arg);
226 	    }
227 	    if (verbose) printf("\n");
228 
229 	    if (callBack()) {
230 		if (verbose) printf("\tWe will call them back.\n\n");
231 		return(0);
232 	    }
233 	}
234 	else {	/* MACHINE */
235 	    p = _Flds[U_MACHINE];
236 	    if (verbose) printf("When we call system(s): ");
237 	    while (*p != '\0') {
238 		p = nextarg(p, &arg);
239 		if (verbose) printf("(%s) ", arg);
240 	    }
241 	    if (verbose) printf("\n");
242 
243 	}
244 
245 	if (verbose) printf("\tWe %s allow them to request files.\n",
246 	    requestOK()? "DO" : "DO NOT");
247 
248 	if (type == U_LOGNAME) {
249 		if (verbose) printf("\tWe %s send files queued for them on this call.\n",
250 		    switchRole()? "WILL" : "WILL NOT");
251 	}
252 
253 	if (verbose) printf("\tThey can send files to\n");
254 	if (_Flds[U_WRITEPATH] == NULL) {
255 	    if (verbose) printf("\t    %s (DEFAULT)\n", Pubdir);
256 	}
257 	else {
258 	    for (i=0; _WPaths[i] != NULL; i++)
259 		if (verbose) printf("\t    %s\n", _WPaths[i]);
260 	}
261 
262 	if (_Flds[U_NOWRITEPATH] != NULL) {
263 	    if (verbose) printf("\tExcept\n");
264 	    for (i=0; _NoWPaths[i] != NULL; i++)
265 		if (verbose) printf("\t    %s\n", _NoWPaths[i]);
266 	}
267 
268 	if (verbose) {
269 	    if (noSpool())
270 		(void) printf("\tSent files will be created directly in the target directory.\n");
271 	    else {
272 		(void) printf("\tSent files will be created in %s\n", SPOOL);
273 		(void) printf("\t before they are copied to the target directory.\n");
274 	    }
275 	}
276 
277 	if (requestOK()) {
278 	    if (verbose) printf("\tThey can request files from\n");
279 	    if (_Flds[U_READPATH] == NULL) {
280 		if (verbose) printf("\t    %s (DEFAULT)\n", Pubdir);
281 	    }
282 	    else {
283 		for (i=0; _RPaths[i] != NULL; i++)
284 		    if (verbose) printf("\t    %s\n", _RPaths[i]);
285 	    }
286 
287 	    if (_Flds[U_NOREADPATH] != NULL) {
288 		if (verbose) printf("\tExcept\n");
289 		for (i=0; _NoRPaths[i] != NULL; i++)
290 		    if (verbose) printf("\t    %s\n", _NoRPaths[i]);
291 	    }
292 	}
293 
294 	myName(myname);
295 	if (verbose) printf("\tMyname for the conversation will be %s.\n",
296 	    myname);
297 	if (verbose) printf("\tPUBDIR for the conversation will be %s.\n",
298 	    Pubdir);
299 
300 	if (verbose) printf("\n");
301 
302 	if (type == U_MACHINE) {
303 	    if (verbose) printf("Machine(s): ");
304 	    p = _Flds[U_MACHINE];
305 	    while (*p != '\0') {
306 		p = nextarg(p, &arg);
307 		if (verbose) printf("(%s) ", arg);
308 	    }
309 	    if (verbose) printf("\nCAN execute the following commands:\n");
310 	    for (i=0; _Commands[i] != NULL; i++) {
311 		if (cmdOK(BASENAME(_Commands[i], '/'), cmd) == FALSE) {
312 		    if (verbose) printf("Software Error in permission.c\n");
313 		    error++;
314 		}
315 		if (verbose) printf("command (%s), fullname (%s)\n",
316 		    BASENAME(_Commands[i], '/'), cmd);
317 	    }
318 	    if (verbose) printf("\n");
319 	}
320 
321 	return(error);
322 }
323 
324 void
325 cleanup(s)
326 	int s;
327 {
328 	exit(s);
329 }
330