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 /*
23462be471Sceastha * 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 #define UUCHECK
317c478bd9Sstevel@tonic-gate int Uerrors = 0; /* error count */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate /* This unusual include (#include "permission.c") is done because
347c478bd9Sstevel@tonic-gate * uucheck wants to use the global static variable in permission.c
357c478bd9Sstevel@tonic-gate */
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #include "uucp.h"
387c478bd9Sstevel@tonic-gate #include "permission.c"
397c478bd9Sstevel@tonic-gate #include "sysfiles.h"
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate /* These are here because uucpdefs.c is not used, and
427c478bd9Sstevel@tonic-gate * some routines are referenced (never called within uucheck execution)
437c478bd9Sstevel@tonic-gate * and not included.
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #define USAGE "[-v] [-xNUM]"
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate int Debug=0;
mkdirs()49462be471Sceastha int mkdirs(){ return (0); }
canPath()50462be471Sceastha int canPath(){ return (0); }
517c478bd9Sstevel@tonic-gate char RemSpool[] = SPOOL; /* this is a dummy for chkpth() -- never used here */
527c478bd9Sstevel@tonic-gate char *Spool = SPOOL;
537c478bd9Sstevel@tonic-gate char *Pubdir = PUBDIR;
547c478bd9Sstevel@tonic-gate char *Bnptr;
557c478bd9Sstevel@tonic-gate char Progname[NAMESIZE];
567c478bd9Sstevel@tonic-gate /* used for READANY and READSOME macros */
577c478bd9Sstevel@tonic-gate struct stat __s_;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /* This is stuff for uucheck */
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate struct tab
627c478bd9Sstevel@tonic-gate {
637c478bd9Sstevel@tonic-gate char *name;
647c478bd9Sstevel@tonic-gate char *value;
657c478bd9Sstevel@tonic-gate } tab[] =
667c478bd9Sstevel@tonic-gate {
677c478bd9Sstevel@tonic-gate #ifdef CORRUPTDIR
687c478bd9Sstevel@tonic-gate "CORRUPT", CORRUPTDIR,
697c478bd9Sstevel@tonic-gate #endif
707c478bd9Sstevel@tonic-gate "LOGUUCP", LOGUUCP,
717c478bd9Sstevel@tonic-gate "LOGUUX", LOGUUX,
727c478bd9Sstevel@tonic-gate "LOGUUXQT", LOGUUXQT,
737c478bd9Sstevel@tonic-gate "LOGCICO", LOGCICO,
747c478bd9Sstevel@tonic-gate "SEQDIR", SEQDIR,
757c478bd9Sstevel@tonic-gate "STATDIR", STATDIR,
767c478bd9Sstevel@tonic-gate "PERMISSIONS", PERMISSIONS,
777c478bd9Sstevel@tonic-gate "SYSTEMS", SYSTEMS,
787c478bd9Sstevel@tonic-gate "DEVICES", DEVICES ,
797c478bd9Sstevel@tonic-gate "DIALCODES", DIALCODES,
807c478bd9Sstevel@tonic-gate "DIALERS", DIALERS,
817c478bd9Sstevel@tonic-gate #ifdef USRSPOOLLOCKS
827c478bd9Sstevel@tonic-gate "USRSPOOLLOCKS", "/var/spool/locks",
837c478bd9Sstevel@tonic-gate #endif
847c478bd9Sstevel@tonic-gate #ifdef NOSTRANGERS
857c478bd9Sstevel@tonic-gate "NOSTRANGERS", NOSTRANGERS,
867c478bd9Sstevel@tonic-gate #endif
877c478bd9Sstevel@tonic-gate "LIMITS", LIMITS, /* if not defined we'll stat NULL, it's not a bug */
887c478bd9Sstevel@tonic-gate "XQTDIR", XQTDIR,
897c478bd9Sstevel@tonic-gate "WORKSPACE", WORKSPACE,
907c478bd9Sstevel@tonic-gate "admin directory", ADMIN,
917c478bd9Sstevel@tonic-gate NULL,
927c478bd9Sstevel@tonic-gate };
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate extern char *nextarg();
957c478bd9Sstevel@tonic-gate int verbose = 0; /* fsck-like verbosity */
967c478bd9Sstevel@tonic-gate
97462be471Sceastha int
main(argc,argv)987c478bd9Sstevel@tonic-gate main(argc, argv)
99462be471Sceastha int argc;
1007c478bd9Sstevel@tonic-gate char *argv[];
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate struct stat statbuf;
1037c478bd9Sstevel@tonic-gate struct tab *tabptr;
1047c478bd9Sstevel@tonic-gate int i;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate (void) strcpy(Progname, "uucheck");
1077c478bd9Sstevel@tonic-gate while ((i = getopt(argc, argv, "vx:")) != EOF) {
1087c478bd9Sstevel@tonic-gate switch(i){
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate case 'v':
1117c478bd9Sstevel@tonic-gate verbose++;
1127c478bd9Sstevel@tonic-gate break;
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate case 'x':
1157c478bd9Sstevel@tonic-gate Debug = atoi(optarg);
1167c478bd9Sstevel@tonic-gate if (Debug <= 0)
1177c478bd9Sstevel@tonic-gate Debug = 1;
1187c478bd9Sstevel@tonic-gate #ifdef SMALL
1197c478bd9Sstevel@tonic-gate fprintf(stderr,
1207c478bd9Sstevel@tonic-gate "WARNING: uucheck built with SMALL flag defined -- no debug info available\n");
1217c478bd9Sstevel@tonic-gate #endif /* SMALL */
1227c478bd9Sstevel@tonic-gate break;
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate default:
1257c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\tusage: %s %s\n",
1267c478bd9Sstevel@tonic-gate Progname, USAGE);
1277c478bd9Sstevel@tonic-gate exit(1);
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate if (argc != optind) {
1317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\tusage: %s %s\n", Progname, USAGE);
1327c478bd9Sstevel@tonic-gate exit(1);
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate if (verbose) printf("*** uucheck: Check Required Files and Directories\n");
1367c478bd9Sstevel@tonic-gate for (tabptr = tab; tabptr->name != NULL; tabptr++) {
137*2a8bcb4eSToomas Soome if (stat(tabptr->value, &statbuf) < 0) {
1387c478bd9Sstevel@tonic-gate fprintf(stderr, "%s - ", tabptr->name);
1397c478bd9Sstevel@tonic-gate perror(tabptr->value);
1407c478bd9Sstevel@tonic-gate Uerrors++;
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate if (verbose) printf("*** uucheck: Directories Check Complete\n\n");
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate /* check the permissions file */
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate if (verbose) printf("*** uucheck: Check %s file\n", PERMISSIONS);
1497c478bd9Sstevel@tonic-gate Uerrors += checkPerm();
1507c478bd9Sstevel@tonic-gate if (verbose) printf("*** uucheck: %s Check Complete\n\n", PERMISSIONS);
1517c478bd9Sstevel@tonic-gate
152462be471Sceastha return(Uerrors);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate int
checkPerm()1567c478bd9Sstevel@tonic-gate checkPerm ()
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate int type;
1597c478bd9Sstevel@tonic-gate int error=0;
1607c478bd9Sstevel@tonic-gate char defaults[BUFSIZ];
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate for (type=0; type<2; type++) {
1637c478bd9Sstevel@tonic-gate /* type = 0 for LOGNAME, 1 for MACHINE */
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate if (verbose) printf("** %s \n\n",
1667c478bd9Sstevel@tonic-gate type == U_MACHINE
1677c478bd9Sstevel@tonic-gate ?"MACHINE PHASE (when we call or execute their uux requests)"
1687c478bd9Sstevel@tonic-gate :"LOGNAME PHASE (when they call us)" );
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate Fp = fopen(PERMISSIONS, "r");
1717c478bd9Sstevel@tonic-gate if (Fp == NULL) {
1727c478bd9Sstevel@tonic-gate if (verbose) printf("can't open %s\n", PERMISSIONS);
1737c478bd9Sstevel@tonic-gate exit(1);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate for (;;) {
1777c478bd9Sstevel@tonic-gate if (parse_tokens(_Flds, NULL) != 0) {
1787c478bd9Sstevel@tonic-gate fclose(Fp);
1797c478bd9Sstevel@tonic-gate break;
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate if (_Flds[type] == NULL)
1827c478bd9Sstevel@tonic-gate continue;
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate /* XXX - need to reset defaults here */
1857c478bd9Sstevel@tonic-gate fillFlds();
1867c478bd9Sstevel@tonic-gate /* if no ReadPath set num to 1--Path already set */
1877c478bd9Sstevel@tonic-gate fillList(U_READPATH, _RPaths);
1887c478bd9Sstevel@tonic-gate fillList(U_WRITEPATH, _WPaths);
1897c478bd9Sstevel@tonic-gate fillList(U_NOREADPATH, _NoRPaths);
1907c478bd9Sstevel@tonic-gate fillList(U_NOWRITEPATH, _NoWPaths);
1917c478bd9Sstevel@tonic-gate if (_Flds[U_COMMANDS] == NULL) {
1927c478bd9Sstevel@tonic-gate strcpy(defaults, DEFAULTCMDS);
1937c478bd9Sstevel@tonic-gate _Flds[U_COMMANDS] = defaults;
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate fillList(U_COMMANDS, _Commands);
1967c478bd9Sstevel@tonic-gate error += outLine(type);
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate return(error);
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate int
outLine(type)2047c478bd9Sstevel@tonic-gate outLine(type)
2057c478bd9Sstevel@tonic-gate int type;
2067c478bd9Sstevel@tonic-gate {
207462be471Sceastha int i;
208462be471Sceastha char *p;
2097c478bd9Sstevel@tonic-gate char *arg, cmd[BUFSIZ];
2107c478bd9Sstevel@tonic-gate int error = 0;
2117c478bd9Sstevel@tonic-gate char myname[MAXBASENAME+1];
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate if (_Flds[type][0] == 0)
2147c478bd9Sstevel@tonic-gate return(0);
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate if (type == U_LOGNAME) { /* for LOGNAME */
2177c478bd9Sstevel@tonic-gate p = _Flds[U_LOGNAME];
2187c478bd9Sstevel@tonic-gate if (verbose) printf("When a system logs in as: ");
2197c478bd9Sstevel@tonic-gate while (*p != '\0') {
2207c478bd9Sstevel@tonic-gate p = nextarg(p, &arg);
2217c478bd9Sstevel@tonic-gate if (verbose) printf("(%s) ", arg);
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate if (callBack()) {
2267c478bd9Sstevel@tonic-gate if (verbose) printf("\tWe will call them back.\n\n");
2277c478bd9Sstevel@tonic-gate return(0);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate else { /* MACHINE */
2317c478bd9Sstevel@tonic-gate p = _Flds[U_MACHINE];
2327c478bd9Sstevel@tonic-gate if (verbose) printf("When we call system(s): ");
2337c478bd9Sstevel@tonic-gate while (*p != '\0') {
2347c478bd9Sstevel@tonic-gate p = nextarg(p, &arg);
2357c478bd9Sstevel@tonic-gate if (verbose) printf("(%s) ", arg);
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate if (verbose) printf("\tWe %s allow them to request files.\n",
2427c478bd9Sstevel@tonic-gate requestOK()? "DO" : "DO NOT");
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate if (type == U_LOGNAME) {
2457c478bd9Sstevel@tonic-gate if (verbose) printf("\tWe %s send files queued for them on this call.\n",
2467c478bd9Sstevel@tonic-gate switchRole()? "WILL" : "WILL NOT");
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate if (verbose) printf("\tThey can send files to\n");
2507c478bd9Sstevel@tonic-gate if (_Flds[U_WRITEPATH] == NULL) {
2517c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s (DEFAULT)\n", Pubdir);
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate else {
2547c478bd9Sstevel@tonic-gate for (i=0; _WPaths[i] != NULL; i++)
2557c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s\n", _WPaths[i]);
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate if (_Flds[U_NOWRITEPATH] != NULL) {
2597c478bd9Sstevel@tonic-gate if (verbose) printf("\tExcept\n");
2607c478bd9Sstevel@tonic-gate for (i=0; _NoWPaths[i] != NULL; i++)
2617c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s\n", _NoWPaths[i]);
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate if (verbose) {
2657c478bd9Sstevel@tonic-gate if (noSpool())
2667c478bd9Sstevel@tonic-gate (void) printf("\tSent files will be created directly in the target directory.\n");
2677c478bd9Sstevel@tonic-gate else {
2687c478bd9Sstevel@tonic-gate (void) printf("\tSent files will be created in %s\n", SPOOL);
2697c478bd9Sstevel@tonic-gate (void) printf("\t before they are copied to the target directory.\n");
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate if (requestOK()) {
2747c478bd9Sstevel@tonic-gate if (verbose) printf("\tThey can request files from\n");
2757c478bd9Sstevel@tonic-gate if (_Flds[U_READPATH] == NULL) {
2767c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s (DEFAULT)\n", Pubdir);
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate else {
2797c478bd9Sstevel@tonic-gate for (i=0; _RPaths[i] != NULL; i++)
2807c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s\n", _RPaths[i]);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate if (_Flds[U_NOREADPATH] != NULL) {
2847c478bd9Sstevel@tonic-gate if (verbose) printf("\tExcept\n");
2857c478bd9Sstevel@tonic-gate for (i=0; _NoRPaths[i] != NULL; i++)
2867c478bd9Sstevel@tonic-gate if (verbose) printf("\t %s\n", _NoRPaths[i]);
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate myName(myname);
2917c478bd9Sstevel@tonic-gate if (verbose) printf("\tMyname for the conversation will be %s.\n",
2927c478bd9Sstevel@tonic-gate myname);
2937c478bd9Sstevel@tonic-gate if (verbose) printf("\tPUBDIR for the conversation will be %s.\n",
2947c478bd9Sstevel@tonic-gate Pubdir);
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate if (type == U_MACHINE) {
2997c478bd9Sstevel@tonic-gate if (verbose) printf("Machine(s): ");
3007c478bd9Sstevel@tonic-gate p = _Flds[U_MACHINE];
3017c478bd9Sstevel@tonic-gate while (*p != '\0') {
3027c478bd9Sstevel@tonic-gate p = nextarg(p, &arg);
3037c478bd9Sstevel@tonic-gate if (verbose) printf("(%s) ", arg);
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate if (verbose) printf("\nCAN execute the following commands:\n");
3067c478bd9Sstevel@tonic-gate for (i=0; _Commands[i] != NULL; i++) {
3077c478bd9Sstevel@tonic-gate if (cmdOK(BASENAME(_Commands[i], '/'), cmd) == FALSE) {
3087c478bd9Sstevel@tonic-gate if (verbose) printf("Software Error in permission.c\n");
3097c478bd9Sstevel@tonic-gate error++;
3107c478bd9Sstevel@tonic-gate }
3117c478bd9Sstevel@tonic-gate if (verbose) printf("command (%s), fullname (%s)\n",
3127c478bd9Sstevel@tonic-gate BASENAME(_Commands[i], '/'), cmd);
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate if (verbose) printf("\n");
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate return(error);
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate void
cleanup(s)3217c478bd9Sstevel@tonic-gate cleanup(s)
3227c478bd9Sstevel@tonic-gate int s;
3237c478bd9Sstevel@tonic-gate {
3247c478bd9Sstevel@tonic-gate exit(s);
3257c478bd9Sstevel@tonic-gate }
326