home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / newc_dev / uucicosd.lha / uucico.c < prev    next >
C/C++ Source or Header  |  1993-03-21  |  47KB  |  2,015 lines

  1. /*
  2.  *  UUCICO.C
  3.  *
  4.  *  (C) Copyright 1987 by John Gilmore.
  5.  *  Copying and use of this program are controlled by the terms of the Free
  6.  *  Software Foundation's GNU Emacs General Public License.
  7.  *
  8.  *  Derived from:
  9.  *  i[$]uuslave.c     1.7 08/12/85 14:04:20
  10.  *  which came from the ACGNJ BBS system at +1 201 753 9758.  Original
  11.  *  author unknown.
  12.  *
  13.  *  Ported to Amiga by William Loftus
  14.  *  Amiga Changes Copyright 1988 by William Loftus.  All rights reserved.
  15.  *  Additional Major Changes (c)Copyright 1989-91 by Matthew Dillon, All rights reserved
  16.  *  Additional Changes (alternate send-expect) by Chris Hind Genly),
  17.  *    (c)Copyright 1991 by Chris Hind Genly, All rights Reserved
  18.  *
  19.  *  Added variable packetsize (-Pn). <CB>
  20.  *
  21.  *  JJB  - Xferstat support (patches posted to .patches).
  22.  *
  23.  *  sd:.1 - Added Mail notify on failure/success file copies
  24.  *       - Added Packet retry logging and Force failure if > %25 in error.
  25.  *       - Added 8K (setvbuf) to buffer writes to disk.
  26.  *       - Fixed bug with send_file returning COPYFAIL (lost files on send)
  27.  *       - Logging of number dailed to logfile
  28.  *       - Record device used and phone number dailed in xferstat
  29.  *       - Added Converstation failed msgs & failed msg to xferstat
  30.  *  sd:.2 - Now run sendmail so as not to hold up uucico
  31.  *  sd:.3 - Mods to gio.c & sysdep.c to decrease cpu load during highspeed
  32.  *          receiving of files: delays to read more serial data in one read
  33.  *        (also fixed host_name overwritting thanks to Kai.)
  34.  */
  35.  
  36.  
  37. #include "includes.h"           /* System include files, system dependent */
  38. #include "uucp.h"               /* Uucp definitions and parameters */
  39. #include <log.h>
  40. #include "version.h"
  41. #include <owndevunit.h>
  42.  
  43. #define PROTOF_SHEREEQUALS  0x0001  /*    ProtoHacks  */
  44.  
  45. Prototype   int getname(int);
  46. Prototype   int get_proto(void);
  47. Prototype   int instr(char *, int, int);
  48. Prototype   int inline(int, char *, int);
  49. Prototype   int twrite(const char *, int);
  50. Prototype   void xlat_str(char *);
  51. Prototype   int read_ctl(void);
  52. Prototype   int do_outbound(void);
  53. Prototype   int call_system(char *, int);
  54. Prototype   int call_sysline(char *);
  55. Prototype   int do_session(int);
  56. Prototype   int top_level(int);
  57. Prototype   int do_one_slave(void);
  58. Prototype   int do_one_master(void);
  59. Prototype   int yesno(char, int, int);
  60. Prototype   int host_send_file(char *);
  61. Prototype   int host_receive_file(char *);
  62. Prototype   int local_send_file(char *, int *);
  63. Prototype   int local_receive_file(void);
  64. Prototype   int receive_file(FILE *, char *, char *, char *, int);
  65. Prototype   int send_file(FILE *);
  66.  
  67. Prototype   short ProtoHacks;
  68. Prototype   short PriMode;
  69. Prototype   short OldPri;
  70. Prototype   short BigGOpt;
  71. Prototype   short IgnoreDTR;
  72. Prototype   int   PacketTimeout;
  73. Prototype   int   SendExpectTimeout;
  74. Prototype   int   ExitCode;
  75.  
  76. Prototype   long  BytesIn;
  77. Prototype   long  BytesOut;
  78.  
  79. void LogTimes(short);
  80.  
  81. #define MAX_FLAGS    40
  82.  
  83. extern int errno;
  84.  
  85. IDENT(".23 sd.3");
  86.  
  87. char *ver= "$VER: 1.16.23.sd.3"; 
  88.  
  89. static char *Copyright = COPYRIGHT;
  90.  
  91. char    ttynam[NAMESIZE],        /* Name of tty we use as serial port */
  92.     srcnam[NAMESIZE],        /* Source file name */
  93.     dstnam[NAMESIZE],        /* Dest file name */
  94.     who[NAMESIZE] = "-",            /* Who sent the file */
  95.     flags[MAX_FLAGS],        /* Flags from file xfer cmd */
  96.     temp[NAMESIZE];         /* Temp file name */
  97.  
  98. int    ourpid = 0,            /* Our process ID */
  99.     ignore_time_restrictions = 0,    /* Call out even if L.sys sez no */
  100.     mode;                /* File mode from file xfer cmd */
  101.  
  102. char  host_name[MAX_HOST] = "AmigaUUCP";  /* Other guy's host name */
  103. char  our_name[MAX_HOST];    /* Our uucp hostname, set from usenet.ctl */
  104. char  path[128];
  105. int   debug   = -1;    /* -1 indicates not set by command line or ctl file */
  106. int   f_wait  = 0;    /* wait for a call (-w) or calls (-w -e) after outbnd */
  107. int   loop    = 0;    /* Loop accepting logins if tty name specified */
  108. int   Overide = 0;    /* overide modem protocol        */
  109. int   Getty   = 0;    /* -Getty initiated            */
  110. int   IgnoreCD= 0;    /* xgetc() should ignore carrier?   */
  111. int   OurNameOv= 0;
  112. int   WindowSize = 999;
  113. int   SegSize = 2;
  114. int   NoReScan = 0;    /* do not rescan for work after error    */
  115. int   SevenWire= 0;
  116. int   XDebug  = 0;    /* do not pass debug parameter to remote    */
  117. int   DebugHandshake = 0;
  118. int   PacketTimeout = 0;
  119. int   SendExpectTimeout = SENDEXPECT_TO;
  120. int   ExitCode = 0;
  121. short ProtoHacks;     /*  protocol hacks  */
  122. short PriMode;
  123. short OldPri;
  124. short IgnoreDTR = 0;
  125. short DoAttempt = 0;
  126. short BigGOpt;
  127.  
  128. long  BytesIn;
  129. long  BytesOut;
  130. time_t    TimeBegin1;
  131. time_t    TimeBegin2;
  132.  
  133. int copynotify;  /* mail notify bits */
  134. char mailsub[NAMESIZE+100];
  135. #define CTRLFILE(f) (f[1] == '.' && (f[0] == 'D' || f[0] == 'X' || f[0] == 'C'))
  136.  
  137. struct Library *OwnDevUnitBase;
  138.  
  139. #define MAX_STRING    200    /* Max length string to send/expect */
  140.  
  141. #define MSGO2IDX    6
  142.  
  143. /* We print these prompts */
  144.  
  145. char msgo0[] = "login: ";
  146. char msgo1[] = "Password:";
  147. char msgo2[10+MAX_HOST] = { "\20Shere" };   /*  NO =    */
  148. char msgo3[] = "\20ROK\0";
  149. char msgo3a[]= "\20P";
  150. char msgo3bg[]= "\20Pg\0";
  151. char msgo3bG[]= "\20PG\0";
  152. char msgo4[] = "\20OOOOOOO\0";
  153.  
  154. /* We expect to receive these strings */
  155.  
  156. char msgi0[] = "uucp\r";
  157. char msgi1[] = "s8000\r";
  158. /* char msgi2[] = "\20S*\0"; We now scan it specially FIXME */
  159. char msgi3g[] = "\20Ug\0";
  160. char msgi3G[] = "\20UG\0";
  161. char msgi4[] = "OOOOOO";
  162.  
  163. /*
  164.  * Protocol switch data structure
  165.  */
  166.  
  167. #define turnon    gturnon
  168. #define rdmsg    grdmsg
  169. #define wrmsg    gwrmsg
  170. #define rddata    grddata
  171. #define wrdata    gwrdata
  172. #define turnoff gturnoff
  173.  
  174. int
  175. getname(isshere)
  176. int isshere;
  177. {
  178.     int data, count = 0;
  179.     static char msgi[MAX_STRING+SLOP];    /* Incoming trash buffer */
  180.  
  181.     /* Read data until null character */
  182.  
  183.     while ((data = xgetc(BYTE_TO,0)) != EOF) {
  184.     data &= 0x7F;
  185.     if (data == 020)
  186.         break;
  187.     }
  188.     if (data == EOF)
  189.     return FAIL;
  190.  
  191.     while ((data = xgetc(BYTE_TO,0)) != EOF && (data & 0x7F)) {
  192.     data &= 0x7F;
  193.     if (count == 0 && data != 'S')
  194.         continue;
  195.     if (count > sizeof(msgi) - 2)
  196.         continue;
  197.     if (data == 0x0A)       /*  hack fix for tuvie ? */
  198.         break;
  199.     msgi[count++] = (char)data;
  200.     }
  201.     msgi[count] = 0;
  202.  
  203.     if (debug > 8)
  204.     printf("GETNAME MSG (%d): %s\n", count, msgi);
  205.  
  206.     if (msgi[0] != 'S')
  207.     return FAIL;
  208.     if (isshere) {
  209.     for (count = 1; msgi[count] && msgi[count] != '='; ++count);
  210.     if (msgi[count] == '=')
  211.         ++count;
  212.     } else {
  213.     count = 1;
  214.     }
  215.     if (msgi[count]) {
  216.         strncpy(host_name, msgi + count, MAX_HOST-1);
  217.         host_name[MAX_HOST-1] = '\0';
  218.     if (debug > 8)
  219.         printf("Compare host names: '%s' '%s'\n", host_name, msgi + count);
  220.     }
  221.     strtok(host_name, " \t");     /*  put \0 after hostname */
  222.     if (debug > 8)
  223.     printf("Hostname is '%s'\n", host_name);
  224.     return SUCCESS;
  225. }
  226.  
  227. /*
  228.  *  get_proto() checks the list of protos given by the foriegn machine
  229.  *  checking for 'g' (which is the only proto we have).  Use only in master
  230.  *  mode.
  231.  */
  232.  
  233. int
  234. get_proto()
  235. {
  236.     int data;
  237.  
  238.     while ((data = xgetc(BYTE_TO,0)) != EOF) {
  239.     data &= 0x7F;
  240.     if (data == 0)
  241.         break;
  242.     if (data == 'g')
  243.         return(SUCCESS);
  244.     }
  245.     return FAIL;
  246. }
  247.  
  248. /*
  249.  * Medium level input routine.
  250.  *
  251.  * Look for an input string for the send-expect sequence.
  252.  * Return 0 for matching string, 1 for timeout before we found it.
  253.  * FIXME:  we only time out if the other end stops sending.  If it
  254.  *       keeps sending, we keep listening forever.
  255.  */
  256.  
  257. instr(s, n, to)
  258. char *s;
  259. int n;
  260. int to;     /*    timeout */
  261. {
  262.     int data,count,j;
  263.     int i;
  264.     static char msgi[512];  /* Incoming trash buffer */
  265.  
  266.     count = 0;
  267.     if (to == 0)
  268.     to = BYTE_TO;
  269.  
  270.     if (debug > 8) {
  271.     printf("Expecting ");
  272.     for (i = 0; i < n; i++)
  273.         printc(s[i]);
  274.     printf("\n");
  275.     }
  276.     if (DebugHandshake) {
  277.     printf("recvd: '");
  278.     fflush(stdout);
  279.     }
  280.  
  281.     while ((data = xgetc(to,0)) != EOF) {
  282.     data &= 0x7F;
  283.  
  284.     msgi[count++] = data;
  285.  
  286.     if (DebugHandshake) {
  287.         if (data < 0x20)
  288.         printf("^%c", data + '@');
  289.         else
  290.         printf("%c", data);
  291.         fflush(stdout);
  292.     }
  293.  
  294.     if (count == sizeof(msgi)) {    /*  throw away first half */
  295.         count = sizeof(msgi) / 2;
  296.         bcopy(msgi + sizeof(msgi) / 2, msgi, sizeof(msgi) / 2);
  297.     }
  298.  
  299.     if (count >= n) {
  300.         for (i = n - 1, j = count - 1; i >= 0; i--, j--) {
  301.         if (*(s+i) != msgi[j])
  302.             break;
  303.         }
  304.         if (i < 0) {
  305.         if (debug > 8)
  306.             printf("\n");
  307.         if (DebugHandshake)
  308.             printf("' (GOTIT!)\n");
  309.         return(0);
  310.         }
  311.     }
  312.     }
  313.     if (DebugHandshake)
  314.     printf("' (TIMEOUT!)\n");
  315.  
  316.     if (debug > 8)
  317.     printf("\n");
  318.     msgi[count] = (char)0;
  319.     return(1);
  320. }
  321.  
  322. /*
  323.  * Medium level input routine.
  324.  *
  325.  *  input a line, return -1 on timeout condition else 0
  326.  */
  327.  
  328. inline(to, buf, max)
  329. int to;
  330. char *buf;
  331. int max;
  332. {
  333.     short c;
  334.     short i = 0;
  335.  
  336.     --max;
  337.     if (to == 0)
  338.     to = BYTE_TO;
  339.  
  340.     if (debug > 8 || DebugHandshake) {
  341.     printf("Inline: ");
  342.     fflush(stdout);
  343.     }
  344.  
  345.     while ((c = xgetc(to,0)) != EOF && i < max) {
  346.     if (c == '\n' || c == '\r')
  347.         break;
  348.     if (debug > 8 || DebugHandshake)
  349.         printf("%c", c);
  350.     buf[i++] = c;
  351.     }
  352.     if (debug > 8 || DebugHandshake)
  353.     printf(" (%d c=%d)\n", i, c);
  354.     buf[i] = 0;
  355.     if (c == EOF)
  356.     return(-1);
  357.     return(0);
  358. }
  359.  
  360. /*
  361.  * Debugging hack for stuff written to the modem.
  362.  */
  363.  
  364. int
  365. twrite(s, n)
  366. const char *s;
  367. int  n;
  368. {
  369.     int i;
  370.  
  371.     if (debug > 8) {
  372.     printf("Wrote:  ");
  373.     for (i = 0; i < n; i++)
  374.         printc(s[i]);
  375.     printf("\n");
  376.     }
  377.     return xwrite(s, n);
  378. }
  379.  
  380. void
  381. myexit()
  382. {
  383.     if (PriMode) {
  384.     long task = FindTask(NULL);
  385.     SetTaskPri(task, OldPri);
  386.     }
  387.  
  388.     UnLockFiles();
  389.  
  390.     if (OwnDevUnitBase) {
  391.     CloseLibrary(OwnDevUnitBase);
  392.     OwnDevUnitBase = NULL;
  393.     }
  394. }
  395.  
  396. /*
  397.  * MAIN ROUTINE.
  398.  *
  399.  * This is called at program startup.  It parses the arguments to the
  400.  * program (if any) and sets up to receive a call on the modem.
  401.  *
  402.  * If there are no arguments, we assume the caller is already on standard
  403.  * input, waiting to do uucp protocols (past the login prompt), and we
  404.  * just handle one caller.
  405.  *
  406.  * If there is an argument, it is the name of the tty device where we
  407.  * should listen for multiple callers and handle login and password.
  408.  */
  409.  
  410. main(argc,argv)
  411. int argc;
  412. char *argv[];
  413. {
  414.     int     i;
  415.     char    *poll_sys = (char *)NULL;   /* System name to poll, or none */
  416.     short   rmode = 0;            /* 1 = master, 0 = slave    */
  417.  
  418.     LogProgram = "uucico";
  419.     LogHost = host_name;
  420.     LogWho  = who;
  421.  
  422.     signal(SIGINT, sigint);
  423.     atexit(myexit);
  424.  
  425.     if ((OwnDevUnitBase = OpenLibrary(ODU_NAME, 0)) == NULL) {
  426.     printf("Unable to open %s\n", ODU_NAME);
  427.     exit(20);
  428.     }
  429.  
  430.     /* FIXME, use getopt */
  431.     /* scan command line arguments, kinda kludgy but it works */
  432.  
  433.     for (i = 1; i < argc; ++i) {
  434.     char *ptr = argv[i];
  435.  
  436.     if (*ptr != '-') {
  437.         printf("uucico: warning, extra args ignored: %s\n", argv[i]);
  438.         break;
  439.     }
  440.     ptr += 2;
  441.     switch (ptr[-1]) {
  442.     case 'N':
  443.         strcpy(our_name, ptr);
  444.         OurNameOv = 1;
  445.         break;
  446.     case 'D':       /*  Serial Device   */
  447.         {
  448.         extern char *DeviceName;
  449.         DeviceName = argv[++i];
  450.         }
  451.         break;
  452.     case 'U':       /*  Serial Unit     */
  453.         {
  454.         extern long DeviceUnit;
  455.         DeviceUnit = ((*ptr >= '0' && *ptr <= '9') ? atoi(ptr) : atoi(argv[++i]));
  456.         }
  457.         break;
  458.     case 'p':       /*  protocol hacks  */
  459.         if (strcmp(ptr, "ri") == 0) {   /*  -pri    */
  460.         long task = FindTask(NULL);
  461.  
  462.         PriMode = 1;
  463.         OldPri = SetTaskPri(task, 5);
  464.         SetTaskPri(task, OldPri + 1);
  465.         } else if (strcmp(ptr, "G") == 0) {
  466.         /*
  467.          *  XXX in development, does NOT work yet!
  468.          */
  469.  
  470.         BigGOpt = 1;
  471.         } else {                /*    -proto    */
  472.         ProtoHacks |= (*ptr) ? atoi(ptr) : atoi(argv[++i]);
  473.         }
  474.         break;
  475.     case 'g':
  476.     case 'G':
  477.         Getty = 1;
  478.         break;
  479.     case 'h':
  480.         IgnoreCD = 1;
  481.         break;
  482.     case 'w':
  483.         ++f_wait;
  484.         break;
  485.     case 'r':
  486.         rmode = atoi(&argv[i][2]);
  487.         break;
  488.     case 'X':
  489.         XDebug = 1;
  490.     case 'x':
  491.         if (argv[i][2] == 'x') {
  492.         DebugHandshake = 1;
  493.         break;
  494.         }
  495.  
  496.         debug = atoi(&argv[i][2]);
  497.         LogLevel = debug;
  498.         LogToStdout = 0;
  499.         printf("uucico: debug level set to %d\n", debug);
  500.         break;
  501.     case 'o':
  502.         Overide = 1;
  503.         break;
  504.     case 'n':
  505.         WindowSize = (*ptr) ? atoi(ptr) : 1;
  506.         break;
  507.     case 'P':
  508.         SegSize = (*ptr) ? atoi(ptr) : 1;
  509.         break;
  510.     case 'b':
  511.         system(GetConfigProgram(BATCHNEWS));
  512.         break;
  513.     case 'S':
  514.         ignore_time_restrictions++;
  515.     case 's':
  516.         poll_sys = &argv[i][2];
  517.         break;
  518.     case 'e':
  519.         ++loop;
  520.         break;
  521.     case 't':
  522.         PacketTimeout = (*ptr) ? atoi(ptr) : atoi(argv[++i]);
  523.         break;
  524.     case 'T':
  525.         SendExpectTimeout = (*ptr) ? atoi(ptr) : atoi(argv[++i]);
  526.         break;
  527.     case '7':
  528.         SevenWire = 1;
  529.         break;
  530.     case 'd':
  531.         IgnoreDTR = (*ptr) ? !atoi(ptr) : 1;
  532.         break;
  533.     case 'H':
  534.         IgnoreCD = 1;
  535.         Overide = 1;
  536.         break;
  537.     case 'B':
  538.         i++;    /* throw away baud rate argument */
  539.         break;
  540.     case 'A':
  541.         DoAttempt = 1;
  542.         break;
  543.     default:
  544.         printf("uucico: warning, bad flag %s\n", argv[i]);
  545.         break;
  546.     }
  547.     }
  548.  
  549.     /* If argument provided, use it as name of comm port */
  550.  
  551.     /* FIXME, this needs some thought. */
  552.  
  553.     getcwd(path,128);
  554.     if (chdir(GetConfigDir(UUSPOOL))) {
  555.     perror("Can't chdir to Spool directory");
  556.     exit(2);
  557.     }
  558.  
  559.     read_ctl();
  560.  
  561.     /*
  562.      * If running via getty/login, our debug stdout had better
  563.      * go to a file, not to the usual stdout!
  564.      */
  565.  
  566.     if (debug > 0 && Getty) {
  567.     freopen("T:uuslave.log", "a", stdout);
  568.     }
  569.  
  570.     /*setvbuf(stdout, NULL, _IOLBF, 0);*/
  571.  
  572.     /* Timestamp the long debug log */
  573.  
  574.     if (debug > 0) {
  575.     long clock;
  576.  
  577.     time(&clock);
  578.     printf("\014\nuuslave log on tty '%s' starting %s\n",
  579.         ttynam, ctime(&clock));
  580.     }
  581.  
  582.     /* Log our presence so we humans reading the logs can find the
  583.        entries created by uuslave. */
  584.  
  585.     ulog(-1, "Startup %s", VERSION);
  586.  
  587.     amiga_setup();
  588.  
  589.     modem_init();
  590.  
  591.     if (poll_sys) {
  592.     if (*poll_sys == '\0')
  593.         poll_sys = (char *)NULL;
  594.  
  595.     if (call_system(poll_sys, rmode) == FAIL)
  596.         ExitCode = 5;
  597.  
  598.     if (!f_wait)
  599.         goto end;
  600.     } else {
  601.     if (rmode) {
  602.         if (do_outbound() == FAIL)
  603.         ExitCode = 5;
  604.         if (!f_wait)
  605.         goto end;
  606.     }
  607.     }
  608.  
  609.     do {
  610.     /*
  611.      *  Set up serial channel, wait for incoming call.
  612.      */
  613.  
  614.     DEBUG(0, "\nRestarting\n", 0);
  615.  
  616.     if (Getty == 0 && Overide == 0)
  617.         openline();
  618.  
  619.     do_session(Getty);
  620.     LogTimes(0);
  621.     hangup();
  622.     DEBUG(0, "\nEnd of call\n", 0);
  623.     } while (loop && !Getty);
  624.  
  625. end:
  626.     cleanup();
  627.     return(ExitCode);
  628. }
  629.  
  630. /*
  631.  * translate embedded escape characters
  632.  */
  633.  
  634. void
  635. xlat_str(msg)
  636. char    *msg;
  637. {
  638.     int i  = 0;
  639.     int cr = 1;
  640.  
  641.     while (msg[i]) {
  642.     if (msg[i] == '\\') {
  643.         switch (msg[++i]) {
  644.         case 'r':            /* carriage return */
  645.         twrite("\r", 1);
  646.         break;
  647.         case 'n':            /* line feed */
  648.         twrite("\n", 1);
  649.         break;
  650.         case '\\':           /* back slash */
  651.         twrite("\\", 1);
  652.         break;
  653.         case 't':            /* tab */
  654.         twrite("\t", 1);
  655.         break;
  656.         case 'b':
  657.         SendBreak();
  658.         break;
  659.         case 'd':            /* delay */
  660.         Delay(180);
  661.         break;
  662.         case 's':            /* space */
  663.         twrite(" ", 1);
  664.         break;
  665.         case 'c':            /* no CR at end */
  666.         cr = 0;
  667.         break;
  668.         default:        /* don't know so skip it */
  669.         break;
  670.         }
  671.         ++i;
  672.     } else {
  673.         twrite(msg + i, 1);
  674.         ++i;
  675.     }
  676.     }
  677.     if (cr) {
  678.     twrite("\r", 1);
  679.     }
  680. }
  681.  
  682.  
  683. /*
  684.  * Read the control file and grab a few parameters.
  685.  */
  686.  
  687.  
  688. int
  689. read_ctl()
  690. {
  691.     char *nodename = FindConfig(NODENAME);
  692.     char *debugstr = FindConfig(DEBUGNAME);
  693.     char *tmp;
  694.  
  695.     if (nodename && OurNameOv == 0)
  696.     strcpy(our_name, nodename);
  697.     if (debugstr && debug < 0)
  698.     debug = atoi(debugstr);
  699.  
  700.     /*
  701.      * sd, get copy notify bits
  702.      *
  703.      * 1 - notify of send failures that will not be retried (ie denied)
  704.      * 2 - notify of send failures that will be retried (ie protocol errors)
  705.      * 4 - notify of successfull outgoing file copy (uucp'd copies only)
  706.      * 8 - notify of incoming file (uucp'd file copies only)
  707.      *16 - notify of incoming failure of anykind
  708.      * 
  709.      * ie set to 31 for all features.
  710.      * mail is sent to username config entry for incoming file and to
  711.      * originator of outgoing file copies (usually the same username)
  712.      */
  713. #define NOTIFY_FAILED   1
  714. #define NOTIFY_RETRY    2
  715. #define NOTIFY_SUCCESS  4
  716. #define NOTIFY_INCOMING 8
  717. #define NOTIFY_INCOMING_FAILURE 16
  718.  
  719.     tmp = FindConfig("CopyNotify"); 
  720.     if (tmp) {
  721.         copynotify = atoi(tmp);
  722.     }
  723.  
  724.     return (1);
  725. }
  726.  
  727. /*
  728.  *  Search spool queues for work, call the systems we need to call.
  729.  *
  730.  *  return FAIL if any system has failed, SUCCESS otherwise.
  731.  */
  732.  
  733. int
  734. do_outbound()
  735. {
  736.     return call_system((char *)NULL, 1);
  737. }
  738.  
  739. /*
  740.  *  Call a specific system, or all systems that have work pending.
  741.  *
  742.  *  If a failure occurs with any system, return FAIL, else return
  743.  *  SUCCESS.
  744.  */
  745.  
  746. int
  747. call_system(sys, ifworkpend)
  748. char    *sys;
  749. {
  750.     FILE    *lsys;
  751.     static char buf[MAX_LSYS];
  752.     static char sysnam[MAX_HOST];
  753.     static char prev_name[MAX_HOST];
  754.     int     called = FAIL;
  755.     int     status = SUCCESS;
  756.  
  757.     /*
  758.      * Unix uucico just reads the directory, and calls the systems
  759.      * in the order of the files in the directory.  We want more
  760.      * control than that, though I'm not sure that L.sys order is
  761.      * best either.  For example, in the first call after 11PM,
  762.      * I'd like to call the sites that haven't been callable before
  763.      * 11PM first, and finish up with the ones I've been able to call
  764.      * all day.  FIXME.
  765.      */
  766.  
  767.     if (! (lsys = fopen(MakeConfigPath(UULIB, "L.sys"), "r"))) {
  768.     DEBUG(0, "uucico: can't open L.sys, errno %d\n", errno);
  769.     return FAIL;
  770.     }
  771.     sysnam[0] = '\0';               /* Initially, no previous sys */
  772.  
  773.     /* Once per system in L.sys... */
  774.     /* FIXME, handle continuation lines (trailing "\") */
  775.  
  776.     while (fgets(buf, sizeof buf, lsys)) {
  777.     if (buf[0] == '#' || buf[0] == '\n')
  778.         continue;
  779.  
  780.     /*
  781.      * Grab the system name.  If same as previous, and
  782.      * the previous call worked, skip it.
  783.      */
  784.  
  785.     strcpy(prev_name, sysnam);
  786.     (void) sscanf(buf, "%s", sysnam);
  787.     if (!strcmp(sysnam, prev_name)) {
  788.         if (called == SUCCESS)
  789.         continue;
  790.     }
  791.  
  792.     /*
  793.      * If a system name was specified, skip til we find it
  794.      * If none was specified, only call if there is work.
  795.      */
  796.  
  797.     if (sys) {
  798.         if (strcmp(sys, sysnam) != 0)
  799.         continue;
  800.         if (ifworkpend && !work_scan(sysnam)) {
  801.         ulog(-1, "No work for system %s", sysnam);
  802.         called = SUCCESS;
  803.         continue;
  804.         }
  805.     } else {
  806.         DEBUG(3,"searching for outbound to %s\n", sysnam);
  807.         if (!work_scan(sysnam)) {
  808.         DEBUG(3,"no work for %s\n", sysnam);
  809.         called = SUCCESS;    /* Don't try further */
  810.         continue;
  811.         }
  812.         DEBUG(2, "uucico: found work for %s\n", sysnam);
  813.     }
  814.  
  815.     /*
  816.      *  call system.  If calling a single system and it succeeds, break
  817.      *  out of loop.  If calling a single system with multiple L.Sys
  818.      *  lines, a later success overides an initial failure in terms of
  819.      *  the return code.
  820.      *
  821.      *  If calling all systems any failure causes a failure return code
  822.      *  XXX FIXME, handling multiple L.Sys entries for same system ???
  823.      */
  824.  
  825.     called = call_sysline(buf);
  826.  
  827.     if (sys) {
  828.         status = called;
  829.         if (called == SUCCESS)
  830.         break;
  831.     } else {
  832.         if (called == FAIL)
  833.         status = FAIL;
  834.     }
  835.     }
  836.     fclose(lsys);
  837.     return(status);
  838. }
  839.  
  840. /*
  841.  *  Call out to a system, given its L.sys line.
  842.  *
  843.  *  Return FAIL if any failure occurs, SUCCESS if all went well.
  844.  */
  845.  
  846. int
  847. call_sysline(lsysline)
  848. char *lsysline;
  849. {
  850.     static char    tempname[MAX_HOST + 30 + SLOP];
  851.     char    *sysnam,
  852.         *times,
  853.         *acu,
  854.         *sbaud,
  855.         *telno,
  856.         *send,
  857.         *expct,
  858.         *expct1,
  859.         *errm;
  860.     int     baud, sendexpectok;
  861.     int     r;
  862.     char    *pnum;
  863.  
  864.     who[0] = '-'; who[1] = '\0';    /* No user now (for logit) */
  865.  
  866.     /* FIXME, use the values it is ignoring here */
  867.  
  868.     sysnam = strtok(lsysline, " \t");
  869.     times =  strtok(NULL, " \t");   /* Time */
  870.     acu =    strtok(NULL, " \t");   /* ACU  */
  871.     sbaud =  strtok(NULL, " \t");   /* Baud */
  872.     telno =  strtok(NULL," \t");    /* phone*/
  873.  
  874.     strcpy(host_name, sysnam);
  875.  
  876.     if (ignore_time_restrictions == 0) {
  877.     if (CheckTimeRestrictions(times) == FAIL) {
  878.         ulog(-1, "Wrong Time To Call %s", sysnam);
  879.         return(FAIL);
  880.     }
  881.     }
  882.  
  883.     baud = atoi(sbaud);
  884.  
  885.     /*    FIX ME, acu not implemented ?    */
  886.     DEBUG(4, "Opening outgoing line %s\n", acu);
  887.  
  888.     if (openout(acu, baud) != SUCCESS)
  889.     return (FAIL);
  890.  
  891.     /* sd added telno logging */
  892.     for (pnum = (telno + strlen(telno)) -1 ; pnum > telno; --pnum) {
  893.     if (isalpha(*pnum)) {
  894.         ++pnum;
  895.         break;
  896.       }
  897.     }
  898.  
  899.     if (Overide == 0) {
  900.     char *errmsg;
  901.     if (errmsg = dial_nbr(telno)) {
  902.         ulog(-1, "FAILED call to %s (%s): %s", host_name, pnum, errmsg);
  903.         return (FAIL);
  904.     }
  905.     }
  906.  
  907.     TimeBegin1 = time(NULL);
  908.     TimeBegin2 = 0;
  909.     BytesIn = 0;
  910.     BytesOut= 0;
  911.  
  912.     /* FIXME, log tty, baud rate, ... */
  913.  
  914.     ulog(-1, "DIALED %s (%s)", host_name,pnum);
  915.  
  916.     /*
  917.      * Process send-expect strings.
  918.      * FIXME, deal with "-", BREAK, etc.
  919.      */
  920.  
  921.     if (DebugHandshake)
  922.     puts("CONNECTED, running send-expect strings");
  923.  
  924.     sendexpectok = TRUE;
  925.  
  926.     do {
  927.     expct = (char *)strtok((char *)NULL, " \t");
  928.     if (expct == NULL)
  929.         break;
  930.  
  931.     if (DebugHandshake)
  932.         printf("Expect = %s\n", expct);
  933.  
  934.     expct1 = strtokp(&expct, "-");
  935.  
  936.     while (expct1) {
  937.         if (expct1[0] != '"' || expct1[1] != '"' || expct1[2] != '\0') {
  938.         if (DebugHandshake)
  939.             printf("Expect %s\n", expct1);
  940.         if (instr(expct1, strlen(expct1), SendExpectTimeout) == SUCCESS)
  941.             break;
  942.         } else {
  943.         if (DebugHandshake)
  944.             puts("Expect Nothing");
  945.         break;
  946.         }
  947.         /*
  948.          *    expect failed, check for alternates
  949.          */
  950.  
  951.         errm = expct1;
  952.         if (expct1 = (char *)strtokp(&expct, "-")) {
  953.         if (DebugHandshake)
  954.             printf("Send = %s\n", expct1);
  955.         xlat_str(expct1);
  956.         } else {
  957.         sendexpectok = FALSE;
  958.         strtok("", " ");
  959.         break;
  960.         }
  961.         expct1 = strtokp(&expct, "-");
  962.     }
  963.     if (send = (char*)strtok((char *)NULL, " \t\n")) {
  964.         if (DebugHandshake)
  965.         printf("Send %s\n", send);
  966.         xlat_str(send);
  967.     }
  968.     } while (send);
  969.  
  970.     TimeBegin2 = time(NULL);
  971.  
  972.     if (sendexpectok)
  973.     ulog(-1, "SUCCEEDED call to %s", host_name);
  974.     else {
  975.     ulog(-1, "FAILED call to %s.  Expected %s", host_name, errm);
  976.     goto bort1;
  977.     }
  978.  
  979.     if (getname(1))         /*  get name        */
  980.     goto bort1;
  981.                 /*    send response    */
  982.     sprintf(tempname, "\20S%s -Q0 -x%d\0", our_name, (XDebug) ? 0 : debug);
  983.     twrite(tempname, strlen(tempname)+1); /* Including null */
  984.  
  985.     /* wait for ok message, wait for protocol request
  986.      * send protocol 'g' response */
  987.     /* FIXME, we don't actually wait for the ROK message, since
  988.      * it is immediately followed by the Pprotos message.  We
  989.      * currently just look for a Pg message.  This needs work.
  990.      * FIXME, WE CAN'T TALK TO SITES THAT SUPPORT more than 'g'.
  991.      */
  992.  
  993.     if (instr(msgo3a, sizeof(msgo3a)-1, 0)) {
  994.     if (!get_proto())
  995.        goto bort1;
  996.     }
  997.  
  998.     if (BigGOpt)
  999.     twrite( msgi3G, sizeof(msgi3G)-1);
  1000.     else
  1001.     twrite( msgi3g, sizeof(msgi3g)-1);
  1002.  
  1003.     ResetGIO();                         /* reset GIO protocol   */
  1004.  
  1005.     if (turnon(1))
  1006.     goto bort1;
  1007.  
  1008.     ulog(-1, "OK Startup");
  1009.  
  1010.     xferinit(host_name);
  1011.     xfer.flags |= XFERF_OUTGOING;
  1012.  
  1013.     r = top_level(1);
  1014.     hangup();
  1015.  
  1016.     xfer.time_stop = time(NULL);
  1017.     if (r == FAIL) {    /* sd */
  1018.         ulog(-1, "Conversation FAILED");
  1019.     }
  1020.     xferstat(pnum, (r == FAIL) ? "# Conversation FAILED => LOGFILE" :  NULL);
  1021.  
  1022.     LogTimes(r);
  1023.     return (r);
  1024.  
  1025. bort1:
  1026.     hangup();
  1027.     LogTimes(FAIL);
  1028.     return (FAIL);
  1029. }
  1030.  
  1031. void
  1032. LogTimes(r)
  1033. short r;
  1034. {
  1035.     time_t e = time(NULL);
  1036.     time_t t1 = (TimeBegin1) ? e - TimeBegin1 : 0;
  1037.     time_t t2 = (TimeBegin2) ? e - TimeBegin2 : 0;
  1038.     FILE *fi;
  1039.     char *logFile = MakeConfigPath(UUSPOOL, "TimeLog");
  1040.     char buf[64];
  1041.  
  1042.     if (fi = fopen(logFile, "a")) {
  1043.     strftime(buf, sizeof(buf), "%d-%b-%y", localtime(&e));
  1044.     fprintf(fi, "%s %02d:%02d %2d:%02d in=%-8d out=%-8d %s\n",
  1045.         buf,
  1046.         e / 3600 % 24, e / 60 % 60,
  1047.         t2 / 60, t2 % 60,
  1048.         BytesIn,
  1049.         BytesOut,
  1050.         host_name
  1051.     );
  1052.     fclose(fi);
  1053.     }
  1054. }
  1055.  
  1056. /* Handle a single uucp [slave] login session */
  1057.  
  1058. int
  1059. do_session(ontheline)
  1060. int ontheline;
  1061. {
  1062.     TimeBegin1 = 0;
  1063.     TimeBegin2 = time(NULL);
  1064.     BytesIn = 0;
  1065.     BytesOut= 0;
  1066.     int r;
  1067.     
  1068.     if (ontheline == 0) {
  1069.     /* output login request, verify uucp */
  1070.     twrite(msgo0,sizeof(msgo0)-1);
  1071.     if (instr(msgi0, sizeof(msgi0)-1, 0)) {
  1072.         printf("uucico: invalid login name\n");
  1073.         goto bort;
  1074.     }
  1075.  
  1076.     /* output password request, verify s8000 */
  1077.     twrite(msgo1,sizeof(msgo1)-1);
  1078.     if (instr(msgi1, sizeof(msgi1)-1, 0)) {
  1079.         printf("uucico: invalid password\n");
  1080.         goto bort;
  1081.     }
  1082.  
  1083.     printf("uucico: correct login\n");
  1084.     }
  1085.  
  1086.     /*
  1087.      *    send Shere=<myhost>
  1088.      *
  1089.      *    Apparently mac UUCP has a bug that only allows 7
  1090.      *    char host names, and it fails if it gets shere=<myhost>
  1091.      *    where <myhost> is > 7 chars.
  1092.      *
  1093.      *    Apparently some implementations of AmigaUUCP do not accept
  1094.      *    an SHere with an =<myhost>, so this is disabled unless -p1 is used.
  1095.      */
  1096.  
  1097.     if (ProtoHacks & PROTOF_SHEREEQUALS)
  1098.     sprintf(msgo2 + MSGO2IDX, "=%s", our_name);
  1099.     twrite(msgo2,strlen(msgo2)+1);
  1100.  
  1101.     /*
  1102.      *    get \020S<host> -Qn n    (??)
  1103.      */
  1104.  
  1105.     if (getname(0))
  1106.     goto bort;
  1107.  
  1108.     /* output ok message, output protocol request, wait for response */
  1109.  
  1110.     twrite(msgo3,sizeof(msgo3)-1);
  1111.  
  1112.     /* FIXME, make the protocol list here, and use it */
  1113.  
  1114.     if (BigGOpt)
  1115.     twrite(msgo3bG,sizeof(msgo3bG)-1);
  1116.     else
  1117.     twrite(msgo3bg,sizeof(msgo3bg)-1);
  1118.  
  1119.     if (BigGOpt) {
  1120.     if (instr(msgi3G, sizeof(msgi3G)-1, 0))
  1121.         goto bort;
  1122.     } else {
  1123.     if (instr(msgi3g, sizeof(msgi3g)-1, 0))
  1124.         goto bort;
  1125.     }
  1126.     ResetGIO();                         /* reset GIO protocol   */
  1127.  
  1128.     if (turnon(0))
  1129.     goto bort;
  1130.  
  1131.     ulog(-1, "OK Startup");
  1132.  
  1133.     xferinit(host_name);
  1134.  
  1135.     r = top_level(0);
  1136.  
  1137.     xfer.time_stop = time(NULL);
  1138.     if (r == FAIL) {    /* sd */
  1139.         ulog(-1, "Conversation FAILED");
  1140.     }
  1141.     xferstat(NULL, (r == FAIL) ? "# Conversation FAILED => LOGFILE" :  NULL);
  1142.  
  1143. bort:
  1144.     if (debug > 0)
  1145.     printf("uucico: call complete\n");
  1146.     return (1);
  1147. }
  1148.  
  1149. /*
  1150.  * Handle transactions "at top level", as Unix uucp's debug log says.
  1151.  *
  1152.  * As master, we scan our queues for work and send requests to the
  1153.  * other side.    When done, we send a hangup request and switch to slave mode.
  1154.  *
  1155.  * As slave, we accept requests from the other side; when it is done,
  1156.  * it sends a hangup request, and we switch to master mode, if we have
  1157.  * any work queued up for that system.
  1158.  *
  1159.  * This repeats as long as either side has work to do.    When all the
  1160.  * queued work is done, we agree to hang up, terminate the packet protocol,
  1161.  * and return to the caller.  (We still haven't hung up the phone line yet.)
  1162.  *
  1163.  * A curious feature of the hangup protocol is that it is not a simple
  1164.  * question-answer.  The master says "H", asking about hangup.  The
  1165.  * slave responds "HY" saying OK.  The master then says "HY" also,
  1166.  * then both of them hang up.  Maybe this is to make sure the first HY
  1167.  * got ack'ed?  Anyway, an "H" is reported as HANGUP and an "HY" as
  1168.  * HANGNOW.  After we send an HY, we go back to listening for commands;
  1169.  * if the master sends something other than HY, we'll do it.
  1170.  */
  1171.  
  1172. #define HANGUP        2        /* Signal to switch master/slave roles */
  1173. #define HANGNOW     3        /* Signal to hang up now */
  1174. #define COPYFAIL    4        /* File copy failed */
  1175.  
  1176. int
  1177. top_level(master_mode)
  1178. int master_mode;
  1179. {
  1180.     static char    buf[MAXMSGLEN];    /* For hangup responses */
  1181.  
  1182.     if (master_mode) {
  1183.     (void) work_scan(host_name);    /* Kick off queue scan */
  1184.     goto master;
  1185.     }
  1186.  
  1187.     for (;;) {
  1188.     slave:            /*  SLAVE SIDE    */
  1189.     for (;;) {
  1190.         DEBUG(4, "*** TOP *** - slave\n", 0);
  1191.         switch (do_one_slave()) {
  1192.         case SUCCESS:
  1193.         break;
  1194.         case FAIL:
  1195.         DEBUG(4, "*** DO_ONE_SLAVE FAIL *** - slave\n", 0);
  1196.         return (FAIL);
  1197.         case HANGUP:
  1198.         if (work_scan(host_name)) {
  1199.             if (wrmsg("HN") != SUCCESS) {
  1200.             DEBUG(4, "*** WRMSG HN FAIL *** - slave\n", 0);
  1201.             return (FAIL);
  1202.             }
  1203.             goto master;
  1204.         } else {
  1205.             if (wrmsg("HY") != SUCCESS) {
  1206.             DEBUG(4, "*** WRMSG HY FAIL *** - slave\n", 0);
  1207.             return (FAIL);
  1208.             }
  1209.             break;    /*  go to master mode */
  1210.         }
  1211.         case HANGNOW:
  1212.         goto quit;
  1213.         }
  1214.     }
  1215.     master:    /*  MASTER SIDE */
  1216.     for (;;) {
  1217.         DEBUG(4, "*** TOP *** - master\n", 0);
  1218.         switch (do_one_master()) {
  1219.         case SUCCESS:
  1220.         break;
  1221.         case FAIL:
  1222.         DEBUG(4, "*** DO_ONE_MASTER FAIL *** - master\n", 0);
  1223.         return (FAIL);
  1224.         case HANGUP:
  1225.         /* We wrote an H command, what's the resp? */
  1226.         if (rdmsg(buf, MAXMSGLEN) != SUCCESS) {
  1227.             DEBUG(4, "*** RDMSG HANGUP FAIL *** - master\n", 0);
  1228.             return (FAIL);
  1229.         }
  1230.         if (buf[0] != 'H') {
  1231.             DEBUG(4, "*** RDMSG HANGUP != 'H' *** - master\n", 0);
  1232.             return (FAIL);
  1233.         }
  1234.         if (buf[1] == 'N') {
  1235.             goto slave;
  1236.         } else {
  1237.             /*
  1238.              *    send final HY?    not sure if this should happen, will
  1239.              *    necessarily fail if the other side does not expect
  1240.              *    it so do not return... continue on w/ exit code.
  1241.              *
  1242.              *    however, reduce timeout parameters
  1243.              */
  1244.  
  1245.             ++ReducedTimeout;
  1246.             wrmsg("HY");
  1247.             --ReducedTimeout;
  1248.             goto quit;
  1249.         }
  1250.         }
  1251.     }
  1252.     }
  1253.  
  1254. quit:
  1255.     /* Shut down the packet protocol */
  1256.  
  1257.     turnoff();
  1258.  
  1259.     /* Write the closing sequence */
  1260.  
  1261.     twrite(msgo4, sizeof(msgo4)-1);
  1262.     (void) instr(msgi4, sizeof(msgi4)-1, 0);
  1263.  
  1264.     twrite(msgo4, sizeof(msgo4)-1);
  1265.  
  1266.     strcpy(who, "-");
  1267.     ulog(-1, "OK Conversation complete");
  1268.  
  1269.     return (SUCCESS);   /* Go byebye */
  1270. }
  1271.  
  1272. /*
  1273.  * We are slave; get a command from the other side and execute it.
  1274.  *
  1275.  * Result is SUCCESS, FAIL, HANGUP, or HANGNOW.
  1276.  */
  1277.  
  1278. int
  1279. do_one_slave()
  1280. {
  1281.     static char msg[MAXMSGLEN];        /* Master's message to us */
  1282.  
  1283.     /* Get master's command */
  1284.     if (rdmsg(msg, MAXMSGLEN) != SUCCESS)
  1285.     return (FAIL);
  1286.  
  1287.     /* Print it for easy debugging */
  1288.     DEBUG(5,"\nCommand: %s\n\n", msg);
  1289.  
  1290.     switch (msg[0]) {
  1291.     case 'S':
  1292.     if (msg[1] != ' ')
  1293.         break;
  1294.     return host_send_file(msg);
  1295.     case 'R':
  1296.     if (msg[1] != ' ')
  1297.         break;
  1298.     return host_receive_file(msg);
  1299.     case 'X':
  1300.     break;
  1301.     case 'H':
  1302.     if (msg[1] == '\0') return (HANGUP);
  1303.     if (msg[1] == 'Y')  return (HANGNOW);
  1304.     if (msg[1] == 'N')  return (SUCCESS);     /* Ignore HN to slave */
  1305.     break;
  1306.     }
  1307.  
  1308.     /* Unrecognized packet from the other end */
  1309.  
  1310.     DEBUG(0, "Bad control packet refused: %s\n", msg);
  1311.  
  1312.     if (ExitCode < 2)
  1313.     ExitCode = 2;
  1314.  
  1315.     return(yesno(msg[0], 0, 0));
  1316. }
  1317.  
  1318. /*
  1319.  *  Do one piece of work as master.
  1320.  *
  1321.  *  FIXME:  we don't handle the flags, e.g. -c, properly!
  1322.  *
  1323.  *  Now only dequeues queue file if all transfers were successful.
  1324.  */
  1325.  
  1326. int
  1327. do_one_master()
  1328. {
  1329.     FILE    *fd;
  1330.     char    *sname;
  1331.     static char cmnd[256];        /* Command character */
  1332.     static char buf[256];
  1333.     int     fail = SUCCESS;
  1334.     int     failAction = SUCCESS;
  1335.     int     failaccum = 0;
  1336.     int     num;
  1337.     int     delmeflag;
  1338.     static char notify[NAMESIZE];   /* A bit large...FIXME */
  1339.     char    *delList[16];        /* delete files list   */
  1340.     short   di = 0;
  1341.  
  1342.     /*
  1343.      *    Get the next work item.  If no work left re-scan the directory
  1344.      *    just to be sure, and if still no work then do the right thing.
  1345.      */
  1346.  
  1347.     sname = work_next();
  1348.     if (!sname && NoReScan == 0) {
  1349.     if (work_scan(host_name))
  1350.         sname = work_next();
  1351.     }
  1352.     if (!sname) {
  1353.     /* No more work, time to hang up. */
  1354.     if (wrmsg("H") != SUCCESS)
  1355.         return (FAIL);
  1356.     return (HANGUP);
  1357.     }
  1358.  
  1359.     DEBUG(2, "Request file %s\n", sname);
  1360.  
  1361.     LockFile(sname);
  1362.  
  1363.     fd = fopen(sname, "r");
  1364.     if (fd == NULL) {
  1365.     UnLockFile(sname);
  1366.     DEBUG(0, "uucico: couldn't open %s\n", sname);
  1367.     return (SUCCESS);
  1368.     }
  1369.  
  1370.     while (fgets(buf, sizeof(buf), fd)) {
  1371.     DEBUG(3, "Queued request: %s", buf);
  1372.  
  1373.     if (buf[1] != ' ')
  1374.         goto badnum;
  1375.  
  1376.     num = sscanf(buf, "%s %s %s %s %s %s %o\n",
  1377.         cmnd, srcnam, dstnam, who, flags, temp, &mode, notify
  1378.     );
  1379.  
  1380.     switch (cmnd[0]) {
  1381.     case 'S':
  1382.         if (num < 7 || num > 8)
  1383.         goto badnum;
  1384.         fail = local_send_file(buf, &delmeflag);
  1385.         if (delmeflag) {
  1386.         if (di == sizeof(delList)/sizeof(delList[0])) {
  1387.             ulog(-1, "Too many source files in Cmd file! %s", sname);
  1388.         } else {
  1389.             delList[di] = malloc(strlen(temp) + 1);
  1390.             strcpy(delList[di], temp);
  1391.             ++di;
  1392.         }
  1393.         }
  1394.         break;
  1395.     case 'R':
  1396.         if (num != 5) {
  1397.         if (debug > 7)
  1398.             printf("Invalid scanf %d/5 :%s:%s:%s\n", num, cmnd, srcnam, dstnam);
  1399.         goto badnum;
  1400.         }
  1401.         fail = local_receive_file();
  1402.         break;
  1403.     default:
  1404.     badnum:
  1405.         ulog(-1, "Illegal Work Request (%s): %s", sname, buf);
  1406.         fail = REFUSED;
  1407.         break;
  1408.     }
  1409.  
  1410.     switch(fail) {
  1411.     case SUCCESS:
  1412.         break;
  1413.     case FAIL:
  1414.         ++failaccum;
  1415.         if (failAction == SUCCESS)
  1416.         failAction = FAIL;
  1417.         ulog(-1, "Protocol Failure at (%s): %s", sname, buf);
  1418.         NoReScan = 1;
  1419.         break;
  1420.     case REFUSED:
  1421.         ++failaccum;
  1422.         failAction = REFUSED;
  1423.         ulog(-1, "Work Refused (%s): %s", sname, buf);
  1424.         break;
  1425.     }
  1426.     }
  1427.     fclose(fd);
  1428.  
  1429.     switch(failAction) {
  1430.     case SUCCESS:
  1431.     while (di) {
  1432.         --di;
  1433.         remove(delList[di]);
  1434.         free(delList[di]);
  1435.     }
  1436.     fail = remove(sname);
  1437.     UnLockFile(sname);
  1438.     if (fail != 0) {
  1439.         ulog(-1, "Unable to remove work file %s", sname);
  1440.         DEBUG(0, "Can't remove, errno %d\n", errno);
  1441.     } else {
  1442.         DEBUG(4, "Removed work file %s\n", sname);
  1443.     }
  1444.     break;
  1445.     case FAIL:
  1446.     UnLockFile(sname);
  1447.     break;
  1448.     case REFUSED:
  1449.     UnLockFile(sname);
  1450.     strcpy(buf, sname);
  1451.     {
  1452.         short i;
  1453.         for (i = strlen(buf); i >= 0 && buf[i] != ':' && buf[i] != '/'; --i);
  1454.         ++i;
  1455.         if ((buf[i]|0x20) == 'c')
  1456.         buf[i] = 'E';
  1457.     }
  1458.     if (strcmp(sname, buf) == 0) {
  1459.         ulog(-1, "Removing %s", sname);
  1460.         remove(sname);
  1461.     } else {
  1462.         ulog(-1, "Renaming %s to %s", sname, buf);
  1463.         rename(sname, buf);
  1464.     }
  1465.     break;
  1466.     }
  1467.     if (failAction == FAIL)
  1468.     return(FAIL);
  1469.     return(SUCCESS);
  1470. }
  1471.  
  1472. /*
  1473.  *  Send a yes/no packet
  1474.  */
  1475.  
  1476. int
  1477. yesno(c, true, err)
  1478. char c;
  1479. int true;
  1480. int err;
  1481. {
  1482.     char buf[21];
  1483.  
  1484.     buf[0] = c;
  1485.     buf[1] = true? 'Y': 'N';
  1486.     buf[2] = 0;
  1487.     if (err && !true)
  1488.     sprintf(buf+2,"%d", err);
  1489.  
  1490.     return (wrmsg(buf));
  1491. }
  1492.  
  1493. /*
  1494.  *  SLAVE MODE, Master wishes to send a file to us
  1495.  *
  1496.  *  SECURITY:    If file is not in list of allowed directories
  1497.  *        disallow transfer.  UUSPOOL:   is always in the
  1498.  *        list.
  1499.  *
  1500.  *        If file is for UUSPOOL: (the current dir), disallow "C." files
  1501.  *        NOTE: success return and file redirected to T: as this can
  1502.  *        occur only if somebody purposefully is trying to break us.
  1503.  *
  1504.  *        NOTE: for received files to UUSPOOL: (no path element),
  1505.  *        case insensitivity munging will occur.    UUXQT will handle
  1506.  *        name translations for X. files so we do not modify their
  1507.  *        contents.
  1508.  *
  1509.  *  Return 0 = success
  1510.  */
  1511.  
  1512. int
  1513. host_send_file(msg)
  1514. char  *msg;
  1515. {
  1516.     FILE *fddsk;            /* Disk file pointer */
  1517.     static char cmnd[256];        /* Command character */
  1518.     int r;
  1519.     int nor = 0;
  1520.  
  1521.     sscanf(msg,"%s %s %s %s %s %s %o",
  1522.         cmnd, srcnam, dstnam, who, flags, temp, &mode);
  1523.  
  1524.     ulog(-1, "REQUESTED %s", msg);
  1525.     munge_filename(dstnam, dstnam);           /* Translate to local name    */
  1526.     mungecase_filename(dstnam, dstnam);      /* Handle case insensitivity  */
  1527.     strcpy (temp, TmpFileName(dstnam));       /* Create a handy temp file   */
  1528.  
  1529.     if (SecurityDisallow(dstnam, 'w')) {
  1530.     ulog(-1, "REQUEST FAILED -- SECURITY");
  1531.     return(yesno('S', 0, 4));
  1532.     }
  1533.     if (SecurityDisallow(dstnam, 'c') > 0) {
  1534.     ulog(-1, "REQUEST FAILED -- SECURITY, REMOTE TRIED TO SEND");
  1535.     ulog(-1, "US A COMMAND FILE: %s, FILE COPIED TO T:Bad-Cmd", dstnam);
  1536.     strcpy(dstnam, "T:Bad-Cmd");
  1537.     nor = 1;
  1538.     }
  1539.  
  1540.     /* FIXME: deal with file modes now that we fopen. */
  1541.  
  1542.     LockFile(temp);
  1543.  
  1544.     fddsk = fopen(temp, "wb" /*, mode|0600 */);
  1545.     if (fddsk == NULL) {
  1546.     UnLockFile(temp);
  1547.     /* Can't open file -- send error response */
  1548.     if (debug > 0) {
  1549.         printf("Cannot open temp file %s (%s) for writing, errno=%d\n",
  1550.         temp,
  1551.         dstnam,
  1552.         errno
  1553.         );
  1554.     }
  1555.     ulog(-1, "REQUEST FAILED -- TEMP FILE");
  1556.     return (yesno('S', 0, 4));
  1557.     }
  1558.  
  1559.     /* FIXME: Are the above permissions right?? */
  1560.     /* FIXME: Should we create directories for the file? */
  1561.  
  1562.     if (yesno('S',1, 0) != SUCCESS) {
  1563.     fclose(fddsk);
  1564.     unlink(temp);
  1565.     UnLockFile(temp);
  1566.     return(FAIL);
  1567.     }
  1568.     r = receive_file(fddsk, temp, dstnam, srcnam, nor);
  1569.     UnLockFile(temp);
  1570.  
  1571.     /*
  1572.      * sd
  1573.      * Notify username of incoming file, cept if D. or X. or C. ctrl files.
  1574.      * Notify of any incoming failure (if NOTIFY_INCOMING_FAILURE bit set)
  1575.      */
  1576.     {
  1577.         char from[80];
  1578.         char *GetUserName();
  1579.  
  1580.         sprintf(from,"%s!%s",host_name,who);
  1581.         if (r == SUCCESS && ((copynotify & NOTIFY_INCOMING) 
  1582.                     && !CTRLFILE(dstnam))) {
  1583.             sprintf(mailsub,"NEW FILE: %s",dstnam);
  1584.             mail_notify(from,who,mailsub);
  1585.         }
  1586.         else if (r != SUCCESS && (copynotify & NOTIFY_INCOMING_FAILURE)) {
  1587.             sprintf(mailsub,"INCOMING FAILURE: %s",dstnam);
  1588.             mail_notify(from,who,mailsub);
  1589.         }            
  1590.     }                 
  1591.  
  1592.     return(r);
  1593. }
  1594.  
  1595. /*
  1596.  *  SLAVE MODE, Master wants us to send a file to it
  1597.  *
  1598.  *  SECURITY:    If file is not in list of allowed directories
  1599.  *        disallow transfer.  UUSPOOL:   is always in the
  1600.  *        list.
  1601.  *
  1602.  *  0 = success
  1603.  */
  1604.  
  1605. int
  1606. host_receive_file(msg)
  1607. char  *msg;
  1608. {
  1609.     FILE *fddsk;     /* Disk file descriptor */
  1610.     int x;
  1611.     static char cmnd[256];          /* Command character */
  1612.  
  1613.     ulog(-1, "REQUESTED %s", msg);
  1614.  
  1615.     sscanf(msg,"%s %s %s",cmnd,srcnam,dstnam);
  1616.     munge_filename(srcnam, temp);
  1617.  
  1618.     if (SecurityDisallow(temp, 'r')) {
  1619.     ulog(-1, "COPY FAILED -- SECURITY");
  1620.     return (yesno('R', 0, 4));
  1621.     }
  1622.  
  1623.     fddsk = fopen(temp, "rb");              /* Try to open the file */
  1624.     if (fddsk == NULL) {
  1625.     /* File didn't open, sigh. */
  1626.     if (debug > 0) {
  1627.         printf("Cannot open file %s (%s) for reading, errno=%d\n",
  1628.         temp, srcnam, errno
  1629.         );
  1630.     }
  1631.     ulog(-1, "DENIED CAN'T OPEN %s", temp);
  1632.     return(yesno('R', 0, 2));
  1633.     }
  1634.  
  1635.     if (yesno('R',1, 0) != SUCCESS) {
  1636.     fclose(fddsk);
  1637.     return(FAIL);
  1638.     }
  1639.  
  1640.     x = send_file(fddsk);
  1641.  
  1642.     /*
  1643.      *    if copy failed, don't care since master asked for the file and knows
  1644.      *    the result if it failed.
  1645.      */
  1646.  
  1647.     if (x == COPYFAIL)
  1648.     return(SUCCESS);
  1649.     return(x);
  1650. }
  1651.  
  1652. /*
  1653.  *  MASTER MODE, We want to send a file.
  1654.  *
  1655.  *  Return FAIL, SUCCESS, or COPYFAIL.
  1656.  *
  1657.  *  SUCCESS is returned either if the file was not found locally (local
  1658.  *  error, and the queued transfer should be flushed) or if it was moved
  1659.  *  successfully.  COPYFAIL indicates that the queued transfer should be
  1660.  *  left queued, and later retried.  FIXME, there are several failure points
  1661.  *  in the transaction and we need finer control here.
  1662.  */
  1663.  
  1664. int
  1665. local_send_file(workstr, delmeflag)
  1666. char *workstr;
  1667. int *delmeflag;
  1668. {
  1669.     static char buf[MAXMSGLEN];    /* Used for both xmit and receive */
  1670.     FILE *fddsk;        /* Disk file descriptor */
  1671.     int res;            /* Result and file removal status */
  1672.  
  1673.     *delmeflag = 0;
  1674.  
  1675.     /* WHY are temp and srcnam switched?  FIXME!  And no notify? */
  1676.  
  1677.     sprintf(buf,"S %s %s %s %s %s 0%o %s",
  1678.     temp, dstnam, who, flags, srcnam, mode, who
  1679.     );
  1680.  
  1681.     ulog(-1, "REQUEST %s", buf);
  1682.  
  1683.     if (strchr(flags, 'c')) {
  1684.     munge_filename(srcnam, temp);
  1685.     } else {
  1686.     munge_filename(temp, temp);
  1687.     }
  1688.     LockFile(temp);
  1689.     fddsk = fopen(temp, "rb");
  1690.     if (fddsk == NULL) {
  1691.     UnLockFile(temp);
  1692.     /* FIXME -- handle queued request for nonexistent file */
  1693.     if (debug > 0)
  1694.         printf("Can't open file %s (%s), errno=%d\n",
  1695.         temp,
  1696.         srcnam,
  1697.         errno
  1698.         );
  1699.     ulog(-1, "NOT FOUND %s", temp);
  1700.         /*
  1701.          * sd: Notify of failure, file to send could not be found
  1702.          */
  1703.         sprintf(mailsub,"FAILED: Can't open %s",srcnam);
  1704.  
  1705.         if (copynotify & NOTIFY_FAILED)
  1706.             mail_notify("uucico","uucico",mailsub);
  1707.  
  1708.     /* return COPYFAIL;*/
  1709.     return SUCCESS;     /*    assume file previously sent */
  1710.     }
  1711.  
  1712.     /* Tell the other side we want to send this file */
  1713.  
  1714.     if (wrmsg(buf) != SUCCESS) {
  1715.     fclose(fddsk);
  1716.     UnLockFile(temp);
  1717.     return (FAIL);
  1718.     }
  1719.  
  1720.     /* See what they have to say about it */
  1721.  
  1722.     if (rdmsg(buf, MAXMSGLEN) != SUCCESS) {
  1723.     fclose(fddsk);
  1724.     UnLockFile(temp);
  1725.     return FAIL;
  1726.     }
  1727.     if ((buf[0] != 'S') || (buf[1] != 'Y')) {
  1728.     ulog(-1, "REQUEST DENIED %s", buf);
  1729.     fclose(fddsk);
  1730.     UnLockFile(temp);
  1731.         /*
  1732.          * sd - send mail indicating request was denied
  1733.          */
  1734.         sprintf(mailsub,"REFUSED by %s: %s",host_name,dstnam);
  1735.         if (copynotify & NOTIFY_FAILED)
  1736.             mail_notify("uucico","uucico",mailsub);
  1737.  
  1738.     return(REFUSED);
  1739.     }
  1740.     res = send_file(fddsk); /* FAIL, SUCCESS, or COPYFAIL */
  1741.  
  1742.     /*
  1743.      * sd - since our caller does not seem to pay any attention to
  1744.      * COPYFAIL, it defaults to success?? It also reties on FAIL.
  1745.      * Without this patch, sending files can be lost and assume sent ok
  1746.      * even though may of failed due to protocol errors.
  1747.      */
  1748.     if (res == COPYFAIL) 
  1749.         res = FAIL;
  1750.  
  1751.  
  1752.     /*
  1753.      * sd - send mail indicating copy failed.
  1754.      */
  1755.     if (res != SUCCESS) {
  1756.         sprintf(mailsub,"COPY FAILED: (will retry) to %s!%s from %s",
  1757.             host_name,dstnam,srcnam);
  1758.         if (copynotify & NOTIFY_RETRY)
  1759.             mail_notify("uucico","uucico",mailsub);
  1760.     }
  1761.     else if (!CTRLFILE(srcnam)) {
  1762.         sprintf(mailsub,"COPY DONE: %s!%s from %s",
  1763.             host_name,dstnam,srcnam);
  1764.         if (copynotify & NOTIFY_SUCCESS)
  1765.             mail_notify("uucico","uucico",mailsub);
  1766.     }
  1767.  
  1768.  
  1769.     /* Delete the source file if it was just a copy */
  1770.  
  1771.     if (res != SUCCESS) {
  1772.     UnLockFile(temp);
  1773.     return res;
  1774.     }
  1775.     if (strchr(flags, 'c')) {   /* If copied direct from source */
  1776.     UnLockFile(temp);
  1777.     return res;        /* ...just return. */
  1778.     }
  1779.     *delmeflag = 1;
  1780.     UnLockFile(temp);
  1781.  
  1782.     return (res);
  1783. }
  1784.  
  1785. /*
  1786.  *  MASTER MODE, We wish to receive a specific file so we ask for it
  1787.  *
  1788.  *  Return 0 = success
  1789.  */
  1790.  
  1791. int
  1792. local_receive_file()
  1793. {
  1794.     static char buf[MAXMSGLEN];
  1795.     FILE *fddsk;            /* Disk file pointer */
  1796.     int r;
  1797.  
  1798.     /* FIXME, test dest file access before we ask for it. */
  1799.  
  1800.     sprintf(buf,"R %s %s %s %s %s 0%o %s",
  1801.     srcnam, dstnam, who, flags, temp, mode, who
  1802.     );
  1803.  
  1804.     munge_filename(dstnam, dstnam);           /* tlate to local name      */
  1805.     strcpy (temp, TmpFileName(dstnam));       /* Create a handy temp file */
  1806.  
  1807.     /* FIXME: deal with file modes now that we fopen. */
  1808.     /* FIXME: Are the above permissions right?? */
  1809.     /* FIXME: Should we create directories for the file? */
  1810.  
  1811.     LockFile(temp);
  1812.     fddsk = fopen(temp, "wb" /*, mode|060 */);
  1813.  
  1814.     if (fddsk == NULL) {
  1815.     UnLockFile(temp);
  1816.     /* Can't open temp file -- send error response */
  1817.     if (debug > 0) {
  1818.         printf("Cannot open temp file %s (%s) for writing, errno=%d\n",
  1819.         temp,
  1820.         dstnam,
  1821.         errno
  1822.         );
  1823.     }
  1824.     ulog(-1, "REQUEST FAILED -- TEMPFILE %s", temp);
  1825.     return FAIL;
  1826.     }
  1827.  
  1828.     ulog(-1, "REQUEST %s", buf);
  1829.     if (wrmsg(buf) != SUCCESS) {
  1830.     fclose(fddsk);
  1831.     UnLockFile(temp);
  1832.     printf("uucico: problem sending request\n");
  1833.     return (FAIL);
  1834.     }
  1835.  
  1836.     /* See what the other side has to say about it */
  1837.  
  1838.     if (rdmsg(buf, MAXMSGLEN) != SUCCESS) {
  1839.     fclose(fddsk);
  1840.     UnLockFile(temp);
  1841.     return (FAIL);
  1842.     }
  1843.     if ((buf[0] != 'R') || (buf[1] != 'Y')) {
  1844.     ulog(-1, "REQUEST DENIED %s", buf);
  1845.     fclose(fddsk);
  1846.     UnLockFile(temp);
  1847.         /*
  1848.          * sd - send mail indicating request was denied
  1849.          */
  1850.         sprintf(mailsub,"REFUSED by %s: %s",host_name,srcnam);
  1851.         if (copynotify & NOTIFY_FAILED)
  1852.             mail_notify("uucico","uucico",mailsub);
  1853.     return (REFUSED);
  1854.     }
  1855.  
  1856.     r = receive_file(fddsk, temp, dstnam, srcnam, 0);
  1857.     UnLockFile(temp);
  1858.     /*
  1859.      * sd - send mail indicating copy failed.
  1860.      */
  1861.     if (r != SUCCESS) {
  1862.         sprintf(mailsub,"COPY FAILED: (will retry) %s!%s",host_name,srcnam);
  1863.         if (copynotify & NOTIFY_RETRY)
  1864.             mail_notify("uucico","uucico",mailsub);
  1865.     }
  1866.     else {
  1867.         sprintf(mailsub,"COPY DONE: %s!%s to %s",host_name,srcnam,dstnam);
  1868.         if (copynotify & NOTIFY_SUCCESS)
  1869.             mail_notify("uucico","uucico",mailsub);
  1870.     }    
  1871.     return(r);
  1872. }
  1873.  
  1874. /*
  1875.  *  General receive file
  1876.  */
  1877.  
  1878. int
  1879. receive_file(fddsk, temp, dstnam, srcnam, norename)
  1880. FILE *fddsk;
  1881. char    *temp, *dstnam, *srcnam;
  1882. {
  1883.     int status;
  1884.     int error = 0;            /* No errors so far */
  1885.     extern long Tot_Retries;
  1886.     extern long Tot_Packets;
  1887.     static char *fbuf = NULL;
  1888.     
  1889.     Tot_Packets = Tot_Retries = 0;
  1890.  
  1891.     if (fbuf == NULL) fbuf = malloc(8192); /* just call malloc once, and reuse*/
  1892.     
  1893.     if (fbuf) setvbuf(fddsk,fbuf,_IOFBF,8192);
  1894.     
  1895.     if (rddata(fddsk) != SUCCESS)
  1896.     error++;
  1897.     
  1898.     xfer.files_recv++;
  1899.     xfer.fbytes_recv += ftell(fddsk);
  1900.  
  1901.     if (Tot_Retries) {
  1902.         ulog(-1,"Retransmitted/Total Packets: %d/%d",Tot_Retries,Tot_Packets);
  1903.     }
  1904.  
  1905.     status = fclose(fddsk);         /* Make sure the data got here */
  1906.  
  1907.     if (status != 0) {
  1908.     error++;
  1909.     DEBUG(0, "fclose errno=%d\n", errno);
  1910.     }
  1911.  
  1912.     /*
  1913.      *    Move the file from its temp location to its real location,
  1914.      *    This needs to be able to copy a file if a simple rename
  1915.      *    does not suffice.  Should create directories if necesary.
  1916.      *    should use source ]name if target is a directory (i.e. no
  1917.      *    target source name
  1918.      */
  1919.  
  1920.     unlink(dstnam);
  1921.  
  1922.     if (norename) {     /*  for security redirect   */
  1923.     status = 0;
  1924.     } else {
  1925.     status = rename(temp, dstnam);
  1926.     if (status < 0) {
  1927.         ulog(-1, "RENAME TO %s FAILED, DELETING FILE AND TRYING AGAIN", dstnam);
  1928.         remove(dstnam);
  1929.         status = rename(temp, dstnam);
  1930.     }
  1931.     }
  1932.  
  1933.     if (status != 0) {
  1934.     error++;
  1935.     if (debug > 0) {
  1936.         printf("Cannot rename file %s to %s, errno=%d\n",
  1937.         temp, dstnam, errno);
  1938.     }
  1939.     }
  1940.  
  1941.     ulog(-1, "COPY %s", error ? "FAILED": "SUCCEEDED");
  1942.  
  1943.     return(yesno('C', error == 0, 5));
  1944. }
  1945.  
  1946. /*
  1947.  * general file send routine
  1948.  * Return SUCCESS, FAIL, or COPYFAIL.
  1949.  */
  1950.  
  1951. int
  1952. send_file(fddsk)
  1953. FILE *fddsk;     /* Disk file pointer */
  1954. {
  1955.     static char ansbuf[MAXMSGLEN];
  1956.     int s;
  1957.     extern long Tot_Packets; 
  1958.     extern long Tot_Retries; 
  1959.     
  1960.     Tot_Packets = Tot_Retries = 0;
  1961.  
  1962.     s = wrdata(fddsk);
  1963.  
  1964.     xfer.files_send++;
  1965.     xfer.fbytes_send += ftell(fddsk);
  1966.  
  1967.     if (Tot_Retries) {
  1968.         ulog(-1,"Retransmitted/Total Packets: %d/%d",Tot_Retries,Tot_Packets);
  1969.     }
  1970.     if (s != SUCCESS) {
  1971.     fclose(fddsk);
  1972.     return COPYFAIL;
  1973.     }
  1974.     fclose(fddsk);
  1975.  
  1976.     /* Await the "CY" or "CNddd" packet, and toss it. */
  1977.  
  1978.     for (;;) {
  1979.     if (rdmsg(ansbuf, MAXMSGLEN) != SUCCESS)
  1980.         return (FAIL);
  1981.     if (ansbuf[0] != 'C') {
  1982.         DEBUG(0,"\nDidn't get 'CY' or 'CN', got %s\n", ansbuf);
  1983.         /* and loop looking for C message */
  1984.     } else if (ansbuf[1] == 'Y') {
  1985.         ulog(-1, "REQUESTED %s", ansbuf);
  1986.         return (SUCCESS);
  1987.     } else {
  1988.         ulog(-1, "COPY FAILED %s", ansbuf);
  1989.         return (COPYFAIL);
  1990.     }
  1991.     }
  1992.     return (COPYFAIL);  /*  NOTREACHED  */
  1993. }
  1994.  
  1995.  
  1996. mail_notify(from,real,subject)
  1997. char *from;
  1998. char *real;
  1999. char *subject;
  2000. {
  2001.     char mailcmd[NAMESIZE+100];
  2002.     char *to = "postmaster";
  2003.     /*
  2004.      * should really inquire on SENDMAIL variable in config file
  2005.      */
  2006.     char *sendmail = "sendmail";
  2007.  
  2008.     if (strlen(subject) > 200) subject[200] = '\0';  /* cli input limits */
  2009.  
  2010.     sprintf(mailcmd, "run %s <nil: >nil: -f %s -R \"%s\" -t %s -s \"%s\" -raw",
  2011.         sendmail,from,real,to,subject);
  2012.         
  2013.     Execute(mailcmd,NULL,NULL);
  2014. }
  2015.