📄 uux.c
字号:
expand &&
(expand_path(file, NULL, E_homedir, NULL) == NULL))
return FALSE; /* expand_path will delivery any needed
nasty-gram to user */
return TRUE;
} /* if ( p_left == NULL ) */
/*--------------------------------------------------------------------*/
/* Find the last bang */
/*--------------------------------------------------------------------*/
p_right = strrchr(p, '!'); // look for the last bang
/*--------------------------------------------------------------------*/
/* If the first bang is the first character, it's a local file */
/*--------------------------------------------------------------------*/
if (p_left == p) // First character in path?
{ // Yes --> not a remote path
if ( p_left != p_right ) // More bangs?
{
printmsg(0,"uux - Invalid syntax for local file: %s", p );
return FALSE; // Yes --> I don't grok this
}
strcpy(file, p+1); // Just return filename
if ( expand && (expand_path(file, NULL, E_homedir, NULL) == NULL))
return FALSE; /* expand_path will delivery any needed
nasty-gram to user */
strcpy(sysname, E_nodename);
return TRUE;
} /* p_left == p */
/*--------------------------------------------------------------------*/
/* It's not a local file, continue processing */
/*--------------------------------------------------------------------*/
strcpy(file, p_right + 1); // and thats our filename
strncpy(sysname, p, p_left - p); // and we have a system thats not us
sysname[p_left - p] = '\0';
/*--------------------------------------------------------------------*/
/* Now see if there is an intermediate path */
/*--------------------------------------------------------------------*/
if (p_left != p_right)
{
printmsg(0, "uux - Intermediate system %.*s not supported",
p_right - (p_left + 1), p_left + 1);
return FALSE;
} /* if (p_left != p_right) */
return TRUE; // and we're done
} /* split_path */
/*--------------------------------------------------------------------*/
/* d o _ u u x q t */
/* */
/* Generate a UUXQT command file for local system */
/*--------------------------------------------------------------------*/
static boolean do_uuxqt(char *job_name,
char *src_syst,
char *src_file,
char *dest_syst,
char *dest_file)
{
long seqno = 0;
char *seq = NULL;
FILE *stream; // For writing out data
char msfile[FILENAME_MAX]; // MS-DOS format name of files
char msname[22]; // MS-DOS format w/o path name
char ixfile[15]; /* eXecute file for local system,
UNIX format name for local system */
/*--------------------------------------------------------------------*/
/* Create the UNIX format of the file names we need */
/*--------------------------------------------------------------------*/
seqno = getseq();
seq = JobNumber( seqno );
sprintf(ixfile, spool_fmt, 'X', E_nodename, grade , seq);
/*--------------------------------------------------------------------*/
/* create local X (xqt) file */
/*--------------------------------------------------------------------*/
importpath( msname, ixfile, E_nodename);
mkfilename( msfile, E_spooldir, msname);
if ( (stream = FOPEN(msfile, "w", BINARY_MODE)) == NULL ) {
printerr(msfile);
printmsg(0, "uux: cannot open X file %s", msfile);
return FALSE;
} /* if */
fprintf(stream, "# third party request, job id\n" );
fprintf(stream, "J %s\n", job_name );
fprintf(stream, "F %s/%s/%s %s\n", E_spooldir, src_syst, dest_file,
src_file );
fprintf(stream, "C uucp -C %s %s!%s\n", src_file, dest_syst, dest_file );
fclose (stream);
return TRUE;
} /* do_uuxqt */
/*--------------------------------------------------------------------*/
/* d o _ c o p y */
/* */
/* At this point only one of the systems can be remote and only */
/* 1 hop away. All the rest have been filtered out */
/*--------------------------------------------------------------------*/
static boolean do_copy(char *src_syst,
char *src_file,
char *dest_syst,
char *dest_file)
{
char tmfile[25]; // Unix style name for c file
char idfile[25]; // Unix style name for data file copy
char work[66]; // temp area for filename hacking
char icfilename[66]; // our hacked c file path
char idfilename[66]; // our hacked d file path
struct stat statbuf;
long int sequence;
char *remote_syst; // Non-local system in copy
char *sequence_s;
FILE *cfile;
sequence = getseq();
sequence_s = JobNumber( sequence );
remote_syst = equal(src_syst, E_nodename) ? dest_syst : src_syst;
sprintf(tmfile, spool_fmt, 'C', remote_syst, grade, sequence_s);
importpath(work, tmfile, remote_syst);
mkfilename(icfilename, E_spooldir, work);
if (!equal(src_syst, E_nodename))
{
if (expand_path(dest_file, NULL, E_homedir, NULL) == NULL)
return FALSE;
SwapSlash(src_file);
printmsg(1, "uux - from \"%s\" - control = %s", src_syst,
tmfile);
if ((cfile = FOPEN(icfilename, "a",TEXT_MODE)) == NULL) {
printerr( icfilename );
printmsg(0, "uux: cannot append to %s\n", icfilename);
return FALSE;
}
fprintf(cfile, "R %s %s %s -c D.0 0666", src_file, dest_file,
E_mailbox);
if (flags[FLG_USE_USERID])
fprintf(cfile, " %s\n", user_id);
else
fprintf(cfile, " %s\n", E_mailbox);
fclose(cfile);
return TRUE;
}
else if (!equal(dest_syst, E_nodename)) {
printmsg(1,"uux - spool %s - execute %s",
flags[FLG_COPY_SPOOL] ? "on" : "off",
flags[FLG_QUEUE_ONLY] ? "do" : "don't");
printmsg(1," - dest m/c = %s sequence = %ld control = %s",
dest_syst, sequence, tmfile);
if (expand_path(src_file, NULL, E_homedir, NULL) == NULL)
return FALSE;
SwapSlash(dest_file);
if (stat(src_file, &statbuf) != 0) {
printerr( src_file );
return FALSE;
}
if (statbuf.st_mode & S_IFDIR) {
printf("uux - directory name \"%s\" illegal\n",
src_file );
return FALSE;
}
if (flags[FLG_COPY_SPOOL]) {
sprintf(idfile , dataf_fmt, 'D', E_nodename, sequence_s,
subseq());
importpath(work, idfile, remote_syst);
mkfilename(idfilename, E_spooldir, work);
/* Do we need a MKDIR here for the system? */
if (!cp(src_file, idfilename)) {
printmsg(0, "copy \"%s\" to \"%s\" failed",
src_file, idfilename); // copy data
return FALSE;
}
}
else
strcpy(idfile, "D.0");
if ((cfile = FOPEN(icfilename, "a",TEXT_MODE)) == NULL)
{
printerr( icfilename );
printf("uux: cannot append to %s\n", icfilename);
return FALSE;
} /* if ((cfile = FOPEN(icfilename, "a",TEXT_MODE)) == NULL) */
fprintf(cfile, "S %s %s %s -%s %s 0666", src_file, dest_file,
E_mailbox, flags[FLG_COPY_SPOOL] ? "c" : " ", idfile);
if (flags[FLG_USE_USERID])
fprintf(cfile, " %s\n", user_id);
else
fprintf(cfile, " %s\n", E_mailbox);
fclose(cfile);
return TRUE;
}
else {
if (expand_path(src_file, NULL, E_homedir, NULL) == NULL)
return FALSE;
if (expand_path(dest_file, NULL, E_homedir, NULL) == NULL)
return FALSE;
if (strcmp(src_file, dest_file) == 0)
{
printmsg(0, "%s %s - same file; can't copy\n",
src_file, dest_file);
return FALSE;
} /* if (strcmp(src_file, dest_file) == 0) */
return(cp(src_file, dest_file));
} /* else */
} /* do_copy */
/*--------------------------------------------------------------------*/
/* p r e a m b l e */
/* */
/* write the execute file preamble based on the global flags */
/*--------------------------------------------------------------------*/
static void preamble(FILE* stream)
{
fprintf(stream, "U %s %s\n", E_mailbox, E_nodename);
if (flags[FLG_RETURN_STDIN]) {
fprintf(stream, "# return input on abnormal exit\n");
fprintf(stream, "B\n");
}
if (flags[FLG_NOTIFY_SUCCESS]) {
fprintf(stream, "# return status on success\n");
fprintf(stream, "n\n");
}
if (flags[FLG_NONOTIFY_FAIL]) {
fprintf(stream, "# don't return status on failure\n");
fprintf(stream, "N\n");
} else {
fprintf(stream, "# return status on failure\n");
fprintf(stream, "Z\n");
}
if (flags[FLG_USE_EXEC]) {
fprintf(stream, "# use exec to execute\n");
fprintf(stream, "E\n");
} else {
fprintf(stream, "# use sh execute\n");
fprintf(stream, "e\n");
}
if (flags[FLG_STATUS_FILE]) {
fprintf(stream, "M %s\n", st_out );
}
if (flags[FLG_USE_USERID]) {
fprintf(stream, "# return address for status or input return\n");
fprintf(stream, "R %s\n", user_id );
}
fprintf(stream, "# job id for status reporting\n");
fprintf(stream, "J %s\n", job_id );
return;
} /* preamble */
/*--------------------------------------------------------------------*/
/* d o _ r e m o t e */
/* */
/* gather data files to ship to execution system and build X file */
/*--------------------------------------------------------------------*/
static boolean do_remote(int optind, int argc, char **argv)
{
FILE *stream; // For writing out data
char *sequence_s;
boolean s_remote;
boolean d_remote;
boolean i_remote = FALSE;
boolean o_remote = FALSE;
long sequence;
char src_system[100];
char dest_system[100];
char src_file[FILENAME_MAX];
char dest_file[FILENAME_MAX];
char command[BUFSIZ];
char msfile[FILENAME_MAX]; // MS-DOS format name of files
char msname[22]; // MS-DOS format w/o path name
char tmfile[15]; // Call file, UNIX format name
char lxfile[15]; /* eXecute file for remote system,
UNIX format name for local system */
char rxfile[15]; /* Remote system UNIX name of eXecute
file */
char lifile[15]; // Data file, UNIX format name
char rifile[15]; /* Data file name on remote system,
UNIX format */
char* jobid_fmt = &spool_fmt[3];
/*--------------------------------------------------------------------*/
/* Get the remote system and command to execute on that system */
/*--------------------------------------------------------------------*/
if (!split_path(argv[optind++], dest_system, command, FALSE, E_nodename))
{
printmsg(0, "uux - illegal syntax %s", argv[--optind]);
return FALSE;
}
d_remote = equal(dest_system, E_nodename) ? FALSE : TRUE ;
/*--------------------------------------------------------------------*/
/* OK - we have a destination system - do we know him? */
/*--------------------------------------------------------------------*/
if ((d_remote) && (checkreal(dest_system) == BADHOST))
{
printmsg(0, "uux - bad system: %s", dest_system);
return FALSE;
}
printmsg(9,"xsys -> %s", dest_system);
printmsg(9, "system \"%s\", rest \"%s\"", dest_system, command);
sequence = getseq();
sequence_s = JobNumber( sequence );
sprintf(job_id, jobid_fmt, dest_system, grade, sequence_s);
/*--------------------------------------------------------------------*/
/* create remote X (xqt) file */
/*--------------------------------------------------------------------*/
sprintf(rxfile, dataf_fmt, 'X', E_nodename, sequence_s, subseq());
sprintf(lxfile, dataf_fmt, d_remote ? 'D' : 'X', E_nodename,
sequence_s, subseq());
importpath( msname, lxfile, dest_system);
mkfilename( msfile, E_spooldir, msname);
if ( (stream = FOPEN(msfile, "w", BINARY_MODE)) == NULL ) {
printerr(msfile);
printmsg(0, "uux: cannot open X file %s", msfile);
return FALSE;
} /* if */
preamble(stream);
/*--------------------------------------------------------------------*/
/* Process options for the remote command */
/*--------------------------------------------------------------------*/
for (; optind < argc; optind++)
{
FileType f_remote = DATA_FILE;
char *remote_file;
switch (*argv[optind])
{
case '-':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -