home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / ecu / part17 < prev    next >
Encoding:
Text File  |  1992-09-13  |  56.9 KB  |  2,432 lines

  1. Newsgroups: comp.sources.misc
  2. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  3. Subject:  v32i052:  ecu - ECU Asynchronous Communications v3.20, Part17/40
  4. Message-ID: <1992Sep13.153653.5650@sparky.imd.sterling.com>
  5. X-Md4-Signature: 1e1581eedfca7743f82adff0a5d02ca7
  6. Date: Sun, 13 Sep 1992 15:36:53 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  10. Posting-number: Volume 32, Issue 52
  11. Archive-name: ecu/part17
  12. Environment: SCO,XENIX,ISC,SUNOS,SYSVR4,HDB,Curses
  13. Supersedes: ecu: Volume 21, Issue 53-89
  14.  
  15. ---- Cut Here and feed the following to sh ----
  16. #!/bin/sh
  17. # this is ecu320.17 (part 17 of ecu320)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file gint.c continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 17; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping gint.c'
  35. else
  36. echo 'x - continuing file gint.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'gint.c' &&
  38. X
  39. X        default:
  40. X            break;
  41. X    }   /* end of switch statement */
  42. X
  43. X/* we did not catch any special cases with the switch statement must
  44. Xbe numeric integer */
  45. X
  46. X    return(gint_constant(param,value));
  47. X
  48. X}   /* end of gint_base() */
  49. X
  50. X/*+-------------------------------------------------------------------------
  51. X    gintop(param,intop) - evaluate integer operator
  52. X--------------------------------------------------------------------------*/
  53. Xint
  54. Xgintop(param,intop)
  55. XESD *param;
  56. Xint *intop;
  57. X{
  58. X    register erc;
  59. X
  60. X    if(erc = skip_cmd_break(param))
  61. X        return(erc);
  62. X    switch(param->pb[param->index])
  63. X    {
  64. X        case '+':
  65. X            param->index++;
  66. X            *intop = OP_ADD;
  67. X            break;
  68. X
  69. X        case '-':
  70. X            param->index++;
  71. X            *intop = OP_SUB;
  72. X            break;
  73. X
  74. X        case '*':
  75. X            param->index++;
  76. X            *intop = OP_MUL;
  77. X            break;
  78. X
  79. X        case '/':
  80. X            param->index++;
  81. X            *intop = OP_DIV;
  82. X            break;
  83. X
  84. X        case '|':
  85. X            if(*(param->pb + param->index + 1) == '|')
  86. X                return(eInvalidIntOp);
  87. X            param->index++;
  88. X            *intop = OP_OR;
  89. X            break;
  90. X
  91. X        case '@':
  92. X            param->index++;
  93. X            *intop = OP_MOD;
  94. X            break;
  95. X
  96. X        case '^':
  97. X            param->index++;
  98. X            *intop = OP_XOR;
  99. X            break;
  100. X
  101. X        case '&':
  102. X            if(*(param->pb + param->index + 1) == '&')
  103. X                return(eInvalidIntOp);
  104. X            param->index++;
  105. X            *intop = OP_AND;
  106. X            break;
  107. X
  108. X        default:
  109. X            return(eInvalidIntOp);
  110. X    }   /* end of switch statement */
  111. X
  112. X    return(0);
  113. X
  114. X}   /* end of gintop() */
  115. X
  116. X/*+-------------------------------------------------------------------------
  117. X    gint(param,int_returned) - evaluate integer expression
  118. X--------------------------------------------------------------------------*/
  119. Xint
  120. Xgint(param,int_returned)
  121. XESD *param;
  122. Xlong *int_returned;
  123. X{
  124. Xregister erc;
  125. Xlong int1;
  126. Xlong int_accum = 0;
  127. Xint intop;
  128. Xint unary_minus = 0;
  129. X
  130. X    if(erc = skip_cmd_break(param))
  131. X        return(erc);
  132. X    if(param->pb[param->index] == '-')
  133. X        unary_minus++,param->index++;
  134. X
  135. X    if(erc = gint_base(param,&int1))
  136. X        return(erc);
  137. X    int_accum = (unary_minus) ? -int1 : int1;
  138. X
  139. X    while((erc = gintop(param,&intop)) == 0)
  140. X    {
  141. X        if(erc = gint_base(param,&int1))
  142. X            return(erc);
  143. X        switch(intop)
  144. X        {
  145. X            case OP_ADD:
  146. X                int_accum += int1;
  147. X                break;
  148. X            case OP_SUB:
  149. X                int_accum -= int1;
  150. X                break;
  151. X            case OP_MUL:
  152. X                int_accum *= int1;
  153. X                break;
  154. X            case OP_DIV:
  155. X                int_accum /= int1;
  156. X                break;
  157. X            case OP_MOD:
  158. X                int_accum %= int1;
  159. X                break;
  160. X            case OP_XOR:
  161. X                int_accum ^= (unsigned)int1;
  162. X                break;
  163. X            case OP_AND:
  164. X                int_accum &= (unsigned)int1;
  165. X                break;
  166. X            case OP_OR:
  167. X                int_accum |= (unsigned)int1;
  168. X                break;
  169. X            default:
  170. X                return(eInvalidIntOp);
  171. X        }
  172. X    }
  173. X    param->index = param->old_index;
  174. X
  175. X    *int_returned = int_accum;
  176. X    return(0);
  177. X}   /* end of gint() */
  178. X
  179. X/*+-------------------------------------------------------------------------
  180. X    col_range(param,col1,col2) - get a column range
  181. X:$i0[-$i1]
  182. Xargument may be integer constant, function or variable, but not expression
  183. X--------------------------------------------------------------------------*/
  184. Xint
  185. Xgcol_range(param,col1,col2)
  186. XESD *param;
  187. Xulong *col1;
  188. Xulong *col2;
  189. X{
  190. X    register erc;
  191. X
  192. X    if(skip_cmd_char(param,':') == 0)
  193. X    {
  194. X        if(erc = gint_base(param,col1))
  195. X            return(erc);
  196. X
  197. X        if(skip_cmd_char(param,'-') == 0)     /* if hyphen found, range */
  198. X        {
  199. X            if(erc = gint_base(param,col2))
  200. X                return(erc);
  201. X        }
  202. X        else
  203. X            *col2 = *col1;        /* otherwise, first and last columns same */
  204. X
  205. X        if(*col1 > *col2)
  206. X        {
  207. X            pputs("Invalid column range: column 1 greater than column 2\n");
  208. X            return(eFATAL_ALREADY);
  209. X        }
  210. X    }
  211. X    else
  212. X        erc = eBadParameter;
  213. X
  214. X    return(erc);
  215. X}   /* end of gcol_range() */
  216. X
  217. X/* vi: set tabstop=4 shiftwidth=4: */
  218. X/* end of gint.c */
  219. SHAR_EOF
  220. echo 'File gint.c is complete' &&
  221. chmod 0644 gint.c ||
  222. echo 'restore of gint.c failed'
  223. Wc_c="`wc -c < 'gint.c'`"
  224. test 7030 -eq "$Wc_c" ||
  225.     echo 'gint.c: original size 7030, current size' "$Wc_c"
  226. rm -f _shar_wnt_.tmp
  227. fi
  228. # ============= gstr.c ==============
  229. if test -f 'gstr.c' -a X"$1" != X"-c"; then
  230.     echo 'x - skipping gstr.c (File already exists)'
  231.     rm -f _shar_wnt_.tmp
  232. else
  233. > _shar_wnt_.tmp
  234. echo 'x - extracting gstr.c (Text)'
  235. sed 's/^X//' << 'SHAR_EOF' > 'gstr.c' &&
  236. X/*+-------------------------------------------------------------------------
  237. X    gstr.c - ecu get string parameter functions
  238. X    wht@n4hgf.Mt-Park.GA.US
  239. X
  240. X  Defined functions:
  241. X    gstr(param,result,realloc_ok)
  242. X
  243. X--------------------------------------------------------------------------*/
  244. X/*+:EDITS:*/
  245. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  246. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  247. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  248. X/*:05-02-1991-03:54-wht@n4hgf-new realloc algorithm */
  249. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  250. X
  251. X#include "ecu.h"
  252. X#include "ecuerror.h"
  253. X#include "esd.h"
  254. X#include "var.h"
  255. X
  256. Xextern int proctrace;
  257. X
  258. X/*+-------------------------------------------------------------------------
  259. X    gstr(param,result,realloc_ok) - get a string 
  260. X
  261. XExamples:
  262. X
  263. X set $s0='test ... '+%date+' '+%time+%chr(0x0D)+%chr(0x0A)
  264. X hexdump $s0
  265. X0000  74 65 73 74 20 2E 2E 2E 20 30 36 2D 30 39 2D 31 | test ... 06-09-1 |
  266. X0010  39 38 39 20 31 37 3A 31 35 0D 0A                | 989 17:15..      |
  267. X
  268. X set $s0='12345678':1-6+'abc'
  269. X set s0
  270. X$S00 = '234567abc'
  271. X
  272. Xif realloc_ok and string too small, realloc result string as necessary
  273. X
  274. X--------------------------------------------------------------------------*/
  275. Xint
  276. Xgstr(param,result,realloc_ok)
  277. XESD *param;
  278. XESD *result;
  279. Xint realloc_ok;
  280. X{
  281. Xregister char param_char;
  282. Xregister char *pb;
  283. XESD *tesd;
  284. XESD *svptr;
  285. Xint cb = 0;
  286. Xint segment_index;
  287. Xint next_is_literal = 0;    /* last char was not a backslash */
  288. Xulong itmp1;
  289. Xulong itmp2;
  290. Xulong itmp3;
  291. Xulong itmp4;
  292. Xint erc;
  293. Xint param_index_save;
  294. Xint result_remaining;
  295. Xint in_quoted_string = 0;   /* not currently in quoted string */
  296. Xint end_of_parameter = 0;
  297. X
  298. X    if(erc = skip_cmd_break(param))
  299. X        return(erc);
  300. X
  301. X    segment_index = 0;            
  302. X    result_remaining = result->maxcb;    /* number we can put into result */
  303. X    param_index_save = param->index;
  304. X
  305. X    if((tesd = esdalloc(ESD_MAXSIZE)) == (ESD *)0)
  306. X        return(eNoMemory);
  307. X    pb = tesd->pb;
  308. X
  309. XCONCATENATE:
  310. X    while((param->index < param->cb) && !end_of_parameter)
  311. X    {
  312. X        param_char = param->pb[param->index];
  313. X        if(in_quoted_string)
  314. X        {
  315. X            ++param->index;
  316. X            if(next_is_literal)
  317. X            {
  318. X                next_is_literal = 0;
  319. X                switch(param_char)
  320. X                {
  321. X                    case 'b' : param_char = 0x08; break;
  322. X                    case 'n' : param_char = 0x0A; break;
  323. X                    case 'r' : param_char = 0x0D; break;
  324. X                    case 't' : param_char = 0x09; break;
  325. X                    case '\'': param_char = '\''; break;
  326. X                }
  327. X                if((result_remaining-- == 0) &&
  328. X                    (!realloc_ok && (cb == ESD_MAXSIZE)))
  329. X                {
  330. X                    erc = eBufferTooSmall;
  331. X                    goto RETURN;
  332. X                }
  333. X                *(pb + cb++) = param_char;
  334. X            }
  335. X            else if(param_char == '\\')
  336. X                next_is_literal = 1;
  337. X            else if(param_char == '\'')
  338. X                in_quoted_string = 0;
  339. X            else
  340. X            {
  341. X                if((result_remaining-- == 0) &&
  342. X                    (!realloc_ok && (cb == ESD_MAXSIZE)))
  343. X                {
  344. X                    erc = eBufferTooSmall;
  345. X                    goto RETURN;
  346. X                }
  347. X                *(pb + cb++) = param_char;
  348. X            }
  349. X        }
  350. X        else /* not in quoted string */
  351. X        {
  352. X            param->old_index = param->index;
  353. X            switch(param_char)
  354. X            {
  355. X            case '\'':      /* apostrophe denotes literal text */
  356. X                ++param->index;
  357. X                in_quoted_string = 1;
  358. X                break;
  359. X
  360. X            case '%':
  361. X                ++param->index;
  362. X                tesd->cb = cb;
  363. X                if(erc = feval_str(param,tesd))
  364. X                    goto RETURN;
  365. X                cb = tesd->cb;
  366. X                result_remaining = (result->maxcb - cb);
  367. X                break;
  368. X
  369. X            case '$':           /* '$Snn' variable reference? */
  370. X                /* must be at least two more character */
  371. X                if(param->index >= param->cb-2)
  372. X                {
  373. X                    erc = eSyntaxError;
  374. X                    goto RETURN;
  375. X                }
  376. X                param->old_index = ++param->index;
  377. X                if(to_lower(param->pb[param->index++]) != 's' )
  378. X                {
  379. X                    erc = eIllegalVarType;
  380. X                    goto RETURN;
  381. X                }
  382. X                if(erc = get_svptr(param,&svptr,0))
  383. X                    goto RETURN;
  384. X                if((!realloc_ok && (svptr->cb > (result->maxcb - cb))) ||
  385. X                    (svptr->cb > (ESD_MAXSIZE - cb)))
  386. X                {
  387. X                    erc = eBufferTooSmall;
  388. X                    goto RETURN;
  389. X                }
  390. X                else if(svptr->cb)
  391. X                {
  392. X                    memcpy(&pb[cb],svptr->pb,svptr->cb);
  393. X                    cb += svptr->cb;
  394. X                    result_remaining -= svptr->cb;
  395. X                }
  396. X                break;
  397. X
  398. X            case ':':
  399. X/*
  400. X * itmp1 holds col 1 (0-n) of substring operation
  401. X * itmp2 holds col 2 (0-n) of operation adjusted to reflect
  402. X *       end of string segment
  403. X * itmp3 holds length of string segment
  404. X * itmp4 holds length of substring segment output by substring operation
  405. X*/
  406. X                if(erc = gcol_range(param,&itmp1,&itmp2))
  407. X                    goto RETURN;
  408. X                if((itmp3 = cb - segment_index)
  409. X                    &&
  410. X                    (itmp4 = ((itmp2<itmp3)?itmp2:itmp3) - itmp1 + 1))
  411. X                {
  412. X                    if(itmp1)
  413. X                        memcpy(&pb[segment_index],
  414. X                            &pb[segment_index+(int)itmp1],(int)itmp4);
  415. X                    cb -= ((int)itmp3 - (int)itmp4);
  416. X                }
  417. X                break;
  418. X
  419. X            case '+':
  420. X                segment_index = cb;
  421. X                ++param->index;
  422. X                goto CONCATENATE;
  423. X
  424. X            case ';':
  425. X            case '#':
  426. X                end_of_parameter = 1;
  427. X                break;
  428. X
  429. X            default:
  430. X                erc = 0;
  431. X                if((param->index < param->cb) &&
  432. X                    isalnum(*(param->pb + param->index)))
  433. X                    erc = eSyntaxError;
  434. X                else if(param_index_save == param->index)
  435. X                    erc = eBadParameter;
  436. X                end_of_parameter = 1;
  437. X                break;
  438. X            }   /* end of switch (param_char) */
  439. X        }       /* end of else not in quoted string */
  440. X    }           /* end of while(index<cb) */
  441. X
  442. X
  443. XRETURN:
  444. X    if(result_remaining < 0)
  445. X    {
  446. X        if(!realloc_ok)
  447. X            erc = eBufferTooSmall;
  448. X        else
  449. X        {
  450. X            int new_size = (cb + 128) & (~127);    /* speed + anti-fragment */
  451. X            if(new_size > ESD_MAXSIZE)
  452. X                new_size = ESD_MAXSIZE;
  453. X            if(new_size < cb)
  454. X                erc = eBufferTooSmall;
  455. X            else
  456. X                erc = esdrealloc(result,new_size);
  457. X        }
  458. X        if(erc)
  459. X            return(erc);
  460. X    }
  461. X    if(cb)
  462. X        memcpy(result->pb,pb,cb);
  463. X    result->cb = cb;
  464. X    esd_null_terminate(result);
  465. X    esdfree(tesd);
  466. X    return(erc);
  467. X}   /* end of gqstr */
  468. X
  469. X/* vi: set tabstop=4 shiftwidth=4: */
  470. X/* end of qstr.c */
  471. SHAR_EOF
  472. chmod 0644 gstr.c ||
  473. echo 'restore of gstr.c failed'
  474. Wc_c="`wc -c < 'gstr.c'`"
  475. test 5625 -eq "$Wc_c" ||
  476.     echo 'gstr.c: original size 5625, current size' "$Wc_c"
  477. rm -f _shar_wnt_.tmp
  478. fi
  479. # ============= hdbintf.c ==============
  480. if test -f 'hdbintf.c' -a X"$1" != X"-c"; then
  481.     echo 'x - skipping hdbintf.c (File already exists)'
  482.     rm -f _shar_wnt_.tmp
  483. else
  484. > _shar_wnt_.tmp
  485. echo 'x - extracting hdbintf.c (Text)'
  486. sed 's/^X//' << 'SHAR_EOF' > 'hdbintf.c' &&
  487. X#if defined(SHARE_DEBUG)
  488. X#define LOG_UNGETTY
  489. X#define LOG_HDBDIAL
  490. X#endif
  491. X
  492. X/* #define CHOOSE_DEBUG */
  493. X
  494. X/*+-------------------------------------------------------------------------
  495. X    hdbintf.c - HDB UUCP database and /etc/utmp interface routines
  496. X    wht@n4hgf.Mt-Park.GA.US
  497. X
  498. X  Defined functions:
  499. X    _ungetty_return_line(line)
  500. X    add_to_ungetty_list(line)
  501. X    dialcodes_translate(phone)
  502. X    dialstr_translate(translate_list,to_translate)
  503. X    display_ungetty_list()
  504. X    dvtype_match(typespec,dvtype)
  505. X    enddlent()
  506. X    enddvent()
  507. X    getdlent()
  508. X    getdlentname(name)
  509. X    getdvbaud(baud)
  510. X    getdvent()
  511. X    getdvline(line)
  512. X    getdvtype(type)
  513. X    hdb_choose_Any(baud)
  514. X    hdb_choose_Device(type,baud)
  515. X    hdb_dial(presult)
  516. X    hdb_dial_error_text(errcode)
  517. X    hdb_init()
  518. X    in_ungetty_list(line)
  519. X    malformed_Devices_entry(text,ntokens,tokens)
  520. X    remove_from_ungetty_list(line)
  521. X    reserve_line(line)
  522. X    strip_phone_num(sptr)
  523. X    ugstat_text(ugstat)
  524. X    ungetty_get_line(line)
  525. X    ungetty_return_all_but(line)
  526. X    ungetty_return_line(line)
  527. X
  528. XDate: Fri, 23 Aug 91 18:30:06 +0300 (MSD)
  529. XFrom: emory!hq.demos.su!ache (Andrew A. Chernov, canton Uri's citizen)
  530. X1) HDB dialers may return connect speed as return code (!= 0)
  531. X2) Using HDB Dialcodes file for phone numbers translation now
  532. X   (\D,\T escape sequence)
  533. X
  534. X--------------------------------------------------------------------------*/
  535. X/*+:EDITS:*/
  536. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  537. X/*:09-10-1992-03:35-wht@n4hgf-change the way we flunk a line=="-" */
  538. X/*:09-04-1992-19:08-wht@n4hgf-harden Devices parsing */
  539. X/*:08-29-1992-15:37-wht@n4hgf-absolutely prohibit /dev/tty fed to ecuungetty */
  540. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  541. X/*:07-21-1992-17:20-wht@n4hgf-hdb_dial of "/=" type bug fixed */
  542. X/*:07-19-1992-22:12-wht@n4hgf-move old check_utmp here+call it reserve_line */
  543. X/*:07-19-1992-10:07-wht@n4hgf-add ungetty_return_all_but */
  544. X/*:07-19-1992-09:11-wht@n4hgf-validate tty line name before ungetty get */
  545. X/*:06-07-1992-17:05-wht@n4hgf-lock tty before ungetty get */
  546. X/*:05-13-1992-13:27-wht@n4hgf-active_pde use */
  547. X/*:05-13-1992-10:30-cma@ifsbd-Add baud rate checking to hdb_dial function */
  548. X/*:05-04-1992-04:45-wht@n4hgf-wrong sense of strcmp in ,M test for SVR4 */
  549. X/*:04-28-1992-03:29-wht@n4hgf-more fixes for abend due to line problems */
  550. X/*:04-27-1992-20:02-wht@n4hgf-add ecuungetty error reporting */
  551. X/*:04-25-1992-13:02-wht@n4hgf-some exits from hdb_choose_Any omitted enddvent */
  552. X/*:04-24-1992-21:59-wht@n4hgf-more SCO tty name normalizing */
  553. X/*:04-19-1992-03:21-jhpb@sarto.budd-lake.nj.us-3.18.37 has ESIX SVR4 */
  554. X/*:01-18-1992-13:29-root@n4hgf-use proctrace value for expresp_verbosity */
  555. X/*:11-15-1991-04:02-wht@n4hgf-SCO tty naming now observed in getdvline */
  556. X/*:09-01-1991-16:20-wht@n4hgf2-generalize HDB configuration files location */
  557. X/*:09-01-1991-02:27-wht@n4hgf2-dialer gets file name instead of "ECUdial" */
  558. X/*:08-25-1991-13:07-wht@n4hgf-apply ache@hq.demos.su patches */
  559. X/*:08-10-1991-17:39-wht@n4hgf-US_WEGOTIT handling */
  560. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  561. X/*:06-02-1991-17:42-wht@n4hgf-add getdvtype */
  562. X/*:06-02-1991-17:27-wht@n4hgf-hdb_choose_Device + move hdb_choose_Any here */
  563. X/*:10-16-1990-20:43-wht@n4hgf-add SHARE_DEBUG */
  564. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  565. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  566. X
  567. X#include "ecu.h"
  568. X#include "ecupde.h"
  569. X#include "esd.h"
  570. X#include "var.h"
  571. X#include "termecu.h"
  572. X#include "utmpstatus.h"
  573. X#include "ecuungetty.h"
  574. X#include "dvent.h"
  575. X#include "dlent.h"
  576. X#include "dialprog.h"
  577. X#include <errno.h>
  578. X#include <utmp.h>
  579. X
  580. Xchar *arg_token();
  581. Xchar *skip_ld_break();
  582. Xchar *dialcodes_translate();
  583. Xchar *strip_phone_num();
  584. X
  585. Xextern char kbdintr;        /* current input INTR */
  586. Xextern ulong colors_current;
  587. Xextern int proctrace;
  588. Xextern int expresp_verbosity;
  589. X
  590. Xint there_is_hdb_on_this_machine = 0;
  591. Xstatic FILE *fpdv = (FILE *)0;
  592. Xstatic FILE *fpdl = (FILE *)0;
  593. Xchar *Devices_file = "/usr/lib/uucp/Devices";
  594. Xchar *Dialers_file = "/usr/lib/uucp/Dialers";
  595. Xchar *Dialcodes_file = "/usr/lib/uucp/Dialcodes";
  596. Xuchar last_ugstat = 0;
  597. X
  598. X#define UNGETTY_LIST_MAX    3
  599. Xchar *ungetty_list[UNGETTY_LIST_MAX];
  600. X
  601. X/*+-------------------------------------------------------------------------
  602. X    display_ungetty_list() - display ungetty list with pputs()
  603. X--------------------------------------------------------------------------*/
  604. X#if defined(USE_ECUUNGETTY)
  605. Xvoid
  606. Xdisplay_ungetty_list()
  607. X{
  608. X    int itmp;
  609. X    int found_one = 0;
  610. X
  611. X    for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++)
  612. X    {
  613. X        if(*ungetty_list[itmp])
  614. X        {
  615. X            found_one = 1;
  616. X            break;
  617. X        }
  618. X    }
  619. X
  620. X    if(!found_one)
  621. X    {
  622. X        pputs("No lines acquired by ecuungetty\n");
  623. X        return;
  624. X    }
  625. X
  626. X    pputs("Acquired by ecuungetty: ");
  627. X    for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++)
  628. X    {
  629. X        if(*ungetty_list[itmp])
  630. X        {
  631. X            pputs(ungetty_list[itmp]);
  632. X            pputs(" ");
  633. X        }
  634. X    }
  635. X    pputs("\n");
  636. X
  637. X}    /* end of display_ungetty_list */
  638. X#endif /* defined(USE_ECUUNGETTY) */
  639. X
  640. X/*+-------------------------------------------------------------------------
  641. X    in_ungetty_list(line) - check for line present in ungetty list
  642. X--------------------------------------------------------------------------*/
  643. X#if defined(USE_ECUUNGETTY)
  644. Xint
  645. Xin_ungetty_list(line)
  646. Xchar *line;
  647. X{
  648. X    int itmp;
  649. X
  650. X    for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++)
  651. X    {
  652. X        if(!strcmp(line,ungetty_list[itmp]))
  653. X            return(1);
  654. X    }
  655. X    return(0);
  656. X
  657. X}    /* end of in_ungetty_list */
  658. X#endif /* defined(USE_ECUUNGETTY) */
  659. X
  660. X/*+-------------------------------------------------------------------------
  661. X    add_to_ungetty_list(line) - add line to ungetty list
  662. X--------------------------------------------------------------------------*/
  663. X#if defined(USE_ECUUNGETTY)
  664. Xvoid
  665. Xadd_to_ungetty_list(line)
  666. Xchar *line;
  667. X{
  668. X    int itmp;
  669. X    char *lptr;
  670. X
  671. X    if(in_ungetty_list(line))
  672. X        return;
  673. X
  674. X    for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++)
  675. X    {
  676. X        if(!*(lptr = ungetty_list[itmp]))
  677. X        {
  678. X            strcpy(lptr,line);
  679. X            return;
  680. X        }
  681. X    }
  682. X    ecu_log_event(getpid(),"ungetty_list overflow");
  683. X    termecu(TERMECU_LOGIC_ERROR);
  684. X    /*NOTREACHED*/
  685. X
  686. X}    /* end of add_to_ungetty_list */
  687. X#endif /* defined(USE_ECUUNGETTY) */
  688. X
  689. X/*+-------------------------------------------------------------------------
  690. X    remove_from_ungetty_list(line) - remove line from ungetty list
  691. X--------------------------------------------------------------------------*/
  692. X#if defined(USE_ECUUNGETTY)
  693. Xvoid
  694. Xremove_from_ungetty_list(line)
  695. Xchar *line;
  696. X{
  697. X    int itmp;
  698. X    char *lptr;
  699. X
  700. X    for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++)
  701. X    {
  702. X        if(!strcmp((lptr = ungetty_list[itmp]),line))
  703. X        {
  704. X            *lptr = 0;
  705. X            return;
  706. X        }
  707. X    }
  708. X
  709. X#ifdef CHOOSE_DEBUG
  710. X    {
  711. X        char s128[128];
  712. X        sprintf(s128,"remove_from_ungetty_list failed for %s",line);
  713. X        ecu_log_event(getpid(),s128);
  714. X    }
  715. X#endif
  716. X
  717. X}    /* end of remove_from_ungetty_list */
  718. X#endif /* defined(USE_ECUUNGETTY) */
  719. X
  720. X/*+-------------------------------------------------------------------------
  721. X    ugstat_text(ugstat) - text for ecuungetty code
  722. X--------------------------------------------------------------------------*/
  723. Xchar *
  724. Xugstat_text(ugstat)
  725. Xint ugstat;
  726. X{
  727. X    static char errant[32];
  728. X
  729. X    switch(ugstat)
  730. X    {
  731. X        case UG_NOTENAB:
  732. X            return("line not enabled");
  733. X            break;
  734. X        case UG_RESTART:
  735. X            return("restart needed");
  736. X            break;
  737. X        case UG_FAIL:
  738. X            return("line in use");
  739. X            break;
  740. X        case UGE_T_LOGIN:
  741. X            return("-t found US_LOGIN");
  742. X            break;
  743. X        case UGE_T_LOGGEDIN:
  744. X            return("-t found US_LOGGGEDIN");
  745. X            break;
  746. X        case UGE_T_NOTFOUND:
  747. X            return("not found");
  748. X            break;
  749. X        case UGE_BADSWITCH:
  750. X            return("usage: bad switch");
  751. X            break;
  752. X        case UGE_BADARGC:
  753. X            return("usage: bad arg count");
  754. X            break;
  755. X        case UGE_BADARGV:
  756. X            return("this a valid tty??");
  757. X            break;
  758. X        case UGE_NOTROOT:
  759. X            return("not setuid root");
  760. X            break;
  761. X        case UGE_CALLER:
  762. X            return("invalid caller");
  763. X            break;
  764. X        case UGE_NOUUCP:
  765. X            return("cannot find uucp passwd entry");
  766. X            break;
  767. X        case UGE_LOGIC:
  768. X            return("logic error");
  769. X            break;
  770. X        case UGE_BOMB:
  771. X            return("core dumped or killed");
  772. X            break;
  773. X        case UGE_DNE:
  774. X            return("did not execute");
  775. X            break;
  776. X    }
  777. X    sprintf(errant,"error %u",ugstat);
  778. X    return(errant);
  779. X}    /* end of ugstat_text */
  780. X
  781. X/*+-------------------------------------------------------------------------
  782. X    ungetty_get_line(line) - acquire a line through ecuungetty protocol
  783. X--------------------------------------------------------------------------*/
  784. Xint
  785. Xungetty_get_line(line)
  786. Xchar *line;
  787. X{
  788. X#if !defined(USE_ECUUNGETTY)
  789. X    return(0);
  790. X#else
  791. X    int itmp;
  792. X    int rtn = 0;
  793. X    int we_locked = 0;
  794. X    int ungetty_pid;
  795. X    SIGTYPE (*original_sighdlr)();
  796. X    int wait_status;
  797. X    char ungetty[128];
  798. X    char ungetty_log[80];
  799. X    char bamboozlement[20];
  800. X    struct stat st;
  801. X    char *bamboozle();
  802. X
  803. X    /*
  804. X     * quick check - ecuungetty does a much better job
  805. X     */
  806. X    if(!strcmp(line,"/dev/tty")) /* some keep getting /dev/tty chown'd! */
  807. X        return(LINST_INVALID);
  808. X    if(stat(line,&st))
  809. X    {
  810. X        if(errno == ENOENT)
  811. X            return(LINST_NODEV);
  812. X        return(LINST_OPNFAIL);
  813. X    }
  814. X    if((st.st_mode & S_IFMT) != S_IFCHR)
  815. X        return(LINST_NOTCHR);
  816. X    if(!there_is_hdb_on_this_machine)
  817. X        return(0);
  818. X    if(in_ungetty_list(line))
  819. X        return(0);
  820. X
  821. X    /*
  822. X     * lock line before ecuungetty call
  823. X     */
  824. X    if((itmp = lock_tty(line)) && (itmp != LINST_WEGOTIT))
  825. X        return(itmp);
  826. X    we_locked = (!itmp);
  827. X
  828. X    sprintf(ungetty,"%s/ecuungetty",ECULIBDIR);
  829. X    strcpy(bamboozlement,bamboozle(getpid()));
  830. X    if(access(ungetty,1))
  831. X    {
  832. X        pperror(ungetty);
  833. X        rtn = LINST_ENABLED;
  834. X        goto RETURN;
  835. X    }
  836. X    original_sighdlr = signal(SIGCLD,SIG_DFL);
  837. X    if((ungetty_pid = smart_fork()) == 0)
  838. X    {
  839. X        execl(ungetty,"ungetty",line,bamboozlement,(char *)0);
  840. X        _exit(UGE_DNE);    /* did not execute */
  841. X    }
  842. X    while(((itmp = wait(&wait_status)) != ungetty_pid) && (itmp != -1))
  843. X        ;
  844. X    signal(SIGCLD,original_sighdlr);
  845. X
  846. X    if(wait_status & 0xFF)
  847. X        last_ugstat = UGE_BOMB;
  848. X    else
  849. X        last_ugstat = (uchar)(wait_status >> 8);
  850. X    switch(last_ugstat)
  851. X    {
  852. X        case UG_NOTENAB:    /* line acquired: not enabled */
  853. X            break;
  854. X
  855. X        case UG_RESTART:    /* line acquired: need ungetty -r when done */
  856. X#if defined(LOG_UNGETTY)
  857. X            sprintf(ungetty_log,"UNGETTY acquired %s",shm->Lline);
  858. X            ecu_log_event(getpid(),ungetty_log);
  859. X#endif
  860. X            add_to_ungetty_list(line);
  861. X            break;
  862. X
  863. X        case UG_FAIL:        /* line in use */
  864. X            rtn = LINST_ENABLED_IN_USE;
  865. X            break;
  866. X
  867. X        default:
  868. X            sprintf(ungetty_log,"UNGETTY status 0x%04x: %s",
  869. X                wait_status,ugstat_text(last_ugstat));
  870. X            ecu_log_event(getpid(),ungetty_log);
  871. X            rtn = (last_ugstat == UGE_BOMB)
  872. X                ? LINST_ECUUNGETTY2 : LINST_ECUUNGETTY;
  873. X            break;
  874. X    }
  875. X
  876. XRETURN: ;
  877. X    if(rtn && we_locked)
  878. X        unlock_tty(line);
  879. X    return(rtn);
  880. X
  881. X#endif /* !defined(USE_ECUUNGETTY) */
  882. X}    /* end of ungetty_get_line */
  883. X
  884. X/*+-------------------------------------------------------------------------
  885. X    reserve_line(line)
  886. Xreturn 0 if line reserved, else LINST code
  887. X--------------------------------------------------------------------------*/
  888. Xint
  889. Xreserve_line(line)
  890. Xchar *line;
  891. X{
  892. Xregister utstatus;
  893. Xregister status = 0;
  894. X
  895. X    switch(utstatus = utmp_status(line))
  896. X    {
  897. X        case US_DIALOUT:    /* enabled for login, currently dialout */
  898. X            status = LINST_DIALOUT_IN_USE;
  899. X            break;
  900. X        case US_LOGGEDIN:   /* enabled for login, in use */
  901. X            status = LINST_ENABLED_IN_USE;
  902. X            break;
  903. X        case US_NOTFOUND:   /* not in utmp, or getty dead */
  904. X            break;
  905. X        case US_WEGOTIT:    /* we own the line */
  906. X            status = LINST_WEGOTIT;   /* not really an error */
  907. X            break;
  908. X        case US_LOGIN:      /* enabled for login, idle */
  909. X            status = ungetty_get_line(line);
  910. X            break;
  911. X    }
  912. X
  913. X#if defined(LOG_LOCKS)
  914. X    {
  915. X        char s64[64];
  916. X        sprintf(s64,"UTMPCHK %s st=%d ut=%d",line,status,utstatus);
  917. X        ecu_log_event(getpid(),s64);
  918. X    }
  919. X#endif
  920. X
  921. X    return(status);
  922. X
  923. X}   /* end of reserve_line */
  924. X
  925. X/*+-------------------------------------------------------------------------
  926. X    _ungetty_return_line(line) - return line to "getty" status
  927. X--------------------------------------------------------------------------*/
  928. Xvoid
  929. X_ungetty_return_line(line)
  930. Xchar *line;
  931. X{
  932. X#if !defined(USE_ECUUNGETTY)
  933. X    return;
  934. X#else
  935. X    int ungetty_pid;
  936. X    int itmp;
  937. X    SIGTYPE (*original_sighdlr)();
  938. X    int wait_status = 0xDEAD;
  939. X    char ungetty[128];
  940. X#if defined(LOG_UNGETTY)
  941. X    char ungetty_log[80];
  942. X#endif
  943. X    char bamboozlement[20];
  944. X    char *bamboozle();
  945. X
  946. X    if(!there_is_hdb_on_this_machine)
  947. X        return;
  948. X    if(!in_ungetty_list(line))
  949. X        return;
  950. X
  951. X    sprintf(ungetty,"%s/ecuungetty",ECULIBDIR);
  952. X    strcpy(bamboozlement,bamboozle(getpid()));
  953. X
  954. X    /* call ungetty to see if we need to switch to dialin */
  955. X#if 0 /* if in_ungetty_list, trust we need to -r */
  956. X    if(access(ungetty,1))
  957. X    {
  958. X        pperror(ungetty);
  959. X        return;
  960. X    }
  961. X    original_sighdlr = signal(SIGCLD,SIG_DFL);
  962. X    if((ungetty_pid = smart_fork()) == 0)
  963. X    {
  964. X        execl(ungetty,"ungetty","-t",line,bamboozlement,(char *)0);
  965. X        ecu_log_event(getpid(),"could not exec ecuungetty -t");
  966. X        _exit(UGE_DNE);    /* did not execute */
  967. X    }
  968. X    while(((itmp = wait(&wait_status)) != ungetty_pid) &&
  969. X            (itmp != -1) )
  970. X        ;
  971. X    signal(SIGCLD,original_sighdlr);
  972. X
  973. X#if defined(LOG_UNGETTY)
  974. X    sprintf(ungetty_log,"UNGETTY -t %s status %04x",line,wait_status);
  975. X    ecu_log_event(getpid(),ungetty_log);
  976. X#endif
  977. X    switch((uchar)(wait_status >> 8))
  978. X    {
  979. X        case UG_RESTART:
  980. X            break;
  981. X
  982. X        default:
  983. X            remove_from_ungetty_list(line);
  984. X            return;
  985. X    }
  986. X#endif
  987. X
  988. X    original_sighdlr = signal(SIGCLD,SIG_DFL);
  989. X    if((ungetty_pid = smart_fork()) == 0)
  990. X    {
  991. X        execl(ungetty,"ungetty","-r",line,bamboozlement,(char *)0);
  992. X        ecu_log_event(getpid(),"could not exec ecuungetty -r");
  993. X        _exit(UGE_DNE);    /* did not execute */
  994. X    }
  995. X
  996. X    while(((itmp = wait(&wait_status)) != ungetty_pid) &&
  997. X            (itmp != -1))
  998. X        ;
  999. X
  1000. X#if defined(LOG_UNGETTY)
  1001. X    if(wait_status)
  1002. X    {
  1003. X        sprintf(ungetty_log,"UNGETTY -r %s status 0x%04x",
  1004. X            line,wait_status);
  1005. X    }
  1006. X    else
  1007. X        sprintf(ungetty_log,"UNGETTY returned %s",line);
  1008. X    ecu_log_event(getpid(),ungetty_log);
  1009. X#endif
  1010. X
  1011. X    remove_from_ungetty_list(line);
  1012. X
  1013. X#endif /* !defined(USE_ECUUNGETTY) */
  1014. X}    /* end of _ungetty_return_line */
  1015. X
  1016. X/*+-------------------------------------------------------------------------
  1017. X    ungetty_return_line(line) - return one or all lines to "getty" status
  1018. X--------------------------------------------------------------------------*/
  1019. Xvoid
  1020. Xungetty_return_line(line)
  1021. Xchar *line;
  1022. X{
  1023. X#if !defined(USE_ECUUNGETTY)
  1024. X    return;
  1025. X#else
  1026. X    int itmp;
  1027. X
  1028. X    if(line)
  1029. X        _ungetty_return_line(line);
  1030. X    else
  1031. X    {
  1032. X        for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++)
  1033. X        {
  1034. X            if(*(line = ungetty_list[itmp]))
  1035. X                _ungetty_return_line(line);
  1036. X        }
  1037. X    }
  1038. X
  1039. X#endif /* !defined(USE_ECUUNGETTY) */
  1040. X}    /* end of ungetty_return_line */
  1041. X
  1042. X/*+-------------------------------------------------------------------------
  1043. X    ungetty_return_all_but(line) - return all lines but 'line'
  1044. X--------------------------------------------------------------------------*/
  1045. Xvoid
  1046. Xungetty_return_all_but(line)
  1047. Xchar *line;
  1048. X{
  1049. X#if !defined(USE_ECUUNGETTY)
  1050. X    return;
  1051. X#else
  1052. X    int itmp;
  1053. X
  1054. X    for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++)
  1055. X    {
  1056. X        if(ungetty_list[itmp][0] && strcmp(line,ungetty_list[itmp]))
  1057. X            _ungetty_return_line(line);
  1058. X    }
  1059. X
  1060. X#endif /* !defined(USE_ECUUNGETTY) */
  1061. X}    /* end of ungetty_return_all_but */
  1062. X
  1063. X/*+-------------------------------------------------------------------------
  1064. X    malformed_Devices_entry(text,ntokens,tokens)
  1065. X--------------------------------------------------------------------------*/
  1066. Xvoid
  1067. Xmalformed_Devices_entry(text,ntokens,tokens)
  1068. Xchar *text;
  1069. Xint ntokens;
  1070. Xchar **tokens;
  1071. X{
  1072. X    char s512[512];
  1073. X    char *cptr;
  1074. X    char *nlptr;
  1075. X    static already = 0;
  1076. X    extern int tty_not_char_special;
  1077. X
  1078. X    sprintf(s512,"malformed Devices entry (%s):\n",text);
  1079. X    cptr = s512 + strlen(s512);
  1080. X    nlptr = cptr - 1;
  1081. X
  1082. X    while(ntokens--)
  1083. X    {
  1084. X        if(((cptr - s512) + strlen(*tokens) + 2) > sizeof(s512))
  1085. X            break;
  1086. X        sprintf(cptr,"%s ",*tokens++);
  1087. X        cptr += strlen(cptr);
  1088. X    }
  1089. X
  1090. X    if(!already && !tty_not_char_special)
  1091. X    {
  1092. X        pputs("\7\n");
  1093. X        pputs(s512);
  1094. X        pputs("\nFurther Devices errors will not be displayed,\n");
  1095. X        pputs("but are logged in ~/.ecu/log.  Press any key to continue.\7");
  1096. X        ttyflush(0);
  1097. X        ttygetc(1);
  1098. X        pputs("\n");
  1099. X    }
  1100. X    already = 1;
  1101. X
  1102. X    memcpy(s512,"MALFORMED",9);        /* mod for log file */
  1103. X    *nlptr = ' ';
  1104. X    ecu_log_event(xmtr_pid,s512);
  1105. X
  1106. X}    /* end of malformed_Devices_entry */
  1107. X
  1108. X/*+-------------------------------------------------------------------------
  1109. X    getdvent() - get first or next Devices entry (a la getpwent)
  1110. X--------------------------------------------------------------------------*/
  1111. XDVE *
  1112. Xgetdvent()
  1113. X{
  1114. X#define MAX_DV_TOKENS 9
  1115. X    char *tokens[MAX_DV_TOKENS];
  1116. X    int ntokens;
  1117. X#if 0
  1118. X    int itokens;
  1119. X#endif
  1120. X    char *cptr;
  1121. X    static DVE dve;
  1122. X    static char dvstr[256];
  1123. X    char *strchr();
  1124. X    char *skip_ld_break();
  1125. X
  1126. X    if(!there_is_hdb_on_this_machine)
  1127. X        goto RETURN_NULL;
  1128. X
  1129. X    if(!fpdv)
  1130. X    {
  1131. X        if(!(fpdv = fopen(Devices_file,"r")))
  1132. X        {
  1133. X            pperror(Devices_file);
  1134. X            goto RETURN_NULL;
  1135. X        }
  1136. X    }
  1137. X
  1138. X    while(1)
  1139. X    {
  1140. X        /*
  1141. X         * read a Devices line
  1142. X         */
  1143. X        if(!fgets(dvstr,sizeof(dvstr),fpdv))
  1144. X        {
  1145. XRETURN_NULL:
  1146. X#ifdef CHOOSE_DEBUG
  1147. X            ecu_log_event(xmtr_pid,"getdvent returning NULL");
  1148. X#endif
  1149. X            return((DVE *)0);
  1150. X        }
  1151. X
  1152. X        /*
  1153. X         * weed out comments and blank lines
  1154. X         */
  1155. X        if(strlen(dvstr) <= 1)                    /* blank line */
  1156. X            continue;
  1157. X        cptr = skip_ld_break(dvstr);            /* first non-blank */
  1158. X        if(!*cptr || strchr("#\n",*cptr))        /* comment or all white space */
  1159. X            continue;
  1160. X
  1161. X        /*
  1162. X         * tokenize
  1163. X         */
  1164. X        build_arg_array(dvstr,tokens,MAX_DV_TOKENS,&ntokens);
  1165. X
  1166. X        /*
  1167. X         * honor '#' whever it occurs
  1168. X         */
  1169. X#if 0
  1170. X        for(itokens = 0; itokens < ntokens; itokens++)
  1171. X        {
  1172. X            if(!tokens[itokens])
  1173. X                tokens[itokens] = "";
  1174. X            if(cptr = strchr(tokens[itokens],'#'))
  1175. X            {
  1176. X                *cptr = 0;
  1177. X                ntokens = itokens + 1;
  1178. X                break;
  1179. X            }
  1180. X        }
  1181. X#endif
  1182. X
  1183. X        /*
  1184. X         * a bit of validation
  1185. X         */
  1186. X        if(ntokens < 4)
  1187. X        {
  1188. X            malformed_Devices_entry("too few fields",ntokens,tokens);
  1189. X            continue;
  1190. X        }
  1191. X
  1192. X        /*
  1193. X         * TCP,et - - Any TCP - 
  1194. X         * found in Sun Devices (UUCP over TCP)
  1195. X         */
  1196. X#if 0    /* leave this generic; handle in getdvbaud and getdvtype */
  1197. X        if(!strcmp(tokens[1],"-"))
  1198. X        {
  1199. X            malformed_Devices_entry("bad tty specified",ntokens,tokens);
  1200. X            continue;
  1201. X        }
  1202. X#endif
  1203. X
  1204. X        break;
  1205. X    }
  1206. X
  1207. X    /*
  1208. X     * we have a good entry
  1209. X     */
  1210. X    dve.type = tokens[0];
  1211. X    dve.line = tokens[1];
  1212. X
  1213. X#if defined(SVR4)
  1214. X    { /* get rid of possible SVR4 ",M" modem control suffix */
  1215. X        int itmp;
  1216. X        itmp = strlen(dve.line);
  1217. X        if((itmp > 2) && !strcmp(dve.line + itmp - 2,",M"))
  1218. X          dve.line[itmp - 2] = 0;
  1219. X    }
  1220. X#endif /* SVR4 */
  1221. X
  1222. X    dve.dialer = tokens[2];
  1223. X    if(!strcmpi(tokens[3],"Any"))
  1224. X    {
  1225. X        dve.low_baud = 1;
  1226. X        dve.high_baud = 65535;
  1227. X    }
  1228. X    else
  1229. X    {
  1230. X        dve.low_baud = atoi(tokens[3]);
  1231. X        if(!(cptr = strchr(tokens[3],'-')))
  1232. X            dve.high_baud = dve.low_baud;
  1233. X        else
  1234. X            dve.high_baud = atoi(cptr + 1);
  1235. X    }
  1236. X    dve.dialprog = tokens[4];
  1237. X    dve.token = tokens[5];
  1238. X#ifdef CHOOSE_DEBUG
  1239. X    {
  1240. X        char s256[256];
  1241. X        sprintf(s256,"getdvent returning '%s' type='%s'",dve.line,dve.type);
  1242. X        ecu_log_event(xmtr_pid,s256);
  1243. X    }
  1244. X#endif
  1245. X    return(&dve);
  1246. X
  1247. X}    /* end of getdvent */
  1248. X
  1249. X/*+-------------------------------------------------------------------------
  1250. X    enddvent() - close Devices file
  1251. X--------------------------------------------------------------------------*/
  1252. Xvoid
  1253. Xenddvent()
  1254. X{
  1255. X    if(fpdv)
  1256. X    {
  1257. X        fclose(fpdv);
  1258. X        fpdv = (FILE *)0;
  1259. X    }
  1260. X}    /* end of enddvent */
  1261. X
  1262. X/*+-------------------------------------------------------------------------
  1263. X    getdvbaud(baud) - get Devices entry matching baud rate
  1264. X--------------------------------------------------------------------------*/
  1265. XDVE *
  1266. Xgetdvbaud(baud)
  1267. Xuint baud;
  1268. X{
  1269. X    DVE *tdve;
  1270. X
  1271. X#ifdef CHOOSE_DEBUG
  1272. X    char s128[128];
  1273. X
  1274. X    sprintf(s128,"getdvbaud looking for %u baud",baud);
  1275. X    ecu_log_event(getpid(),s128);
  1276. X#endif
  1277. X
  1278. X    while(1)
  1279. X    {
  1280. X        if((tdve = getdvent()) == (DVE *)0)
  1281. X            return(tdve);
  1282. X#ifdef CHOOSE_DEBUG
  1283. X        sprintf(s128,"getdvbaud found %s type '%s' baud lo=%d hi=%d",
  1284. X            tdve->line,tdve->type,tdve->low_baud,tdve->high_baud);
  1285. X        
  1286. X        ecu_log_event(getpid(),s128);
  1287. X#endif
  1288. X        if(!strcmp(tdve->line,"-"))    /* neo-entries like TCP have "-" line */
  1289. X            continue;
  1290. X        if((tdve->low_baud <= baud) && (baud <= tdve->high_baud))
  1291. X        {
  1292. X#ifdef CHOOSE_DEBUG
  1293. X            sprintf(s128,"getdvbaud returning %s",tdve->line);
  1294. X            ecu_log_event(getpid(),s128);
  1295. X#endif
  1296. X            return(tdve);
  1297. X        }
  1298. X    }
  1299. X    /*NOTREACHED*/
  1300. X
  1301. X}    /* end of getdvbaud */
  1302. X
  1303. X/*+-------------------------------------------------------------------------
  1304. X    getdvline(line) - get Devices entry matching line
  1305. Xcalling argument 'line's is string AFTER "/dev/"
  1306. X--------------------------------------------------------------------------*/
  1307. XDVE *
  1308. Xgetdvline(line)
  1309. Xchar *line;
  1310. X{
  1311. X    DVE *tdve;
  1312. X
  1313. X#ifdef CHOOSE_DEBUG
  1314. X    char s128[128];
  1315. X
  1316. X    sprintf(s128,"getdvline looking for %s",line);
  1317. X    ecu_log_event(getpid(),s128);
  1318. X#endif
  1319. X
  1320. X    while(1)
  1321. X    {
  1322. X        if((tdve = getdvent()) == (DVE *)0)
  1323. X            return(tdve);
  1324. X#ifdef CHOOSE_DEBUG
  1325. X        sprintf(s128,"getdvline %s found baud lo=%d hi=%d",tdve->line,
  1326. X            tdve->low_baud, tdve->high_baud);
  1327. X        ecu_log_event(getpid(),s128);
  1328. X#endif
  1329. X        if(!TTYNAME_STRCMP(tdve->line,line))
  1330. X            return(tdve);
  1331. X    }
  1332. X    /*NOTREACHED*/
  1333. X
  1334. X}    /* end of getdvline */
  1335. X
  1336. X/*+-------------------------------------------------------------------------
  1337. X    dvtype_match(typespec,dvtype) - match between pde typespec and dvtype
  1338. X
  1339. Xreturns 1 if pde type specification 'typespec' matches Devices device 'type'
  1340. X--------------------------------------------------------------------------*/
  1341. Xint
  1342. Xdvtype_match(typespec,dvtype)
  1343. Xchar *typespec;
  1344. Xchar *dvtype;
  1345. X{
  1346. X    char *emsg;
  1347. X    char *match;
  1348. X    int matchlen;
  1349. X    int re_match = 1;
  1350. X    char cmpbuf[128];
  1351. X
  1352. X    if(*typespec == '=')
  1353. X        typespec++;
  1354. X    else if(*typespec == '/')
  1355. X    {
  1356. X        re_match = 0;
  1357. X        typespec++;
  1358. X    }
  1359. X
  1360. X    if(re_match)
  1361. X    {
  1362. X        if(!strcmp(dvtype,typespec))
  1363. X            return(1);
  1364. X    }
  1365. X    else
  1366. X    {
  1367. X        if(regexp_compile(typespec,cmpbuf,sizeof(cmpbuf),&emsg))
  1368. X            return(0);
  1369. X        if(regexp_scan(cmpbuf,dvtype,&match,&matchlen))
  1370. X            return(1);
  1371. X    }
  1372. X    return(0);
  1373. X
  1374. X}    /* end of dvtype_match */
  1375. X
  1376. X/*+-------------------------------------------------------------------------
  1377. X    getdvtype(type) - get Devices entry matching type
  1378. X
  1379. Xtype is either 'Device_type'   search for exact match on Device_type
  1380. X               '=Device_type'  search for exact match on Device_type
  1381. X               '/regexp'       search for match with regular expression
  1382. X
  1383. Xyou must make sure any supplied regexp is a valid one, for regexp
  1384. Xcompilation errors are indistinguishable from other seach failures
  1385. X
  1386. Xuses optimized implementation of dvtype_match functionality
  1387. X--------------------------------------------------------------------------*/
  1388. XDVE *
  1389. Xgetdvtype(type)
  1390. Xchar *type;
  1391. X{
  1392. X    DVE *tdve;
  1393. X    char *emsg;
  1394. X    char *match;
  1395. X    int matchlen;
  1396. X    int re_match = 0;    /* regular expression match */
  1397. X    char cmpbuf[128];
  1398. X
  1399. X    if(*type == '=')
  1400. X        type++;
  1401. X    else if(*type == '/')
  1402. X    {
  1403. X        re_match = 1;
  1404. X        type++;
  1405. X        if(regexp_compile(type,cmpbuf,sizeof(cmpbuf),&emsg))
  1406. X            return((DVE *)0);
  1407. X    }
  1408. X
  1409. X    while(tdve = getdvent())
  1410. X    {
  1411. X        if(!strcmp(tdve->line,"-"))    /* neo-entries like TCP have "-" line */
  1412. X            continue;
  1413. X        if(re_match)
  1414. X        {
  1415. X            if(regexp_scan(cmpbuf,tdve->type,&match,&matchlen))
  1416. X                break;
  1417. X        }
  1418. X        else
  1419. X        {
  1420. X            if(!strcmp(tdve->type,type))
  1421. X                break;
  1422. X        }
  1423. X    }
  1424. X    return(tdve);
  1425. X
  1426. X}    /* end of getdvtype */
  1427. X
  1428. X/*+-------------------------------------------------------------------------
  1429. X    dialstr_translate(translate_list,to_translate) - translate dial strings
  1430. X--------------------------------------------------------------------------*/
  1431. X#if 0
  1432. Xvoid
  1433. Xdialstr_translate(translate_list,to_translate)
  1434. Xregister char *translate_list;
  1435. Xchar *to_translate;
  1436. X{
  1437. X    register char *cptr;
  1438. X
  1439. X    while(*translate_list && *(translate_list + 1))
  1440. X    {
  1441. X        for(cptr=to_translate; *cptr; cptr++)
  1442. X        {
  1443. X            if(*translate_list == *cptr)
  1444. X                *cptr = *(translate_list + 1);
  1445. X        }
  1446. X        translate_list += 2;
  1447. X    }
  1448. X}    /* end of dialstr_translate */
  1449. X#endif
  1450. X
  1451. X/*+-------------------------------------------------------------------------
  1452. X    getdlent() - get first or next Dialers entry (a la getpwent)
  1453. X--------------------------------------------------------------------------*/
  1454. Xstruct dlent *
  1455. Xgetdlent()
  1456. X{
  1457. X    int itmp;
  1458. X#define MAX_DL_TOKENS 3
  1459. X    char *tokens[MAX_DL_TOKENS];
  1460. X    static struct dlent dle;
  1461. X    static char dlstr[128];
  1462. X    char *strchr();
  1463. X
  1464. X    if(!there_is_hdb_on_this_machine)
  1465. X        return((struct dlent *)0);
  1466. X
  1467. X    if(!fpdl)
  1468. X    {
  1469. X        if(!(fpdl = fopen(Dialers_file,"r")))
  1470. X        {
  1471. X            pperror(Dialers_file);
  1472. X            return((struct dlent *)0);
  1473. X        }
  1474. X    }
  1475. X
  1476. X    while(1)
  1477. X    {
  1478. X        if(!fgets(dlstr,sizeof(dlstr),fpdl))
  1479. X            return((struct dlent *)0);
  1480. X        if(((itmp = strlen(dlstr)) <= 1) || (dlstr[0] == '#') ||
  1481. X            (dlstr[0] == ' '))
  1482. X        {
  1483. X            continue;
  1484. X        }
  1485. X        dlstr[--itmp] = 0;
  1486. X        for(itmp = 0; itmp < MAX_DL_TOKENS; itmp++)
  1487. X            tokens[itmp] = "";
  1488. X        if(tokens[0] = arg_token(dlstr," \t\r\n"))
  1489. X        {
  1490. X            if(tokens[1] = arg_token((char *)0," \t\r\n"))
  1491. X            {
  1492. X            extern char *str_token_static;
  1493. X                tokens[2] = skip_ld_break(str_token_static);
  1494. X            }
  1495. X        }
  1496. X        break;
  1497. X    }
  1498. X
  1499. X    dle.name = tokens[0];
  1500. X    dle.tlate = tokens[1];
  1501. X    dle.script = tokens[2];
  1502. X    return(&dle);
  1503. X
  1504. X}    /* end of getdlent */
  1505. X
  1506. X/*+-------------------------------------------------------------------------
  1507. X    enddlent() - close Dialers file
  1508. X--------------------------------------------------------------------------*/
  1509. Xvoid
  1510. Xenddlent()
  1511. X{
  1512. X    if(fpdl)
  1513. X    {
  1514. X        fclose(fpdl);
  1515. X        fpdl = (FILE *)0;
  1516. X    }
  1517. X}    /* end of enddlent */
  1518. X
  1519. X/*+-------------------------------------------------------------------------
  1520. X    getdlentname(name) - get Dialers entry by name
  1521. X--------------------------------------------------------------------------*/
  1522. Xstruct dlent *
  1523. Xgetdlentname(name)
  1524. Xchar *name;
  1525. X{
  1526. X    register DLE *tdle;
  1527. X
  1528. X    while(tdle = getdlent())
  1529. X    {
  1530. X        if(!strcmp(name,tdle->name))
  1531. X            break;
  1532. X    }
  1533. X    return(tdle);
  1534. X
  1535. X}    /* end of getdlentname */
  1536. X
  1537. X/*+-------------------------------------------------------------------------
  1538. X    hdb_choose_Any(baud) - user will take 'Any' line
  1539. X
  1540. Xgive preference to current line
  1541. X--------------------------------------------------------------------------*/
  1542. XDVE *
  1543. Xhdb_choose_Any(baud)
  1544. Xuint baud;
  1545. X{
  1546. X    DVE *tdve = (DVE *)0;
  1547. X    char newtty[sizeof(shm->Lline)];
  1548. X    int lerr = 0;
  1549. X    int utmpst = 0;
  1550. X#if defined(LOG_HDBDIAL) || defined(CHOOSE_DEBUG)
  1551. X    char s128[128];
  1552. X#endif
  1553. X
  1554. X#ifdef CHOOSE_DEBUG
  1555. X    sprintf(s128,"hdb_choose_Any baud=%u current line='%s'",baud,shm->Lline);
  1556. X    ecu_log_event(getpid(),s128);
  1557. X#endif
  1558. X
  1559. X    enddvent();    /* krock but safe */
  1560. X
  1561. X/*
  1562. X * see if shm->Lline in use by someone else; if not and baud rate ok, no further
  1563. X */
  1564. X
  1565. X    if(shm->Lline[0])
  1566. X    {
  1567. X        while(tdve = getdvline(shm->Lline + 5))
  1568. X        {
  1569. X            if((tdve->low_baud <= baud) && (baud <= tdve->high_baud))
  1570. X                break;
  1571. X        }
  1572. X
  1573. X        if(tdve)
  1574. X        {
  1575. X            switch(utmpst = utmp_status(shm->Lline))
  1576. X            {
  1577. X            case US_WEGOTIT:
  1578. X                goto RETURN;
  1579. X            case US_NOTFOUND:    /* not in utmp, or getty dead */
  1580. X#if 0
  1581. X                if(access(shm->Lline,6))
  1582. X                    break;
  1583. X#endif
  1584. X                if((lerr = line_lock_status(shm->Lline)) &&
  1585. X                    (lerr != LINST_WEGOTIT))
  1586. X                {
  1587. X                    break;
  1588. X                }
  1589. X                goto RETURN;
  1590. X            case US_LOGIN:        /* enabled for login, idle */
  1591. X                goto RETURN;
  1592. X            }
  1593. X        }
  1594. X
  1595. X        enddvent();
  1596. X    }
  1597. X
  1598. X    /*
  1599. X     * we've got to pick a new line
  1600. X     */
  1601. X
  1602. X#ifdef CHOOSE_DEBUG
  1603. X    sprintf(s128,"must pick new line utmpst=%u lerr=%u",utmpst,lerr);
  1604. X    ecu_log_event(getpid(),s128);
  1605. X#endif
  1606. X
  1607. X    lerr = 0;
  1608. X    while(1)
  1609. X    {
  1610. X        if(!(tdve = getdvbaud(baud)))
  1611. X            break;
  1612. X
  1613. X        /* by now, we know shm->Lline wont work */
  1614. X        if(!TTYNAME_STRCMP(tdve->line,shm->Lline + 5))
  1615. X            continue;
  1616. X
  1617. X        /* if not acu, dont use it */
  1618. X        if(ulindex(tdve->type,"ACU") < 0)
  1619. X            continue;
  1620. X
  1621. X        sprintf(newtty,"/dev/%s",tdve->line);
  1622. X        switch(utmpst = utmp_status(newtty))
  1623. X        {
  1624. X            case US_NOTFOUND:    /* not in utmp, or getty dead */
  1625. X#if 0
  1626. X                if(access(newtty,6)) /* ecuungetty won't be able to help us */
  1627. X                    break;
  1628. X#endif
  1629. X                if((lerr = line_lock_status(newtty)) &&
  1630. X                    (lerr != LINST_WEGOTIT))
  1631. X                {
  1632. X                    break;
  1633. X                }
  1634. X                goto RETURN;
  1635. X
  1636. X            case US_LOGIN:        /* enabled for login, idle */
  1637. X                goto RETURN;
  1638. X
  1639. X            case US_WEGOTIT:
  1640. X                goto RETURN;
  1641. X        }
  1642. X    }
  1643. X
  1644. XRETURN:
  1645. X    enddvent();
  1646. X#ifdef LOG_HDBDIAL
  1647. X    sprintf(s128,"CHOOSEANY lerr=%d chose %s",
  1648. X        lerr,(tdve) ? tdve->line : "<none>");
  1649. X    ecu_log_event(getpid(),s128);
  1650. X#endif
  1651. X    return(tdve);
  1652. X
  1653. X}    /* end of hdb_choose_Any */
  1654. X
  1655. X/*+-------------------------------------------------------------------------
  1656. X    hdb_choose_Device(type,baud) - need line with 'type' and 'baud'
  1657. X
  1658. Xreturn DVE pointer if line chosen, 0 if failed to find a line
  1659. XPriority is given to retaining the current line
  1660. X--------------------------------------------------------------------------*/
  1661. XDVE *
  1662. Xhdb_choose_Device(type,baud)
  1663. Xchar *type;
  1664. Xuint baud;
  1665. X{
  1666. X    DVE *tdve = (DVE *)0;
  1667. X    char s32[32];
  1668. X    int itmp = 0;
  1669. X    int lerr = 0;
  1670. X    int utmpst = 0;
  1671. X    int done;
  1672. X
  1673. X#ifdef CHOOSE_DEBUG
  1674. X    char s128[128];
  1675. X    sprintf(s128,"hdb_choose_Device type='%s' baud=%u curr line='%s'",
  1676. X        type,baud,shm->Lline);
  1677. X    ecu_log_event(getpid(),s128);
  1678. X#endif
  1679. X
  1680. X    /*
  1681. X     * check current line
  1682. X     */
  1683. X    if(shm->Lline[0])
  1684. X    {
  1685. X        while(tdve = getdvline(shm->Lline + 5))
  1686. X        {
  1687. X            if(dvtype_match(type,tdve->type) &&
  1688. X                (tdve->low_baud <= baud) && (baud <= tdve->high_baud))
  1689. X            {
  1690. X                break;
  1691. X            }
  1692. X        }
  1693. X        enddvent();
  1694. X
  1695. X        if(tdve)
  1696. X        {
  1697. X            switch(utmpst = utmp_status(shm->Lline))
  1698. X            {
  1699. X                case US_WEGOTIT:
  1700. X                    goto RETURN;
  1701. X
  1702. X                case US_NOTFOUND:    /* not in utmp, or getty dead */
  1703. X#if 0
  1704. X                    if(access(shm->Lline,6))
  1705. X                        break;
  1706. X#endif
  1707. X                    if((lerr = line_lock_status(shm->Lline)) &&
  1708. X                        (lerr != LINST_WEGOTIT))
  1709. X                    {
  1710. X                        break;
  1711. X                    }
  1712. X                    goto RETURN;
  1713. X
  1714. X                case US_LOGIN:        /* enabled for login, idle */
  1715. X                    goto RETURN;
  1716. X            }
  1717. X        }
  1718. X    }
  1719. X
  1720. X    /*
  1721. X     * we've got to pick a new line
  1722. X     */
  1723. X
  1724. X#ifdef CHOOSE_DEBUG
  1725. X    sprintf(s128,"must pick new line utmpst=%u lerr=%u",utmpst,lerr);
  1726. X    ecu_log_event(getpid(),s128);
  1727. X#endif
  1728. X
  1729. X    done = 0;
  1730. X    lerr = 0;
  1731. X    while(!done)
  1732. X    {
  1733. X        /*
  1734. X         * get Devices entry matching type
  1735. X         */
  1736. X        if(!(tdve = getdvtype(type)))
  1737. X        {
  1738. X#ifdef CHOOSE_DEBUG
  1739. X            sprintf(s128,"no line matches type '%s'",type);
  1740. X            ecu_log_event(getpid(),s128);
  1741. X#endif
  1742. X            break;
  1743. X        }
  1744. X
  1745. X        /*
  1746. X         * does baud rate match?
  1747. X         */
  1748. X        if((tdve->low_baud > baud) || (baud > tdve->high_baud))
  1749. X            continue;
  1750. X
  1751. X        sprintf(s32,"/dev/%s",tdve->line);
  1752. X        itmp = utmp_status(s32);
  1753. X#ifdef CHOOSE_DEBUG
  1754. X        sprintf(s128,"%s: utmp_status = %d  lock status=%d",s32,itmp,
  1755. X                line_lock_status(s32));
  1756. X        ecu_log_event(getpid(),s128);
  1757. X#endif
  1758. X        switch(itmp)
  1759. X        {
  1760. X            case US_NOTFOUND:    /* not in utmp, or getty dead */
  1761. X#if 0
  1762. X                if(access(s32,6))    /* ecuungetty won't be able to help us */
  1763. X                    break;
  1764. X#endif
  1765. X                if(!(itmp = line_lock_status(s32)) || (itmp == LINST_WEGOTIT))
  1766. X                    done = 1;
  1767. X                break;
  1768. X
  1769. X            case US_WEGOTIT:    /* we own the line */
  1770. X                /* this would be a curious case to succeed */
  1771. X                done = 1;
  1772. X                break;
  1773. X
  1774. X            case US_LOGIN:        /* enabled for login, idle */
  1775. X                done = 1;
  1776. X                break;
  1777. X
  1778. X            default:
  1779. X                break;
  1780. X        }
  1781. X    }
  1782. X
  1783. XRETURN:
  1784. X    enddvent();
  1785. X    return(tdve);
  1786. X
  1787. X}    /* end of hdb_choose_Device */
  1788. X
  1789. X/*+-------------------------------------------------------------------------
  1790. X    hdb_dial_error(errcode) - dialer program error code to text
  1791. X
  1792. Xalso sets iv[0] to dial command status
  1793. X--------------------------------------------------------------------------*/
  1794. Xchar *
  1795. Xhdb_dial_error_text(errcode)
  1796. Xint errcode;
  1797. X{
  1798. X    static char errant[64];
  1799. X
  1800. X    iv[0] = 1;
  1801. X    switch(errcode &= 0x7F)
  1802. X    {
  1803. X        case RCE_INUSE:
  1804. X            return("!Line in use");
  1805. X        case RCE_SIG:
  1806. X            iv[0] = 2;
  1807. X            return("!Interrupted");
  1808. X        case RCE_ARGS:
  1809. X            return("!Invalid arguments");
  1810. X        case RCE_PHNO:
  1811. X            return("!Invalid phone number");
  1812. X        case RCE_SPEED:
  1813. X            return("!Bad baud rate");
  1814. X        case RCE_OPEN:
  1815. X            return("!Line open error");
  1816. X        case RCE_IOCTL:
  1817. X            return("!Ioctl error");
  1818. X        case RCE_TIMOUT:
  1819. X            iv[0] = 3;
  1820. X            return("!Modem Error");
  1821. X        case RCE_NOTONE:
  1822. X            return("NO DIAL TONE");
  1823. X        case RCE_BUSY:
  1824. X            return("BUSY");
  1825. X        case RCE_NOCARR:
  1826. X            return("NO CARRIER");
  1827. X        case RCE_ANSWER:
  1828. X            return("NO ANSWER");
  1829. X        default:
  1830. X        case RCE_NULL:
  1831. X            sprintf(errant,"unknown dialer error code %d",errcode);
  1832. X            return(errant);
  1833. X    }
  1834. X    /*NOTREACHED*/
  1835. X}    /* end of hdb_dial_error */
  1836. X
  1837. X/*+-------------------------------------------------------------------------
  1838. X    hdb_dial(presult) - dial with uucp dialer if we can
  1839. X
  1840. Xreturn 0 if connected
  1841. X       1 if dial failed
  1842. X       2 if interrupted
  1843. X       3 if modem error
  1844. X       4 if use ecu DCE dialer
  1845. X--------------------------------------------------------------------------*/
  1846. Xint
  1847. Xhdb_dial(presult)
  1848. Xchar **presult;
  1849. X{
  1850. X    int itmp;
  1851. X    PID_T dial_pid;
  1852. X    int wait_status;
  1853. X    int old_ttymode = get_ttymode();
  1854. X    SIGTYPE (*original_sighdlr)();
  1855. X    DVE *tdve;
  1856. X    struct dlent *tdle = (struct dlent *)0;
  1857. X    char baudstr[16];
  1858. X    char dbgstr[16];
  1859. X    char dial_log[100];
  1860. X    char *stripped_num;
  1861. X    char *sptr;
  1862. X    char *dptr;
  1863. X    static char stat_s64[64];
  1864. X    ulong colors_at_entry = colors_current;
  1865. X    extern char *make_char_graphic();
  1866. X    char token[128];        /* translated dialer token */
  1867. X    FILE *fp;
  1868. X    char credit_file[128];
  1869. X    char *error_name = "";
  1870. X    int error_baud = 0;
  1871. X
  1872. X    if(sigint)    /* don't even start if console interrupt posted */
  1873. X    {
  1874. X        sigint = 0;
  1875. X        return(2);
  1876. X    }
  1877. X
  1878. X    if(!there_is_hdb_on_this_machine)
  1879. X        return(4);
  1880. X
  1881. X#if defined(CHOOSE_DEBUG)
  1882. X    sprintf(dial_log,"HDB_DIAL Lline=%s Lbaud=%d",
  1883. X        shm->Lline,shm->Lbaud);
  1884. X    ecu_log_event(getpid(),dial_log);
  1885. X#endif
  1886. X
  1887. X    /*
  1888. X     * get a Devices entry appropriate for dialing on the line;
  1889. X     */
  1890. X    enddvent();
  1891. X    while(tdve = getdvline(shm->Lline + 5))
  1892. X    {
  1893. X        if((tdve->low_baud <= shm->Lbaud) &&
  1894. X            (shm->Lbaud <= tdve->high_baud)) 
  1895. X        {
  1896. X            break;
  1897. X        }
  1898. X    }
  1899. X    error_name = shm->Lline + 5;
  1900. X    error_baud = shm->Lbaud;
  1901. X    enddvent();
  1902. X
  1903. X    if(!tdve)
  1904. X    {
  1905. X        pprintf("no Devices entry for %s at %u baud ... trying ecu dialer\n",
  1906. X            error_name,error_baud);
  1907. X        return(4);
  1908. X    }
  1909. X
  1910. X    dial_log[0] = 0;
  1911. X    if(*tdve->dialprog != '/')
  1912. X    {
  1913. X        tdle = getdlentname(tdve->dialprog);
  1914. X        enddlent();
  1915. X        if(!tdle)
  1916. X        {
  1917. X            sprintf(dial_log,
  1918. X                "UUCPDIAL Devices entry %s: '%s' not found in Dialers",
  1919. X                shm->Lline + 5,tdve->dialprog);
  1920. X        }
  1921. X    }
  1922. X    else if(access(tdve->dialprog,1))
  1923. X    {
  1924. X        sprintf(dial_log,"UUCPDIAL Devices entry %s: (%s) %s",
  1925. X            shm->Lline + 5,tdve->dialprog,errno_text(errno));
  1926. X    }
  1927. X
  1928. X    if(dial_log[0])
  1929. X    {
  1930. X#if defined(LOG_HDBDIAL)
  1931. X        ecu_log_event(getpid(),dial_log);
  1932. X#endif
  1933. X        pputs(dial_log + 9);
  1934. X        pputs("\n");
  1935. X        return(4);
  1936. X    }
  1937. X
  1938. X    stripped_num = strip_phone_num(shm->Ltelno);
  1939. X
  1940. X    /*
  1941. X     * if trailing '$', read and append ~/.ecu/.credit
  1942. X     */
  1943. X    dptr = stripped_num;
  1944. X    if(*(dptr - 1) == '$')
  1945. X    {
  1946. X        *--dptr = 0;
  1947. X        get_home_dir(credit_file);
  1948. X        strcat(credit_file,"/.ecu/.credit");
  1949. X        chmod(credit_file,0400);    /* let's keep this one quiet */
  1950. X        if(fp = fopen(credit_file,"r"))
  1951. X        {
  1952. X            fgets(dptr,30,fp);
  1953. X            fclose(fp);
  1954. X        }
  1955. X        if(!fp || !(*dptr))
  1956. X        {
  1957. X            strcpy(sv[0]->pb,"!CREDIT CARD ERROR");
  1958. X            sv[0]->cb = strlen(sv[0]->pb);
  1959. X            pputs("\ncredit card error\n");
  1960. X            iv[0] = 1;
  1961. X            return(1);
  1962. X        }
  1963. X        if(*(dptr + strlen(dptr) - 1) == 0x0A)
  1964. X            *(dptr + strlen(dptr) - 1) = 0; /* kill NL */
  1965. X    }
  1966. X
  1967. X  /* Translate Token now (thanks to ache@hq.demos.su) */
  1968. X
  1969. X    if (tdve->token == (char *)0 || !tdve->token[0])
  1970. X        strcpy(token, stripped_num);
  1971. X    else {
  1972. X        dptr = token;
  1973. X        for (sptr = tdve->token; *sptr; sptr++)
  1974. X            if (*sptr != '\\')
  1975. X                *dptr++ = *sptr;
  1976. X            else {
  1977. X                char *s, *t;
  1978. X
  1979. X                switch (*(sptr + 1)) {
  1980. X
  1981. X                /* Direct */
  1982. X                case 'D':
  1983. X                    sptr++;
  1984. X                    s = stripped_num;
  1985. X                    while (*s)
  1986. X                        *dptr++ = *s++;
  1987. X                    break;
  1988. X
  1989. X                /* Dialcodes Translate */
  1990. X                case 'T':
  1991. X                    sptr++;
  1992. X                    s = stripped_num;
  1993. X                    t = dialcodes_translate(&s);
  1994. X                    while(*t)
  1995. X                        *dptr++ = *t++;
  1996. X                    while (*s)
  1997. X                        *dptr++ = *s++;
  1998. X                    break;
  1999. X
  2000. X                default:
  2001. X                    *dptr++ = '\\';
  2002. X                    break;
  2003. X                }
  2004. X            }
  2005. X        *dptr = 0;
  2006. X    }
  2007. X
  2008. X    pprintf("Type %s to abort ... ",
  2009. X        (kbdintr == 0x7F) ? "DEL" : make_char_graphic(kbdintr,0));
  2010. X    setcolor(colors_normal);
  2011. X
  2012. X    if(Ldial_debug_level)
  2013. X    {
  2014. X        ttymode(0);
  2015. X        pputs("\n");
  2016. X    }
  2017. X    else
  2018. X        ttymode(2);
  2019. X
  2020. X    if(!tdle)
  2021. X    {
  2022. X        if(access(tdve->dialprog,1))
  2023. X        {
  2024. X            pperror(tdve->dialprog);
  2025. X            pputs("trying ecu dialer\n");
  2026. X            return(4);
  2027. X        }
  2028. X        sprintf(baudstr,"%u",shm->Lbaud);
  2029. X        sprintf(dbgstr,"-x%d",Ldial_debug_level);
  2030. X        original_sighdlr = signal(SIGCLD,SIG_DFL);
  2031. X        if((dial_pid = smart_fork()) == 0)
  2032. X        {
  2033. X            signal(SIGINT,SIG_DFL);
  2034. X            execl(tdve->dialprog,
  2035. X#if defined(WHT) || defined(ECUdial)
  2036. X                "ECUdial",        /* tell dialer ECU is calling */
  2037. X#else
  2038. X                tdve->dialprog,
  2039. X#endif
  2040. X                dbgstr, shm->Lline,token,baudstr,(char *)0);
  2041. X            _exit(0xFF);    /* did not execute */
  2042. X        }
  2043. X
  2044. X        wait_status = (RC_FAIL | RCE_SIG) << 8;
  2045. X        while(((itmp = wait(&wait_status)) != dial_pid) && (itmp != -1))
  2046. X            ;
  2047. X        signal(SIGCLD,original_sighdlr);
  2048. X        ttymode(old_ttymode);
  2049. X        ttyflush(0);
  2050. X
  2051. X        if(sigint)    /* keyboard interrupt? */
  2052. X        {
  2053. X            kill(dial_pid,9);    /* kill dialer */
  2054. X            lflash_dtr();        /* drop line */
  2055. X            sigint = 0;            /* reset SIGINT indication */
  2056. X        }
  2057. X        lreset_ksr(); /* uucp dialers are nice guys, but lets use our termio */
  2058. X
  2059. X#if defined(LOG_HDBDIAL)
  2060. X        if(wait_status)
  2061. X        {
  2062. X            sprintf(dial_log,"UUCPDIAL %s %s exit status0x%04x",
  2063. X                tdve->dialprog,token,wait_status & 0xFFFF);
  2064. X            ecu_log_event(getpid(),dial_log);
  2065. X        }
  2066. X#endif
  2067. X
  2068. X        /*
  2069. X         * if system reports interrupt, fake dial-reported status
  2070. X         */
  2071. X        if(wait_status & 0xFF)
  2072. X            wait_status = (RC_FAIL | RCE_SIG) << 8;
  2073. X
  2074. X        if((wait_status & 0xFF00) == 0xFF00)
  2075. X        {
  2076. X            pprintf("%s failed  ... trying ecu dialer\n",tdve->dialprog);
  2077. X            return(4);
  2078. X        }
  2079. X
  2080. X        wait_status = (wait_status >> 8) & 0xFF;
  2081. X
  2082. X        if(!(wait_status & ~RC_BAUD))
  2083. X        {
  2084. X            char *cptr;
  2085. X
  2086. X            wait_status &= RC_BAUD;
  2087. X            switch (wait_status) 
  2088. X            {
  2089. X            case 0:         cptr = baudstr; break;  /* SAME */
  2090. X            case B50:       cptr = "50"; break;
  2091. X            case B75:       cptr = "75"; break;
  2092. X            case B110:      cptr = "110"; break;
  2093. X            case B134:      cptr = "134.5"; break;
  2094. X            case B150:      cptr = "150"; break;
  2095. X            case B200:      cptr = "200"; break;
  2096. X            case B300:      cptr = "300"; break;
  2097. X            case B600:      cptr = "600"; break;
  2098. X            case B1200:     cptr = "1200"; break;
  2099. X            case B1800:     cptr = "1800"; break;
  2100. X            case B2400:     cptr = "2400"; break;
  2101. X            case B4800:     cptr = "4800"; break;
  2102. X            case B9600:     cptr = "9600"; break;
  2103. X#if defined(B19200)
  2104. X            case B19200:    cptr = "19200"; break;
  2105. X#endif
  2106. X#if defined(B38400)
  2107. X            case B38400:    cptr = "38400"; break;
  2108. X#endif
  2109. X            default:
  2110. X                switch (wait_status) {
  2111. X                case EXTA:      cptr = "EXTA"; break;
  2112. X                case EXTB:      cptr = "EXTB"; break;
  2113. X                default:        cptr = "????"; break;
  2114. X                }
  2115. X            }
  2116. X
  2117. X            sprintf(stat_s64,"CONNECT %s",cptr);
  2118. X            *presult = stat_s64;    /* DCE_dial will report result code */
  2119. X            return(0);
  2120. X        }
  2121. X
  2122. X        *presult = hdb_dial_error_text(wait_status);
  2123. X        setcolor(colors_error);
  2124. X        pputs(*presult);
  2125. X        setcolor(colors_at_entry);
  2126. X        pputc('\n');
  2127. X        lflash_dtr();
  2128. X    }
  2129. X    else
  2130. X    {
  2131. X        pprintf("using Dialers entry '%s'\n",tdle->name);
  2132. X        expresp_verbosity = (proc_level & proctrace) ? proctrace : 0;
  2133. X        if(execute_expresp(tdle->script))
  2134. X        {
  2135. X            *presult = "DIALER SCRIPT FAILED";
  2136. X            setcolor(colors_error);
  2137. X            pputs(*presult);
  2138. X            setcolor(colors_at_entry);
  2139. X            pputc('\n');
  2140. X            iv[0] = 1;
  2141. X        }
  2142. X        else
  2143. X        {
  2144. X            extern char last_Speed_result[];
  2145. X            if(last_Speed_result[0])
  2146. X                *presult = last_Speed_result;
  2147. X            else
  2148. X            {
  2149. X                sprintf(stat_s64,"CONNECT %u",shm->Lbaud);
  2150. X                *presult = stat_s64;    /* DCE_dial will report result code */
  2151. X            }
  2152. X            setcolor(colors_at_entry);
  2153. X            iv[0] = 0;
  2154. X        }
  2155. X    }
  2156. X
  2157. X    return((int)iv[0]);
  2158. X
  2159. X}    /* end of hdb_dial */
  2160. X
  2161. X/*+-------------------------------------------------------------------------
  2162. X    hdb_init() - initialize HoneyDanBerInterface
  2163. X--------------------------------------------------------------------------*/
  2164. Xvoid
  2165. Xhdb_init()
  2166. X{
  2167. X    char *hdblibdir = HDBLIBDIR;        /* system independent location */
  2168. X    int itmp;
  2169. X    int buflen = strlen(hdblibdir) + 64;
  2170. X    char *emsg = "hdb_init memory allocation failed!\n";
  2171. X
  2172. X    if(!(Devices_file = malloc(buflen)))
  2173. X    {
  2174. X        pputs(emsg);
  2175. X        termecu(TERMECU_MALLOC);
  2176. X    }
  2177. X    strcpy(Devices_file,hdblibdir);
  2178. X    strcat(Devices_file,"/Devices");
  2179. X
  2180. X    if(!(Dialers_file = malloc(buflen)))
  2181. X    {
  2182. X        pputs(emsg);
  2183. X        termecu(TERMECU_MALLOC);
  2184. X    }
  2185. X    for(itmp = 0; itmp < UNGETTY_LIST_MAX; itmp++)
  2186. X    {
  2187. X        if(!(ungetty_list[itmp] = malloc(64)))
  2188. X        {
  2189. X            pputs(emsg);
  2190. X            termecu(TERMECU_MALLOC);
  2191. X        }
  2192. X    }
  2193. X    strcpy(Dialers_file,hdblibdir);
  2194. X    strcat(Dialers_file,"/Dialers");
  2195. X
  2196. X    if(!(Dialcodes_file = malloc(buflen)))
  2197. X    {
  2198. X        pputs(emsg);
  2199. X        termecu(TERMECU_MALLOC);
  2200. X    }
  2201. X    strcpy(Dialcodes_file,hdblibdir);
  2202. X    strcat(Dialcodes_file,"/Dialcodes");
  2203. X
  2204. X    there_is_hdb_on_this_machine = !access(Devices_file,4);
  2205. X
  2206. X}    /* end of hdb_init */
  2207. X
  2208. X/*+-------------------------------------------------------------------------
  2209. Xdialcodes_translate(phone)  -  translate first part of phone using Dialcodes
  2210. X--------------------------------------------------------------------------*/
  2211. Xchar *
  2212. Xdialcodes_translate(phone)
  2213. Xchar **phone;
  2214. X{
  2215. X    FILE *f;
  2216. X    int itmp;
  2217. X#define MAX_DLC_TOKENS 2
  2218. X    char *tokens[MAX_DLC_TOKENS];
  2219. X    static char dlstr[128];
  2220. X
  2221. X    if(!(f = fopen(Dialcodes_file, "r")))
  2222. X        return("");
  2223. X
  2224. X    while(fgets(dlstr,sizeof(dlstr),f))
  2225. X    {
  2226. X        if(((itmp = strlen(dlstr)) > 0) && (dlstr[itmp - 1] == '\n'))
  2227. X            dlstr[--itmp] = 0;
  2228. X        if((dlstr[0] == '#') || (dlstr[0] == ' ') || (!itmp))
  2229. X            continue;
  2230. X        if(tokens[0] = arg_token(dlstr," \t\r\n"))
  2231. X        {
  2232. X            if (!(tokens[1] = arg_token((char *)0," \t\r\n")))
  2233. X                tokens[1] = "";
  2234. X            itmp = strlen(tokens[0]);
  2235. X            if (strncmp(*phone, tokens[0], itmp))
  2236. X                continue;
  2237. X            fclose(f);
  2238. X            *phone += itmp;
  2239. X            fclose(f);
  2240. X            return(tokens[1]);
  2241. X        }
  2242. X        break;
  2243. X    }
  2244. X
  2245. X    fclose(f);
  2246. X    return("");
  2247. X}
  2248. X
  2249. X/*+-------------------------------------------------------------------------
  2250. X      strip_phone_num(sptr) - remove junk characters from phone
  2251. X--------------------------------------------------------------------------*/
  2252. Xchar *
  2253. Xstrip_phone_num(sptr)
  2254. Xchar *sptr;
  2255. X{
  2256. X    static char stripped_num[64];
  2257. X    char *dptr;
  2258. X
  2259. X    dptr = stripped_num;
  2260. X    while(*sptr)
  2261. X    {
  2262. X        if((*sptr == '(') || (*sptr == ')')
  2263. X#if defined(WHT) || defined(STRIP_TELNO_HYPHENS)
  2264. X            || (*sptr == '-')    /* some want '-' for pauses; I use ',' */
  2265. X#endif
  2266. X            )
  2267. X        {
  2268. X            sptr++;
  2269. X            continue;
  2270. X        }
  2271. X        *dptr++ = *sptr++;
  2272. X    }
  2273. X    *dptr = 0;
  2274. X
  2275. X    return(stripped_num);
  2276. X}
  2277. X
  2278. X/* vi: set tabstop=4 shiftwidth=4: */
  2279. X/* end of hdbintf.c */
  2280. SHAR_EOF
  2281. chmod 0644 hdbintf.c ||
  2282. echo 'restore of hdbintf.c failed'
  2283. Wc_c="`wc -c < 'hdbintf.c'`"
  2284. test 40881 -eq "$Wc_c" ||
  2285.     echo 'hdbintf.c: original size 40881, current size' "$Wc_c"
  2286. rm -f _shar_wnt_.tmp
  2287. fi
  2288. # ============= kbdtest.c ==============
  2289. if test -f 'kbdtest.c' -a X"$1" != X"-c"; then
  2290.     echo 'x - skipping kbdtest.c (File already exists)'
  2291.     rm -f _shar_wnt_.tmp
  2292. else
  2293. > _shar_wnt_.tmp
  2294. echo 'x - extracting kbdtest.c (Text)'
  2295. sed 's/^X//' << 'SHAR_EOF' > 'kbdtest.c' &&
  2296. X/*+-----------------------------------------------------------------------
  2297. X    kbdtest.c -- hack to test keyboard function key sequences
  2298. X    wht@n4hgf.Mt-Park.GA.US
  2299. X
  2300. X  compile with     cc -o kbdtest kbdtest.c
  2301. X  or just          cc kbdtest.c;a.out
  2302. X------------------------------------------------------------------------*/
  2303. X/*+:EDITS:*/
  2304. X/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  2305. X/*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA */
  2306. X/*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 */
  2307. X/*:12-21-1990-23:47-wht@n4hgf-liven up for release with ECU 3 */
  2308. X/*:04-07-1990-01:36-wht@tridom-bring out of the daaaaark ages a bit */
  2309. X/*:04-18-1988-13:44-wht-first edits -- oollldd program */
  2310. X
  2311. X#include <stdio.h>
  2312. X#include <signal.h>
  2313. X#include <ctype.h>
  2314. X#include <fcntl.h>
  2315. X#include <termio.h>
  2316. X#include "ecu_types.h"
  2317. X#include <sys/errno.h>
  2318. X#include "ecu_stat.h"
  2319. X#include <string.h>
  2320. X
  2321. X#define TTYIN   0
  2322. X#define TTYOUT  1
  2323. X#define TTYERR  2
  2324. X
  2325. Xstruct termio tv0;        /* for saving, changing TTY atributes */
  2326. Xstruct termio tv;        /* for saving, changing TTY atributes */
  2327. X
  2328. X/*+-----------------------------------------------------------------------
  2329. X    ttymode(arg) -- control user console (kbd/screen)
  2330. X
  2331. X  Where arg ==
  2332. X    0 restore attributes saved at start of execution
  2333. X    1 raw mode 
  2334. X
  2335. X------------------------------------------------------------------------*/
  2336. Xvoid ttymode(arg)
  2337. X{
  2338. X    char *mode_type;
  2339. X
  2340. X    switch(arg)
  2341. X    {
  2342. X        case 0:    
  2343. X            mode_type = "console to cooked mode\r\n";
  2344. X            break;
  2345. X        default: 
  2346. X            mode_type = "console to raw mode\r\n";
  2347. X            break;
  2348. X    }
  2349. X    (void)fprintf(stderr,mode_type);
  2350. X
  2351. X    if(arg)
  2352. X    {
  2353. X        (void)ioctl(TTYIN,TCGETA,&tv);
  2354. X        Ltermio.c_cflag &= ~(CS8 | PARENB | PARODD);
  2355. X        Ltermio.c_cflag |= CS8;
  2356. X        tv.c_iflag &= ~(INLCR | ICRNL | IGNCR | IXOFF | IUCLC | ISTRIP);
  2357. X        tv.c_oflag |= OPOST;
  2358. X        tv.c_oflag &= ~(OLCUC | ONLCR | OCRNL | ONOCR | ONLRET);
  2359. X        tv.c_lflag &= ~(ICANON | ISIG | ECHO);
  2360. X        tv.c_cc[VEOF] = '\01';
  2361. X        tv.c_cc[VEOL] = '\0';
  2362. X        tv.c_cc[VMIN] = 1;
  2363. X        tv.c_cc[VTIME] = 1;
  2364. X        (void)ioctl(TTYIN,TCSETAW,&tv);
  2365. X    }
  2366. X    else
  2367. X        (void)ioctl(TTYIN,TCSETAW,&tv0);
  2368. X}
  2369. X
  2370. X
  2371. X/*+-----------------------------------------------------------------------
  2372. X    main()
  2373. X------------------------------------------------------------------------*/
  2374. Xmain(argc,argv)
  2375. Xint argc;
  2376. Xchar **argv;
  2377. X{
  2378. Xunsigned char inchar;
  2379. X
  2380. X    setbuf(stdout,NULL);
  2381. X    setbuf(stderr,NULL);
  2382. X
  2383. X    ioctl(TTYIN,TCGETA,&tv0);        /* get original status */
  2384. X    ttymode(2);
  2385. X
  2386. X    fprintf(stderr,"press ^D (0x04) to terminate program\r\n");
  2387. X
  2388. X    while(read(TTYIN,&inchar,1) == 1)
  2389. X    {
  2390. X        printf("%02x %c\r\n",inchar,
  2391. X            ((inchar >= 0x20) && (inchar < 0x7F)) ? inchar : '.');
  2392. X        if((inchar & 0x7F) == 4)
  2393. X        {
  2394. X            ttymode(0);
  2395. X            exit(0);
  2396. X        }
  2397. X    }
  2398. X    ttymode(0);
  2399. X    exit(1);
  2400. X
  2401. X}
  2402. X
  2403. X/* vi: set tabstop=4 shiftwidth=4: */
  2404. X/* end of kbdtest.c */
  2405. SHAR_EOF
  2406. chmod 0644 kbdtest.c ||
  2407. echo 'restore of kbdtest.c failed'
  2408. Wc_c="`wc -c < 'kbdtest.c'`"
  2409. test 2711 -eq "$Wc_c" ||
  2410.     echo 'kbdtest.c: original size 2711, current size' "$Wc_c"
  2411. rm -f _shar_wnt_.tmp
  2412. fi
  2413. # ============= kbdtest3.c ==============
  2414. if test -f 'kbdtest3.c' -a X"$1" != X"-c"; then
  2415.     echo 'x - skipping kbdtest3.c (File already exists)'
  2416.     rm -f _shar_wnt_.tmp
  2417. else
  2418. > _shar_wnt_.tmp
  2419. echo 'x - extracting kbdtest3.c (Text)'
  2420. sed 's/^X//' << 'SHAR_EOF' > 'kbdtest3.c' &&
  2421. X/* CHK=0x2F4F */
  2422. Xchar *revision = "3.21";
  2423. SHAR_EOF
  2424. true || echo 'restore of kbdtest3.c failed'
  2425. fi
  2426. echo 'End of ecu320 part 17'
  2427. echo 'File kbdtest3.c is continued in part 18'
  2428. echo 18 > _shar_seq_.tmp
  2429. exit 0
  2430.  
  2431. exit 0 # Just in case...
  2432.