home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * UUX.C
- *
- * Copyright 1988 by William Loftus. All rights reserved.
- *
- * Example: 1> uux mail-message "burdvax!rmail wpl"
- *
- * NOTE: UUX uses C.<host>N<seqno> instead of C.<host>A<seqno> to ensure
- * UUX transfers occur *after* any email
- *
- * Hierarchical Spool Conversion 1 Dec 93,
- * Mike J. Bruins, bruins@hal9000.apana.org.au
- *
- * NOTE: UUX uses <host>/C.<host>N<seqno> instead of C.<host>N<seqno>
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "version.h"
- #include "protos.h"
- #include <log.h>
- #include "owndevunit.h"
-
- IDENT(".06");
-
- char *NodeName;
- char CutNodeName[8];
-
- char user[128];
- char file_name[128];
- char command[128];
-
- char ExecFile[128];
- char RemoteExecFile[128];
- char CommandFile[128];
- char DataFile[128];
- char RemoteDataFile[128];
- int seq;
- struct Library *OwnDevUnitBase;
-
- char path[128];
-
- void GetTo();
- void GetSubject();
- void myexit(void);
-
- #define TRUE 1
- #define FALSE 0
-
- int
- brk()
- {
- return(0);
- }
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- int error;
- char *up = GetUserName();
-
- LogProgram = "uux";
- LogWho = strdup(up);
-
- atexit(myexit);
-
- if ((OwnDevUnitBase = OpenLibrary(ODU_NAME, 0)) == NULL) {
- printf("Unable to open %s\n", ODU_NAME);
- exit(20);
- }
-
-
- NodeName = FindConfig(NODENAME);
- strncpy(CutNodeName, NodeName, 7);
-
- onbreak(brk);
- if (up == NULL) {
- printf("couldn't find config entry for %s\n", USERNAME);
- exit(1);
- }
- strcpy(user, up);
-
- getcwd(path,128);
- if (argc == 3) {
- strcpy(file_name, argv[1]);
- strcpy(command, argv[2]);
- } else {
- printf("Usage: uux file-name command\n");
- printf("Example: 1> uux mail-message \"burdvax!rmail wpl\"\n");
- chdir(path);
- exit(1);
- }
- seq = GetSequence(4);
- if (seq >= 0)
- error = Queue();
- UnLockFile(ExecFile);
- UnLockFile(CommandFile);
- UnLockFile(DataFile);
- chdir(path);
- if (seq < 0 || error < 0)
- exit(1);
- return(0);
- }
-
- void
- myexit()
- {
- UnLockFiles();
-
- if (OwnDevUnitBase) {
- CloseLibrary(OwnDevUnitBase);
- OwnDevUnitBase = NULL;
- }
- }
-
- Queue()
- {
- FILE *fp;
- char system_name[32],dir[256];
- int bang;
- int error;
-
- bang = (int)strchr(command,'!');
- bang = bang - (int)command;
-
- strncpy(system_name, command, bang);
-
- system_name[bang] = '\0';
-
- if (!is_in_L_sys_file(system_name)) {
- printf ("System \"%s\" not in L.sys file.\n", system_name);
- return(-1);
- }
-
- system_name[7] = '\0';
-
- strcpy(dir,MakeConfigPath(UUSPOOL,system_name)); /* hierarch - bruins */
- if(dir==NULL || *dir=='\0'){
- ulog(-1,"Can't create spool for \"%s\".",system_name);
- return(-1);
- }
- if(chdir(dir)){
- ulog(-1,"Can't find spool: \"%s\", creating.",dir);
- if(mkdir(dir)){
- ulog(-1,"Failed to make spool: \"%s\".",dir);
- return(-1);
- }
- chdir(dir);
- }
-
-
- /*
- * exec_file Exec file as it appears on remote machine
- * x_exec_file Remote's Exec file as it appears on this machine
- * command_file Command file (this machine only)
- * data_file DataFile as it appears on
- * x_data_file
- *
- * local (overload) txfer_to remote (uunet)
- *
- * C.uunetNxxxx <not txfered> command file
- * D.uunetXxxxx X.overloaXxxxx exec / Coexec
- * D.uunetBxxxx D.overloaBxxxx data file
- */
-
- sprintf(CommandFile,"C.%sN%s", system_name, SeqToName(seq));
- sprintf(ExecFile, "D.%sX%s", system_name, SeqToName(seq));
- sprintf(DataFile, "D.%sB%s", system_name, SeqToName(seq));
- ++seq;
- sprintf(RemoteExecFile, "X.%sX%s", CutNodeName, SeqToName(seq));
- ++seq;
- sprintf(RemoteDataFile, "D.%sB%s", CutNodeName, SeqToName(seq));
-
- LockFile(CommandFile);
- LockFile(ExecFile);
- LockFile(DataFile);
-
- fp = fopen(ExecFile,"w");
- if (fp) {
- fprintf(fp,"U %s %s\n", user, NodeName);
- fprintf(fp,"F %s\n", RemoteDataFile);
- fprintf(fp,"I %s\n", RemoteDataFile);
- fprintf(fp,"C %s\n", (char *)command + bang + 1);
- fclose(fp);
- } else {
- perror(ExecFile);
- return(-1);
- }
-
- fp = fopen(CommandFile, "w");
- if (fp) {
- fprintf(fp,"S %s %s %s - %s 0666\n",
- DataFile,
- RemoteDataFile,
- user,
- DataFile
- );
- fprintf(fp,"S %s %s %s - %s 0666\n",
- ExecFile,
- RemoteExecFile,
- user,
- ExecFile
- );
- fclose(fp);
- } else {
- perror(CommandFile);
- return(-1);
- }
- chdir(path);
- error = Copy(file_name, DataFile,system_name);
- /* chdir(GetConfigDir(UUSPOOL)); needed? - bruins */
- return(error);
- }
-
- /*
- * Read the control file and grab a few parameters.
- */
-
- Copy(from, to, sys)
- char *from;
- char *to;
- char *sys;
- {
- FILE *fd;
- FILE *td;
- int c;
- static char to_buf[128];
-
- fd = fopen(from, "r");
- if (!fd) {
- printf("Could not open %s.\n", from);
- perror(from);
- return(-1);
- }
-
- sprintf(to_buf,"%s/%s", MakeConfigPath(UUSPOOL, sys),to); /* hierach */
-
- td = fopen(to_buf, "w");
- if (!td) {
- printf("Could not open %s.\n", to_buf);
- perror(to);
- return(-1);
- }
- while ((c = fgetc(fd)) != EOF) {
- fputc((char)c, td);
- }
- fclose(fd);
- fclose(td);
- return(1);
- }
-
-
-