home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / uucp_mods.lha.30.12.93 / uucp_mods / uucico / uux.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  5.0 KB  |  256 lines

  1.  
  2. /*
  3.  *  UUX.C
  4.  *
  5.  *  Copyright 1988 by William Loftus.    All rights reserved.
  6.  *
  7.  *  Example: 1> uux mail-message "burdvax!rmail wpl"
  8.  *
  9.  *  NOTE:   UUX uses C.<host>N<seqno> instead of C.<host>A<seqno> to ensure
  10.  *        UUX transfers occur *after* any email
  11.  *
  12.  *  Hierarchical Spool Conversion 1 Dec 93,
  13.  *                        Mike J. Bruins, bruins@hal9000.apana.org.au
  14.  *
  15.  *  NOTE:   UUX uses <host>/C.<host>N<seqno> instead of C.<host>N<seqno>
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "version.h"
  22. #include "protos.h"
  23. #include <log.h>
  24. #include "owndevunit.h"
  25.  
  26. IDENT(".06");
  27.  
  28. char *NodeName;
  29. char CutNodeName[8];
  30.  
  31. char user[128];
  32. char file_name[128];
  33. char command[128];
  34.  
  35. char ExecFile[128];
  36. char RemoteExecFile[128];
  37. char CommandFile[128];
  38. char DataFile[128];
  39. char RemoteDataFile[128];
  40. int seq;
  41. struct Library *OwnDevUnitBase;
  42.  
  43. char path[128];
  44.  
  45. void GetTo();
  46. void GetSubject();
  47. void myexit(void);
  48.  
  49. #define TRUE 1
  50. #define FALSE 0
  51.  
  52. int
  53. brk()
  54. {
  55.     return(0);
  56. }
  57.  
  58. main(argc, argv)
  59. int argc;
  60. char **argv;
  61. {
  62.     int error;
  63.     char *up = GetUserName();
  64.  
  65.     LogProgram = "uux";
  66.     LogWho  = strdup(up);
  67.  
  68.     atexit(myexit);
  69.  
  70.     if ((OwnDevUnitBase = OpenLibrary(ODU_NAME, 0)) == NULL) {
  71.     printf("Unable to open %s\n", ODU_NAME);
  72.     exit(20);
  73.     }
  74.  
  75.  
  76.     NodeName = FindConfig(NODENAME);
  77.     strncpy(CutNodeName, NodeName, 7);
  78.  
  79.     onbreak(brk);
  80.     if (up == NULL) {
  81.     printf("couldn't find config entry for %s\n", USERNAME);
  82.     exit(1);
  83.     }
  84.     strcpy(user, up);
  85.  
  86.     getcwd(path,128);
  87.     if (argc == 3) {
  88.     strcpy(file_name, argv[1]);
  89.     strcpy(command, argv[2]);
  90.     } else {
  91.     printf("Usage: uux file-name command\n");
  92.     printf("Example: 1> uux mail-message \"burdvax!rmail wpl\"\n");
  93.     chdir(path);
  94.     exit(1);
  95.     }
  96.     seq = GetSequence(4);
  97.     if (seq >= 0)
  98.     error = Queue();
  99.     UnLockFile(ExecFile);
  100.     UnLockFile(CommandFile);
  101.     UnLockFile(DataFile);
  102.     chdir(path);
  103.     if (seq < 0 || error < 0)
  104.     exit(1);
  105.     return(0);
  106. }
  107.  
  108. void
  109. myexit()
  110. {
  111.     UnLockFiles();
  112.  
  113.     if (OwnDevUnitBase) {
  114.     CloseLibrary(OwnDevUnitBase);
  115.     OwnDevUnitBase = NULL;
  116.     }
  117. }
  118.  
  119. Queue()
  120. {
  121.     FILE *fp;
  122.     char system_name[32],dir[256];
  123.     int bang;
  124.     int error;
  125.  
  126.     bang = (int)strchr(command,'!');
  127.     bang = bang - (int)command;
  128.  
  129.     strncpy(system_name, command, bang);
  130.  
  131.     system_name[bang] = '\0';
  132.  
  133.     if (!is_in_L_sys_file(system_name)) {
  134.     printf ("System \"%s\" not in L.sys file.\n", system_name);
  135.     return(-1);
  136.     }
  137.  
  138.     system_name[7] = '\0';
  139.  
  140.     strcpy(dir,MakeConfigPath(UUSPOOL,system_name));  /* hierarch - bruins */
  141.     if(dir==NULL || *dir=='\0'){
  142.     ulog(-1,"Can't create spool for \"%s\".",system_name);
  143.     return(-1);
  144.     }
  145.     if(chdir(dir)){
  146.     ulog(-1,"Can't find spool: \"%s\", creating.",dir);
  147.     if(mkdir(dir)){
  148.       ulog(-1,"Failed to make spool: \"%s\".",dir);
  149.       return(-1);
  150.     }
  151.     chdir(dir);
  152.     }
  153.  
  154.  
  155.     /*
  156.      *    exec_file    Exec file as it appears on remote machine
  157.      *    x_exec_file    Remote's Exec file as it appears on this machine
  158.      *    command_file    Command file (this machine only)
  159.      *    data_file    DataFile as it appears on
  160.      *    x_data_file
  161.      *
  162.      *    local (overload)    txfer_to    remote (uunet)
  163.      *
  164.      *        C.uunetNxxxx    <not txfered>        command file
  165.      *        D.uunetXxxxx    X.overloaXxxxx        exec / Coexec
  166.      *        D.uunetBxxxx    D.overloaBxxxx        data file
  167.      */
  168.  
  169.     sprintf(CommandFile,"C.%sN%s", system_name, SeqToName(seq));
  170.     sprintf(ExecFile,   "D.%sX%s", system_name, SeqToName(seq));
  171.     sprintf(DataFile,   "D.%sB%s", system_name, SeqToName(seq));
  172.     ++seq;
  173.     sprintf(RemoteExecFile, "X.%sX%s", CutNodeName, SeqToName(seq));
  174.     ++seq;
  175.     sprintf(RemoteDataFile, "D.%sB%s", CutNodeName, SeqToName(seq));
  176.  
  177.     LockFile(CommandFile);
  178.     LockFile(ExecFile);
  179.     LockFile(DataFile);
  180.  
  181.     fp = fopen(ExecFile,"w");
  182.     if (fp) {
  183.     fprintf(fp,"U %s %s\n", user, NodeName);
  184.     fprintf(fp,"F %s\n", RemoteDataFile);
  185.     fprintf(fp,"I %s\n", RemoteDataFile);
  186.     fprintf(fp,"C %s\n", (char *)command + bang + 1);
  187.     fclose(fp);
  188.     } else {
  189.     perror(ExecFile);
  190.     return(-1);
  191.     }
  192.  
  193.     fp = fopen(CommandFile, "w");
  194.     if (fp) {
  195.     fprintf(fp,"S %s %s %s - %s 0666\n",
  196.         DataFile,
  197.         RemoteDataFile,
  198.         user,
  199.         DataFile
  200.     );
  201.     fprintf(fp,"S %s %s %s - %s 0666\n",
  202.         ExecFile,
  203.         RemoteExecFile,
  204.         user,
  205.         ExecFile
  206.     );
  207.     fclose(fp);
  208.     } else {
  209.     perror(CommandFile);
  210.     return(-1);
  211.     }
  212.     chdir(path);
  213.     error = Copy(file_name, DataFile,system_name);
  214. /*    chdir(GetConfigDir(UUSPOOL));   needed? - bruins */
  215.     return(error);
  216. }
  217.  
  218. /*
  219.  * Read the control file and grab a few parameters.
  220.  */
  221.  
  222. Copy(from, to, sys)
  223. char *from;
  224. char *to;
  225. char *sys;
  226. {
  227.     FILE *fd;
  228.     FILE *td;
  229.     int c;
  230.     static char to_buf[128];
  231.  
  232.     fd = fopen(from, "r");
  233.     if (!fd) {
  234.     printf("Could not open %s.\n", from);
  235.     perror(from);
  236.     return(-1);
  237.     }
  238.  
  239.     sprintf(to_buf,"%s/%s", MakeConfigPath(UUSPOOL, sys),to); /* hierach */
  240.  
  241.     td = fopen(to_buf, "w");
  242.     if (!td) {
  243.     printf("Could not open %s.\n", to_buf);
  244.     perror(to);
  245.     return(-1);
  246.     }
  247.     while ((c = fgetc(fd)) != EOF) {
  248.     fputc((char)c, td);
  249.     }
  250.     fclose(fd);
  251.     fclose(td);
  252.     return(1);
  253. }
  254.  
  255.  
  256.