home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckuusy.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  134KB  |  4,725 lines

  1. #include "ckcsym.h"
  2. #define XFATAL fatal
  3.  
  4. /*  C K U U S Y --  "User Interface" for Unix Kermit, part Y  */
  5.  
  6. /*  Command-Line Argument Parser */
  7.  
  8. /*
  9.   Authors:
  10.     Frank da Cruz <fdc@columbia.edu>,
  11.       The Kermit Project, Columbia University, New York City
  12.     Jeffrey E Altman <jaltman@secure-endpoints.com>
  13.       Secure Endpoints Inc., New York City
  14.  
  15.   Copyright (C) 1985, 2005,
  16.     Trustees of Columbia University in the City of New York.
  17.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  18.     copyright text in the ckcmai.c module for disclaimer and permissions.
  19. */
  20. #include "ckcdeb.h"
  21.  
  22. char * bannerfile = NULL;
  23. char * helpfile = NULL;
  24. extern int xferlog, filepeek, nolinks;
  25. extern char * xferfile;
  26. extern int debtim;
  27.  
  28. #include "ckcasc.h"
  29. #include "ckcker.h"
  30. #include "ckucmd.h"
  31. #include "ckcnet.h"
  32. #include "ckuusr.h"
  33. #include "ckcxla.h"
  34. #ifdef CK_SSL
  35. #include "ck_ssl.h"
  36. #endif /* CK_SSL */
  37. #include <signal.h>
  38.  
  39. #ifdef OS2
  40. #include <io.h>
  41. #ifdef KUI
  42. #include "ikui.h"
  43. extern struct _kui_init kui_init;
  44. #endif /* KUI */
  45. #endif /* OS2 */
  46.  
  47. extern int inserver, fncnv, f_save, xfermode;
  48. #ifdef PATTERNS
  49. extern int patterns;
  50. #endif /* PATTERNS */
  51.  
  52. #ifndef NOICP
  53. extern int cmdint;
  54. #endif /* NOICP */
  55. extern int xsuspend;
  56.  
  57. #ifdef NETCONN
  58. #ifdef ANYX25
  59. extern int revcall, closgr, cudata;
  60. extern char udata[];
  61. extern int x25fd;
  62. #endif /* ANYX25 */
  63. #ifndef VMS
  64. #ifndef OS2
  65. #ifndef OSK
  66. extern
  67. #endif /* OSK */
  68. #endif /* OS2 */
  69. #endif /* VMS */
  70.  
  71. int telnetfd;
  72. extern struct keytab netcmd[];
  73. extern int tn_exit;
  74. #ifndef NOICP
  75. #ifndef NODIAL
  76. extern int nnets, nnetdir;              /* Network services directory */
  77. extern char *netdir[];
  78. extern char *nh_p[];                    /* Network directory entry pointers */
  79. extern char *nh_p2[];                   /* Network directory entry nettype */
  80. extern char *nh_px[4][MAXDNUMS + 1];
  81. #endif /* NODIAL */
  82. extern int nhcount;
  83. extern char * n_name;                   /* Network name pointer */
  84. #endif /* NOICP */
  85. #endif /* NETCONN */
  86.  
  87. #ifndef NOSPL
  88. extern int nmac;
  89. extern struct mtab *mactab;
  90. #endif /* NOSPL */
  91. extern char uidbuf[];
  92.  
  93. #ifdef CK_LOGIN
  94. extern int logintimo;
  95. #endif /* CK_LOGIN */
  96.  
  97. extern char * myname, * dftty;
  98. extern int howcalled;
  99.  
  100. extern char *ckxsys, *ckzsys, **xargv, *xarg0, **cmlist, *clcmds;
  101.  
  102. extern int action, cflg, xargc, cnflg, local, quiet, escape, network, mdmtyp,
  103.   bgset, backgrd, xargs, binary, parity, turn, turnch, duplex, flow, clfils,
  104.   noinit, stayflg, nettype, cfilef, noherald, cmask, cmdmsk, exitonclose,
  105.   haveline, justone, cxtype, xfinish, ttnproto;
  106.  
  107. extern long speed;
  108. extern char ttname[];
  109. extern char * pipedata, * cmdfil;
  110.  
  111. #ifndef NOXFER
  112. extern char *cmarg, *cmarg2;
  113.  
  114. extern int nfils, stdouf, stdinf, displa, maxrps, rpsiz, ckwarn, urpsiz,
  115.   wslotr, swcapr, ckdelay, recursive, reliable, xreliable, fnspath, fncact,
  116.   clearrq, setreliable;
  117.  
  118. #ifdef PIPESEND
  119. extern int usepipes, pipesend;
  120. #endif /* PIPESEND */
  121. extern int protocol;
  122. #endif /* NOXFER */
  123.  
  124. #ifndef NOPUSH
  125. extern int nopush;
  126. #endif /* NOPUSH */
  127.  
  128. #ifdef OS2
  129. extern struct keytab os2devtab[];
  130. extern int nos2dev;
  131. extern int ttslip;
  132. extern int tt_scroll, tt_escape;
  133. #ifdef OS2PM
  134. extern int os2pm;
  135. #endif /* OS2PM */
  136. #endif /* OS2 */
  137.  
  138. #ifdef CK_NETBIOS
  139. extern unsigned char NetBiosAdapter;
  140. #endif /* CK_NETBIOS */
  141.  
  142. #ifdef XFATAL
  143. #undef XFATAL
  144. #endif /* XFATAL */
  145.  
  146. #ifdef TNCODE
  147. _PROTOTYP(static int dotnarg, (char x) );
  148. #endif /* TNCODE */
  149. #ifdef RLOGCODE
  150. _PROTOTYP(static int dorlgarg, (char x) );
  151. #endif /* RLOGCODE */
  152. #ifdef SSHBUILTIN
  153. _PROTOTYP(static int dossharg, (char x) );
  154. #endif /* SSHBUILTIN */
  155.  
  156. int haveftpuid = 0;            /* Have FTP user ID */
  157. static int have_cx = 0;            /* Have connection */
  158.  
  159. #ifdef NEWFTP
  160. extern char * ftp_host;
  161. #endif /* NEWFTP */
  162.  
  163. extern int what;
  164.  
  165. #ifndef NOICP
  166. #ifndef NODIAL
  167. extern int nmdm, telephony;
  168. extern struct keytab mdmtab[];
  169. extern int usermdm, dialudt;
  170. #endif /* NODIAL */
  171. _PROTOTYP(static int pmsg, (char *) );
  172. _PROTOTYP(static int fmsg, (char *) );
  173. static int pmsg(s) char *s; { printf("%s\n", s); return(0); }
  174. static int fmsg(s) char *s; { fatal(s); return(0); }
  175. #define XFATAL(s) return(what==W_COMMAND?pmsg(s):fmsg(s))
  176. #else
  177. #define XFATAL fatal
  178. #endif /* NOICP */
  179.  
  180. #ifndef NOHTTP
  181. #define HTTP_GET 1
  182. #define HTTP_PUT 2
  183. #define HTTP_HED 3
  184. #endif /* NOHTTP */
  185.  
  186. #ifdef CK_URL
  187. /* URLs we recognize */
  188.  
  189. #define URL_FTP    1
  190. #define URL_HTTP   2
  191. #define URL_HTTPS  3
  192. #define URL_IKSD   4
  193. #define URL_TELNET 5
  194. #define URL_LOGIN  6
  195.  
  196. struct keytab urltab[] = {
  197. #ifdef NEWFTP
  198.     "ftp",    URL_FTP,    0,
  199. #endif /* NEWFTP */
  200. #ifndef NOHTTP
  201.     "http",   URL_HTTP,   0,
  202.     "https",  URL_HTTPS,  0,
  203. #endif /* NOHTTP */
  204.     "iksd",   URL_IKSD,   0,
  205.     "kermit", URL_IKSD,   0,
  206.     "telnet", URL_TELNET, 0,
  207.     "", 0, 0
  208. };
  209. int nurltab = sizeof(urltab)/sizeof(struct keytab) - 1;
  210.  
  211. #ifndef URLBUFLEN
  212. #define URLBUFLEN 1024
  213. #endif /* URLBUFLEN */
  214. static char urlbuf[URLBUFLEN];
  215. struct urldata g_url = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  216.  
  217. /* u r l p a r s e  --  Parse a possible URL */
  218.  
  219. /*
  220.   Returns 0 if the candidate does not seem to be a URL.
  221.   Returns 1 if it might be a URL, with the above pointers set to its pieces:
  222.     service : [ // ] [ user [ : password ] @ ] host [ : service ] [ / path ] -
  223.               [ ? name [ = value ]]
  224.  
  225.   Example: ftp://ds.internic.net:21/rfc/rfc1234.txt
  226.     url.svc = [ftp]
  227.     url.usr = [(NULL)]
  228.     url.psw = [(NULL)]
  229.     url.hos = [ds.internic.net]
  230.     url.por = [21]
  231.     url.pth = [rfc/rfc1234.txt]
  232.  
  233.   It might be a URL if it contains a possible service name followed by a
  234.   a colon (:).  Thus "telnet:xyzcorp.com" is a minimal URL, whereas a
  235.   full-blown example would be:
  236.  
  237.     ftp://olga:secret@ftp.xyzcorp.com/public/oofa.txt
  238.  
  239.   The caller must verify the results, i.e. that the service string is a real
  240.   TCP service, etc.  This routine just parses the fields.
  241.  
  242.   struct urldata defined in ckcker.h
  243. */
  244.  
  245. int
  246. urlparse(s,url) char *s; struct urldata * url; {
  247.     char * p = NULL, * urlbuf = NULL;
  248.     int x;
  249.  
  250.     if (!s || !url)
  251.         return(0);
  252.  
  253.     if (!*s)
  254.         return(0);
  255.  
  256.     makestr(&urlbuf,s);
  257.  
  258.     if (url->sav) {            /* In case we were called before... */
  259.         free(url->sav);
  260.         url->sav = NULL;
  261.     }
  262.     if (url->svc) {
  263.         free(url->svc);
  264.         url->svc = NULL;
  265.     }
  266.     if (url->hos) {
  267.         free(url->hos);
  268.         url->hos = NULL;
  269.     }
  270.     if (url->por) {
  271.         free(url->por);
  272.         url->por = NULL;
  273.     }
  274.     if (url->usr) {
  275.         free(url->usr);
  276.         url->usr = NULL;
  277.     }
  278.     if (url->psw) {
  279.         free(url->psw);
  280.         url->psw = NULL;
  281.     }
  282.     if (url->pth) {
  283.         free(url->pth);
  284.         url->pth = NULL;
  285.     }
  286.     if (url->nopts) {
  287.         int i;
  288.         for ( i=0; i<url->nopts && i<MAX_URL_OPTS; i++ ) {
  289.             if (url->opt[i].nam) {
  290.                 free(url->opt[i].nam);
  291.                 url->opt[i].nam = NULL;
  292.             }
  293.             if (url->opt[i].val) {
  294.                 free(url->opt[i].val);
  295.                 url->opt[i].val = NULL;
  296.             }
  297.         }
  298.         url->nopts = 0;
  299.     }
  300.  
  301.     p = urlbuf;                /* Was a service requested? */
  302.     while (*p && *p != ':')        /* Look for colon */
  303.       p++;
  304.     if (*p == ':') {                    /* Have a colon */
  305.         *p++ = NUL;            /* Get service name or number */
  306.         if (*p == ':')            /* a second colon */
  307.           *p++ = NUL;            /* get rid of that one too */
  308.         while (*p == '/') *p++ = NUL;    /* and slashes */
  309. #ifdef COMMENT
  310.         /* Trailing slash is part of path - leave it - jaltman */
  311.         x = strlen(p);                  /* Length of remainder */
  312.         if (p[x-1] == '/')              /* If there is a trailing slash */
  313.           p[x-1] = NUL;            /* remove it. */
  314. #endif /* COMMENT */
  315.         if (urlbuf[0]) {        /* Anything left? */
  316.             char *q = p, *r = p, *w = p;
  317.         makestr(&url->svc,urlbuf);
  318.  
  319.             while (*p != NUL && *p != '@') /* look for @ */
  320.           p++;
  321.             if (*p == '@') {        /* Signifies user ID, maybe password */
  322.                 *p++ = NUL;
  323.         url->hos = p;
  324.                 while (*w != NUL && *w != ':')
  325.                   w++;
  326.                 if (*w == ':')
  327.                   *w++ = NUL;
  328.         url->usr = r;        /* Username */
  329.         if (*w)
  330.           url->psw = w;        /* Password */
  331.                 q = p;
  332.             } else {            /* No username or password */
  333.                 p = q;
  334.         url->hos = p;
  335.             }
  336. #ifdef COMMENT
  337.         debug(F111,"urlparse url->usr",url->usr,url->usr);
  338.         debug(F111,"urlparse url->psw",url->usr,url->psw);
  339.         debug(F111,"urlparse url->hos",url->usr,url->hos);
  340. #endif    /* COMMENT */
  341.             while (*p != NUL && *p != ':' && *p != '/')    /* Port? */
  342.               p++;
  343.             if (*p == ':') {        /* TCP port */
  344.                 *p++ = NUL;
  345.                 r = p;
  346.         url->por = r;
  347.                 while (*p != NUL && *p != '/')
  348.           p++;
  349.                 /* '/' is part of path, leave it until we can copy */
  350.                 if (*p == '/') {
  351.             makestr(&url->pth,p);  /* Path */
  352.             *p = NUL;
  353.                 }
  354.             } else {            /* No port */
  355.                 /* '/' is part of path, leave it */
  356.                 if (*p == '/') {
  357.             makestr(&url->pth,p);  /* Path */
  358.             *p = NUL;
  359.                 }
  360.             }
  361.         }
  362.     /* Copy non-NULL result strings */
  363.     if (url->svc) if (*url->svc) {
  364.             p = url->svc;
  365.             url->svc = NULL;
  366.             makestr(&url->svc,p);
  367.         }
  368.     if (url->hos) if (*url->hos) {
  369.             p = url->hos;
  370.             url->hos = NULL;
  371.             makestr(&url->hos,p);
  372.         }
  373.     if (url->por) if (*url->por) {
  374.             p = url->por;
  375.             url->por = NULL;
  376.             makestr(&url->por,p);
  377.         }
  378. /*
  379.   WARNING (Wed Oct  9 16:09:03 2002): We now allow the username and
  380.   password to be empty strings.  These are treated differently from null
  381.   pointers: an empty string means the URL included username and/or password
  382.   fields that were empty, e.g. ftp://:@ftp.xyzcorp.com/somepath/somefile,
  383.   which causes the client to prompt for the username and/or password.
  384. */
  385.     if (url->usr) /* if (*url->usr) */ {
  386.             p = url->usr;
  387.             url->usr = NULL;
  388.             makestr(&url->usr,p);
  389.         }
  390.     if (url->psw) /* if (*url->psw) */ {
  391.             p = url->psw;
  392.             url->psw = NULL;
  393.             makestr(&url->psw,p);
  394.         }
  395.         /* Save a copy of the full url if one was found. */
  396.     if (url->svc) 
  397.       makestr(&url->sav,s);
  398.         free(urlbuf);
  399.     return(url->svc ? 1 : 0);
  400.     }
  401.     return(0);
  402. }
  403. #endif /* CK_URL */
  404.  
  405. #ifndef NOCMDL
  406.  
  407. char *hlp1[] = {
  408. #ifndef NOICP
  409. " [filename] [-x arg [-x arg]...[-yyy]..] [ = text ] ]\n",
  410. #else
  411. "[-x arg [-x arg]...[-yyy]..]\n",
  412. #endif /* NOICP */
  413. "\n",
  414. "  -x is an option requiring an argument, -y an option with no argument.\n",
  415. "  If the first command-line argument is the name of a file, interactive-\n",
  416. "  mode commands are executed from the file.  The '=' argument tells Kermit\n",
  417. "  not to parse the remainder of the command line, but to make the words\n",
  418. "  following '=' available as \\%1, \\%2, ... \\%9.  The command file \
  419. (if any)\n",
  420. "  is executed before the command-line options.\n",
  421. "\n",
  422. #ifndef NOICP
  423. "If no action command is included, or -S is, then after the command line is\n",
  424. "executed, Kermit issues its prompt and waits for you to type commands.\n",
  425. #else
  426. "Operation by command-line options only.\n",
  427. #endif /* NOICP */
  428. ""
  429. };
  430.  
  431. static
  432. char *hlp2[] = {
  433. "  [option-list] host[:port] [port]\n",
  434. "  The option-list consists of zero, one, or more of:\n",
  435. "  -8                Negotiate Telnet Binary in both directions\n",
  436. "  -a                Require use of Telnet authentication\n",
  437. "  -d                Turn on debug mode\n",
  438. "  -E                No escape character\n",
  439. "  -K                Refuse use of authentication; do not send username\n",
  440. "  -l user           Set username and request Telnet authentication\n",
  441. "  -L                Negotiate Telnet Binary Output only\n",
  442. "  -x                Require Encryption\n",
  443. "  -D                Disable forward-X\n",
  444. "  -T cert=file      Use certificate in file\n",
  445. "  -T key=file       Use private key in file\n",
  446. "  -T crlfile=file   Use CRL in file\n",
  447. "  -T crldir=dir     Use CRLs in directory\n",
  448. "  -T cipher=string  Use only ciphers in string\n",
  449. "  -f                Forward credentials to host\n",
  450. "  -k realm          Set default Kerberos realm\n",
  451. ""
  452. };
  453.  
  454. static
  455. char *hlp3[] = {        /* rlogin */
  456. "  [option-list] host[:port] [port]\n",
  457. "  The option-list consists of zero, one, or more of:\n",
  458. "  -d                Turn on debug mode\n",
  459. "  -l user           Set username\n",
  460. ""
  461. };
  462.  
  463. static
  464. char *hlp4[] = {        /* ssh */
  465. "  [option-list] host[:port] [port]\n",
  466. "  The option-list consists of zero, one, or more of:\n",
  467. #ifdef OS2
  468. "  -# flags          Kermit 95 Startup Flags\n",
  469. "       1              turn off Win95 special fixes\n",
  470. "       2              do not load optional network dlls\n",
  471. "       4              do not load optional tapi dlls\n",
  472. "       8              do not load optional kerberos dlls\n",
  473. "      16              do not load optional zmodem dlls\n",
  474. "      32              use stdin for input instead of the console\n",
  475. "      64              use stdout for output instead of the console\n",
  476. "     128              do not terminate process in response to Session Logoff\n",
  477. #endif /* OS2 */
  478. "  -d                Turn on debug mode\n",
  479. "  -Y                Disable init file processing\n",
  480. "  -l user           Set username\n",
  481. ""
  482. };
  483.  
  484. /* Command-line option help lines.  Update this when adding new options! */
  485.  
  486. char * opthlp[128];                     /* Option help */
  487. char * arghlp[128];                     /* Argument for option */
  488. int optact[128];                        /* Action-option flag */
  489.  
  490. VOID
  491. fatal2(msg1,msg2) char *msg1, *msg2; {
  492.     char buf[256];
  493.     if (!msg1) msg1 = "";
  494.     if (!msg2) msg2 = "";
  495.     ckmakmsg(buf,256,"\"",msg1,"\" - ",msg2);
  496. #ifndef NOICP
  497.     if (what == W_COMMAND)
  498.       printf("%s\n",buf);
  499.     else
  500. #endif /* NOICP */
  501.       fatal((char *)buf);
  502. }
  503.  
  504. static SIGTYP
  505. #ifdef CK_ANSI
  506. cl_int(int dummy)
  507. #else /* CK_ANSI */
  508. cl_int(dummy) int dummy;
  509. #endif /* CK_ANSI */
  510. {                    /* Command-line interrupt handler */
  511.     doexit(BAD_EXIT,1);
  512.     SIGRETURN;
  513. }
  514.  
  515. #ifdef NEWFTP
  516. extern int ftp_action, ftp_cmdlin;
  517.  
  518. static int
  519. xx_ftp(host, port) char * host, * port; {
  520. #ifdef CK_URL
  521.     extern int haveurl;
  522. #endif /* CK_URL */
  523.     extern char * ftp_logname;
  524.     int use_tls = 0;
  525.     char * p;
  526.  
  527.     if (port) if (!*port) port = NULL;
  528.  
  529.     if (!host)
  530.       return(0);
  531.     if (!*host)
  532.       return(0);
  533.     debug(F111,"ftp xx_ftp host",ftp_host,haveftpuid);
  534.     debug(F111,"ftp xx_ftp uidbuf 1",uidbuf,haveftpuid);
  535.     ftp_cmdlin = 1;            /* 1 = FTP started from command line */
  536.     if (nfils > 0)
  537.       ftp_cmdlin++;            /* 2 = same plus file transfer */
  538.  
  539. #ifndef NOURL
  540.     /* debug(F111,"ftp xx_ftp g_url.usr",g_url.usr,g_url.usr); */
  541.     if (haveurl && g_url.usr) {        /* Wed Oct  9 15:15:22 2002 */
  542.     if (!*(g_url.usr)) {        /* Force username prompt if */
  543.         haveftpuid = 0;        /* "ftp://:@host" given. */
  544.         uidbuf[0] = NUL;
  545.         makestr(&ftp_logname,NULL);
  546.     }      
  547.     debug(F111,"ftp xx_ftp uidbuf 2",uidbuf,haveftpuid);
  548.     }
  549. #endif /* NOURL */
  550.     debug(F111,"ftp xx_ftp uidbuf 3",uidbuf,haveftpuid);
  551.     if (haveftpuid) {
  552.     makestr(&ftp_logname,uidbuf);
  553.     debug(F111,"ftp_logname",ftp_logname,haveftpuid);
  554.     }
  555.     if (!port) {
  556.     if ((p = ckstrchr(ftp_host,':')))
  557.       *p++ = NUL;
  558.     port = p;
  559.     }
  560.     if (!port) {
  561. #ifdef CK_URL
  562.         if (haveurl) {
  563.         if (g_url.por) 
  564.           port = g_url.por;
  565.             else if (g_url.svc)
  566.           port = g_url.svc;
  567.             else 
  568.           port = "ftp";
  569.         } else
  570. #endif /* CK_URL */
  571.       port = "ftp";
  572.     }
  573.  
  574. #ifdef CK_SSL
  575.     if (haveurl && g_url.svc)
  576.       use_tls = !ckstrcmp("ftps",g_url.svc,-1,0);
  577. #endif /* CK_SSL */
  578.  
  579.     if (ftpopen(ftp_host,port,use_tls) < 1)
  580.       return(-1);
  581.     debug(F111,"ftp xx_ftp action",ckctoa((char)ftp_action),nfils);
  582.     if (nfils > 0) {
  583.     switch (ftp_action) {
  584.       case 'g':
  585.         return(cmdlinget(stayflg));
  586.       case 'p':
  587.       case 's':
  588.         return(cmdlinput(stayflg));
  589.     }
  590.     }
  591.     return(1);
  592. }
  593. #endif /* NEWFTP */
  594.  
  595.  
  596. #ifndef NOHTTP
  597. static
  598. char * http_hlp[] = {
  599.     " -h             This message.\n",
  600.     " -d             Debug to debug.log.\n",
  601.     " -S             Stay (issue command prompt when done).\n",
  602.     " -Y             Do not execute Kermit initialization file.\n",
  603.     " -q             Quiet (suppress most messages).\n",
  604.     " -u name        Username.\n",
  605.     " -P password    Password.\n",
  606.     " -g pathname    Get remote pathname.\n",
  607.     " -p pathname    Put remote pathname.\n",
  608.     " -H pathname    Head remote pathname.\n",
  609.     " -l pathname    Local path for -g, -p, and -H.\n",
  610. #ifdef CK_SSL
  611.     " -z opt[=value] Security options...\n",
  612.     "    cert=file   Client certificate file\n",
  613.     "    certsok     Accept all certificates\n",
  614.     "    key=file    Client private key file\n",
  615.     "    secure      Use SSL\n",
  616.     "    verify=n    0 = none, 1 = peer , 2 = certificate required\n",
  617. #endif /* CK_SSL */
  618.     ""
  619. };
  620.  
  621. #define HT_CERTFI 0
  622. #define HT_OKCERT 1
  623. #define HT_KEY    2
  624. #define HT_SECURE 3
  625. #define HT_VERIFY 4
  626.  
  627. static struct keytab httpztab[] = {
  628.     { "cert",    HT_CERTFI, CM_ARG },
  629.     { "certsok", HT_OKCERT, 0 },
  630.     { "key",     HT_KEY,    CM_ARG },
  631.     { "secure",  HT_SECURE, 0 },
  632.     { "verify",  HT_VERIFY, CM_ARG },
  633.     { "", 0, 0 }
  634. };
  635. static int nhttpztab = sizeof(httpztab) / sizeof(struct keytab) - 1;
  636. #endif /* NOHTTP */
  637.  
  638. /*  U S A G E */
  639.  
  640. VOID
  641. usage() {
  642. #ifdef MINIX
  643.     conol("Usage: ");
  644.     conol(xarg0);
  645.     conol(" [-x arg [-x arg]...[-yyy]..] ]\n");
  646. #else
  647.     conol("Usage: ");
  648.     conol(xarg0);
  649.     if (howcalled == I_AM_KERMIT || howcalled == I_AM_IKSD ||
  650.         howcalled == I_AM_SSHSUB)
  651.       conola(hlp1);
  652.     else if (howcalled == I_AM_TELNET)
  653.       conola(hlp2);
  654.     else if (howcalled == I_AM_RLOGIN)
  655.       conola(hlp3);
  656.     else if (howcalled == I_AM_SSH)
  657.       conola(hlp4);
  658.     if (howcalled == I_AM_KERMIT || howcalled == I_AM_IKSD ||
  659.         howcalled == I_AM_SSHSUB) {
  660.     int c;
  661.     conoll("");
  662.     conoll("Complete listing of command-line options:");
  663.     conoll("");
  664.     for (c = 31; c < 128; c++) {
  665.         if (!opthlp[c])
  666.           continue;
  667.         if (arghlp[c]) {
  668.         printf(" -%c <arg>%s\n",
  669.                (char)c,
  670.                (optact[c] ? " (action option)" : "")
  671.                );
  672.         printf("     %s\n",opthlp[c]);
  673.         printf("     Argument: %s\n\n",arghlp[c]);
  674.         } else {            /* Option without arg */
  675.         printf(" -%c  %s%s\n",
  676.                (char)c, opthlp[c],
  677.                (optact[c]?" (action option)":"")
  678.                );
  679.         printf("     Argument: (none)\n\n");
  680.         }
  681.     }
  682. #ifdef OS2ORUNIX
  683.     printf("To prevent this message from scrolling, use '%s -h | more'.\n",
  684.            xarg0);
  685. #endif /* OS2ORUNIX */
  686.     printf("For a list of extended options use '%s --help'.\n",
  687.            xarg0);
  688.     }
  689. #endif /* MINIX */
  690. }
  691.  
  692.  
  693. /*  C M D L I N  --  Get arguments from command line  */
  694.  
  695. int
  696. cmdlin() {
  697.     char x;                             /* Local general-purpose char */
  698.     extern int haveurl;
  699.  
  700. #ifdef NEWFTP
  701.     char * port = NULL;
  702. #endif /* NEWFTP */
  703.  
  704. #ifndef NOXFER
  705.     cmarg = "";                         /* Initialize globals */
  706.     cmarg2 = "";
  707. #endif /* NOXFER */
  708.     action = 0;
  709.     cflg = 0;
  710.  
  711.     signal(SIGINT,cl_int);
  712.  
  713. /* Here we handle different "Command Line Personalities" */
  714.  
  715. #ifdef TCPSOCKET
  716. #ifndef NOHTTP
  717.     if (howcalled == I_AM_HTTP) {       /* If I was called as HTTP... */
  718.     char rdns[128];
  719. #ifdef OS2
  720.     char * agent = "Kermit 95";
  721. #else   
  722.     char * agent = "C-Kermit";
  723. #endif /* OS2 */
  724.  
  725.         debug(F100,"http personality","",0);
  726. #ifdef CK_URL
  727.         if (haveurl) {
  728.             int type;
  729.             char * lfile;
  730.  
  731.         type = lookup(urltab,g_url.svc,nurltab,NULL);
  732.             if (!(type == URL_HTTP || type == URL_HTTPS)) {
  733.                 printf("?Internal Error: HTTP command line processing\n");
  734.                 debug(F100,"Error: HTTP command line processing","",0);
  735.                 doexit(BAD_EXIT,1);
  736.             }
  737.             rdns[0] = '\0';
  738.             lfile = "";
  739.             x = (http_open(g_url.hos,g_url.por ? g_url.por : g_url.svc, 
  740.                            type == URL_HTTPS, rdns,128,NULL) == 0);
  741.             if (x) {
  742. #ifdef KUI
  743.         char asname[CKMAXPATH+1];
  744. #endif /* KUI */
  745.                 if (!quiet) {
  746.                     if (rdns[0])
  747.               printf("Connected to %s [%s]\r\n",g_url.hos,rdns);
  748.                     else
  749.               printf("Connected to %s\r\n",g_url.hos);
  750.                 }
  751.                 if (g_url.pth)
  752.                   zstrip(g_url.pth,&lfile);
  753.                 else
  754.           g_url.pth = "/";
  755.  
  756.                 if (!*lfile)
  757.                   lfile = "index.html";
  758.  
  759. #ifdef KUI
  760.         if (uq_file(NULL,    /* K95 GUI: Put up file box. */
  761.                 NULL,    /* (not tested...) */
  762.                 4,
  763.                 NULL,
  764.                 lfile,
  765.                 asname,
  766.                 CKMAXPATH+1
  767.                 ) > 0)
  768.           lfile = asname;
  769. #endif /* KUI */
  770.  
  771.                 x = http_get(agent,
  772.                  NULL,    /* hdrlist */
  773.                  g_url.usr,
  774.                  g_url.psw,
  775.                  0,
  776.                  lfile,
  777.                  g_url.pth,
  778.                  0        /* stdio */
  779.                  );
  780.                 x = (http_close() == 0);
  781.             } else {
  782.                 if (!quiet)
  783.           printf("?HTTP Connection failed.\r\n");
  784.             }
  785.             doexit(x ? GOOD_EXIT : BAD_EXIT, -1);
  786.         } else 
  787. #endif /* CK_URL */
  788.       {
  789.           int http_action = 0;
  790.           char * host = NULL, * svc = NULL, * lpath = NULL;
  791.           char * user = NULL, * pswd = NULL, * path = NULL;
  792.           char * xp;
  793.  
  794.           while (--xargc > 0) {    /* Go through command line words */
  795.           xargv++;
  796.           debug(F111,"cmdlin http xargv",*xargv,xargc);
  797.           xp = *xargv+1;
  798.           if (**xargv == '-') { /* Got an option */
  799.               int xx;
  800.               x = *(*xargv+1);    /* Get the option letter */
  801.               switch (x) {
  802.             case 'd':    /* Debug */
  803. #ifdef DEBUG
  804.               if (deblog) {
  805.                   debtim = 1;
  806.               } else {
  807.                   deblog = debopn("debug.log",0);
  808.               }
  809. #endif /* DEBUG */
  810.               break;
  811.             case 'S':    /* Stay */
  812.             case 'Y':    /* No initialization file */
  813.               break;    /* (already done in prescan) */
  814.             case 'q':    /* Quiet */
  815.               quiet = 1;
  816.               break;
  817.             case 'u':    /* Options that require arguments */
  818.             case 'P':
  819.             case 'g':
  820.             case 'p':
  821.             case 'H':
  822.             case 'l':
  823.               if (*(xp+1)) {
  824.                   XFATAL("Invalid argument bundling");
  825.               }
  826.               xargv++, xargc--;
  827.               if ((xargc < 1) || (**xargv == '-')) {
  828.                   XFATAL("Missing argument");
  829.               }
  830.               switch (x) {
  831.                 case 'u':
  832.                   user = *xargv;
  833.                   break;
  834.                 case 'P':
  835.                   pswd = *xargv;
  836.                   break;
  837.                 case 'l':
  838.                   if (http_action != HTTP_PUT)
  839.                 lpath = *xargv;
  840.                   break;
  841.                 case 'g':
  842.                   http_action = HTTP_GET;
  843.                   path = *xargv;
  844.                   debug(F111,"cmdlin http GET",path,http_action);
  845.                   break;
  846.                 case 'p':
  847.                   http_action = HTTP_PUT;
  848.                   path = *xargv;
  849.                   break;
  850.                 case 'H':
  851.                   http_action = HTTP_HED;
  852.                   path = *xargv;
  853.               }
  854.               break;
  855.  
  856. #ifdef CK_SSL
  857.                         case 'z': {
  858.                 /* *xargv contains a value of the form tag=value */
  859.                 /* we need to lookup the tag and save the value  */
  860.                 int x,y,z;
  861.                 char * p, * q;
  862.                 makestr(&p,*xargv);
  863.                 y = ckindex("=",p,0,0,1);
  864.                 if (y > 0)
  865.                               p[y-1] = '\0';
  866.                 x = lookup(httpztab,p,nhttpztab,&z);
  867.                 if (x < 0) {
  868.                 printf("?Invalid security option: \"%s\"\n",p);
  869.                 } else {
  870.                 printf("Security option: \"%s",p);
  871.                 if (httpztab[z].flgs & CM_ARG) {
  872.                     q = &p[y];
  873.                     if (!*q)
  874.                                       fatal("?Missing required value");
  875.                 }
  876.                 /* -z options w/args */
  877.                 switch (httpztab[z].kwval) {
  878.                   case HT_CERTFI:
  879.                     makestr(&ssl_rsa_cert_file,q);
  880.                     break;
  881.                   case HT_OKCERT:
  882.                     ssl_certsok_flag = 1;
  883.                     break;
  884.                   case HT_KEY:
  885.                     makestr(&ssl_rsa_key_file,q);
  886.                     break;
  887.                   case HT_SECURE:
  888.                     svc="https";
  889.                     break;
  890.                   case HT_VERIFY:
  891.                     if (!rdigits(q))
  892.                                       printf("?Bad number: %s\n",q);
  893.                     ssl_verify_flag = atoi(q);
  894.                     break;
  895.                 }
  896.                 }
  897.                 free(p);
  898.                 break;
  899.                         }
  900. #endif /* CK_SSL */
  901.  
  902.             case 'h':    /* Help */
  903.             default:
  904.               printf("Usage: %s host [ options... ]\n",xarg0);
  905.               conola(http_hlp);
  906.               doexit(GOOD_EXIT,-1);
  907.               }
  908.           } else {        /* No dash - must be hostname */
  909.               host = *xargv;
  910.               if (xargc > 1) {
  911.               svc = *(xargv+1);
  912.               if (svc) if (*svc == '-' || !*svc)
  913.                 svc = NULL;
  914.               if (svc) {
  915.                   xargv++;
  916.                   xargc--;
  917.               }
  918.               }
  919.           }
  920.           }
  921.           if (!svc) svc = "";
  922.           if (!*svc) svc = "http";
  923.           if (!host) XFATAL("No http host given");
  924.  
  925.           /* Check action args before opening the connection */
  926.           if (http_action) {
  927.           if (http_action == HTTP_PUT) {
  928.               if (!lpath)
  929.             XFATAL("No local path for http PUT");
  930.           }
  931.           if (!path)
  932.             XFATAL("No remote path for http action");
  933.           }
  934.           /* Now it's OK to open the connection */
  935.           rdns[0] = NUL;
  936.           x = (http_open(host,
  937.                  svc,!ckstrcmp("https",svc,-1,0),rdns,128,NULL
  938.                  ) == 0);
  939.           if (!x) {
  940.           if (!quiet)
  941.             printf("?HTTP Connection failed.\r\n");
  942.           doexit(BAD_EXIT,-1);
  943.           }
  944.           if (!quiet) {
  945.           if (rdns[0])
  946.             printf("Connected to %s [%s]\r\n",host,rdns);
  947.           else
  948.             printf("Connected to %s\r\n",host);
  949.           }
  950.           if (http_action) {
  951.                   int pcpy = 0;
  952.           if (http_action != HTTP_PUT) { /* Supply default */
  953.               if (!lpath) {         /* local path... */
  954.               zstrip(path,&lpath);
  955.               if (!lpath)
  956.                 lpath = "";
  957.               if (!*lpath)
  958.                 lpath = "index.html";
  959.               }
  960.           }
  961.                   if (*path != '/') {
  962.                       char * p = (char *) malloc(strlen(path)+2);
  963.                       if (!p) fatal("?Memory allocation error\n");
  964.                       *p = '/';
  965.                       strcpy(&p[1],path);      /* safe */
  966.                       path = p;
  967.                       pcpy = 1;
  968.                   }
  969.           switch (http_action) {
  970.             case HTTP_GET:
  971.               x = http_get(agent,NULL,user,pswd,0,lpath,path,0);
  972.               break;
  973.               
  974.             case HTTP_PUT:
  975.               x = http_put(agent,NULL,"text/HTML",
  976.                    user,pswd,0,lpath,path,NULL,0);
  977.               break;
  978.  
  979.             case HTTP_HED:
  980.               x = http_head(agent,NULL,user,pswd,0,lpath,path,0);
  981.               break;
  982.           }
  983.           debug(F101,"cmdline http result","",x);
  984.                   x = (http_close() == 0);
  985.                   if (pcpy) free(path);
  986.                   doexit(x ? GOOD_EXIT : BAD_EXIT, -1);
  987.           }
  988.           return(0);
  989.       }
  990.     } else
  991. #endif /* NOHTTP */
  992. #ifdef NEWFTP
  993.       if (howcalled == I_AM_FTP) {    /* If I was called as FTP... */
  994.       debug(F100,"ftp personality","",0);
  995. #ifdef CK_URL
  996.       if (haveurl)
  997.             doftparg('U');
  998.       else 
  999. #endif /* CK_URL */
  1000.         {
  1001.         while (--xargc > 0) {    /* Go through command line words */
  1002.             xargv++;
  1003.             debug(F111,"cmdlin ftp xargv",*xargv,xargc);
  1004.             if (**xargv == '-') { /* Got an option */
  1005.             int xx;
  1006.             x = *(*xargv+1); /* Get the option letter */
  1007.             xx = doftparg(x);
  1008.             if (xx < 0) {
  1009.                 if (what == W_COMMAND)
  1010.                   return(0);
  1011.                 else
  1012.                   doexit(BAD_EXIT,1);
  1013.             }
  1014.             } else {        /* No dash - must be hostname */
  1015.             makestr(&ftp_host,*xargv);
  1016.             if (xargc > 1) {
  1017.                 port = *(xargv+1);
  1018.                 if (port) if (*port == '-' || !*port)
  1019.                   port = NULL;
  1020.                 if (port) {
  1021.                 xargv++;
  1022.                 xargc--;
  1023.                 }
  1024.             }
  1025.             debug(F110,"cmdlin ftp host",ftp_host,0);
  1026.             debug(F110,"cmdlin ftp port",port,0);
  1027.             }
  1028.         } /* while */
  1029.         } /* if (haveurl) */
  1030.  
  1031.       if (ftp_host) {
  1032.           int xx;
  1033. #ifdef NODIAL
  1034.           xx = xx_ftp(ftp_host,port);
  1035.           if (xx < 0 && (haveurl || ftp_cmdlin > 1)) doexit(BAD_EXIT,-1);
  1036. #else
  1037. #ifdef NOICP
  1038.           xx = xx_ftp(ftp_host,port);
  1039.           if (xx < 0 && (haveurl || ftp_cmdlin > 1)) doexit(BAD_EXIT,-1);
  1040. #else
  1041.           if (*ftp_host == '=') {    /* Skip directory lookup */
  1042.           xx = xx_ftp(&ftp_host[1],port);
  1043.           if (xx < 0 && (haveurl || ftp_cmdlin > 1))
  1044.             doexit(BAD_EXIT,-1);
  1045.           } else {            /* Want lookup */
  1046.           int i;
  1047.           nhcount = 0;        /* Check network directory */
  1048.           debug(F101,"cmdlin nnetdir","",nnetdir);
  1049.           if (nnetdir > 0)    /* If there is a directory... */
  1050.             lunet(ftp_host);    /* Look up the name */
  1051.           else            /* If no directory */
  1052.             nhcount = 0;    /* we didn't find anything there */
  1053. #ifdef DEBUG
  1054.           if (deblog) {
  1055.               debug(F101,"cmdlin lunet nhcount","",nhcount);
  1056.               if (nhcount > 0) {
  1057.               debug(F110,"cmdlin lunet nh_p[0]",nh_p[0],0);
  1058.               debug(F110,"cmdlin lunet nh_p2[0]",nh_p2[0],0);
  1059.               debug(F110,"cmdlin lunet nh_px[0][0]",
  1060.                 nh_px[0][0],0);
  1061.               }
  1062.           }
  1063. #endif /* DEBUG */
  1064.           if (nhcount == 0) {
  1065.               xx = xx_ftp(ftp_host,port);
  1066.               if (xx < 0 && (haveurl || ftp_cmdlin > 1))
  1067.             doexit(BAD_EXIT,-1);
  1068.           } else {
  1069.               for (i = 0; i < nhcount; i++) {
  1070.               if (ckstrcmp(nh_p2[i],"tcp/ip",6,0))
  1071.                 continue;
  1072.               makestr(&ftp_host,nh_p[i]);
  1073.               debug(F110,"cmdlin calling xx_ftp",ftp_host,0);
  1074.               if (!quiet)
  1075.                 printf("Trying %s...\n",ftp_host);
  1076.               if (xx_ftp(ftp_host,port) > -1)
  1077.                 break;
  1078.               }
  1079.           }
  1080.           }
  1081. #endif /* NODIAL */
  1082. #endif /* NOICP */
  1083.           if (!ftpisconnected())
  1084.         doexit(BAD_EXIT,-1);
  1085.       }
  1086.       return(0);
  1087.       }
  1088. #endif /* NEWFTP */
  1089.  
  1090. #ifdef TNCODE
  1091.     if (howcalled == I_AM_TELNET) {     /* If I was called as Telnet... */
  1092.  
  1093.         while (--xargc > 0) {        /* Go through command line words */
  1094.             xargv++;
  1095.             debug(F111,"cmdlin telnet xargv",*xargv,xargc);
  1096.             if (**xargv == '=')
  1097.           return(0);
  1098.             if (!strcmp(*xargv,"--"))    /* getopt() conformance */
  1099.           return(0);
  1100. #ifdef VMS
  1101.             else if (**xargv == '/')
  1102.           continue;
  1103. #endif /* VMS */
  1104.             else if (**xargv == '-') {    /* Got an option (begins with dash) */
  1105.                 int xx;
  1106.                 x = *(*xargv+1);    /* Get the option letter */
  1107.                 debug(F111,"cmdlin telnet args 1",*xargv,xargc);
  1108.                 xx = dotnarg(x);
  1109.                 debug(F101,"cmdlin telnet doarg","",xx);
  1110.                 debug(F111,"cmdlin telnet args 2",*xargv,xargc);
  1111.                 if (xx < 0) {
  1112. #ifndef NOICP
  1113.                     if (what == W_COMMAND)
  1114.               return(0);
  1115.                     else
  1116. #endif /* NOICP */
  1117.               {
  1118. #ifdef OS2
  1119.               sleep(1);    /* Give it a chance... */
  1120. #endif /* OS2 */
  1121.               doexit(BAD_EXIT,1); /* Go handle option */
  1122.               }
  1123.                 }
  1124.             } else {            /* No dash must be hostname */
  1125.                 ckstrncpy(ttname,*xargv,TTNAMLEN+1);
  1126.                 debug(F110,"cmdlin telnet host",ttname,0);
  1127.  
  1128. #ifndef NOICP
  1129. #ifndef NODIAL
  1130.                 nhcount = 0;        /* Check network directory */
  1131.                 debug(F101,"cmdlin telnet nnetdir","",nnetdir);
  1132.                 if (nnetdir > 0)    /* If there is a directory... */
  1133.           lunet(*xargv);    /* Look up the name */
  1134.                 else            /* If no directory */
  1135.           nhcount = 0;        /* we didn't find anything there */
  1136. #ifdef DEBUG
  1137.                 if (deblog) {
  1138.                     debug(F101,"cmdlin telnet lunet nhcount","",nhcount);
  1139.                     if (nhcount > 0) {
  1140.                         debug(F110,"cmdlin telnet lunet nh_p[0]",nh_p[0],0);
  1141.                         debug(F110,"cmdlin telnet lunet nh_p2[0]",nh_p2[0],0);
  1142.                         debug(F110,"cmdlin telnet lunet nh_px[0][0]",
  1143.                   nh_px[0][0],0);
  1144.                     }
  1145.                 }
  1146. #endif /* DEBUG */
  1147.                 if (nhcount > 0 && nh_p2[0]) /* If network type specified */
  1148.           if (ckstrcmp(nh_p2[0],"tcp/ip",6,0)) /* it must be TCP/IP */
  1149.             nhcount = 0;
  1150.                 if (nhcount == 1) {    /* Still OK, so make substitution */
  1151.                     ckstrncpy(ttname,nh_p[0],TTNAMLEN+1);
  1152.                     debug(F110,"cmdlin telnet lunet substitution",ttname,0);
  1153.                 }
  1154. #endif /* NODIAL */
  1155. #endif /* NOICP */
  1156.  
  1157.                 if (--xargc > 0 && !haveurl) { /* Service from command line? */
  1158.                     xargv++;
  1159.                     ckstrncat(ttname,":",TTNAMLEN+1);
  1160.                     ckstrncat(ttname,*xargv,TTNAMLEN+1);
  1161.                     debug(F110,"cmdlin telnet host2",ttname,0);
  1162.                 }
  1163. #ifndef NOICP
  1164. #ifndef NODIAL
  1165.                 else if (nhcount) {    /* No - how about in net directory? */
  1166.                     if (nh_px[0][0]) {
  1167.                         ckstrncat(ttname,":",TTNAMLEN+1);
  1168.                         ckstrncat(ttname,nh_px[0][0],TTNAMLEN+1);
  1169.                     }
  1170.                 }
  1171. #endif /* NODIAL */
  1172. #endif /* NOICP */
  1173.                 local = 1;        /* Try to open the connection */
  1174.                 nettype = NET_TCPB;
  1175.                 mdmtyp = -nettype;
  1176.                 if (ttopen(ttname,&local,mdmtyp,0) < 0) {
  1177.                     XFATAL("can't open host connection");
  1178.                 }
  1179.                 network = 1;        /* It's open */
  1180. #ifdef CKLOGDIAL
  1181.                 dolognet();
  1182. #endif /* CKLOGDIAL */
  1183. #ifndef NOXFER
  1184.                 reliable = 1;        /* It's reliable */
  1185.                 xreliable = 1;        /* ... */
  1186.                 setreliable = 1;
  1187. #endif /* NOXFER */
  1188.                 cflg = 1;        /* Connect */
  1189.                 stayflg = 1;        /* Stay */
  1190.                 tn_exit = 1;        /* Telnet-like exit condition */
  1191.                 quiet = 1;
  1192.                 exitonclose = 1;    /* Exit when connection closes */
  1193. #ifndef NOSPL
  1194.                 if (local) {
  1195.                     if (nmac) {        /* Any macros defined? */
  1196.                         int k;        /* Yes */
  1197.                         k = mlook(mactab,"on_open",nmac); /* Look this up */
  1198.                         if (k >= 0) {                     /* If found, */
  1199.                             if (dodo(k,ttname,0) > -1)    /* set it up, */
  1200.                                 parser(1);                /* and execute it */
  1201.                         }
  1202.                     }
  1203.                 }
  1204. #endif /* NOSPL */
  1205.                 break;
  1206.             }
  1207.         }
  1208.         return(0);
  1209.     }
  1210. #endif /* TNCODE */
  1211. #ifdef RLOGCODE
  1212.     else if (howcalled == I_AM_RLOGIN) { /* If I was called as Rlogin... */
  1213.         while (--xargc > 0) {        /* Go through command line words */
  1214.             xargv++;
  1215.             debug(F111,"cmdlin rlogin xargv",*xargv,xargc);
  1216.             if (**xargv == '=')
  1217.           return(0);
  1218.             if (!strcmp(*xargv,"--"))    /* getopt() conformance */
  1219.           return(0);
  1220. #ifdef VMS
  1221.             else if (**xargv == '/')
  1222.           continue;
  1223. #endif /* VMS */
  1224.             else if (**xargv == '-') {    /* Got an option (begins with dash) */
  1225.                 int xx;
  1226.                 x = *(*xargv+1);    /* Get the option letter */
  1227.                 debug(F111,"cmdlin rlogin args 1",*xargv,xargc);
  1228.                 xx = dorlgarg(x);
  1229.                 debug(F101,"cmdlin rlogin doarg","",xx);
  1230.                 debug(F111,"cmdlin rlogin args 2",*xargv,xargc);
  1231.                 if (xx < 0) {
  1232. #ifndef NOICP
  1233.                     if (what == W_COMMAND)
  1234.               return(0);
  1235.                     else
  1236. #endif /* NOICP */
  1237.               {
  1238. #ifdef OS2
  1239.               sleep(1);    /* Give it a chance... */
  1240. #endif /* OS2 */
  1241.               doexit(BAD_EXIT,1); /* Go handle option */
  1242.               }
  1243.                 }
  1244.             } else {            /* No dash must be hostname */
  1245.                 ckstrncpy(ttname,*xargv,TTNAMLEN+1);
  1246.                 debug(F110,"cmdlin rlogin host",ttname,0);
  1247.  
  1248. #ifndef NOICP
  1249. #ifndef NODIAL
  1250.                 nhcount = 0;        /* Check network directory */
  1251.                 debug(F101,"cmdlin rlogin nnetdir","",nnetdir);
  1252.                 if (nnetdir > 0)    /* If there is a directory... */
  1253.           lunet(*xargv);    /* Look up the name */
  1254.                 else            /* If no directory */
  1255.           nhcount = 0;        /* we didn't find anything there */
  1256. #ifdef DEBUG
  1257.                 if (deblog) {
  1258.                     debug(F101,"cmdlin rlogin lunet nhcount","",nhcount);
  1259.                     if (nhcount > 0) {
  1260.                         debug(F110,"cmdlin rlogin lunet nh_p[0]",nh_p[0],0);
  1261.                         debug(F110,"cmdlin rlogin lunet nh_p2[0]",nh_p2[0],0);
  1262.                         debug(F110,"cmdlin rlogin lunet nh_px[0][0]",
  1263.                   nh_px[0][0],0);
  1264.                     }
  1265.                 }
  1266. #endif /* DEBUG */
  1267.                 if (nhcount > 0 && nh_p2[0]) /* If network type specified */
  1268.           if (ckstrcmp(nh_p2[0],"tcp/ip",6,0)) /* it must be TCP/IP */
  1269.             nhcount = 0;
  1270.                 if (nhcount == 1) {    /* Still OK, so make substitution */
  1271.                     ckstrncpy(ttname,nh_p[0],TTNAMLEN+1);
  1272.                     debug(F110,"cmdlin rlogin lunet substitution",ttname,0);
  1273.                 }
  1274. #endif /* NODIAL */
  1275. #endif /* NOICP */
  1276.  
  1277.                 if (!haveurl) { /* Service from command line? */
  1278.                     ckstrncat(ttname,":login",TTNAMLEN+1);
  1279.                     debug(F110,"cmdlin rlogin host2",ttname,0);
  1280.                 }
  1281.                 local = 1;        /* Try to open the connection */
  1282.                 nettype = NET_TCPB;
  1283.                 mdmtyp = -nettype;
  1284.                 if (ttopen(ttname,&local,mdmtyp,0) < 0) {
  1285.                     XFATAL("can't open host connection");
  1286.                 }
  1287.                 network = 1;        /* It's open */
  1288. #ifdef CKLOGDIAL
  1289.                 dolognet();
  1290. #endif /* CKLOGDIAL */
  1291. #ifndef NOXFER
  1292.                 reliable = 1;        /* It's reliable */
  1293.                 xreliable = 1;        /* ... */
  1294.                 setreliable = 1;
  1295. #endif /* NOXFER */
  1296.                 cflg = 1;        /* Connect */
  1297.                 stayflg = 1;        /* Stay */
  1298.                 tn_exit = 1;        /* Telnet-like exit condition */
  1299.                 quiet = 1;
  1300.                 exitonclose = 1;    /* Exit when connection closes */
  1301. #ifndef NOSPL
  1302.                 if (local) {
  1303.                     if (nmac) {        /* Any macros defined? */
  1304.                         int k;        /* Yes */
  1305.                         k = mlook(mactab,"on_open",nmac); /* Look this up */
  1306.                         if (k >= 0) {                     /* If found, */
  1307.                             if (dodo(k,ttname,0) > -1)    /* set it up, */
  1308.                                 parser(1);                /* and execute it */
  1309.                         }
  1310.                     }
  1311.                 }
  1312. #endif /* NOSPL */
  1313.                 break;
  1314.             }
  1315.         }
  1316.         return(0);
  1317.     }
  1318. #endif /* RLOGCODE */
  1319. #endif /* TCPSOCKET */
  1320.  
  1321. #ifdef SSHBUILTIN
  1322.       if (howcalled == I_AM_SSH) {    /* If I was called as SSH... */
  1323.           extern char * ssh_hst, * ssh_cmd, * ssh_prt;
  1324.       debug(F100,"ssh personality","",0);
  1325. #ifdef CK_URL
  1326.       if (haveurl) {
  1327.               makestr(&ssh_hst,g_url.hos);
  1328.               makestr(&ssh_prt,g_url.svc);
  1329.           ckstrncpy(ttname,ssh_hst,TTNAMLEN+1);
  1330.               ckstrncat(ttname,":",TTNAMLEN+1);
  1331.               ckstrncat(ttname,ssh_prt,TTNAMLEN+1);
  1332.           }
  1333.       else 
  1334. #endif /* CK_URL */
  1335.       {
  1336.               while (--xargc > 0) {    /* Go through command line words */
  1337.                   xargv++;
  1338.                   debug(F111,"cmdlin ssh xargv",*xargv,xargc);
  1339.                   if (**xargv == '=')
  1340.                       return(0);
  1341.                   if (!strcmp(*xargv,"--")) /* getopt() conformance */
  1342.                       return(0);
  1343. #ifdef VMS
  1344.                   else if (**xargv == '/')
  1345.                       continue;
  1346. #endif /* VMS */
  1347.           /* Got an option (begins with dash) */
  1348.                   else if (**xargv == '-') {
  1349.                       int xx;
  1350.                       x = *(*xargv+1);    /* Get the option letter */
  1351.                       debug(F111,"cmdlin args 1",*xargv,xargc);
  1352.                       xx = dossharg(x);
  1353.                       debug(F101,"cmdlin doarg","",xx);
  1354.                       debug(F111,"cmdlin args 2",*xargv,xargc);
  1355.                       if (xx < 0) {
  1356. #ifndef NOICP
  1357.                           if (what == W_COMMAND)
  1358.                 return(0);
  1359.                           else
  1360. #endif /* NOICP */
  1361.                           {
  1362. #ifdef OS2
  1363.                               sleep(1);    /* Give it a chance... */
  1364. #endif /* OS2 */
  1365.                               doexit(BAD_EXIT,1); /* Go handle option */
  1366.                           }
  1367.                       }
  1368.                   } else {            /* No dash must be hostname */
  1369.                       ckstrncpy(ttname,*xargv,TTNAMLEN+1);
  1370.                       makestr(&ssh_hst,ttname);
  1371.                       debug(F110,"cmdlin ssh host",ttname,0);
  1372. #ifndef NOICP
  1373. #ifndef NODIAL
  1374.                       nhcount = 0;        /* Check network directory */
  1375.                       debug(F101,"cmdlin nnetdir","",nnetdir);
  1376.                       if (nnetdir > 0)    /* If there is a directory... */
  1377.             lunet(*xargv);    /* Look up the name */
  1378.                       else        /* If no directory */
  1379.             nhcount = 0;    /* we didn't find anything there */
  1380. #ifdef DEBUG
  1381.                       if (deblog) {
  1382.                           debug(F101,"cmdlin lunet nhcount","",nhcount);
  1383.                           if (nhcount > 0) {
  1384.                               debug(F110,"cmdlin lunet nh_p[0]",nh_p[0],0);
  1385.                               debug(F110,"cmdlin lunet nh_p2[0]",nh_p2[0],0);
  1386.                               debug(F110,
  1387.                     "cmdlin lunet nh_px[0][0]",nh_px[0][0],0);
  1388.                           }
  1389.                       }
  1390. #endif /* DEBUG */
  1391.               /* If network type specified */
  1392.               /* it must be TCP/IP */
  1393.                       if (nhcount > 0 && nh_p2[0])
  1394.             if (ckstrcmp(nh_p2[0],"tcp/ip",6,0))
  1395.               nhcount = 0;
  1396.                       if (nhcount == 1) { /* Still OK, so make substitution */
  1397.                           ckstrncpy(ttname,nh_p[0],TTNAMLEN+1);
  1398.                           makestr(&ssh_hst,ttname);
  1399.                           debug(F110,"cmdlin lunet substitution",ttname,0);
  1400.                       }
  1401. #endif /* NODIAL */
  1402. #endif /* NOICP */
  1403.               /* Service from command line? */
  1404.                       if (--xargc > 0 && !haveurl) {
  1405.                           xargv++;
  1406.                           ckstrncat(ttname,":",TTNAMLEN+1);
  1407.                           ckstrncat(ttname,*xargv,TTNAMLEN+1);
  1408.                           makestr(&ssh_prt,*xargv);
  1409.                           debug(F110,"cmdlin telnet host2",ttname,0);
  1410.                       }
  1411. #ifdef COMMENT
  1412.                       /* Do not substitute net dir service for ssh port */
  1413. #ifndef NOICP
  1414. #ifndef NODIAL
  1415.               /* No - how about in net directory? */
  1416.                       else if (nhcount) {
  1417.                           if (nh_px[0][0]) {
  1418.                               ckstrncat(ttname,":",TTNAMLEN+1);
  1419.                               ckstrncat(ttname,nh_px[0][0],TTNAMLEN+1);
  1420.                               makestr(&ssh_prt,nh_px[0][0]);
  1421.                           }
  1422.                       }
  1423.  
  1424. #endif /* NODIAL */
  1425. #endif /* NOICP */
  1426. #endif /* COMMENT */
  1427.                       break;
  1428.                   }
  1429.               }
  1430.           }
  1431.           local = 1;            /* Try to open the connection */
  1432.           nettype = NET_SSH;
  1433.           mdmtyp = -nettype;
  1434.           if (ttopen(ttname,&local,mdmtyp,0) < 0) {
  1435.               XFATAL("can't open host connection");
  1436.           }
  1437.           network = 1;            /* It's open */
  1438. #ifdef CKLOGDIAL
  1439.           dolognet();
  1440. #endif /* CKLOGDIAL */
  1441. #ifndef NOXFER
  1442.           reliable = 1;            /* It's reliable */
  1443.           xreliable = 1;        /* ... */
  1444.           setreliable = 1;
  1445. #endif /* NOXFER */
  1446.           cflg = 1;            /* Connect */
  1447.           stayflg = 1;            /* Stay */
  1448.           tn_exit = 1;            /* Telnet-like exit condition */
  1449.           quiet = 1;
  1450.           exitonclose = 1;        /* Exit when connection closes */
  1451. #ifndef NOSPL
  1452.           if (local) {
  1453.               if (nmac) {        /* Any macros defined? */
  1454.                   int k;        /* Yes */
  1455.                   k = mlook(mactab,"on_open",nmac); /* Look this up */
  1456.                   if (k >= 0) {                     /* If found, */
  1457.                       if (dodo(k,ttname,0) > -1)    /* set it up, */
  1458.                           parser(1);                /* and execute it */
  1459.                   } 
  1460.               }     
  1461.           }
  1462. #endif /* NOSPL */
  1463.       return(0);
  1464.       }
  1465. #endif /* SSHBUILTIN */
  1466.  
  1467.     if (howcalled == I_AM_SSHSUB)
  1468.       return(0);
  1469.  
  1470. /*
  1471.   From here down: We were called as "kermit" or "iksd".
  1472.  
  1473.   If we were started directly from a Kermit script file,
  1474.   the filename of the script is in argv[1], so skip past it.
  1475. */
  1476.     if (xargc > 1) {
  1477.         int n = 1;
  1478.         if (*xargv[1] != '-') {
  1479.  
  1480. #ifdef KERBANG
  1481.             /* If we were started with a Kerbang script, the script */
  1482.             /* arguments were already picked up in prescan / cmdini() */
  1483.             /* and there is nothing here for us anyway. */
  1484.             if (!strcmp(xargv[1],"+"))
  1485.               return(0);
  1486. #endif /* KERBANG */
  1487.  
  1488.             if (cfilef) {               /* Command file found in prescan() */
  1489.                 xargc -= n;             /* Skip past it */
  1490.                 xargv += n;
  1491.                 cfilef = 0;
  1492.                 debug(F101,"cmdlin cfilef set to 0","",cfilef);
  1493.             }
  1494.         }
  1495.     }
  1496. /*
  1497.   Regular Unix-style command line parser, mostly conforming with 'A Proposed
  1498.   Command Syntax Standard for Unix Systems', Hemenway & Armitage, Unix/World,
  1499.   Vol.1, No.3, 1984.
  1500. */
  1501.     while (--xargc > 0) {               /* Go through command line words */
  1502.         xargv++;
  1503.         debug(F111,"cmdlin xargv",*xargv,xargc);
  1504.         if (**xargv == '=')
  1505.           return(0);
  1506.         if (!strcmp(*xargv,"--"))       /* getopt() conformance */
  1507.           return(0);
  1508. #ifdef VMS
  1509.         else if (**xargv == '/')
  1510.           continue;
  1511. #endif /* VMS */
  1512.         else if (**xargv == '-') {      /* Got an option (begins with dash) */
  1513.             int xx;
  1514.             x = *(*xargv+1);            /* Get the option letter */
  1515.             debug(F111,"cmdlin args 1",*xargv,xargc);
  1516.             xx = doarg(x);
  1517.             debug(F101,"cmdlin doarg","",xx);
  1518.             debug(F111,"cmdlin args 2",*xargv,xargc);
  1519.             if (xx < 0) {
  1520. #ifndef NOICP
  1521.                 if (what == W_COMMAND)
  1522.                   return(0);
  1523.                 else
  1524. #endif /* NOICP */
  1525.                   {
  1526. #ifdef OS2
  1527.                       sleep(1);         /* Give it a chance... */
  1528. #endif /* OS2 */
  1529.                       doexit(BAD_EXIT,1); /* Go handle option */
  1530.                   }
  1531.             }
  1532.         } else if (!haveurl) {        /* No dash where expected */
  1533.         char xbuf[32];
  1534.             char buf[128];
  1535.         int k;
  1536.         k = ckstrncpy(xbuf,*xargv,40);
  1537.         if (k > 30) {
  1538.         xbuf[30] = '.';
  1539.         xbuf[29] = '.';
  1540.         xbuf[28] = '.';
  1541.         }
  1542.         xbuf[31] = NUL;
  1543.             ckmakmsg(buf,
  1544.              128,
  1545.              "invalid command-line option, type \"",
  1546.              myname,
  1547.              " -h\" for help",
  1548.              NULL
  1549.              );
  1550.         fatal2(xbuf,buf);
  1551.         }
  1552.     }
  1553. #ifdef DEBUG
  1554.     if (deblog) {
  1555. #ifndef NOICP
  1556.         debug(F101,"cmdlin what","",what);
  1557. #endif /* NOICP */
  1558.         debug(F101,"cmdlin action","",action);
  1559. #ifndef NOXFER
  1560.         debug(F101,"cmdlin stdouf","",stdouf);
  1561. #endif /* NOXFER */
  1562.     }
  1563. #endif /* DEBUG */
  1564.  
  1565. #ifdef NOICP
  1566.     if (!action && !cflg && !cnflg) {
  1567.         debug(F100,"cmdlin NOICP fatal no action","",0);
  1568.         XFATAL("?No actions specified on command line");
  1569.     }
  1570. #else
  1571.     if (inserver && what == 0) {        /* Internet Kermit server checks */
  1572.         if (local || (action != 0 && action != 'x')) {
  1573.             if (local)
  1574.               printf("local\r\n");
  1575.             if (action)
  1576.               printf("action=%c\r\n",action);
  1577.             debug(F100,"cmdlin fatal 1","",0);
  1578.             XFATAL("No actions or connections allowed with -A");
  1579.         }
  1580.     }
  1581. #endif /* NOICP */
  1582.  
  1583. #ifndef NOLOCAL
  1584.     if (!local) {
  1585.         if ((action == 'c') || (cflg != 0)) {
  1586.             debug(F100,"cmdlin fatal 2","",0);
  1587.             XFATAL("-l or -j or -X required");
  1588.         }
  1589.     }
  1590. #endif /* NOLOCAL */
  1591. #ifndef NOXFER
  1592.     if (*cmarg2 != 0) {
  1593.         if ((action != 's') && (action != 'r') && (action != 'v')) {
  1594.             debug(F100,"cmdlin fatal 3","",0);
  1595.             XFATAL("-a without -s, -r, or -g");
  1596.         }
  1597.         if (action == 'r' || action == 'v') {
  1598. #ifdef CK_TMPDIR
  1599.             if (isdir(cmarg2)) {        /* -a is a directory */
  1600.                 if (!zchdir(cmarg2)) {  /* try to change to it */
  1601.                     debug(F100,"cmdlin fatal 4","",0);
  1602.                     XFATAL("can't change to '-a' directory");
  1603.                 } else cmarg2 = "";
  1604.             } else
  1605. #endif /* CK_TMPDIR */
  1606.               if (zchko(cmarg2) < 0) {
  1607.                   debug(F100,"cmdlin fatal 5","",0);
  1608.                   XFATAL("write access to -a file denied");
  1609.               }
  1610.         }
  1611.     }
  1612.     if ((action == 'v') && (stdouf) && (!local)) {
  1613.         if (is_a_tty(1)) {
  1614.             debug(F100,"cmdlin fatal 6","",0);
  1615.             XFATAL("unredirected -k can only be used in local mode");
  1616.         }
  1617.     }
  1618.     if ((action == 's') || (action == 'v') ||
  1619.         (action == 'r') || (action == 'x')) {
  1620.         if (local)
  1621.           displa = 1;
  1622.         if (stdouf) {
  1623.             displa = 0;
  1624.             quiet = 1;
  1625.         }
  1626.     }
  1627.     if (quiet) displa = 0;              /* No display if quiet requested */
  1628. #endif /* NOXFER */
  1629. #ifdef DEBUG
  1630.     if (action)
  1631.       debug(F000,"cmdlin returns action","",action);
  1632.     else
  1633.       debug(F101,"cmdlin returns action","",action);
  1634. #endif /* DEBUG */
  1635.  
  1636.     return(action);                     /* Then do any requested protocol */
  1637. }
  1638.  
  1639. /* Extended argument parsing: --keyword[:value] (or =value) */
  1640.  
  1641. /*
  1642.   XA_xxxx symbols are defined in ckuusr.h.
  1643.   If you add a new one, also remember to update doshow(),
  1644.   SHXOPT section, in ckuus5.c.
  1645. */
  1646. struct keytab xargtab[] = {
  1647. #ifdef CK_LOGIN
  1648.     { "anonymous",   XA_ANON, CM_ARG|CM_PRE },
  1649. #endif /* CK_LOGIN */
  1650.     { "bannerfile",  XA_BAFI, CM_ARG },
  1651.     { "cdfile",      XA_CDFI, CM_ARG },
  1652.     { "cdmessage",   XA_CDMS, CM_ARG },
  1653.     { "cdmsg",       XA_CDMS, CM_ARG|CM_INV },
  1654. #ifdef KUI
  1655.     { "changedim",   XA_CHGD, CM_PRE },
  1656. #endif /* KUI */
  1657. #ifndef NOCSETS
  1658.     { "charset",     XA_CSET, CM_ARG|CM_PRE },
  1659. #endif /* NOCSETS */
  1660. #ifdef IKSDB
  1661.     { "database",    XA_DBAS, CM_ARG|CM_PRE },
  1662.     { "dbfile",      XA_DBFI, CM_ARG|CM_PRE },
  1663. #endif /* IKSDB */
  1664. #ifdef KUI
  1665.     { "facename",    XA_FNAM, CM_ARG|CM_PRE|CM_INV },
  1666.     { "fontname",    XA_FNAM, CM_ARG|CM_PRE },
  1667.     { "fontsize",    XA_FSIZ, CM_ARG|CM_PRE },
  1668. #endif /* KUI */
  1669. #ifdef COMMENT
  1670. #ifdef NEWFTP
  1671.     { "ftp",         XA_FTP,  CM_ARG },
  1672. #endif /* NEWFTP */
  1673. #endif /* COMMENT */
  1674. #ifndef NOLOCAL
  1675. #ifdef OS2
  1676.     { "height",      XA_ROWS, CM_ARG|CM_PRE },
  1677. #endif /* OS2 */
  1678. #endif /* NOLOCAL */
  1679.     { "help",        XA_HELP, 0 },
  1680. #ifndef NOHELP
  1681.     { "helpfile",    XA_HEFI, CM_ARG },
  1682. #endif /* NOHELP */
  1683. #ifdef CK_LOGIN
  1684.     { "initfile",    XA_ANFI, CM_ARG|CM_PRE },
  1685. #endif /* CK_LOGIN */
  1686. #ifdef OS2
  1687.     { "lockdown",    XA_LOCK, CM_PRE },
  1688. #ifdef KUI
  1689.     { "maximize",    XA_WMAX,  CM_PRE },
  1690.     { "minimize",    XA_WMIN,  CM_PRE },
  1691.     { "nobars",      XA_NOBAR, CM_PRE },
  1692.     { "noclose" ,    XA_NOCLOSE, CM_PRE },
  1693. #endif /* KUI */
  1694.     { "noescape",    XA_NOESCAPE, CM_PRE },
  1695. #endif /* OS2 */
  1696.     { "nointerrupts",XA_NOIN, CM_PRE },
  1697. #ifdef KUI
  1698.     { "nomenubar",   XA_NOMN, CM_PRE },
  1699. #endif /* KUI */
  1700.     { "noperms",     XA_NPRM, 0 },
  1701. #ifndef NOPUSH
  1702.     { "nopush",      XA_NOPUSH, CM_PRE },
  1703. #endif /* NOPUSH */
  1704. #ifdef OS2
  1705.     { "noscroll",    XA_NOSCROLL, CM_PRE },
  1706. #endif /* OS2 */
  1707. #ifdef KUI
  1708.     { "nostatusbar", XA_NOSB, CM_PRE },
  1709.     { "notoolbar",   XA_NOTB, CM_PRE },
  1710. #endif /* KUI */
  1711. #ifdef COMMENT
  1712.     { "password",    XA_PASS, CM_ARG|CM_INV },
  1713. #endif /* COMMENT */
  1714. #ifdef CK_LOGIN
  1715. #ifndef NOXFER
  1716. #ifdef CK_PERM
  1717.     { "permissions", XA_PERM, CM_ARG|CM_PRE },
  1718.     { "perms",       XA_PERM, CM_ARG|CM_PRE|CM_INV },
  1719. #endif /* CK_PERM */
  1720. #endif /* NOXFER */
  1721. #ifdef UNIX
  1722.     { "privid",      XA_PRIV, CM_ARG|CM_PRE },
  1723. #endif /* UNIX */
  1724. #ifndef NOLOCAL
  1725. #ifndef NOCSETS
  1726.     { "rcharset",    XA_CSET, CM_ARG|CM_PRE|CM_INV },
  1727. #endif /* NOCSETS */
  1728. #endif /* NOLOCAL */
  1729. #ifdef UNIX
  1730.     { "root",        XA_ROOT, CM_ARG|CM_PRE },
  1731. #else /* UNIX */
  1732. #ifdef CKROOT
  1733.     { "root",        XA_ROOT, CM_ARG|CM_PRE },
  1734. #endif /* CKROOT */
  1735. #endif /* UNIX */
  1736. #ifdef KUI
  1737.     { "scalefont",   XA_SCALE, CM_PRE },
  1738. #endif /* KUI */
  1739. #ifdef COMMENT
  1740. #ifdef SSHBUILTIN
  1741.     { "ssh",         XA_SSH,  CM_ARG },
  1742. #endif /* SSHBUILTIN */
  1743. #endif /* COMMENT */
  1744. #ifdef CKSYSLOG
  1745.     { "syslog",      XA_SYSL, CM_ARG|CM_PRE },
  1746. #endif /* CKSYSLOG */
  1747. #ifndef NOLOCAL
  1748. #ifdef COMMENT
  1749. #ifdef TNCODE
  1750.     { "telnet",      XA_TEL,  CM_ARG },
  1751. #endif /* TNCODE */
  1752. #endif /* COMMENT */
  1753.     { "termtype",    XA_TERM, CM_ARG|CM_PRE },
  1754. #endif /* NOLOCAL */
  1755.     { "timeout",     XA_TIMO, CM_ARG|CM_PRE },
  1756. #ifndef NOLOCAL
  1757. #ifdef OS2
  1758.     { "title",       XA_TITL, CM_ARG },
  1759. #endif /* OS2 */
  1760. #ifdef UNIX
  1761.     { "unbuffered",  XA_UNBUF, 0 },
  1762. #endif    /* UNIX */
  1763. #ifndef NOSPL
  1764.     { "user",        XA_USER, CM_ARG },
  1765. #endif /* NOSPL */
  1766. #endif /* NOLOCAL */
  1767.     { "userfile",    XA_USFI, CM_ARG|CM_PRE },
  1768.     { "version",     XA_VERS, 0 },
  1769. #ifndef NOLOCAL
  1770. #ifdef OS2
  1771.     { "width",       XA_COLS, CM_ARG|CM_PRE },
  1772. #endif /* OS2 */
  1773. #endif /* NOLOCAL */
  1774. #ifdef CKWTMP
  1775.     { "wtmpfile",    XA_WTFI, CM_ARG|CM_PRE },
  1776.     { "wtmplog",     XA_WTMP, CM_ARG|CM_PRE },
  1777. #endif /* CKWTMP */
  1778. #endif /* CK_LOGIN */
  1779.     { "xferfile",    XA_IKFI, CM_ARG|CM_PRE },
  1780.     { "xferlog",     XA_IKLG, CM_ARG|CM_PRE },
  1781. #ifndef NOLOCAL
  1782. #ifdef KUI
  1783.     { "xpos",        XA_XPOS, CM_ARG|CM_PRE },
  1784.     { "ypos",        XA_YPOS, CM_ARG|CM_PRE },
  1785. #endif /* KUI */
  1786. #endif /* NOLOCAL */
  1787.     {"", 0, 0 }
  1788. };
  1789. int nxargs = sizeof(xargtab)/sizeof(struct keytab) - 1;
  1790.  
  1791. static struct keytab oktab[] = {
  1792.     { "0",     0, 0 },
  1793.     { "1",     1, 0 },
  1794.     { "2",     2, 0 },
  1795.     { "3",     3, 0 },
  1796.     { "4",     4, 0 },
  1797.     { "5",     5, 0 },
  1798.     { "6",     6, 0 },
  1799.     { "7",     7, 0 },
  1800.     { "8",     8, 0 },
  1801.     { "9",     9, 0 },
  1802.     { "false", 0, 0 },
  1803.     { "no",    0, 0 },
  1804.     { "off",   0, 0 },
  1805.     { "ok",    1, 0 },
  1806.     { "on",    1, 0 },
  1807.     { "true",  1, 0 },
  1808.     { "yes",   1, 0 }
  1809. };
  1810. static int noktab = sizeof(oktab)/sizeof(struct keytab);
  1811.  
  1812. #define XARGBUFL 32
  1813.  
  1814. char * xopthlp[XA_MAX+1];               /* Extended option help */
  1815. char * xarghlp[XA_MAX+1];               /* Extended argument for option */
  1816.  
  1817. static VOID
  1818. inixopthlp() {
  1819.     int i, j;
  1820.     for (i = 0; i <= XA_MAX; i++) {     /* Initialize all to null */
  1821.         xopthlp[i] = NULL;
  1822.         xarghlp[i] = NULL;
  1823.     }
  1824.     for (i = 0; i < nxargs; i++) {      /* Then for each defined keyword */
  1825.         j = xargtab[i].kwval;           /* index by associated value */
  1826.         if (j < 0 || j > XA_MAX)
  1827.           continue;
  1828.         switch (j) {
  1829. #ifdef CK_LOGIN
  1830.           case XA_ANON:                 /* "--anonymous" */
  1831.             xopthlp[j] = "--anonymous:{on,off} [IKSD only]";
  1832.             xarghlp[j] = "Whether to allow anonymous IKSD logins";
  1833.             break;
  1834. #ifdef UNIX
  1835.       case XA_PRIV:
  1836.             xopthlp[j] = "--privid:{on,off} [IKSD only]";
  1837.             xarghlp[j] = "Whether to allow privileged IDs to login to IKSD";
  1838.             break;
  1839. #endif /* UNIX */
  1840. #endif /* CK_LOGIN */
  1841.           case XA_BAFI:                 /* "--bannerfile" */
  1842.             xopthlp[j] = "--bannerfile:<filename>";
  1843.             xarghlp[j] = "File to display upon startup or IKSD login";
  1844.             break;
  1845.           case XA_CDFI:                 /* "--cdfile" */
  1846.             xopthlp[j] = "--cdfile:<filename>";
  1847.             xarghlp[j] = "File to display when server changes directory";
  1848.             break;
  1849.           case XA_CDMS:                 /* "--cdmessage" */
  1850.             xopthlp[j] = "--cdmessage:{on,off}";
  1851.             xarghlp[j] = "Whether to display CD message file";
  1852.             break;
  1853.           case XA_HELP:                 /* "--help" */
  1854.             xopthlp[j] = "--help";
  1855.             xarghlp[j] = "Print this help text about extended options";
  1856.             break;
  1857.           case XA_HEFI:                 /* "--help" */
  1858.             xopthlp[j] = "--helpfile:<filename>";
  1859.             xarghlp[j] = "File containing custom info for HELP command";
  1860.             break;
  1861.           case XA_IKFI:                 /* "--xferfile" */
  1862.             xopthlp[j] = "--xferfile:<filename> [IKSD only]";
  1863.             xarghlp[j] = "Name of ftpd-like logfile.";
  1864.             break;
  1865.           case XA_IKLG:                 /* "--xferlog" */
  1866.             xopthlp[j] = "--xferlog:{on,off} [IKSD only]";
  1867.             xarghlp[j] = "Whether to keep an ftpd-like logfile.";
  1868.             break;
  1869. #ifdef CK_LOGIN
  1870.           case XA_ANFI:                 /* "--initfile" */
  1871.             xopthlp[j] = "--initfile:<filename> [IKSD only]";
  1872.             xarghlp[j] = "Initialization file for anonymous users.";
  1873.             break;
  1874. #ifdef CK_PERM
  1875.           case XA_PERM:                 /* "--permissions" */
  1876.             xopthlp[j] = "--permissions:<octalnum> [IKSD only]";
  1877.             xarghlp[j] = "Permissions for files uploaded by anonymous users.";
  1878.             break;
  1879. #endif /* CK_PERM */
  1880. #ifdef UNIX
  1881.           case XA_ROOT:                 /* "--root" */
  1882.             xopthlp[j] = "--root:<directory> [IKSD only]";
  1883.             xarghlp[j] = "File-system root for anonymous users.";
  1884.             break;
  1885. #else /* UNIX */
  1886. #ifdef CKROOT
  1887.           case XA_ROOT:                 /* "--root" */
  1888.             xopthlp[j] = "--root:<directory> [IKSD only]";
  1889.             xarghlp[j] = "File-system root for anonymous users.";
  1890.             break;
  1891. #endif /* CKROOT */
  1892. #endif /* UNIX */
  1893. #endif /* CK_LOGIN */
  1894. #ifdef CKSYSLOG
  1895.           case XA_SYSL:                 /* "--syslog" */
  1896.             xopthlp[j] = "--syslog:<digit> [IKSD only]";
  1897.             xarghlp[j] = "Syslog recording level, 0-6.";
  1898.             break;
  1899. #endif /* CKSYSLOG */
  1900.           case XA_USFI:                 /* "--userfile" */
  1901.             xopthlp[j] = "--userfile:<filename> [IKSD only]";
  1902.             xarghlp[j] = "Forbidden user file.";
  1903.             break;
  1904. #ifdef CKWTMP
  1905.           case XA_WTFI:                 /* "--wtmpfile" */
  1906.             xopthlp[j] = "--wtmpfile:<filename> [IKSD only]";
  1907.             xarghlp[j] = "Name of wtmp logfile.";
  1908.             break;
  1909.           case XA_WTMP:                 /* "--wtmplog" */
  1910.             xopthlp[j] = "--wtmplog:{on,off} [IKSD only]";
  1911.             xarghlp[j] = "Whether to keep a wtmp logfile.";
  1912.             break;
  1913. #endif /* CKWTMP */
  1914. #ifdef CK_LOGIN
  1915.           case XA_TIMO:                 /* "--timeout" */
  1916.             xopthlp[j] = "--timeout:<seconds> [IKSD only]";
  1917.             xarghlp[j] =
  1918.  "How long to wait for login before closing the connection.";
  1919.             break;
  1920. #endif /* CK_LOGIN */
  1921.           case XA_NOIN:
  1922.             xopthlp[j] = "--nointerrupts";
  1923.             xarghlp[j] = "Disable keyboard interrupts.";
  1924.             break;
  1925. #ifdef UNIX
  1926.           case XA_UNBUF:
  1927.             xopthlp[j] = "--unbuffered";
  1928.             xarghlp[j] = "Force unbuffered console i/o.";
  1929.             break;
  1930. #endif    /* UNIX */
  1931. #ifdef IKSDB
  1932.           case XA_DBAS:
  1933.             xopthlp[j] = "--database:{on,off}";
  1934.             xarghlp[j] = "Enable/Disable IKSD database (IKSD only)";
  1935.             break;
  1936.           case XA_DBFI:
  1937.             xopthlp[j] = "--dbfile:<filename>";
  1938.             xarghlp[j] = "Specify IKSD database file (IKSD only)";
  1939.             break;
  1940. #endif /* IKSDB */
  1941. #ifdef CK_PERMS
  1942.       case XA_NPRM:
  1943.             xopthlp[j] = "--noperms";
  1944.             xarghlp[j] = "Disable file-transfer Permissions attribute.";
  1945.             break;
  1946. #endif /* CK_PERMS */
  1947. #ifdef KUI
  1948.           case XA_CHGD:
  1949.         xopthlp[j] = "--changedim";
  1950.         xarghlp[j] = "Change Dimension on Window Resize";
  1951.           case XA_SCALE:
  1952.         xopthlp[j] = "--scalefont";
  1953.         xarghlp[j] = "Scale Font on Window Resize";
  1954.           case XA_WMAX:
  1955.         xopthlp[j] = "--maximize";
  1956.         xarghlp[j] = "start K95G window maximized.";
  1957.         break;
  1958.           case XA_WMIN:
  1959.         xopthlp[j] = "--minimize";
  1960.         xarghlp[j] = "start K95G window minimized.";
  1961.         break;
  1962.       case XA_XPOS:
  1963.         xopthlp[j] = "--xpos:n";
  1964.         xarghlp[j] = "X-coordinate of window position (number).";
  1965.         break;
  1966.       case XA_YPOS:
  1967.         xopthlp[j] = "--ypos:n";
  1968.         xarghlp[j] = "Y-coordinate of window position (number).";
  1969.         break;
  1970.       case XA_FNAM:
  1971.         xopthlp[j] = "--fontname:s (or --facename:s)";
  1972.         xarghlp[j] = "Font/typeface name: string with _ replacing blank.";
  1973.         break;
  1974.       case XA_FSIZ:
  1975.         xopthlp[j] = "--fontsize:n";
  1976.         xarghlp[j] = "Font point size (number).";
  1977.         break;
  1978.           case XA_NOMN:
  1979.             xopthlp[j] = "--nomenubar";
  1980.             xarghlp[j] = "No Menu Bar";
  1981.             break;
  1982.           case XA_NOTB:
  1983.             xopthlp[j] = "--notoolbar";
  1984.             xarghlp[j] = "No Tool Bar";
  1985.             break;
  1986.           case XA_NOSB:
  1987.             xopthlp[j] = "--nostatusbar";
  1988.             xarghlp[j] = "No Status Bar";
  1989.             break;
  1990.           case XA_NOBAR:
  1991.             xopthlp[j] = "--nobars";
  1992.             xarghlp[j] = "No Menu, Status, or Tool Bars";
  1993.             break;
  1994. #endif /* KUI */
  1995. #ifndef NOPUSH
  1996.           case XA_NOPUSH:
  1997.         xopthlp[j] = "--nopush";
  1998.         xarghlp[j] = "Disable external command execution.";
  1999.         break;
  2000. #endif /* NOPUSH */
  2001. #ifdef OS2
  2002.           case XA_LOCK:
  2003.         xopthlp[j] = "--lockdown";
  2004.         xarghlp[j] = "Enable all lockdown options.";
  2005.         break;
  2006.           case XA_NOCLOSE:
  2007.             xopthlp[j] = "--noclose";
  2008.             xarghlp[j] = "Disable Close Window and Menu Exit.";
  2009.             break;
  2010.           case XA_NOSCROLL:
  2011.         xopthlp[j] = "--noscroll";
  2012.         xarghlp[j] = "Disable scrollback operations.";
  2013.         break;
  2014.           case XA_NOESCAPE:
  2015.         xopthlp[j] = "--noescape";
  2016.         xarghlp[j] = "Disable escape from connect mode.";
  2017.         break;
  2018.       case XA_ROWS:
  2019.         xopthlp[j] = "--height:n";
  2020.         xarghlp[j] = "Screen height (number of rows).";
  2021.         break;
  2022.       case XA_COLS:
  2023.         xopthlp[j] = "--width:n";
  2024.         xarghlp[j] = "Screen width (number of columns).";
  2025.         break;
  2026.           case XA_TITL:
  2027.             xopthlp[j] = "--title:string";
  2028.             xarghlp[j] = "Window Title.";
  2029.             break;
  2030. #endif /* OS2 */
  2031.       case XA_CSET:
  2032.         xopthlp[j] = "--rcharset:name";
  2033.         xarghlp[j] = "Name of remote terminal character set.";
  2034.         break;
  2035.       case XA_TERM:
  2036.         xopthlp[j] = "--termtype:name";
  2037. #ifdef OS2
  2038.         xarghlp[j] = "Choose terminal emulation.";
  2039. #else
  2040.         xarghlp[j] = "Choose terminal type.";
  2041. #endif /* OS2 */
  2042.         break;
  2043.       case XA_USER:
  2044.         xopthlp[j] = "--user:name";
  2045. #ifndef NETCONN
  2046.         xarghlp[j] = "Username (for network login)";
  2047. #else
  2048.         xarghlp[j] = "Username.";
  2049. #endif /* NETCONN */
  2050.         break;
  2051.        }
  2052.     }
  2053. }
  2054.  
  2055. VOID
  2056. iniopthlp() {
  2057.     int i;
  2058.     for (i = 0; i < 128; i++) {
  2059.         optact[i] = 0;
  2060.         switch(i) {
  2061. #ifdef OS2
  2062.           case '#':                     /* K95 Startup Flags */
  2063.             opthlp[i] = "Kermit 95 Startup Flags";
  2064.             arghlp[i] = "\n"\
  2065.               "   1 - turn off Win95 special fixes\n"\
  2066.               "   2 - do not load optional network dlls\n"\
  2067.               "   4 - do not load optional tapi dlls\n"\
  2068.               "   8 - do not load optional kerberos dlls\n"\
  2069.               "  16 - do not load optional zmodem dlls\n"\
  2070.               "  32 - use stdin for input instead of the console\n"\
  2071.               "  64 - use stdout for output instead of the console\n"\
  2072.               " 128 - do not terminate process in response to Session Logoff";
  2073.             break;
  2074. #endif /* OS2 */
  2075.           case '0':                     /* In the middle */
  2076.             opthlp[i] =
  2077.               "100% transparent CONNECT mode for \"in-the-middle\" operation";
  2078.             arghlp[i] = NULL;
  2079.             break;
  2080.  
  2081.           case '8':
  2082.             opthlp[i] = "Connection is 8-bit clean";
  2083.             arghlp[i] = NULL;
  2084.             break;
  2085.  
  2086. #ifdef NEWFTP
  2087.           case '9':
  2088.             opthlp[i] = "Make a connection to an FTP server";
  2089.             arghlp[i] = "IP-address-or-hostname[:optional-TCP-port]";
  2090.             break;
  2091. #endif /* NEWFTP */
  2092.  
  2093. #ifdef IKSD
  2094.           case 'A':
  2095.             opthlp[i] = "Kermit is to be started as an Internet service";
  2096. #ifdef NT
  2097.             arghlp[i] = "  socket handle of incoming connection";
  2098. #else /* NT */
  2099.             arghlp[i] = NULL;
  2100. #endif /* NT */
  2101.             break;
  2102. #endif /* IKSD */
  2103.           case 'B': opthlp[i] =
  2104.       "Kermit is running in Batch or Background (no controlling terminal)";
  2105.             break;
  2106. #ifndef NOSPL
  2107.           case 'C':
  2108.             opthlp[i] = "Interactive-mode Commands to be executed";
  2109.             arghlp[i] = "Commands separated by commas, list in doublequotes";
  2110.             break;
  2111. #endif /* NOSPL */
  2112.           case 'D':
  2113.             opthlp[i] = "Delay before starting to send";
  2114.             arghlp[i] = "Number of seconds";
  2115.             break;
  2116.           case 'E':
  2117.             opthlp[i] = "Exit automatically when connection closes";
  2118.             arghlp[i] = NULL;
  2119.             break;
  2120. #ifdef TCPSOCKET
  2121.           case 'F':
  2122.             opthlp[i] = "Make a TCP connection";
  2123.             arghlp[i] = "Numeric file descriptor of open TCP connection";
  2124.             break;
  2125. #endif /* TCPSOCKET */
  2126.           case 'G':
  2127.             opthlp[i] = "GET from server, send to standard output";
  2128.             arghlp[i] = "Remote file specification";
  2129.             optact[i] = 1;
  2130.             break;
  2131.           case 'H':
  2132.             opthlp[i] = "Suppress program startup Herald and greeting";
  2133.             arghlp[i] = NULL;
  2134.             break;
  2135.           case 'I':
  2136.             opthlp[i] = "Connection is reliable, streaming is allowed";
  2137.             arghlp[i] = NULL;
  2138.             break;
  2139. #ifdef TCPSOCKET
  2140.           case 'J':
  2141.             opthlp[i] = "'Be like Telnet'";
  2142.             arghlp[i] = "IP hostname/address optionally followed by service";
  2143.             break;
  2144. #endif /* TCPSOCKET */
  2145.           case 'L':
  2146.             opthlp[i] = "Recursive directory descent for files in -s option";
  2147.             arghlp[i] = NULL;
  2148.             break;
  2149.           case 'M':
  2150.             opthlp[i] = "My user name (for use with Telnet, Rlogin, etc)";
  2151.             arghlp[i] = "Username string";
  2152.             break;
  2153. #ifdef NETBIOS
  2154.           case 'N':
  2155.             opthlp[i] = "NETBIOS adapter number";
  2156.             arghlp[i] = "Number";
  2157.             break;
  2158. #endif /* NETBIOS */
  2159.           case 'O':                     /* Be a server for One command only */
  2160.             opthlp[i] = "Be a server for One command only";
  2161.             arghlp[i] = NULL;
  2162.             optact[i] = 1;
  2163.             break;
  2164.           case 'P':
  2165.             opthlp[i] = "Don't convert file (Path) names";
  2166.             arghlp[i] = NULL;
  2167.             break;
  2168.           case 'Q':
  2169.             opthlp[i] = "Quick (FAST) Kermit protocol settings";
  2170.             arghlp[i] = NULL;
  2171.             break;
  2172.           case 'R':                     /* Remote-Only */
  2173.             opthlp[i] = "Remote-only (makes IF REMOTE true)";
  2174.             arghlp[i] = NULL;
  2175.             break;
  2176.           case 'S':                     /* "Stay" - enter interactive */
  2177.             opthlp[i] = "Stay (enter command parser after action options)";
  2178.             arghlp[i] = NULL;
  2179.             break;
  2180.           case 'T':                     /* Text file transfer mode */
  2181.             opthlp[i] = "Transfer files in Text mode";
  2182.             arghlp[i] = NULL;
  2183.             break;
  2184. #ifdef ANYX25
  2185.           case 'U':                     /* X.25 call user data */
  2186.             opthlp[i] = "X.25 call User data";
  2187.             arghlp[i] = "Call-user-data string";
  2188.             break;
  2189. #endif /* ANYX25 */
  2190.           case 'V':                     /* No automatic filetype switching */
  2191.             opthlp[i] = "Disable automatic per-file text/binary switching";
  2192.             arghlp[i] = NULL;
  2193.             break;
  2194. #ifdef COMMENT
  2195. #ifdef OS2
  2196.           case 'W':                     /* Win32 Window Handle */
  2197.             opthlp[i] = "";
  2198.             arghlp[i] = NULL;
  2199.             break;
  2200. #endif /* OS2 */
  2201. #endif /* COMMENT */
  2202. #ifdef ANYX25
  2203.           case 'X':                     /* SET HOST to X.25 address */
  2204.             opthlp[i] = "Make an X.25 connection";
  2205.             arghlp[i] = "X.25 or X.121 address";
  2206.             break;
  2207. #endif /* ANYX25 */
  2208.           case 'Y':                     /* No initialization file */
  2209.             opthlp[i] = "Skip initialization file";
  2210.             arghlp[i] = NULL;
  2211.             break;
  2212. #ifdef ANYX25
  2213.           case 'Z':                     /* SET HOST to X.25 file descriptor */
  2214.             opthlp[i] = "Make an X.25 connection";
  2215.             arghlp[i] = "Numeric file descriptor of open X.25 connection";
  2216.             break;
  2217. #endif /* ANYX25 */
  2218.           case 'a':                     /* as-name */
  2219.             opthlp[i] = "As-name for file(s) in -s, -r, or -g";
  2220.             arghlp[i] = "As-name string (alternative filename)";
  2221.             break;
  2222.           case 'b':                     /* Set bits-per-second for serial */
  2223.             opthlp[i] = "Speed for serial device";
  2224.             arghlp[i] = "Numeric Bits per second";
  2225.             break;
  2226.           case 'c':                     /* Connect before */
  2227.             optact[i] = 1;
  2228.             opthlp[i] = "CONNECT before transferring files";
  2229.             arghlp[i] = NULL;
  2230.             break;
  2231.           case 'd':                     /* DEBUG */
  2232.             opthlp[i] = "Create debug.log file (a second -d adds timestamps)";
  2233.             arghlp[i] = NULL;
  2234.             break;
  2235.           case 'e':                     /* Extended packet length */
  2236.             opthlp[i] = "Maximum length for incoming file-transfer packets";
  2237.             arghlp[i] = "Length in bytes";
  2238.             break;
  2239.           case 'f':                     /* finish */
  2240.             optact[i] = 1;
  2241.             opthlp[i] = "Send Finish command to a Kermit server";
  2242.             arghlp[i] = NULL;
  2243.             break;
  2244.           case 'g':                     /* get */
  2245.             optact[i] = 1;
  2246.             opthlp[i] = "GET file(s) from a Kermit server";
  2247.             arghlp[i] = "Remote file specification";
  2248.             break;
  2249.           case 'h':                     /* help */
  2250.             optact[i] = 1;
  2251. #ifdef OS2ORUNIX
  2252.             opthlp[i] =
  2253.           "Print this message (pipe thru 'more' to prevent scrolling)";
  2254. #else
  2255.           "Print this message";
  2256. #endif /* OS2ORUNIX */
  2257.             arghlp[i] = NULL;
  2258.             break;
  2259.           case 'i':                     /* Treat files as binary */
  2260.             opthlp[i] ="Transfer files in binary mode";
  2261.             arghlp[i] = NULL;
  2262.             break;
  2263. #ifdef TCPSOCKET
  2264.           case 'j':                     /* SET HOST (TCP/IP socket) */
  2265.             opthlp[i] = "Make a TCP connection";
  2266.             arghlp[i] =
  2267.           "TCP host name/address and optional service name or number";
  2268.             break;
  2269. #endif /* TCPSOCKET */
  2270.           case 'k':                     /* receive to stdout */
  2271.             optact[i] = 1;
  2272.             opthlp[i] = "RECEIVE file(s) to standard output";
  2273.             arghlp[i] = NULL;
  2274.             break;
  2275.           case 'l':                     /* SET LINE */
  2276.             opthlp[i] = "Make connection on serial communications device";
  2277.             arghlp[i] = "Serial device name";
  2278.             break;
  2279.           case 'm':                     /* Modem type */
  2280.             opthlp[i] = "Modem type for use with -l device";
  2281.             arghlp[i] = "Modem name as in SET MODEM TYPE command";
  2282.             break;
  2283.           case 'n':                     /* connect after */
  2284.             optact[i] = 1;
  2285.             opthlp[i] = "CONNECT after transferring files";
  2286.             arghlp[i] = NULL;
  2287.             break;
  2288. #ifdef ANYX25
  2289.           case 'o':                     /* X.25 closed user group */
  2290.             opthlp[i] = "X.25 closed user group";
  2291.             arghlp[i] = "User group string";
  2292.             break;
  2293. #endif /* ANYX25 */
  2294.           case 'p':                     /* SET PARITY */
  2295.             opthlp[i] = "Parity";
  2296.             arghlp[i] = "One of the following: even, odd, mark, none, space";
  2297.             break;
  2298.           case 'q':                     /* Quiet */
  2299.             opthlp[i] = "Quiet (suppress most messages)";
  2300.             arghlp[i] = NULL;
  2301.             break;
  2302.           case 'r':                     /* receive */
  2303.             optact[i] = 1;
  2304.             opthlp[i] = "RECEIVE file(s)";
  2305.             arghlp[i] = NULL;
  2306.             break;
  2307.           case 's':                     /* send */
  2308.             optact[i] = 1;
  2309.             opthlp[i] = "SEND file(s)";
  2310.             arghlp[i] = "One or more file specifications";
  2311.             break;
  2312.           case 't':                     /* Line turnaround handshake */
  2313.             opthlp[i] = "XON Turnaround character for half-duplex connections";
  2314.             arghlp[i] = NULL;
  2315.             break;
  2316. #ifdef ANYX25
  2317.           case 'u':                     /* X.25 reverse charge call */
  2318.             opthlp[i] = "X.25 reverse charge call";
  2319.             arghlp[i] = NULL;
  2320.             break;
  2321. #endif /* ANYX25 */
  2322.           case 'v':                     /* Vindow size */
  2323.             opthlp[i] = "Window size";
  2324.             arghlp[i] = "Number, 1 to 32";
  2325.             break;
  2326.           case 'w':                     /* Writeover */
  2327.             opthlp[i] = "Incoming files Write over existing files";
  2328.             arghlp[i] = NULL;
  2329.             break;
  2330.           case 'x':                     /* Server */
  2331.             optact[i] = 1;
  2332.             opthlp[i] = "Be a Kermit SERVER";
  2333.             arghlp[i] = NULL;
  2334.             break;
  2335.           case 'y':                     /* Alternate init-file name */
  2336.             opthlp[i] = "Alternative initialization file";
  2337.             arghlp[i] = "File specification";
  2338.             break;
  2339.           case 'z':                     /* Not background */
  2340.             opthlp[i] = "Force foreground behavior";
  2341.             arghlp[i] = NULL;
  2342.             break;
  2343.           default:
  2344.             opthlp[i] = NULL;
  2345.             arghlp[i] = NULL;
  2346.         }
  2347.     }
  2348.     inixopthlp();
  2349. }
  2350.  
  2351. int
  2352. doxarg(s,pre) char ** s; int pre; {
  2353. #ifdef IKSD
  2354. #ifdef CK_LOGIN
  2355.     extern int ckxsyslog, ckxwtmp, ckxanon;
  2356. #ifdef UNIX
  2357.     extern int ckxpriv;
  2358. #endif /* UNIX */
  2359. #ifdef CK_PERMS
  2360.     extern int ckxperms;
  2361. #endif /* CK_PERMS */
  2362.     extern char * anonfile, * userfile, * anonroot;
  2363. #endif /* CK_LOGIN */
  2364. #ifdef CKWTMP
  2365.     extern char * wtmpfile;
  2366. #endif /* CKWTMP */
  2367. #endif /* IKSD */
  2368.     extern int srvcdmsg;
  2369.     extern char * cdmsgfile[], * cdmsgstr;
  2370.     char tmpbuf[CKMAXPATH+1];
  2371.  
  2372.     int i, x, y, z, havearg = 0;
  2373.     char buf[XARGBUFL], c, * p;
  2374.  
  2375.     if (nxargs < 1)
  2376.       return(-1);
  2377.  
  2378.     c = *(*s + 1);                      /* Hyphen or Plus sign */
  2379.  
  2380.     p = *s + 2;
  2381.     for (i = 0; *p && i < XARGBUFL; i++) {
  2382.         buf[i] = *p++;
  2383.         if (buf[i] == '=' || buf[i] == ':') {
  2384.             havearg = 1;
  2385.             buf[i] = NUL;
  2386.             break;
  2387.         } else if (buf[i] < ' ') {
  2388.             buf[i] = NUL;
  2389.             break;
  2390.         }
  2391.     }
  2392.     if (i > XARGBUFL - 1)
  2393.       return(-1);
  2394.     buf[i] = NUL;
  2395.  
  2396.     x = lookup(xargtab,buf,nxargs,&z);  /* Lookup the option keyword */
  2397.  
  2398.     if (x < 0)                          /* On any kind of error */
  2399.       return(-1);                       /* fail. */
  2400.  
  2401.     /* Handle prescan versus post-initialization file */
  2402.  
  2403.     if (((xargtab[z].flgs & CM_PRE) || (c == '+')) && !pre)
  2404.       return(0);
  2405.     else if (pre && !(xargtab[z].flgs & CM_PRE) && (c != '+'))
  2406.       return(0);
  2407.  
  2408.     /* Ensure that argument is given if and only if required */
  2409.  
  2410.     p = havearg ? *s + i + 3 : NULL;
  2411.  
  2412.     if ((xargtab[z].flgs & CM_ARG) && !havearg)
  2413.       return(-1);
  2414.     else if ((!(xargtab[z].flgs & CM_ARG)) && havearg)
  2415.       return(-1);
  2416.  
  2417.     switch (x) {                        /* OK to process this option... */
  2418. #ifdef CKSYSLOG
  2419.       case XA_SYSL:                     /* IKS: Syslog level */
  2420.         y = 0;
  2421.         if (isdigit(*p)) {
  2422.             while (*p) {
  2423.                 if (*p < '0' || *p > '9')
  2424.                   return(-1);
  2425.                 y = y * 10 + (*p++ - '0');
  2426.             }
  2427.         } else {
  2428.             y = lookup(oktab,p,noktab,&z);
  2429.             if (y > 0) y = SYSLG_DF;    /* Yes = default logging level */
  2430.         }
  2431. #ifndef SYSLOGLEVEL
  2432.         /* If specified on cc command line, user can't change it. */
  2433.         if (!inserver)                  /* Don't allow voluminous syslogging */
  2434.           if (y > SYSLG_FA)             /* by ordinary users. */
  2435.             y = SYSLG_FA;
  2436. #endif /* SYSLOGLEVEL */
  2437.         if (y < 0) return(-1);
  2438. #ifdef DEBUG
  2439.         if (y >= SYSLG_DB)
  2440.           if (!deblog)
  2441.             deblog = debopn("debug.log",0);
  2442. #endif /* DEBUG */
  2443. #ifdef SYSLOGLEVEL
  2444.         /* If specified on cc command line, user can't change it. */
  2445.         y = SYSLOGLEVEL;
  2446. #endif /* SYSLOGLEVEL */
  2447.         ckxsyslog = y;
  2448.         /* printf("ckxsyslog=%d\n",ckxsyslog); */
  2449.         break;
  2450. #endif /* CKSYSLOG */
  2451.  
  2452. #ifdef CK_LOGIN
  2453. #ifdef CKWTMP
  2454.       case XA_WTMP:                     /* IKS: wtmp log */
  2455.         y = lookup(oktab,p,noktab,&z);
  2456.         if (y < 0) return(-1);
  2457.         ckxwtmp = y;
  2458.         /* printf("ckxwtmp=%d\n",ckxwtmp); */
  2459.         break;
  2460.  
  2461.       case XA_WTFI:                     /* IKS: wtmp logfile */
  2462.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2463.           p = tmpbuf;
  2464.         makestr(&wtmpfile,p);
  2465.         /* printf("wtmpfile=%s\n",wtmpfile); */
  2466.         break;
  2467. #endif /* CKWTMP */
  2468.  
  2469.       case XA_ANON:                     /* IKS: Anonymous login allowed */
  2470.         y = lookup(oktab,p,noktab,&z);
  2471.         if (y < 0) return(-1);
  2472.         ckxanon = y;
  2473.         /* printf("ckxanon=%d\n",ckxanon); */
  2474.         break;
  2475.  
  2476. #ifdef UNIX
  2477.       case XA_PRIV:                     /* IKS: Priv'd login allowed */
  2478.         y = lookup(oktab,p,noktab,&z);
  2479.         if (y < 0) return(-1);
  2480.         ckxpriv = y;
  2481.         /* printf("ckxpriv=%d\n",ckxpriv); */
  2482.         break;
  2483. #endif /* UNIX */
  2484.  
  2485. #ifdef CK_PERMS
  2486.       case XA_PERM:                     /* IKS: Anonymous Upload Permissions */
  2487.         y = 0;
  2488.         while (*p) {
  2489.             if (*p < '0' || *p > '7')
  2490.               return(-1);
  2491.             y = y * 8 + (*p++ - '0');
  2492.         }
  2493.         ckxperms = y;
  2494.         /* printf("ckxperms=%04o\n",ckxperms); */
  2495.         break;
  2496. #endif /* CK_PERMS */
  2497.  
  2498.       case XA_ANFI:                     /* Anonymous init file */
  2499.     if (!isabsolute(p))
  2500.       if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2501.         p = tmpbuf;
  2502.         makestr(&anonfile,p);
  2503.         /* printf("anonfile=%s\n",anonfile); */
  2504.         break;
  2505.  
  2506.       case XA_USFI:                     /* IKS: Forbidden user file */
  2507.     if (!isabsolute(p))
  2508.       if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2509.         p = tmpbuf;
  2510.         makestr(&userfile,p);
  2511.         /* printf("userfile=%s\n",userfile); */
  2512.         break;
  2513.  
  2514.       case XA_ROOT:                     /* IKS: Anonymous root */
  2515.     if (!isabsolute(p))
  2516.       if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2517.         p = tmpbuf;
  2518.         makestr(&anonroot,p);
  2519.         /* printf("anonroot=%s\n",anonroot); */
  2520.         break;
  2521. #endif /* CK_LOGIN */
  2522.  
  2523.       case XA_CDFI:                     /* CD filename */
  2524. #ifdef COMMENT
  2525.         /* Do NOT expand this one! */
  2526.         if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2527.           p = tmpbuf;
  2528. #endif /* COMMENT */
  2529.         makelist(p,cdmsgfile,16);
  2530.         makestr(&cdmsgstr,p);
  2531.         /* printf("cdmsgstr=%s\n",cdmsgstr); */
  2532.         break;
  2533.  
  2534.       case XA_CDMS:                     /* CD messages */
  2535.         y = lookup(oktab,p,noktab,&z);
  2536.         if (y < 0) return(-1);
  2537.         srvcdmsg = y;
  2538.         /* printf("srvcdmsg=%d\n",srvcdmsg); */
  2539.         break;
  2540.  
  2541. #ifndef NOXFER
  2542.       case XA_IKLG:                     /* Transfer log on/off */
  2543.         y = lookup(oktab,p,noktab,&z);
  2544.         if (y < 0) return(-1);
  2545.         xferlog = y;
  2546.         /* printf("xferlog=%d\n",xferlog); */
  2547.         break;
  2548.  
  2549.       case XA_IKFI:                     /* Transfer log file */
  2550.     if (!isabsolute(p))
  2551.       if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2552.         p = tmpbuf;
  2553.         makestr(&xferfile,p);
  2554.         xferlog = 1;
  2555.         /* printf("xferfile=%s\n",xferfile); */
  2556.         break;
  2557.  
  2558.       case XA_BAFI:                     /* IKS: banner (greeting) file */
  2559.     if (!isabsolute(p))
  2560.       if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2561.         p = tmpbuf;
  2562.         makestr(&bannerfile,p);
  2563.         /* printf("bannerfile=%s\n",bannerfile); */
  2564.         break;
  2565. #endif /* NOXFER */
  2566.  
  2567. #ifndef NOHELP
  2568.       case XA_HELP:                     /* Help */
  2569.         /* printf("help\n"); */
  2570.         for (i = 0; i <= XA_MAX; i++)
  2571.           if (xopthlp[i])
  2572.             printf("%s\n   %s\n\n",xopthlp[i],xarghlp[i]);
  2573.         if (stayflg || what == W_COMMAND)
  2574.           break;
  2575.         else
  2576.           doexit(GOOD_EXIT,-1);
  2577. #endif /* NOHELP */
  2578.  
  2579. #ifndef NOHELP
  2580.       case XA_HEFI:                     /* IKS: custom help file */
  2581.     if (!isabsolute(p))
  2582.       if (zfnqfp(p,CKMAXPATH,tmpbuf))
  2583.         p = tmpbuf;
  2584.         makestr(&helpfile,p);
  2585.         /* printf("helpfile=%s\n",helpfile); */
  2586.         break;
  2587. #endif /* NOHELP */
  2588.  
  2589. #ifdef CK_LOGIN
  2590.       case XA_TIMO:
  2591.         if (!rdigits(p))
  2592.           return(-1);
  2593.         logintimo = atoi(p);
  2594.         /* printf("logintimo=%d\n",p); */
  2595.         break;
  2596. #endif /* CK_LOGIN */
  2597.  
  2598.       case XA_NOIN:                     /* No interrupts */
  2599. #ifndef NOICP
  2600.         cmdint = 0;
  2601. #endif /* NOICP */
  2602.     xsuspend = 0;
  2603.         break;
  2604.  
  2605. #ifdef UNIX
  2606.       case XA_UNBUF:            /* Unbuffered console i/o*/
  2607.     /* This one is handled in ckcmai.c */
  2608.       break;
  2609. #endif    /* UNIX */
  2610.  
  2611. #ifdef IKSDB
  2612.       case XA_DBFI: {
  2613.           extern char * dbdir, * dbfile;
  2614.           extern int dbenabled;
  2615.           struct zfnfp * zz;
  2616.           if ((zz = zfnqfp(p,CKMAXPATH,tmpbuf))) {
  2617.           char *s, *s2 = NULL;
  2618.               makestr(&dbdir,zz->fpath);
  2619.               makestr(&dbfile,zz->fpath);
  2620.           for (s = dbdir; *s; s++) {
  2621.           if (ISDIRSEP(*s))
  2622.             s2 = s+1;
  2623.           }
  2624.           if (s2) *s2 = NUL;
  2625.           debug(F110,"XA_DBFI dbdir",dbdir,0);
  2626.           debug(F110,"XA_DBFI dbfile",dbfile,0);
  2627.               dbenabled = 1;
  2628.           }
  2629.           break;
  2630.       }
  2631.       case XA_DBAS: {
  2632.           extern int dbenabled;
  2633.           y = lookup(oktab,p,noktab,&z);
  2634.           if (y < 0) return(-1);
  2635.           dbenabled = y;
  2636.           break;
  2637.       }
  2638. #endif /* IKSDB */
  2639.  
  2640.       case XA_VERS: {
  2641.       extern char * ck_s_ver, * ck_s_xver;
  2642.       printf("%s",ck_s_ver);
  2643.       if (*ck_s_xver)
  2644.         printf(" [%s]\n",ck_s_xver);
  2645.       printf("\n");
  2646.       if (stayflg || what == W_COMMAND)
  2647.         break;
  2648.       else
  2649.         doexit(GOOD_EXIT,-1);
  2650.       }
  2651. #ifndef NOXFER
  2652. #ifdef CK_PERMS
  2653.       case XA_NPRM: {
  2654.       extern int atlpri, atlpro, atgpri, atgpro;
  2655.       atlpri = 0;
  2656.       atlpro = 0;
  2657.       atgpri = 0;
  2658.       atgpro = 0;
  2659.       break;
  2660.       }
  2661. #endif /* CK_PERMS */
  2662. #endif /* NOXFER */
  2663.  
  2664. #ifdef KUI
  2665.       case XA_SCALE:
  2666.         kui_init.resizeMode = 1;
  2667.         break;
  2668.       case XA_CHGD:
  2669.         kui_init.resizeMode = 2;
  2670.         break;
  2671.       case XA_WMAX:
  2672.         kui_init.nCmdShow = SW_MAXIMIZE;
  2673.         break;
  2674.       case XA_WMIN:
  2675.         kui_init.nCmdShow = SW_MINIMIZE;
  2676.         break;
  2677.  
  2678.       case XA_XPOS:
  2679.         if (!rdigits(p))
  2680.           return(-1);
  2681.     kui_init.pos_init++;
  2682.     kui_init.pos_x = atoi(p);
  2683.         break;
  2684.  
  2685.       case XA_YPOS:
  2686.         if (!rdigits(p))
  2687.           return(-1);
  2688.     kui_init.pos_init++;
  2689.     kui_init.pos_y = atoi(p);
  2690.         break;
  2691.  
  2692.       case XA_FNAM: {
  2693.       extern struct _kui_init kui_init;
  2694.       extern struct keytab * term_font;
  2695.       extern struct keytab * _term_font;
  2696.       extern int tt_font, ntermfont;
  2697.       int x, z;
  2698.       if (ntermfont == 0)
  2699.         BuildFontTable(&term_font, &_term_font, &ntermfont);
  2700.       if (!(term_font && _term_font && ntermfont > 0)) {
  2701.             printf("?Unable to construct Font Facename Table\n");
  2702.         return(0);
  2703.           }
  2704.       x = lookup(term_font,p,ntermfont,&z);
  2705.       if (x < 0) {
  2706.               x = lookup(_term_font,p,ntermfont,&z);
  2707.               if (x < 0) {
  2708.                   printf("?Invalid Font Facename: %s\n",p);
  2709.                   return(0);
  2710.               }
  2711.           }
  2712.       tt_font = x;
  2713.       kui_init.face_init++;
  2714.       makestr(&kui_init.facename,term_font[z].kwd);
  2715.       break;
  2716.       }
  2717.       case XA_FSIZ: {
  2718.       extern struct _kui_init kui_init;
  2719.       extern int tt_font_size;
  2720.           char * q;
  2721.           int halfpoint = 0;
  2722.  
  2723.       kui_init.font_init++;
  2724.           for ( q=p ; *q ; q++ ) {
  2725.               if ( *q == '.') {
  2726.                   *q++ = '\0';
  2727.                   if (!rdigits(q))
  2728.                       return(-1);
  2729.                   if (!*q || atoi(q) == 0)
  2730.                       break;    /* no halfpoint */
  2731.                   halfpoint = 1;
  2732.                   if (atoi(q) != 5)
  2733.                 printf("? Font sizes are treated in half-point increments\n");
  2734.                   break;
  2735.               }
  2736.           }
  2737.       if (!rdigits(p))
  2738.         return(-1);
  2739.       tt_font_size = kui_init.font_size = 2 * atoi(p) + halfpoint;
  2740.       break;
  2741.       }
  2742.       case XA_NOMN:
  2743.         kui_init.nomenubar = 1;
  2744.         break;
  2745.       case XA_NOTB:
  2746.         kui_init.notoolbar = 1;
  2747.         break;
  2748.       case XA_NOSB:
  2749.         kui_init.nostatusbar = 1;
  2750.         break;
  2751.       case XA_NOBAR:
  2752.         kui_init.nomenubar = 1;
  2753.         kui_init.notoolbar = 1;
  2754.         kui_init.nostatusbar = 1;
  2755.         break;
  2756. #endif /* KUI */
  2757.  
  2758. #ifndef NOPUSH
  2759.     case XA_NOPUSH:
  2760.         nopush = 1;
  2761.         break;
  2762. #endif /* NOPUSH */
  2763. #ifdef OS2
  2764.     case XA_LOCK:
  2765.         tt_scroll = 0;
  2766.         tt_escape = 0;
  2767. #ifndef NOPUSH
  2768.         nopush = 1;
  2769. #endif
  2770. #ifdef KUI
  2771.         kui_init.nomenubar = 1;
  2772.         kui_init.notoolbar = 1;
  2773.         kui_init.nostatusbar = 1;
  2774. #endif
  2775.         break;
  2776. #ifdef KUI
  2777.     case XA_NOCLOSE:
  2778.         kui_init.noclose = 1;
  2779.         break;
  2780. #endif /* KUI */
  2781.     case XA_NOSCROLL:
  2782.         tt_scroll = 0;
  2783.         break;
  2784.     case XA_NOESCAPE:
  2785.         tt_escape = 0;
  2786.         break;
  2787. #endif /* OS2 */
  2788.  
  2789. #ifndef NOLOCAL
  2790.       case XA_TERM: {            /* Terminal type */
  2791.           extern struct keytab ttyptab[];
  2792.           extern int nttyp;
  2793. #ifdef TNCODE
  2794.       extern char * tn_term;
  2795. #endif /* TNCODE */
  2796. #ifdef OS2
  2797.       int x, z;
  2798.       extern int tt_type, tt_type_mode;
  2799.       x = lookup(ttyptab,p,nttyp,&z);
  2800.       if (x < 0)
  2801.         return(-1);
  2802.       tt_type_mode = tt_type = x;
  2803. #endif /* OS2 */
  2804. #ifdef TNCODE
  2805.       makestr(&tn_term,p);
  2806. #endif /* TNCODE */
  2807.       break;
  2808.       }
  2809.       case XA_CSET: {            /* Remote Character Set */
  2810. #ifndef NOCSETS
  2811. #ifdef CKOUNI
  2812.           extern struct keytab txrtab[];
  2813.           extern int ntxrtab;
  2814.           x = lookup(txrtab,p,ntxrtab,&z);
  2815. #else /* CKOUNI */
  2816.           extern struct keytab ttcstab[];
  2817.           extern int ntermc;
  2818.           x = lookup(ttcstab,p,ntermc,&z);
  2819. #endif /* CKOUNI */
  2820.       if (x < 0)
  2821.         return(-1);
  2822.           setremcharset(z,4 /* TT_GR_ALL (in ckuus7.c) */);
  2823. #else /* NOCSETS */
  2824.           return(-1);
  2825. #endif /* NOCSETS */
  2826.       break;
  2827.       }
  2828.       case XA_ROWS: {            /* Screen rows (height) */
  2829. #ifdef OS2
  2830.           extern int row_init;
  2831. #else /* OS2 */
  2832.       extern int tt_rows;
  2833. #endif /* OS2 */
  2834.       if (!rdigits(p))
  2835.         return(-1);
  2836. #ifdef OS2
  2837.       if (!os2_settermheight(atoi(p)))
  2838.         return(-1);
  2839.           row_init++;
  2840. #else  /* Not OS/2 */
  2841.       tt_rows = atoi(p);
  2842. #endif /* OS2 */
  2843.       break;
  2844.       }
  2845.       case XA_COLS: {            /* Screen columns (width) */
  2846. #ifdef OS2
  2847.           extern int col_init;
  2848. #else /* OS2 */
  2849.       extern int tt_cols;
  2850. #endif /* OS2 */
  2851.       if (!rdigits(p))
  2852.         return(-1);
  2853. #ifdef OS2
  2854.       if (!os2_settermwidth(atoi(p)))
  2855.         return(-1);
  2856.           col_init++;
  2857. #else  /* Not OS/2 */
  2858.       tt_cols = atoi(p);
  2859. #endif /* OS2 */
  2860.       break;
  2861.       }
  2862. #ifdef OS2
  2863.     case XA_TITL: {
  2864.         extern char usertitle[];
  2865.         ckstrncpy(usertitle,p,64);
  2866.         os2settitle("",1);
  2867.         break;
  2868.     }
  2869. #endif /* OS2 */
  2870.  
  2871. #ifdef COMMENT                /* TO BE FILLED IN ... */
  2872.       case XA_TEL:            /* Make a Telnet connection */
  2873.       case XA_FTP:            /* Make an FTP connection */
  2874.       case XA_SSH:            /* Make an SSH connection */
  2875. #endif /* COMMENT */
  2876.  
  2877. #ifndef NOSPL
  2878.       case XA_USER:            /* Username for login */
  2879. #ifdef IKSD
  2880.     if (!inserver)
  2881. #endif /* IKSD */
  2882.     {
  2883.         ckstrncpy(uidbuf,*xargv,UIDBUFLEN);
  2884.         haveftpuid = 1;
  2885.     }
  2886.     break;
  2887. #endif /* NOSPL */
  2888. #endif /* NOLOCAL */
  2889.  
  2890.       default:
  2891.         return(-1);
  2892.     }
  2893.     return(0);
  2894. }
  2895.  
  2896. #ifdef IKSD
  2897. #ifdef IKSDCONF
  2898. #define IKS_ANON 0
  2899. #define IKS_BAFI 1
  2900. #define IKS_CDFI 2
  2901. #define IKS_CDMS 3
  2902. #define IKS_HEFI 4
  2903. #define IKS_ANFI 5
  2904. #define IKS_USFI 6
  2905. #define IKS_IKLG 7
  2906. #define IKS_IKFI 8
  2907. #define IKS_DBAS 9
  2908. #define IKS_DBFI 10
  2909. #define IKS_PERM 11
  2910. #define IKS_PRIV 12
  2911. #define IKS_ROOT 13
  2912. #define IKS_TIMO 14
  2913. #define IKS_WTFI 15
  2914. #define IKS_WTMP 16
  2915. #define IKS_SRVR 17
  2916. #define IKS_NOIN 18
  2917. #define IKS_INIT 19
  2918. #define IKS_ANLG 20
  2919. #define IKS_ACCT 21
  2920. #define IKS_NTDOM 22
  2921. #define IKS_SYSL 23
  2922.  
  2923. #ifdef CK_LOGIN
  2924. static struct keytab iksantab[] = {
  2925. #ifdef OS2
  2926.     { "account",     IKS_ACCT, 0 },
  2927. #endif /* OS2 */
  2928.     { "initfile",    IKS_ANFI, 0 },
  2929.     { "login",       IKS_ANLG, 0 },
  2930. #ifdef UNIX
  2931.     { "root",        IKS_ROOT, 0 },
  2932. #else
  2933. #ifdef CKROOT
  2934.     { "root",        IKS_ROOT, 0 },
  2935. #endif /* CKROOT */
  2936. #endif /* UNIX */
  2937.     { "", 0, 0 }
  2938. };
  2939. static int niksantab = sizeof(iksantab) / sizeof(struct keytab) - 1;
  2940. #endif /* CK_LOGIN */
  2941.  
  2942. static struct keytab ikstab[] = {
  2943. #ifdef CK_LOGIN
  2944.     { "anonymous",   IKS_ANON, 0 },
  2945. #endif /* CK_LOGIN */
  2946.     { "bannerfile",  IKS_BAFI, 0 },
  2947.     { "cdfile",      IKS_CDFI, 0 },
  2948.     { "cdmessage",   IKS_CDMS, 0 },
  2949.     { "cdmsg",       IKS_CDMS, CM_INV },
  2950. #ifdef IKSDB
  2951.     { "database",    IKS_DBAS, 0 },
  2952.     { "dbfile",      IKS_DBFI, 0 },
  2953. #endif /* IKSDB */
  2954. #ifdef CK_LOGIN
  2955. #ifdef NT
  2956.     { "default-domain", IKS_NTDOM, 0 },
  2957. #endif /* NT */
  2958. #endif /* CK_LOGIN */
  2959. #ifndef NOHELP
  2960.     { "helpfile",    IKS_HEFI, 0 },
  2961. #endif /* NOHELP */
  2962.     { "initfile",    IKS_INIT, 0 },
  2963.     { "no-initfile", IKS_NOIN, 0 },
  2964. #ifdef CK_LOGIN
  2965. #ifdef CK_PERM
  2966.     { "permissions", IKS_PERM, 0 },
  2967.     { "perms",       IKS_PERM, CM_INV },
  2968. #endif /* CK_PERM */
  2969. #ifdef UNIX
  2970.     { "privid",      IKS_PRIV, 0 },
  2971. #endif /* UNIX */
  2972.     { "server-only", IKS_SRVR, 0 },
  2973. #ifdef CKSYSLOG
  2974.     { "syslog",      IKS_SYSL, 0 },
  2975. #endif /* CKSYSLOG */
  2976.     { "timeout",     IKS_TIMO, 0 },
  2977.     { "userfile",    IKS_USFI, 0 },
  2978. #ifdef CKWTMP
  2979.     { "wtmpfile",    IKS_WTFI, 0 },
  2980.     { "wtmplog",     IKS_WTMP, 0 },
  2981. #endif /* CKWTMP */
  2982. #endif /* CK_LOGIN */
  2983.     { "xferfile",    IKS_IKFI, 0 },
  2984.     { "xferlog",     IKS_IKLG, 0 }
  2985. };
  2986. static int nikstab = sizeof(ikstab) / sizeof(struct keytab);
  2987. #endif /* IKSDCONF */
  2988.  
  2989. #ifndef NOICP
  2990. int
  2991. setiks() {                /* SET IKS */
  2992. #ifdef IKSDCONF
  2993. #ifdef CK_LOGIN
  2994.     extern int ckxsyslog, ckxwtmp, ckxanon;
  2995. #ifdef UNIX
  2996.     extern int ckxpriv;
  2997. #endif /* UNIX */
  2998. #ifdef CK_PERMS
  2999.     extern int ckxperms;
  3000. #endif /* CK_PERMS */
  3001.     extern char * anonfile, * userfile, * anonroot;
  3002. #ifdef OS2
  3003.     extern char * anonacct;
  3004. #endif /* OS2 */
  3005. #ifdef NT
  3006.     extern char * iks_domain;
  3007. #endif /* NT */
  3008. #endif /* CK_LOGIN */
  3009. #ifdef CKWTMP
  3010.     extern char * wtmpfile;
  3011. #endif /* CKWTMP */
  3012.     extern int srvcdmsg, success, iksdcf, rcflag, noinit, arg_x;
  3013.     extern char * cdmsgfile[], * cdmsgstr, *kermrc;
  3014.     extern xx_strp xxstring;
  3015.     int x, y, z;
  3016.     char *s;
  3017.     char tmpbuf[CKMAXPATH+1];
  3018.  
  3019.     if ((y = cmkey(ikstab,nikstab,"","",xxstring)) < 0)
  3020.       return(y);
  3021.  
  3022. #ifdef CK_LOGIN
  3023.     if (y == IKS_ANON) {
  3024.         if ((y = cmkey(iksantab,niksantab,"","",xxstring)) < 0)
  3025.       return(y);
  3026.     }
  3027. #endif /* CK_LOGIN */
  3028.  
  3029.     switch (y) {
  3030. #ifdef CKSYSLOG
  3031.       case IKS_SYSL:                     /* IKS: Syslog level */
  3032.         if ((z = cmkey(oktab,noktab,"","",xxstring)) < 0)
  3033.       return(z);
  3034.         if ((x = cmcfm()) < 0) return(x);
  3035.         if (iksdcf) return(success = 0);
  3036. #ifndef SYSLOGLEVEL
  3037.         /* If specified on cc command line, user can't change it. */
  3038.         if (!inserver)                  /* Don't allow voluminous syslogging */
  3039.           if (y > SYSLG_FA)             /* by ordinary users. */
  3040.             y = SYSLG_FA;
  3041. #endif /* SYSLOGLEVEL */
  3042.         if (y < 0) return(-1);
  3043. #ifdef DEBUG
  3044.         if (y >= SYSLG_DB)
  3045.           if (!deblog)
  3046.             deblog = debopn("debug.log",0);
  3047. #endif /* DEBUG */
  3048. #ifdef SYSLOGLEVEL
  3049.         /* If specified on cc command line, user can't change it. */
  3050.         y = SYSLOGLEVEL;
  3051. #endif /* SYSLOGLEVEL */
  3052.         ckxsyslog = y;
  3053.         /* printf("ckxsyslog=%d\n",ckxsyslog); */
  3054.         break;
  3055. #endif /* CKSYSLOG */
  3056.  
  3057. #ifdef CK_LOGIN
  3058. #ifdef NT
  3059.       case IKS_NTDOM:
  3060.         if ((z = cmtxt(
  3061.  "DOMAIN to be used for user authentication when none is specified",
  3062.                        "", &s,xxstring)) < 0)
  3063.       return(z);
  3064.         if (iksdcf) return(success = 0);
  3065.         if (!*s) s= NULL;
  3066.           makestr(&iks_domain,s);
  3067.         break;
  3068. #endif /* NT */
  3069. #ifdef OS2
  3070.       case IKS_ACCT:
  3071.         if ((z = cmtxt("Name of local account to use for anonymous logins",
  3072.             "GUEST", &s,xxstring)) < 0)
  3073.       return(z);
  3074.         if (iksdcf) return(success = 0);
  3075.         if (*s) {
  3076.             makestr(&anonacct,s);
  3077.         } else if ( anonacct ) {
  3078.         free(anonacct);
  3079.         anonacct = NULL;
  3080.     }
  3081.         break;
  3082. #endif /* OS2 */
  3083.       case IKS_ANLG:
  3084.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  3085.       return(z);
  3086.         if ((x = cmcfm()) < 0) return(x);
  3087.         if (iksdcf) return(success = 0);
  3088.         ckxanon = z;
  3089. #ifdef OS2
  3090.     if (ckxanon && !anonacct)
  3091.       makestr(&anonacct,"GUEST");
  3092. #endif /* OS2 */
  3093.         break;
  3094. #endif /* CK_LOGIN */
  3095.       case IKS_BAFI:
  3096.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  3097.       return(z);
  3098.         if (x) {
  3099.             printf("?Wildcards not allowed\n");
  3100.             return(-9);
  3101.         }
  3102.         debug(F110,"bannerfile before zfnqfp()",s,0);
  3103.         if (zfnqfp(s,CKMAXPATH,tmpbuf)) {
  3104.             debug(F110,"bannerfile after zfnqfp()",tmpbuf,0);
  3105.             s = tmpbuf;
  3106.         }
  3107.         if ((x = cmcfm()) < 0) return(x);
  3108.         if (iksdcf) return(success = 0);
  3109.         if (*s)
  3110.       makestr(&bannerfile,s);
  3111.         break;
  3112.       case IKS_CDFI:
  3113.         if ((z = cmtxt("list of cd message file names","READ.ME",
  3114.                &s,xxstring)) < 0)
  3115.       return(z);
  3116.         if (iksdcf) return(success = 0);
  3117.         if (*s) {
  3118.             makelist(s,cdmsgfile,16);
  3119.             makestr(&cdmsgstr,s);
  3120.         }
  3121.         break;
  3122.       case IKS_CDMS:
  3123.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  3124.       return(z);
  3125.         if ((x = cmcfm()) < 0) return(x);
  3126.         if (iksdcf) return(success = 0);
  3127.         srvcdmsg = z;
  3128.         break;
  3129.       case IKS_HEFI:
  3130.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  3131.       return(z);
  3132.         if (x) {
  3133.             printf("?Wildcards not allowed\n");
  3134.             return(-9);
  3135.         }
  3136.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  3137.           s = tmpbuf;
  3138.         if ((x = cmcfm()) < 0) return(x);
  3139.         if (iksdcf) return(success = 0);
  3140.         if (*s)
  3141.       makestr(&helpfile,s);
  3142.         break;
  3143.       case IKS_ANFI:
  3144.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  3145.       return(z);
  3146.         if (x) {
  3147.             printf("?Wildcards not allowed\n");
  3148.             return(-9);
  3149.         }
  3150.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  3151.           s = tmpbuf;
  3152.         if ((x = cmcfm()) < 0) return(x);
  3153.         if (iksdcf) return(success = 0);
  3154.         if (*s)
  3155.       makestr(&anonfile,s);
  3156.         break;
  3157.       case IKS_USFI:
  3158.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  3159.       return(z);
  3160.         if (x) {
  3161.             printf("?Wildcards not allowed\n");
  3162.             return(-9);
  3163.         }
  3164.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  3165.           s = tmpbuf;
  3166.         if ((x = cmcfm()) < 0) return(x);
  3167.         if (iksdcf) return(success = 0);
  3168.         if (*s)
  3169.       makestr(&userfile,s);
  3170.         break;
  3171.       case IKS_IKFI:
  3172.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  3173.       return(z);
  3174.         if (x) {
  3175.             printf("?Wildcards not allowed\n");
  3176.             return(-9);
  3177.         }
  3178.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  3179.           s = tmpbuf;
  3180.         if ((x = cmcfm()) < 0) return(x);
  3181.         if (iksdcf) return(success = 0);
  3182.         if (*s) {
  3183.             makestr(&xferfile,s);
  3184.             xferlog = 1;
  3185.         }
  3186.         break;
  3187.       case IKS_IKLG:
  3188.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  3189.       return(z);
  3190.         if ((x = cmcfm()) < 0) return(x);
  3191.         if (iksdcf) return(success = 0);
  3192.         xferlog = z;
  3193.         break;
  3194.  
  3195. #ifdef CK_LOGIN
  3196. #ifdef CK_PERM
  3197.       case IKS_PERM:
  3198.         if ((z = cmtxt("Octal file permssion code","000",
  3199.                &s,xxstring)) < 0)
  3200.       return(z);
  3201.     if (z < 0) return(z);
  3202.         if (iksdcf) return(success = 0);
  3203.         y = 0;
  3204.         while (*s) {
  3205.             if (*s < '0' || *s > '7')
  3206.               return(-9);
  3207.             y = y * 8 + (*s++ - '0');
  3208.         }
  3209.         ckxperms = y;
  3210.         break;
  3211. #endif /* CK_PERM */
  3212. #ifdef UNIX
  3213.       case IKS_PRIV:                     /* IKS: Priv'd login allowed */
  3214.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  3215.       return(z);
  3216.         if ((x = cmcfm()) < 0) return(x);
  3217.         if (iksdcf) return(success = 0);
  3218.         ckxpriv = z;
  3219.         break;
  3220. #endif /* UNIX */
  3221.  
  3222.       case IKS_ROOT:                     /* IKS: Anonymous root */
  3223.     if ((z = cmdir("Name of disk and/or directory","",&s,
  3224.                xxstring)) < 0 ) {
  3225.         if (z != -3)
  3226.           return(z);
  3227.     }
  3228.         if (*s) {
  3229.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  3230.           s = tmpbuf;
  3231.         } else
  3232.       s = "";
  3233.         if ((x = cmcfm()) < 0) return(x);
  3234.         if (iksdcf) return(success = 0);
  3235.         if (*s)
  3236.       makestr(&anonroot,s);
  3237.         /* printf("anonroot=%s\n",anonroot); */
  3238.         break;
  3239.  
  3240.       case IKS_TIMO:
  3241.     z = cmnum("login timeout, seconds","0",10,&x,xxstring);
  3242.     if (z < 0) return(z);
  3243.         if (x < 0 || x > 7200) {
  3244.             printf("?Value must be between 0 and 7200\r\n");
  3245.             return(-9);
  3246.         }
  3247.         if ((z = cmcfm()) < 0) return(z);
  3248.         if (iksdcf) return(success = 0);
  3249.         logintimo = x;
  3250.         break;
  3251.  
  3252. #ifdef CKWTMP
  3253.       case IKS_WTMP:                     /* IKS: wtmp log */
  3254.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  3255.       return(z);
  3256.         if ((x = cmcfm()) < 0) return(x);
  3257.         if (iksdcf) return(success = 0);
  3258.         ckxwtmp = z;
  3259.         break;
  3260.  
  3261.       case IKS_WTFI:                     /* IKS: wtmp logfile */
  3262.         if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  3263.       return(z);
  3264.         if (x) {
  3265.             printf("?Wildcards not allowed\n");
  3266.             return(-9);
  3267.         }
  3268.         if (zfnqfp(s,CKMAXPATH,tmpbuf))
  3269.           s = tmpbuf;
  3270.         if ((x = cmcfm()) < 0) return(x);
  3271.         if (iksdcf) return(success = 0);
  3272.         if (*s)
  3273.       makestr(&wtmpfile,s);
  3274.         break;
  3275. #endif /* CKWTMP */
  3276. #endif /* CK_LOGIN */
  3277. #ifdef IKSDB
  3278.       case IKS_DBFI: {
  3279.           extern char * dbdir, * dbfile;
  3280.           extern int dbenabled;
  3281.           struct zfnfp * zz;
  3282.           if ((z = cmifi("Filename","",&s,&x,xxstring)) < 0)
  3283.         return(z);
  3284.           if (x) {
  3285.               printf("?Wildcards not allowed\n");
  3286.               return(-9);
  3287.           }
  3288.           zz = zfnqfp(s,CKMAXPATH,tmpbuf);
  3289.           if ((x = cmcfm()) < 0) return(x);
  3290.           if (iksdcf) return(success = 0);
  3291.           if (zz) {
  3292.               makestr(&dbdir,zz->fpath);
  3293.               makestr(&dbfile,(char *)tmpbuf);
  3294.               dbenabled = 1;
  3295.           } else
  3296.         return(success = 0);
  3297.           break;
  3298.       }
  3299.       case IKS_DBAS: {
  3300.           extern int dbenabled;
  3301.           if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  3302.         return(z);
  3303.           if ((x = cmcfm()) < 0) return(x);
  3304.           if (iksdcf) return(success = 0);
  3305.           dbenabled = z;
  3306.           break;
  3307.       }
  3308. #endif /* IKSDB */
  3309.  
  3310.       case IKS_INIT:
  3311.         if ((z = cmtxt("Alternate init file specification","",
  3312.                &s,xxstring)) < 0)
  3313.       return(z);
  3314.         if (z < 0) return(z);
  3315.         if (iksdcf) return(success = 0);
  3316.         ckstrncpy(kermrc,s,KERMRCL);
  3317.         rcflag = 1;            /* Flag that this has been done */
  3318.         break;
  3319.  
  3320.       case IKS_NOIN:
  3321.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  3322.       return(z);
  3323.         if ((x = cmcfm()) < 0) return(x);
  3324.         if (iksdcf) return(success = 0);
  3325.         noinit = z;
  3326.         break;
  3327.  
  3328.       case IKS_SRVR:
  3329.         if ((z = cmkey(oktab,noktab,"","no",xxstring)) < 0)
  3330.       return(z);
  3331.         if ((x = cmcfm()) < 0) return(x);
  3332.         if (iksdcf) return(success = 0);
  3333.         arg_x = z;
  3334.         break;
  3335.  
  3336.       default:
  3337.         return(-9);
  3338.     }
  3339.     return(success = (inserver ? 1 : 0));
  3340. #else /* IKSDCONF */
  3341.     if ((x = cmcfm()) < 0)
  3342.       return(x);
  3343.     return(success = 0);
  3344. #endif /* IKSDCONF */
  3345. }
  3346. #endif /* NOICP */
  3347. #endif /* IKSD */
  3348.  
  3349. /*  D O A R G  --  Do a command-line argument.  */
  3350.  
  3351. int
  3352. #ifdef CK_ANSIC
  3353. doarg(char x)
  3354. #else
  3355. doarg(x) char x;
  3356. #endif /* CK_ANSIC */
  3357. /* doarg */ {
  3358.     int i, n, y, z, xx; long zz; char *xp;
  3359.  
  3360. #ifdef NETCONN
  3361. extern char *line, *tmpbuf;             /* Character buffers for anything */
  3362. #endif /* NETCONN */
  3363.  
  3364. #ifdef IKSD
  3365.     /* Internet Kermit Server set some way besides -A... */
  3366.     if (inserver)
  3367.       dofast();
  3368. #endif /* IKSD */
  3369.  
  3370.     xp = *xargv+1;                      /* Pointer for bundled args */
  3371.     debug(F111,"doarg entry",xp,xargc);
  3372.     while (x) {
  3373.         debug(F000,"doarg arg","",x);
  3374.         switch (x) {                    /* Big switch on arg */
  3375.  
  3376. #ifndef COMMENT
  3377.       case '-':            /* Extended commands... */
  3378.         if (doxarg(xargv,0) < 0) {
  3379.         XFATAL("Extended option error");
  3380.         } /* Full thru... */
  3381.       case '+':            /* Extended command for prescan() */
  3382.         return(0);
  3383. #else  /* NOICP */
  3384.       case '-':
  3385.       case '+':
  3386.         XFATAL("Extended options not configured");
  3387. #endif /* NOICP */
  3388.  
  3389. #ifndef NOSPL
  3390.       case 'C': {            /* Commands for parser */
  3391.           char * s;
  3392.           xargv++, xargc--;
  3393.           if ((xargc < 1) || (**xargv == '-')) {
  3394.           XFATAL("No commands given for -C");
  3395.           }
  3396.           s = *xargv;        /* Get the argument (must be quoted) */
  3397.           if (!*s)            /* If empty quotes */
  3398.         s = NULL;        /* ignore this option */
  3399.           if (s) {
  3400.           makestr(&clcmds,s);    /* Make pokeable copy */
  3401.           s = clcmds;        /* Change tabs to spaces */
  3402.           while (*s) {
  3403.               if (*s == '\t') *s = ' ';
  3404.               s++;
  3405.           }
  3406.           }
  3407.           break;
  3408.       }
  3409. #endif /* NOSPL */
  3410.  
  3411. #ifndef NOXFER
  3412.       case 'D':            /* Delay */
  3413.         if (*(xp+1)) {
  3414.         XFATAL("invalid argument bundling");
  3415.         }
  3416.         xargv++, xargc--;
  3417.         if ((xargc < 1) || (**xargv == '-')) {
  3418.         XFATAL("missing delay value");
  3419.         }
  3420.         z = atoi(*xargv);        /* Convert to number */
  3421.         if (z > -1)            /* If in range */
  3422.           ckdelay = z;        /* set it */
  3423.         else {
  3424.         XFATAL("bad delay value");
  3425.         }
  3426.         break;
  3427. #endif /* NOXFER */
  3428.  
  3429.       case 'E':            /* Exit on close */
  3430. #ifdef NETCONN
  3431.         tn_exit = 1;
  3432. #endif /* NETCONN */
  3433.         exitonclose = 1;
  3434.         break;
  3435.  
  3436. #ifndef NOICP
  3437.       case 'S':            /* "Stay" - enter interactive */
  3438.         stayflg = 1;        /* command parser after executing */
  3439.         xfinish = 0;        /* command-line actions. */
  3440.         break;
  3441. #endif /* NOICP */
  3442.  
  3443.       case 'T':            /* File transfer mode = text */
  3444.         binary = XYFT_T;
  3445.         xfermode = XMODE_M;        /* Transfer mode manual */
  3446.         filepeek = 0;
  3447. #ifdef PATTERNS
  3448.         patterns = 0;
  3449. #endif /* PATTERNS */
  3450.         break;
  3451.  
  3452.       case '7':
  3453.         break;
  3454.  
  3455. #ifdef IKSD
  3456.       case 'A': {            /* Internet server */
  3457.           /* Already done in prescan() */
  3458.           /* but implies 'x' &&  'Q'   */
  3459. #ifdef OS2
  3460.           char * p;
  3461.           if (*(xp+1)) {
  3462.           XFATAL("invalid argument bundling");
  3463.           }
  3464. #ifdef NT
  3465.           /* Support for Pragma Systems Telnet/Terminal Servers */
  3466.           p = getenv("PRAGMASYS_INETD_SOCK");
  3467.           if (!(p && atoi(p) != 0)) {
  3468.           xargv++, xargc--;
  3469.           if (xargc < 1 || **xargv == '-') {
  3470.               XFATAL("missing socket handle");
  3471.           }
  3472.           }
  3473. #else /* NT */
  3474.           xargv++, xargc--;
  3475.           if (xargc < 1 || **xargv == '-') {
  3476.           XFATAL("missing socket handle");
  3477.           }
  3478. #endif /* NT */
  3479. #endif /* OS2 */
  3480. #ifdef NOICP                            /* If no Interactive Command Parser */
  3481.           action = 'x';        /* -A implies -x. */
  3482. #endif /* NOICP */
  3483. #ifndef NOXFER
  3484.           dofast();
  3485. #endif /* NOXFER */
  3486.           break;
  3487.       }
  3488. #endif /* IKSD */
  3489.  
  3490. #ifndef NOXFER
  3491.       case 'Q':            /* Quick (i.e. FAST) */
  3492.         dofast();
  3493.         break;
  3494. #endif /* NOXFER */
  3495.  
  3496.       case 'R':            /* Remote-Only */
  3497.         break;            /* This is handled in prescan(). */
  3498.  
  3499. #ifndef NOSERVER
  3500.       case 'x':            /* server */
  3501.       case 'O':            /* (for One command only) */
  3502.         if (action) {
  3503.         XFATAL("conflicting actions");
  3504.         }
  3505.         if (x == 'O') justone = 1;
  3506.         xfinish = 1;
  3507.         action = 'x';
  3508.         break;
  3509. #endif /* NOSERVER */
  3510.  
  3511. #ifndef NOXFER
  3512.       case 'f':            /* finish */
  3513.         if (action) {
  3514.         XFATAL("conflicting actions");
  3515.         }
  3516.         action = setgen('F',"","","");
  3517.         break;
  3518. #endif /* NOXFER */
  3519.  
  3520.       case 'r': {            /* receive */
  3521.           if (action) {
  3522.           XFATAL("conflicting actions");
  3523.           }
  3524.           action = 'v';
  3525.           break;
  3526.       }
  3527.  
  3528. #ifndef NOXFER
  3529.       case 'k':            /* receive to stdout */
  3530.         if (action) {
  3531.         XFATAL("conflicting actions");
  3532.         }
  3533.         stdouf = 1;
  3534.         action = 'v';
  3535.         break;
  3536.  
  3537.       case 's': {            /* send */
  3538.           int fil2snd, rc;
  3539.           if (!recursive)
  3540.           nolinks = 0;        /* Follow links by default */
  3541.  
  3542.           if (action) {
  3543.           XFATAL("conflicting actions");
  3544.           }
  3545.           if (*(xp+1)) {
  3546.           XFATAL("invalid argument bundling after -s");
  3547.           }
  3548.           nfils = 0;        /* Initialize file counter */
  3549.           fil2snd = 0;        /* Assume nothing to send  */
  3550.           z = 0;            /* Flag for stdin */
  3551.           cmlist = xargv + 1;    /* Remember this pointer */
  3552.           while (++xargv, --xargc > 0) { /* Traverse the list */
  3553. #ifdef PIPESEND
  3554.           if (usepipes && protocol == PROTO_K && **xargv == '!') {
  3555.               cmarg = *xargv;
  3556.               cmarg++;
  3557.               debug(F110,"doarg pipesend",cmarg,0);
  3558.               nfils = -1;
  3559.               z = 1;
  3560.               pipesend = 1;
  3561.           } else
  3562. #endif /* PIPESEND */
  3563.             if (**xargv == '-') { /* Check for sending stdin */
  3564.             if (strcmp(*xargv,"-") != 0) /* next option? */
  3565.               break;
  3566.             z++;        /* "-" alone means send from stdin. */
  3567. #ifdef RECURSIVE
  3568.             } else if (!strcmp(*xargv,".")) {
  3569.             fil2snd = 1;
  3570.             nfils++;
  3571.             recursive = 1;
  3572.             nolinks = 2;
  3573. #endif /* RECURSIVE */
  3574.             } else /* Check if file exists */
  3575.               if ((rc = zchki(*xargv)) > -1 || (rc == -2)) {
  3576.               if  (rc != -2)
  3577.                 fil2snd = 1;
  3578.               nfils++;    /* Bump file counter */
  3579.               } else if (iswild(*xargv) && nzxpand(*xargv,0) > 0) {
  3580.               /* or contains wildcard characters matching real files */
  3581.               fil2snd = 1;
  3582.               nfils++;
  3583.               }
  3584.           }
  3585.           xargc++, xargv--;        /* Adjust argv/argc */
  3586.           if (!fil2snd && z == 0) {
  3587. #ifdef VMS
  3588.           XFATAL("%CKERMIT-E-SEARCHFAIL, no files for -s");
  3589. #else
  3590.           XFATAL("No files for -s");
  3591. #endif /* VMS */
  3592.           }
  3593.           if (z > 1) {
  3594.           XFATAL("-s: too many -'s");
  3595.           }
  3596.           if (z == 1 && fil2snd) {
  3597.           XFATAL("invalid mixture of filenames and '-' in -s");
  3598.           }
  3599.           debug(F101,"doarg s nfils","",nfils);
  3600.           debug(F101,"doarg s z","",z);
  3601.           if (nfils == 0) {        /* no file parameters were specified */
  3602.           if (is_a_tty(0)) {    /* (used to be is_a_tty(1) - why?) */
  3603.               XFATAL("sending from terminal not allowed");
  3604.           } else stdinf = 1;
  3605.           }
  3606.           debug(F101,"doarg s stdinf","",stdinf);
  3607.           debug(F111,"doarg",*xargv,nfils);
  3608.           action = 's';
  3609.           break;
  3610.       }
  3611.  
  3612.       case 'g':            /* get */
  3613.       case 'G':            /* get to stdout */
  3614.         if (action) {
  3615.         XFATAL("conflicting actions");
  3616.         }
  3617.         if (*(xp+1)) {
  3618.         XFATAL("invalid argument bundling after -g");
  3619.         }
  3620.         xargv++, xargc--;
  3621.         if ((xargc == 0) || (**xargv == '-')) {
  3622.         XFATAL("missing filename for -g");
  3623.         }
  3624.         if (x == 'G') stdouf = 1;
  3625.         cmarg = *xargv;
  3626.         action = 'r';
  3627.         break;
  3628. #endif /* NOXFER */
  3629.  
  3630. #ifndef NOLOCAL
  3631.       case 'c':            /* connect before */
  3632.         cflg = 1;
  3633.         break;
  3634.  
  3635.       case 'n':            /* connect after */
  3636.         cnflg = 1;
  3637.         break;
  3638. #endif /* NOLOCAL */
  3639.  
  3640.       case 'h':            /* help */
  3641.         usage();
  3642. #ifndef NOICP
  3643.         if (stayflg || what == W_COMMAND)
  3644.           break;
  3645.         else
  3646. #endif /* NOICP */
  3647.           doexit(GOOD_EXIT,-1);
  3648.  
  3649. #ifndef NOXFER
  3650.       case 'a':            /* "as" */
  3651.         if (*(xp+1)) {
  3652.         XFATAL("invalid argument bundling after -a");
  3653.         }
  3654.         xargv++, xargc--;
  3655.         if ((xargc < 1) || (**xargv == '-')) {
  3656.         XFATAL("missing name in -a");
  3657.         }
  3658.         cmarg2 = *xargv;
  3659.         debug(F111,"doarg a",cmarg2,xargc);
  3660.         break;
  3661. #endif /* NOXFER */
  3662.  
  3663. #ifndef NOICP
  3664.       case 'Y':            /* No initialization file */
  3665.         noinit = 1;
  3666.         break;
  3667.  
  3668.       case 'y':            /* Alternate init-file name */
  3669.         noinit = 0;
  3670.         if (*(xp+1)) {
  3671.         XFATAL("invalid argument bundling after -y");
  3672.         }
  3673.         xargv++, xargc--;
  3674.         if (xargc < 1) {
  3675.         XFATAL("missing filename in -y");
  3676.         }
  3677.         /* strcpy(kermrc,*xargv); ... already done in prescan()... */
  3678.         break;
  3679. #endif /* NOICP */
  3680.  
  3681. #ifndef NOXFER
  3682.       case 'I':            /* Assume we have an "Internet" */
  3683.         reliable = 1;        /* or other reliable connection */
  3684.         xreliable = 1;
  3685.         setreliable = 1;
  3686.  
  3687.         /* I'm not so sure about this -- what about VMS? (next comment) */
  3688.         clearrq = 1;        /* therefore the channel is clear */
  3689.  
  3690. #ifndef VMS
  3691. /*
  3692.   Since this can trigger full control-character unprefixing, we need to
  3693.   ensure that our terminal or pty driver is not doing Xon/Xoff; otherwise
  3694.   we can become deadlocked the first time we receive a file that contains
  3695.   Xoff.
  3696. */
  3697.         flow = FLO_NONE;
  3698. #endif /* VMS */
  3699.         break;
  3700. #endif /* NOXFER */
  3701.  
  3702. #ifndef NOLOCAL
  3703.       case 'l':            /* SET LINE */
  3704. #ifdef NETCONN
  3705. #ifdef ANYX25
  3706.       case 'X':            /* SET HOST to X.25 address */
  3707. #ifdef SUNX25
  3708.       case 'Z':            /* SET HOST to X.25 file descriptor */
  3709. #endif /* SUNX25 */
  3710. #endif /* ANYX25 */
  3711. #ifdef TCPSOCKET
  3712.       case 'J':
  3713.       case 'j':            /* SET HOST (TCP/IP socket) */
  3714. #endif /* TCPSOCKET */
  3715. #endif /* NETCONN */
  3716. #ifndef NOXFER
  3717.         if (x == 'j' || x == 'J' || x == 'X' || x == 'Z') {
  3718.         reliable = 1;        /* or other reliable connection */
  3719.         xreliable = 1;
  3720.         setreliable = 1;
  3721.         }
  3722. #endif /* NOXFER */
  3723.         network = 0;
  3724.         if (*(xp+1)) {
  3725.         XFATAL("invalid argument bundling after -l or -j");
  3726.         }
  3727.         xargv++, xargc--;
  3728.         if ((xargc < 1) || (**xargv == '-')) {
  3729.         XFATAL("communication line device name missing");
  3730.         }
  3731.  
  3732. #ifdef NETCONN
  3733.         if (x == 'J') {
  3734.         cflg    = 1;        /* Connect */
  3735.         stayflg = 1;        /* Stay */
  3736.         tn_exit = 1;        /* Telnet-like exit condition */
  3737.         exitonclose = 1;
  3738.         }
  3739. #endif /* NETCONN */
  3740.         ckstrncpy(ttname,*xargv,TTNAMLEN+1);
  3741.         local = (strcmp(ttname,CTTNAM) != 0);
  3742.         if (local && strcmp(ttname,"0") == 0)
  3743.           local = 0;
  3744. /*
  3745.   NOTE: We really do not need to call ttopen here, since it should be called
  3746.   again later, automatically, when we first try to condition the device via
  3747.   ttpkt or ttvt.  Calling ttopen here has the bad side effect of making the
  3748.   order of the -b and -l options significant when the order of command-line
  3749.   options should not matter.  However, the network cases immediately below
  3750.   complicate matters a bit, so we'll settle this in a future edit.
  3751. */
  3752.         if (x == 'l') {
  3753.         if (ttopen(ttname,&local,mdmtyp,0) < 0) {
  3754.             XFATAL("can't open device");
  3755.         }
  3756. #ifdef CKLOGDIAL
  3757.         dologline();
  3758. #endif /* CKLOGDIAL */
  3759.         debug(F101,"doarg speed","",speed);
  3760.         cxtype = (mdmtyp > 0) ? CXT_MODEM : CXT_DIRECT;
  3761.         speed = ttgspd();    /* Get the speed. */
  3762.         setflow();        /* Do something about flow control. */
  3763. #ifndef NOSPL
  3764.         if (local) {
  3765.             if (nmac) {        /* Any macros defined? */
  3766.             int k;        /* Yes */
  3767.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  3768.             if (k >= 0) {    /* If found, */
  3769.                 if (dodo(k,ttname,0) > -1) /* set it up, */
  3770.                   parser(1); /* and execute it */
  3771.             }
  3772.             }
  3773.         }
  3774. #endif /* NOSPL */
  3775.  
  3776. #ifdef NETCONN
  3777.         } else {
  3778.         if (x == 'j' || x == 'J') { /* IP network host name */
  3779.             char * s = line;
  3780.             char * service = tmpbuf;
  3781.             if (xargc > 0) {    /* Check if it's followed by */
  3782.             /* A service name or number */
  3783.             if (*(xargv+1) && *(*(xargv+1)) != '-') {
  3784.                 xargv++, xargc--;
  3785.                 ckstrncat(ttname,":",TTNAMLEN+1);
  3786.                 ckstrncat(ttname,*xargv,TTNAMLEN+1);
  3787.             }
  3788.             }
  3789.             nettype = NET_TCPB;
  3790.             mdmtyp = -nettype;    /* Perhaps already set in init file */
  3791.             telnetfd = 1;    /* Or maybe an open file descriptor */
  3792.             ckstrncpy(line, ttname, LINBUFSIZ); /* Working copy */
  3793.             for (s = line; *s != NUL && *s != ':'; s++);
  3794.             if (*s) {
  3795.             *s++ = NUL;
  3796.             ckstrncpy(service, s, TMPBUFSIZ);
  3797.             } else *service = NUL;
  3798.             s = line;
  3799. #ifndef NODIAL
  3800. #ifndef NOICP
  3801.             /* Look up in network directory */
  3802.             x = 0;
  3803.             if (*s == '=') {    /* If number starts with = sign */
  3804.             s++;        /* strip it */
  3805.             while (*s == SP) /* and also any leading spaces */
  3806.               s++;
  3807.             ckstrncpy(line,s,LINBUFSIZ); /* Do this again. */
  3808.             nhcount = 0;
  3809.             } else if (!isdigit(line[0])) {
  3810. /*
  3811.   nnetdir will be greater than 0 if the init file has been processed and it
  3812.   contained a SET NETWORK DIRECTORY command.
  3813. */
  3814.             xx = 0;        /* Initialize this */
  3815.             if (nnetdir > 0) /* If there is a directory... */
  3816.               xx = lunet(line); /* Look up the name */
  3817.             else        /* If no directory */
  3818.               nhcount = 0;    /* we didn't find anything there */
  3819.             if (xx < 0) {    /* Lookup error: */
  3820.                 ckmakmsg(tmpbuf,
  3821.                      TMPBUFSIZ,
  3822.                     "?Fatal network directory lookup error - ",
  3823.                      line,
  3824.                      "\n",
  3825.                      NULL
  3826.                      );
  3827.                 XFATAL(tmpbuf);
  3828.             }
  3829.             }
  3830. #endif /* NOICP */
  3831. #endif /* NODIAL */
  3832.             /* Add service to line specification for ttopen() */
  3833.             if (*service) {    /* There is a service specified */
  3834.             ckstrncat(line, ":",LINBUFSIZ);
  3835.             ckstrncat(line, service,LINBUFSIZ);
  3836.             ttnproto = NP_DEFAULT;
  3837.             } else {
  3838.             ckstrncat(line, ":telnet",LINBUFSIZ);
  3839.             ttnproto = NP_TELNET;
  3840.             }
  3841.  
  3842. #ifndef NOICP
  3843. #ifndef NODIAL
  3844.             if ((nhcount > 1) && !quiet && !backgrd) {
  3845.             printf("%d entr%s found for \"%s\"%s\n",
  3846.                    nhcount,
  3847.                    (nhcount == 1) ? "y" : "ies",
  3848.                    s,
  3849.                    (nhcount > 0) ? ":" : "."
  3850.                    );
  3851.             for (i = 0; i < nhcount; i++)
  3852.               printf("%3d. %s %-12s => %s\n",
  3853.                  i+1, n_name, nh_p2[i], nh_p[i]
  3854.                  );
  3855.             }
  3856.             if (nhcount == 0)
  3857.               n = 1;
  3858.             else
  3859.               n = nhcount;
  3860. #else
  3861.             n = 1;
  3862.             nhcount = 0;
  3863. #endif /* NODIAL */
  3864.             for (i = 0; i < n; i++) {
  3865. #ifndef NODIAL
  3866.             if (nhcount >= 1) {
  3867.                 /* Copy the current entry to line */
  3868.                 ckstrncpy(line,nh_p[i],LINBUFSIZ);
  3869.                     /* Check to see if the network entry contains a service */
  3870.                 for (s = line ; (*s != NUL) && (*s != ':'); s++)
  3871.                   ;
  3872.                 /* If directory does not have a service ... */
  3873.                 /* and the user specified one */
  3874.                 if (!*s && *service) {
  3875.                 ckstrncat(line, ":",LINBUFSIZ);
  3876.                 ckstrncat(line, service,LINBUFSIZ);
  3877.                 }
  3878.                 if (lookup(netcmd,nh_p2[i],nnets,&z) > -1) {
  3879.                 mdmtyp = 0 - netcmd[z].kwval;
  3880.                 } else {
  3881.                 printf(
  3882.                  "Error - network type \"%s\" not supported\n",
  3883.                        nh_p2[i]
  3884.                        );
  3885.                 continue;
  3886.                 }
  3887.             }
  3888. #endif /* NODIAL */
  3889.             }
  3890. #endif /* NOICP */
  3891.             ckstrncpy(ttname, line,TTNAMLEN+1);
  3892.             cxtype = CXT_TCPIP;    /* Set connection type */
  3893.             setflow();        /* Set appropriate flow control. */
  3894. #ifdef SUNX25
  3895.         } else if (x == 'X') {    /* X.25 address */
  3896.             nettype = NET_SX25;
  3897.             mdmtyp = -nettype;
  3898.         } else if (x == 'Z') {    /* Open X.25 file descriptor */
  3899.             nettype = NET_SX25;
  3900.             mdmtyp = -nettype;
  3901.             x25fd = 1;
  3902. #endif /* SUNX25 */
  3903. #ifdef STRATUSX25
  3904.         } else if (x == 'X') {    /* X.25 address */
  3905.             nettype = NET_VX25;
  3906.             mdmtyp = -nettype;
  3907. #endif /* STRATUSX25 */
  3908. #ifdef IBMX25
  3909.         } else if (x == 'X') {    /* X.25 address */
  3910.             nettype = NET_IX25;
  3911.             mdmtyp = -nettype;
  3912. #endif /* IBMX25 */
  3913. #ifdef HPX25
  3914.         } else if (x == 'X') {    /* X.25 address */
  3915.             nettype = NET_HX25;
  3916.             mdmtyp = -nettype;
  3917. #endif /* HPX25 */
  3918.         }
  3919.         if (ttopen(ttname,&local,mdmtyp,0) < 0) {
  3920.             XFATAL("can't open host connection");
  3921.         }
  3922.         network = 1;
  3923. #ifdef CKLOGDIAL
  3924.         dolognet();
  3925. #endif /* CKLOGDIAL */
  3926.         cxtype = CXT_X25;    /* Set connection type */
  3927.         setflow();        /* Set appropriate flow control. */
  3928. #ifndef NOSPL
  3929.         if (local) {
  3930.             if (nmac) {        /* Any macros defined? */
  3931.             int k;        /* Yes */
  3932.             k = mlook(mactab,"on_open",nmac); /* Look this up */
  3933.             if (k >= 0) {    /* If found, */
  3934.                 if (dodo(k,ttname,0) > -1) /* set it up, */
  3935.                   parser(1);        /* and execute it */
  3936.             }
  3937.             }
  3938.         }
  3939. #endif /* NOSPL */
  3940. #endif /* NETCONN */
  3941.         }
  3942.         /* add more here -- decnet, etc... */
  3943.         haveline = 1;
  3944.         break;
  3945.  
  3946. #ifdef ANYX25
  3947.       case 'U':            /* X.25 call user data */
  3948.         if (*(xp+1)) {
  3949.         XFATAL("invalid argument bundling");
  3950.         }
  3951.         xargv++, xargc--;
  3952.         if ((xargc < 1) || (**xargv == '-')) {
  3953.         XFATAL("missing call user data string");
  3954.         }
  3955.         ckstrncpy(udata,*xargv,MAXCUDATA);
  3956.         if ((int)strlen(udata) <= MAXCUDATA) {
  3957.         cudata = 1;
  3958.         } else {
  3959.         XFATAL("Invalid call user data");
  3960.         }
  3961.         break;
  3962.  
  3963.       case 'o':            /* X.25 closed user group */
  3964.         if (*(xp+1)) {
  3965.         XFATAL("invalid argument bundling");
  3966.         }
  3967.         xargv++, xargc--;
  3968.         if ((xargc < 1) || (**xargv == '-')) {
  3969.         XFATAL("missing closed user group index");
  3970.         }
  3971.         z = atoi(*xargv);        /* Convert to number */
  3972.         if (z >= 0 && z <= 99) {
  3973.         closgr = z;
  3974.         } else {
  3975.         XFATAL("Invalid closed user group index");
  3976.         }
  3977.         break;
  3978.  
  3979.       case 'u':            /* X.25 reverse charge call */
  3980.         revcall = 1;
  3981.         break;
  3982. #endif /* ANYX25 */
  3983. #endif /* NOLOCAL */
  3984.  
  3985.       case 'b':            /* Bits-per-second for serial device */
  3986.         if (*(xp+1)) {
  3987.         XFATAL("invalid argument bundling");
  3988.         }
  3989.         xargv++, xargc--;
  3990.         if ((xargc < 1) || (**xargv == '-')) {
  3991.         XFATAL("missing bps");
  3992.         }
  3993.         zz = atol(*xargv);        /* Convert to long int */
  3994.         i = zz / 10L;
  3995. #ifndef NOLOCAL
  3996.         if (ttsspd(i) > -1)        /* Check and set it */
  3997. #endif /* NOLOCAL */
  3998.           speed = ttgspd();        /* and read it back. */
  3999. #ifndef NOLOCAL
  4000.         else {
  4001.         XFATAL("unsupported transmission rate");
  4002.         }
  4003. #endif /* NOLOCAL */
  4004.         break;
  4005.  
  4006. #ifndef NODIAL
  4007. #ifndef NOICP
  4008.       case 'm':            /* Modem type */
  4009.         if (*(xp+1)) {
  4010.         XFATAL("invalid argument bundling after -m");
  4011.         }
  4012.         xargv++, xargc--;
  4013.         if ((xargc < 1) || (**xargv == '-')) {
  4014.         XFATAL("modem type missing");
  4015.         }
  4016.         y = lookup(mdmtab,*xargv,nmdm,&z);
  4017.         if (y < 0) {
  4018.         XFATAL("unknown modem type");
  4019.         }
  4020.         usermdm = 0;
  4021.         usermdm = (y == dialudt) ? x : 0;
  4022.         initmdm(y);
  4023.         break;
  4024. #endif /* NOICP */
  4025. #endif /* NODIAL */
  4026.  
  4027. #ifndef NOXFER
  4028.       case 'e':            /* Extended packet length */
  4029.         if (*(xp+1)) {
  4030.         XFATAL("invalid argument bundling after -e");
  4031.         }
  4032.         xargv++, xargc--;
  4033.         if ((xargc < 1) || (**xargv == '-')) {
  4034.         XFATAL("missing length");
  4035.         }
  4036.         z = atoi(*xargv);        /* Convert to number */
  4037.         if (z > 10 && z <= maxrps) {
  4038.         rpsiz = urpsiz = z;
  4039.         if (z > 94) rpsiz = 94;    /* Fallback if other Kermit can't */
  4040.         } else {
  4041.         XFATAL("Unsupported packet length");
  4042.         }
  4043.         break;
  4044.  
  4045.       case 'v':            /* Vindow size */
  4046.         if (*(xp+1)) {
  4047.         XFATAL("invalid argument bundling");
  4048.         }
  4049.         xargv++, xargc--;
  4050.         if ((xargc < 1) || (**xargv == '-')) {
  4051.         XFATAL("missing or bad window size");
  4052.         }
  4053.         z = atoi(*xargv);        /* Convert to number */
  4054.         if (z < 32) {        /* If in range */
  4055.         wslotr = z;        /* set it */
  4056.         if (z > 1) swcapr = 1;    /* Set capas bit if windowing */
  4057.         } else {
  4058.         XFATAL("Unsupported packet length");
  4059.         }
  4060.         break;
  4061. #endif /* NOXFER */
  4062.  
  4063.       case 'i':            /* Treat files as binary */
  4064.         binary = XYFT_B;
  4065.         xfermode = XMODE_M;        /* Transfer mode manual */
  4066.         filepeek = 0;
  4067. #ifdef PATTERNS
  4068.         patterns = 0;
  4069. #endif /* PATTERNS */
  4070.         break;
  4071.  
  4072. #ifndef NOXFER
  4073.       case 'w':            /* Writeover */
  4074.         ckwarn = 0;
  4075.         fncact = XYFX_X;
  4076.         break;
  4077. #endif /* NOXFER */
  4078.  
  4079.       case 'q':            /* Quiet */
  4080.         quiet = 1;
  4081.         break;
  4082.  
  4083. #ifdef DEBUG
  4084.       case 'd':            /* DEBUG */
  4085.         break;            /* Handled in prescan() */
  4086. #endif /* DEBUG */
  4087.  
  4088.       case '0': {            /* In the middle */
  4089.           extern int tt_escape, lscapr;
  4090.           tt_escape = 0;        /* No escape character */
  4091.           flow = 0;            /* No Xon/Xoff (what about hwfc?) */
  4092. #ifndef NOXFER
  4093.           lscapr = 0;        /* No locking shifts */
  4094. #endif /* NOXFER */
  4095. #ifdef CK_APC
  4096.           {
  4097.           extern int apcstatus;    /* No APCs */
  4098.           apcstatus = APC_OFF;
  4099.           }
  4100. #endif /* CK_APC */
  4101. #ifndef NOLOCAL
  4102. #ifdef CK_AUTODL
  4103.               setautodl(0,0);        /* No autodownload */
  4104. #endif /* CK_AUTODL */
  4105. #endif /* NOLOCAL */
  4106. #ifndef NOCSETS
  4107.           {
  4108.           extern int tcsr, tcsl; /* No character-set translation */
  4109.           tcsr = 0;
  4110.           tcsl = tcsr;        /* Make these equal */
  4111.           }
  4112. #endif /* NOCSETS */
  4113. #ifdef TNCODE
  4114.           TELOPT_DEF_C_U_MODE(TELOPT_KERMIT) = TN_NG_RF;
  4115.           TELOPT_DEF_C_ME_MODE(TELOPT_KERMIT) = TN_NG_RF;
  4116.           TELOPT_DEF_S_U_MODE(TELOPT_KERMIT) = TN_NG_RF;
  4117.           TELOPT_DEF_S_ME_MODE(TELOPT_KERMIT) = TN_NG_RF;
  4118. #endif /* TNCODE */
  4119.       }
  4120. /* Fall thru... */
  4121.  
  4122.       case '8':            /* 8-bit clean */
  4123.         parity = 0;
  4124.         cmdmsk = 0xff;
  4125.         cmask = 0xff;
  4126.         break;
  4127.  
  4128.       case 'V': {
  4129.           extern int xfermode;
  4130. #ifdef PATTERNS
  4131.           extern int patterns;
  4132.           patterns = 0;        /* No patterns */
  4133. #endif /* PATTERNS */
  4134.           xfermode = XMODE_M;    /* Manual transfer mode */
  4135.           filepeek = 0;
  4136.           break;
  4137.       }
  4138.  
  4139.       case 'p':            /* SET PARITY */
  4140.         if (*(xp+1)) {
  4141.         XFATAL("invalid argument bundling");
  4142.         }
  4143.         xargv++, xargc--;
  4144.         if ((xargc < 1) || (**xargv == '-')) {
  4145.         XFATAL("missing parity");
  4146.         }
  4147.         switch(x = **xargv) {
  4148.           case 'e':
  4149.           case 'o':
  4150.           case 'm':
  4151.           case 's': parity = x; break;
  4152.           case 'n': parity = 0; break;
  4153.           default:  { XFATAL("invalid parity"); }
  4154.         }
  4155.         break;
  4156.  
  4157.       case 't':            /* Line turnaround handshake */
  4158.         turn = 1;
  4159.         turnch = XON;        /* XON is turnaround character */
  4160.         duplex = 1;            /* Half duplex */
  4161.         flow = 0;            /* No flow control */
  4162.         break;
  4163.  
  4164.       case 'B':
  4165.         bgset = 1;            /* Force background (batch) */
  4166.         backgrd = 1;
  4167.         break;
  4168.  
  4169.       case 'z':            /* Force foreground */
  4170.         bgset = 0;
  4171.         backgrd = 0;
  4172.         break;
  4173.  
  4174. #ifndef NOXFER
  4175. #ifdef RECURSIVE
  4176.       case 'L':
  4177.         recursive = 2;
  4178.         nolinks = 2;
  4179.         fnspath = PATH_REL;
  4180.         break;
  4181. #endif /* RECURSIVE */
  4182. #endif /* NOXFER */
  4183.  
  4184. #ifndef NOSPL
  4185.       case 'M':            /* My User Name */
  4186.         if (*(xp+1)) {
  4187.         XFATAL("invalid argument bundling");
  4188.         }
  4189.         xargv++, xargc--;
  4190.         if ((xargc < 1) || (**xargv == '-')) {
  4191.         XFATAL("missing username");
  4192.         }
  4193.         if ((int)strlen(*xargv) > 63) {
  4194.         XFATAL("username too long");
  4195.         }
  4196. #ifdef IKSD
  4197.         if (!inserver)
  4198. #endif /* IKSD */
  4199.           {
  4200.           ckstrncpy(uidbuf,*xargv,UIDBUFLEN);
  4201.           haveftpuid = 1;
  4202.           }
  4203.         break;
  4204. #endif /* NOSPL */
  4205.  
  4206. #ifdef CK_NETBIOS
  4207.       case 'N':            /* NetBios Adapter Number follows */
  4208.         if (*(xp+1)) {
  4209.         XFATAL("invalid argument bundling after -N");
  4210.         }
  4211.         xargv++, xargc--;
  4212.         if ((xargc < 1) || (**xargv == '-')) {
  4213.         XFATAL("missing NetBios Adapter number");
  4214.         }
  4215.         if ((strlen(*xargv) != 1) ||
  4216.         (*xargv)[0] != 'X' &&
  4217.         (atoi(*xargv) < 0) &&
  4218.         (atoi(*xargv) > 9)) {
  4219.         XFATAL("Invalid NetBios Adapter - Adapters 0 to 9 are valid");
  4220.         }
  4221.         break;
  4222. #endif /* CK_NETBIOS */
  4223.  
  4224. #ifdef NETCONN
  4225.       case 'F':
  4226.         network = 1;
  4227.         if (*(xp+1)) {
  4228.         XFATAL("invalid argument bundling after -F");
  4229.         }
  4230.         xargv++, xargc--;
  4231.         if ((xargc < 1) || (**xargv == '-')) {
  4232.         XFATAL("network file descriptor missing");
  4233.         }
  4234.         ckstrncpy(ttname,*xargv,TTNAMLEN+1);
  4235.         nettype = NET_TCPB;
  4236.         mdmtyp = -nettype;
  4237.         telnetfd = 1;
  4238.         local = 1;
  4239.         break;
  4240. #endif /* NETCONN */
  4241.  
  4242. #ifdef COMMENT
  4243. #ifdef OS2PM
  4244.       case 'P':            /* OS/2 Presentation Manager */
  4245.         if (*(xp+1)) {
  4246.         XFATAL("invalid argument bundling after -P");
  4247.         }
  4248.         xargv++, xargc--;
  4249.         if ((xargc < 1) || (**xargv == '-')) {
  4250.         XFATAL("pipe data missing");
  4251.         }
  4252.         pipedata = *xargv;
  4253.         break;
  4254. #endif /* OS2PM */
  4255. #else
  4256.       case 'P':            /* Filenames literal */
  4257.         fncnv  = XYFN_L;
  4258.         f_save = XYFN_L;
  4259.         break;
  4260. #endif /* COMMENT */
  4261.  
  4262. #ifndef NOICP
  4263.       case 'H':
  4264.         noherald = 1;
  4265.         break;
  4266. #endif /* NOICP */
  4267.  
  4268. #ifdef OS2
  4269.       case 'W':
  4270.         if (*(xp+1)) {
  4271.         XFATAL("invalid argument bundling after -W");
  4272.         }
  4273.         xargv++, xargc--;
  4274.         if ((xargc < 1)) { /* could be negative */
  4275.         XFATAL("Window handle missing");
  4276.         }
  4277.         xargv++, xargc--;
  4278.         if ((xargc < 1) || (**xargv == '-')) {
  4279.         XFATAL("Kermit Instance missing");
  4280.         }
  4281.         /* Action done in prescan */
  4282.         break;
  4283.  
  4284.       case '#':            /* K95 stdio threads */
  4285.         xargv++, xargc--;        /* Skip past argument */
  4286.         break;            /* Action done in prescan */
  4287. #endif /* OS2 */
  4288.  
  4289. #ifdef NEWFTP
  4290.       case '9':            /* FTP */
  4291.         if (*(xp+1)) {
  4292.         XFATAL("invalid argument bundling after -9");
  4293.         }
  4294.         xargv++, xargc--;
  4295.         if ((xargc < 1) || (**xargv == '-')) {
  4296.         XFATAL("FTP server address missing");
  4297.         }
  4298.         makestr(&ftp_host,*xargv);
  4299.         break;
  4300. #endif /* NEWFTP */
  4301.  
  4302.       default:
  4303.         fatal2(*xargv,
  4304. #ifdef NT
  4305.                    "invalid command-line option, type \"k95 -h\" for help"
  4306. #else
  4307. #ifdef OS2
  4308.                    "invalid command-line option, type \"k2 -h\" for help"
  4309. #else
  4310.                    "invalid command-line option, type \"kermit -h\" for help"
  4311. #endif /* OS2 */
  4312. #endif /* NT */
  4313.            );
  4314.         }
  4315.     if (!xp) break;
  4316.     x = *++xp;            /* See if options are bundled */
  4317.     }
  4318.     return(0);
  4319. }
  4320.  
  4321. #ifdef TNCODE
  4322. /*  D O T N A R G  --  Do a telnet command-line argument.  */
  4323.  
  4324. static int
  4325. #ifdef CK_ANSIC
  4326. dotnarg(char x)
  4327. #else
  4328. dotnarg(x) char x;
  4329. #endif /* CK_ANSIC */
  4330. /* dotnarg */ {
  4331.     char *xp;
  4332.  
  4333.     xp = *xargv+1;                      /* Pointer for bundled args */
  4334.     debug(F111,"dotnarg entry",xp,xargc);
  4335.     while (x) {
  4336.         debug(F000,"dotnarg arg","",x);
  4337.         switch (x) {                    /* Big switch on arg */
  4338.  
  4339. #ifndef COMMENT
  4340.       case '-':            /* Extended commands... */
  4341.             if (doxarg(xargv,0) < 0) {
  4342.                 XFATAL("Extended option error");
  4343.             } /* Full thru... */
  4344.       case '+':            /* Extended command for prescan() */
  4345.             return(0);
  4346. #else  /* COMMENT */
  4347.       case '-':
  4348.       case '+':
  4349.         XFATAL("Extended options not configured");
  4350. #endif /* COMMENT */
  4351.  
  4352. /*
  4353.  * -#                Kermit 95 Startup Flags
  4354.  * -8                Negotiate Telnet Binary in both directions
  4355.  * -a                Require use of Telnet authentication
  4356.  * -c                Do not read the .telnetrc file
  4357.  * -d                Turn on debug mode
  4358.  * -E                No escape character
  4359.  * -f                Forward credentials to host
  4360.  * -K                Refuse use of authentication; do not send username
  4361.  * -k realm          Set default realm
  4362.  * -l user           Set username and request Telnet authentication
  4363.  * -L                Negotiate Telnet Binary Output only
  4364.  * -q                Quiet mode (suppress messages)
  4365.  * -S tos            Use the IP type-of-service tos
  4366.  * -x                Require Encryption
  4367.  * -D                Disable forward-X
  4368.  * -T cert=file      Use certificate in file
  4369.  * -T key=file       Use private key in file
  4370.  * -T crlfile=file   Use CRL in file
  4371.  * -T crldir=dir     Use CRLs in directory
  4372.  * -T cipher=string  Use only ciphers in string
  4373.  * -X atype          Disable use of atype authentication
  4374.  * -Y                Disable init file processing
  4375.  *
  4376.  */
  4377.       case 'h':            /* help */
  4378.         usage();
  4379.         doexit(GOOD_EXIT,-1);
  4380.         break;
  4381.  
  4382.       case '8':            /* Telnet Binary in both directions */
  4383.         TELOPT_DEF_C_U_MODE(TELOPT_BINARY) = TN_NG_MU;
  4384.         TELOPT_DEF_C_ME_MODE(TELOPT_BINARY) = TN_NG_MU;
  4385.         parity = 0;
  4386.         cmdmsk = 0xff;
  4387.         cmask = 0xff;
  4388.         break;
  4389.  
  4390.       case 'a':            /* Require Telnet Auth */
  4391.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  4392.         break;
  4393.  
  4394.         case 'Y':
  4395.               xargv++, xargc--;        /* Skip past argument */
  4396.               break;            /* Action done in prescan */
  4397.  
  4398. #ifdef OS2
  4399.           case '#':            /* K95 stdio threads */
  4400.               xargv++, xargc--;        /* Skip past argument */
  4401.               break;            /* Action done in prescan */
  4402. #endif /* OS2 */
  4403.  
  4404.           case 'q':                    /* Quiet */
  4405.               quiet = 1;
  4406.               break;
  4407.  
  4408.       case 'd':
  4409. #ifdef DEBUG
  4410.         if (deblog) {
  4411.         debtim = 1;
  4412.         } else {
  4413.         deblog = debopn("debug.log",0);
  4414.         }
  4415. #endif /* DEBUG */
  4416.         break;
  4417.  
  4418.       case 'E': {            /* No Escape character */
  4419.           extern int tt_escape;
  4420.           tt_escape = 0;
  4421.       }
  4422.         break;
  4423.  
  4424.       case 'K':
  4425.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
  4426.         uidbuf[0] = NUL;
  4427.         break;
  4428.  
  4429.       case 'l': /* Set username and request telnet authentication */
  4430.         if (*(xp+1)) {
  4431.         XFATAL("invalid argument bundling");
  4432.         }
  4433.         xargv++, xargc--;
  4434.         if ((xargc < 1) || (**xargv == '-')) {
  4435.         XFATAL("missing username");
  4436.         }
  4437.         if ((int)strlen(*xargv) > 63) {
  4438.         XFATAL("username too long");
  4439.         }
  4440.         ckstrncpy(uidbuf,*xargv,UIDBUFLEN);
  4441.         TELOPT_DEF_C_ME_MODE(TELOPT_AUTHENTICATION) = TN_NG_MU;
  4442.         break;
  4443.  
  4444.       case 'L':            /* Require BINARY mode outbound only */
  4445.         TELOPT_DEF_C_ME_MODE(TELOPT_BINARY) = TN_NG_MU;
  4446.         break;
  4447.  
  4448.       case 'x':            /* Require Encryption */
  4449.         TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  4450.         TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_MU;
  4451.         break;
  4452.  
  4453.       case 'D':            /* Disable use of Forward X */
  4454.         TELOPT_DEF_C_U_MODE(TELOPT_FORWARD_X) = TN_NG_RF;
  4455.         break;
  4456.  
  4457.       case 'f':            /* Forward credentials to host */
  4458.         {
  4459. #ifdef CK_AUTHENTICATION
  4460.         extern int forward_flag;
  4461.         forward_flag = 1;
  4462. #endif
  4463.         break;
  4464.         }
  4465.  
  4466.       case 'k': {
  4467. #ifdef CK_KERBEROS
  4468.           extern char * krb5_d_realm, * krb4_d_realm;
  4469. #endif /* CK_KERBEROS */
  4470.           if (*(xp+1)) {
  4471.           XFATAL("invalid argument bundling");
  4472.           }
  4473.           xargv++, xargc--;
  4474.           if ((xargc < 1) || (**xargv == '-')) {
  4475.           XFATAL("missing realm");
  4476.           }
  4477. #ifdef CK_KERBEROS
  4478.           if ((int)strlen(*xargv) > 63) {
  4479.           XFATAL("realm too long");
  4480.           }
  4481.           makestr(&krb5_d_realm,*xargv);
  4482.           makestr(&krb4_d_realm,*xargv);
  4483. #endif /* CK_KERBEROS */
  4484.           break;
  4485.       }
  4486.  
  4487.       case 'T': {
  4488.           if (*(xp+1)) {
  4489.           XFATAL("invalid argument bundling");
  4490.           }
  4491.           xargv++, xargc--;
  4492.           if ((xargc < 1) || (**xargv == '-')) {
  4493.           XFATAL("missing cert=, key=, crlfile=, crldir=, or cipher=");
  4494.           }
  4495. #ifdef CK_SSL
  4496.           if (!strncmp(*xargv,"cert=",5)) {
  4497.           extern char * ssl_rsa_cert_file;
  4498.           makestr(&ssl_rsa_cert_file,&(*xargv[5]));
  4499.           } else if ( !strncmp(*xargv,"key=",4) ) {
  4500.           extern char * ssl_rsa_key_file;
  4501.           makestr(&ssl_rsa_key_file,&(*xargv[4]));
  4502.           } else if ( !strncmp(*xargv,"crlfile=",8) ) {
  4503.           extern char * ssl_crl_file;
  4504.           makestr(&ssl_crl_file,&(*xargv[8]));
  4505.           } else if ( !strncmp(*xargv,"crldir=",7) ) {
  4506.           extern char * ssl_crl_dir;
  4507.           makestr(&ssl_crl_dir,&(*xargv[7]));
  4508.           } else if ( !strncmp(*xargv,"cipher=",7) ) {
  4509.           extern char * ssl_cipher_list;
  4510.           makestr(&ssl_cipher_list,&(*xargv[7]));
  4511.           } else {
  4512.           XFATAL("invalid parameter");
  4513.           }
  4514. #endif /* CK_SSL */
  4515.           break;
  4516.       }
  4517.  
  4518.       default:
  4519.         fatal2(*xargv,
  4520.            "invalid command-line option, type \"telnet -h\" for help"
  4521.            );
  4522.         }
  4523.  
  4524.     if (!xp) break;
  4525.     x = *++xp;            /* See if options are bundled */
  4526.     }
  4527.     return(0);
  4528. }
  4529. #endif /* TNCODE */
  4530.  
  4531. #ifdef RLOGCODE
  4532.  
  4533. /*  D O R L G A R G  --  Do a rlogin command-line argument.  */
  4534.  
  4535. static int
  4536. #ifdef CK_ANSIC
  4537. dorlgarg(char x)
  4538. #else
  4539. dorlgarg(x) char x;
  4540. #endif /* CK_ANSIC */
  4541. /* dorlgarg */ {
  4542.     char *xp;
  4543.  
  4544.     xp = *xargv+1;                      /* Pointer for bundled args */
  4545.     debug(F111,"dorlgarg entry",xp,xargc);
  4546.     while (x) {
  4547.         debug(F000,"dorlgarg arg","",x);
  4548.         switch (x) {                    /* Big switch on arg */
  4549.  
  4550. #ifndef COMMENT
  4551.       case '-':            /* Extended commands... */
  4552.             if (doxarg(xargv,0) < 0) {
  4553.             XFATAL("Extended option error");
  4554.             } /* Full thru... */
  4555.       case '+':            /* Extended command for prescan() */
  4556.             return(0);
  4557. #else  /* COMMENT */
  4558.       case '-':
  4559.       case '+':
  4560.         XFATAL("Extended options not configured");
  4561. #endif /* COMMENT */
  4562.  
  4563. /*
  4564.  * -d                Debug
  4565.  * -l user           Set username
  4566.  *
  4567.  */
  4568.       case 'h':            /* help */
  4569.         usage();
  4570.         doexit(GOOD_EXIT,-1);
  4571.         break;
  4572.  
  4573.           case 'Y':
  4574.               xargv++, xargc--;        /* Skip past argument */
  4575.               break;            /* Action done in prescan */
  4576. #ifdef OS2
  4577.           case '#':            /* K95 stdio threads */
  4578.               xargv++, xargc--;        /* Skip past argument */
  4579.               break;            /* Action done in prescan */
  4580. #endif /* OS2 */
  4581.           case 'q':                    /* Quiet */
  4582.               quiet = 1;
  4583.               break;
  4584.  
  4585.       case 'd':
  4586. #ifdef DEBUG
  4587.         if (deblog) {
  4588.         debtim = 1;
  4589.         } else {
  4590.         deblog = debopn("debug.log",0);
  4591.         }
  4592. #endif /* DEBUG */
  4593.         break;
  4594.  
  4595.       case 'l': /* Set username and request telnet authentication */
  4596.         if (*(xp+1)) {
  4597.         XFATAL("invalid argument bundling");
  4598.         }
  4599.         xargv++, xargc--;
  4600.         if ((xargc < 1) || (**xargv == '-')) {
  4601.         XFATAL("missing username");
  4602.         }
  4603.         if ((int)strlen(*xargv) > 63) {
  4604.         XFATAL("username too long");
  4605.         }
  4606.         ckstrncpy(uidbuf,*xargv,UIDBUFLEN);
  4607.         break;
  4608.  
  4609.       default:
  4610.         fatal2(*xargv,
  4611.            "invalid command-line option, type \"rlogin -h\" for help"
  4612.            );
  4613.         }
  4614.  
  4615.     if (!xp) break;
  4616.     x = *++xp;            /* See if options are bundled */
  4617.     }
  4618.     return(0);
  4619. }
  4620. #endif /* RLOGCODE */
  4621.  
  4622. #ifdef SSHBUILTIN
  4623.  
  4624. /*  D O S S H A R G  --  Do a ssh command-line argument.  */
  4625.  
  4626. static int
  4627. #ifdef CK_ANSIC
  4628. dossharg(char x)
  4629. #else
  4630. dossharg(x) char x;
  4631. #endif /* CK_ANSIC */
  4632. /* dossharg */ {
  4633.     char *xp;
  4634.  
  4635.     xp = *xargv+1;                      /* Pointer for bundled args */
  4636.     debug(F111,"dossharg entry",xp,xargc);
  4637.     while (x) {
  4638.         debug(F000,"dossharg arg","",x);
  4639.         switch (x) {                    /* Big switch on arg */
  4640.  
  4641. #ifndef COMMENT
  4642.       case '-':            /* Extended commands... */
  4643.             if (doxarg(xargv,0) < 0) {
  4644.                 XFATAL("Extended option error");
  4645.             } /* Full thru... */
  4646.       case '+':            /* Extended command for prescan() */
  4647.             return(0);
  4648. #else  /* COMMENTP */
  4649.       case '-':
  4650.       case '+':
  4651.         XFATAL("Extended options not configured");
  4652. #endif /* COMMENT */
  4653.  
  4654. /*
  4655.  * -d                Debug
  4656.  * -# args           Init
  4657.  * -Y                no init file
  4658.  * -l user           Set username
  4659.  *
  4660.  */
  4661.       case 'h':            /* help */
  4662.         usage();
  4663.         doexit(GOOD_EXIT,-1);
  4664.         break;
  4665.  
  4666.           case 'Y':
  4667.               xargv++, xargc--;        /* Skip past argument */
  4668.               break;            /* Action done in prescan */
  4669. #ifdef OS2
  4670.           case '#':            /* K95 stdio threads */
  4671.               xargv++, xargc--;        /* Skip past argument */
  4672.               break;            /* Action done in prescan */
  4673. #endif /* OS2 */
  4674.           case 'q':                    /* Quiet */
  4675.               quiet = 1;
  4676.               break;
  4677.  
  4678.       case 'd':
  4679. #ifdef DEBUG
  4680.               if (deblog) {
  4681.                   debtim = 1;
  4682.               } else {
  4683.                   deblog = debopn("debug.log",0);
  4684.               }
  4685. #endif /* DEBUG */
  4686.         break;
  4687.  
  4688.       case 'l': /* Set username and request telnet authentication */
  4689.         if (*(xp+1)) {
  4690.         XFATAL("invalid argument bundling");
  4691.         }
  4692.         xargv++, xargc--;
  4693.         if ((xargc < 1) || (**xargv == '-')) {
  4694.         XFATAL("missing username");
  4695.         }
  4696.         if ((int)strlen(*xargv) > 63) {
  4697.         XFATAL("username too long");
  4698.         }
  4699.         ckstrncpy(uidbuf,*xargv,UIDBUFLEN);
  4700.         break;
  4701.  
  4702.       default:
  4703.         fatal2(*xargv,
  4704.            "invalid command-line option, type \"ssh -h\" for help"
  4705.            );
  4706.         }
  4707.  
  4708.     if (!xp) break;
  4709.     x = *++xp;            /* See if options are bundled */
  4710.     }
  4711.     return(0);
  4712. }
  4713. #endif /* SSHBUILTIN */
  4714.  
  4715. #else /* No command-line interface... */
  4716.  
  4717. extern int xargc;
  4718. int
  4719. cmdlin() {
  4720.     if (xargc > 1) {
  4721.         XFATAL("Sorry, command-line options disabled.");
  4722.     }
  4723. }
  4724. #endif /* NOCMDL */
  4725.