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