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