17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23*462be471Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #define UUCHECK
347c478bd9Sstevel@tonic-gate int Uerrors = 0; /* error count */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate /* This unusual include (#include "permission.c") is done because
377c478bd9Sstevel@tonic-gate * uucheck wants to use the global static variable in permission.c
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #include "uucp.h"
417c478bd9Sstevel@tonic-gate #include "permission.c"
427c478bd9Sstevel@tonic-gate #include "sysfiles.h"
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate /* These are here because uucpdefs.c is not used, and
457c478bd9Sstevel@tonic-gate * some routines are referenced (never called within uucheck execution)
467c478bd9Sstevel@tonic-gate * and not included.
477c478bd9Sstevel@tonic-gate */
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate #define USAGE "[-v] [-xNUM]"
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate int Debug=0;
mkdirs()52*462be471Sceastha int mkdirs(){ return (0); }
canPath()53*462be471Sceastha int canPath(){ return (0); }
547c478bd9Sstevel@tonic-gate char RemSpool[] = SPOOL; /* this is a dummy for chkpth() -- never used here */
557c478bd9Sstevel@tonic-gate char *Spool = SPOOL;
567c478bd9Sstevel@tonic-gate char *Pubdir = PUBDIR;
577c478bd9Sstevel@tonic-gate char *Bnptr;
587c478bd9Sstevel@tonic-gate char Progname[NAMESIZE];
597c478bd9Sstevel@tonic-gate /* used for READANY and READSOME macros */
607c478bd9Sstevel@tonic-gate struct stat __s_;
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /* This is stuff for uucheck */
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate struct tab
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate char *name;
677c478bd9Sstevel@tonic-gate char *value;
687c478bd9Sstevel@tonic-gate } tab[] =
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate #ifdef CORRUPTDIR
717c478bd9Sstevel@tonic-gate "CORRUPT", CORRUPTDIR,
727c478bd9Sstevel@tonic-gate #endif
737c478bd9Sstevel@tonic-gate "LOGUUCP", LOGUUCP,
747c478bd9Sstevel@tonic-gate "LOGUUX", LOGUUX,
757c478bd9Sstevel@tonic-gate "LOGUUXQT", LOGUUXQT,
767c478bd9Sstevel@tonic-gate "LOGCICO", LOGCICO,
777c478bd9Sstevel@tonic-gate "SEQDIR", SEQDIR,
787c478bd9Sstevel@tonic-gate "STATDIR", STATDIR,
797c478bd9Sstevel@tonic-gate "PERMISSIONS", PERMISSIONS,
807c478bd9Sstevel@tonic-gate "SYSTEMS", SYSTEMS,
817c478bd9Sstevel@tonic-gate "DEVICES", DEVICES ,
827c478bd9Sstevel@tonic-gate "DIALCODES", DIALCODES,
837c478bd9Sstevel@tonic-gate "DIALERS", DIALERS,
847c478bd9Sstevel@tonic-gate #ifdef USRSPOOLLOCKS
857c478bd9Sstevel@tonic-gate "USRSPOOLLOCKS", "/var/spool/locks",
867c478bd9Sstevel@tonic-gate #endif
877c478bd9Sstevel@tonic-gate #ifdef NOSTRANGERS
887c478bd9Sstevel@tonic-gate "NOSTRANGERS", NOSTRANGERS,
897c478bd9Sstevel@tonic-gate #endif
907c478bd9Sstevel@tonic-gate "LIMITS", LIMITS, /* if not defined we'll stat NULL, it's not a bug */
917c478bd9Sstevel@tonic-gate "XQTDIR", XQTDIR,
927c478bd9Sstevel@tonic-gate "WORKSPACE", WORKSPACE,
937c478bd9Sstevel@tonic-gate "admin directory", ADMIN,
947c478bd9Sstevel@tonic-gate NULL,
957c478bd9Sstevel@tonic-gate };
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate extern char *nextarg();
987c478bd9Sstevel@tonic-gate int verbose = 0; /* fsck-like verbosity */
997c478bd9Sstevel@tonic-gate
100*462be471Sceastha int
main(argc,argv)1017c478bd9Sstevel@tonic-gate main(argc, argv)
102*462be471Sceastha int argc;
1037c478bd9Sstevel@tonic-gate char *argv[];
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate struct stat statbuf;
1067c478bd9Sstevel@tonic-gate struct tab *tabptr;
1077c478bd9Sstevel@tonic-gate int i;
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate (void) strcpy(Progname, "uucheck");
1107c478bd9Sstevel@tonic-gate while ((i = getopt(argc, argv, "vx:")) != EOF) {
1117c478bd9Sstevel@tonic-gate switch(i){
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate case 'v':
1147c478bd9Sstevel@tonic-gate verbose++;
1157c478bd9Sstevel@tonic-gate break;
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate case 'x':
1187c478bd9Sstevel@tonic-gate Debug = atoi(optarg);
1197c478bd9Sstevel@tonic-gate if (Debug <= 0)
1207c478bd9Sstevel@tonic-gate Debug = 1;
1217c478bd9Sstevel@tonic-gate #ifdef SMALL
1227c478bd9Sstevel@tonic-gate fprintf(stderr,
1237c478bd9Sstevel@tonic-gate "WARNING: uucheck built with SMALL flag defined -- no debug info available\n");
1247c478bd9Sstevel@tonic-gate #endif /* SMALL */
1257c478bd9Sstevel@tonic-gate break;
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate default:
1287c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\tusage: %s %s\n",
1297c478bd9Sstevel@tonic-gate Progname, USAGE);
1307c478bd9Sstevel@tonic-gate exit(1);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate if (argc != optind) {
1347c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\tusage: %s %s\n", Progname, USAGE);
1357c478bd9Sstevel@tonic-gate exit(1);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate if (verbose) printf("*** uucheck: Check Required Files and Directories\n");
1397c478bd9Sstevel@tonic-gate for (tabptr = tab; tabptr->name != NULL; tabptr++) {
1407c478bd9Sstevel@tonic-gate if (stat(tabptr->value, &statbuf) < 0) {
1417c478bd9Sstevel@tonic-gate fprintf(stderr, "%s - ", tabptr->name);
1427c478bd9Sstevel@tonic-gate perror(tabptr->value);
1437c478bd9Sstevel@tonic-gate Uerrors++;
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate if (verbose) printf("*** uucheck: Directories Check Complete\n\n");
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /* check the permissions file */
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate if (verbose) printf("*** uucheck: Check %s file\n", PERMISSIONS);
1527c478bd9Sstevel@tonic-gate Uerrors += checkPerm();
1537c478bd9Sstevel@tonic-gate if (verbose) printf("*** uucheck: %s Check Complete\n\n", PERMISSIONS);
1547c478bd9Sstevel@tonic-gate
155*462be471Sceastha return(Uerrors);
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate int
checkPerm()1597c478bd9Sstevel@tonic-gate checkPerm ()
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate int type;
1627c478bd9Sstevel@tonic-gate int error=0;
1637c478bd9Sstevel@tonic-gate char defaults[BUFSIZ];
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate for (type=0; type<2; type++) {
1667c478bd9Sstevel@tonic-gate /* type = 0 for LOGNAME, 1 for MACHINE */
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate if (verbose) printf("** %s \n\n",
1697c478bd9Sstevel@tonic-gate type == U_MACHINE
1707c478bd9Sstevel@tonic-gate ?"MACHINE PHASE (when we call or execute their uux requests)"
1717c478bd9Sstevel@tonic-gate :"LOGNAME PHASE (when they call us)" );
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate Fp = fopen(PERMISSIONS, "r");
1747c478bd9Sstevel@tonic-gate if (Fp == NULL) {
1757c478bd9Sstevel@tonic-gate if (verbose) printf("can't open %s\n", PERMISSIONS);
1767c478bd9Sstevel@tonic-gate exit(1);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate for (;;) {
1807c478bd9Sstevel@tonic-gate if (parse_tokens(_Flds, NULL) != 0) {
1817c478bd9Sstevel@tonic-gate fclose(Fp);
1827c478bd9Sstevel@tonic-gate break;
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate if (_Flds[type] == NULL)
1857c478bd9Sstevel@tonic-gate continue;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate /* XXX - need to reset defaults here */
1887c478bd9Sstevel@tonic-gate fillFlds();
1897c478bd9Sstevel@tonic-gate /* if no ReadPath set num to 1--Path already set */
1907c478bd9Sstevel@tonic-gate fillList(U_READPATH, _RPaths);
1917c478bd9Sstevel@tonic-gate fillList(U_WRITEPATH, _WPaths);
1927c478bd9Sstevel@tonic-gate fillList(U_NOREADPATH, _NoRPaths);
1937c478bd9Sstevel@tonic-gate fillList(U_NOWRITEPATH, _NoWPaths);
1947c478bd9Sstevel@tonic-gate if (_Flds[U_COMMANDS] == NULL) {
1957c478bd9Sstevel@tonic-gate strcpy(defaults, DEFAULTCMDS);
1967c478bd9Sstevel@tonic-gate _Flds[U_COMMANDS] = defaults;
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate fillList(U_COMMANDS, _Commands);
1997c478bd9Sstevel@tonic-gate error += outLine(type);
2007c478bd9Sstevel@tonic-gate }
2017c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate return(error);
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate int
outLine(type)2077c478bd9Sstevel@tonic-gate outLine(type)
2087c478bd9Sstevel@tonic-gate int type;
2097c478bd9Sstevel@tonic-gate {
210*462be471Sceastha int i;
211*462be471Sceastha char *p;
2127c478bd9Sstevel@tonic-gate char *arg, cmd[BUFSIZ];
2137c478bd9Sstevel@tonic-gate int error = 0;
2147c478bd9Sstevel@tonic-gate char myname[MAXBASENAME+1];
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate if (_Flds[type][0] == 0)
2177c478bd9Sstevel@tonic-gate return(0);
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate if (type == U_LOGNAME) { /* for LOGNAME */
2207c478bd9Sstevel@tonic-gate p = _Flds[U_LOGNAME];
2217c478bd9Sstevel@tonic-gate if (verbose) printf("When a system logs in as: ");
2227c478bd9Sstevel@tonic-gate while (*p != '\0') {
2237c478bd9Sstevel@tonic-gate p = nextarg(p, &arg);
2247c478bd9Sstevel@tonic-gate if (verbose) printf("(%s) ", arg);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate if (callBack()) {
2297c478bd9Sstevel@tonic-gate if (verbose) printf("\tWe will call them back.\n\n");
2307c478bd9Sstevel@tonic-gate return(0);
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate else { /* MACHINE */
2347c478bd9Sstevel@tonic-gate p = _Flds[U_MACHINE];
2357c478bd9Sstevel@tonic-gate if (verbose) printf("When we call system(s): ");
2367c478bd9Sstevel@tonic-gate while (*p != '\0') {
2377c478bd9Sstevel@tonic-gate p = nextarg(p, &arg);
2387c478bd9Sstevel@tonic-gate if (verbose) printf("(%s) ", arg);
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate if (verbose) printf("\tWe %s allow them to request files.\n",
2457c478bd9Sstevel@tonic-gate requestOK()? "DO" : "DO NOT");
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate if (type == U_LOGNAME) {
2487c478bd9Sstevel@tonic-gate if (verbose) printf("\tWe %s send files queued for them on this call.\n",
2497c478bd9Sstevel@tonic-gate switchRole()? "WILL" : "WILL NOT");
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate if (verbose) printf("\tThey can send files to\n");
2537c478bd9Sstevel@tonic-gate if (_Flds[U_WRITEPATH] == NULL) {
2547c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s (DEFAULT)\n", Pubdir);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate else {
2577c478bd9Sstevel@tonic-gate for (i=0; _WPaths[i] != NULL; i++)
2587c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s\n", _WPaths[i]);
2597c478bd9Sstevel@tonic-gate }
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate if (_Flds[U_NOWRITEPATH] != NULL) {
2627c478bd9Sstevel@tonic-gate if (verbose) printf("\tExcept\n");
2637c478bd9Sstevel@tonic-gate for (i=0; _NoWPaths[i] != NULL; i++)
2647c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s\n", _NoWPaths[i]);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate if (verbose) {
2687c478bd9Sstevel@tonic-gate if (noSpool())
2697c478bd9Sstevel@tonic-gate (void) printf("\tSent files will be created directly in the target directory.\n");
2707c478bd9Sstevel@tonic-gate else {
2717c478bd9Sstevel@tonic-gate (void) printf("\tSent files will be created in %s\n", SPOOL);
2727c478bd9Sstevel@tonic-gate (void) printf("\t before they are copied to the target directory.\n");
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate if (requestOK()) {
2777c478bd9Sstevel@tonic-gate if (verbose) printf("\tThey can request files from\n");
2787c478bd9Sstevel@tonic-gate if (_Flds[U_READPATH] == NULL) {
2797c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s (DEFAULT)\n", Pubdir);
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate else {
2827c478bd9Sstevel@tonic-gate for (i=0; _RPaths[i] != NULL; i++)
2837c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s\n", _RPaths[i]);
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate
2867c478bd9Sstevel@tonic-gate if (_Flds[U_NOREADPATH] != NULL) {
2877c478bd9Sstevel@tonic-gate if (verbose) printf("\tExcept\n");
2887c478bd9Sstevel@tonic-gate for (i=0; _NoRPaths[i] != NULL; i++)
2897c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s\n", _NoRPaths[i]);
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate myName(myname);
2947c478bd9Sstevel@tonic-gate if (verbose) printf("\tMyname for the conversation will be %s.\n",
2957c478bd9Sstevel@tonic-gate myname);
2967c478bd9Sstevel@tonic-gate if (verbose) printf("\tPUBDIR for the conversation will be %s.\n",
2977c478bd9Sstevel@tonic-gate Pubdir);
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate if (type == U_MACHINE) {
3027c478bd9Sstevel@tonic-gate if (verbose) printf("Machine(s): ");
3037c478bd9Sstevel@tonic-gate p = _Flds[U_MACHINE];
3047c478bd9Sstevel@tonic-gate while (*p != '\0') {
3057c478bd9Sstevel@tonic-gate p = nextarg(p, &arg);
3067c478bd9Sstevel@tonic-gate if (verbose) printf("(%s) ", arg);
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate if (verbose) printf("\nCAN execute the following commands:\n");
3097c478bd9Sstevel@tonic-gate for (i=0; _Commands[i] != NULL; i++) {
3107c478bd9Sstevel@tonic-gate if (cmdOK(BASENAME(_Commands[i], '/'), cmd) == FALSE) {
3117c478bd9Sstevel@tonic-gate if (verbose) printf("Software Error in permission.c\n");
3127c478bd9Sstevel@tonic-gate error++;
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate if (verbose) printf("command (%s), fullname (%s)\n",
3157c478bd9Sstevel@tonic-gate BASENAME(_Commands[i], '/'), cmd);
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate return(error);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate void
cleanup(s)3247c478bd9Sstevel@tonic-gate cleanup(s)
3257c478bd9Sstevel@tonic-gate int s;
3267c478bd9Sstevel@tonic-gate {
3277c478bd9Sstevel@tonic-gate exit(s);
3287c478bd9Sstevel@tonic-gate }
329