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