📄 uuxqt.c
字号:
/*
Program: uuxqt.c 23 September 1991
Author: Mitch Mitchell
Email: mitch@harlie.lonestar.org
This is a re-write of the (much cleaner) UUXQT.C originally
distributed with UUPC/Extended. The modifications are
intended primarily to lay a foundation for support for the
more advanced features of UUX.
Usage: uuxqt -xDEBUG -sSYSTEM
*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1989-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by */
/* the UUPC/extended license agreement. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: uuxqt.c 1.18 1993/10/03 22:10:24 ahd Exp $
*
* Revision history:
* $Log: uuxqt.c $
* Revision 1.18 1993/10/03 22:10:24 ahd
* Use signed for length of parameters
*
* Revision 1.17 1993/10/03 20:43:08 ahd
* Normalize comments to C++ double slash
*
* Revision 1.16 1993/09/29 23:29:56 ahd
* Add xqtrootdir for UUXQT
*
* Revision 1.15 1993/09/20 04:48:25 ahd
* TCP/IP support from Dave Watt
* 't' protocol support
* OS/2 2.x support (BC++ 1.0 for OS/2)
*
* Revision 1.14 1993/08/03 03:35:58 ahd
* Correct path pointer to initialized variable
*
* Revision 1.13 1993/08/03 03:11:49 ahd
* Initialize buffer for shell() in non-Windows environment
*
* Revision 1.12 1993/07/31 16:27:49 ahd
* Changes in support of Robert Denny's Windows support
*
* Revision 1.11 1993/07/24 03:40:55 ahd
* Agressively trap carriage returns at ends of lines (from X.* files
* being edited by elves with DOS editors!)
*
* Revision 1.10 1993/07/20 21:45:37 ahd
* Don't delete file after -2 abort from UUXQT
*
* Revision 1.9 1993/06/26 16:01:48 ahd
* Normalize white space used to parse strings
*
* Revision 1.8 1993/06/13 14:06:00 ahd
* Correct off-by-one error in RMAIL arg parse loop which crashed UUXQT
* on long system names
*
* Revision 1.7 1993/04/11 00:35:46 ahd
* Global edits for year, TEXT, etc.
*
* Revision 1.6 1993/04/05 04:35:40 ahd
* Use timestamp/file size information returned by directory search
*
* Revision 1.5 1992/11/25 12:59:17 ahd
* Change NUL to /dev/nul to prevent ImportPath() mangling.
*
* Revision 1.4 1992/11/23 03:56:06 ahd
* Selected fixes for use of generlized uux commands
*
* Revision 1.3 1992/11/19 03:03:33 ahd
* drop rcsid
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <fcntl.h>
#include <process.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#ifdef _Windows
#include <windows.h>
#endif
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "arpadate.h"
#include "dater.h"
#include "expath.h"
#include "getopt.h"
#include "getseq.h"
#include "hlib.h"
#include "hostable.h"
#include "import.h"
#include "lock.h"
#include "logger.h"
#include "pushpop.h"
#include "readnext.h"
#include "security.h"
#include "timestmp.h"
#include "usertabl.h"
#include "execute.h"
#ifdef _Windows
#include "winutil.h"
#endif
currentfile();
/*--------------------------------------------------------------------*/
/* Execution flag defines */
/*--------------------------------------------------------------------*/
typedef enum {
X_OUTPUT, /* 'O' return output to "outnode" */
X_FAILED, /* 'Z' send status if command failed */
X_SUCCESS, /* 'n' send status if command succeeded */
X_INPUT, /* 'B' return command input on error */
X_USEEXEC, /* 'E' process command using exec(2) */
X_STATFIL, /* 'M' return status to file on remote */
S_CORRUPT,
S_EMPTY,
S_NOREAD,
S_NOWRITE,
S_STDIN,
E_NORMAL,
E_NOACC,
E_SIGNAL,
E_STATUS,
E_NOEXE,
E_FAILED,
UU_LAST
} UU_FLAGS;
/*--------------------------------------------------------------------*/
/* Global Variables */
/*--------------------------------------------------------------------*/
static char *spool_fmt = SPOOLFMT;
static char *dataf_fmt = DATAFFMT;
static char *send_cmd = "S %s %s %s -%s %s 0666 %s\n";
/*--------------------------------------------------------------------*/
/* Internal prototypes */
/*--------------------------------------------------------------------*/
static void usage( void );
static boolean copylocal(const char *from, const char *to);
static boolean do_uuxqt( const char *sysname );
static void process( const char *fname,
const char *remote,
const char *executeDirectory);
char **create_environment(const char *logname,
const char *requestor);
static void delete_environment( char **envp);
static boolean AppendData( const char *input, FILE* dataout);
static boolean do_copy( char *localfile,
const char *rmtsystem,
const char *remotefile,
const char *requestor,
const boolean success );
static void ReportResults(const int status,
const char *input,
char *output,
const char *command,
const char *job_id,
const time_t jtime,
const char *requestor,
const char *outnode,
const char *outname,
const boolean xflag[],
const char *statfil,
const char *machine,
const char *user);
static int shell(char *command,
const char *inname,
const char *outname,
const char *remotename,
boolean xflag[]);
static boolean MailStatus(char *tempfile,
char *address,
char *subject);
/*--------------------------------------------------------------------*/
/* m a i n */
/* */
/* Main program */
/*--------------------------------------------------------------------*/
void main( int argc, char **argv)
{
int c;
extern char *optarg;
extern int optind;
char *sysname = "all";
/*--------------------------------------------------------------------*/
/* Report our version number and date/time compiled */
/*--------------------------------------------------------------------*/
debuglevel = 1;
banner( argv );
#if defined(__CORE__)
copywrong = strdup(copyright);
checkref(copywrong);
#endif
/*--------------------------------------------------------------------*/
/* Process our arguments */
/*--------------------------------------------------------------------*/
while ((c = getopt(argc, argv, "s:x:")) != EOF)
switch(c) {
case 's':
sysname = optarg;
break;
case 'x':
debuglevel = atoi( optarg );
break;
case '?':
usage();
exit(1);
break;
default:
printmsg(0, "uuxqt - invalid option -%c", c);
usage();
exit(2);
break;
}
if (optind != argc) {
fputs("Extra parameter(s) at end.\n", stderr);
usage();
exit(2);
}
/*--------------------------------------------------------------------*/
/* Initialize */
/*--------------------------------------------------------------------*/
tzset(); // Set up time zone information
if (!configure( B_UUXQT ))
exit(1); /* system configuration failed */
/*--------------------------------------------------------------------*/
/* Switch to the spooling directory */
/*--------------------------------------------------------------------*/
PushDir( E_spooldir );
atexit( PopDir );
/*--------------------------------------------------------------------*/
/* Initialize logging file */
/*--------------------------------------------------------------------*/
openlog( NULL );
checkuser( E_mailbox ); // Force User Table to initialize
checkreal( E_mailserv ); // Force Host Table to initialize
if (!LoadSecurity())
{
printmsg(0,"Unable to initialize security, see previous message");
exit(2);
} /* if (!LoadSecurity()) */
#if defined(_Windows)
atexit( CloseEasyWin ); // Auto-close EasyWin on exit
#endif
/*--------------------------------------------------------------------*/
/* Set up search path for our programs */
/*--------------------------------------------------------------------*/
if ( E_uuxqtpath != NULL )
{
char buf[BUFSIZ];
char *p;
sprintf(buf,"PATH=%s", E_uuxqtpath);
p = newstr(buf);
if (putenv( p ))
{
printmsg(0,"Unable to set path \"%s\"", p);
panic();
} /* if (putenv( p )) */
} /* if ( E_uuxqtpath != NULL ) */
/*--------------------------------------------------------------------*/
/* Disable OS/2 undelete support if desired */
/*--------------------------------------------------------------------*/
if ( !bflag[ F_UNDELETE ] )
putenv( "DELDIR=");
/*--------------------------------------------------------------------*/
/* Actually invoke the processing routine for the eXecute files */
/*--------------------------------------------------------------------*/
do_uuxqt( sysname );
if( equal( sysname , "all" ) )
do_uuxqt( E_nodename );
exit(0);
} /* main */
/*--------------------------------------------------------------------*/
/* d o _ u u x q t */
/* */
/* Processing incoming eXecute (X.*) files for a remote system */
/*--------------------------------------------------------------------*/
static boolean do_uuxqt( const char *sysname )
{
struct HostTable *hostp;
static char uu_machine[] = UU_MACHINE "=";
char hostenv[sizeof uu_machine + 25 + 2];
char executeDirectory[FILENAME_MAX];
char *pattern;
/*--------------------------------------------------------------------*/
/* Determine if we have a valid host */
/*--------------------------------------------------------------------*/
if( !equal( sysname , "all" ) ) {
if (equal( sysname , E_nodename ))
hostp = checkname( sysname );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -