xref: /titanic_41/usr/src/cmd/bnu/uucheck.c (revision f29fbe76ce646ba8bcf62627d89087d5f02c62a8)
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 
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 int mkdirs(){ return (0); }
53 int canPath(){ return (0); }
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 int
101 main(argc, argv)
102 int argc;
103 char *argv[];
104 {
105     struct stat statbuf;
106     struct tab *tabptr;
107     int i;
108 
109 	(void) strcpy(Progname, "uucheck");
110 	while ((i = getopt(argc, argv, "vx:")) != EOF) {
111 		switch(i){
112 
113 		case 'v':
114 			verbose++;
115 			break;
116 
117 		case 'x':
118 			Debug = atoi(optarg);
119 			if (Debug <= 0)
120 				Debug = 1;
121 #ifdef SMALL
122 			fprintf(stderr,
123 			"WARNING: uucheck built with SMALL flag defined -- no debug info available\n");
124 #endif /* SMALL */
125 			break;
126 
127 		default:
128 			(void) fprintf(stderr, "\tusage: %s %s\n",
129 			    Progname, USAGE);
130 			exit(1);
131 		}
132 	}
133 	if (argc != optind) {
134 		(void) fprintf(stderr, "\tusage: %s %s\n", Progname, USAGE);
135 		exit(1);
136 	}
137 
138     if (verbose) printf("*** uucheck:  Check Required Files and Directories\n");
139     for (tabptr = tab; tabptr->name != NULL; tabptr++) {
140         if (stat(tabptr->value, &statbuf) < 0) {
141 	    fprintf(stderr, "%s - ", tabptr->name);
142 	    perror(tabptr->value);
143 	    Uerrors++;
144 	}
145     }
146 
147     if (verbose) printf("*** uucheck:  Directories Check Complete\n\n");
148 
149     /* check the permissions file */
150 
151     if (verbose) printf("*** uucheck:  Check %s file\n", PERMISSIONS);
152     Uerrors += checkPerm();
153     if (verbose) printf("*** uucheck:  %s Check Complete\n\n", PERMISSIONS);
154 
155     return(Uerrors);
156 }
157 
158 int
159 checkPerm ()
160 {
161     int type;
162     int error=0;
163     char defaults[BUFSIZ];
164 
165     for (type=0; type<2; type++) {
166 	/* type = 0 for LOGNAME, 1 for MACHINE */
167 
168 	if (verbose) printf("** %s \n\n",
169 	    type == U_MACHINE
170 		?"MACHINE PHASE (when we call or execute their uux requests)"
171 		:"LOGNAME PHASE (when they call us)" );
172 
173 	Fp = fopen(PERMISSIONS, "r");
174 	if (Fp == NULL) {
175 		if (verbose) printf("can't open %s\n", PERMISSIONS);
176 		exit(1);
177 	}
178 
179 	for (;;) {
180 	    if (parse_tokens(_Flds, NULL) != 0) {
181 		fclose(Fp);
182 		break;
183 	    }
184 	    if (_Flds[type] == NULL)
185 	        continue;
186 
187 	    /* XXX - need to reset defaults here */
188 	    fillFlds();
189 	    /* if no ReadPath set num to 1--Path already set */
190 	    fillList(U_READPATH, _RPaths);
191 	    fillList(U_WRITEPATH, _WPaths);
192 	    fillList(U_NOREADPATH, _NoRPaths);
193 	    fillList(U_NOWRITEPATH, _NoWPaths);
194 	    if (_Flds[U_COMMANDS] == NULL) {
195 		strcpy(defaults, DEFAULTCMDS);
196 		_Flds[U_COMMANDS] = defaults;
197 	    }
198 	    fillList(U_COMMANDS, _Commands);
199 	    error += outLine(type);
200 	}
201     if (verbose) printf("\n");
202     }
203     return(error);
204 }
205 
206 int
207 outLine(type)
208 int type;
209 {
210 	int i;
211 	char *p;
212 	char *arg, cmd[BUFSIZ];
213 	int error = 0;
214 	char myname[MAXBASENAME+1];
215 
216 	if (_Flds[type][0] == 0)
217 	    return(0);
218 
219 	if (type == U_LOGNAME) { /* for LOGNAME */
220 	    p = _Flds[U_LOGNAME];
221 	    if (verbose) printf("When a system logs in as: ");
222 	    while (*p != '\0') {
223 		p = nextarg(p, &arg);
224 		if (verbose) 	printf("(%s) ", arg);
225 	    }
226 	    if (verbose) printf("\n");
227 
228 	    if (callBack()) {
229 		if (verbose) printf("\tWe will call them back.\n\n");
230 		return(0);
231 	    }
232 	}
233 	else {	/* MACHINE */
234 	    p = _Flds[U_MACHINE];
235 	    if (verbose) printf("When we call system(s): ");
236 	    while (*p != '\0') {
237 		p = nextarg(p, &arg);
238 		if (verbose) printf("(%s) ", arg);
239 	    }
240 	    if (verbose) printf("\n");
241 
242 	}
243 
244 	if (verbose) printf("\tWe %s allow them to request files.\n",
245 	    requestOK()? "DO" : "DO NOT");
246 
247 	if (type == U_LOGNAME) {
248 		if (verbose) printf("\tWe %s send files queued for them on this call.\n",
249 		    switchRole()? "WILL" : "WILL NOT");
250 	}
251 
252 	if (verbose) printf("\tThey can send files to\n");
253 	if (_Flds[U_WRITEPATH] == NULL) {
254 	    if (verbose) printf("\t    %s (DEFAULT)\n", Pubdir);
255 	}
256 	else {
257 	    for (i=0; _WPaths[i] != NULL; i++)
258 		if (verbose) printf("\t    %s\n", _WPaths[i]);
259 	}
260 
261 	if (_Flds[U_NOWRITEPATH] != NULL) {
262 	    if (verbose) printf("\tExcept\n");
263 	    for (i=0; _NoWPaths[i] != NULL; i++)
264 		if (verbose) printf("\t    %s\n", _NoWPaths[i]);
265 	}
266 
267 	if (verbose) {
268 	    if (noSpool())
269 		(void) printf("\tSent files will be created directly in the target directory.\n");
270 	    else {
271 		(void) printf("\tSent files will be created in %s\n", SPOOL);
272 		(void) printf("\t before they are copied to the target directory.\n");
273 	    }
274 	}
275 
276 	if (requestOK()) {
277 	    if (verbose) printf("\tThey can request files from\n");
278 	    if (_Flds[U_READPATH] == NULL) {
279 		if (verbose) printf("\t    %s (DEFAULT)\n", Pubdir);
280 	    }
281 	    else {
282 		for (i=0; _RPaths[i] != NULL; i++)
283 		    if (verbose) printf("\t    %s\n", _RPaths[i]);
284 	    }
285 
286 	    if (_Flds[U_NOREADPATH] != NULL) {
287 		if (verbose) printf("\tExcept\n");
288 		for (i=0; _NoRPaths[i] != NULL; i++)
289 		    if (verbose) printf("\t    %s\n", _NoRPaths[i]);
290 	    }
291 	}
292 
293 	myName(myname);
294 	if (verbose) printf("\tMyname for the conversation will be %s.\n",
295 	    myname);
296 	if (verbose) printf("\tPUBDIR for the conversation will be %s.\n",
297 	    Pubdir);
298 
299 	if (verbose) printf("\n");
300 
301 	if (type == U_MACHINE) {
302 	    if (verbose) printf("Machine(s): ");
303 	    p = _Flds[U_MACHINE];
304 	    while (*p != '\0') {
305 		p = nextarg(p, &arg);
306 		if (verbose) printf("(%s) ", arg);
307 	    }
308 	    if (verbose) printf("\nCAN execute the following commands:\n");
309 	    for (i=0; _Commands[i] != NULL; i++) {
310 		if (cmdOK(BASENAME(_Commands[i], '/'), cmd) == FALSE) {
311 		    if (verbose) printf("Software Error in permission.c\n");
312 		    error++;
313 		}
314 		if (verbose) printf("command (%s), fullname (%s)\n",
315 		    BASENAME(_Commands[i], '/'), cmd);
316 	    }
317 	    if (verbose) printf("\n");
318 	}
319 
320 	return(error);
321 }
322 
323 void
324 cleanup(s)
325 	int s;
326 {
327 	exit(s);
328 }
329