diff options
author | kris <kris@FreeBSD.org> | 2001-10-01 06:22:53 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 2001-10-01 06:22:53 +0000 |
commit | ebde71313f25e6c00554d63efdb7e13e7ec8da0f (patch) | |
tree | cf5a73cdbdc325eb67758fae618b870f0530f779 /gnu/libexec/uucp/libunix | |
parent | 5a5b9f79f48be499ceca11f3d54c0525935b9ac1 (diff) | |
download | FreeBSD-src-ebde71313f25e6c00554d63efdb7e13e7ec8da0f.zip FreeBSD-src-ebde71313f25e6c00554d63efdb7e13e7ec8da0f.tar.gz |
Phase I of UUCP migration to ports. This leaves behind a minimal build
environment for cu, which is still useful.
Diffstat (limited to 'gnu/libexec/uucp/libunix')
58 files changed, 4 insertions, 9059 deletions
diff --git a/gnu/libexec/uucp/libunix/MANIFEST b/gnu/libexec/uucp/libunix/MANIFEST deleted file mode 100644 index 342650a..0000000 --- a/gnu/libexec/uucp/libunix/MANIFEST +++ /dev/null @@ -1,84 +0,0 @@ -Makefile.in -MANIFEST -access.c -addbas.c -app3.c -app4.c -basnam.c -bytfre.c -chmod.c -cohtty.c -corrup.c -cusub.c -cwd.c -detach.c -dirent.c -dup2.c -efopen.c -epopen.c -exists.c -failed.c -filnam.c -fsusg.c -fsusg.h -ftw.c -getcwd.c -indir.c -init.c -isdir.c -isfork.c -iswait.c -jobid.c -lcksys.c -link.c -locfil.c -lock.c -loctim.c -mail.c -mkdir.c -mkdirs.c -mode.c -move.c -opensr.c -pause.c -picksb.c -pipe.c -portnm.c -priv.c -proctm.c -recep.c -remove.c -rename.c -rmdir.c -run.c -seq.c -serial.c -signal.c -sindir.c -size.c -sleep.c -splcmd.c -splnam.c -spool.c -spawn.c -srmdir.c -statsb.c -status.c -strerr.c -sync.c -tcp.c -time.c -tli.c -tmpfil.c -trunc.c -uacces.c -ufopen.c -uid.c -ultspl.c -unknwn.c -uuto.c -walk.c -wldcrd.c -work.c -xqtfil.c -xqtsub.c diff --git a/gnu/libexec/uucp/libunix/Makefile b/gnu/libexec/uucp/libunix/Makefile index 750521e..a5d506f 100644 --- a/gnu/libexec/uucp/libunix/Makefile +++ b/gnu/libexec/uucp/libunix/Makefile @@ -2,16 +2,10 @@ # $FreeBSD$ LIB= unix -SRCS = access.c addbas.c app3.c app4.c basnam.c bytfre.c corrup.c \ - chmod.c cohtty.c cusub.c cwd.c detach.c efopen.c epopen.c \ - exists.c failed.c filnam.c fsusg.c indir.c init.c isdir.c \ - isfork.c iswait.c jobid.c lcksys.c link.c locfil.c lock.c \ - loctim.c mail.c mkdirs.c mode.c move.c opensr.c pause.c \ - picksb.c pipe.c portnm.c priv.c proctm.c recep.c run.c seq.c \ - serial.c signal.c sindir.c size.c sleep.c spawn.c splcmd.c \ - splnam.c spool.c srmdir.c statsb.c status.c sync.c tcp.c \ - time.c tli.c tmpfil.c trunc.c uacces.c ufopen.c uid.c ultspl.c \ - unknwn.c uuto.c walk.c wldcrd.c work.c xqtfil.c xqtsub.c ftw.c +SRCS= basnam.c cusub.c efopen.c epopen.c init.c isdir.c isfork.c \ + iswait.c lock.c loctim.c mail.c mkdirs.c pause.c pipe.c \ + portnm.c proctm.c serial.c signal.c sindir.c sleep.c spawn.c \ + sync.c tcp.c time.c ufopen.c uid.c CFLAGS+= -I$(.CURDIR)/../common_sources \ -DOWNER=\"$(owner)\" -DSBINDIR=\"$(libxdir)\" diff --git a/gnu/libexec/uucp/libunix/access.c b/gnu/libexec/uucp/libunix/access.c deleted file mode 100644 index c2c0eef..0000000 --- a/gnu/libexec/uucp/libunix/access.c +++ /dev/null @@ -1,83 +0,0 @@ -/* access.c - Check access to files by the user and by the daemon. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -/* See if the user has access to a file, to prevent the setuid uucp - and uux programs handing out unauthorized access. */ - -boolean -fsysdep_access (zfile) - const char *zfile; -{ - if (access (zfile, R_OK) == 0) - return TRUE; - ulog (LOG_ERROR, "%s: %s", zfile, strerror (errno)); - return FALSE; -} - -/* See if the daemon has access to a file. This is called if a file - is not being transferred to the spool directory, since if the - daemon does not have access the later transfer will fail. We - assume that the daemon will have the same euid (or egid) as the one - we are running under. If our uid (gid) and euid (egid) are the - same, we assume that we have access. Note that is not important - for security, since the check will be (implicitly) done again when - the daemon tries to transfer the file. This routine should work - whether the UUCP programs are installed setuid or setgid. */ - -boolean -fsysdep_daemon_access (zfile) - const char *zfile; -{ - struct stat s; - uid_t ieuid, iuid, iegid, igid; - boolean fok; - - ieuid = geteuid (); - if (ieuid == 0) - return TRUE; - iuid = getuid (); - iegid = getegid (); - igid = getgid (); - - /* If our effective uid and gid are the same as our real uid and - gid, we assume the daemon will have access to the file. */ - if (ieuid == iuid && iegid == igid) - return TRUE; - - if (stat ((char *) zfile, &s) != 0) - { - ulog (LOG_ERROR, "stat (%s): %s", zfile, strerror (errno)); - return FALSE; - } - - /* If our euid is not our uid, but it is the file's uid, see if the - owner has read access. Otherwise, if our egid is not our gid, - but it is the file's gid, see if the group has read access. - Otherwise, see if the world has read access. We know from the - above check that at least one of our euid and egid are different, - so that is the only one we want to check. This check could fail - if the UUCP programs were both setuid and setgid, but why would - they be? */ - if (ieuid != iuid && ieuid == s.st_uid) - fok = (s.st_mode & S_IRUSR) != 0; - else if (iegid != igid && iegid == s.st_gid) - fok = (s.st_mode & S_IRGRP) != 0; - else - fok = (s.st_mode & S_IROTH) != 0; - - if (! fok) - { - ulog (LOG_ERROR, "%s: cannot be read by daemon", zfile); - return FALSE; - } - - return TRUE; -} diff --git a/gnu/libexec/uucp/libunix/addbas.c b/gnu/libexec/uucp/libunix/addbas.c deleted file mode 100644 index 8597918..0000000 --- a/gnu/libexec/uucp/libunix/addbas.c +++ /dev/null @@ -1,50 +0,0 @@ -/* addbas.c - If we have a directory, add in a base name. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -/* If we have a directory, add a base name. */ - -char * -zsysdep_add_base (zfile, zname) - const char *zfile; - const char *zname; -{ - size_t clen; - const char *zlook; - char *zfree; - char *zret; - -#if DEBUG > 0 - if (*zfile != '/') - ulog (LOG_FATAL, "zsysdep_add_base: %s: Can't happen", zfile); -#endif - - clen = strlen (zfile); - - if (zfile[clen - 1] != '/') - { - if (! fsysdep_directory (zfile)) - return zbufcpy (zfile); - zfree = NULL; - } - else - { - /* Trim out the trailing '/'. */ - zfree = zbufcpy (zfile); - zfree[clen - 1] = '\0'; - zfile = zfree; - } - - zlook = strrchr (zname, '/'); - if (zlook != NULL) - zname = zlook + 1; - - zret = zsysdep_in_dir (zfile, zname); - ubuffree (zfree); - return zret; -} diff --git a/gnu/libexec/uucp/libunix/app3.c b/gnu/libexec/uucp/libunix/app3.c deleted file mode 100644 index f3c3555..0000000 --- a/gnu/libexec/uucp/libunix/app3.c +++ /dev/null @@ -1,32 +0,0 @@ -/* app3.c - Stick two directories and a file name together. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" - -char * -zsappend3 (zdir1, zdir2, zfile) - const char *zdir1; - const char *zdir2; - const char *zfile; -{ - size_t cdir1, cdir2, cfile; - char *zret; - - cdir1 = strlen (zdir1); - cdir2 = strlen (zdir2); - cfile = strlen (zfile); - zret = zbufalc (cdir1 + cdir2 + cfile + 3); - if (cdir1 == 1 && *zdir1 == '/') - cdir1 = 0; - else - memcpy (zret, zdir1, cdir1); - memcpy (zret + cdir1 + 1, zdir2, cdir2); - memcpy (zret + cdir1 + cdir2 + 2, zfile, cfile); - zret[cdir1] = '/'; - zret[cdir1 + cdir2 + 1] = '/'; - zret[cdir1 + cdir2 + cfile + 2] = '\0'; - return zret; -} diff --git a/gnu/libexec/uucp/libunix/app4.c b/gnu/libexec/uucp/libunix/app4.c deleted file mode 100644 index d3a243f..0000000 --- a/gnu/libexec/uucp/libunix/app4.c +++ /dev/null @@ -1,36 +0,0 @@ -/* app4.c - Stick three directories and a file name together. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" - -char * -zsappend4 (zdir1, zdir2, zdir3, zfile) - const char *zdir1; - const char *zdir2; - const char *zdir3; - const char *zfile; -{ - size_t cdir1, cdir2, cdir3, cfile; - char *zret; - - cdir1 = strlen (zdir1); - cdir2 = strlen (zdir2); - cdir3 = strlen (zdir3); - cfile = strlen (zfile); - zret = zbufalc (cdir1 + cdir2 + cdir3 + cfile + 4); - if (cdir1 == 1 && *zdir1 == '/') - cdir1 = 0; - else - memcpy (zret, zdir1, cdir1); - memcpy (zret + cdir1 + 1, zdir2, cdir2); - memcpy (zret + cdir1 + cdir2 + 2, zdir3, cdir3); - memcpy (zret + cdir1 + cdir2 + cdir3 + 3, zfile, cfile); - zret[cdir1] = '/'; - zret[cdir1 + cdir2 + 1] = '/'; - zret[cdir1 + cdir2 + cdir3 + 2] = '/'; - zret[cdir1 + cdir2 + cdir3 + cfile + 3] = '\0'; - return zret; -} diff --git a/gnu/libexec/uucp/libunix/bytfre.c b/gnu/libexec/uucp/libunix/bytfre.c deleted file mode 100644 index 3091e7a..0000000 --- a/gnu/libexec/uucp/libunix/bytfre.c +++ /dev/null @@ -1,27 +0,0 @@ -/* bytfre.c - Get the number of bytes free on a file system. */ - -#include "uucp.h" - -#include "system.h" -#include "sysdep.h" -#include "fsusg.h" - -#if HAVE_LIMITS_H -#include <limits.h> -#else -#define LONG_MAX 2147483647 -#endif - -long -csysdep_bytes_free (zfile) - const char *zfile; -{ - struct fs_usage s; - - if (get_fs_usage ((char *) zfile, (char *) NULL, &s) < 0) - return -1; - if (s.fsu_bavail >= LONG_MAX / (long) 512) - return LONG_MAX; - return s.fsu_bavail * (long) 512; -} diff --git a/gnu/libexec/uucp/libunix/chmod.c b/gnu/libexec/uucp/libunix/chmod.c deleted file mode 100644 index cf69f3e..0000000 --- a/gnu/libexec/uucp/libunix/chmod.c +++ /dev/null @@ -1,25 +0,0 @@ -/* chmod.c - Change the mode of a file. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -/* Change the mode of a file. */ - -boolean -fsysdep_change_mode (zfile, imode) - const char *zfile; - unsigned int imode; -{ - if (chmod ((char *) zfile, imode) < 0) - { - ulog (LOG_ERROR, "chmod (%s): %s", zfile, strerror (errno)); - return FALSE; - } - return TRUE; -} diff --git a/gnu/libexec/uucp/libunix/cohtty.c b/gnu/libexec/uucp/libunix/cohtty.c deleted file mode 100644 index 9cbe220..0000000 --- a/gnu/libexec/uucp/libunix/cohtty.c +++ /dev/null @@ -1,261 +0,0 @@ -/* Coherent tty locking support. This file was contributed by Bob - Hemedinger <bob@dalek.mwc.com> of Mark Williams Corporation and - lightly edited by Ian Lance Taylor. */ - -/* $FreeBSD$ */ - -/* The bottom part of this file is lock.c. - * This is a hacked lock.c. A full lock.c can be found in the libmisc sources - * under /usr/src/misc.tar.Z. - * - * These are for checking for the existence of locks: - * lockexist(resource) - * lockttyexist(ttyname) - */ - -#include "uucp.h" - -#if HAVE_COHERENT_LOCKFILES - -/* cohtty.c: Given a serial device name, read /etc/ttys and determine if - * the device is already enabled. If it is, disable the - * device and return a string so that it can be re-enabled - * at the completion of the uucico session as part of the - * function that resets the serial device before uucico - * terminates. - * - */ - -#include "uudefs.h" -#include "sysdep.h" - -#include <ctype.h> -#include <access.h> -#include <paths.h> - -/* fscoherent_disable_tty() is a COHERENT specific function. It takes the name - * of a serial device and then scans /etc/ttys for a match. If it finds one, - * it checks the first field of the entry. If it is a '1', then it will disable - * the port and set a flag. The flag will be checked later when uucico wants to - * reset the serial device to see if the device needs to be re-enabled. - */ - -/* May 10, 1993: This function will always return true for the following - * reasons: - * 1) lock files have already been dealt with - * 2) if someone else already has the port open, uucico should fail anyways - * 3) Coherent's disable command return can return '0' or '1', but will - * succeed in any event. - * 4) It doesn't matter if there is a ttys entry for the port in question. - * /etc/ttys generally only lists devices that MAY be enabled for logins. - * If a device will never be used for logins, then there may not be a - * ttys entry, in which case, disable won't be called anyways. - * ---bob@mwc.com - */ - -boolean -fscoherent_disable_tty (zdevice, pzenable) - const char *zdevice; - char **pzenable; -{ - - -struct ttyentry{ /* this is an /etc/ttys entry */ - char enable_disable[1]; - char remote_local[1]; - char baud_rate[1]; - char tty_device[16]; -}; - -struct ttyentry sought_tty; - -int x,y,z; /* dummy */ -FILE * infp; /* this will point to /etc/ttys */ -char disable_command[66]; /* this will be the disable command - * passed to the system. - */ -char enable_device[16]; /* this will hold our device name - * to enable. - */ - - *pzenable = NULL; - - strcpy(enable_device,""); /* initialize our strings */ - strcpy(sought_tty.tty_device,""); - - if( (infp = fopen("/etc/ttys","r")) == NULL){ - ulog(LOG_ERROR,"Error: check_disable_tty: failed to open /etc/ttys\n"); - return FALSE; - } - - while (NULL !=(fgets(&sought_tty, sizeof (sought_tty), infp ))){ - sought_tty.tty_device[strlen(sought_tty.tty_device) -1] = '\0'; - strcpy(enable_device,sought_tty.tty_device); - - /* we must strip away the suffix to the com port name or - * we will never find a match. For example, if we are passed - * /dev/com4l to call out with and the port is already enabled, - * 9/10 the port enabled will be com4r. After we strip away the - * suffix of the port found in /etc/ttys, then we can test - * if the base port name appears in the device name string - * passed to us. - */ - - for(z = strlen(sought_tty.tty_device) ; z > 0 ; z--){ - if(isdigit(sought_tty.tty_device[z])){ - break; - } - } - y = strlen(sought_tty.tty_device); - for(x = z+1 ; x <= y; x++){ - sought_tty.tty_device[x] = '\0'; - } - - -/* ulog(LOG_NORMAL,"found device {%s}\n",sought_tty.tty_device); */ - if(strstr(zdevice, sought_tty.tty_device)){ - if(sought_tty.enable_disable[0] == '1'){ - ulog(LOG_NORMAL, "coh_tty: Disabling device %s {%s}\n", - zdevice, sought_tty.tty_device); - sprintf(disable_command, "/etc/disable %s",enable_device); - { - pid_t ipid; - const char *azargs[3]; - int aidescs[3]; - - azargs[0] = "/etc/disable"; - azargs[1] = enable_device; - azargs[2] = NULL; - aidescs[0] = SPAWN_NULL; - aidescs[1] = SPAWN_NULL; - aidescs[2] = SPAWN_NULL; - ipid = ixsspawn (azargs, aidescs, TRUE, - FALSE, - (const char *) NULL, TRUE, - TRUE, - (const char *) NULL, - (const char *) NULL, - (const char *) NULL); - if (ipid < 0) - x = 1; - else - x = ixswait ((unsigned long) ipid, - (const char *) NULL); - } - *pzenable = zbufalc (sizeof _PATH_DEV - + strlen (enable_device)); - sprintf(*pzenable,"%s%s",_PATH_DEV, - enable_device); -/* ulog(LOG_NORMAL,"Enable string is {%s}",*pzenable); */ - return TRUE; - }else{ - /* device not enabled */ - return TRUE; - } - } - } - return TRUE; /* no ttys entry found */ -} - -/* The following is COHERENT 4.0 specific. It is used to test for any - * existing lockfiles on a port which would have been created by init - * when a user logs into a port. - */ - -#define LOCKSIG 9 /* Significant Chars of Lockable Resources. */ -#define LOKFLEN 64 /* Max Length of UUCP Lock File Name. */ - -#define LOCKPRE "LCK.." -#define PIDLEN 6 /* Maximum length of string representing a pid. */ - -#ifndef LOCKDIR -#define LOCKDIR SPOOLDIR -#endif - -/* There is a special version of DEVMASK for the PE multiport driver - * because of the peculiar way it uses the minor device number. For - * all other drivers, the lower 5 bits describe the physical port-- - * the upper 3 bits give attributes for the port. - */ - -#define PE_DRIVER 21 /* Major device number for the PE driver. */ -#define PE_DEVMASK 0x3f /* PE driver minor device mask. */ -#define DEVMASK 0x1f /* Minor device mask. */ - -/* - * Generates a resource name for locking, based on the major number - * and the lower 4 bits of the minor number of the tty device. - * - * Builds the name in buff as two "." separated decimal numbers. - * Returns NULL on failure, buff on success. - */ -static char * -gen_res_name(path, buff) -char *path; -char *buff; -{ - struct stat sbuf; - int status; - - if (0 != (status = stat(path, &sbuf))) { - /* Can't stat the file. */ - return (NULL); - } - - if (PE_DRIVER == major(sbuf.st_rdev)) { - sprintf(buff, "%d.%d", major(sbuf.st_rdev), - PE_DEVMASK & minor(sbuf.st_rdev)); - } else { - sprintf(buff, "%d.%d", major(sbuf.st_rdev), - DEVMASK & minor(sbuf.st_rdev)); - } - - return(buff); -} /* gen_res_name */ - -/* - * lockexist(resource) char *resource; - * - * Test for existance of a lock on the given resource. - * - * Returns: (1) Resource is locked. - * (0) Resource is not locked. - */ - -static boolean -lockexist(resource) -const char *resource; -{ - char lockfn[LOKFLEN]; - - if ( resource == NULL ) - return(0); - sprintf(lockfn, "%s/%s%.*s", LOCKDIR, LOCKPRE, LOCKSIG, resource); - - return (!access(lockfn, AEXISTS)); -} /* lockexist() */ - -/* - * lockttyexist(ttyname) char *ttyname; - * - * Test for existance of a lock on the given tty. - * - * Returns: (1) Resource is locked. - * (0) Resource is not locked. - */ -boolean -lockttyexist(ttyn) -const char *ttyn; -{ - char resource[LOKFLEN]; - char filename[LOKFLEN]; - - sprintf(filename, "%s%s", _PATH_DEV, ttyn); - if (NULL == gen_res_name(filename, resource)){ - return(0); /* Non-existent tty can not be locked :-) */ - } - - return(lockexist(resource)); -} /* lockttyexist() */ - -#endif /* HAVE_COHERENT_LOCKFILES */ diff --git a/gnu/libexec/uucp/libunix/corrup.c b/gnu/libexec/uucp/libunix/corrup.c deleted file mode 100644 index 87f19e6..0000000 --- a/gnu/libexec/uucp/libunix/corrup.c +++ /dev/null @@ -1,33 +0,0 @@ -/* corrup.c - Save a file in the .Corrupt directory. */ - -#include "uucp.h" - -#include "sysdep.h" -#include "uudefs.h" -#include "system.h" - -char * -zsysdep_save_corrupt_file (zfile) - const char *zfile; -{ - const char *zslash; - char *zto; - - zslash = strrchr (zfile, '/'); - if (zslash == NULL) - zslash = zfile; - else - ++zslash; - - zto = zsappend3 (zSspooldir, CORRUPTDIR, zslash); - - if (! fsysdep_move_file (zfile, zto, TRUE, FALSE, FALSE, - (const char *) NULL)) - { - ubuffree (zto); - return NULL; - } - - return zto; -} diff --git a/gnu/libexec/uucp/libunix/cwd.c b/gnu/libexec/uucp/libunix/cwd.c deleted file mode 100644 index 71d05d1..0000000 --- a/gnu/libexec/uucp/libunix/cwd.c +++ /dev/null @@ -1,58 +0,0 @@ -/* cwd.c - Routines dealing with the current working directory. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -/* See whether running this file through zsysdep_add_cwd would require - knowing the current working directory. This is used to avoid - determining the cwd if it will not be needed. */ - -boolean -fsysdep_needs_cwd (zfile) - const char *zfile; -{ - return *zfile != '/' && *zfile != '~'; -} - -/* Expand a local file, putting relative pathnames in the current - working directory. Note that ~/file is placed in the public - directory, rather than in the user's home directory. This is - consistent with other UUCP packages. */ - -char * -zsysdep_local_file_cwd (zfile, zpubdir, pfbadname) - const char *zfile; - const char *zpubdir; - boolean *pfbadname; -{ - if (pfbadname != NULL) - *pfbadname = FALSE; - if (*zfile == '/') - return zbufcpy (zfile); - else if (*zfile == '~') - return zsysdep_local_file (zfile, zpubdir, pfbadname); - else - return zsysdep_add_cwd (zfile); -} - -/* Add the current working directory to a remote file name. */ - -char * -zsysdep_add_cwd (zfile) - const char *zfile; -{ - if (*zfile == '/' || *zfile == '~') - return zbufcpy (zfile); - - if (zScwd == NULL) - { - ulog (LOG_ERROR, "Can't determine current directory"); - return NULL; - } - - return zsysdep_in_dir (zScwd, zfile); -} diff --git a/gnu/libexec/uucp/libunix/detach.c b/gnu/libexec/uucp/libunix/detach.c deleted file mode 100644 index ad753b4..0000000 --- a/gnu/libexec/uucp/libunix/detach.c +++ /dev/null @@ -1,184 +0,0 @@ -/* detach.c - Detach from the controlling terminal. - - Copyright (C) 1992, 1993, 1995 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -/* $FreeBSD$ */ - -#include "uucp.h" - -#include "uudefs.h" -#include "system.h" -#include "sysdep.h" - -#include <errno.h> -#include <paths.h> - -#if HAVE_SYS_IOCTL_H -#include <sys/ioctl.h> -#endif - -#ifdef TIOCNOTTY -#define HAVE_TIOCNOTTY 1 -#else -#define HAVE_TIOCNOTTY 0 -#endif - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -#ifndef O_RDONLY -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#endif - -#if HAVE_BROKEN_SETSID -#undef HAVE_SETSID -#define HAVE_SETSID 0 -#endif - -/* Detach from the controlling terminal. This is called by uucico if - it is calling out to another system, so that it can receive SIGHUP - signals from the port it calls out on. It is also called by uucico - just before it starts uuxqt, so that uuxqt is completely - independent of the terminal. */ - -void -usysdep_detach () -{ - pid_t igrp; - - /* Make sure that we can open the log file. We do this now so that, - if we can't, a message will be written to stderr. After we leave - this routine, stderr will be closed. */ - ulog (LOG_NORMAL, (const char *) NULL); - - /* Make sure we are not a process group leader. */ -#if HAVE_BSD_PGRP - igrp = getpgrp (0); -#else - igrp = getpgrp (); -#endif - - if (igrp == getpid ()) - { - boolean fignored; - pid_t ipid; - - /* Ignore SIGHUP, since our process group leader is about to - die. */ - usset_signal (SIGHUP, SIG_IGN, FALSE, &fignored); - - ipid = ixsfork (); - if (ipid < 0) - ulog (LOG_FATAL, "fork: %s", strerror (errno)); - - if (ipid != 0) - _exit (EXIT_SUCCESS); - - /* We'll always wind up as a child of process number 1, right? - Right? We have to wait for our parent to die before - reenabling SIGHUP. */ - while (getppid () != 1) - sleep (1); - - ipid = getpid (); - ulog_id (ipid); - - /* Restore SIGHUP catcher if it wasn't being ignored. */ - if (! fignored) - usset_signal (SIGHUP, ussignal, TRUE, (boolean *) NULL); - - DEBUG_MESSAGE2 (DEBUG_PORT, - "usysdep_detach: Forked; old PID %ld, new pid %ld", - (long) igrp, (long) ipid); - } - -#if ! HAVE_SETSID && HAVE_TIOCNOTTY - /* Lose the original controlling terminal as well as our process - group. */ - { - int o; - - o = open ((char *) _PATH_TTY, O_RDONLY); - if (o >= 0) - { - (void) ioctl (o, TIOCNOTTY, (char *) NULL); - (void) close (o); - } - } -#endif /* ! HAVE_SETSID && HAVE_TIOCNOTTY */ - - /* Close stdin, stdout and stderr and reopen them on /dev/null, to - make sure we have no connection at all to the terminal. */ - (void) close (0); - (void) close (1); - (void) close (2); - if (open ((char *) _PATH_DEVNULL, O_RDONLY) != 0 - || open ((char *) _PATH_DEVNULL, O_WRONLY) != 1 - || open ((char *) _PATH_DEVNULL, O_WRONLY) != 2) - ulog (LOG_FATAL, "open (%s): %s", _PATH_DEVNULL, strerror (errno)); - -#if HAVE_SETSID - - /* Under POSIX the setsid call creates a new session for which we - are the process group leader. It also detaches us from our - controlling terminal. */ - if (setsid () < 0) - ulog (LOG_ERROR, "setsid: %s", strerror (errno)); - -#else /* ! HAVE_SETSID */ - -#if ! HAVE_SETPGRP - #error Cannot detach from controlling terminal -#endif - - /* If we don't have setsid, we must use setpgrp. On an old System V - system setpgrp will make us the leader of a new process group and - detach the controlling terminal. On an old BSD system the call - setpgrp (0, 0) will set our process group to 0 so that we can - acquire a new controlling terminal (TIOCNOTTY may or may not have - already done that anyhow). */ -#if HAVE_BSD_PGRP - if (setpgrp (0, 0) < 0) -#else - if (setpgrp () < 0) -#endif - { - /* Some systems seem to give EPERM errors inappropriately. */ - if (errno != EPERM) - ulog (LOG_ERROR, "setpgrp: %s", strerror (errno)); - } - -#endif /* ! HAVE_SETSID */ - - /* At this point we have completely detached from our controlling - terminal. The next terminal device we open will probably become - our controlling terminal. */ -} diff --git a/gnu/libexec/uucp/libunix/dirent.c b/gnu/libexec/uucp/libunix/dirent.c deleted file mode 100644 index 7ad0ec6..0000000 --- a/gnu/libexec/uucp/libunix/dirent.c +++ /dev/null @@ -1,123 +0,0 @@ -/* dirent.c - Replacements for opendir, readdir and closedir for the original - Unix filesystem only. - - Copyright (C) 1992 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "sysdep.h" - -#include <errno.h> - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -#ifndef O_RDONLY -#define O_RDONLY 0 -#endif - -#ifndef O_NOCTTY -#define O_NOCTTY 0 -#endif - -#ifndef FD_CLOEXEC -#define FD_CLOEXEC 1 -#endif - -/* Simple emulations of opendir/readdir/closedir for systems which - have the original format of Unix directories. It's probably better - to get Doug Gwyn's public domain set of emulation functions. */ - -DIR * -opendir (zdir) - const char *zdir; -{ - int o; - struct stat s; - DIR *qret; - - o = open ((char *) zdir, O_RDONLY | O_NOCTTY, 0); - if (o < 0) - return NULL; - if (fcntl (o, F_SETFD, fcntl (o, F_GETFD, 0) | FD_CLOEXEC) < 0 - || fstat (o, &s) < 0) - { - int isave; - - isave = errno; - (void) close (o); - errno = isave; - return NULL; - } - if (! S_ISDIR (s.st_mode)) - { - (void) close (o); - errno = ENOTDIR; - return NULL; - } - qret = (DIR *) xmalloc (sizeof (DIR)); - qret->o = o; - return qret; -} - -struct dirent * -readdir (q) - DIR *q; -{ - struct direct sdir; - int cgot; - - do - { - cgot = read (q->o, &sdir, sizeof (struct direct)); - if (cgot <= 0) - return NULL; - if (cgot != sizeof (struct direct)) - { - errno = ENOENT; - return NULL; - } - } - while (sdir.d_ino == 0); - - strncpy (q->s.d_name, sdir.d_name, DIRSIZ); - q->s.d_name[DIRSIZ] = '\0'; - return &q->s; -} - -int -closedir (q) - DIR *q; -{ - int o; - - o = q->o; - xfree (q); - return close (o); -} diff --git a/gnu/libexec/uucp/libunix/dup2.c b/gnu/libexec/uucp/libunix/dup2.c deleted file mode 100644 index a3fcea5..0000000 --- a/gnu/libexec/uucp/libunix/dup2.c +++ /dev/null @@ -1,69 +0,0 @@ -/* dup2.c - The Unix dup2 function, for systems which only have dup. - - Copyright (C) 1985, 1986, 1987, 1988, 1990 Free Software Foundation, Inc. - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" -#include "sysdep.h" - -#include <errno.h> - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -/* I basically took this from the emacs 18.57 distribution, although I - cleaned it up a bit and made it POSIX compliant. */ - -int -dup2 (oold, onew) - int oold; - int onew; -{ - if (oold == onew) - return onew; - (void) close (onew); - -#ifdef F_DUPFD - return fcntl (oold, F_DUPFD, onew); -#else - { - int onext, oret, isave; - - onext = dup (oold); - if (onext == onew) - return onext; - if (onext < 0) - return -1; - oret = dup2 (oold, onew); - isave = errno; - (void) close (onext); - errno = isave; - return oret; - } -#endif -} diff --git a/gnu/libexec/uucp/libunix/exists.c b/gnu/libexec/uucp/libunix/exists.c deleted file mode 100644 index 9473922..0000000 --- a/gnu/libexec/uucp/libunix/exists.c +++ /dev/null @@ -1,16 +0,0 @@ -/* exists.c - Check whether a file exists. */ - -#include "uucp.h" - -#include "sysdep.h" -#include "system.h" - -boolean -fsysdep_file_exists (zfile) - const char *zfile; -{ - struct stat s; - - return stat ((char *) zfile, &s) == 0; -} diff --git a/gnu/libexec/uucp/libunix/failed.c b/gnu/libexec/uucp/libunix/failed.c deleted file mode 100644 index 66c98a8..0000000 --- a/gnu/libexec/uucp/libunix/failed.c +++ /dev/null @@ -1,26 +0,0 @@ -/* failed.c - Save a file in the .Failed directory. */ - -#include "uucp.h" - -#include "sysdep.h" -#include "uudefs.h" -#include "system.h" - -char * -zsysdep_save_failed_file (zfile) - const char *zfile; -{ - char *zto; - - zto = zsappend3 (zSspooldir, FAILEDDIR, zfile); - - if (! fsysdep_move_file (zfile, zto, TRUE, FALSE, FALSE, - (const char *) NULL)) - { - ubuffree (zto); - return NULL; - } - - return zto; -} diff --git a/gnu/libexec/uucp/libunix/filnam.c b/gnu/libexec/uucp/libunix/filnam.c deleted file mode 100644 index 6f804bb..0000000 --- a/gnu/libexec/uucp/libunix/filnam.c +++ /dev/null @@ -1,584 +0,0 @@ -/* filnam.c - Get names to use for UUCP files. - - Copyright (C) 1991, 1992, 1993, 1995 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "uuconf.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -#ifndef O_RDONLY -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#endif - -#ifndef O_NOCTTY -#define O_NOCTTY 0 -#endif - -/* We need a definition for SEEK_SET. */ - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -/* We use POSIX style fcntl locks if they are available, unless - O_CREAT is not defined. We could use them in the latter case, but - the code would have to become more complex to avoid races - concerning the use of creat. It is very unlikely that there is any - system which does have POSIX style locking but does not have - O_CREAT. */ -#if ! HAVE_BROKEN_SETLKW -#ifdef F_SETLKW -#ifdef O_CREAT -#define USE_POSIX_LOCKS 1 -#endif -#endif -#endif -#ifndef USE_POSIX_LOCKS -#define USE_POSIX_LOCKS 0 -#endif - -/* External functions. */ -#ifndef lseek -extern off_t lseek (); -#endif - -#define ZCHARS \ - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" - -/* Local functions. */ - -static boolean fscmd_seq P((const char *zsystem, char *zseq)); -static char *zsfile_name P((int btype, const char *zsystem, - const char *zlocalname, int bgrade, - boolean fxqt, char *ztname, char *zdname, - char *zxname)); - -/* Get a new command sequence number (this is not a sequence number to - be used for communicating with another system, but a sequence - number to be used when generating the name of a command file). - The sequence number is placed into zseq, which should be five - characters long. */ - -static boolean -fscmd_seq (zsystem, zseq) - const char *zsystem; - char *zseq; -{ - int cdelay; - char *zfree; - const char *zfile; - int o; - boolean flockfile; - int i; - boolean fret; - - cdelay = 5; - -#if ! USE_POSIX_LOCKS - { - boolean ferr; - - /* Lock the sequence file. */ - while (! fsdo_lock ("LCK..SEQ", TRUE, &ferr)) - { - if (ferr || FGOT_SIGNAL ()) - return FALSE; - sleep (cdelay); - if (cdelay < 60) - ++cdelay; - } - } -#endif - - zfree = NULL; - -#if SPOOLDIR_V2 || SPOOLDIR_BSD42 || SPOOLDIR_BSD43 - zfile = "SEQF"; -#endif -#if SPOOLDIR_HDB || SPOOLDIR_SVR4 - zfree = zsysdep_in_dir (".Sequence", zsystem); - zfile = zfree; -#endif -#if SPOOLDIR_ULTRIX - if (! fsultrix_has_spool (zsystem)) - zfile = "sys/DEFAULT/.SEQF"; - else - { - zfree = zsappend3 ("sys", zsystem, ".SEQF"); - zfile = zfree; - } -#endif /* SPOOLDIR_ULTRIX */ -#if SPOOLDIR_TAYLOR - zfree = zsysdep_in_dir (zsystem, "SEQF"); - zfile = zfree; -#endif /* SPOOLDIR_TAYLOR */ - -#ifdef O_CREAT - o = open ((char *) zfile, O_RDWR | O_CREAT | O_NOCTTY, IPRIVATE_FILE_MODE); -#else - o = open ((char *) zfile, O_RDWR | O_NOCTTY); - if (o < 0 && errno == ENOENT) - { - o = creat ((char *) zfile, IPRIVATE_FILE_MODE); - if (o >= 0) - { - (void) close (o); - o = open ((char *) zfile, O_RDWR | O_NOCTTY); - } - } -#endif - - if (o < 0) - { - if (errno == ENOENT) - { - if (! fsysdep_make_dirs (zfile, FALSE)) - { -#if ! USE_POSIX_LOCKS - (void) fsdo_unlock ("LCK..SEQ", TRUE); -#endif - return FALSE; - } -#ifdef O_CREAT - o = open ((char *) zfile, - O_RDWR | O_CREAT | O_NOCTTY, - IPRIVATE_FILE_MODE); -#else - o = creat ((char *) zfile, IPRIVATE_FILE_MODE); - if (o >= 0) - { - (void) close (o); - o = open ((char *) zfile, O_RDWR | O_NOCTTY); - } -#endif - } - if (o < 0) - { - ulog (LOG_ERROR, "open (%s): %s", zfile, strerror (errno)); -#if ! USE_POSIX_LOCKS - (void) fsdo_unlock ("LCK..SEQ", TRUE); -#endif - return FALSE; - } - } - -#if ! USE_POSIX_LOCKS - flockfile = TRUE; -#else - { - struct flock slock; - - flockfile = FALSE; - - slock.l_type = F_WRLCK; - slock.l_whence = SEEK_SET; - slock.l_start = 0; - slock.l_len = 0; - while (fcntl (o, F_SETLKW, &slock) == -1) - { - boolean fagain; - - /* Some systems define F_SETLKW, but it does not work. We try - to catch those systems at runtime, and revert to using a - lock file. */ - if (errno == EINVAL) - { - boolean ferr; - - /* Lock the sequence file. */ - while (! fsdo_lock ("LCK..SEQ", TRUE, &ferr)) - { - if (ferr || FGOT_SIGNAL ()) - { - (void) close (o); - return FALSE; - } - sleep (cdelay); - if (cdelay < 60) - ++cdelay; - } - - flockfile = TRUE; - - break; - } - - fagain = FALSE; - if (errno == ENOMEM) - fagain = TRUE; -#ifdef ENOLCK - if (errno == ENOLCK) - fagain = TRUE; -#endif -#ifdef ENOSPC - if (errno == ENOSPC) - fagain = TRUE; -#endif - if (fagain) - { - sleep (cdelay); - if (cdelay < 60) - ++cdelay; - continue; - } - ulog (LOG_ERROR, "Locking %s: %s", zfile, strerror (errno)); - (void) close (o); - return FALSE; - } - } -#endif - - if (read (o, zseq, CSEQLEN) != CSEQLEN) - strcpy (zseq, "0000"); - zseq[CSEQLEN] = '\0'; - - /* We must add one to the sequence number and return the new value. - On Ultrix, arbitrary characters are allowed in the sequence - number. On other systems, the sequence number apparently must be - in hex. */ -#if SPOOLDIR_V2 || SPOOLDIR_BSD42 || SPOOLDIR_BSD43 || SPOOLDIR_HDB || SPOOLDIR_SVR4 - i = (int) strtol (zseq, (char **) NULL, 16); - ++i; - if (i > 0xffff) - i = 0; - /* The sprintf argument has CSEQLEN built into it. */ - sprintf (zseq, "%04x", (unsigned int) i); -#endif -#if SPOOLDIR_ULTRIX || SPOOLDIR_TAYLOR - for (i = CSEQLEN - 1; i >= 0; i--) - { - const char *zdig; - - zdig = strchr (ZCHARS, zseq[i]); - if (zdig == NULL || zdig[0] == '\0' || zdig[1] == '\0') - zseq[i] = '0'; - else - { - zseq[i] = zdig[1]; - break; - } - } -#endif /* SPOOLDIR_ULTRIX || SPOOLDIR_TAYLOR */ - - fret = TRUE; - - if (lseek (o, (off_t) 0, SEEK_SET) < 0 - || write (o, zseq, CSEQLEN) != CSEQLEN - || close (o) < 0) - { - ulog (LOG_ERROR, "lseek or write or close %s: %s", - zfile, strerror (errno)); - (void) close (o); - fret = FALSE; - } - - if (flockfile) - (void) fsdo_unlock ("LCK..SEQ", TRUE); - - ubuffree (zfree); - - return fret; -} - -/* Get the name of a command or data file for a remote system. The - btype argument should be C for a command file or D for a data file. - If the grade of a data file is X, it is assumed that this is going - to become an execute file on some other system. The zsystem - argument is the system that the file will be transferred to. The - ztname argument will be set to a file name that could be passed to - zsysdep_spool_file_name. The zdname argument, if not NULL, will be - set to a data file name appropriate for the remote system. The - zxname argument, if not NULL, will be set to the name of an execute - file on the remote system. None of the names will be more than 14 - characters long. */ - -/*ARGSUSED*/ -static char * -zsfile_name (btype, zsystem, zlocalname, bgrade, fxqt, ztname, zdname, zxname) - int btype; - const char *zsystem; - const char *zlocalname; - int bgrade; - boolean fxqt; - char *ztname; - char *zdname; - char *zxname; -{ - char abseq[CSEQLEN + 1]; - char absimple[11 + CSEQLEN]; - char *zname; - - if (zlocalname == NULL) - zlocalname = zSlocalname; - - while (TRUE) - { - if (! fscmd_seq (zsystem, abseq)) - return NULL; - - if (btype == 'C') - { -#if ! SPOOLDIR_TAYLOR - sprintf (absimple, "C.%.7s%c%s", zsystem, bgrade, abseq); -#else - sprintf (absimple, "C.%c%s", bgrade, abseq); -#endif - } - else if (btype == 'D') - { - /* This name doesn't really matter that much; it's just the - name we use on the local system. The name we use on the - remote system, which we return in zdname, should contain - our system name so that remote UUCP's running SPOOLDIR_V2 - and the like can distinguish while files come from which - systems. */ -#if SPOOLDIR_SVR4 - sprintf (absimple, "D.%.7s%c%s", zsystem, bgrade, abseq); -#else /* ! SPOOLDIR_SVR4 */ -#if ! SPOOLDIR_TAYLOR - sprintf (absimple, "D.%.7s%c%s", zlocalname, bgrade, abseq); -#else /* SPOOLDIR_TAYLOR */ - if (fxqt) - sprintf (absimple, "D.X%s", abseq); - else - sprintf (absimple, "D.%s", abseq); -#endif /* SPOOLDIR_TAYLOR */ -#endif /* ! SPOOLDIR_HDB && ! SPOOLDIR_SVR4 */ - } -#if DEBUG > 0 - else - ulog (LOG_FATAL, "zsfile_name: Can't happen"); -#endif - - zname = zsfind_file (absimple, zsystem, bgrade); - if (zname == NULL) - return NULL; - - if (! fsysdep_file_exists (zname)) - break; - - ubuffree (zname); - } - - if (ztname != NULL) - strcpy (ztname, absimple); - - if (zdname != NULL) - sprintf (zdname, "D.%.7s%c%s", zlocalname, bgrade, abseq); - - if (zxname != NULL) - sprintf (zxname, "X.%.7s%c%s", zlocalname, bgrade, abseq); - - return zname; -} - -/* Return a name to use for a data file to be copied to another - system. The name returned will be for a real file. The zlocalname - argument is the local name as seen by the remote system, the bgrade - argument is the file grade, and the fxqt argument is TRUE if this - file will become an execution file. The ztname argument, if not - NULL, will be set to a name that could be passed to - zsysdep_spool_file_name to get back the return value of this - function. The zdname argument, if not NULL, will be set to a name - that the file could be given on another system. The zxname - argument, if not NULL, will be set to a name for an execute file on - another system. */ - -char * -zsysdep_data_file_name (qsys, zlocalname, bgrade, fxqt, ztname, zdname, - zxname) - const struct uuconf_system *qsys; - const char *zlocalname; - int bgrade; - boolean fxqt; - char *ztname; - char *zdname; - char *zxname; -{ - return zsfile_name ('D', qsys->uuconf_zname, zlocalname, bgrade, fxqt, - ztname, zdname, zxname); -} - -#if SPOOLDIR_TAYLOR - -/* Write out a number in base 62 into a given number of characters, - right justified with zero fill. This is used by zscmd_file if - SPOOLDIR_TAYLOR. */ - -static void usput62 P((long i, char *, int c)); - -static void -usput62 (i, z, c) - long i; - char *z; - int c; -{ - for (--c; c >= 0; --c) - { - int d; - - d = i % 62; - i /= 62; - if (d < 26) - z[c] = 'A' + d; - else if (d < 52) - z[c] = 'a' + d - 26; - else - z[c] = '0' + d - 52; - } -} - -#endif /* SPOOLDIR_TAYLOR */ - -/* Get a command file name. */ - -char * -zscmd_file (qsys, bgrade) - const struct uuconf_system *qsys; - int bgrade; -{ -#if ! SPOOLDIR_TAYLOR - return zsfile_name ('C', qsys->uuconf_zname, (const char *) NULL, - bgrade, FALSE, (char *) NULL, (char *) NULL, - (char *) NULL); -#else - char *zname; - long isecs, imicros; - pid_t ipid; - - /* This file name is never seen by the remote system, so we don't - actually need to get a sequence number for it. We just need to - get a file name which is unique for this system. We don't try - this optimization for other spool directory formats, mainly due - to compatibility concerns. It would be possible for HDB and SVR4 - spool directory formats. - - We get a unique name by combining the process ID and the current - time. The file name must start with C.g, where g is the grade. - Note that although it is likely that this name will be unique, it - is not guaranteed, so the caller must be careful. */ - - isecs = ixsysdep_time (&imicros); - ipid = getpid (); - - /* We are going to represent the file name as a series of numbers in - base 62 (using the alphanumeric characters). The maximum file - name length is 14 characters, so we may use 11. We use 3 for the - seconds within the day, 3 for the microseconds, and 5 for the - process ID. */ - - /* Cut the seconds down to a number within a day (maximum value - 86399 < 62 ** 3 == 238328). */ - isecs %= (long) 24 * (long) 60 * (long) 60; - /* Divide the microseconds (max 999999) by 5 to make sure they are - less than 62 ** 3. */ - imicros %= 1000000; - imicros /= 5; - - while (TRUE) - { - char ab[15]; - - ab[0] = 'C'; - ab[1] = '.'; - ab[2] = bgrade; - usput62 (isecs, ab + 3, 3); - usput62 (imicros, ab + 6, 3); - usput62 ((long) ipid, ab + 9, 5); - ab[14] = '\0'; - - zname = zsfind_file (ab, qsys->uuconf_zname, bgrade); - if (zname == NULL) - return NULL; - - if (! fsysdep_file_exists (zname)) - break; - - ubuffree (zname); - - /* We hit a duplicate. Move backward in time until we find an - available name. Note that there is still a theoretical race - condition, since 5 base 62 digits might not be enough for the - process ID, and some other process might be running these - checks at the same time as we are. The caller must deal with - this. */ - if (imicros == 0) - { - imicros = (long) 62 * (long) 62 * (long) 62; - if (isecs == 0) - isecs = (long) 62 * (long) 62 * (long) 62; - --isecs; - } - --imicros; - } - - return zname; - -#endif -} - -/* Return a name for an execute file to be created locally. This is - used by uux to execute a command locally with remote files. */ - -char * -zsysdep_xqt_file_name () -{ - char abseq[CSEQLEN + 1]; - char absx[11 + CSEQLEN]; - char *zname; - - while (TRUE) - { - if (! fscmd_seq (zSlocalname, abseq)) - return NULL; - - sprintf (absx, "X.%.7sX%s", zSlocalname, abseq); - - zname = zsfind_file (absx, zSlocalname, -1); - if (zname == NULL) - return NULL; - - if (! fsysdep_file_exists (zname)) - break; - - ubuffree (zname); - } - - return zname; -} diff --git a/gnu/libexec/uucp/libunix/fsusg.c b/gnu/libexec/uucp/libunix/fsusg.c deleted file mode 100644 index 9189193..0000000 --- a/gnu/libexec/uucp/libunix/fsusg.c +++ /dev/null @@ -1,332 +0,0 @@ -/* fsusage.c -- return space usage of mounted filesystems - Copyright (C) 1991, 1992 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - This file was modified slightly by Ian Lance Taylor, December 1992, - and again July 1995, for use with Taylor UUCP. */ - -#include "uucp.h" -#include "uudefs.h" -#include "sysdep.h" -#include "fsusg.h" - -int statfs (); - -#if HAVE_SYS_PARAM_H -#include <sys/param.h> -#endif - -#if HAVE_SYS_MOUNT_H -#include <sys/mount.h> -#endif - -#if HAVE_SYS_VFS_H -#include <sys/vfs.h> -#endif - -#if HAVE_SYS_FILSYS_H -#include <sys/filsys.h> /* SVR2. */ -#endif - -#if HAVE_FCNTL_H -#include <fcntl.h> -#endif - -#if HAVE_SYS_STATFS_H -#include <sys/statfs.h> -#endif - -#if HAVE_SYS_DUSTAT_H /* AIX PS/2. */ -#include <sys/dustat.h> -#endif - -#if HAVE_SYS_STATVFS_H /* SVR4. */ -#include <sys/statvfs.h> -int statvfs (); -#endif - -#if HAVE_USTAT_H /* SVR2 and others. */ -#include <ustat.h> -#endif - -#if STAT_DISK_SPACE /* QNX. */ -#include <sys/disk.h> -#include <errno.h> -#endif - -#define STAT_NONE 0 - -#if ! STAT_STATFS3_OSF1 -#if ! STAT_STATFS2_FS_DATA -#if ! STAT_STATFS2_BSIZE -#if ! STAT_STATFS2_FSIZE -#if ! STAT_STATFS4 -#if ! STAT_STATVFS -#if ! STAT_DISK_SPACE -#if ! STAT_USTAT -#undef STAT_NONE -#define STAT_NONE 1 -#endif -#endif -#endif -#endif -#endif -#endif -#endif -#endif - -#if ! STAT_NONE - -static long adjust_blocks P((long blocks, int fromsize, int tosize)); - -/* Return the number of TOSIZE-byte blocks used by - BLOCKS FROMSIZE-byte blocks, rounding away from zero. - TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */ - -static long -adjust_blocks (blocks, fromsize, tosize) - long blocks; - int fromsize, tosize; -{ - if (tosize <= 0) - abort (); - if (fromsize <= 0) - return -1; - - if (fromsize == tosize) /* E.g., from 512 to 512. */ - return blocks; - else if (fromsize > tosize) /* E.g., from 2048 to 512. */ - return blocks * (fromsize / tosize); - else /* E.g., from 256 to 512. */ - return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize); -} - -#endif - -/* Fill in the fields of FSP with information about space usage for - the filesystem on which PATH resides. - DISK is the device on which PATH is mounted, for space-getting - methods that need to know it. - Return 0 if successful, -1 if not. */ - -int -get_fs_usage (path, disk, fsp) - char *path, *disk; - struct fs_usage *fsp; -{ -#if STAT_NONE - return -1; -#endif - -#if STAT_STATFS3_OSF1 - struct statfs fsd; - - if (statfs (path, &fsd, sizeof (struct statfs)) != 0) - return -1; -#define CONVERT_BLOCKS(b) adjust_blocks ((b), fsd.f_fsize, 512) -#endif /* STAT_STATFS3_OSF1 */ - -#if STAT_STATFS2_FS_DATA /* Ultrix. */ - struct fs_data fsd; - - if (statfs (path, &fsd) != 1) - return -1; -#define CONVERT_BLOCKS(b) adjust_blocks ((long) (b), 1024, 512) - fsp->fsu_blocks = CONVERT_BLOCKS (fsd.fd_req.btot); - fsp->fsu_bfree = CONVERT_BLOCKS (fsd.fd_req.bfree); - fsp->fsu_bavail = CONVERT_BLOCKS (fsd.fd_req.bfreen); - fsp->fsu_files = fsd.fd_req.gtot; - fsp->fsu_ffree = fsd.fd_req.gfree; -#endif - -#if STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX. */ - struct statfs fsd; - - if (statfs (path, &fsd) < 0) - return -1; -#define CONVERT_BLOCKS(b) adjust_blocks ((b), fsd.f_bsize, 512) -#endif - -#if STAT_STATFS2_FSIZE /* 4.4BSD. */ - struct statfs fsd; - - if (statfs (path, &fsd) < 0) - return -1; -#define CONVERT_BLOCKS(b) adjust_blocks ((b), fsd.f_fsize, 512) -#endif - -#if STAT_STATFS4 /* SVR3, Dynix, Irix. */ - struct statfs fsd; - - if (statfs (path, &fsd, sizeof fsd, 0) < 0) - return -1; - /* Empirically, the block counts on most SVR3 and SVR3-derived - systems seem to always be in terms of 512-byte blocks, - no matter what value f_bsize has. */ -# if _AIX -# define CONVERT_BLOCKS(b) adjust_blocks ((b), fsd.f_bsize, 512) -# else -# define CONVERT_BLOCKS(b) (b) -# ifndef _SEQUENT_ /* _SEQUENT_ is DYNIX/ptx. */ -# ifndef DOLPHIN /* DOLPHIN 3.8.alfa/7.18 has f_bavail */ -# define f_bavail f_bfree -# endif -# endif -# endif -#endif - -#if STAT_STATVFS /* SVR4. */ - struct statvfs fsd; - - if (statvfs (path, &fsd) < 0) - return -1; - /* f_frsize isn't guaranteed to be supported. */ -#define CONVERT_BLOCKS(b) \ - adjust_blocks ((b), fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize, 512) -#endif - -#if STAT_DISK_SPACE /* QNX. */ - int o; - int iret; - long cfree_blocks, ctotal_blocks; - char *zpath; - char *zslash; - - zpath = zbufcpy (path); - while ((o = open (zpath, O_RDONLY, 0)) == -1 - && errno == ENOENT) - { - /* The named file doesn't exist, so we can't open it. Try the - directory containing it. */ - if ((strcmp ("/", zpath) == 0) - || (strcmp (zpath, ".") == 0) - || (strcmp (zpath, "") == 0) - /* QNX peculiarity: "//2" means root on node 2 */ - || ((strncmp (zpath, "//", 2) == 0) - && (strchr (zpath + 2, '/') == NULL))) - { - /* We can't shorten this! */ - break; - } - - /* Shorten the pathname by one component and try again. */ - zslash = strrchr (zpath, '/'); - if (zslash == NULL) - { - /* Try the current directory. We can open directories. */ - zpath[0] = '.'; - zpath[1] = '\0'; - } - else if (zslash == zpath) - { - /* Try the root directory. */ - zpath[0] = '/'; - zpath[1] = '\0'; - } - else - { - /* Chop off last path component. */ - zslash[0] = '\0'; - } - } - if (o == -1) - { - ulog (LOG_ERROR, "get_fs_usage: open (%s) failed: %s", zpath, - strerror (errno)); - ubuffree (zpath); - return -1; - } - ubuffree (zpath); - - iret = disk_space (o, &cfree_blocks, &ctotal_blocks); - (void) close (o); - if (iret == -1) - { - ulog (LOG_ERROR, "get_fs_usage: disk_space failed: %s", - strerror (errno)); - return -1; - } - - fsp->fsu_blocks = ctotal_blocks; - fsp->fsu_bfree = cfree_blocks; - fsp->fsu_bavail = cfree_blocks; - - /* QNX has no limit on the number of inodes. Most inodes are stored - directly in the directory entry. */ - fsp->fsu_files = -1; - fsp->fsu_ffree = -1; -#endif /* STAT_DISK_SPACE */ - -#if STAT_USTAT - struct stat sstat; - struct ustat s; - - if (stat (path, &sstat) < 0 - || ustat (sstat.st_dev, &s) < 0) - return -1; - fsp->fsu_blocks = -1; - fsp->fsu_bfree = s.f_tfree; - fsp->fsu_bavail = s.f_tfree; - fsp->fsu_files = -1; - fsp->fsu_ffree = -1; -#endif - -#if ! STAT_STATFS2_FS_DATA /* ! Ultrix */ -#if ! STAT_DISK_SPACE -#if ! STAT_USTAT -#if ! STAT_NONE - fsp->fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks); - fsp->fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree); - fsp->fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail); - fsp->fsu_files = fsd.f_files; - fsp->fsu_ffree = fsd.f_ffree; -#endif -#endif -#endif -#endif - - return 0; -} - -#ifdef _AIX -#ifdef _I386 -/* AIX PS/2 does not supply statfs. */ - -int -statfs (path, fsb) - char *path; - struct statfs *fsb; -{ - struct stat stats; - struct dustat fsd; - - if (stat (path, &stats)) - return -1; - if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd))) - return -1; - fsb->f_type = 0; - fsb->f_bsize = fsd.du_bsize; - fsb->f_blocks = fsd.du_fsize - fsd.du_isize; - fsb->f_bfree = fsd.du_tfree; - fsb->f_bavail = fsd.du_tfree; - fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; - fsb->f_ffree = fsd.du_tinode; - fsb->f_fsid.val[0] = fsd.du_site; - fsb->f_fsid.val[1] = fsd.du_pckno; - return 0; -} -#endif /* _I386 */ -#endif /* _AIX */ diff --git a/gnu/libexec/uucp/libunix/fsusg.h b/gnu/libexec/uucp/libunix/fsusg.h deleted file mode 100644 index 2b9ddd5..0000000 --- a/gnu/libexec/uucp/libunix/fsusg.h +++ /dev/null @@ -1,31 +0,0 @@ -/* fsusage.h -- declarations for filesystem space usage info - Copyright (C) 1991, 1992 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - This files was modified slightly by Ian Lance Taylor for use with - Taylor UUCP. */ - -/* Space usage statistics for a filesystem. Blocks are 512-byte. */ -struct fs_usage -{ - long fsu_blocks; /* Total blocks. */ - long fsu_bfree; /* Free blocks available to superuser. */ - long fsu_bavail; /* Free blocks available to non-superuser. */ - long fsu_files; /* Total file nodes. */ - long fsu_ffree; /* Free file nodes. */ -}; - -extern int get_fs_usage P((char *path, char *disk, struct fs_usage *fsp)); diff --git a/gnu/libexec/uucp/libunix/ftw.c b/gnu/libexec/uucp/libunix/ftw.c deleted file mode 100644 index f7af66f..0000000 --- a/gnu/libexec/uucp/libunix/ftw.c +++ /dev/null @@ -1,254 +0,0 @@ -/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. -This file is part of the GNU C Library. -Contributed by Ian Lance Taylor (ian@airs.com). - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 59 Temple Place - -Suite 330, Boston, MA 02111-1307, USA. - -Modified by Ian Lance Taylor for Taylor UUCP, June 1992, and October 1993. */ - -#include "uucp.h" - -#include "sysdep.h" - -#include <errno.h> - -#if HAVE_LIMITS_H -#include <limits.h> -#endif - -#if HAVE_SYS_PARAM_H -#include <sys/param.h> -#endif - -#if HAVE_OPENDIR -#if HAVE_DIRENT_H -#include <dirent.h> -#else /* ! HAVE_DIRENT_H */ -#include <sys/dir.h> -#define dirent direct -#endif /* ! HAVE_DIRENT_H */ -#endif /* HAVE_OPENDIR */ - -#if HAVE_FTW_H -#include <ftw.h> -#endif - -#ifndef PATH_MAX -#ifdef MAXPATHLEN -#define PATH_MAX MAXPATHLEN -#else -#define PATH_MAX 1024 -#endif -#endif - -/* Traverse one level of a directory tree. */ - -static int -ftw_dir (dirs, level, descriptors, dir, len, func) - DIR **dirs; - int level; - int descriptors; - char *dir; - size_t len; - int (*func) P((const char *file, struct stat *status, int flag)); -{ - int got; - struct dirent *entry; - - got = 0; - - errno = 0; - - while ((entry = readdir (dirs[level])) != NULL) - { - size_t namlen; - struct stat s; - int flag, ret, newlev = 0; - - ++got; - - namlen = strlen (entry->d_name); - if (entry->d_name[0] == '.' - && (namlen == 1 || - (namlen == 2 && entry->d_name[1] == '.'))) - { - errno = 0; - continue; - } - - if (namlen + len + 1 > PATH_MAX) - { -#ifdef ENAMETOOLONG - errno = ENAMETOOLONG; -#else - errno = ENOMEM; -#endif - return -1; - } - - dir[len] = '/'; - memcpy ((dir + len + 1), entry->d_name, namlen + 1); - - if (stat (dir, &s) < 0) - { - if (errno != EACCES) - return -1; - flag = FTW_NS; - } - else if (S_ISDIR (s.st_mode)) - { - newlev = (level + 1) % descriptors; - - if (dirs[newlev] != NULL) - closedir (dirs[newlev]); - - dirs[newlev] = opendir (dir); - if (dirs[newlev] != NULL) - flag = FTW_D; - else - { - if (errno != EACCES) - return -1; - flag = FTW_DNR; - } - } - else - flag = FTW_F; - - ret = (*func) (dir, &s, flag); - - if (flag == FTW_D) - { - if (ret == 0) - ret = ftw_dir (dirs, newlev, descriptors, dir, - namlen + len + 1, func); - if (dirs[newlev] != NULL) - { - int save; - - save = errno; - closedir (dirs[newlev]); - errno = save; - dirs[newlev] = NULL; - } - } - - if (ret != 0) - return ret; - - if (dirs[level] == NULL) - { - int skip; - - dir[len] = '\0'; - dirs[level] = opendir (dir); - if (dirs[level] == NULL) - return -1; - skip = got; - while (skip-- != 0) - { - errno = 0; - if (readdir (dirs[level]) == NULL) - return errno == 0 ? 0 : -1; - } - } - - errno = 0; - } - - return errno == 0 ? 0 : -1; -} - -/* Call a function on every element in a directory tree. */ - -int -ftw (dir, func, descriptors) - const char *dir; - int (*func) P((const char *file, struct stat *status, int flag)); - int descriptors; -{ - DIR **dirs; - int c; - DIR **p; - size_t len; - char buf[PATH_MAX + 1]; - struct stat s; - int flag, ret; - - if (descriptors <= 0) - descriptors = 1; - - dirs = (DIR **) malloc (descriptors * sizeof (DIR *)); - if (dirs == NULL) - return -1; - c = descriptors; - p = dirs; - while (c-- != 0) - *p++ = NULL; - - len = strlen (dir); - memcpy (buf, dir, len + 1); - - if (stat (dir, &s) < 0) - { - if (errno != EACCES) - { - free ((pointer) dirs); - return -1; - } - flag = FTW_NS; - } - else if (S_ISDIR (s.st_mode)) - { - dirs[0] = opendir (dir); - if (dirs[0] != NULL) - flag = FTW_D; - else - { - if (errno != EACCES) - { - free ((pointer) dirs); - return -1; - } - flag = FTW_DNR; - } - } - else - flag = FTW_F; - - ret = (*func) (buf, &s, flag); - - if (flag == FTW_D) - { - if (ret == 0) - { - if (len == 1 && *buf == '/') - len = 0; - ret = ftw_dir (dirs, 0, descriptors, buf, len, func); - } - if (dirs[0] != NULL) - { - int save; - - save = errno; - closedir (dirs[0]); - errno = save; - } - } - - free ((pointer) dirs); - return ret; -} diff --git a/gnu/libexec/uucp/libunix/getcwd.c b/gnu/libexec/uucp/libunix/getcwd.c deleted file mode 100644 index d3623bd..0000000 --- a/gnu/libexec/uucp/libunix/getcwd.c +++ /dev/null @@ -1,59 +0,0 @@ -/* getcwd.c - Replacement for the getcwd function that just calls /bin/pwd. */ - -#include "uucp.h" - -#include "sysdep.h" - -#include <errno.h> - -char * -getcwd (zbuf, cbuf) - char *zbuf; - size_t cbuf; -{ - const char *azargs[2]; - FILE *e; - pid_t ipid; - int cread; - int ierr; - - azargs[0] = PWD_PROGRAM; - azargs[1] = NULL; - e = espopen (azargs, TRUE, &ipid); - if (e == NULL) - return NULL; - - ierr = 0; - - cread = fread (zbuf, sizeof (char), cbuf, e); - if (cread == 0) - ierr = errno; - - (void) fclose (e); - - if (ixswait ((unsigned long) ipid, (const char *) NULL) != 0) - { - ierr = EACCES; - cread = 0; - } - - if (cread != 0) - { - if (zbuf[cread - 1] == '\n') - zbuf[cread - 1] = '\0'; - else - { - ierr = ERANGE; - cread = 0; - } - } - - if (cread == 0) - { - errno = ierr; - return NULL; - } - - return zbuf; -} diff --git a/gnu/libexec/uucp/libunix/indir.c b/gnu/libexec/uucp/libunix/indir.c deleted file mode 100644 index 88cdb0e..0000000 --- a/gnu/libexec/uucp/libunix/indir.c +++ /dev/null @@ -1,133 +0,0 @@ -/* indir.c - See if a file is in a directory. - - Copyright (C) 1992 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -/* See whether a file is in a directory, and optionally check access. */ - -boolean -fsysdep_in_directory (zfile, zdir, fcheck, freadable, zuser) - const char *zfile; - const char *zdir; - boolean fcheck; - boolean freadable; - const char *zuser; -{ - size_t c; - char *zcopy, *zslash; - struct stat s; - - if (*zfile != '/') - return FALSE; - c = strlen (zdir); - if (c > 0 && zdir[c - 1] == '/') - c--; - if (strncmp (zfile, zdir, c) != 0 - || (zfile[c] != '/' && zfile[c] != '\0')) - return FALSE; - if (strstr (zfile + c, "/../") != NULL) - return FALSE; - - /* If we're not checking access, get out now. */ - if (! fcheck) - return TRUE; - - zcopy = zbufcpy (zfile); - - /* Start checking directories after zdir. Otherwise, we would - require that all directories down to /usr/spool/uucppublic be - publically searchable; they probably are but it should not be a - requirement. */ - zslash = zcopy + c; - do - { - char b; - struct stat shold; - - b = *zslash; - *zslash = '\0'; - - shold = s; - if (stat (zcopy, &s) != 0) - { - if (errno != ENOENT) - { - ulog (LOG_ERROR, "stat (%s): %s", zcopy, strerror (errno)); - ubuffree (zcopy); - return FALSE; - } - - /* If this is the top directory, any problems will be caught - later when we try to open it. */ - if (zslash == zcopy + c) - { - ubuffree (zcopy); - return TRUE; - } - - /* Go back and check the last directory for read or write - access. */ - s = shold; - break; - } - - /* If this is not a directory, get out of the loop. */ - if (! S_ISDIR (s.st_mode)) - break; - - /* Make sure the directory is searchable. */ - if (! fsuser_access (&s, X_OK, zuser)) - { - ulog (LOG_ERROR, "%s: %s", zcopy, strerror (EACCES)); - ubuffree (zcopy); - return FALSE; - } - - /* If we've reached the end of the string, get out. */ - if (b == '\0') - break; - - *zslash = b; - } - while ((zslash = strchr (zslash + 1, '/')) != NULL); - - /* At this point s holds a stat on the last component of the path. - We must check it for readability or writeability. */ - if (! fsuser_access (&s, freadable ? R_OK : W_OK, zuser)) - { - ulog (LOG_ERROR, "%s: %s", zcopy, strerror (EACCES)); - ubuffree (zcopy); - return FALSE; - } - - ubuffree (zcopy); - return TRUE; -} diff --git a/gnu/libexec/uucp/libunix/jobid.c b/gnu/libexec/uucp/libunix/jobid.c deleted file mode 100644 index b7f9145..0000000 --- a/gnu/libexec/uucp/libunix/jobid.c +++ /dev/null @@ -1,169 +0,0 @@ -/* jobid.c - Convert file names to jobids and vice versa. - - Copyright (C) 1991, 1992, 1995 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uuconf.h" -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -/* Translate a file name and an associated system into a job id. - These job ids are used by uustat. */ - -char * -zsfile_to_jobid (qsys, zfile, bgrade) - const struct uuconf_system *qsys; - const char *zfile; - int bgrade; -{ - size_t clen; - char *zret; - - clen = strlen (qsys->uuconf_zname); - -#if ! SPOOLDIR_TAYLOR - - /* We use the system name attached to the grade and sequence number. - This won't work correctly if the file name was actually created - by some other version of uucp that uses a different length for - the sequence number. Too bad. */ - - zret = zbufalc (clen + CSEQLEN + 2); - memcpy (zret, qsys->uuconf_zname, clen); - zret[clen] = bgrade; - memcpy (zret + clen + 1, zfile + strlen (zfile) - CSEQLEN, CSEQLEN + 1); - -#else - - /* We use the system name followed by a dot, the grade, and the - sequence number. In this case, the sequence number is a long - string. */ - - { - size_t cseqlen; - - /* zfile is SYS/C./C.gseq. */ - zfile = strrchr (zfile, '/'); - -#if DEBUG > 0 - if (zfile == NULL - || zfile[1] != 'C' - || zfile[2] != '.' - || zfile[3] == '\0') - ulog (LOG_FATAL, "zsfile_to_jobid: Can't happen"); -#endif - - /* Make zfile point at .gseq. */ - zfile += 2; - - cseqlen = strlen (zfile); - zret = zbufalc (clen + cseqlen + 1); - memcpy (zret, qsys->uuconf_zname, clen); - memcpy (zret + clen, zfile, cseqlen + 1); - } - -#endif - - return zret; -} - -/* Turn a job id back into a file name. */ - -char * -zsjobid_to_file (zid, pzsystem, pbgrade) - const char *zid; - char **pzsystem; - char *pbgrade; -{ -#if ! SPOOLDIR_TAYLOR - size_t clen; - const char *zend; - char *zsys; - char abname[CSEQLEN + 11]; - char *zret; - - clen = strlen (zid); - if (clen <= CSEQLEN) - { - ulog (LOG_ERROR, "%s: Bad job id", zid); - return NULL; - } - - zend = zid + clen - CSEQLEN - 1; - - zsys = zbufalc (clen - CSEQLEN); - memcpy (zsys, zid, clen - CSEQLEN - 1); - zsys[clen - CSEQLEN - 1] = '\0'; - - /* This must correspond to zsfile_name. */ - sprintf (abname, "C.%.7s%s", zsys, zend); - - zret = zsfind_file (abname, zsys, *zend); - - if (zret != NULL && pzsystem != NULL) - *pzsystem = zsys; - else - ubuffree (zsys); - - if (pbgrade != NULL) - *pbgrade = *zend; - - return zret; -#else /* SPOOLDIR_TAYLOR */ - char *zdot; - size_t csyslen; - char *zsys; - char ab[15]; - char *zret; - - zdot = strrchr (zid, '.'); - if (zdot == NULL) - { - ulog (LOG_ERROR, "%s: Bad job id", zid); - return NULL; - } - - csyslen = zdot - zid; - zsys = zbufalc (csyslen + 1); - memcpy (zsys, zid, csyslen); - zsys[csyslen] = '\0'; - - ab[0] = 'C'; - strcpy (ab + 1, zdot); - - zret = zsfind_file (ab, zsys, zdot[1]); - - if (zret != NULL && pzsystem != NULL) - *pzsystem = zsys; - else - ubuffree (zsys); - - if (pbgrade != NULL) - *pbgrade = zdot[1]; - - return zret; -#endif /* SPOOLDIR_TAYLOR */ -} diff --git a/gnu/libexec/uucp/libunix/lcksys.c b/gnu/libexec/uucp/libunix/lcksys.c deleted file mode 100644 index ab2e2c8..0000000 --- a/gnu/libexec/uucp/libunix/lcksys.c +++ /dev/null @@ -1,62 +0,0 @@ -/* lcksys.c - Lock and unlock a remote system. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "uuconf.h" -#include "sysdep.h" -#include "system.h" - -/* Do the actual lock or unlock. */ - -static boolean fslock_sys P((boolean, const char *)); - -static boolean -fslock_sys (flock, zname) - boolean flock; - const char *zname; -{ - size_t clen; - char *z; - boolean fret; - - clen = strlen (zname); - -#if ! HAVE_LONG_FILE_NAMES - if (clen > 8) - clen = 8; -#endif - - z = zbufalc (sizeof "LCK.." + clen); - memcpy (z, "LCK..", sizeof "LCK.." - 1); - memcpy (z + sizeof "LCK.." - 1, zname, clen); - z[sizeof "LCK.." - 1 + clen] = '\0'; - - if (flock) - fret = fsdo_lock (z, FALSE, (boolean *) NULL); - else - fret = fsdo_unlock (z, FALSE); - - ubuffree (z); - - return fret; -} - -/* Lock a remote system. */ - -boolean -fsysdep_lock_system (qsys) - const struct uuconf_system *qsys; -{ - return fslock_sys (TRUE, qsys->uuconf_zname); -} - -/* Unlock a remote system. */ - -boolean -fsysdep_unlock_system (qsys) - const struct uuconf_system *qsys; -{ - return fslock_sys (FALSE, qsys->uuconf_zname); -} diff --git a/gnu/libexec/uucp/libunix/link.c b/gnu/libexec/uucp/libunix/link.c deleted file mode 100644 index 4550c76..0000000 --- a/gnu/libexec/uucp/libunix/link.c +++ /dev/null @@ -1,38 +0,0 @@ -/* link.c - Link two files. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -boolean -fsysdep_link (zfrom, zto, pfworked) - const char *zfrom; - const char *zto; - boolean *pfworked; -{ - *pfworked = FALSE; - if (link (zfrom, zto) == 0) - { - *pfworked = TRUE; - return TRUE; - } - if (errno == ENOENT) - { - if (! fsysdep_make_dirs (zto, TRUE)) - return FALSE; - if (link (zfrom, zto) == 0) - { - *pfworked = TRUE; - return TRUE; - } - } - if (errno == EXDEV) - return TRUE; - ulog (LOG_ERROR, "link (%s, %s): %s", zfrom, zto, strerror (errno)); - return FALSE; -} diff --git a/gnu/libexec/uucp/libunix/locfil.c b/gnu/libexec/uucp/libunix/locfil.c deleted file mode 100644 index 47581cf..0000000 --- a/gnu/libexec/uucp/libunix/locfil.c +++ /dev/null @@ -1,101 +0,0 @@ -/* locfil.c - Expand a file name on the local system. - - Copyright (C) 1991, 1992, 1993 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <pwd.h> - -#if GETPWNAM_DECLARATION_OK -#ifndef getpwnam -extern struct passwd *getpwnam (); -#endif -#endif - -/* Turn a file name into an absolute path, by doing tilde expansion - and moving any other type of file into the public directory. */ - -char * -zsysdep_local_file (zfile, zpubdir, pfbadname) - const char *zfile; - const char *zpubdir; - boolean *pfbadname; -{ - const char *zdir; - - if (pfbadname != NULL) - *pfbadname = FALSE; - - if (*zfile == '/') - return zbufcpy (zfile); - - if (*zfile != '~') - zdir = zpubdir; - else - { - if (zfile[1] == '\0') - return zbufcpy (zpubdir); - - if (zfile[1] == '/') - { - zdir = zpubdir; - zfile += 2; - } - else - { - size_t cuserlen; - char *zcopy; - struct passwd *q; - - ++zfile; - cuserlen = strcspn ((char *) zfile, "/"); - zcopy = zbufalc (cuserlen + 1); - memcpy (zcopy, zfile, cuserlen); - zcopy[cuserlen] = '\0'; - - q = getpwnam (zcopy); - if (q == NULL) - { - ulog (LOG_ERROR, "User %s not found", zcopy); - ubuffree (zcopy); - if (pfbadname != NULL) - *pfbadname = TRUE; - return NULL; - } - ubuffree (zcopy); - - if (zfile[cuserlen] == '\0') - return zbufcpy (q->pw_dir); - - zdir = q->pw_dir; - zfile += cuserlen + 1; - } - } - - return zsysdep_in_dir (zdir, zfile); -} diff --git a/gnu/libexec/uucp/libunix/mkdir.c b/gnu/libexec/uucp/libunix/mkdir.c deleted file mode 100644 index 2546cbf..0000000 --- a/gnu/libexec/uucp/libunix/mkdir.c +++ /dev/null @@ -1,58 +0,0 @@ -/* mkdir.c - Create a directory. We must go through a subsidiary program to - force our real uid to be the uucp owner before invoking the setuid - /bin/mkdir program. */ - -#include "uucp.h" - -#include "sysdep.h" - -#include <errno.h> - -int -mkdir (zdir, imode) - const char *zdir; - int imode; -{ - struct stat s; - const char *azargs[3]; - int aidescs[3]; - pid_t ipid; - - /* Make sure the directory does not exist, since we will otherwise - get the wrong errno value. */ - if (stat (zdir, &s) == 0) - { - errno = EEXIST; - return -1; - } - - /* /bin/mkdir will create the directory with mode 777, so we set our - umask to get the mode we want. */ - (void) umask ((~ imode) & (S_IRWXU | S_IRWXG | S_IRWXO)); - - azargs[0] = UUDIR_PROGRAM; - azargs[1] = zdir; - azargs[2] = NULL; - aidescs[0] = SPAWN_NULL; - aidescs[1] = SPAWN_NULL; - aidescs[2] = SPAWN_NULL; - - ipid = ixsspawn (azargs, aidescs, TRUE, FALSE, (const char *) NULL, - TRUE, FALSE, (const char *) NULL, - (const char *) NULL, (const char *) NULL); - - (void) umask (0); - - if (ipid < 0) - return -1; - - if (ixswait ((unsigned long) ipid, (const char *) NULL) != 0) - { - /* Make up an errno value. */ - errno = EACCES; - return -1; - } - - return 0; -} diff --git a/gnu/libexec/uucp/libunix/mode.c b/gnu/libexec/uucp/libunix/mode.c deleted file mode 100644 index 53f74ec..0000000 --- a/gnu/libexec/uucp/libunix/mode.c +++ /dev/null @@ -1,33 +0,0 @@ -/* mode.c - Get the Unix file mode of a file. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -unsigned int -ixsysdep_file_mode (zfile) - const char *zfile; -{ - struct stat s; - - if (stat ((char *) zfile, &s) != 0) - { - ulog (LOG_ERROR, "stat (%s): %s", zfile, strerror (errno)); - return 0; - } - -#if S_IRWXU != 0700 - #error Files modes need to be translated -#endif - - /* We can't return 0, since that indicate an error. */ - if ((s.st_mode & 0777) == 0) - return 0400; - - return s.st_mode & 0777; -} diff --git a/gnu/libexec/uucp/libunix/move.c b/gnu/libexec/uucp/libunix/move.c deleted file mode 100644 index 19828c2..0000000 --- a/gnu/libexec/uucp/libunix/move.c +++ /dev/null @@ -1,162 +0,0 @@ -/* move.c - Move a file. - - Copyright (C) 1991, 1992, 1993 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -/* Move (rename) a file from one name to another. This routine will - optionally create necessary directories, and fpublic indicates - whether the new directories should be publically accessible or not. - If fcheck is true, it will try to determine whether the named user - has write access to the new file. */ - -boolean -fsysdep_move_file (zorig, zto, fmkdirs, fpublic, fcheck, zuser) - const char *zorig; - const char *zto; - boolean fmkdirs; - boolean fpublic; - boolean fcheck; - const char *zuser; -{ - struct stat s; - int o; - - DEBUG_MESSAGE2 (DEBUG_SPOOLDIR, - "fsysdep_move_file: Moving %s to %s", zorig, zto); - - /* Optionally make sure that zuser has write access on the - directory. */ - if (fcheck) - { - char *zcopy; - char *zslash; - - zcopy = zbufcpy (zto); - zslash = strrchr (zcopy, '/'); - if (zslash == zcopy) - zslash[1] = '\0'; - else - *zslash = '\0'; - - if (stat (zcopy, &s) != 0) - { - ulog (LOG_ERROR, "stat (%s): %s", zcopy, strerror (errno)); - ubuffree (zcopy); - return FALSE; - } - if (! fsuser_access (&s, W_OK, zuser)) - { - ulog (LOG_ERROR, "%s: %s", zcopy, strerror (EACCES)); - ubuffree (zcopy); - return FALSE; - } - ubuffree (zcopy); - - /* A malicious user now has a few milliseconds to change a - symbolic link to a directory uucp has write permission on but - the user does not (the obvious choice being /usr/lib/uucp). - The only certain method I can come up with to close this race - is to fork an suid process which takes on the users identity - and does the actual copy. This is sufficiently high overhead - that I'm not going to do it. */ - } - - /* We try to use rename to move the file. */ - - if (rename (zorig, zto) == 0) - return TRUE; - - if (fmkdirs && errno == ENOENT) - { - if (! fsysdep_make_dirs (zto, fpublic)) - return FALSE; - if (rename (zorig, zto) == 0) - return TRUE; - } - -#if HAVE_RENAME - /* On some systems the system call rename seems to fail for - arbitrary reasons. To get around this, we always try to copy the - file by hand if the rename failed. */ - errno = EXDEV; -#endif - - /* If we can't link across devices, we must copy the file by hand. */ - if (errno != EXDEV) - { - ulog (LOG_ERROR, "rename (%s, %s): %s", zorig, zto, - strerror (errno)); - return FALSE; - } - - /* Copy the file. */ - if (stat ((char *) zorig, &s) < 0) - { - ulog (LOG_ERROR, "stat (%s): %s", zorig, strerror (errno)); - return FALSE; - } - - /* Make sure the file gets the right mode by creating it before we - call fcopy_file. */ - (void) remove (zto); - o = creat ((char *) zto, s.st_mode); - if (o < 0) - { - if (fmkdirs && errno == ENOENT) - { - if (! fsysdep_make_dirs (zto, fpublic)) - return FALSE; - o = creat ((char *) zto, s.st_mode); - } - if (o < 0) - { - ulog (LOG_ERROR, "creat (%s): %s", zto, strerror (errno)); - return FALSE; - } - } - (void) close (o); - - if (! fcopy_file (zorig, zto, fpublic, fmkdirs, FALSE)) - return FALSE; - - if (remove (zorig) != 0) - ulog (LOG_ERROR, "remove (%s): %s", zorig, strerror (errno)); - - return TRUE; -} diff --git a/gnu/libexec/uucp/libunix/opensr.c b/gnu/libexec/uucp/libunix/opensr.c deleted file mode 100644 index 5217741..0000000 --- a/gnu/libexec/uucp/libunix/opensr.c +++ /dev/null @@ -1,252 +0,0 @@ -/* opensr.c - Open files for sending and receiving. - - Copyright (C) 1991, 1992, 1993 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "uuconf.h" -#include "system.h" -#include "sysdep.h" - -#include <errno.h> - -#if HAVE_TIME_H -#include <time.h> -#endif - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -#ifndef O_RDONLY -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#endif - -#ifndef O_NOCTTY -#define O_NOCTTY 0 -#endif - -#ifndef FD_CLOEXEC -#define FD_CLOEXEC 1 -#endif - -#ifndef time -extern time_t time (); -#endif - -/* Open a file to send to another system, and return the mode and - the size. */ - -openfile_t -esysdep_open_send (qsys, zfile, fcheck, zuser) - const struct uuconf_system *qsys; - const char *zfile; - boolean fcheck; - const char *zuser; -{ - struct stat s; - openfile_t e; - int o; - - if (fsysdep_directory (zfile)) - { - ulog (LOG_ERROR, "%s: is a directory", zfile); - return EFILECLOSED; - } - -#if USE_STDIO - e = fopen (zfile, BINREAD); - if (e == NULL) - { - ulog (LOG_ERROR, "fopen (%s): %s", zfile, strerror (errno)); - return NULL; - } - o = fileno (e); -#else - e = open ((char *) zfile, O_RDONLY | O_NOCTTY, 0); - if (e == -1) - { - ulog (LOG_ERROR, "open (%s): %s", zfile, strerror (errno)); - return -1; - } - o = e; -#endif - - if (fcntl (o, F_SETFD, fcntl (o, F_GETFD, 0) | FD_CLOEXEC) < 0) - { - ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - (void) ffileclose (e); - return EFILECLOSED; - } - - if (fstat (o, &s) == -1) - { - ulog (LOG_ERROR, "fstat: %s", strerror (errno)); - s.st_mode = 0666; - } - - /* We have to recheck the file permission, although we probably - checked it already, because otherwise there would be a window in - which somebody could change the contents of a symbolic link to - point to some file which was only readable by uucp. */ - if (fcheck) - { - if (! fsuser_access (&s, R_OK, zuser)) - { - ulog (LOG_ERROR, "%s: %s", zfile, strerror (EACCES)); - (void) ffileclose (e); - return EFILECLOSED; - } - } - - return e; -} - -/* Get a temporary file name to receive into. We use the ztemp - argument to pick the file name, so that we restart the file if the - transmission is aborted. */ - -char * -zsysdep_receive_temp (qsys, zto, ztemp, frestart) - const struct uuconf_system *qsys; - const char *zto; - const char *ztemp; - boolean frestart; -{ - if (frestart - && ztemp != NULL - && *ztemp == 'D' - && strcmp (ztemp, "D.0") != 0) - return zsappend3 (".Temp", qsys->uuconf_zname, ztemp); - else - return zstemp_file (qsys); -} - -/* The number of seconds in one week. We must cast to long for this - to be calculated correctly on a machine with 16 bit ints. */ -#define SECS_PER_WEEK ((long) 7 * (long) 24 * (long) 60 * (long) 60) - -/* Open a temporary file to receive into. This should, perhaps, check - that we have write permission on the receiving directory, but it - doesn't. */ - -openfile_t -esysdep_open_receive (qsys, zto, ztemp, zreceive, pcrestart) - const struct uuconf_system *qsys; - const char *zto; - const char *ztemp; - const char *zreceive; - long *pcrestart; -{ - int o; - openfile_t e; - - /* If we used the ztemp argument in zsysdep_receive_temp, above, - then we will have a name consistent across conversations. In - that case, we may have already received some portion of this - file. */ - o = -1; - if (pcrestart != NULL) - *pcrestart = -1; - if (pcrestart != NULL - && ztemp != NULL - && *ztemp == 'D' - && strcmp (ztemp, "D.0") != 0) - { - o = open ((char *) zreceive, O_WRONLY); - if (o >= 0) - { - struct stat s; - - /* For safety, we insist on the file being less than 1 week - old. This can still catch people, unfortunately. I - don't know of any good solution to the problem of old - files hanging around. If anybody has a file they want - restarted, and they know about this issue, they can touch - it to bring it up to date. */ - if (fstat (o, &s) < 0 - || s.st_mtime + SECS_PER_WEEK < time ((time_t *) NULL)) - { - (void) close (o); - o = -1; - } - else - { - DEBUG_MESSAGE1 (DEBUG_SPOOLDIR, - "esysdep_open_receive: Reusing %s", - zreceive); - *pcrestart = (long) s.st_size; - } - } - } - - if (o < 0) - o = creat ((char *) zreceive, IPRIVATE_FILE_MODE); - - if (o < 0) - { - if (errno == ENOENT) - { - if (! fsysdep_make_dirs (zreceive, FALSE)) - return EFILECLOSED; - o = creat ((char *) zreceive, IPRIVATE_FILE_MODE); - } - if (o < 0) - { - ulog (LOG_ERROR, "creat (%s): %s", zreceive, strerror (errno)); - return EFILECLOSED; - } - } - - if (fcntl (o, F_SETFD, fcntl (o, F_GETFD, 0) | FD_CLOEXEC) < 0) - { - ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - (void) close (o); - (void) remove (zreceive); - return EFILECLOSED; - } - -#if USE_STDIO - e = fdopen (o, (char *) BINWRITE); - - if (e == NULL) - { - ulog (LOG_ERROR, "fdopen (%s): %s", zreceive, strerror (errno)); - (void) close (o); - (void) remove (zreceive); - return EFILECLOSED; - } -#else - e = o; -#endif - - return e; -} diff --git a/gnu/libexec/uucp/libunix/picksb.c b/gnu/libexec/uucp/libunix/picksb.c deleted file mode 100644 index 2aacc15..0000000 --- a/gnu/libexec/uucp/libunix/picksb.c +++ /dev/null @@ -1,234 +0,0 @@ -/* picksb.c - System dependent routines for uupick. - - Copyright (C) 1992, 1993 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#if USE_RCS_ID -const char picksb_rcsid[] = "$FreeBSD$"; -#endif - -#include "uudefs.h" -#include "system.h" -#include "sysdep.h" - -#include <errno.h> -#include <pwd.h> - -#if HAVE_OPENDIR -#if HAVE_DIRENT_H -#include <dirent.h> -#else /* ! HAVE_DIRENT_H */ -#include <sys/dir.h> -#define dirent direct -#endif /* ! HAVE_DIRENT_H */ -#endif /* HAVE_OPENDIR */ - -#if GETPWUID_DECLARATION_OK -#ifndef getpwuid -extern struct passwd *getpwuid (); -#endif -#endif - -/* Local variables. */ - -/* Directory of ~/receive/USER. */ -static DIR *qStopdir; - -/* Name of ~/receive/USER. */ -static char *zStopdir; - -/* Directory of ~/receive/USER/SYSTEM. */ -static DIR *qSsysdir; - -/* Name of system. */ -static char *zSsysdir; - -/* Prepare to get a list of all the file to uupick for this user. */ - -/*ARGSUSED*/ -boolean -fsysdep_uupick_init (zsystem, zpubdir) - const char *zsystem; - const char *zpubdir; -{ - const char *zuser; - - zuser = zsysdep_login_name (); - - zStopdir = (char *) xmalloc (strlen (zpubdir) - + sizeof "/receive/" - + strlen (zuser)); - sprintf (zStopdir, "%s/receive/%s", zpubdir, zuser); - - qStopdir = opendir (zStopdir); - if (qStopdir == NULL && errno != ENOENT) - { - ulog (LOG_ERROR, "opendir (%s): %s", zStopdir, - strerror (errno)); - return FALSE; - } - - qSsysdir = NULL; - - return TRUE; -} - -/* Return the next file from the uupick directories. */ - -/*ARGSUSED*/ -char * -zsysdep_uupick (zsysarg, zpubdir, pzfrom, pzfull) - const char *zsysarg; - const char *zpubdir; - char **pzfrom; - char **pzfull; -{ - struct dirent *qentry; - - while (TRUE) - { - while (qSsysdir == NULL) - { - const char *zsystem; - char *zdir; - - if (qStopdir == NULL) - return NULL; - - if (zsysarg != NULL) - { - closedir (qStopdir); - qStopdir = NULL; - zsystem = zsysarg; - } - else - { - do - { - qentry = readdir (qStopdir); - if (qentry == NULL) - { - closedir (qStopdir); - qStopdir = NULL; - return NULL; - } - } - while (strcmp (qentry->d_name, ".") == 0 - || strcmp (qentry->d_name, "..") == 0); - - zsystem = qentry->d_name; - } - - zdir = zbufalc (strlen (zStopdir) + strlen (zsystem) + sizeof "/"); - sprintf (zdir, "%s/%s", zStopdir, zsystem); - - qSsysdir = opendir (zdir); - if (qSsysdir == NULL) - { - if (errno != ENOENT && errno != ENOTDIR) - ulog (LOG_ERROR, "opendir (%s): %s", zdir, strerror (errno)); - } - else - { - ubuffree (zSsysdir); - zSsysdir = zbufcpy (zsystem); - } - - ubuffree (zdir); - } - - qentry = readdir (qSsysdir); - if (qentry == NULL) - { - closedir (qSsysdir); - qSsysdir = NULL; - continue; - } - - if (strcmp (qentry->d_name, ".") == 0 - || strcmp (qentry->d_name, "..") == 0) - continue; - - *pzfrom = zbufcpy (zSsysdir); - *pzfull = zsappend3 (zStopdir, zSsysdir, qentry->d_name); - return zbufcpy (qentry->d_name); - } -} - -/*ARGSUSED*/ -boolean -fsysdep_uupick_free (zsystem, zpubdir) - const char *zsystem; - const char *zpubdir; -{ - xfree ((pointer) zStopdir); - if (qStopdir != NULL) - { - closedir (qStopdir); - qStopdir = NULL; - } - ubuffree (zSsysdir); - zSsysdir = NULL; - if (qSsysdir != NULL) - { - closedir (qSsysdir); - qSsysdir = NULL; - } - - return TRUE; -} - -/* Expand a local file name for uupick. */ - -char * -zsysdep_uupick_local_file (zfile, pfbadname) - const char *zfile; - boolean *pfbadname; -{ - struct passwd *q; - - if (pfbadname != NULL) - *pfbadname = FALSE; - - /* If this does not start with a simple ~, pass it to - zsysdep_local_file_cwd; as it happens, zsysdep_local_file_cwd - only uses the zpubdir argument if the file starts with a simple - ~, so it doesn't really matter what we pass for zpubdir. */ - if (zfile[0] != '~' - || (zfile[1] != '/' && zfile[1] != '\0')) - return zsysdep_local_file_cwd (zfile, (const char *) NULL, pfbadname); - - q = getpwuid (getuid ()); - if (q == NULL) - { - ulog (LOG_ERROR, "Can't get home directory"); - return NULL; - } - - if (zfile[1] == '\0') - return zbufcpy (q->pw_dir); - - return zsysdep_in_dir (q->pw_dir, zfile + 2); -} diff --git a/gnu/libexec/uucp/libunix/priv.c b/gnu/libexec/uucp/libunix/priv.c deleted file mode 100644 index 207bd3d..0000000 --- a/gnu/libexec/uucp/libunix/priv.c +++ /dev/null @@ -1,24 +0,0 @@ -/* priv.c - See if a user is privileged. */ - -#include "uucp.h" - -#include "sysdep.h" -#include "system.h" - -/* See whether the user is privileged (for example, only privileged - users are permitted to kill arbitrary jobs with uustat). This is - true only for root and uucp. We check for uucp by seeing if the - real user ID and the effective user ID are the same; this works - because we should be suid to uucp, so our effective user ID will - always be uucp while our real user ID will be whoever ran the - program. */ - -boolean -fsysdep_privileged () -{ - uid_t iuid; - - iuid = getuid (); - return iuid == 0 || iuid == geteuid (); -} diff --git a/gnu/libexec/uucp/libunix/recep.c b/gnu/libexec/uucp/libunix/recep.c deleted file mode 100644 index a1f893d..0000000 --- a/gnu/libexec/uucp/libunix/recep.c +++ /dev/null @@ -1,201 +0,0 @@ -/* recep.c - See whether a file has already been received. - - Copyright (C) 1992, 1993, 1995 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "uuconf.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -#if HAVE_TIME_H -#include <time.h> -#endif - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -static char *zsreceived_name P((const struct uuconf_system *qsys, - const char *ztemp)); - -/* These routines are used to see whether we have already received a - file in a previous UUCP connection. It is possible for the - acknowledgement of a received file to be lost. The sending system - will then not know that the file was correctly received, and will - send it again. This can be a problem particularly with protocols - which support channels, since they may send several small files in - a single window, all of which may be received correctly although - the sending system never sees the acknowledgement. If these files - involve an execution, the execution will happen twice, which will - be bad. - - We use a simple system. For each file we want to remember, we - create an empty file names .Received/SYS/TEMP, where SYS is the - name of the system and TEMP is the name of the temporary file used - by the sender. If no temporary file is used by the sender, we - don't remember that we received the file. This is not perfect, but - execution files will always have a temporary file, so the most - important case is handled. Also, any file received from Taylor - UUCP 1.04 or greater will always have a temporary file. */ - -/* Return the name we are going use for the marker, or NULL if we have - no name. */ - -static char * -zsreceived_name (qsys, ztemp) - const struct uuconf_system *qsys; - const char *ztemp; -{ - if (ztemp != NULL - && *ztemp == 'D' - && strcmp (ztemp, "D.0") != 0) - return zsappend3 (".Received", qsys->uuconf_zname, ztemp); - else - return NULL; -} - -/* Remember that we have already received a file. */ - -/*ARGSUSED*/ -boolean -fsysdep_remember_reception (qsys, zto, ztemp) - const struct uuconf_system *qsys; - const char *zto; - const char *ztemp; -{ - char *zfile; - int o; - - zfile = zsreceived_name (qsys, ztemp); - if (zfile == NULL) - return TRUE; - o = creat (zfile, IPUBLIC_FILE_MODE); - if (o < 0) - { - if (errno == ENOENT) - { - if (fsysdep_make_dirs (zfile, FALSE)) - { - ubuffree (zfile); - return FALSE; - } - o = creat (zfile, IPUBLIC_FILE_MODE); - } - if (o < 0) - { - ulog (LOG_ERROR, "creat (%s): %s", zfile, strerror (errno)); - ubuffree (zfile); - return FALSE; - } - } - - ubuffree (zfile); - - /* We don't have to actually put anything in the file; we just use - the name. This is more convenient than keeping a file with a - list of names. */ - if (close (o) < 0) - { - ulog (LOG_ERROR, "fsysdep_remember_reception: close: %s", - strerror (errno)); - return FALSE; - } - - return TRUE; -} - -/* The number of seconds in one week. We must cast to long for this - to be calculated correctly on a machine with 16 bit ints. */ -#define SECS_PER_WEEK ((long) 7 * (long) 24 * (long) 60 * (long) 60) - -/* See if we have already received a file. Note that don't delete the - marker file here, because we need to know that the sending system - has received our denial first. This function returns TRUE if the - file has already been received, FALSE if it has not. */ - -/*ARGSUSED*/ -boolean -fsysdep_already_received (qsys, zto, ztemp) - const struct uuconf_system *qsys; - const char *zto; - const char *ztemp; -{ - char *zfile; - struct stat s; - boolean fret; - - zfile = zsreceived_name (qsys, ztemp); - if (zfile == NULL) - return FALSE; - if (stat (zfile, &s) < 0) - { - if (errno != ENOENT) - ulog (LOG_ERROR, "stat (%s): %s", zfile, strerror (errno)); - ubuffree (zfile); - return FALSE; - } - - /* Ignore the file (return FALSE) if it is over one week old. */ - fret = s.st_mtime + SECS_PER_WEEK >= time ((time_t *) NULL); - - if (fret) - DEBUG_MESSAGE1 (DEBUG_SPOOLDIR, "fsysdep_already_received: Found %s", - zfile); - - ubuffree (zfile); - - return fret; -} - -/* Forget that we have received a file. */ - -/*ARGSUSED*/ -boolean -fsysdep_forget_reception (qsys, zto, ztemp) - const struct uuconf_system *qsys; - const char *zto; - const char *ztemp; -{ - char *zfile; - - zfile = zsreceived_name (qsys, ztemp); - if (zfile == NULL) - return TRUE; - if (remove (zfile) < 0 - && errno != ENOENT) - { - ulog (LOG_ERROR, "remove (%s): %s", zfile, strerror (errno)); - ubuffree (zfile); - return FALSE; - } - return TRUE; -} diff --git a/gnu/libexec/uucp/libunix/remove.c b/gnu/libexec/uucp/libunix/remove.c deleted file mode 100644 index b695888..0000000 --- a/gnu/libexec/uucp/libunix/remove.c +++ /dev/null @@ -1,13 +0,0 @@ -/* remove.c - Remove a file (Unix specific implementation). */ - -#include "uucp.h" - -#include "sysdep.h" - -int -remove (z) - const char *z; -{ - return unlink (z); -} diff --git a/gnu/libexec/uucp/libunix/rename.c b/gnu/libexec/uucp/libunix/rename.c deleted file mode 100644 index 0947ef5..0000000 --- a/gnu/libexec/uucp/libunix/rename.c +++ /dev/null @@ -1,27 +0,0 @@ -/* rename.c - Rename a file to a new name (Unix specific implementation). */ - -#include "uucp.h" - -#include "sysdep.h" - -#include <errno.h> - -/* This implementation will not work on directories, but fortunately - we never want to rename directories. */ - -int -rename (zfrom, zto) - const char *zfrom; - const char *zto; -{ - if (link (zfrom, zto) < 0) - { - if (errno != EEXIST) - return -1; - if (unlink (zto) < 0 - || link (zfrom, zto) < 0) - return -1; - } - return unlink (zfrom); -} diff --git a/gnu/libexec/uucp/libunix/rmdir.c b/gnu/libexec/uucp/libunix/rmdir.c deleted file mode 100644 index 12a7b9e..0000000 --- a/gnu/libexec/uucp/libunix/rmdir.c +++ /dev/null @@ -1,43 +0,0 @@ -/* rmdir.c - Remove a directory on a system which doesn't have the rmdir system - call. This is only called by uupick, which is not setuid, so we - don't have to worry about the problems of invoking the setuid - /bin/rmdir program. */ - -#include "uucp.h" - -#include "sysdep.h" - -#include <errno.h> - -int -rmdir (zdir) - const char *zdir; -{ - const char *azargs[3]; - int aidescs[3]; - pid_t ipid; - - azargs[0] = RMDIR_PROGRAM; - azargs[1] = zdir; - azargs[2] = NULL; - aidescs[0] = SPAWN_NULL; - aidescs[1] = SPAWN_NULL; - aidescs[2] = SPAWN_NULL; - - ipid = ixsspawn (azargs, aidescs, TRUE, FALSE, (const char *) NULL, - TRUE, TRUE, (const char *) NULL, - (const char *) NULL, (const char *) NULL); - - if (ipid < 0) - return -1; - - if (ixswait ((unsigned long) ipid, (const char *) NULL) != 0) - { - /* Make up an errno value. */ - errno = EBUSY; - return -1; - } - - return 0; -} diff --git a/gnu/libexec/uucp/libunix/run.c b/gnu/libexec/uucp/libunix/run.c deleted file mode 100644 index d789d37..0000000 --- a/gnu/libexec/uucp/libunix/run.c +++ /dev/null @@ -1,113 +0,0 @@ -/* run.c - Run a program. - - Copyright (C) 1992, 1993, 1994 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -/* Start up a new program. */ - -boolean -fsysdep_run (ffork, zprogram, zarg1, zarg2) - boolean ffork; - const char *zprogram; - const char *zarg1; - const char *zarg2; -{ - char *zlib; - const char *azargs[4]; - int aidescs[3]; - pid_t ipid; - - /* If we are supposed to fork, fork and then spawn so that we don't - have to worry about zombie processes. */ - if (ffork) - { - ipid = ixsfork (); - if (ipid < 0) - { - ulog (LOG_ERROR, "fork: %s", strerror (errno)); - return FALSE; - } - - if (ipid != 0) - { - /* This is the parent. Wait for the child we just forked to - exit (below) and return. */ - (void) ixswait ((unsigned long) ipid, (const char *) NULL); - - /* Force the log files to be reopened in case the child just - output any error messages and stdio doesn't handle - appending correctly. */ - ulog_close (); - - return TRUE; - } - - /* This is the child. Detach from the terminal to avoid any - unexpected SIGHUP signals. At this point we are definitely - not a process group leader, so usysdep_detach will not fork - again. */ - usysdep_detach (); - - /* Now spawn the program and then exit. */ - } - - zlib = zbufalc (sizeof SBINDIR + sizeof "/" + strlen (zprogram)); - sprintf (zlib, "%s/%s", SBINDIR, zprogram); - - azargs[0] = zlib; - azargs[1] = zarg1; - azargs[2] = zarg2; - azargs[3] = NULL; - - aidescs[0] = SPAWN_NULL; - aidescs[1] = SPAWN_NULL; - aidescs[2] = SPAWN_NULL; - - /* We pass fsetuid and fshell as TRUE, which permits uucico and - uuxqt to be replaced by (non-setuid) shell scripts. */ - ipid = ixsspawn (azargs, aidescs, TRUE, FALSE, (const char *) NULL, - FALSE, TRUE, (const char *) NULL, - (const char *) NULL, (const char *) NULL); - ubuffree (zlib); - - if (ipid < 0) - { - ulog (LOG_ERROR, "ixsspawn: %s", strerror (errno)); - if (ffork) - _exit (EXIT_FAILURE); - return FALSE; - } - - if (ffork) - _exit (EXIT_SUCCESS); - - return TRUE; -} diff --git a/gnu/libexec/uucp/libunix/seq.c b/gnu/libexec/uucp/libunix/seq.c deleted file mode 100644 index 321ed74..0000000 --- a/gnu/libexec/uucp/libunix/seq.c +++ /dev/null @@ -1,126 +0,0 @@ -/* seq.c - Get and increment the conversation sequence number for a system. - - Copyright (C) 1991, 1992, 1993 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "uuconf.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -/* Get the current conversation sequence number for a remote system, - and increment it for next time. The conversation sequence number - is kept in a file named for the system in the directory .Sequence - in the spool directory. This is not compatible with other versions - of UUCP, but it makes more sense to me. The sequence file is only - used if specified in the information for that system. */ - -long -ixsysdep_get_sequence (qsys) - const struct uuconf_system *qsys; -{ - FILE *e; - char *zname; - struct stat s; - long iseq; - - /* This will only be called when the system is locked anyhow, so there - is no need to use a separate lock for the conversation sequence - file. */ - zname = zsysdep_in_dir (".Sequence", qsys->uuconf_zname); - - iseq = 0; - if (stat (zname, &s) == 0) - { - boolean fok; - char *zline; - size_t cline; - - /* The file should only be readable and writable by uucp. */ - if ((s.st_mode & (S_IRWXG | S_IRWXO)) != 0) - { - ulog (LOG_ERROR, - "Bad file protection for conversation sequence file"); - ubuffree (zname); - return -1; - } - - e = fopen (zname, "r+"); - if (e == NULL) - { - ulog (LOG_ERROR, "fopen (%s): %s", zname, strerror (errno)); - ubuffree (zname); - return -1; - } - - ubuffree (zname); - - fok = TRUE; - zline = NULL; - cline = 0; - if (getline (&zline, &cline, e) <= 0) - fok = FALSE; - else - { - char *zend; - - iseq = strtol (zline, &zend, 10); - if (zend == zline) - fok = FALSE; - } - - xfree ((pointer) zline); - - if (! fok) - { - ulog (LOG_ERROR, "Bad format for conversation sequence file"); - (void) fclose (e); - return -1; - } - - rewind (e); - } - else - { - e = esysdep_fopen (zname, FALSE, FALSE, TRUE); - ubuffree (zname); - if (e == NULL) - return -1; - } - - ++iseq; - - fprintf (e, "%ld", iseq); - - if (fclose (e) != 0) - { - ulog (LOG_ERROR, "fclose: %s", strerror (errno)); - return -1; - } - - return iseq; -} diff --git a/gnu/libexec/uucp/libunix/size.c b/gnu/libexec/uucp/libunix/size.c deleted file mode 100644 index 8d021db..0000000 --- a/gnu/libexec/uucp/libunix/size.c +++ /dev/null @@ -1,27 +0,0 @@ -/* size.c - Get the size in bytes of a file. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -long -csysdep_size (zfile) - const char *zfile; -{ - struct stat s; - - if (stat ((char *) zfile, &s) < 0) - { - if (errno == ENOENT) - return -1; - ulog (LOG_ERROR, "stat (%s): %s", zfile, strerror (errno)); - return -2; - } - - return s.st_size; -} diff --git a/gnu/libexec/uucp/libunix/splcmd.c b/gnu/libexec/uucp/libunix/splcmd.c deleted file mode 100644 index d085cee..0000000 --- a/gnu/libexec/uucp/libunix/splcmd.c +++ /dev/null @@ -1,161 +0,0 @@ -/* splcmd.c - Spool a command. - - Copyright (C) 1991, 1992, 1993, 1995 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "uuconf.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> -#include <ctype.h> - -/* Given a set of commands to execute for a remote system, create a - command file holding them. This creates a single command file - holding all the commands passed in. It returns a jobid. */ - -char * -zsysdep_spool_commands (qsys, bgrade, ccmds, pascmds) - const struct uuconf_system *qsys; - int bgrade; - int ccmds; - const struct scmd *pascmds; -{ - char abtempfile[sizeof "TMP1234567890"]; - char *ztemp; - FILE *e; - int i; - const struct scmd *q; - char *z; - char *zjobid; - -#if DEBUG > 0 - if (! UUCONF_GRADE_LEGAL (bgrade)) - ulog (LOG_FATAL, "Bad grade %d", bgrade); -#endif - - /* Write the commands into a temporary file and then rename it to - avoid a race with uucico reading the file. */ - sprintf (abtempfile, "TMP%010lx", (unsigned long) getpid ()); - ztemp = zsfind_file (abtempfile, qsys->uuconf_zname, bgrade); - if (ztemp == NULL) - return NULL; - - e = esysdep_fopen (ztemp, FALSE, FALSE, TRUE); - if (e == NULL) - { - ubuffree (ztemp); - return NULL; - } - - for (i = 0, q = pascmds; i < ccmds; i++, q++) - { - switch (q->bcmd) - { - case 'S': - fprintf (e, "S %s %s %s -%s %s 0%o %s\n", q->zfrom, q->zto, - q->zuser, q->zoptions, q->ztemp, q->imode, - q->znotify == NULL ? (const char *) "" : q->znotify); - break; - case 'R': - fprintf (e, "R %s %s %s -%s\n", q->zfrom, q->zto, q->zuser, - q->zoptions); - break; - case 'X': - fprintf (e, "X %s %s %s -%s\n", q->zfrom, q->zto, q->zuser, - q->zoptions); - break; - case 'E': - fprintf (e, "E %s %s %s -%s %s 0%o %s 0 %s\n", q->zfrom, q->zto, - q->zuser, q->zoptions, q->ztemp, q->imode, - q->znotify, q->zcmd); - break; - default: - ulog (LOG_ERROR, - "zsysdep_spool_commands: Unrecognized type %d", - q->bcmd); - (void) fclose (e); - (void) remove (ztemp); - ubuffree (ztemp); - return NULL; - } - } - - if (! fstdiosync (e, ztemp)) - { - (void) fclose (e); - (void) remove (ztemp); - ubuffree (ztemp); - return NULL; - } - - if (fclose (e) != 0) - { - ulog (LOG_ERROR, "fclose: %s", strerror (errno)); - (void) remove (ztemp); - ubuffree (ztemp); - return NULL; - } - - /* The filename returned by zscmd_file is subject to some unlikely - race conditions, so keep trying the link until the destination - file does not already exist. Each call to zscmd_file should - return a file name which does not already exist, so we don't have - to do anything special before calling it again. */ - while (TRUE) - { - z = zscmd_file (qsys, bgrade); - if (z == NULL) - { - (void) remove (ztemp); - ubuffree (ztemp); - return NULL; - } - - if (link (ztemp, z) >= 0) - break; - - if (errno != EEXIST) - { - ulog (LOG_ERROR, "link (%s, %s): %s", ztemp, z, strerror (errno)); - (void) remove (ztemp); - ubuffree (ztemp); - ubuffree (z); - return NULL; - } - - ubuffree (z); - } - - (void) remove (ztemp); - ubuffree (ztemp); - - zjobid = zsfile_to_jobid (qsys, z, bgrade); - if (zjobid == NULL) - (void) remove (z); - ubuffree (z); - return zjobid; -} diff --git a/gnu/libexec/uucp/libunix/splnam.c b/gnu/libexec/uucp/libunix/splnam.c deleted file mode 100644 index 06ce360..0000000 --- a/gnu/libexec/uucp/libunix/splnam.c +++ /dev/null @@ -1,19 +0,0 @@ -/* splnam.c - Get the full name of a file in the spool directory. */ - -#include "uucp.h" - -#include "uuconf.h" -#include "sysdep.h" -#include "system.h" - -/* Get the real name of a spool file. */ - -char * -zsysdep_spool_file_name (qsys, zfile, pseq) - const struct uuconf_system *qsys; - const char *zfile; - pointer pseq; -{ - return zsfind_file (zfile, qsys->uuconf_zname, bsgrade (pseq)); -} diff --git a/gnu/libexec/uucp/libunix/spool.c b/gnu/libexec/uucp/libunix/spool.c deleted file mode 100644 index b14b560..0000000 --- a/gnu/libexec/uucp/libunix/spool.c +++ /dev/null @@ -1,427 +0,0 @@ -/* spool.c - Find a file in the spool directory. - - Copyright (C) 1991, 1992, 1993 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#if USE_RCS_ID -const char spool_rcsid[] = "$FreeBSD$"; -#endif - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -/* There are several types of files that go in the spool directory, - and they go into various different subdirectories. Whenever the - system name LOCAL appears below, it means whatever the local system - name is. - - Command files - These contain instructions for uucico indicating what files to transfer - to and from what systems. Each line of a work file is a command - beginning with S, R, X, or E. - #if ! SPOOLDIR_TAYLOR - They are named C.ssssssgqqqq, where ssssss is the system name to - transfer to or from, g is the grade and qqqq is the sequence number. - #if SPOOLDIR_V2 - They are put in the spool directory. - #elif SPOOLDIR_BSD42 || SPOOLDIR_BSD43 - They are put in the directory "C.". - #elif SPOOLDIR_HDB - They are put in a directory named for the system for which they were - created. - #elif SPOOLDIR_ULTRIX - If the directory sys/ssssss exists, they are put in the directory - sys/ssssss/C; otherwise, they are put in the directory sys/DEFAULT/C. - #elif SPOOLDIR_SVR4 - They are put in the directory sys/g, where sys is the system name - and g is the grade. - #endif - #else SPOOLDIR_TAYLOR - They are named C.gqqqq, where g is the grade and qqqq is the - sequence number, and are placed in the directory ssssss/C. where - ssssss is the system name to transfer to or from. The sequence - number for a C. file is actually a long string; it is not based on - the sequence number file, but is generated via a process which - attempts to produce a unique string each time it is run. - #endif - - Data files - There are files to be transferred to other systems. Some files to - be transferred may not be in the spool directory, depending on how - uucp was invoked. Data files are named in work files, so it is - never necessary to look at them directly (except to remove old ones); - it is only necessary to create them. These means that the many - variations in naming are inconsequential. - #if ! SPOOLDIR_TAYLOR - They are named D.ssssssgqqqq where ssssss is a system name (which - may be LOCAL for locally initiated transfers or a remote system for - remotely initiated transfers, except that HDB appears to use the - system the file is being transferred to), g is the grade and qqqq - is the sequence number. Some systems use a trailing subjob ID - number, but we currently do not. The grade is not important, and - some systems do not use it. If the data file is to become an - execution file on another system the grade (if present) will be - 'X'. Otherwise Ultrix appears to use 'b'; the uux included with - gnuucp 1.0 appears to use 'S'; SCO does not appear to use a grade, - although it does use a subjob ID number. - #if SPOOLDIR_V2 - They are put in the spool directory. - #elif SPOOLDIR_BSD42 - If the name begins with D.LOCAL, the file is put in the directory - D.LOCAL. Otherwise the file is put in the directory D.. - #elif SPOOLDIR_BSD43 - If the name begins with D.LOCALX, the file is put in the directory - D.LOCALX. Otherwise if the name begins with D.LOCAL, the file is - put in the directory D.LOCAL Otherwise the file is put in the - directory "D.". - #elif SPOOLDIR_HDB - They are put in a directory named for the system for which they - were created. - #elif SPOOLDIR_ULTRIX - Say the file is being transferred to system REMOTE. If the - directory sys/REMOTE exists, then if the file begins with D.LOCALX - it is put in sys/REMOTE/D.LOCALX, if the file begins with D.LOCAL - it is put in sys/REMOTE/D.LOCAL, and otherwise it is put in - "sys/REMOTE/D.". If the directory sys/REMOTE does not exist, the - same applies except that DEFAULT is used instead of REMOTE. - #elif SPOOLDIR_SVR4 - They are put in the directory sys/g, where sys is the system name - and g is the grade. - #endif - #else SPOOLDIR_TAYLOR - If the file is to become an executable file on another system it is - named D.Xqqqq, otherwise it is named D.qqqq where in both cases - qqqq is a sequence number. If the corresponding C. file is in - directory ssssss/C., a D.X file is placed in ssssss/D.X and a D. - file is placed in "ssssss/D.". - #endif - - Execute files - These are files that specify programs to be executed. They are - created by uux, perhaps as run on another system. These names are - important, because a file transfer done to an execute file name - causes an execution to occur. The name is X.ssssssgqqqq, where - ssssss is the requesting system, g is the grade, and qqqq is a - sequence number. - #if SPOOLDIR_V2 || SPOOLDIR_BSD42 - These files are placed in the spool directory. - #elif SPOOLDIR_BSD43 - These files are placed in the directory X.. - #elif SPOOLDIR_HDB || SPOOLDIR_SVR4 - These files are put in a directory named for the system for which - the files were created. - #elif SPOOLDIR_ULTRIX - If there is a spool directory (sys/ssssss) for the requesting - system, the files are placed in sys/ssssss/X.; otherwise, the files - are placed in "sys/DEFAULT/X.". - #elif SPOOLDIR_TAYLOR - The system name is automatically truncated to seven characters when - a file is created. The files are placed in the subdirectory X. of - a directory named for the system for which the files were created. - #endif - - Temporary receive files - These are used when receiving files from another system. They are - later renamed to the final name. The actual name is unimportant, - although it generally begins with TM.. - #if SPOOLDIR_V2 || SPOOLDIR_BSD42 - These files are placed in the spool directory. - #elif SPOOLDIR_BSD43 || SPOOLDIR_ULTRIX || SPOOLDIR_TAYLOR - These files are placed in the directory .Temp. - #elif SPOOLDIR_HDB || SPOOLDIR_SVR4 - These files are placed in a directory named for the system for - which they were created. - #endif - - System status files - These are used to record when the last call was made to the system - and what the status is. They are used to prevent frequent recalls - to a system which is not responding. I will not attempt to - recreate the format of these exactly, since they are not all that - important. They will be put in the directory .Status, as in HDB, - and they use the system name as the name of the file. - - Sequence file - This is used to generate a unique sequence number. It contains an - ASCII number. - #if SPOOLDIR_V2 || SPOOLDIR_BSD42 || SPOOLDIR_BSD43 - The file is named SEQF and is kept in the spool directory. - #elif SPOOLDIR_HDB || SPOOLDIR_SVR4 - A separate sequence file is kept for each system in the directory - .Sequence with the name of the system. - #elif SPOOLDIR_ULTRIX - Each system with a file sys/ssssss has a sequence file in - sys/ssssss/.SEQF. Other systems use sys/DEFAULT/.SEQF. - #else SPOOLDIR_TAYLOR - A sequence file named SEQF is kept in the directory ssssss for each - system. - #endif - */ - -/* Given the name of a file as specified in a UUCP command, and the - system for which this file has been created, return where to find - it in the spool directory. The file will begin with C. (a command - file), D. (a data file) or X. (an execution file). Under - SPOOLDIR_SVR4 we need to know the grade of the file created by the - local system; this is the bgrade argument, which is -1 for a file - from a remote system. */ - -/*ARGSUSED*/ -char * -zsfind_file (zsimple, zsystem, bgrade) - const char *zsimple; - const char *zsystem; - int bgrade; -{ - /* zsysdep_spool_commands calls this with TMPXXX which we must treat - as a C. file. */ - if ((zsimple[0] != 'T' - || zsimple[1] != 'M' - || zsimple[2] != 'P') - && ! fspool_file (zsimple)) - { - ulog (LOG_ERROR, "Unrecognized file name %s", zsimple); - return NULL; - } - -#if ! SPOOLDIR_HDB && ! SPOOLDIR_SVR4 && ! SPOOLDIR_TAYLOR - if (*zsimple == 'X') - { - static char *zbuf; - static size_t cbuf; - size_t clen, cwant; - - /* Files beginning with X. are execute files. It is important - for security reasons that we know the system which created - the X. file. This is easy under SPOOLDIR_HDB or - SPOOLDIR_SVR4 SPOOLDIR_TAYLOR, because the file will be in a - directory named for the system. Under other schemes, we must - get the system name from the X. file name. To prevent - security violations, we set the system name directly here; - this will cause problems if the maximum file name length is - too short, but hopefully no problem will occur since any - System V systems will be using HDB or SVR4 or TAYLOR. */ - clen = strlen (zsimple); - if (clen < 5) - { - ulog (LOG_ERROR, "Bad file name (too short) %s", zsimple); - return NULL; - } - cwant = strlen (zsystem) + 8; - if (cwant > cbuf) - { - zbuf = (char *) xrealloc ((pointer) zbuf, cwant); - cbuf = cwant; - } - sprintf (zbuf, "X.%s%s", zsystem, zsimple + clen - 5); - zsimple = zbuf; - } -#endif /* ! SPOOLDIR_HDB && ! SPOOLDIR_SVR4 && ! SPOOLDIR_TAYLOR */ - -#if SPOOLDIR_V2 - /* V2 never uses subdirectories. */ - return zbufcpy (zsimple); -#endif /* SPOOLDIR_V2 */ - -#if SPOOLDIR_HDB - /* HDB always uses the system name as a directory. */ - return zsysdep_in_dir (zsystem, zsimple); -#endif /* SPOOLDIR_HDB */ - -#if SPOOLDIR_SVR4 - /* SVR4 uses grade directories within the system directory for local - command and data files. */ - if (bgrade < 0 || *zsimple == 'X') - return zsysdep_in_dir (zsystem, zsimple); - else - { - char abgrade[2]; - - abgrade[0] = bgrade; - abgrade[1] = '\0'; - return zsappend3 (zsystem, abgrade, zsimple); - } -#endif /* SPOOLDIR_SVR4 */ - -#if ! SPOOLDIR_V2 && ! SPOOLDIR_HDB && ! SPOOLDIR_SVR4 - switch (*zsimple) - { - case 'C': - case 'T': -#if SPOOLDIR_BSD42 || SPOOLDIR_BSD43 - return zsysdep_in_dir ("C.", zsimple); -#endif /* SPOOLDIR_BSD42 || SPOOLDIR_BSD43 */ -#if SPOOLDIR_ULTRIX - if (fsultrix_has_spool (zsystem)) - return zsappend4 ("sys", zsystem, "C.", zsimple); - else - return zsappend4 ("sys", "DEFAULT", "C.", zsimple); -#endif /* SPOOLDIR_ULTRIX */ -#if SPOOLDIR_TAYLOR - return zsappend3 (zsystem, "C.", zsimple); -#endif /* SPOOLDIR_TAYLOR */ - - case 'D': -#if SPOOLDIR_BSD42 || SPOOLDIR_BSD43 - { - size_t c; - boolean ftruncated; - - /* D.LOCAL in D.LOCAL/, others in D./. If BSD43, D.LOCALX in - D.LOCALX/. */ - ftruncated = TRUE; - if (strncmp (zsimple + 2, zSlocalname, strlen (zSlocalname)) == 0) - { - c = strlen (zSlocalname); - ftruncated = FALSE; - } - else if (strncmp (zsimple + 2, zSlocalname, 7) == 0) - c = 7; - else if (strncmp (zsimple + 2, zSlocalname, 6) == 0) - c = 6; - else - c = 0; -#if SPOOLDIR_BSD43 - if (c > 0 && zsimple[c + 2] == 'X') - c++; -#endif /* SPOOLDIR_BSD43 */ - if (c > 0) - { - char *zalloc; - - zalloc = zbufalc (c + 3); - memcpy (zalloc, zsimple, c + 2); - zalloc[c + 2] = '\0'; - - /* If we truncated the system name, and there is no existing - directory with the truncated name, then just use D.. */ - if (! ftruncated || fsysdep_directory (zalloc)) - { - char *zret; - - zret = zsysdep_in_dir (zalloc, zsimple); - ubuffree (zalloc); - return zret; - } - ubuffree (zalloc); - } - return zsysdep_in_dir ("D.", zsimple); - } -#endif /* SPOOLDIR_BSD42 || SPOOLDIR_BSD43 */ -#if SPOOLDIR_ULTRIX - { - size_t c; - boolean ftruncated; - char *zfree; - const char *zdir; - char *zret; - - /* D.LOCALX in D.LOCALX/, D.LOCAL in D.LOCAL/, others in D./. */ - ftruncated = TRUE; - if (strncmp (zsimple + 2, zSlocalname, strlen (zSlocalname)) == 0) - { - c = strlen (zSlocalname); - ftruncated = FALSE; - } - else if (strncmp (zsimple + 2, zSlocalname, 7) == 0) - c = 7; - else if (strncmp (zsimple + 2, zSlocalname, 6) == 0) - c = 6; - else - c = 0; - if (c > 0 && zsimple[c + 2] == 'X') - ++c; - if (c > 0) - { - zfree = zbufalc (c + 3); - memcpy (zfree, zsimple, c + 2); - zfree[c + 2] = '\0'; - zdir = zfree; - - /* If we truncated the name, and there is no directory for - the truncated name, then don't use it. */ - if (ftruncated) - { - char *zlook; - - zlook = zsappend3 ("sys", - (fsultrix_has_spool (zsystem) - ? zsystem - : "DEFAULT"), - zdir); - if (! fsysdep_directory (zlook)) - zdir = "D."; - ubuffree (zlook); - } - } - else - { - zfree = NULL; - zdir = "D."; - } - - zret = zsappend4 ("sys", - (fsultrix_has_spool (zsystem) - ? zsystem - : "DEFAULT"), - zdir, - zsimple); - ubuffree (zfree); - return zret; - } -#endif /* SPOOLDIR_ULTRIX */ -#if SPOOLDIR_TAYLOR - if (zsimple[2] == 'X') - return zsappend3 (zsystem, "D.X", zsimple); - else - return zsappend3 (zsystem, "D.", zsimple); -#endif /* SPOOLDIR_TAYLOR */ - - - case 'X': -#if SPOOLDIR_BSD42 - return zbufcpy (zsimple); -#endif -#if SPOOLDIR_BSD43 - return zsysdep_in_dir ("X.", zsimple); -#endif -#if SPOOLDIR_ULTRIX - return zsappend4 ("sys", - (fsultrix_has_spool (zsystem) - ? zsystem - : "DEFAULT"), - "X.", - zsimple); -#endif -#if SPOOLDIR_TAYLOR - return zsappend3 (zsystem, "X.", zsimple); -#endif - } - - /* This is just to avoid warnings; it will never be executed. */ - return NULL; -#endif /* ! SPOOLDIR_V2 && ! SPOOLDIR_HDB && ! SPOOLDIR_SVR4 */ -} diff --git a/gnu/libexec/uucp/libunix/srmdir.c b/gnu/libexec/uucp/libunix/srmdir.c deleted file mode 100644 index e143cdf..0000000 --- a/gnu/libexec/uucp/libunix/srmdir.c +++ /dev/null @@ -1,112 +0,0 @@ -/* srmdir.c - Remove a directory and all its contents. - - Copyright (C) 1992 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -#if HAVE_FTW_H -#include <ftw.h> -#endif - -static int isremove_dir P((const char *, struct stat *, int)); - -/* Keep a list of directories to be removed. */ - -struct sdirlist -{ - struct sdirlist *qnext; - char *zdir; -}; - -static struct sdirlist *qSdirlist; - -/* Remove a directory and all files in it. */ - -boolean -fsysdep_rmdir (zdir) - const char *zdir; -{ - boolean fret; - struct sdirlist *q; - - qSdirlist = NULL; - - fret = TRUE; - if (ftw ((char *) zdir, isremove_dir, 5) != 0) - { - ulog (LOG_ERROR, "ftw: %s", strerror (errno)); - fret = FALSE; - } - - q = qSdirlist; - while (q != NULL) - { - struct sdirlist *qnext; - - if (rmdir (q->zdir) != 0) - { - ulog (LOG_ERROR, "rmdir (%s): %s", q->zdir, strerror (errno)); - fret = FALSE; - } - ubuffree (q->zdir); - qnext = q->qnext; - xfree ((pointer) q); - q = qnext; - } - - return fret; -} - -/* Remove a file in a directory. */ - -/*ARGSUSED*/ -static int -isremove_dir (zfile, qstat, iflag) - const char *zfile; - struct stat *qstat; - int iflag; -{ - if (iflag == FTW_D || iflag == FTW_DNR) - { - struct sdirlist *q; - - q = (struct sdirlist *) xmalloc (sizeof (struct sdirlist)); - q->qnext = qSdirlist; - q->zdir = zbufcpy (zfile); - qSdirlist = q; - } - else - { - if (remove (zfile) != 0) - ulog (LOG_ERROR, "remove (%s): %s", zfile, strerror (errno)); - } - - return 0; -} diff --git a/gnu/libexec/uucp/libunix/statsb.c b/gnu/libexec/uucp/libunix/statsb.c deleted file mode 100644 index 4989cad..0000000 --- a/gnu/libexec/uucp/libunix/statsb.c +++ /dev/null @@ -1,634 +0,0 @@ -/* statsb.c - System dependent routines for uustat. - - Copyright (C) 1992, 1993, 1994 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#if USE_RCS_ID -const char statsb_rcsid[] = "$FreeBSD$"; -#endif - -#include "uudefs.h" -#include "uuconf.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -#ifndef O_RDONLY -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#endif - -#ifndef O_NOCTTY -#define O_NOCTTY 0 -#endif - -#if HAVE_OPENDIR -#if HAVE_DIRENT_H -#include <dirent.h> -#else /* ! HAVE_DIRENT_H */ -#include <sys/dir.h> -#define dirent direct -#endif /* ! HAVE_DIRENT_H */ -#endif /* HAVE_OPENDIR */ - -#if HAVE_TIME_H -#include <time.h> -#endif - -#if HAVE_UTIME_H -#include <utime.h> -#endif - -/* Local functions. */ - -static int issettime P((const char *z, time_t inow)); -static boolean fskill_or_rejuv P((pointer puuconf, const char *zid, - boolean fkill)); - -/* Set file access time to the present. On many systems this could be - done by passing NULL to utime, but on some that doesn't work. This - routine is not time critical, so we never rely on NULL. */ - -static int -issettime(z, inow) - const char *z; - time_t inow; -{ -#if HAVE_UTIME_H - struct utimbuf s; - - s.actime = inow; - s.modtime = inow; - return utime ((char *) z, &s); -#else - time_t ai[2]; - - ai[0] = inow; - ai[1] = inow; - return utime ((char *) z, ai); -#endif -} - -/* Kill a job, given the jobid. */ - -boolean -fsysdep_kill_job (puuconf, zid) - pointer puuconf; - const char *zid; -{ - return fskill_or_rejuv (puuconf, zid, TRUE); -} - -/* Rejuvenate a job, given the jobid. */ - -boolean -fsysdep_rejuvenate_job (puuconf, zid) - pointer puuconf; - const char *zid; -{ - return fskill_or_rejuv (puuconf, zid, FALSE); -} - -/* Kill or rejuvenate a job, given the jobid. */ - -static boolean -fskill_or_rejuv (puuconf, zid, fkill) - pointer puuconf; - const char *zid; - boolean fkill; -{ - char *zfile; - char *zsys; - char bgrade; - time_t inow = 0; - int iuuconf; - struct uuconf_system ssys; - FILE *e; - boolean fret; - char *zline; - size_t cline; - int isys; - - zfile = zsjobid_to_file (zid, &zsys, &bgrade); - if (zfile == NULL) - return FALSE; - - if (! fkill) - inow = time ((time_t *) NULL); - - iuuconf = uuconf_system_info (puuconf, zsys, &ssys); - if (iuuconf == UUCONF_NOT_FOUND) - { - if (! funknown_system (puuconf, zsys, &ssys)) - { - ulog (LOG_ERROR, "%s: Bad job id", zid); - ubuffree (zfile); - ubuffree (zsys); - return FALSE; - } - } - else if (iuuconf != UUCONF_SUCCESS) - { - ulog_uuconf (LOG_ERROR, puuconf, iuuconf); - ubuffree (zfile); - ubuffree (zsys); - return FALSE; - } - - e = fopen (zfile, "r"); - if (e == NULL) - { - if (errno == ENOENT) - ulog (LOG_ERROR, "%s: Job not found", zid); - else - ulog (LOG_ERROR, "fopen (%s): %s", zfile, strerror (errno)); - (void) uuconf_system_free (puuconf, &ssys); - ubuffree (zfile); - ubuffree (zsys); - return FALSE; - } - - /* Now we have to read through the file to identify any temporary - files. */ - fret = TRUE; - zline = NULL; - cline = 0; - while (getline (&zline, &cline, e) > 0) - { - struct scmd s; - - if (! fparse_cmd (zline, &s)) - { - ulog (LOG_ERROR, "Bad line in command file %s", zfile); - fret = FALSE; - continue; - } - - /* You are only permitted to delete a job if you submitted it or - if you are root or uucp. */ - if (strcmp (s.zuser, zsysdep_login_name ()) != 0 - && ! fsysdep_privileged ()) - { - ulog (LOG_ERROR, "%s: Not submitted by you", zid); - xfree ((pointer) zline); - (void) fclose (e); - (void) uuconf_system_free (puuconf, &ssys); - ubuffree (zfile); - ubuffree (zsys); - return FALSE; - } - - if (s.bcmd == 'S' || s.bcmd == 'E') - { - char *ztemp; - - ztemp = zsfind_file (s.ztemp, ssys.uuconf_zname, bgrade); - if (ztemp == NULL) - fret = FALSE; - else - { - if (fkill) - isys = remove (ztemp); - else - isys = issettime (ztemp, inow); - - if (isys != 0 && errno != ENOENT) - { - ulog (LOG_ERROR, "%s (%s): %s", - fkill ? "remove" : "utime", ztemp, - strerror (errno)); - fret = FALSE; - } - - ubuffree (ztemp); - } - } - } - - xfree ((pointer) zline); - (void) fclose (e); - (void) uuconf_system_free (puuconf, &ssys); - ubuffree (zsys); - - if (fkill) - isys = remove (zfile); - else - isys = issettime (zfile, inow); - - if (isys != 0 && errno != ENOENT) - { - ulog (LOG_ERROR, "%s (%s): %s", fkill ? "remove" : "utime", - zfile, strerror (errno)); - fret = FALSE; - } - - ubuffree (zfile); - - return fret; -} - -/* Get the time a work job was queued. */ - -long -ixsysdep_work_time (qsys, pseq) - const struct uuconf_system *qsys; - pointer pseq; -{ - char *zjobid, *zfile; - long iret; - - zjobid = zsysdep_jobid (qsys, pseq); - zfile = zsjobid_to_file (zjobid, (char **) NULL, (char *) NULL); - if (zfile == NULL) - return 0; - ubuffree (zjobid); - iret = ixsysdep_file_time (zfile); - ubuffree (zfile); - return iret; -} - -/* Get the time a file was created (actually, the time it was last - modified). */ - -long -ixsysdep_file_time (zfile) - const char *zfile; -{ - struct stat s; - - if (stat ((char *) zfile, &s) < 0) - { - if (errno != ENOENT) - ulog (LOG_ERROR, "stat (%s): %s", zfile, strerror (errno)); - return ixsysdep_time ((long *) NULL); - } - - return (long) s.st_mtime; -} - -/* Set the time of a file to the current time. */ - -boolean -fsysdep_touch_file (zfile) - const char *zfile; -{ - if (issettime (zfile, time ((time_t *) NULL)) != 0) - { - ulog (LOG_ERROR, "utime (%s): %s", zfile, strerror (errno)); - return FALSE; - } - - return TRUE; -} - -/* Start getting the status files. */ - -boolean -fsysdep_all_status_init (phold) - pointer *phold; -{ - DIR *qdir; - - qdir = opendir ((char *) ".Status"); - if (qdir == NULL) - { - ulog (LOG_ERROR, "opendir (.Status): %s", strerror (errno)); - return FALSE; - } - - *phold = (pointer) qdir; - return TRUE; -} - -/* Get the next status file. */ - -char * -zsysdep_all_status (phold, pferr, qstat) - pointer phold; - boolean *pferr; - struct sstatus *qstat; -{ - DIR *qdir = (DIR *) phold; - struct dirent *qentry; - - while (TRUE) - { - errno = 0; - qentry = readdir (qdir); - if (qentry == NULL) - { - if (errno == 0) - *pferr = FALSE; - else - { - ulog (LOG_ERROR, "readdir: %s", strerror (errno)); - *pferr = TRUE; - } - return NULL; - } - - if (qentry->d_name[0] != '.') - { - struct uuconf_system ssys; - - /* Hack seriously; fsysdep_get_status only looks at the - zname element of the qsys argument, so if we fake that we - can read the status file. This should really be done - differently. */ - ssys.uuconf_zname = qentry->d_name; - if (fsysdep_get_status (&ssys, qstat, (boolean *) NULL)) - return zbufcpy (qentry->d_name); - - /* If fsysdep_get_status fails, it will output an error - message. We just continue with the next entry, so that - most of the status files will be displayed. */ - } - } -} - -/* Finish getting the status file. */ - -void -usysdep_all_status_free (phold) - pointer phold; -{ - DIR *qdir = (DIR *) phold; - - (void) closedir (qdir); -} - -/* Get the status of all processes holding lock files. We do this by - invoking ps after we've figured out the process entries to use. */ - -boolean -fsysdep_lock_status () -{ - DIR *qdir; - struct dirent *qentry; - int calc; - pid_t *pai; -#if HAVE_QNX_LOCKFILES - nid_t *painid; -#endif - int cgot; - int aidescs[3]; - char *zcopy, *ztok; - int cargs, iarg; - char **pazargs; - - qdir = opendir ((char *) zSlockdir); - if (qdir == NULL) - { - ulog (LOG_ERROR, "opendir (%s): %s", zSlockdir, strerror (errno)); - return FALSE; - } - - /* We look for entries that start with "LCK.." and ignore everything - else. This won't find all possible lock files, but it should - find all the locks on terminals and systems. */ - - calc = 0; - pai = NULL; - cgot = 0; -#if HAVE_QNX_LOCKFILES - painid = NULL; -#endif - while ((qentry = readdir (qdir)) != NULL) - { - char *zname; - int o; -#if HAVE_QNX_LOCKFILES - nid_t inid; - char ab[23]; - char *zend; -#else -#if HAVE_V2_LOCKFILES - int i; -#else - char ab[12]; -#endif -#endif - int cread; - int ierr; - pid_t ipid; - int icheck; - - if (strncmp (qentry->d_name, "LCK..", sizeof "LCK.." - 1) != 0) - continue; - - zname = zsysdep_in_dir (zSlockdir, qentry->d_name); - o = open ((char *) zname, O_RDONLY | O_NOCTTY, 0); - if (o < 0) - { - if (errno != ENOENT) - ulog (LOG_ERROR, "open (%s): %s", zname, strerror (errno)); - ubuffree (zname); - continue; - } - -#if HAVE_V2_LOCKFILES - cread = read (o, &i, sizeof i); -#else - cread = read (o, ab, sizeof ab - 1); -#endif - - ierr = errno; - (void) close (o); - - if (cread < 0) - { - ulog (LOG_ERROR, "read %s: %s", zname, strerror (ierr)); - ubuffree (zname); - continue; - } - - ubuffree (zname); - -#if HAVE_QNX_LOCKFILES - ab[cread] = '\0'; - ipid = (pid_t) strtol (ab, &zend, 10); - inid = (nid_t) strtol (zend, (char **) NULL, 10); -#else -#if HAVE_V2_LOCKFILES - ipid = (pid_t) i; -#else - ab[cread] = '\0'; - ipid = (pid_t) strtol (ab, (char **) NULL, 10); -#endif -#endif - -#if HAVE_QNX_LOCKFILES - printf ("%s: %ld %ld\n", qentry->d_name, (long) inid, (long) ipid); -#else - printf ("%s: %ld\n", qentry->d_name, (long) ipid); -#endif - - for (icheck = 0; icheck < cgot; icheck++) - if (pai[icheck] == ipid) - break; - if (icheck < cgot) - continue; - - if (cgot >= calc) - { - calc += 10; - pai = (pid_t *) xrealloc ((pointer) pai, calc * sizeof (pid_t)); -#if HAVE_QNX_LOCKFILES - painid = (nid_t *) xrealloc ((pointer) painid, - calc * sizeof (nid_t)); -#endif - } - - pai[cgot] = ipid; -#if HAVE_QNX_LOCKFILES - painid[cgot] = inid; -#endif - ++cgot; - } - - if (cgot == 0) - return TRUE; - - aidescs[0] = SPAWN_NULL; - aidescs[1] = 1; - aidescs[2] = 2; - - /* Parse PS_PROGRAM into an array of arguments. */ - zcopy = zbufcpy (PS_PROGRAM); - - cargs = 0; - for (ztok = strtok (zcopy, " \t"); - ztok != NULL; - ztok = strtok ((char *) NULL, " \t")) - ++cargs; - - pazargs = (char **) xmalloc ((cargs + 1) * sizeof (char *)); - - memcpy (zcopy, PS_PROGRAM, sizeof PS_PROGRAM); - for (ztok = strtok (zcopy, " \t"), iarg = 0; - ztok != NULL; - ztok = strtok ((char *) NULL, " \t"), ++iarg) - pazargs[iarg] = ztok; - pazargs[iarg] = NULL; - -#if ! HAVE_PS_MULTIPLE - /* We have to invoke ps multiple times. */ - { - int i; - char *zlast, *zset; -#if HAVE_QNX_LOCKFILES - char *zpenultimate, *zsetnid; -#endif /* HAVE_QNX_LOCKFILES */ - - zlast = pazargs[cargs - 1]; - zset = zbufalc (strlen (zlast) + 20); - -#if HAVE_QNX_LOCKFILES - /* We assume in this case that PS_PROGRAM ends with " -n -p". - Thus, the last argument is "-p" and the second-to-last - (penultimate) argument is "-n". We modify them to read "-n###" - and "-p###" where "###" is the node ID and the process ID, - respectively. This seems like quite a roundabout way of doing - things. Why don't we just leave the " -n -p" part out of - PS_PROGRAM and construct the "-n###" and "-p###" arguments here - from scratch? Because that would not fit as well with how the - code works for the other systems and would require larger - changes. */ - zpenultimate = pazargs[cargs - 2]; - zsetnid = zbufalc (strlen (zpenultimate) + 20); -#endif - - for (i = 0; i < cgot; i++) - { - pid_t ipid; - - sprintf (zset, "%s%ld", zlast, (long) pai[i]); - pazargs[cargs - 1] = zset; - -#if HAVE_QNX_LOCKFILES - sprintf (zsetnid, "%s%ld", zpenultimate, (long) painid[i]); - pazargs[cargs - 2] = zsetnid; -#endif - - ipid = ixsspawn ((const char **) pazargs, aidescs, FALSE, FALSE, - (const char *) NULL, FALSE, TRUE, - (const char *) NULL, (const char *) NULL, - (const char *) NULL); - if (ipid < 0) - ulog (LOG_ERROR, "ixsspawn: %s", strerror (errno)); - else - (void) ixswait ((unsigned long) ipid, PS_PROGRAM); - } - ubuffree (zset); -#if HAVE_QNX_LOCKFILES - ubuffree (zsetnid); -#endif - } -#else - { - char *zlast; - int i; - pid_t ipid; - - zlast = zbufalc (strlen (pazargs[cargs - 1]) + cgot * 20 + 1); - strcpy (zlast, pazargs[cargs - 1]); - for (i = 0; i < cgot; i++) - { - char ab[20]; - - sprintf (ab, "%ld", (long) pai[i]); - strcat (zlast, ab); - if (i + 1 < cgot) - strcat (zlast, ","); - } - pazargs[cargs - 1] = zlast; - - ipid = ixsspawn ((const char **) pazargs, aidescs, FALSE, FALSE, - (const char *) NULL, FALSE, TRUE, - (const char *) NULL, (const char *) NULL, - (const char *) NULL); - if (ipid < 0) - ulog (LOG_ERROR, "ixsspawn: %s", strerror (errno)); - else - (void) ixswait ((unsigned long) ipid, PS_PROGRAM); - ubuffree (zlast); - } -#endif - - ubuffree (zcopy); - xfree ((pointer) pazargs); - - return TRUE; -} diff --git a/gnu/libexec/uucp/libunix/status.c b/gnu/libexec/uucp/libunix/status.c deleted file mode 100644 index 66e1d385..0000000 --- a/gnu/libexec/uucp/libunix/status.c +++ /dev/null @@ -1,248 +0,0 @@ -/* status.c - Routines to get and set the status for a system. - - Copyright (C) 1991, 1992, 1993, 1995 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "uuconf.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> -#include <ctype.h> - -#if SPOOLDIR_HDB || SPOOLDIR_SVR4 - -/* If we are using HDB spool layout, store status using HDB status - values. SVR4 is a variant of HDB. */ - -#define MAP_STATUS 1 - -static const int aiMapstatus[] = -{ - 0, 13, 7, 6, 20, 4, 3, 2 -}; -#define CMAPENTRIES (sizeof (aiMapstatus) / sizeof (aiMapstatus[0])) - -#else /* ! SPOOLDIR_HDB && ! SPOOLDIR_SVR4 */ - -#define MAP_STATUS 0 - -#endif /* ! SPOOLDIR_HDB && ! SPOOLDIR_SVR4 */ - -/* Get the status of a system. This assumes that we are in the spool - directory. */ - -boolean -fsysdep_get_status (qsys, qret, pfnone) - const struct uuconf_system *qsys; - struct sstatus *qret; - boolean *pfnone; -{ - char *zname; - FILE *e; - char *zline; - char *zend, *znext; - boolean fbad; - int istat; - - if (pfnone != NULL) - *pfnone = FALSE; - - zname = zsysdep_in_dir (".Status", qsys->uuconf_zname); - e = fopen (zname, "r"); - if (e == NULL) - { - if (errno != ENOENT) - { - ulog (LOG_ERROR, "fopen (%s): %s", zname, strerror (errno)); - ubuffree (zname); - return FALSE; - } - zline = NULL; - } - else - { - size_t cline; - - zline = NULL; - cline = 0; - if (getline (&zline, &cline, e) <= 0) - { - xfree ((pointer) zline); - zline = NULL; - } - (void) fclose (e); - } - - if (zline == NULL) - { - /* There is either no status file for this system, or it's been - truncated, so fake a good status. */ - qret->ttype = STATUS_COMPLETE; - qret->cretries = 0; - qret->ilast = 0; - qret->cwait = 0; - qret->zstring = NULL; - if (pfnone != NULL) - *pfnone = TRUE; - ubuffree (zname); - return TRUE; - } - - /* It turns out that scanf is not used much in this program, so for - the benefit of small computers we avoid linking it in. This is - basically - - sscanf (zline, "%d %d %ld %d", &qret->ttype, &qret->cretries, - &qret->ilast, &qret->cwait); - - except that it's done with strtol. */ - - fbad = FALSE; - istat = (int) strtol (zline, &zend, 10); - if (zend == zline) - fbad = TRUE; - -#if MAP_STATUS - /* On some systems it may be appropriate to map system dependent status - values on to our status values. */ - { - int i; - - for (i = 0; i < CMAPENTRIES; ++i) - { - if (aiMapstatus[i] == istat) - { - istat = i; - break; - } - } - } -#endif /* MAP_STATUS */ - - if (istat < 0 || istat >= (int) STATUS_VALUES) - istat = (int) STATUS_COMPLETE; - qret->ttype = (enum tstatus_type) istat; - znext = zend; - qret->cretries = (int) strtol (znext, &zend, 10); - if (zend == znext) - fbad = TRUE; - znext = zend; - qret->ilast = strtol (znext, &zend, 10); - if (zend == znext) - fbad = TRUE; - znext = zend; - qret->cwait = (int) strtol (znext, &zend, 10); - if (zend == znext) - fbad = TRUE; - - if (! fbad) - { - znext = zend; - while (isspace (BUCHAR (*znext))) - ++znext; - if (*znext == '\0') - qret->zstring = NULL; - else - { - if (*znext == '"') - ++znext; - qret->zstring = zbufcpy (znext); - zend = qret->zstring + strlen (qret->zstring); - while (zend != qret->zstring && *zend != ' ') - --zend; - if (*zend == '"' && zend != qret->zstring) - --zend; - if (zend != qret->zstring) - *zend = '\0'; - else - { - ubuffree (qret->zstring); - qret->zstring = NULL; - } - } - } - - xfree ((pointer) zline); - - if (fbad) - { - ulog (LOG_ERROR, "%s: Bad status file format", zname); - ubuffree (zname); - return FALSE; - } - - ubuffree (zname); - - return TRUE; -} - -/* Set the status of a remote system. This assumes the system is - locked when this is called, and that the program is in the spool - directory. */ - -boolean -fsysdep_set_status (qsys, qset) - const struct uuconf_system *qsys; - const struct sstatus *qset; -{ - char *zname; - FILE *e; - int istat; - - zname = zsysdep_in_dir (".Status", qsys->uuconf_zname); - - e = esysdep_fopen (zname, TRUE, FALSE, TRUE); - ubuffree (zname); - if (e == NULL) - return FALSE; - istat = (int) qset->ttype; - -#if MAP_STATUS - /* On some systems it may be appropriate to map istat onto a system - dependent number. */ - if (istat >= 0 && istat < CMAPENTRIES) - istat = aiMapstatus[istat]; -#endif /* MAP_STATUS */ - - fprintf (e, "%d %d %ld %d ", istat, qset->cretries, qset->ilast, - qset->cwait); - -#if SPOOLDIR_SVR4 - fprintf (e, "\"%s\"", azStatus[(int) qset->ttype]); -#else - fprintf (e, "%s", azStatus[(int) qset->ttype]); -#endif - - fprintf (e, " %s\n", qsys->uuconf_zname); - if (fclose (e) != 0) - { - ulog (LOG_ERROR, "fclose: %s", strerror (errno)); - return FALSE; - } - - return TRUE; -} diff --git a/gnu/libexec/uucp/libunix/strerr.c b/gnu/libexec/uucp/libunix/strerr.c deleted file mode 100644 index 8e7480f..0000000 --- a/gnu/libexec/uucp/libunix/strerr.c +++ /dev/null @@ -1,24 +0,0 @@ -/* strerr.c - Return a string for a Unix errno value. */ - -#include "uucp.h" - -#include <errno.h> - -#ifndef sys_nerr -extern int sys_nerr; -#endif -#ifndef sys_errlist -extern char *sys_errlist[]; -#endif - -#undef strerror - -char * -strerror (ierr) - int ierr; -{ - if (ierr >= 0 && ierr < sys_nerr) - return sys_errlist[ierr]; - return (char *) "unknown error"; -} diff --git a/gnu/libexec/uucp/libunix/tli.c b/gnu/libexec/uucp/libunix/tli.c deleted file mode 100644 index 0330646..0000000 --- a/gnu/libexec/uucp/libunix/tli.c +++ /dev/null @@ -1,629 +0,0 @@ -/* tli.c - Code to handle TLI connections. - - Copyright (C) 1992, 1993, 1994 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#if USE_RCS_ID -const char tli_rcsid[] = "$FreeBSD$"; -#endif - -#if HAVE_TLI - -#include "sysdep.h" -#include "uudefs.h" -#include "uuconf.h" -#include "conn.h" -#include "system.h" - -#include <errno.h> -#include <paths.h> - -#if HAVE_SYS_IOCTL_H -#include <sys/ioctl.h> -#endif - -#if HAVE_TIUSER_H -#include <tiuser.h> -#else -#if HAVE_XTI_H -#include <xti.h> -#else -#if HAVE_SYS_TLI_H -#include <sys/tli.h> -#endif -#endif -#endif - -#if HAVE_STROPTS_H -#include <stropts.h> -#endif - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -#ifndef O_RDONLY -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#endif - -#ifndef FD_CLOEXEC -#define FD_CLOEXEC 1 -#endif - -/* The arguments to t_alloca have two different names. I want the - SVID ones, not the XPG3 ones. */ -#ifndef T_BIND -#define T_BIND T_BIND_STR -#endif -#ifndef T_CALL -#define T_CALL T_CALL_STR -#endif - -/* Hopefully these externs will not cause any trouble. This is how - they are shown in the SVID. */ -extern int t_errno; -extern char *t_errlist[]; -extern int t_nerr; - -#ifndef HAVE_TIUSER_H -#ifndef t_alloc -extern pointer t_alloc (); -#endif -#endif - -/* This code handles TLI connections. It's Unix specific. It's - largely based on code from Unix Network Programming, by W. Richard - Stevens. */ - -/* Local functions. */ -static const char *ztlierror P((void)); -static void utli_free P((struct sconnection *qconn)); -static boolean ftli_push P((struct sconnection *qconn)); -static boolean ftli_open P((struct sconnection *qconn, long ibaud, - boolean fwait)); -static boolean ftli_close P((struct sconnection *qconn, - pointer puuconf, - struct uuconf_dialer *qdialer, - boolean fsuccess)); -static boolean ftli_dial P((struct sconnection *qconn, pointer puuconf, - const struct uuconf_system *qsys, - const char *zphone, - struct uuconf_dialer *qdialer, - enum tdialerfound *ptdialer)); - -/* The command table for a TLI connection. */ -static const struct sconncmds stlicmds = -{ - utli_free, - NULL, /* pflock */ - NULL, /* pfunlock */ - ftli_open, - ftli_close, - ftli_dial, - fsysdep_conn_read, - fsysdep_conn_write, - fsysdep_conn_io, - NULL, /* pfbreak */ - NULL, /* pfset */ - NULL, /* pfcarrier */ - fsysdep_conn_chat, - NULL /* pibaud */ -}; - -/* Get a TLI error string. */ - -static const char * -ztlierror () -{ - if (t_errno == TSYSERR) - return strerror (errno); - if (t_errno < 0 || t_errno >= t_nerr) - return "Unknown TLI error"; - return t_errlist[t_errno]; -} - -/* Initialize a TLI connection. This may be called with qconn->qport - NULL, when opening standard input as a TLI connection. */ - -boolean -fsysdep_tli_init (qconn) - struct sconnection *qconn; -{ - struct ssysdep_conn *q; - - q = (struct ssysdep_conn *) xmalloc (sizeof (struct ssysdep_conn)); - q->o = -1; - q->ord = -1; - q->owr = -1; - q->zdevice = NULL; - q->iflags = -1; - q->iwr_flags = -1; - q->fterminal = FALSE; - q->ftli = TRUE; - q->ibaud = 0; - - qconn->psysdep = (pointer) q; - qconn->qcmds = &stlicmds; - return TRUE; -} - -/* Free a TLI connection. */ - -static void -utli_free (qconn) - struct sconnection *qconn; -{ - xfree (qconn->psysdep); -} - -/* Push all desired modules onto a TLI stream. If the user requests a - STREAMS connection without giving a list of modules, we just push - tirdwr. If the I_PUSH ioctl is not defined on this system, we just - ignore any list of modules. */ - -static boolean -ftli_push (qconn) - struct sconnection *qconn; -{ -#ifdef I_PUSH - - struct ssysdep_conn *qsysdep; - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - if (qconn->qport->uuconf_u.uuconf_stli.uuconf_pzpush != NULL) - { - char **pz; - - for (pz = qconn->qport->uuconf_u.uuconf_stli.uuconf_pzpush; - *pz != NULL; - pz++) - { - if (ioctl (qsysdep->o, I_PUSH, *pz) < 0) - { - ulog (LOG_ERROR, "ioctl (I_PUSH, %s): %s", *pz, - strerror (errno)); - return FALSE; - } - } - } - else if (qconn->qport->uuconf_u.uuconf_stli.uuconf_fstream) - { - if (ioctl (qsysdep->o, I_PUSH, "tirdwr") < 0) - { - ulog (LOG_ERROR, "ioctl (I_PUSH, tirdwr): %s", - strerror (errno)); - return FALSE; - } - } - - /* If we have just put the connection into stream mode, we must turn - off the TLI flag to avoid using TLI calls on it. */ - if (qconn->qport->uuconf_u.uuconf_stli.uuconf_fstream) - qsysdep->ftli = FALSE; - -#endif /* defined (I_PUSH) */ - - return TRUE; -} - -/* Open a TLI connection. If the fwait argument is TRUE, we are - running as a server. Otherwise we are just trying to reach another - system. */ - -static boolean -ftli_open (qconn, ibaud, fwait) - struct sconnection *qconn; - long ibaud; - boolean fwait; -{ - struct ssysdep_conn *qsysdep; - const char *zdevice; - char *zfreedev; - const char *zservaddr; - char *zfreeaddr; - uid_t ieuid; - boolean fswap; - struct t_bind *qtbind; - struct t_call *qtcall; - - /* Unlike most other device types, we don't bother to call - ulog_device here, because fconn_open calls it with the name of - the port anyhow. */ - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - zdevice = qconn->qport->uuconf_u.uuconf_stli.uuconf_zdevice; - if (zdevice == NULL) - zdevice = qconn->qport->uuconf_zname; - - zfreedev = NULL; - if (*zdevice != '/') - { - zfreedev = zbufalc (sizeof _PATH_DEV + strlen (zdevice)); - sprintf (zfreedev, "%s%s", _PATH_DEV, zdevice); - zdevice = zfreedev; - } - - /* If we are acting as a server, swap to our real user ID before - calling t_open. This will permit the server to use privileged - TCP ports when invoked by root. We only swap if our effective - user ID is not root, so that the program can also be made suid - root in order to get privileged ports when invoked by anybody. */ - fswap = fwait && geteuid () != 0; - if (fswap) - { - if (! fsuser_perms (&ieuid)) - { - ubuffree (zfreedev); - return FALSE; - } - } - - qsysdep->o = t_open (zdevice, O_RDWR, (struct t_info *) NULL); - if (qsysdep->o < 0) - { - if (fswap) - (void) fsuucp_perms ((long) ieuid); - ulog (LOG_ERROR, "t_open (%s): %s", zdevice, ztlierror ()); - ubuffree (zfreedev); - return FALSE; - } - - if (fcntl (qsysdep->o, F_SETFD, - fcntl (qsysdep->o, F_GETFD, 0) | FD_CLOEXEC) < 0) - { - if (fswap) - (void) fsuucp_perms ((long) ieuid); - ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - ubuffree (zfreedev); - (void) t_close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } - - qsysdep->iflags = fcntl (qsysdep->o, F_GETFL, 0); - if (qsysdep->iflags < 0) - { - if (fswap) - (void) fsuucp_perms ((long) ieuid); - ulog (LOG_ERROR, "fcntl: %s", strerror (errno)); - ubuffree (zfreedev); - (void) t_close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } - - /* We save our process ID in the qconn structure. This is checked - in ftli_close. */ - qsysdep->ipid = getpid (); - - /* If we aren't waiting for a connection, we can bind to any local - address, and then we're finished. */ - if (! fwait) - { - /* fswap is known to be FALSE here. */ - ubuffree (zfreedev); - if (t_bind (qsysdep->o, (struct t_bind *) NULL, - (struct t_bind *) NULL) < 0) - { - ulog (LOG_ERROR, "t_bind: %s", ztlierror ()); - (void) t_close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } - return TRUE; - } - - /* Run as a server and wait for a new connection. The code in - uucico.c has already detached us from our controlling terminal. - From this point on if the server gets an error we exit; we only - return if we have received a connection. It would be more robust - to respawn the server if it fails; someday. */ - qtbind = (struct t_bind *) t_alloc (qsysdep->o, T_BIND, T_ALL); - if (qtbind == NULL) - { - if (fswap) - (void) fsuucp_perms ((long) ieuid); - ulog (LOG_FATAL, "t_alloc (T_BIND): %s", ztlierror ()); - } - - zservaddr = qconn->qport->uuconf_u.uuconf_stli.uuconf_zservaddr; - if (zservaddr == NULL) - { - if (fswap) - (void) fsuucp_perms ((long) ieuid); - ulog (LOG_FATAL, "Can't run as TLI server; no server address"); - } - - zfreeaddr = zbufcpy (zservaddr); - qtbind->addr.len = cescape (zfreeaddr); - if (qtbind->addr.len > qtbind->addr.maxlen) - { - if (fswap) - (void) fsuucp_perms ((long) ieuid); - ulog (LOG_FATAL, "%s: TLI server address too long (max %d)", - zservaddr, qtbind->addr.maxlen); - } - memcpy (qtbind->addr.buf, zfreeaddr, qtbind->addr.len); - ubuffree (zfreeaddr); - - qtbind->qlen = 5; - - if (t_bind (qsysdep->o, qtbind, (struct t_bind *) NULL) < 0) - { - if (fswap) - (void) fsuucp_perms ((long) ieuid); - ulog (LOG_FATAL, "t_bind (%s): %s", zservaddr, ztlierror ()); - } - - if (fswap) - { - if (! fsuucp_perms ((long) ieuid)) - ulog (LOG_FATAL, "Could not swap back to UUCP user permissions"); - } - - (void) t_free ((pointer) qtbind, T_BIND); - - qtcall = (struct t_call *) t_alloc (qsysdep->o, T_CALL, T_ALL); - if (qtcall == NULL) - ulog (LOG_FATAL, "t_alloc (T_CALL): %s", ztlierror ()); - - while (! FGOT_SIGNAL ()) - { - int onew; - pid_t ipid; - - DEBUG_MESSAGE0 (DEBUG_PORT, - "ftli_open: Waiting for connections"); - - if (t_listen (qsysdep->o, qtcall) < 0) - ulog (LOG_FATAL, "t_listen: %s", ztlierror ()); - - onew = t_open (zdevice, O_RDWR, (struct t_info *) NULL); - if (onew < 0) - ulog (LOG_FATAL, "t_open (%s): %s", zdevice, ztlierror ()); - - if (fcntl (onew, F_SETFD, - fcntl (onew, F_GETFD, 0) | FD_CLOEXEC) < 0) - ulog (LOG_FATAL, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - - if (t_bind (onew, (struct t_bind *) NULL, (struct t_bind *) NULL) < 0) - ulog (LOG_FATAL, "t_bind: %s", ztlierror ()); - - if (t_accept (qsysdep->o, onew, qtcall) < 0) - { - /* We may have received a disconnect. */ - if (t_errno != TLOOK) - ulog (LOG_FATAL, "t_accept: %s", ztlierror ()); - if (t_rcvdis (qsysdep->o, (struct t_discon *) NULL) < 0) - ulog (LOG_FATAL, "t_rcvdis: %s", ztlierror ()); - (void) t_close (onew); - continue; - } - - DEBUG_MESSAGE0 (DEBUG_PORT, - "ftli_open: Got connection; forking"); - - ipid = ixsfork (); - if (ipid < 0) - ulog (LOG_FATAL, "fork: %s", strerror (errno)); - if (ipid == 0) - { - ulog_close (); - - (void) t_close (qsysdep->o); - qsysdep->o = onew; - - /* Push any desired modules. */ - if (! ftli_push (qconn)) - _exit (EXIT_FAILURE); - - /* Now we fork and let our parent die, so that we become - a child of init. This lets the main server code wait - for its child and then continue without accumulating - zombie children. */ - ipid = ixsfork (); - if (ipid < 0) - { - ulog (LOG_ERROR, "fork: %s", strerror (errno)); - _exit (EXIT_FAILURE); - } - - if (ipid != 0) - _exit (EXIT_SUCCESS); - - ulog_id (getpid ()); - - return TRUE; - } - - (void) t_close (onew); - - /* Now wait for the child. */ - (void) ixswait ((unsigned long) ipid, (const char *) NULL); - } - - /* We got a signal. */ - usysdep_exit (FALSE); - - /* Avoid compiler warnings. */ - return FALSE; -} - -/* Close the port. */ - -/*ARGSUSED*/ -static boolean -ftli_close (qconn, puuconf, qdialer, fsuccess) - struct sconnection *qconn; - pointer puuconf; - struct uuconf_dialer *qdialer; - boolean fsuccess; -{ - struct ssysdep_conn *qsysdep; - boolean fret; - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - fret = TRUE; - if (qsysdep->o >= 0) - { - if (qsysdep->ftli) - { - if (t_close (qsysdep->o) < 0) - { - ulog (LOG_ERROR, "t_close: %s", ztlierror ()); - fret = FALSE; - } - } - else - { - if (close (qsysdep->o) < 0) - { - ulog (LOG_ERROR, "close: %s", strerror (errno)); - fret = FALSE; - } - } - - qsysdep->o = -1; - } - - /* If the current pid is not the one we used to open the port, then - we must have forked up above and we are now the child. In this - case, we are being called from within the fendless loop in - uucico.c. We return FALSE to force the loop to end and the child - to exit. This should be handled in a cleaner fashion. */ - if (qsysdep->ipid != getpid ()) - fret = FALSE; - - return fret; -} - -/* Dial out on a TLI port, so to speak: connect to a remote computer. */ - -/*ARGSUSED*/ -static boolean -ftli_dial (qconn, puuconf, qsys, zphone, qdialer, ptdialerfound) - struct sconnection *qconn; - pointer puuconf; - const struct uuconf_system *qsys; - const char *zphone; - struct uuconf_dialer *qdialer; - enum tdialerfound *ptdialerfound; -{ - struct ssysdep_conn *qsysdep; - char **pzdialer; - const char *zaddr; - struct t_call *qtcall; - char *zescape; - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - *ptdialerfound = DIALERFOUND_FALSE; - - pzdialer = qconn->qport->uuconf_u.uuconf_stli.uuconf_pzdialer; - if (*pzdialer == NULL) - pzdialer = NULL; - - /* If the first dialer is "TLI" or "TLIS", we use the first token - (pzdialer[1]) as the address to connect to. */ - zaddr = zphone; - if (pzdialer != NULL - && (strcmp (pzdialer[0], "TLI") == 0 - || strcmp (pzdialer[0], "TLIS") == 0)) - { - if (pzdialer[1] == NULL) - ++pzdialer; - else - { - if (strcmp (pzdialer[1], "\\D") != 0 - && strcmp (pzdialer[1], "\\T") != 0) - zaddr = pzdialer[1]; - pzdialer += 2; - } - } - - if (zaddr == NULL) - { - ulog (LOG_ERROR, "No address for TLI connection"); - return FALSE; - } - - qtcall = (struct t_call *) t_alloc (qsysdep->o, T_CALL, T_ADDR); - if (qtcall == NULL) - { - ulog (LOG_ERROR, "t_alloc (T_CALL): %s", ztlierror ()); - return FALSE; - } - - zescape = zbufcpy (zaddr); - qtcall->addr.len = cescape (zescape); - if (qtcall->addr.len > qtcall->addr.maxlen) - { - ulog (LOG_ERROR, "%s: TLI address too long (max %d)", zaddr, - qtcall->addr.maxlen); - ubuffree (zescape); - return FALSE; - } - memcpy (qtcall->addr.buf, zescape, qtcall->addr.len); - ubuffree (zescape); - - if (t_connect (qsysdep->o, qtcall, (struct t_call *) NULL) < 0) - { - if (t_errno != TLOOK) - ulog (LOG_ERROR, "t_connect: %s", ztlierror ()); - else - { - if (t_rcvdis (qsysdep->o, (struct t_discon *) NULL) < 0) - ulog (LOG_ERROR, "t_rcvdis: %s", ztlierror ()); - else - ulog (LOG_ERROR, "Connection refused"); - } - return FALSE; - } - - /* We've connected to the remote. Push any desired modules. */ - if (! ftli_push (qconn)) - return FALSE; - - /* Handle the rest of the dialer sequence. */ - if (pzdialer != NULL && *pzdialer != NULL) - { - if (! fconn_dial_sequence (qconn, puuconf, pzdialer, qsys, zphone, - qdialer, ptdialerfound)) - return FALSE; - } - - return TRUE; -} - -#endif /* HAVE_TLI */ diff --git a/gnu/libexec/uucp/libunix/tmpfil.c b/gnu/libexec/uucp/libunix/tmpfil.c deleted file mode 100644 index f2f5ba8..0000000 --- a/gnu/libexec/uucp/libunix/tmpfil.c +++ /dev/null @@ -1,84 +0,0 @@ -/* tmpfil.c - Get a temporary file name. - - Copyright (C) 1991, 1992, 1993 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "uuconf.h" -#include "system.h" -#include "sysdep.h" - -#define ZDIGS \ - "0123456789abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-" -#define CDIGS (sizeof ZDIGS - 1) - -/*ARGSUSED*/ -char * -zstemp_file (qsys) - const struct uuconf_system *qsys; -{ - static int icount; - const char *const zdigs = ZDIGS; - char ab[14]; - pid_t ime; - int iset; - - ab[0] = 'T'; - ab[1] = 'M'; - ab[2] = '.'; - - ime = getpid (); - iset = 3; - while (ime > 0 && iset < 10) - { - ab[iset] = zdigs[ime % CDIGS]; - ime /= CDIGS; - ++iset; - } - - ab[iset] = '.'; - ++iset; - - ab[iset] = zdigs[icount / CDIGS]; - ++iset; - ab[iset] = zdigs[icount % CDIGS]; - ++iset; - - ab[iset] = '\0'; - - ++icount; - if (icount >= CDIGS * CDIGS) - icount = 0; - -#if SPOOLDIR_V2 || SPOOLDIR_BSD42 - return zbufcpy (ab); -#endif -#if SPOOLDIR_BSD43 || SPOOLDIR_ULTRIX || SPOOLDIR_TAYLOR - return zsysdep_in_dir (".Temp", ab); -#endif -#if SPOOLDIR_HDB || SPOOLDIR_SVR4 - return zsysdep_in_dir (qsys->uuconf_zname, ab); -#endif -} diff --git a/gnu/libexec/uucp/libunix/trunc.c b/gnu/libexec/uucp/libunix/trunc.c deleted file mode 100644 index c93e82e..0000000 --- a/gnu/libexec/uucp/libunix/trunc.c +++ /dev/null @@ -1,157 +0,0 @@ -/* trunc.c - Truncate a file to zero length. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -#ifndef FD_CLOEXEC -#define FD_CLOEXEC 1 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -/* External functions. */ -#ifndef lseek -extern off_t lseek (); -#endif - -/* Truncate a file to zero length. If this fails, it closes and - removes the file. We support a number of different means of - truncation, which is probably a waste of time since this function - is currently only called when the 'f' protocol resends a file. */ - -#if HAVE_FTRUNCATE -#undef HAVE_LTRUNC -#define HAVE_LTRUNC 0 -#endif - -#if ! HAVE_FTRUNCATE && ! HAVE_LTRUNC -#ifdef F_CHSIZE -#define HAVE_F_CHSIZE 1 -#else /* ! defined (F_CHSIZE) */ -#ifdef F_FREESP -#define HAVE_F_FREESP 1 -#endif /* defined (F_FREESP) */ -#endif /* ! defined (F_CHSIZE) */ -#endif /* ! HAVE_FTRUNCATE && ! HAVE_LTRUNC */ - -openfile_t -esysdep_truncate (e, zname) - openfile_t e; - const char *zname; -{ - int o; - -#if HAVE_FTRUNCATE || HAVE_LTRUNC || HAVE_F_CHSIZE || HAVE_F_FREESP - int itrunc; - - if (! ffilerewind (e)) - { - ulog (LOG_ERROR, "rewind: %s", strerror (errno)); - (void) ffileclose (e); - (void) remove (zname); - return EFILECLOSED; - } - -#if USE_STDIO - o = fileno (e); -#else - o = e; -#endif - -#if HAVE_FTRUNCATE - itrunc = ftruncate (o, 0); -#endif -#if HAVE_LTRUNC - itrunc = ltrunc (o, (long) 0, SEEK_SET); -#endif -#if HAVE_F_CHSIZE - itrunc = fcntl (o, F_CHSIZE, (off_t) 0); -#endif -#if HAVE_F_FREESP - /* This selection is based on an implementation of ftruncate by - kucharsk@Solbourne.com (William Kucharski). */ - { - struct flock fl; - - fl.l_whence = 0; - fl.l_len = 0; - fl.l_start = 0; - fl.l_type = F_WRLCK; - - itrunc = fcntl (o, F_FREESP, &fl); - } -#endif - - if (itrunc != 0) - { -#if HAVE_FTRUNCATE - ulog (LOG_ERROR, "ftruncate: %s", strerror (errno)); -#endif -#ifdef HAVE_LTRUNC - ulog (LOG_ERROR, "ltrunc: %s", strerror (errno)); -#endif -#ifdef HAVE_F_CHSIZE - ulog (LOG_ERROR, "fcntl (F_CHSIZE): %s", strerror (errno)); -#endif -#ifdef HAVE_F_FREESP - ulog (LOG_ERROR, "fcntl (F_FREESP): %s", strerror (errno)); -#endif - - (void) ffileclose (e); - (void) remove (zname); - return EFILECLOSED; - } - - return e; -#else /* ! (HAVE_FTRUNCATE || HAVE_LTRUNC || HAVE_F_CHSIZE || HAVE_F_FREESP) */ - (void) ffileclose (e); - (void) remove (zname); - - o = creat ((char *) zname, IPRIVATE_FILE_MODE); - - if (o == -1) - { - ulog (LOG_ERROR, "creat (%s): %s", zname, strerror (errno)); - return EFILECLOSED; - } - - if (fcntl (o, F_SETFD, fcntl (o, F_GETFD, 0) | FD_CLOEXEC) < 0) - { - ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - (void) close (o); - return EFILECLOSED; - } - -#if USE_STDIO - e = fdopen (o, (char *) BINWRITE); - - if (e == NULL) - { - ulog (LOG_ERROR, "fdopen (%s): %s", zname, strerror (errno)); - (void) close (o); - (void) remove (zname); - return NULL; - } -#else /* ! USE_STDIO */ - e = o; -#endif /* ! USE_STDIO */ - - return e; -#endif /* ! (HAVE_FTRUNCATE || HAVE_LTRUNC || HAVE_F_CHSIZE || HAVE_F_FREESP) */ -} diff --git a/gnu/libexec/uucp/libunix/uacces.c b/gnu/libexec/uucp/libunix/uacces.c deleted file mode 100644 index 8f37a8e..0000000 --- a/gnu/libexec/uucp/libunix/uacces.c +++ /dev/null @@ -1,205 +0,0 @@ -/* uacces.c - Check access to a file by user name. - - Copyright (C) 1992 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" - -#include <pwd.h> -#include <errno.h> - -#if HAVE_GETGRENT -#include <grp.h> -#if GETGRENT_DECLARATION_OK -#ifndef getgrent -extern struct group *getgrent (); -#endif -#endif -#endif /* HAVE_GETGRENT */ - -#if GETPWNAM_DECLARATION_OK -#ifndef getpwnam -extern struct passwd *getpwnam (); -#endif -#endif - -/* Do access(2) on a stat structure, except that the user name is - provided. If the user name in zuser is NULL, require the file to - be accessible to the world. Return TRUE if access is permitted, - FALSE otherwise. This does not log an error message. */ - -boolean -fsuser_access (q, imode, zuser) - const struct stat *q; - int imode; - const char *zuser; -{ - static char *zuser_hold; - static uid_t iuid_hold; - static gid_t igid_hold; - static int cgroups_hold; - static gid_t *paigroups_hold; - int ir, iw, ix, iand; - - if (imode == F_OK) - return TRUE; - - if (zuser != NULL) - { - /* We keep static variables around for the last user we did, to - avoid looking up a user multiple times. */ - if (zuser_hold == NULL || strcmp (zuser_hold, zuser) != 0) - { - struct passwd *qpwd; - - if (zuser_hold != NULL) - { - ubuffree (zuser_hold); - zuser_hold = NULL; - cgroups_hold = 0; - xfree ((pointer) paigroups_hold); - paigroups_hold = NULL; - } - - qpwd = getpwnam ((char *) zuser); - if (qpwd == NULL) - { - /* Check this as a remote request. */ - zuser = NULL; - } - else - { -#if HAVE_GETGRENT - struct group *qg; -#endif - - zuser_hold = zbufcpy (zuser); - - iuid_hold = qpwd->pw_uid; - igid_hold = qpwd->pw_gid; - -#if HAVE_GETGRENT - /* Get the list of groups for this user. This is - definitely more appropriate for BSD than for System - V. It may just be a waste of time, and perhaps it - should be configurable. */ - setgrent (); - while ((qg = getgrent ()) != NULL) - { - const char **pz; - - if (qg->gr_gid == igid_hold) - continue; - for (pz = (const char **) qg->gr_mem; *pz != NULL; pz++) - { - if ((*pz)[0] == *zuser - && strcmp (*pz, zuser) == 0) - { - paigroups_hold = ((gid_t *) - (xrealloc - ((pointer) paigroups_hold, - ((cgroups_hold + 1) - * sizeof (gid_t))))); - paigroups_hold[cgroups_hold] = qg->gr_gid; - ++cgroups_hold; - break; - } - } - } - endgrent (); -#endif - } - } - } - - - /* Now do the actual access check. */ - - if (zuser != NULL) - { - /* The superuser can do anything. */ - if (iuid_hold == 0) - return TRUE; - - /* If this is the uid we're running under, there's no point to - checking access further, because when we actually try the - operation the system will do the checking for us. */ - if (iuid_hold == geteuid ()) - return TRUE; - } - - ir = S_IROTH; - iw = S_IWOTH; - ix = S_IXOTH; - - if (zuser != NULL) - { - if (iuid_hold == q->st_uid) - { - ir = S_IRUSR; - iw = S_IWUSR; - ix = S_IXUSR; - } - else - { - boolean fgroup; - - fgroup = FALSE; - if (igid_hold == q->st_gid) - fgroup = TRUE; - else - { - int i; - - for (i = 0; i < cgroups_hold; i++) - { - if (paigroups_hold[i] == q->st_gid) - { - fgroup = TRUE; - break; - } - } - } - - if (fgroup) - { - ir = S_IRGRP; - iw = S_IWGRP; - ix = S_IXGRP; - } - } - } - - iand = 0; - if ((imode & R_OK) != 0) - iand |= ir; - if ((imode & W_OK) != 0) - iand |= iw; - if ((imode & X_OK) != 0) - iand |= ix; - - return (q->st_mode & iand) == iand; -} diff --git a/gnu/libexec/uucp/libunix/ultspl.c b/gnu/libexec/uucp/libunix/ultspl.c deleted file mode 100644 index 34921d2..0000000 --- a/gnu/libexec/uucp/libunix/ultspl.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ultspl.c - See whether there is an Ultrix spool directory for a system. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -boolean -fsultrix_has_spool (zsystem) - const char *zsystem; -{ - char *z; - boolean fret; - - z = zsysdep_in_dir ("sys", zsystem); - fret = fsysdep_directory (z); - ubuffree (z); - return fret; -} diff --git a/gnu/libexec/uucp/libunix/unknwn.c b/gnu/libexec/uucp/libunix/unknwn.c deleted file mode 100644 index 76f5345..0000000 --- a/gnu/libexec/uucp/libunix/unknwn.c +++ /dev/null @@ -1,43 +0,0 @@ -/* unknwn.c - Check remote.unknown shell script. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -/* Run the remote.unknown shell script. If it succeeds, we return - FALSE because that means that the system is not permitted to log - in. If the execution fails, we return TRUE. */ - -boolean -fsysdep_unknown_caller (zscript, zsystem) - const char *zscript; - const char *zsystem; -{ - const char *azargs[3]; - int aidescs[3]; - pid_t ipid; - - azargs[0] = zscript; - azargs[1] = zsystem; - azargs[2] = NULL; - - aidescs[0] = SPAWN_NULL; - aidescs[1] = SPAWN_NULL; - aidescs[2] = SPAWN_NULL; - - ipid = ixsspawn (azargs, aidescs, TRUE, TRUE, (const char *) NULL, FALSE, - TRUE, (const char *) NULL, (const char *) NULL, - (const char *) NULL); - if (ipid < 0) - { - ulog (LOG_ERROR, "ixsspawn: %s", strerror (errno)); - return FALSE; - } - - return ixswait ((unsigned long) ipid, (const char *) NULL) != 0; -} diff --git a/gnu/libexec/uucp/libunix/uuto.c b/gnu/libexec/uucp/libunix/uuto.c deleted file mode 100644 index debba9d..0000000 --- a/gnu/libexec/uucp/libunix/uuto.c +++ /dev/null @@ -1,31 +0,0 @@ -/* uuto.c - Translate a destination for uuto. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -/* Translate a uuto destination for Unix. */ - -char * -zsysdep_uuto (zdest, zlocalname) - const char *zdest; - const char *zlocalname; -{ - const char *zexclam; - char *zto; - - zexclam = strrchr (zdest, '!'); - if (zexclam == NULL) - return NULL; - zto = (char *) zbufalc (zexclam - zdest - + sizeof "!~/receive///" - + strlen (zexclam) - + strlen (zlocalname)); - memcpy (zto, zdest, (size_t) (zexclam - zdest)); - sprintf (zto + (zexclam - zdest), "!~/receive/%s/%s/", - zexclam + 1, zlocalname); - return zto; -} diff --git a/gnu/libexec/uucp/libunix/walk.c b/gnu/libexec/uucp/libunix/walk.c deleted file mode 100644 index 85b94da..0000000 --- a/gnu/libexec/uucp/libunix/walk.c +++ /dev/null @@ -1,58 +0,0 @@ -/* walk.c - Walk a directory tree. */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#if HAVE_FTW_H -#include <ftw.h> -#endif - -static int iswalk_dir P((const char *zname, struct stat *qstat, int iflag)); - -/* Walk a directory tree. */ - -static size_t cSlen; -static void (*puSfn) P((const char *zfull, const char *zrelative, - pointer pinfo)); -static pointer pSinfo; - -boolean -usysdep_walk_tree (zdir, pufn, pinfo) - const char *zdir; - void (*pufn) P((const char *zfull, const char *zrelative, - pointer pinfo)); - pointer pinfo; -{ - cSlen = strlen (zdir) + 1; - puSfn = pufn; - pSinfo = pinfo; - return ftw ((char *) zdir, iswalk_dir, 5) == 0; -} - -/* Pass a file found in the directory tree to the system independent - function. */ - -/*ARGSUSED*/ -static int -iswalk_dir (zname, qstat, iflag) - const char *zname; - struct stat *qstat; - int iflag; -{ - char *zcopy; - - if (iflag != FTW_F) - return 0; - - zcopy = zbufcpy (zname + cSlen); - - (*puSfn) (zname, zcopy, pSinfo); - - ubuffree (zcopy); - - return 0; -} diff --git a/gnu/libexec/uucp/libunix/wldcrd.c b/gnu/libexec/uucp/libunix/wldcrd.c deleted file mode 100644 index 1aa17fa..0000000 --- a/gnu/libexec/uucp/libunix/wldcrd.c +++ /dev/null @@ -1,213 +0,0 @@ -/* wldcrd.c - Expand wildcards. - - Copyright (C) 1991, 1992, 1993 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <ctype.h> -#include <errno.h> - -#if HAVE_GLOB && ! HAVE_GLOB_H -#undef HAVE_GLOB -#define HAVE_GLOB 0 -#endif - -#if HAVE_GLOB -#include <glob.h> -#endif - -/* Local variables to hold the wildcard in progress. */ - -#if HAVE_GLOB -static glob_t sSglob; -static int iSglob; -#else -static char *zSwildcard_alloc; -static char *zSwildcard; -#endif - -/* Start getting a wildcarded file spec. Use the glob function if it - is available, and otherwise use the shell. */ - -boolean -fsysdep_wildcard_start (zfile) - const char *zfile; -{ -#if HAVE_GLOB - -#if DEBUG > 0 - if (*zfile != '/') - ulog (LOG_FATAL, "fsysdep_wildcard: %s: Can't happen", zfile); -#endif - - if (glob (zfile, 0, (int (*) ()) NULL, &sSglob) != 0) - sSglob.gl_pathc = 0; - iSglob = 0; - return TRUE; - -#else /* ! HAVE_GLOB */ - - char *zcmd, *zto; - const char *zfrom; - size_t c; - const char *azargs[4]; - FILE *e; - pid_t ipid; - -#if DEBUG > 0 - if (*zfile != '/') - ulog (LOG_FATAL, "fsysdep_wildcard: %s: Can't happen", zfile); -#endif - - zSwildcard_alloc = NULL; - zSwildcard = NULL; - - zcmd = zbufalc (sizeof ECHO_PROGRAM + sizeof " " + 2 * strlen (zfile)); - memcpy (zcmd, ECHO_PROGRAM, sizeof ECHO_PROGRAM - 1); - zto = zcmd + sizeof ECHO_PROGRAM - 1; - *zto++ = ' '; - zfrom = zfile; - while (*zfrom != '\0') - { - /* To avoid shell trickery, we quote all characters except - letters, digits, and wildcard specifiers. We don't quote '/' - to avoid an Ultrix sh bug. */ - if (! isalnum (*zfrom) - && *zfrom != '*' - && *zfrom != '?' - && *zfrom != '[' - && *zfrom != ']' - && *zfrom != '/') - *zto++ = '\\'; - *zto++ = *zfrom++; - } - *zto = '\0'; - - azargs[0] = "/bin/sh"; - azargs[1] = "-c"; - azargs[2] = zcmd; - azargs[3] = NULL; - - e = espopen (azargs, TRUE, &ipid); - - ubuffree (zcmd); - - if (e == NULL) - { - ulog (LOG_ERROR, "espopen: %s", strerror (errno)); - return FALSE; - } - - zSwildcard_alloc = NULL; - c = 0; - if (getline (&zSwildcard_alloc, &c, e) <= 0) - { - xfree ((pointer) zSwildcard_alloc); - zSwildcard_alloc = NULL; - } - - if (ixswait ((unsigned long) ipid, ECHO_PROGRAM) != 0) - { - xfree ((pointer) zSwildcard_alloc); - return FALSE; - } - - if (zSwildcard_alloc == NULL) - return FALSE; - - DEBUG_MESSAGE1 (DEBUG_EXECUTE, - "fsysdep_wildcard_start: got \"%s\"", - zSwildcard_alloc); - - zSwildcard = zSwildcard_alloc; - - return TRUE; - -#endif /* ! HAVE_GLOB */ -} - -/* Get the next wildcard spec. */ - -/*ARGSUSED*/ -char * -zsysdep_wildcard (zfile) - const char *zfile; -{ -#if HAVE_GLOB - - char *zret; - - if (iSglob >= sSglob.gl_pathc) - return NULL; - zret = zbufcpy (sSglob.gl_pathv[iSglob]); - ++iSglob; - return zret; - -#else /* ! HAVE_GLOB */ - - char *zret; - - if (zSwildcard_alloc == NULL || zSwildcard == NULL) - return NULL; - - zret = zSwildcard; - - while (*zSwildcard != '\0' && ! isspace (BUCHAR (*zSwildcard))) - ++zSwildcard; - - if (*zSwildcard != '\0') - { - *zSwildcard = '\0'; - ++zSwildcard; - while (*zSwildcard != '\0' && isspace (BUCHAR (*zSwildcard))) - ++zSwildcard; - } - - if (*zSwildcard == '\0') - zSwildcard = NULL; - - return zbufcpy (zret); - -#endif /* ! HAVE_GLOB */ -} - -/* Finish up getting wildcard specs. */ - -boolean -fsysdep_wildcard_end () -{ -#if HAVE_GLOB - globfree (&sSglob); - return TRUE; -#else /* ! HAVE_GLOB */ - xfree ((pointer) zSwildcard_alloc); - zSwildcard_alloc = NULL; - zSwildcard = NULL; - return TRUE; -#endif /* ! HAVE_GLOB */ -} diff --git a/gnu/libexec/uucp/libunix/work.c b/gnu/libexec/uucp/libunix/work.c deleted file mode 100644 index 7e0c12e..0000000 --- a/gnu/libexec/uucp/libunix/work.c +++ /dev/null @@ -1,791 +0,0 @@ -/* work.c - Routines to read command files. - - Copyright (C) 1991, 1992, 1993, 1995 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#if USE_RCS_ID -const char work_rcsid[] = "$FreeBSD$"; -#endif - -#include "uudefs.h" -#include "uuconf.h" -#include "system.h" -#include "sysdep.h" - -#include <ctype.h> -#include <errno.h> - -#if HAVE_OPENDIR -#if HAVE_DIRENT_H -#include <dirent.h> -#else /* ! HAVE_DIRENT_H */ -#include <sys/dir.h> -#define dirent direct -#endif /* ! HAVE_DIRENT_H */ -#endif /* HAVE_OPENDIR */ - -/* Local functions. */ - -static char *zswork_directory P((const char *zsystem)); -static boolean fswork_file P((const char *zsystem, const char *zfile, - char *pbgrade)); -static int iswork_cmp P((constpointer pkey, constpointer pdatum)); - -/* These functions can support multiple actions going on at once. - This allows the UUCP package to send and receive multiple files at - the same time. */ - -/* To avoid wasting a lot of time scanning the spool directory, which - might cause the remote system to time out, we limit each scan to - pick up at most a certain number of files. */ -#define COMMANDS_PER_SCAN (200) - -/* The ssfilename structure holds the name of a work file, as well as - its grade. */ - -struct ssfilename -{ - char *zfile; - char bgrade; - /* Some compiler may need this, and it won't normally hurt. */ - char bdummy; -}; - -/* The ssfile structure holds a command file name and all the lines - read in from that command file. The union within the ssline - structure initially holds a line from the file and then holds a - pointer back to the ssfile structure; a pointer to this union is - used as a sequence pointer. The ztemp entry of the ssline - structure holds the name of a temporary file to delete, if any. */ - -#define CFILELINES (10) - -struct ssline -{ - char *zline; - struct ssfile *qfile; - char *ztemp; -}; - -struct ssfile -{ - char *zfile; - char bgrade; - /* bdummy is needed for some buggy compilers. */ - char bdummy; - int clines; - int cdid; - struct ssline aslines[CFILELINES]; -}; - -/* Static variables for the work scan. */ - -static struct ssfilename *asSwork_files; -static size_t cSwork_files; -static size_t iSwork_file; -static struct ssfile *qSwork_file; - -/* Given a system name, return a directory to search for work. */ - -static char * -zswork_directory (zsystem) - const char *zsystem; -{ -#if SPOOLDIR_V2 - return zbufcpy ("."); -#endif /* SPOOLDIR_V2 */ -#if SPOOLDIR_BSD42 || SPOOLDIR_BSD43 - return zbufcpy ("C."); -#endif /* SPOOLDIR_BSD42 || SPOOLDIR_BSD43 */ -#if SPOOLDIR_HDB || SPOOLDIR_SVR4 - return zbufcpy (zsystem); -#endif /* SPOOLDIR_HDB || SPOOLDIR_SVR4 */ -#if SPOOLDIR_ULTRIX - return zsappend3 ("sys", - (fsultrix_has_spool (zsystem) - ? zsystem - : "DEFAULT"), - "C."); -#endif /* SPOOLDIR_ULTRIX */ -#if SPOOLDIR_TAYLOR - return zsysdep_in_dir (zsystem, "C."); -#endif /* SPOOLDIR_TAYLOR */ -} - -/* See whether a file name from the directory returned by - zswork_directory is really a command for a particular system. - Return the command grade. */ - -/*ARGSUSED*/ -static boolean -fswork_file (zsystem, zfile, pbgrade) - const char *zsystem; - const char *zfile; - char *pbgrade; -{ -#if SPOOLDIR_V2 || SPOOLDIR_BSD42 || SPOOLDIR_BSD43 || SPOOLDIR_ULTRIX - int cfilesys, csys; - - /* The file name should be C.ssssssgqqqq, where g is exactly one - letter and qqqq is exactly four numbers. The system name may be - truncated to six or seven characters. The system name of the - file must match the system name we're looking for, since there - could be work files for several systems in one directory. */ - if (zfile[0] != 'C' || zfile[1] != '.') - return FALSE; - csys = strlen (zsystem); - cfilesys = strlen (zfile) - 7; - if (csys != cfilesys - && (csys < 6 || (cfilesys != 6 && cfilesys != 7))) - return FALSE; - *pbgrade = zfile[cfilesys + 2]; - return strncmp (zfile + 2, zsystem, cfilesys) == 0; -#endif /* V2 || BSD42 || BSD43 || ULTRIX */ -#if SPOOLDIR_HDB || SPOOLDIR_SVR4 - int clen; - - /* The HDB file name should be C.ssssssgqqqq where g is exactly one - letter and qqqq is exactly four numbers or letters. We don't - check the system name, because it is guaranteed by the directory - we are looking in and some versions of uucp set it to the local - system rather than the remote one. I'm not sure of the exact - format of the SVR4 file name, but it does not include the grade - at all. */ - if (zfile[0] != 'C' || zfile[1] != '.') - return FALSE; - clen = strlen (zfile); - if (clen < 7) - return FALSE; -#if ! SPOOLDIR_SVR4 - *pbgrade = zfile[clen - 5]; -#endif - return TRUE; -#endif /* SPOOLDIR_HDB || SPOOLDIR_SVR4 */ -#if SPOOLDIR_TAYLOR - /* We don't keep the system name in the file name, since that - forces truncation. Our file names are always C.gqqqq. */ - *pbgrade = zfile[2]; - return (zfile[0] == 'C' - && zfile[1] == '.' - && zfile[2] != '\0'); -#endif /* SPOOLDIR_TAYLOR */ -} - -/* A comparison function to look through the list of file names. */ - -static int -iswork_cmp (pkey, pdatum) - constpointer pkey; - constpointer pdatum; -{ - const struct ssfilename *qkey = (const struct ssfilename *) pkey; - const struct ssfilename *qdatum = (const struct ssfilename *) pdatum; - - return strcmp (qkey->zfile, qdatum->zfile); -} - -/* See whether there is any work to do for a particular system. */ - -boolean -fsysdep_has_work (qsys) - const struct uuconf_system *qsys; -{ - char *zdir; - DIR *qdir; - struct dirent *qentry; -#if SPOOLDIR_SVR4 - DIR *qgdir; - struct dirent *qgentry; -#endif - - zdir = zswork_directory (qsys->uuconf_zname); - if (zdir == NULL) - return FALSE; - qdir = opendir ((char *) zdir); - if (qdir == NULL) - { - ubuffree (zdir); - return FALSE; - } - -#if SPOOLDIR_SVR4 - qgdir = qdir; - while ((qgentry = readdir (qgdir)) != NULL) - { - char *zsub; - - if (qgentry->d_name[0] == '.' - || qgentry->d_name[1] != '\0') - continue; - zsub = zsysdep_in_dir (zdir, qgentry->d_name); - qdir = opendir (zsub); - ubuffree (zsub); - if (qdir == NULL) - continue; -#endif - - while ((qentry = readdir (qdir)) != NULL) - { - char bgrade; - - if (fswork_file (qsys->uuconf_zname, qentry->d_name, &bgrade)) - { - closedir (qdir); -#if SPOOLDIR_SVR4 - closedir (qgdir); -#endif - ubuffree (zdir); - return TRUE; - } - } - -#if SPOOLDIR_SVR4 - closedir (qdir); - } - qdir = qgdir; -#endif - - closedir (qdir); - ubuffree (zdir); - return FALSE; -} - -/* Initialize the work scan. We have to read all the files in the - work directory, so that we can sort them by work grade. The bgrade - argument is the minimum grade to consider. We don't want to return - files that we have already considered; usysdep_get_work_free will - clear the data out when we are done with the system. This returns - FALSE on error. */ - -#define CWORKFILES (10) - -boolean -fsysdep_get_work_init (qsys, bgrade) - const struct uuconf_system *qsys; - int bgrade; -{ - char *zdir; - DIR *qdir; - struct dirent *qentry; - size_t chad; - size_t callocated; -#if SPOOLDIR_SVR4 - DIR *qgdir; - struct dirent *qgentry; -#endif - - zdir = zswork_directory (qsys->uuconf_zname); - if (zdir == NULL) - return FALSE; - - qdir = opendir (zdir); - if (qdir == NULL) - { - boolean fret; - - if (errno == ENOENT) - fret = TRUE; - else - { - ulog (LOG_ERROR, "opendir (%s): %s", zdir, strerror (errno)); - fret = FALSE; - } - ubuffree (zdir); - return fret; - } - - chad = cSwork_files; - callocated = cSwork_files; - - /* Sort the files we already know about so that we can check the new - ones with bsearch. It would be faster to use a hash table, and - the code should be probably be changed. The sort done at the end - of this function does not suffice because it only includes the - files added last time, and does not sort the entire array. Some - (bad) qsort implementations are very slow when given a sorted - array, which causes particularly bad effects here. */ - if (chad > 0) - qsort ((pointer) asSwork_files, chad, sizeof (struct ssfilename), - iswork_cmp); - -#if SPOOLDIR_SVR4 - qgdir = qdir; - while ((qgentry = readdir (qgdir)) != NULL) - { - char *zsub; - - if (qgentry->d_name[0] == '.' - || qgentry->d_name[1] != '\0' - || UUCONF_GRADE_CMP (bgrade, qgentry->d_name[0]) < 0) - continue; - zsub = zsysdep_in_dir (zdir, qgentry->d_name); - qdir = opendir (zsub); - if (qdir == NULL) - { - if (errno != ENOTDIR && errno != ENOENT) - { - ulog (LOG_ERROR, "opendir (%s): %s", zsub, - strerror (errno)); - ubuffree (zsub); - return FALSE; - } - ubuffree (zsub); - continue; - } - ubuffree (zsub); -#endif - - while ((qentry = readdir (qdir)) != NULL) - { - char bfilegrade; - char *zname; - struct ssfilename slook; - -#if ! SPOOLDIR_SVR4 - zname = zbufcpy (qentry->d_name); -#else - zname = zsysdep_in_dir (qgentry->d_name, qentry->d_name); - bfilegrade = qgentry->d_name[0]; -#endif - - slook.zfile = zname; - if (! fswork_file (qsys->uuconf_zname, qentry->d_name, - &bfilegrade) - || UUCONF_GRADE_CMP (bgrade, bfilegrade) < 0 - || (asSwork_files != NULL - && bsearch ((pointer) &slook, - (pointer) asSwork_files, - chad, sizeof (struct ssfilename), - iswork_cmp) != NULL)) - ubuffree (zname); - else - { - DEBUG_MESSAGE1 (DEBUG_SPOOLDIR, - "fsysdep_get_work_init: Found %s", - zname); - - if (cSwork_files >= callocated) - { - callocated += CWORKFILES; - asSwork_files = - ((struct ssfilename *) - xrealloc ((pointer) asSwork_files, - (callocated * sizeof (struct ssfilename)))); - } - - asSwork_files[cSwork_files].zfile = zname; - asSwork_files[cSwork_files].bgrade = bfilegrade; - ++cSwork_files; - if (cSwork_files - chad > COMMANDS_PER_SCAN) - break; - } - } - -#if SPOOLDIR_SVR4 - closedir (qdir); - if (cSwork_files - chad > COMMANDS_PER_SCAN) - break; - } - qdir = qgdir; -#endif - - closedir (qdir); - ubuffree (zdir); - - /* Sorting the files alphabetically will get the grades in the - right order, since all the file prefixes are the same. */ - if (cSwork_files > iSwork_file) - qsort ((pointer) (asSwork_files + iSwork_file), - cSwork_files - iSwork_file, - sizeof (struct ssfilename), iswork_cmp); - - return TRUE; -} - -/* Get the next work entry for a system. This must parse the next - line in the next work file. The type of command is set into - qcmd->bcmd If there are no more commands, qcmd->bcmd is set to 'H'. - Each field in the structure is set to point to a spot in an - malloced string. The grade argument is never used; it has been - used by fsysdep_get_work_init. */ - -/*ARGSUSED*/ -boolean -fsysdep_get_work (qsys, bgrade, qcmd) - const struct uuconf_system *qsys; - int bgrade; - struct scmd *qcmd; -{ - char *zdir; - - if (qSwork_file != NULL && qSwork_file->cdid >= qSwork_file->clines) - qSwork_file = NULL; - - if (asSwork_files == NULL) - { - qcmd->bcmd = 'H'; - return TRUE; - } - - zdir = NULL; - - /* This loop continues until a line is returned. */ - while (TRUE) - { - /* This loop continues until a file is opened and read in. */ - while (qSwork_file == NULL) - { - FILE *e; - struct ssfile *qfile; - int iline, callocated; - char *zline; - size_t cline; - char *zname; - char bfilegrade; - - /* Read all the lines of a command file into memory. */ - do - { - if (iSwork_file >= cSwork_files) - { - qcmd->bcmd = 'H'; - ubuffree (zdir); - return TRUE; - } - - if (zdir == NULL) - { - zdir = zswork_directory (qsys->uuconf_zname); - if (zdir == NULL) - return FALSE; - } - - zname = zsysdep_in_dir (zdir, asSwork_files[iSwork_file].zfile); - bfilegrade = asSwork_files[iSwork_file].bgrade; - - ++iSwork_file; - - e = fopen (zname, "r"); - if (e == NULL) - { - ulog (LOG_ERROR, "fopen (%s): %s", zname, - strerror (errno)); - ubuffree (zname); - } - } - while (e == NULL); - - qfile = (struct ssfile *) xmalloc (sizeof (struct ssfile)); - callocated = CFILELINES; - iline = 0; - - zline = NULL; - cline = 0; - while (getline (&zline, &cline, e) > 0) - { - if (iline >= callocated) - { - /* The sizeof (struct ssfile) includes CFILELINES - entries already, so using callocated * sizeof - (struct ssline) will give us callocated * - CFILELINES entries. */ - qfile = - ((struct ssfile *) - xrealloc ((pointer) qfile, - (sizeof (struct ssfile) + - (callocated * sizeof (struct ssline))))); - callocated += CFILELINES; - } - qfile->aslines[iline].zline = zbufcpy (zline); - qfile->aslines[iline].qfile = NULL; - qfile->aslines[iline].ztemp = NULL; - iline++; - } - - xfree ((pointer) zline); - - if (fclose (e) != 0) - ulog (LOG_ERROR, "fclose: %s", strerror (errno)); - - if (iline == 0) - { - /* There were no lines in the file; this is a poll file, - for which we return a 'P' command. */ - qfile->aslines[0].zline = zbufcpy ("P"); - qfile->aslines[0].qfile = NULL; - qfile->aslines[0].ztemp = NULL; - iline = 1; - } - - qfile->zfile = zname; - qfile->bgrade = bfilegrade; - qfile->clines = iline; - qfile->cdid = 0; - qSwork_file = qfile; - } - - /* This loop continues until all the lines from the current file - are used up, or a line is returned. */ - while (TRUE) - { - int iline; - - if (qSwork_file->cdid >= qSwork_file->clines) - { - /* We don't want to free qSwork_file here, since it must - remain until all the lines have been completed. It - is freed in fsysdep_did_work. */ - qSwork_file = NULL; - /* Go back to the main loop which finds another file. */ - break; - } - - iline = qSwork_file->cdid; - ++qSwork_file->cdid; - - /* Now parse the line into a command. */ - if (! fparse_cmd (qSwork_file->aslines[iline].zline, qcmd)) - { - ulog (LOG_ERROR, "Bad line in command file %s", - qSwork_file->zfile); - ubuffree (qSwork_file->aslines[iline].zline); - qSwork_file->aslines[iline].zline = NULL; - continue; - } - qcmd->bgrade = qSwork_file->bgrade; - - qSwork_file->aslines[iline].qfile = qSwork_file; - qcmd->pseq = (pointer) (&qSwork_file->aslines[iline]); - - if (qcmd->bcmd == 'S' || qcmd->bcmd == 'E') - { - char *zreal; - - zreal = zsysdep_spool_file_name (qsys, qcmd->ztemp, - qcmd->pseq); - if (zreal == NULL) - { - ubuffree (qSwork_file->aslines[iline].zline); - qSwork_file->aslines[iline].zline = NULL; - ubuffree (zdir); - return FALSE; - } - qSwork_file->aslines[iline].ztemp = zreal; - } - - ubuffree (zdir); - return TRUE; - } - } -} - -/* When a command has been complete, fsysdep_did_work is called. The - sequence entry was set above to be the address of an aslines - structure whose pfile entry points to the ssfile corresponding to - this file. We can then check whether all the lines have been - completed (they will have been if the pfile entry is NULL) and - remove the file if they have been. This means that we only remove - a command file if we manage to complete every transfer it specifies - in a single UUCP session. I don't know if this is how regular UUCP - works. */ - -boolean -fsysdep_did_work (pseq) - pointer pseq; -{ - struct ssfile *qfile; - struct ssline *qline; - int i; - - qline = (struct ssline *) pseq; - - ubuffree (qline->zline); - qline->zline = NULL; - - qfile = qline->qfile; - qline->qfile = NULL; - - /* Remove the temporary file, if there is one. It really doesn't - matter if this fails, and not checking the return value lets us - attempt to remove D.0 or whatever an unused temporary file is - called without complaining. */ - if (qline->ztemp != NULL) - { - (void) remove (qline->ztemp); - ubuffree (qline->ztemp); - qline->ztemp = NULL; - } - - /* If not all the lines have been returned from fsysdep_get_work, - we can't remove the file yet. */ - if (qfile->cdid < qfile->clines) - return TRUE; - - /* See whether all the commands have been completed. */ - for (i = 0; i < qfile->clines; i++) - if (qfile->aslines[i].qfile != NULL) - return TRUE; - - /* All commands have finished. */ - if (remove (qfile->zfile) != 0) - { - ulog (LOG_ERROR, "remove (%s): %s", qfile->zfile, - strerror (errno)); - return FALSE; - } - - ubuffree (qfile->zfile); - xfree ((pointer) qfile); - - if (qfile == qSwork_file) - qSwork_file = NULL; - - return TRUE; -} - -/* Free up the results of a work scan, when we're done with this - system. */ - -/*ARGSUSED*/ -void -usysdep_get_work_free (qsys) - const struct uuconf_system *qsys; -{ - if (asSwork_files != NULL) - { - size_t i; - - for (i = 0; i < cSwork_files; i++) - ubuffree ((pointer) asSwork_files[i].zfile); - xfree ((pointer) asSwork_files); - asSwork_files = NULL; - cSwork_files = 0; - iSwork_file = 0; - } - if (qSwork_file != NULL) - { - int i; - - ubuffree (qSwork_file->zfile); - for (i = 0; i < qSwork_file->cdid; i++) - { - ubuffree (qSwork_file->aslines[i].zline); - ubuffree (qSwork_file->aslines[i].ztemp); - } - for (i = qSwork_file->cdid; i < qSwork_file->clines; i++) - ubuffree (qSwork_file->aslines[i].zline); - xfree ((pointer) qSwork_file); - qSwork_file = NULL; - } -} - -/* Save the temporary file used by a send command, and return an - informative message to mail to the requestor. This is called when - a file transfer failed, to make sure that the potentially valuable - file is not completely lost. */ - -const char * -zsysdep_save_temp_file (pseq) - pointer pseq; -{ - struct ssline *qline = (struct ssline *) pseq; - char *zto, *zslash; - size_t cwant; - static char *zbuf; - static int cbuf; - - if (! fsysdep_file_exists (qline->ztemp)) - return NULL; - - zslash = strrchr (qline->ztemp, '/'); - if (zslash == NULL) - zslash = qline->ztemp; - else - ++zslash; - - zto = zbufalc (sizeof PRESERVEDIR + sizeof "/" + strlen (zslash)); - sprintf (zto, "%s/%s", PRESERVEDIR, zslash); - - if (! fsysdep_move_file (qline->ztemp, zto, TRUE, FALSE, FALSE, - (const char *) NULL)) - { - /* Leave the file where it was, not that is much help. */ - ubuffree (zto); - return "Could not move file to preservation directory"; - } - - cwant = sizeof "File saved as\n\t/" + strlen (zSspooldir) + strlen (zto); - if (cwant > cbuf) - { - ubuffree (zbuf); - zbuf = zbufalc (cwant); - cbuf = cwant; - } - - sprintf (zbuf, "File saved as\n\t%s/%s", zSspooldir, zto); - ubuffree (zto); - return zbuf; -} - -/* Get the jobid of a work file. This is needed by uustat. */ - -char * -zsysdep_jobid (qsys, pseq) - const struct uuconf_system *qsys; - pointer pseq; -{ - return zsfile_to_jobid (qsys, ((struct ssline *) pseq)->qfile->zfile, - bsgrade (pseq)); -} - -/* Get the grade of a work file. The pseq argument can be NULL when - this is called from zsysdep_spool_file_name, and simply means that - this is a remote file; returning -1 will cause zsfind_file to do - the right thing. */ - -int -bsgrade (pseq) - pointer pseq; -{ - const char *zfile; - char bgrade; - - if (pseq == NULL) - return -1; - - zfile = ((struct ssline *) pseq)->qfile->zfile; - -#if SPOOLDIR_TAYLOR - bgrade = *(strrchr (zfile, '/') + 3); -#else -#if ! SPOOLDIR_SVR4 - bgrade = zfile[strlen (zfile) - CSEQLEN - 1]; -#else - bgrade = *(strchr (zfile, '/') + 1); -#endif -#endif - - return bgrade; -} diff --git a/gnu/libexec/uucp/libunix/xqtfil.c b/gnu/libexec/uucp/libunix/xqtfil.c deleted file mode 100644 index 3019a32..0000000 --- a/gnu/libexec/uucp/libunix/xqtfil.c +++ /dev/null @@ -1,298 +0,0 @@ -/* xqtfil.c - Routines to read execute files. - - Copyright (C) 1991, 1992, 1993, 1995 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#if USE_RCS_ID -const char xqtfil_rcsid[] = "$FreeBSD$"; -#endif - -#include "uudefs.h" -#include "sysdep.h" -#include "system.h" - -#include <errno.h> - -#if HAVE_OPENDIR -#if HAVE_DIRENT_H -#include <dirent.h> -#else /* ! HAVE_DIRENT_H */ -#include <sys/dir.h> -#define dirent direct -#endif /* ! HAVE_DIRENT_H */ -#endif /* HAVE_OPENDIR */ - -/* Under the V2 or BSD42 spool directory scheme, all execute files are - in the main spool directory. Under the BSD43 scheme, they are all - in the directory X.. Under the HDB or SVR4 scheme, they are in - directories named after systems. Under the ULTRIX scheme, they are - in X. subdirectories of subdirectories of sys. Under the TAYLOR - scheme, they are all in the subdirectory X. of a directory named - after the system. - - This means that for HDB, ULTRIX, SVR4 or TAYLOR, we have to search - directories of directories. */ - -#if SPOOLDIR_V2 || SPOOLDIR_BSD42 -#define ZDIR "." -#define SUBDIRS 0 -#endif -#if SPOOLDIR_HDB || SPOOLDIR_SVR4 || SPOOLDIR_TAYLOR -#define ZDIR "." -#define SUBDIRS 1 -#endif -#if SPOOLDIR_ULTRIX -#define ZDIR "sys" -#define SUBDIRS 1 -#endif -#if SPOOLDIR_BSD43 -#define ZDIR "X." -#define SUBDIRS 0 -#endif - -/* Static variables for the execute file scan. */ - -static DIR *qSxqt_topdir; -#if ! SUBDIRS -static const char *zSdir; -#else /* SUBDIRS */ -static boolean fSone_dir; -static char *zSdir; -static DIR *qSxqt_dir; -static char *zSsystem; -#endif /* SUBDIRS */ - -/* Initialize the scan for execute files. The function - usysdep_get_xqt_free will clear the data out when we are done with - the system. This returns FALSE on error. */ - -/*ARGSUSED*/ -boolean -fsysdep_get_xqt_init (zsystem) - const char *zsystem; -{ - usysdep_get_xqt_free ((const char *) NULL); - -#if SUBDIRS - if (zsystem != NULL) - { -#if SPOOLDIR_HDB || SPOOLDIR_SVR4 - zSdir = zbufcpy (zsystem); -#endif -#if SPOOLDIR_ULTRIX - zSdir = zsappend3 ("sys", zsystem, "X."); -#endif -#if SPOOLDIR_TAYLOR - zSdir = zsysdep_in_dir (zsystem, "X."); -#endif - - qSxqt_dir = opendir ((char *) zSdir); - if (qSxqt_dir != NULL) - { - qSxqt_topdir = qSxqt_dir; - fSone_dir = TRUE; - zSsystem = zbufcpy (zsystem); - return TRUE; - } - } - - fSone_dir = FALSE; -#endif - - qSxqt_topdir = opendir ((char *) ZDIR); - if (qSxqt_topdir == NULL) - { - if (errno == ENOENT) - return TRUE; - ulog (LOG_ERROR, "opendir (%s): %s", ZDIR, strerror (errno)); - return FALSE; - } - - return TRUE; -} - -/* Return the name of the next execute file to read and process. If - this returns NULL, *pferr must be checked. If will be TRUE on - error, FALSE if there are no more files. On a successful return - *pzsystem will be set to the system for which the execute file was - created. */ - -/*ARGSUSED*/ -char * -zsysdep_get_xqt (zsystem, pzsystem, pferr) - const char *zsystem; - char **pzsystem; - boolean *pferr; -{ - *pferr = FALSE; - - if (qSxqt_topdir == NULL) - return NULL; - - /* This loop continues until we find a file. */ - while (TRUE) - { - DIR *qdir; - struct dirent *q; - -#if ! SUBDIRS - zSdir = ZDIR; - qdir = qSxqt_topdir; -#else /* SUBDIRS */ - /* This loop continues until we find a subdirectory to read. */ - while (qSxqt_dir == NULL) - { - struct dirent *qtop; - - qtop = readdir (qSxqt_topdir); - if (qtop == NULL) - { - (void) closedir (qSxqt_topdir); - qSxqt_topdir = NULL; - return NULL; - } - - /* No system name may start with a dot This allows us to - quickly skip impossible directories. */ - if (qtop->d_name[0] == '.') - continue; - - DEBUG_MESSAGE1 (DEBUG_SPOOLDIR, - "zsysdep_get_xqt: Found %s in top directory", - qtop->d_name); - - ubuffree (zSdir); - -#if SPOOLDIR_HDB || SPOOLDIR_SVR4 - zSdir = zbufcpy (qtop->d_name); -#endif -#if SPOOLDIR_ULTRIX - zSdir = zsappend3 ("sys", qtop->d_name, "X."); -#endif -#if SPOOLDIR_TAYLOR - zSdir = zsysdep_in_dir (qtop->d_name, "X."); -#endif - - ubuffree (zSsystem); - zSsystem = zbufcpy (qtop->d_name); - - qSxqt_dir = opendir (zSdir); - - if (qSxqt_dir == NULL - && errno != ENOTDIR - && errno != ENOENT) - ulog (LOG_ERROR, "opendir (%s): %s", zSdir, strerror (errno)); - } - - qdir = qSxqt_dir; -#endif /* SUBDIRS */ - - q = readdir (qdir); - -#if DEBUG > 1 - if (q != NULL) - DEBUG_MESSAGE2 (DEBUG_SPOOLDIR, - "zsysdep_get_xqt: Found %s in subdirectory %s", - q->d_name, zSdir); -#endif - - /* If we've found an execute file, return it. We have to get - the system name, which is easy for HDB or TAYLOR. For other - spool directory schemes, we have to pull it out of the X. - file name; this would be insecure, except that zsfind_file - clobbers the file name to include the real system name. */ - if (q != NULL - && q->d_name[0] == 'X' - && q->d_name[1] == '.') - { - char *zret; - -#if SPOOLDIR_HDB || SPOOLDIR_SVR4 || SPOOLDIR_TAYLOR - *pzsystem = zbufcpy (zSsystem); -#else - { - size_t clen; - - clen = strlen (q->d_name) - 7; - *pzsystem = zbufalc (clen + 1); - memcpy (*pzsystem, q->d_name + 2, clen); - (*pzsystem)[clen] = '\0'; - } -#endif - - zret = zsysdep_in_dir (zSdir, q->d_name); -#if DEBUG > 1 - DEBUG_MESSAGE2 (DEBUG_SPOOLDIR, - "zsysdep_get_xqt: Returning %s (system %s)", - zret, *pzsystem); -#endif - return zret; - } - - /* If we've reached the end of the directory, then if we are - using subdirectories loop around to read the next one, - otherwise we are finished. */ - if (q == NULL) - { - (void) closedir (qdir); - -#if SUBDIRS - qSxqt_dir = NULL; - if (! fSone_dir) - continue; -#endif - - qSxqt_topdir = NULL; - return NULL; - } - } -} - -/* Free up the results of an execute file scan, when we're done with - this system. */ - -/*ARGSUSED*/ -void -usysdep_get_xqt_free (zsystem) - const char *zsystem; -{ - if (qSxqt_topdir != NULL) - { - (void) closedir (qSxqt_topdir); - qSxqt_topdir = NULL; - } -#if SUBDIRS - if (qSxqt_dir != NULL) - { - (void) closedir (qSxqt_dir); - qSxqt_dir = NULL; - } - ubuffree (zSdir); - zSdir = NULL; - ubuffree (zSsystem); - zSsystem = NULL; - fSone_dir = FALSE; -#endif -} diff --git a/gnu/libexec/uucp/libunix/xqtsub.c b/gnu/libexec/uucp/libunix/xqtsub.c deleted file mode 100644 index 7435497..0000000 --- a/gnu/libexec/uucp/libunix/xqtsub.c +++ /dev/null @@ -1,711 +0,0 @@ -/* xqtsub.c - System dependent functions used only by uuxqt. - - Copyright (C) 1991, 1992, 1993, 1995 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144. - */ - -#include "uucp.h" - -#if USE_RCS_ID -const char xqtsub_rcsid[] = "$FreeBSD$"; -#endif - -#include "uudefs.h" -#include "uuconf.h" -#include "system.h" -#include "sysdep.h" - -#include <ctype.h> -#include <errno.h> - -#if HAVE_FCNTL_H -#include <fcntl.h> -#else -#if HAVE_SYS_FILE_H -#include <sys/file.h> -#endif -#endif - -#ifndef O_RDONLY -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#endif - -#ifndef O_NOCTTY -#define O_NOCTTY 0 -#endif - -#ifndef FD_CLOEXEC -#define FD_CLOEXEC 1 -#endif - -#if HAVE_OPENDIR -#if HAVE_DIRENT_H -#include <dirent.h> -#else /* ! HAVE_DIRENT_H */ -#include <sys/dir.h> -#define dirent direct -#endif /* ! HAVE_DIRENT_H */ -#endif /* HAVE_OPENDIR */ - -/* Get a value for EX_TEMPFAIL. */ - -#if HAVE_SYSEXITS_H -#include <sysexits.h> -#endif - -#ifndef EX_TEMPFAIL -#define EX_TEMPFAIL 75 -#endif - -/* Get the full pathname of the command to execute, given the list of - permitted commands and the allowed path. */ - -char * -zsysdep_find_command (zcmd, pzcmds, pzpath, pferr) - const char *zcmd; - char **pzcmds; - char **pzpath; - boolean *pferr; -{ - char **pz; - struct stat s; - - *pferr = FALSE; - - for (pz = pzcmds; *pz != NULL; pz++) - { - char *zslash; - - if (strcmp (*pz, "ALL") == 0) - break; - - zslash = strrchr (*pz, '/'); - if (zslash != NULL) - ++zslash; - else - zslash = *pz; - if (strcmp (zslash, zcmd) == 0 - || strcmp (*pz, zcmd) == 0) - { - /* If we already have an absolute path, we can get out - immediately. */ - if (**pz == '/') - { - /* Quick error check. */ - if (stat (*pz, &s) != 0) - { - ulog (LOG_ERROR, "%s: %s", *pz, strerror (errno)); - *pferr = TRUE; - return NULL; - } - return zbufcpy (*pz); - } - break; - } - } - - /* If we didn't find this command, get out. */ - if (*pz == NULL) - return NULL; - - /* We didn't find an absolute pathname, so we must look through - the path. */ - for (pz = pzpath; *pz != NULL; pz++) - { - char *zname; - - zname = zsysdep_in_dir (*pz, zcmd); - if (stat (zname, &s) == 0) - return zname; - } - - return NULL; -} - -/* Expand a local filename for uuxqt. This is special because uuxqt - only wants to expand filenames that start with ~ (it does not want - to prepend the current directory to other names) and if the ~ is - double, it is turned into a single ~. This returns NULL to - indicate that no change was required; it has no way to return - error. */ - -char * -zsysdep_xqt_local_file (qsys, zfile) - const struct uuconf_system *qsys; - const char *zfile; -{ - if (*zfile != '~') - return NULL; - if (zfile[1] == '~') - { - size_t clen; - char *zret; - - clen = strlen (zfile); - zret = zbufalc (clen); - memcpy (zret, zfile + 1, clen); - return zret; - } - return zsysdep_local_file (zfile, qsys->uuconf_zpubdir, - (boolean *) NULL); -} - -#if ! ALLOW_FILENAME_ARGUMENTS - -/* Check to see whether an argument specifies a file name; if it does, - make sure that the file may legally be sent and/or received. For - Unix, we do not permit any occurrence of "/../" in the name, nor - may it start with "../". Otherwise, if it starts with "/" we check - against the list of permitted files. */ - -boolean -fsysdep_xqt_check_file (qsys, zfile) - const struct uuconf_system *qsys; - const char *zfile; -{ - size_t clen; - - /* Disallow exact "..", prefix "../", suffix "/..", internal "/../", - and restricted absolute paths. */ - clen = strlen (zfile); - if ((clen == sizeof ".." - 1 - && strcmp (zfile, "..") == 0) - || strncmp (zfile, "../", sizeof "../" - 1) == 0 - || (clen >= sizeof "/.." - 1 - && strcmp (zfile + clen - (sizeof "/.." - 1), "/..") == 0) - || strstr (zfile, "/../") != NULL - || (*zfile == '/' - && (! fin_directory_list (zfile, qsys->uuconf_pzremote_send, - qsys->uuconf_zpubdir, TRUE, FALSE, - (const char *) NULL) - || ! fin_directory_list (zfile, qsys->uuconf_pzremote_receive, - qsys->uuconf_zpubdir, TRUE, FALSE, - (const char *) NULL)))) - { - ulog (LOG_ERROR, "Not permitted to refer to file \"%s\"", zfile); - return FALSE; - } - - return TRUE; -} - -#endif /* ! ALLOW_FILENAME_ARGUMENTS */ - -/* Invoke the command specified by an execute file. */ - -/*ARGSUSED*/ -boolean -fsysdep_execute (qsys, zuser, pazargs, zfullcmd, zinput, zoutput, - fshell, iseq, pzerror, pftemp) - const struct uuconf_system *qsys; - const char *zuser; - const char **pazargs; - const char *zfullcmd; - const char *zinput; - const char *zoutput; - boolean fshell; - int iseq; - char **pzerror; - boolean *pftemp; -{ - int aidescs[3]; - boolean ferr; - pid_t ipid; - int ierr; - char abxqtdir[sizeof XQTDIR + 4]; - const char *zxqtdir; - int istat; - char *zpath; -#if ALLOW_SH_EXECUTION - const char *azshargs[4]; -#endif - - *pzerror = NULL; - *pftemp = FALSE; - - aidescs[0] = SPAWN_NULL; - aidescs[1] = SPAWN_NULL; - aidescs[2] = SPAWN_NULL; - - ferr = FALSE; - - if (zinput != NULL) - { - aidescs[0] = open ((char *) zinput, O_RDONLY | O_NOCTTY, 0); - if (aidescs[0] < 0) - { - ulog (LOG_ERROR, "open (%s): %s", zinput, strerror (errno)); - ferr = TRUE; - } - else if (fcntl (aidescs[0], F_SETFD, - fcntl (aidescs[0], F_GETFD, 0) | FD_CLOEXEC) < 0) - { - ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - ferr = TRUE; - } - } - - if (! ferr && zoutput != NULL) - { - aidescs[1] = creat ((char *) zoutput, IPRIVATE_FILE_MODE); - if (aidescs[1] < 0) - { - ulog (LOG_ERROR, "creat (%s): %s", zoutput, strerror (errno)); - *pftemp = TRUE; - ferr = TRUE; - } - else if (fcntl (aidescs[1], F_SETFD, - fcntl (aidescs[1], F_GETFD, 0) | FD_CLOEXEC) < 0) - { - ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - ferr = TRUE; - } - } - - if (! ferr) - { - *pzerror = zstemp_file (qsys); - aidescs[2] = creat (*pzerror, IPRIVATE_FILE_MODE); - if (aidescs[2] < 0) - { - if (errno == ENOENT) - { - if (! fsysdep_make_dirs (*pzerror, FALSE)) - { - *pftemp = TRUE; - ferr = TRUE; - } - else - aidescs[2] = creat (*pzerror, IPRIVATE_FILE_MODE); - } - if (! ferr && aidescs[2] < 0) - { - ulog (LOG_ERROR, "creat (%s): %s", *pzerror, strerror (errno)); - *pftemp = TRUE; - ferr = TRUE; - } - } - if (! ferr - && fcntl (aidescs[2], F_SETFD, - fcntl (aidescs[2], F_GETFD, 0) | FD_CLOEXEC) < 0) - { - ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - ferr = TRUE; - } - } - - if (iseq == 0) - zxqtdir = XQTDIR; - else - { - sprintf (abxqtdir, "%s%04d", XQTDIR, iseq); - zxqtdir = abxqtdir; - } - - if (ferr) - { - if (aidescs[0] != SPAWN_NULL) - (void) close (aidescs[0]); - if (aidescs[1] != SPAWN_NULL) - (void) close (aidescs[1]); - if (aidescs[2] != SPAWN_NULL) - (void) close (aidescs[2]); - ubuffree (*pzerror); - return FALSE; - } - -#if ALLOW_SH_EXECUTION - if (fshell) - { - azshargs[0] = "/bin/sh"; - azshargs[1] = "-c"; - azshargs[2] = zfullcmd; - azshargs[3] = NULL; - pazargs = azshargs; - } -#else - fshell = FALSE; -#endif - - if (qsys->uuconf_pzpath == NULL) - zpath = NULL; - else - { - size_t c; - char **pz; - - c = 0; - for (pz = qsys->uuconf_pzpath; *pz != NULL; pz++) - c += strlen (*pz) + 1; - zpath = zbufalc (c); - *zpath = '\0'; - for (pz = qsys->uuconf_pzpath; *pz != NULL; pz++) - { - strcat (zpath, *pz); - if (pz[1] != NULL) - strcat (zpath, ":"); - } - } - - /* Pass zchdir as zxqtdir, fnosigs as TRUE, fshell as TRUE if we - aren't already using the shell. */ - ipid = ixsspawn (pazargs, aidescs, TRUE, FALSE, zxqtdir, TRUE, - ! fshell, zpath, qsys->uuconf_zname, zuser); - - ierr = errno; - - ubuffree (zpath); - - if (aidescs[0] != SPAWN_NULL) - (void) close (aidescs[0]); - if (aidescs[1] != SPAWN_NULL) - (void) close (aidescs[1]); - if (aidescs[2] != SPAWN_NULL) - (void) close (aidescs[2]); - - if (ipid < 0) - { - ulog (LOG_ERROR, "ixsspawn: %s", strerror (ierr)); - *pftemp = TRUE; - return FALSE; - } - - istat = ixswait ((unsigned long) ipid, "Execution"); - - if (istat == EX_TEMPFAIL) - *pftemp = TRUE; - - return istat == 0; -} - -/* Lock a uuxqt process. */ - -int -ixsysdep_lock_uuxqt (zcmd, cmaxuuxqts) - const char *zcmd; - int cmaxuuxqts; -{ - char ab[sizeof "LCK.XQT.9999"]; - int i; - - if (cmaxuuxqts <= 0 || cmaxuuxqts >= 10000) - cmaxuuxqts = 9999; - for (i = 0; i < cmaxuuxqts; i++) - { - sprintf (ab, "LCK.XQT.%d", i); - if (fsdo_lock (ab, TRUE, (boolean *) NULL)) - break; - } - if (i >= cmaxuuxqts) - return -1; - - if (zcmd != NULL) - { - char abcmd[sizeof "LXQ.123456789"]; - - sprintf (abcmd, "LXQ.%.9s", zcmd); - abcmd[strcspn (abcmd, " \t/")] = '\0'; - if (! fsdo_lock (abcmd, TRUE, (boolean *) NULL)) - { - (void) fsdo_unlock (ab, TRUE); - return -1; - } - } - - return i; -} - -/* Unlock a uuxqt process. */ - -boolean -fsysdep_unlock_uuxqt (iseq, zcmd, cmaxuuxqts) - int iseq; - const char *zcmd; - int cmaxuuxqts; -{ - char ab[sizeof "LCK.XQT.9999"]; - boolean fret; - - fret = TRUE; - - sprintf (ab, "LCK.XQT.%d", iseq); - if (! fsdo_unlock (ab, TRUE)) - fret = FALSE; - - if (zcmd != NULL) - { - char abcmd[sizeof "LXQ.123456789"]; - - sprintf (abcmd, "LXQ.%.9s", zcmd); - abcmd[strcspn (abcmd, " \t/")] = '\0'; - if (! fsdo_unlock (abcmd, TRUE)) - fret = FALSE; - } - - return fret; -} - -/* See whether a particular uuxqt command is locked (this depends on - the implementation of fsdo_lock). */ - -boolean -fsysdep_uuxqt_locked (zcmd) - const char *zcmd; -{ - char ab[sizeof "LXQ.123456789"]; - struct stat s; - - sprintf (ab, "LXQ.%.9s", zcmd); - return stat (ab, &s) == 0; -} - -/* Lock a particular execute file. */ - -boolean -fsysdep_lock_uuxqt_file (zfile) - const char *zfile; -{ - char *zcopy, *z; - boolean fret; - - zcopy = zbufcpy (zfile); - - z = strrchr (zcopy, '/'); - if (z == NULL) - *zcopy = 'L'; - else - *(z + 1) = 'L'; - - fret = fsdo_lock (zcopy, TRUE, (boolean *) NULL); - ubuffree (zcopy); - return fret; -} - -/* Unlock a particular execute file. */ - -boolean -fsysdep_unlock_uuxqt_file (zfile) - const char *zfile; -{ - char *zcopy, *z; - boolean fret; - - zcopy = zbufcpy (zfile); - - z = strrchr (zcopy, '/'); - if (z == NULL) - *zcopy = 'L'; - else - *(z + 1) = 'L'; - - fret = fsdo_unlock (zcopy, TRUE); - ubuffree (zcopy); - return fret; -} - -/* Lock the execute directory. Since we use a different directory - depending on which LCK.XQT.dddd file we got, there is actually no - need to create a lock file. We do make sure that the directory - exists, though. */ - -boolean -fsysdep_lock_uuxqt_dir (iseq) - int iseq; -{ - const char *zxqtdir; - char abxqtdir[sizeof XQTDIR + 4]; - - if (iseq == 0) - zxqtdir = XQTDIR; - else - { - sprintf (abxqtdir, "%s%04d", XQTDIR, iseq); - zxqtdir = abxqtdir; - } - - if (mkdir (zxqtdir, S_IRWXU) < 0 - && errno != EEXIST - && errno != EISDIR) - { - ulog (LOG_ERROR, "mkdir (%s): %s", zxqtdir, strerror (errno)); - return FALSE; - } - - return TRUE; -} - -/* Unlock the execute directory and clear it out. The lock is - actually the LCK.XQT.dddd file, so we don't unlock it, but we do - remove all the files. */ - -boolean -fsysdep_unlock_uuxqt_dir (iseq) - int iseq; -{ - const char *zxqtdir; - char abxqtdir[sizeof XQTDIR + 4]; - DIR *qdir; - - if (iseq == 0) - zxqtdir = XQTDIR; - else - { - sprintf (abxqtdir, "%s%04d", XQTDIR, iseq); - zxqtdir = abxqtdir; - } - - qdir = opendir ((char *) zxqtdir); - if (qdir != NULL) - { - struct dirent *qentry; - - while ((qentry = readdir (qdir)) != NULL) - { - char *z; - - if (strcmp (qentry->d_name, ".") == 0 - || strcmp (qentry->d_name, "..") == 0) - continue; - z = zsysdep_in_dir (zxqtdir, qentry->d_name); - if (remove (z) < 0) - { - int ierr; - - ierr = errno; - if (! fsysdep_directory (z)) - ulog (LOG_ERROR, "remove (%s): %s", z, - strerror (ierr)); - else - (void) fsysdep_rmdir (z); - } - ubuffree (z); - } - - closedir (qdir); - } - - return TRUE; -} - -/* Move files into the execution directory. */ - -boolean -fsysdep_move_uuxqt_files (cfiles, pzfrom, pzto, fto, iseq, pzinput) - int cfiles; - const char *const *pzfrom; - const char *const *pzto; - boolean fto; - int iseq; - char **pzinput; -{ - char *zinput; - const char *zxqtdir; - char abxqtdir[sizeof XQTDIR + 4]; - int i; - - if (pzinput == NULL) - zinput = NULL; - else - zinput = *pzinput; - - if (iseq == 0) - zxqtdir = XQTDIR; - else - { - sprintf (abxqtdir, "%s%04d", XQTDIR, iseq); - zxqtdir = abxqtdir; - } - - for (i = 0; i < cfiles; i++) - { - const char *zfrom, *zto; - char *zfree; - - if (pzto[i] == NULL) - continue; - - zfree = zsysdep_in_dir (zxqtdir, pzto[i]); - - zfrom = pzfrom[i]; - zto = zfree; - - if (zinput != NULL && strcmp (zinput, zfrom) == 0) - { - *pzinput = zbufcpy (zto); - zinput = NULL; - } - - if (! fto) - { - const char *ztemp; - - ztemp = zfrom; - zfrom = zto; - zto = ztemp; - (void) chmod (zfrom, IPRIVATE_FILE_MODE); - } - - if (rename (zfrom, zto) < 0) - { -#if HAVE_RENAME - /* On some systems the system call rename seems to fail for - arbitrary reasons. To get around this, we always try to - copy the file by hand if the rename failed. */ - errno = EXDEV; -#endif - - if (errno != EXDEV) - { - ulog (LOG_ERROR, "rename (%s, %s): %s", zfrom, zto, - strerror (errno)); - ubuffree (zfree); - break; - } - - if (! fcopy_file (zfrom, zto, FALSE, FALSE, FALSE)) - { - ubuffree (zfree); - break; - } - if (remove (zfrom) < 0) - ulog (LOG_ERROR, "remove (%s): %s", zfrom, - strerror (errno)); - } - - if (fto) - (void) chmod (zto, IPUBLIC_FILE_MODE); - - ubuffree (zfree); - } - - if (i < cfiles) - { - if (fto) - (void) fsysdep_move_uuxqt_files (i, pzfrom, pzto, FALSE, iseq, - (char **) NULL); - return FALSE; - } - - return TRUE; -} |