home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / agetty / part01 < prev    next >
Encoding:
Text File  |  1993-08-23  |  41.6 KB  |  1,418 lines

  1. Newsgroups: comp.sources.misc
  2. From: wietse@wzv.win.tue.nl (Wietse Venema)
  3. Subject: v39i046:  agetty - simple flexible login front end, Part01/01
  4. Message-ID: <1993Aug23.032022.25430@sparky.sterling.com>
  5. X-Md4-Signature: 5855fce9ca0b67f5966c3ca43f41cadf
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Eindhoven University of Technology, The Netherlands
  8. Date: Mon, 23 Aug 1993 03:20:22 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: wietse@wzv.win.tue.nl (Wietse Venema)
  12. Posting-number: Volume 39, Issue 46
  13. Archive-name: agetty/part01
  14. Environment: System V.[24], SunOS 4, termio.
  15. Supersedes: agetty: Volume 22, Issue 86
  16.  
  17. Traditionally, getty is the program that listens on a terminal or modem
  18. port and that prompts for a login name.  Agetty is an alternative for
  19. System V or SunOS 4 environments. It sports useful features such as
  20. automatic adjustment to parity bits, editing characters and baud rates.
  21.  
  22. After bringing up Solaris 2 for the first time, I wanted to *simply*
  23. hook up a dial-in/dial-out modem. After a short glance over the System
  24. V.4 port monitor docs I decided to stick with my own agetty program.
  25. Porting the two-year old code was trivial (changed utmp file handling).
  26.  
  27. Tested with System V.2, SunOS 4.1.3 and SunOS 5.2 (much like System V.4).
  28.  
  29. #! /bin/sh
  30. # This is a shell archive.  Remove anything before this line, then unpack
  31. # it by saving it into a file and typing "sh file".  To overwrite existing
  32. # files, type "sh file -c".  You can also feed this as standard input via
  33. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  34. # will see the following message at the end:
  35. #        "End of shell archive."
  36. # Contents:  README agetty.c agetty.8 Makefile
  37. # Wrapped by wietse@wzv on Sun Aug 22 14:10:30 1993
  38. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  39. if test -f README -a "${1}" != "-c" ; then 
  40.   echo shar: Will not over-write existing file \"README\"
  41. else
  42. echo shar: Extracting \"README\" \(1053 characters\)
  43. sed "s/^X//" >README <<'END_OF_README'
  44. X@(#) README 1.9 8/20/93 22:20:26
  45. X
  46. XTraditionally, getty is the program that listens on terminal and modem
  47. Xports and that prompts for a login name.  Agetty is an alternative for
  48. Xthe System V or SunOS 4 environments that sports some useful features:
  49. X
  50. X- While the user enters the login name, the program adjusts to parity
  51. Xbits, and to line editing, end-of-line or upper-case only characters.
  52. X
  53. X- The baud rate can be established by BREAK character processing and by
  54. Xparsing the CONNECT status messages from Hayes-compatible modems.
  55. X
  56. XOther features: RTS/CTS flow control, alternate login program. Last
  57. Xbut not least, the program does not use any configuration files.
  58. X
  59. XThe program runs without modification on System V.2, SunOS 4.1.3, and
  60. XSunOS 5.2 (a descendant from System V.4). There is a good chance that
  61. Xit runs on System V.3 as well.
  62. X
  63. XIn the Makefile you will have to specify whether diagnostics should be
  64. Xreported through the syslog daemon; the alternative is that all error
  65. Xreports go directly to /dev/console.
  66. X
  67. X        Wietse Venema (wietse@wzv.win.tue.nl)
  68. END_OF_README
  69. if test 1053 -ne `wc -c <README`; then
  70.     echo shar: \"README\" unpacked with wrong size!
  71. fi
  72. # end of overwriting check
  73. fi
  74. if test -f agetty.c -a "${1}" != "-c" ; then 
  75.   echo shar: Will not over-write existing file \"agetty.c\"
  76. else
  77. echo shar: Extracting \"agetty.c\" \(29916 characters\)
  78. sed "s/^X//" >agetty.c <<'END_OF_agetty.c'
  79. X/*++
  80. X/* NAME
  81. X/*    agetty 8
  82. X/* SUMMARY
  83. X/*    alternative System V/SunOS 4 getty
  84. X/* SYSTEM V SYNOPSIS
  85. X/*    agetty [-ih] [-l login] [-m] [-t timeout] [-T term] port speed,...
  86. X/* SUNOS 4 SYNOPSIS
  87. X/*    agetty [-h] [-l login] [-m] [-t timeout] speed,... port
  88. X/* DESCRIPTION
  89. X/*    \fIagetty\fP opens a tty port, prompts for a login name and invokes
  90. X/*    the /bin/login command. It is normally invoked by \fIinit(8)\fP.
  91. X/*
  92. X/*    \fIagetty\fP has several \fInon-standard\fP features that are useful
  93. X/*    for hard-wired and for dial-in lines:
  94. X/* .IP o
  95. X/*    Adapts to parity bits and to line editing, end-of-line, and
  96. X/*    uppercase-only characters when it reads a login name.
  97. X/*    The program can handle 7-bit characters with even, odd, none or space
  98. X/*    parity, and 8-bit characters with no parity. The following special
  99. X/*    characters are recognized: @ and Control-U (kill); #, DEL and
  100. X/*    back space (erase); carriage return and line feed (end of line).
  101. X/* .IP o
  102. X/*    Optionally deduces the baud rate from the CONNECT messages produced by
  103. X/*    Hayes(tm)-compatible modems.
  104. X/* .PP
  105. X/*    This program does not use any configuration file.
  106. X/* ARGUMENTS
  107. X/* .fi
  108. X/* .ad
  109. X/* .TP
  110. X/* port
  111. X/*    A path name relative to the \fI/dev\fP directory. If a "-" is
  112. X/*    specified, \fIagetty\fP assumes that its standard input is
  113. X/*    already connected to a tty port and that a connection to a
  114. X/*    remote user has already been established.
  115. X/* .sp
  116. X/*    Under System V, a "-" \fIport\fP argument should be preceded
  117. X/*    by a "--".
  118. X/* .TP
  119. X/* speed,...
  120. X/*    A comma-separated list of one or more baud rates. Each time
  121. X/*    \fIagetty\fP receives a BREAK character it advances through
  122. X/*    the list, which is treated as if it were circular.
  123. X/* .sp
  124. X/*    Baud rates should be specified in descending order, so that the
  125. X/*    null character (Ctrl-@) can also be used for baud rate switching.
  126. X/* OPTIONS
  127. X/* .fi
  128. X/* .ad
  129. X/* .TP
  130. X/* -h
  131. X/*    Enable hardware (RTS/CTS) flow control. It is left up to the
  132. X/*    application to disable software (XON/XOFF) flow protocol where
  133. X/*    appropriate.
  134. X/* .TP
  135. X/* -i (System V only)
  136. X/*    Do not display the contents of \fI/etc/issue\fP before writing the
  137. X/*    login prompt. Terminals or communications hardware may become confused
  138. X/*    when receiving lots of text at the wrong baud rate; dial-up scripts
  139. X/*    may fail if the login prompt is preceded by too much text.
  140. X/* .TP
  141. X/* -l login
  142. X/*    Invoke the specified \fIlogin\fP program instead of /bin/login.
  143. X/*    For example, one that asks for an additional dial-up password or
  144. X/*    one that uses a different password file.
  145. X/* .TP
  146. X/* -m
  147. X/*    Try to extract the baud rate from the \fIconnect\fP status message
  148. X/*    produced by some Hayes(tm)-compatible modems. These status
  149. X/*    messages are of the form: "<junk><speed><junk>".
  150. X/*    \fIagetty\fP assumes that the modem emits its status message at
  151. X/*    the same speed as specified with (the first) \fIspeed\fP value
  152. X/*    on the command line.
  153. X/* .sp
  154. X/*    Since the \fI-m\fP feature may fail on heavily-loaded systems,
  155. X/*    you still should enable BREAK processing by enumerating all
  156. X/*    expected baud rates on the command line.
  157. X/* .TP
  158. X/* -t timeout
  159. X/*    Terminate if no user name could be read within \fItimeout\fP
  160. X/*    seconds. This option is useful for dial-in lines.
  161. X/* .TP
  162. X/* -T term
  163. X/*    Specifies a value for the TERM environment variable.
  164. X/* SYSTEM V EXAMPLES
  165. X/* .ad
  166. X/* .fi
  167. X/*    This section shows sample entries for the \fI/etc/inittab\fP file.
  168. X/*
  169. X/*    System V.4 note: the port monitor facility should not listen on
  170. X/*    lines that are already being handled by \fIagetty\fP. One way to
  171. X/*    achieve this is to edit the \fI/etc/inittab\fP file so that the
  172. X/*    /usr/lib/saf/sac entry is turned off.
  173. X/* .na
  174. X/* .nf
  175. X/*
  176. X/*    For a hard-wired line:
  177. X/* .ti +5
  178. X/*    t0:234:respawn:/usr/sbin/agetty -T vt100 term/a 19200
  179. X/*
  180. X/*    For a dial-in line with a 2400/1200/300 baud modem:
  181. X/* .ti +5
  182. X/*    t1:234:respawn:/usr/sbin/agetty -mt60 term/b 2400,1200,300
  183. X/* .ad
  184. X/* .fi
  185. X/* .sp
  186. X/*    The latter requires that the \fIDTR\fP and \fICD\fP modem
  187. X/*    control lines are enabled (with Sun equipment, see the 
  188. X/*    eeprom(8) manual page).
  189. X/* .sp
  190. X/*    Some systems support multiple device entries for the same physical
  191. X/*    port, so that a single modem can be used for dial-in and for dial-out
  192. X/*    purposes. With Solaris 2.2 the dial-out and dial-in devices have
  193. X/*    different major numbers; with other System V implementations the
  194. X/*    dial-out and dial-in device minor numbers differ by, e.g., 128. On some
  195. X/*    systems it may be necessary to mknod(8) the /dev/whatever entries
  196. X/*    by hand.
  197. X/* SUNOS 4 EXAMPLES
  198. X/* .ad
  199. X/* .fi
  200. X/*    This section shows sample entries for the \fI/etc/ttytab\fP file.
  201. X/*    Note that init(8) appends the port name to the command
  202. X/*    specified in the inittab file.
  203. X/* .na
  204. X/* .nf
  205. X/*
  206. X/*    For a hard-wired line:
  207. X/* .ti +5
  208. X/*    ttya  "/usr/etc/agetty 9600"  vt100  on local
  209. X/*
  210. X/*    For a dial-in line with a 2400/1200/300 baud modem:
  211. X/* .ti +5
  212. X/*    ttyb  "/usr/etc/agetty -mt60 2400,1200,300"  unknown  on modem
  213. X/*
  214. X/* .ad
  215. X/* .fi
  216. X/* .sp
  217. X/*    The latter requires that the \fIDTR\fP and \fICD\fP modem
  218. X/*    control lines are enabled (see the eeprom(8) manual page).
  219. X/* .sp
  220. X/*    SunOS 4 supports multiple device entries for the same physical
  221. X/*    port, so that a single modem can be used for dial-in and for dial-out
  222. X/*    purposes. The dial-out device minor number is 128 higher than that
  223. X/*    of the dial-in device. It may be necessary to mknod the
  224. X/*    /dev/whatever entries by hand.
  225. X/* FILES
  226. X/*    /etc/utmp, the system status file (System V only).
  227. X/*    /etc/issue, printed before the login prompt (System V only).
  228. X/*    /dev/console, problem reports (if syslog(3) is not used).
  229. X/*    /etc/inittab (System V init(8) configuration file).
  230. X/*    /etc/ttytab (SunOS 4 init(8) configuration file).
  231. X/* BUGS
  232. X/*    The baud-rate detection feature (the \fI-m\fP option) requires that
  233. X/*    \fIagetty\fP be scheduled soon enough after completion of a dial-in
  234. X/*    call (within 30 ms with modems that talk at 2400 baud). For robustness,
  235. X/*    always use the \fI-m\fP option in combination with a multiple baud
  236. X/*    rate command-line argument, so that BREAK processing is enabled.
  237. X/*
  238. X/*    The text in the /etc/issue file (System V only) and the login prompt
  239. X/*    are always output with 7-bit characters and space parity.
  240. X/*
  241. X/*    The baud-rate detection feature (the \fI-m\fP option) requires that
  242. X/*    the modem emits its status message \fIafter\fP raising the DCD line.
  243. X/* DIAGNOSTICS
  244. X/*    Depending on how the program was configured, all diagnostics are
  245. X/*    written to the console device or reported via the syslog(3) facility.
  246. X/*    Error messages are produced if the \fIport\fP argument does not
  247. X/*    specify a terminal device; if there is no /etc/utmp entry for the
  248. X/*    current process (System V only); and so on.
  249. X/* AUTHOR(S)
  250. X/*    W.Z. Venema <wietse@wzv.win.tue.nl>
  251. X/*    Eindhoven University of Technology
  252. X/*    Department of Mathematics and Computer Science
  253. X/*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  254. X/* CREATION DATE
  255. X/*    Sat Nov 25 22:51:05 MET 1989
  256. X/* LAST MODIFICATION
  257. X/*    93/08/22 13:57:02
  258. X/* VERSION/RELEASE
  259. X/*    1.30
  260. X/*--*/
  261. X
  262. X#ifndef    lint
  263. Xchar sccsid[] = "@(#) agetty.c 1.30 22 Aug 1993 13:57:02";
  264. X#endif
  265. X
  266. X#include <termio.h>
  267. X#include <signal.h>
  268. X#include <errno.h>
  269. X#include <sys/types.h>
  270. X#include <sys/stat.h>
  271. X#include <fcntl.h>
  272. X#include <ctype.h>
  273. X#include <utmp.h>
  274. X#include <string.h>
  275. X
  276. X /* If USE_SYSLOG is undefined all diagnostics go directly to /dev/console. */
  277. X
  278. X#ifdef    USE_SYSLOG
  279. X#include <syslog.h>
  280. Xextern void closelog();
  281. X#endif
  282. X
  283. X /*
  284. X  * Some heuristics to find out what environment we are in: if it is not
  285. X  * System V, assume it is SunOS 4.
  286. X  */
  287. X
  288. X#ifdef    LOGIN_PROCESS            /* defined in System V utmp.h */
  289. X#define    SYSV_STYLE            /* select System V style getty */
  290. X#endif
  291. X
  292. X /*
  293. X  * What follows is an attempt to unify varargs.h and stdarg.h. I prefer this
  294. X  * over #ifdefs within the actual code.
  295. X  */
  296. X
  297. X#ifdef __STDC__
  298. X#include <stdarg.h>
  299. X#define VARARGS(func,type,arg) func(type arg, ...)
  300. X#define VASTART(ap,type,name)  va_start(ap,name)
  301. X#define VAEND(ap)              va_end(ap)
  302. X#else
  303. X#include <varargs.h>
  304. X#define VARARGS(func,type,arg) func(va_alist) va_dcl
  305. X#define VASTART(ap,type,name)  {type name; va_start(ap); name = va_arg(ap, type)
  306. X#define VAEND(ap)              va_end(ap);}
  307. X#endif
  308. X
  309. Xextern void exit();
  310. Xextern long time();
  311. X#ifdef SYSV_STYLE
  312. Xextern struct utmp *getutent();
  313. X#endif
  314. Xextern long atol();
  315. X
  316. X /*
  317. X  * Things you may want to modify.
  318. X  * 
  319. X  * If ISSUE is not defined, agetty will never display the contents of the
  320. X  * /etc/issue file. You will not want to spit out large "issue" files at the
  321. X  * wrong baud rate. Relevant for System V only.
  322. X  * 
  323. X  * You may disagree with the default line-editing etc. characters defined
  324. X  * below. Note, however, that DEL cannot be used for interrupt generation
  325. X  * and for line editing at the same time.
  326. X  */
  327. X
  328. X#ifdef    SYSV_STYLE
  329. X#define    ISSUE "/etc/issue"        /* displayed before the login prompt */
  330. X#endif
  331. X
  332. X#define LOGIN "login: "            /* login prompt */
  333. X
  334. X/* Some shorthands for control characters. */
  335. X
  336. X#define CTL(x)        (x ^ 0100)    /* Assumes ASCII dialect */
  337. X#define    CR        CTL('M')    /* carriage return */
  338. X#define    NL        CTL('J')    /* line feed */
  339. X#define    BS        CTL('H')    /* back space */
  340. X#define    DEL        CTL('?')    /* delete */
  341. X
  342. X/* Defaults for line-editing etc. characters; you may want to change this. */
  343. X
  344. X#define DEF_ERASE    DEL        /* default erase character */
  345. X#define DEF_INTR    CTL('C')    /* default interrupt character */
  346. X#define DEF_QUIT    CTL('\\')    /* default quit char */
  347. X#define DEF_KILL    CTL('U')    /* default kill char */
  348. X#define DEF_EOF        CTL('D')    /* default EOF char */
  349. X#define DEF_EOL        0
  350. X#define DEF_SWITCH    0        /* default switch char */
  351. X
  352. X /*
  353. X  * SunOS 4.1.x termio is broken. We must use the termios stuff instead,
  354. X  * because the termio -> termios translation does not clear the termios
  355. X  * CIBAUD bits. Therefore, the tty driver would sometimes report that input
  356. X  * baud rate != output baud rate. I did not notice that problem with SunOS
  357. X  * 4.1. We will use termios where available, and termio otherwise.
  358. X  */
  359. X
  360. X#ifndef SYSV_STYLE
  361. X#ifdef    TCGETS
  362. X#undef    TCGETA
  363. X#undef    TCSETA
  364. X#undef    TCSETAW
  365. X#define    termio    termios
  366. X#define    TCGETA    TCGETS
  367. X#define    TCSETA    TCSETS
  368. X#define    TCSETAW    TCSETSW
  369. X#endif
  370. X#endif                    /* SYSV_STYLE */
  371. X
  372. X /*
  373. X  * This program tries to not use the standard-i/o library.  This keeps the
  374. X  * executable small on systems that do not have shared libraries (System V
  375. X  * Release <3).
  376. X  */
  377. X
  378. X#define    BUFSIZ        1024
  379. X
  380. X /*
  381. X  * When multiple baud rates are specified on the command line, the first one
  382. X  * we will try is the first one specified.
  383. X  */
  384. X
  385. X#define    FIRST_SPEED    0
  386. X
  387. X/* Storage for command-line options. */
  388. X
  389. X#define    MAX_SPEED    10        /* max. nr. of baud rates */
  390. X
  391. Xstruct options {
  392. X    int     flags;            /* toggle switches, see below */
  393. X    int     timeout;            /* time-out period */
  394. X    char   *login;            /* login program */
  395. X    int     numspeed;            /* number of baud rates to try */
  396. X    int     speeds[MAX_SPEED];        /* baud rates to be tried */
  397. X    char   *tty;            /* name of tty */
  398. X};
  399. X
  400. X#define    F_PARSE        (1<<0)        /* process modem status messages */
  401. X#define    F_ISSUE        (1<<1)        /* display /etc/issue */
  402. X#define    F_RTSCTS    (1<<2)        /* enable RTS/CTS flow control */
  403. X
  404. X/* Storage for things detected while the login name was read. */
  405. X
  406. Xstruct chardata {
  407. X    int     erase;            /* erase character */
  408. X    int     kill;            /* kill character */
  409. X    int     eol;            /* end-of-line character */
  410. X    int     parity;            /* what parity did we see */
  411. X    int     capslock;            /* upper case without lower case */
  412. X};
  413. X
  414. X/* Initial values for the above. */
  415. X
  416. Xstruct chardata init_chardata = {
  417. X    DEF_ERASE,                /* default erase character */
  418. X    DEF_KILL,                /* default kill character */
  419. X    0,                    /* always filled in at runtime */
  420. X    0,                    /* space parity */
  421. X    0,                    /* always filled in at runtime */
  422. X};
  423. X
  424. X/* Forward declarations. */
  425. X
  426. Xvoid    parse_args();
  427. Xvoid    parse_speeds();
  428. X#ifdef SYSV_STYLE
  429. Xvoid    update_utmp();
  430. X#endif
  431. Xvoid    open_tty();
  432. Xvoid    termio_init();
  433. Xvoid    auto_baud();
  434. Xvoid    do_prompt();
  435. Xvoid    next_speed();
  436. Xchar   *get_logname();
  437. Xvoid    termio_final();
  438. Xint     caps_lock();
  439. Xint     bcode();
  440. Xvoid    usage();
  441. X#ifdef __STDC__
  442. Xvoid    error(char *fmt,...);
  443. X#else
  444. Xvoid    error();
  445. X#endif
  446. X
  447. X/* The following is used for understandable diagnostics. */
  448. X
  449. Xchar   *progname;
  450. X
  451. X/* ... */
  452. X
  453. Xint     main(argc, argv)
  454. Xint     argc;
  455. Xchar  **argv;
  456. X{
  457. X    char   *logname;            /* login name, given to /bin/login */
  458. X    struct chardata chardata;        /* set by get_logname() */
  459. X    struct termio termio;        /* terminal mode bits */
  460. X    static struct options options = {
  461. X    F_ISSUE,            /* show /etc/issue (SYSV_STYLE) */
  462. X    0,                /* no timeout */
  463. X    "/bin/login",            /* default login program */
  464. X    0,                /* no baud rates known yet */
  465. X    };
  466. X
  467. X    /* The BSD-style init command passes us a useless process name. */
  468. X
  469. X#ifdef    SYSV_STYLE
  470. X    progname = argv[0];
  471. X#else
  472. X    progname = "agetty";
  473. X#endif
  474. X
  475. X    /* Parse command-line arguments. */
  476. X
  477. X    parse_args(argc, argv, &options);
  478. X
  479. X    /* Update the utmp file. */
  480. X
  481. X#ifdef    SYSV_STYLE
  482. X    update_utmp(options.tty);
  483. X#endif
  484. X
  485. X    /* Open the tty as standard { input, output, error }. */
  486. X
  487. X    open_tty(options.tty, &termio);
  488. X
  489. X    /* Initialize the termio settings (raw mode, eight-bit, blocking i/o). */
  490. X
  491. X    termio_init(&termio, &options);
  492. X
  493. X    /* Optionally detect the baud rate from the modem status message. */
  494. X
  495. X    if (options.flags & F_PARSE)
  496. X    auto_baud(&termio);
  497. X
  498. X    /* Set the optional timer. */
  499. X
  500. X    if (options.timeout)
  501. X    (void) alarm((unsigned) options.timeout);
  502. X
  503. X    /* Read the login name. */
  504. X
  505. X    while ((logname = get_logname(&options, &chardata, &termio)) == 0)
  506. X    next_speed(&termio, &options);
  507. X
  508. X    /* Disable timer. */
  509. X
  510. X    if (options.timeout)
  511. X    (void) alarm(0);
  512. X
  513. X    /* Finalize the termio settings. */
  514. X
  515. X    termio_final(&options, &termio, &chardata);
  516. X
  517. X    /* Now the newline character should be properly written. */
  518. X
  519. X    (void) write(1, "\n", 1);
  520. X
  521. X    /* Let the login program take care of password validation. */
  522. X
  523. X    (void) execl(options.login, options.login, logname, (char *) 0);
  524. X    error("%s: can't exec %s: %m", options.tty, options.login);
  525. X    /* NOTREACHED */
  526. X}
  527. X
  528. X/* parse-args - parse command-line arguments */
  529. X
  530. Xvoid    parse_args(argc, argv, op)
  531. Xint     argc;
  532. Xchar  **argv;
  533. Xstruct options *op;
  534. X{
  535. X    extern char *optarg;        /* getopt */
  536. X    extern int optind;            /* getopt */
  537. X    int     c;
  538. X    static char termenv[30] = "TERM=";
  539. X
  540. X    while (isascii(c = getopt(argc, argv, "hil:mt:T:"))) {
  541. X    switch (c) {
  542. X    case 'h':                /* enable h/w flow control */
  543. X        op->flags |= F_RTSCTS;
  544. X        break;
  545. X    case 'i':                /* do not show /etc/issue */
  546. X        op->flags &= ~F_ISSUE;
  547. X        break;
  548. X    case 'l':
  549. X        op->login = optarg;            /* non-default login program */
  550. X        break;
  551. X    case 'm':                /* parse modem status message */
  552. X        op->flags |= F_PARSE;
  553. X        break;
  554. X    case 't':                /* time out */
  555. X        if ((op->timeout = atoi(optarg)) <= 0)
  556. X        error("bad timeout value: %s", optarg);
  557. X        break;
  558. X    case 'T':                /* terminal type */
  559. X        (void) strncpy(termenv + 5, optarg, 24);
  560. X        if (putenv(termenv))
  561. X        error("putenv: %m");
  562. X        break;
  563. X    default:
  564. X        usage();
  565. X    }
  566. X    }
  567. X    if (argc != optind + 2)            /* check parameter count */
  568. X    usage();
  569. X#ifdef    SYSV_STYLE
  570. X    op->tty = argv[optind++];            /* tty name */
  571. X    parse_speeds(op, argv[optind]);        /* baud rate(s) */
  572. X#else
  573. X    parse_speeds(op, argv[optind++]);        /* baud rate(s) */
  574. X    op->tty = argv[optind];            /* tty name */
  575. X#endif
  576. X}
  577. X
  578. X/* parse_speeds - parse alternate baud rates */
  579. X
  580. Xvoid    parse_speeds(op, arg)
  581. Xstruct options *op;
  582. Xchar   *arg;
  583. X{
  584. X    char   *cp;
  585. X
  586. X    for (cp = strtok(arg, ","); cp != 0; cp = strtok((char *) 0, ",")) {
  587. X    if ((op->speeds[op->numspeed++] = bcode(cp)) <= 0)
  588. X        error("bad speed: %s", cp);
  589. X    if (op->numspeed > MAX_SPEED)
  590. X        error("too many alternate speeds");
  591. X    }
  592. X}
  593. X
  594. X#ifdef    SYSV_STYLE
  595. X
  596. X/* update_utmp - update our utmp entry */
  597. X
  598. Xvoid    update_utmp(line)
  599. Xchar   *line;
  600. X{
  601. X    struct utmp *utp;
  602. X    int     mypid = getpid();
  603. X
  604. X    while (utp = getutent()) {
  605. X    if (utp->ut_type == INIT_PROCESS && utp->ut_pid == mypid) {
  606. X        utp->ut_type = LOGIN_PROCESS;
  607. X        utp->ut_time = time((long *) 0);
  608. X        (void) strncpy(utp->ut_name, "LOGIN", sizeof(utp->ut_name));
  609. X        (void) strncpy(utp->ut_line, line, sizeof(utp->ut_line));
  610. X        pututline(utp);
  611. X        endutent();
  612. X        return;
  613. X    }
  614. X    }
  615. X    error("%s: no utmp entry", line);
  616. X}
  617. X
  618. X#endif
  619. X
  620. X/* open_tty - set up tty as standard { input, output, error } */
  621. X
  622. Xvoid    open_tty(tty, tp)
  623. Xchar   *tty;
  624. Xstruct termio *tp;
  625. X{
  626. X    /* Get rid of the present standard { output, error} if any. */
  627. X
  628. X    (void) close(1);
  629. X    (void) close(2);
  630. X
  631. X    /* Set up new standard input, unless we are given an already opened port. */
  632. X
  633. X    if (strcmp(tty, "-")) {
  634. X    struct stat st;
  635. X
  636. X    /* Sanity checks... */
  637. X
  638. X    if (chdir("/dev"))
  639. X        error("/dev: chdir() failed: %m");
  640. X    if (stat(tty, &st) < 0)
  641. X        error("/dev/%s: %m", tty);
  642. X    if ((st.st_mode & S_IFMT) != S_IFCHR)
  643. X        error("/dev/%s: not a character device", tty);
  644. X
  645. X    /* Open the tty as standard input. */
  646. X
  647. X    (void) close(0);
  648. X
  649. X    if (open(tty, 2) != 0)
  650. X        error("/dev/%s: cannot open as standard input: %m", tty);
  651. X
  652. X    } else {
  653. X
  654. X    /*
  655. X     * Standard input should already be connected to an open port. Make
  656. X     * sure it is open for read/write.
  657. X     */
  658. X
  659. X    if ((fcntl(0, F_GETFL, 0) & O_RDWR) != O_RDWR)
  660. X        error("%s: not open for read/write", tty);
  661. X    }
  662. X
  663. X    /* Set up standard output and standard error file descriptors. */
  664. X
  665. X    if (dup(0) != 1 || dup(0) != 2)        /* set up stdout and stderr */
  666. X    error("%s: dup problem: %m", tty);    /* we have a problem */
  667. X
  668. X    /*
  669. X     * The following ioctl will fail if stdin is not a tty, but also when
  670. X     * there is noise on the modem control lines. In the latter case, the
  671. X     * common course of action is (1) fix your cables (2) give the modem more
  672. X     * time to properly reset after hanging up. SunOS users can achieve (2)
  673. X     * by patching the SunOS kernel variable "zsadtrlow" to a larger value; 5
  674. X     * seconds seems to be a good value.
  675. X     */
  676. X
  677. X    if (ioctl(0, TCGETA, tp) < 0)
  678. X    error("%s: ioctl: %m", tty);
  679. X
  680. X    /*
  681. X     * It seems to be a terminal. Set proper protections and ownership. Mode
  682. X     * 0622 is suitable for SYSV <4 because /bin/login does not change
  683. X     * protections. SunOS 4 login will change the protections to 0620 (write
  684. X     * access for group tty) after the login has succeeded. Ignore errors
  685. X     * because we may be called from an unprivileged call-back program.
  686. X     */
  687. X
  688. X    (void) chown(tty, 0, 0);            /* root, sys */
  689. X    (void) chmod(tty, 0622);            /* crw--w--w- */
  690. X}
  691. X
  692. X/* termio_init - initialize termio settings */
  693. X
  694. Xvoid    termio_init(tp, op)
  695. Xstruct termio *tp;
  696. Xstruct options *op;
  697. X{
  698. X
  699. X    /*
  700. X     * Initial termio settings: 8-bit characters, raw-mode, blocking i/o.
  701. X     * Special characters are set after we have read the login name; all
  702. X     * reads will be done in raw mode anyway. Errors will be dealt with
  703. X     * lateron. Turn on h/w flow control for huge /etc/issue files.
  704. X     */
  705. X
  706. X    tp->c_cflag = CS8 | HUPCL | CREAD | op->speeds[FIRST_SPEED];
  707. X#ifdef    CRTSCTS
  708. X    if (op->flags & F_RTSCTS)
  709. X    tp->c_cflag |= CRTSCTS;
  710. X#endif
  711. X    tp->c_iflag = tp->c_lflag = tp->c_oflag = tp->c_line = 0;
  712. X    tp->c_cc[VMIN] = 1;
  713. X    tp->c_cc[VTIME] = 0;
  714. X    (void) ioctl(0, TCSETA, tp);
  715. X}
  716. X
  717. X/* auto_baud - extract baud rate from modem status message */
  718. X
  719. Xvoid    auto_baud(tp)
  720. Xstruct termio *tp;
  721. X{
  722. X    int     speed;
  723. X    int     vmin;
  724. X    unsigned long iflag;
  725. X    char    buf[BUFSIZ];
  726. X    char   *bp;
  727. X    int     nread;
  728. X
  729. X    /*
  730. X     * This works only if the modem produces its status code AFTER raising
  731. X     * the DCD line, and if the computer is fast enough to set the proper
  732. X     * baud rate before the message has gone by. We expect a message of the
  733. X     * following format:
  734. X     * 
  735. X     * <junk><number><junk>
  736. X     * 
  737. X     * The number is interpreted as the baud rate of the incoming call. If the
  738. X     * modem does not tell us the baud rate within one second, we will keep
  739. X     * using the current baud rate. It is advisable to enable BREAK
  740. X     * processing (comma-separated list of baud rates) if the processing of
  741. X     * modem status messages is enabled.
  742. X     */
  743. X
  744. X    /*
  745. X     * Use 7-bit characters, don't block if input queue is empty. Errors will
  746. X     * be dealt with lateron.
  747. X     */
  748. X
  749. X    iflag = tp->c_iflag;
  750. X    tp->c_iflag |= ISTRIP;            /* enable 8th-bit stripping */
  751. X    vmin = tp->c_cc[VMIN];
  752. X    tp->c_cc[VMIN] = 0;                /* don't block if queue empty */
  753. X    (void) ioctl(0, TCSETA, tp);
  754. X
  755. X    /*
  756. X     * Wait for a while, then read everything the modem has said so far and
  757. X     * try to extract the speed of the dial-in call.
  758. X     */
  759. X
  760. X    (void) sleep(1);
  761. X    if ((nread = read(0, buf, sizeof(buf) - 1)) > 0) {
  762. X    buf[nread] = '\0';
  763. X    for (bp = buf; bp < buf + nread; bp++) {
  764. X        if (isascii(*bp) && isdigit(*bp)) {
  765. X        if (speed = bcode(bp)) {
  766. X            tp->c_cflag &= ~CBAUD;
  767. X            tp->c_cflag |= speed;
  768. X        }
  769. X        break;
  770. X        }
  771. X    }
  772. X    }
  773. X    /* Restore terminal settings. Errors will be dealt with lateron. */
  774. X
  775. X    tp->c_iflag = iflag;
  776. X    tp->c_cc[VMIN] = vmin;
  777. X    (void) ioctl(0, TCSETA, tp);
  778. X}
  779. X
  780. X/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
  781. X
  782. Xvoid    do_prompt(op, tp)
  783. Xstruct options *op;
  784. Xstruct termio *tp;
  785. X{
  786. X#ifdef    ISSUE
  787. X    int     fd;
  788. X    int     oflag;
  789. X    int     n;
  790. X    char    buf[BUFSIZ];
  791. X#endif
  792. X
  793. X    (void) write(1, "\r\n", 2);            /* start a new line */
  794. X#ifdef    ISSUE                    /* optional: show /etc/issue */
  795. X    if ((op->flags & F_ISSUE) && (fd = open(ISSUE, 0)) >= 0) {
  796. X    oflag = tp->c_oflag;            /* save current setting */
  797. X    tp->c_oflag |= (ONLCR | OPOST);        /* map NL in output to CR-NL */
  798. X    (void) ioctl(0, TCSETAW, tp);
  799. X    while ((n = read(fd, buf, sizeof(buf))) > 0)
  800. X        (void) write(1, buf, n);
  801. X    tp->c_oflag = oflag;            /* restore settings */
  802. X    (void) ioctl(0, TCSETAW, tp);        /* wait till output is gone */
  803. X    (void) close(fd);
  804. X    }
  805. X#endif
  806. X    (void) write(1, LOGIN, sizeof(LOGIN) - 1);    /* always show login prompt */
  807. X}
  808. X
  809. X/* next_speed - select next baud rate */
  810. X
  811. Xvoid    next_speed(tp, op)
  812. Xstruct termio *tp;
  813. Xstruct options *op;
  814. X{
  815. X    static int baud_index = FIRST_SPEED;/* current speed index */
  816. X
  817. X    baud_index = (baud_index + 1) % op->numspeed;
  818. X    tp->c_cflag &= ~CBAUD;
  819. X    tp->c_cflag |= op->speeds[baud_index];
  820. X    (void) ioctl(0, TCSETA, tp);
  821. X}
  822. X
  823. X/* get_logname - get user name, establish parity, speed, erase, kill, eol */
  824. X
  825. Xchar   *get_logname(op, cp, tp)
  826. Xstruct options *op;
  827. Xstruct chardata *cp;
  828. Xstruct termio *tp;
  829. X{
  830. X    char    logname[BUFSIZ];
  831. X    char   *bp;
  832. X    char    c;                /* input character, full eight bits */
  833. X    char    ascval;            /* low 7 bits of input character */
  834. X    int     bits;            /* # of "1" bits per character */
  835. X    int     mask;            /* mask with 1 bit up */
  836. X    static char *erase[] = {        /* backspace-space-backspace */
  837. X    "\010\040\010",            /* space parity */
  838. X    "\010\040\010",            /* odd parity */
  839. X    "\210\240\210",            /* even parity */
  840. X    "\210\240\210",            /* no parity */
  841. X    };
  842. X
  843. X    /* Initialize kill, erase, parity etc. (also after switching speeds). */
  844. X
  845. X    *cp = init_chardata;
  846. X
  847. X    /* Flush pending input (esp. after parsing or switching the baud rate). */
  848. X
  849. X    (void) sleep(1);
  850. X    (void) ioctl(0, TCFLSH, (struct termio *) 0);
  851. X
  852. X    /* Prompt for and read a login name. */
  853. X
  854. X    for (*logname = 0; *logname == 0; /* void */ ) {
  855. X
  856. X    /* Write issue file and prompt, with "parity" bit == 0. */
  857. X
  858. X    do_prompt(op, tp);
  859. X
  860. X    /* Read name, watch for break, parity, erase, kill, end-of-line. */
  861. X
  862. X    for (bp = logname, cp->eol = 0; cp->eol == 0; /* void */ ) {
  863. X
  864. X        /* Do not report trivial EINTR/EIO errors. */
  865. X
  866. X        if (read(0, &c, 1) < 1) {
  867. X        if (errno == EINTR || errno == EIO)
  868. X            exit(0);
  869. X        error("%s: read: %m", op->tty);
  870. X        }
  871. X        /* Do BREAK handling elsewhere. */
  872. X
  873. X        if ((c == 0) && op->numspeed > 1)
  874. X        return (0);
  875. X
  876. X        /* Do parity bit handling. */
  877. X
  878. X        if (c != (ascval = (c & 0177))) {    /* "parity" bit on ? */
  879. X        for (bits = 1, mask = 1; mask & 0177; mask <<= 1)
  880. X            if (mask & ascval)
  881. X            bits++;            /* count "1" bits */
  882. X        cp->parity |= ((bits & 1) ? 1 : 2);
  883. X        }
  884. X        /* Do erase, kill and end-of-line processing. */
  885. X
  886. X        switch (ascval) {
  887. X        case CR:
  888. X        case NL:
  889. X        *bp = 0;            /* terminate logname */
  890. X        cp->eol = ascval;        /* set end-of-line char */
  891. X        break;
  892. X        case BS:
  893. X        case DEL:
  894. X        case '#':
  895. X        cp->erase = ascval;        /* set erase character */
  896. X        if (bp > logname) {
  897. X            (void) write(1, erase[cp->parity], 3);
  898. X            bp--;
  899. X        }
  900. X        break;
  901. X        case CTL('U'):
  902. X        case '@':
  903. X        cp->kill = ascval;        /* set kill character */
  904. X        while (bp > logname) {
  905. X            (void) write(1, erase[cp->parity], 3);
  906. X            bp--;
  907. X        }
  908. X        break;
  909. X        case CTL('D'):
  910. X        exit(0);
  911. X        default:
  912. X        if (!isascii(ascval) || !isprint(ascval)) {
  913. X             /* ignore garbage characters */ ;
  914. X        } else if (bp - logname >= sizeof(logname) - 1) {
  915. X            error("%s: input overrun", op->tty);
  916. X        } else {
  917. X            (void) write(1, &c, 1);    /* echo the character */
  918. X            *bp++ = ascval;        /* and store it */
  919. X        }
  920. X        break;
  921. X        }
  922. X    }
  923. X    }
  924. X    /* Handle names with upper case and no lower case. */
  925. X
  926. X    if (cp->capslock = caps_lock(logname)) {
  927. X    for (bp = logname; *bp; bp++)
  928. X        if (isupper(*bp))
  929. X        *bp = tolower(*bp);        /* map name to lower case */
  930. X    }
  931. X    return (logname);
  932. X}
  933. X
  934. X/* termio_final - set the final tty mode bits */
  935. X
  936. Xvoid    termio_final(op, tp, cp)
  937. Xstruct options *op;
  938. Xstruct termio *tp;
  939. Xstruct chardata *cp;
  940. X{
  941. X    /* General terminal-independent stuff. */
  942. X
  943. X    tp->c_iflag |= IXON | IXOFF;        /* 2-way flow control */
  944. X    tp->c_lflag |= ICANON | ISIG | ECHO | ECHOE | ECHOK;
  945. X    tp->c_oflag |= OPOST;
  946. X    tp->c_cc[VINTR] = DEF_INTR;            /* default interrupt */
  947. X    tp->c_cc[VQUIT] = DEF_QUIT;            /* default quit */
  948. X    tp->c_cc[VEOF] = DEF_EOF;            /* default EOF character */
  949. X    tp->c_cc[VEOL] = DEF_EOL;
  950. X    tp->c_cc[VSWTCH] = DEF_SWITCH;        /* default switch character */
  951. X
  952. X    /* Account for special characters seen in input. */
  953. X
  954. X    if (cp->eol == CR) {
  955. X    tp->c_iflag |= ICRNL;            /* map CR in input to NL */
  956. X    tp->c_oflag |= ONLCR;            /* map NL in output to CR-NL */
  957. X    }
  958. X    tp->c_cc[VERASE] = cp->erase;        /* set erase character */
  959. X    tp->c_cc[VKILL] = cp->kill;            /* set kill character */
  960. X
  961. X    /* Account for the presence or absence of parity bits in input. */
  962. X
  963. X    switch (cp->parity) {
  964. X    case 0:                    /* space (always 0) parity */
  965. X    break;
  966. X    case 1:                    /* odd parity */
  967. X    tp->c_cflag |= PARODD;
  968. X    /* FALLTHROUGH */
  969. X    case 2:                    /* even parity */
  970. X    tp->c_cflag |= PARENB;
  971. X    tp->c_iflag |= INPCK | ISTRIP;
  972. X    /* FALLTHROUGH */
  973. X    case (1 | 2):                /* no parity bit */
  974. X    tp->c_cflag &= ~CSIZE;
  975. X    tp->c_cflag |= CS7;
  976. X    break;
  977. X    }
  978. X    /* Account for upper case without lower case. */
  979. X
  980. X    if (cp->capslock) {
  981. X    tp->c_iflag |= IUCLC;
  982. X    tp->c_lflag |= XCASE;
  983. X    tp->c_oflag |= OLCUC;
  984. X    }
  985. X    /* Optionally enable hardware flow control */
  986. X
  987. X#ifdef    CRTSCTS
  988. X    if (op->flags & F_RTSCTS)
  989. X    tp->c_cflag |= CRTSCTS;
  990. X#endif
  991. X
  992. X    /* Finally, make the new settings effective */
  993. X
  994. X    if (ioctl(0, TCSETA, tp) < 0)
  995. X    error("%s: ioctl: TCSETA: %m", op->tty);
  996. X}
  997. X
  998. X/* caps_lock - string contains upper case without lower case */
  999. X
  1000. Xint     caps_lock(s)
  1001. Xchar   *s;
  1002. X{
  1003. X    int     capslock;
  1004. X
  1005. X    for (capslock = 0; *s; s++) {
  1006. X    if (islower(*s))
  1007. X        return (0);
  1008. X    if (capslock == 0)
  1009. X        capslock = isupper(*s);
  1010. X    }
  1011. X    return (capslock);
  1012. X}
  1013. X
  1014. X/* bcode - convert speed string to speed code; return 0 on failure */
  1015. X
  1016. Xint     bcode(s)
  1017. Xchar   *s;
  1018. X{
  1019. X    struct Speedtab {
  1020. X    long    speed;
  1021. X    int     code;
  1022. X    };
  1023. X    static struct Speedtab speedtab[] = {
  1024. X    50, B50,
  1025. X    75, B75,
  1026. X    110, B110,
  1027. X    134, B134,
  1028. X    150, B150,
  1029. X    200, B200,
  1030. X    300, B300,
  1031. X    600, B600,
  1032. X    1200, B1200,
  1033. X    1800, B1800,
  1034. X    2400, B2400,
  1035. X    4800, B4800,
  1036. X    9600, B9600,
  1037. X#ifdef    B19200
  1038. X    19200, B19200,
  1039. X#endif
  1040. X#ifdef    B38400
  1041. X    38400, B38400,
  1042. X#endif
  1043. X#ifdef    EXTA
  1044. X    19200, EXTA,
  1045. X#endif
  1046. X#ifdef    EXTB
  1047. X    38400, EXTB,
  1048. X#endif
  1049. X    0, 0,
  1050. X    };
  1051. X    struct Speedtab *sp;
  1052. X    long    speed = atol(s);
  1053. X
  1054. X    for (sp = speedtab; sp->speed; sp++)
  1055. X    if (sp->speed == speed)
  1056. X        return (sp->code);
  1057. X    return (0);
  1058. X}
  1059. X
  1060. X/* usage - explain */
  1061. X
  1062. Xvoid    usage()
  1063. X{
  1064. X#ifdef    SYSV_STYLE
  1065. X    static char msg[] =
  1066. X    "[-ih] [-l login] [-m] [-t timeout] [-T term] line speed,...";
  1067. X#else
  1068. X    static char msg[] =
  1069. X    "[-h] [-l login] [-m] [-t timeout] speed,... line";
  1070. X#endif
  1071. X
  1072. X    error("usage: %s %s", progname, msg);
  1073. X}
  1074. X
  1075. X/* error - report errors to console or syslog; only understands %s and %m */
  1076. X
  1077. X#define    str2cpy(b,s1,s2)    strcat(strcpy(b,s1),s2)
  1078. X
  1079. X/* VARARGS */
  1080. X
  1081. Xvoid    VARARGS(error, char *, fmt)
  1082. X{
  1083. X    va_list ap;
  1084. X#ifndef    USE_SYSLOG
  1085. X    int     fd;
  1086. X#endif
  1087. X    char    buf[BUFSIZ];
  1088. X    char   *bp;
  1089. X    extern char *sys_errlist[];
  1090. X
  1091. X    /*
  1092. X     * If the diagnostic is reported via syslog(3), the process name is
  1093. X     * automatically prepended to the message. If we write directly to
  1094. X     * /dev/console, we must prepend the process name ourselves.
  1095. X     */
  1096. X
  1097. X#ifdef USE_SYSLOG
  1098. X    buf[0] = '\0';
  1099. X    bp = buf;
  1100. X#else
  1101. X    (void) str2cpy(buf, progname, ": ");
  1102. X    bp = buf + strlen(buf);
  1103. X#endif
  1104. X
  1105. X    /*
  1106. X     * %s expansion is done by hand. On a System V Release 2 system without
  1107. X     * shared libraries and without syslog(3), linking with the stdio library
  1108. X     * used to make the program three times as big...
  1109. X     * 
  1110. X     * %m expansion is done here as well. Too bad syslog(3) does not have a
  1111. X     * vsprintf() like interface.
  1112. X     */
  1113. X
  1114. X    VASTART(ap, char *, fmt);
  1115. X    while (*fmt) {
  1116. X    if (strncmp(fmt, "%s", 2) == 0) {
  1117. X        (void) strcpy(bp, va_arg(ap, char *));
  1118. X        bp += strlen(bp);
  1119. X        fmt += 2;
  1120. X    } else if (strncmp(fmt, "%m", 2) == 0) {
  1121. X        (void) strcpy(bp, sys_errlist[errno]);
  1122. X        bp += strlen(bp);
  1123. X        fmt += 2;
  1124. X    } else if (strncmp(fmt, "%%", 2) == 0) {
  1125. X        *bp++ = *fmt++;
  1126. X        fmt++;
  1127. X    } else {
  1128. X        *bp++ = *fmt++;
  1129. X    }
  1130. X    }
  1131. X    *bp = 0;
  1132. X    VAEND(ap);
  1133. X
  1134. X    /*
  1135. X     * Write the diagnostic directly to /dev/console if we do not use the
  1136. X     * syslog(3) facility.
  1137. X     */
  1138. X
  1139. X#ifdef    USE_SYSLOG
  1140. X    (void) openlog(progname, LOG_PID, LOG_AUTH);
  1141. X    (void) syslog(LOG_ERR, "%s", buf);
  1142. X    closelog();
  1143. X#else
  1144. X    /* Terminate with CR-LF since the console mode is unknown. */
  1145. X    (void) strcat(bp, "\r\n");
  1146. X    if ((fd = open("/dev/console", 1)) >= 0) {
  1147. X    (void) write(fd, buf, strlen(buf));
  1148. X    (void) close(fd);
  1149. X    }
  1150. X#endif
  1151. X    (void) sleep((unsigned) 10);        /* be kind to init(8) */
  1152. X    exit(1);
  1153. X}
  1154. END_OF_agetty.c
  1155. if test 29916 -ne `wc -c <agetty.c`; then
  1156.     echo shar: \"agetty.c\" unpacked with wrong size!
  1157. fi
  1158. # end of overwriting check
  1159. fi
  1160. if test -f agetty.8 -a "${1}" != "-c" ; then 
  1161.   echo shar: Will not over-write existing file \"agetty.8\"
  1162. else
  1163. echo shar: Extracting \"agetty.8\" \(6574 characters\)
  1164. sed "s/^X//" >agetty.8 <<'END_OF_agetty.8'
  1165. X.TH AGETTY 8 
  1166. X.ad
  1167. X.fi
  1168. X.SH NAME
  1169. Xagetty
  1170. X\-
  1171. Xalternative System V/SunOS 4 getty
  1172. X.SH SYSTEM V SYNOPSIS
  1173. X.na
  1174. X.nf
  1175. Xagetty [-ih] [-l login] [-m] [-t timeout] [-T term] port speed,...
  1176. X.SH SUNOS 4 SYNOPSIS
  1177. X.na
  1178. X.nf
  1179. Xagetty [-h] [-l login] [-m] [-t timeout] speed,... port
  1180. X.SH DESCRIPTION
  1181. X.ad
  1182. X.fi
  1183. X\fIagetty\fP opens a tty port, prompts for a login name and invokes
  1184. Xthe /bin/login command. It is normally invoked by \fIinit(8)\fP.
  1185. X
  1186. X\fIagetty\fP has several \fInon-standard\fP features that are useful
  1187. Xfor hard-wired and for dial-in lines:
  1188. X.IP o
  1189. XAdapts to parity bits and to line editing, end-of-line, and
  1190. Xuppercase-only characters when it reads a login name.
  1191. XThe program can handle 7-bit characters with even, odd, none or space
  1192. Xparity, and 8-bit characters with no parity. The following special
  1193. Xcharacters are recognized: @ and Control-U (kill); #, DEL and
  1194. Xback space (erase); carriage return and line feed (end of line).
  1195. X.IP o
  1196. XOptionally deduces the baud rate from the CONNECT messages produced by
  1197. XHayes(tm)-compatible modems.
  1198. X.PP
  1199. XThis program does not use any configuration file.
  1200. X.SH ARGUMENTS
  1201. X.na
  1202. X.nf
  1203. X.fi
  1204. X.ad
  1205. X.TP
  1206. Xport
  1207. XA path name relative to the \fI/dev\fP directory. If a "-" is
  1208. Xspecified, \fIagetty\fP assumes that its standard input is
  1209. Xalready connected to a tty port and that a connection to a
  1210. Xremote user has already been established.
  1211. X.sp
  1212. XUnder System V, a "-" \fIport\fP argument should be preceded
  1213. Xby a "--".
  1214. X.TP
  1215. Xspeed,...
  1216. XA comma-separated list of one or more baud rates. Each time
  1217. X\fIagetty\fP receives a BREAK character it advances through
  1218. Xthe list, which is treated as if it were circular.
  1219. X.sp
  1220. XBaud rates should be specified in descending order, so that the
  1221. Xnull character (Ctrl-@) can also be used for baud rate switching.
  1222. X.SH OPTIONS
  1223. X.na
  1224. X.nf
  1225. X.fi
  1226. X.ad
  1227. X.TP
  1228. X-h
  1229. XEnable hardware (RTS/CTS) flow control. It is left up to the
  1230. Xapplication to disable software (XON/XOFF) flow protocol where
  1231. Xappropriate.
  1232. X.TP
  1233. X-i (System V only)
  1234. XDo not display the contents of \fI/etc/issue\fP before writing the
  1235. Xlogin prompt. Terminals or communications hardware may become confused
  1236. Xwhen receiving lots of text at the wrong baud rate; dial-up scripts
  1237. Xmay fail if the login prompt is preceded by too much text.
  1238. X.TP
  1239. X-l login
  1240. XInvoke the specified \fIlogin\fP program instead of /bin/login.
  1241. XFor example, one that asks for an additional dial-up password or
  1242. Xone that uses a different password file.
  1243. X.TP
  1244. X-m
  1245. XTry to extract the baud rate from the \fIconnect\fP status message
  1246. Xproduced by some Hayes(tm)-compatible modems. These status
  1247. Xmessages are of the form: "<junk><speed><junk>".
  1248. X\fIagetty\fP assumes that the modem emits its status message at
  1249. Xthe same speed as specified with (the first) \fIspeed\fP value
  1250. Xon the command line.
  1251. X.sp
  1252. XSince the \fI-m\fP feature may fail on heavily-loaded systems,
  1253. Xyou still should enable BREAK processing by enumerating all
  1254. Xexpected baud rates on the command line.
  1255. X.TP
  1256. X-t timeout
  1257. XTerminate if no user name could be read within \fItimeout\fP
  1258. Xseconds. This option is useful for dial-in lines.
  1259. X.TP
  1260. X-T term
  1261. XSpecifies a value for the TERM environment variable.
  1262. X.SH SYSTEM V EXAMPLES
  1263. X.na
  1264. X.nf
  1265. X.ad
  1266. X.fi
  1267. XThis section shows sample entries for the \fI/etc/inittab\fP file.
  1268. X
  1269. XSystem V.4 note: the port monitor facility should not listen on
  1270. Xlines that are already being handled by \fIagetty\fP. One way to
  1271. Xachieve this is to edit the \fI/etc/inittab\fP file so that the
  1272. X/usr/lib/saf/sac entry is turned off.
  1273. X.na
  1274. X.nf
  1275. X
  1276. XFor a hard-wired line:
  1277. X.ti +5
  1278. Xt0:234:respawn:/usr/sbin/agetty -T vt100 term/a 19200
  1279. X
  1280. XFor a dial-in line with a 2400/1200/300 baud modem:
  1281. X.ti +5
  1282. Xt1:234:respawn:/usr/sbin/agetty -mt60 term/b 2400,1200,300
  1283. X.ad
  1284. X.fi
  1285. X.sp
  1286. XThe latter requires that the \fIDTR\fP and \fICD\fP modem
  1287. Xcontrol lines are enabled (with Sun equipment, see the
  1288. Xeeprom(8) manual page).
  1289. X.sp
  1290. XSome systems support multiple device entries for the same physical
  1291. Xport, so that a single modem can be used for dial-in and for dial-out
  1292. Xpurposes. With Solaris 2.2 the dial-out and dial-in devices have
  1293. Xdifferent major numbers; with other System V implementations the
  1294. Xdial-out and dial-in device minor numbers differ by, e.g., 128. On some
  1295. Xsystems it may be necessary to mknod(8) the /dev/whatever entries
  1296. Xby hand.
  1297. X.SH SUNOS 4 EXAMPLES
  1298. X.na
  1299. X.nf
  1300. X.ad
  1301. X.fi
  1302. XThis section shows sample entries for the \fI/etc/ttytab\fP file.
  1303. XNote that init(8) appends the port name to the command
  1304. Xspecified in the inittab file.
  1305. X.na
  1306. X.nf
  1307. X
  1308. XFor a hard-wired line:
  1309. X.ti +5
  1310. Xttya  "/usr/etc/agetty 9600"  vt100  on local
  1311. X
  1312. XFor a dial-in line with a 2400/1200/300 baud modem:
  1313. X.ti +5
  1314. Xttyb  "/usr/etc/agetty -mt60 2400,1200,300"  unknown  on modem
  1315. X
  1316. X.ad
  1317. X.fi
  1318. X.sp
  1319. XThe latter requires that the \fIDTR\fP and \fICD\fP modem
  1320. Xcontrol lines are enabled (see the eeprom(8) manual page).
  1321. X.sp
  1322. XSunOS 4 supports multiple device entries for the same physical
  1323. Xport, so that a single modem can be used for dial-in and for dial-out
  1324. Xpurposes. The dial-out device minor number is 128 higher than that
  1325. Xof the dial-in device. It may be necessary to mknod the
  1326. X/dev/whatever entries by hand.
  1327. X.SH FILES
  1328. X.na
  1329. X.nf
  1330. X/etc/utmp, the system status file (System V only).
  1331. X/etc/issue, printed before the login prompt (System V only).
  1332. X/dev/console, problem reports (if syslog(3) is not used).
  1333. X/etc/inittab (System V init(8) configuration file).
  1334. X/etc/ttytab (SunOS 4 init(8) configuration file).
  1335. X.SH BUGS
  1336. X.ad
  1337. X.fi
  1338. XThe baud-rate detection feature (the \fI-m\fP option) requires that
  1339. X\fIagetty\fP be scheduled soon enough after completion of a dial-in
  1340. Xcall (within 30 ms with modems that talk at 2400 baud). For robustness,
  1341. Xalways use the \fI-m\fP option in combination with a multiple baud
  1342. Xrate command-line argument, so that BREAK processing is enabled.
  1343. X
  1344. XThe text in the /etc/issue file (System V only) and the login prompt
  1345. Xare always output with 7-bit characters and space parity.
  1346. X
  1347. XThe baud-rate detection feature (the \fI-m\fP option) requires that
  1348. Xthe modem emits its status message \fIafter\fP raising the DCD line.
  1349. X.SH DIAGNOSTICS
  1350. X.ad
  1351. X.fi
  1352. XDepending on how the program was configured, all diagnostics are
  1353. Xwritten to the console device or reported via the syslog(3) facility.
  1354. XError messages are produced if the \fIport\fP argument does not
  1355. Xspecify a terminal device; if there is no /etc/utmp entry for the
  1356. Xcurrent process (System V only); and so on.
  1357. X.SH AUTHOR(S)
  1358. X.na
  1359. X.nf
  1360. XW.Z. Venema <wietse@wzv.win.tue.nl>
  1361. XEindhoven University of Technology
  1362. XDepartment of Mathematics and Computer Science
  1363. XDen Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  1364. X.SH CREATION DATE
  1365. X.na
  1366. X.nf
  1367. XSat Nov 25 22:51:05 MET 1989
  1368. X.SH LAST MODIFICATION
  1369. X.na
  1370. X.nf
  1371. X93/08/22 13:57:02
  1372. X.SH VERSION/RELEASE
  1373. X.na
  1374. X.nf
  1375. X1.30
  1376. END_OF_agetty.8
  1377. if test 6574 -ne `wc -c <agetty.8`; then
  1378.     echo shar: \"agetty.8\" unpacked with wrong size!
  1379. fi
  1380. # end of overwriting check
  1381. fi
  1382. if test -f Makefile -a "${1}" != "-c" ; then 
  1383.   echo shar: Will not over-write existing file \"Makefile\"
  1384. else
  1385. echo shar: Extracting \"Makefile\" \(448 characters\)
  1386. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  1387. X# @(#) Makefile 1.5 9/1/91 23:21:21 
  1388. X
  1389. X# On the CFLAGS line, specify -DUSE_SYSLOG if you want diagnostics to be
  1390. X# reported via the syslog(3) facility. Otherwise, agetty will report its
  1391. X# problems to /dev/console.
  1392. X
  1393. XSHELL    = /bin/sh
  1394. XCFLAGS    = -s -O # -DUSE_SYSLOG
  1395. XFILES    = README agetty.c agetty.8 Makefile
  1396. X
  1397. Xagetty: agetty.c
  1398. X    $(CC) $(CFLAGS) -o $@ $?
  1399. X
  1400. Xclean:
  1401. X    rm -f agetty.o agetty
  1402. X
  1403. Xshar:    $(FILES)
  1404. X    @shar $(FILES)
  1405. X
  1406. Xagetty.8:
  1407. X    srctoman agetty.c >agetty.8
  1408. END_OF_Makefile
  1409. if test 448 -ne `wc -c <Makefile`; then
  1410.     echo shar: \"Makefile\" unpacked with wrong size!
  1411. fi
  1412. # end of overwriting check
  1413. fi
  1414. echo shar: End of shell archive.
  1415. exit 0
  1416.  
  1417. exit 0 # Just in case...
  1418.