Expect

Hex Artifact Content
Login

Hex Artifact Content

Artifact e37844109f96b0fcfae00fba19068416b95cec0f:


0000: 2f 2a 20 70 74 79 5f 75 6e 69 63 6f 73 2e 63 20  /* pty_unicos.c 
0010: 2d 20 72 6f 75 74 69 6e 65 73 20 74 6f 20 61 6c  - routines to al
0020: 6c 6f 63 61 74 65 20 70 74 79 73 20 2d 20 66 6f  locate ptys - fo
0030: 72 20 43 52 41 59 20 55 4e 49 43 4f 53 20 35 2e  r CRAY UNICOS 5.
0040: 31 20 61 6e 64 20 36 2e 30 20 2a 2f 0a 0a 2f 2a  1 and 6.0 */../*
0050: 0a 0a 4f 72 69 67 69 6e 61 6c 20 62 79 3a 20 44  ..Original by: D
0060: 6f 6e 20 4c 69 62 65 73 2c 20 4e 49 53 54 2c 20  on Libes, NIST, 
0070: 32 2f 36 2f 39 30 0a 48 61 63 6b 65 64 20 66 6f  2/6/90.Hacked fo
0080: 72 20 55 6e 69 63 6f 73 20 35 2e 31 20 62 79 3a  r Unicos 5.1 by:
0090: 20 46 72 61 6e 6b 20 54 65 72 68 61 61 72 2d 59   Frank Terhaar-Y
00a0: 6f 6e 6b 65 72 73 2c 20 55 53 20 45 50 41 2c 20  onkers, US EPA, 
00b0: 20 31 2f 31 30 2f 39 31 0a 48 61 63 6b 65 64 20   1/10/91.Hacked 
00c0: 66 6f 72 20 55 6e 69 63 6f 73 20 36 2e 30 20 62  for Unicos 6.0 b
00d0: 79 3a 20 50 65 74 65 20 54 65 72 4d 61 61 74 2c  y: Pete TerMaat,
00e0: 20 70 65 74 65 40 77 69 6c 6c 6f 77 2e 63 72 61   [email protected]
00f0: 79 2e 63 6f 6d 2c 20 33 2f 32 37 2f 39 31 0a 0a  y.com, 3/27/91..
0100: 44 65 73 69 67 6e 20 61 6e 64 20 69 6d 70 6c 65  Design and imple
0110: 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 74 68 69  mentation of thi
0120: 73 20 70 72 6f 67 72 61 6d 20 77 61 73 20 70 61  s program was pa
0130: 69 64 20 66 6f 72 20 62 79 20 55 2e 53 2e 20 74  id for by U.S. t
0140: 61 78 0a 64 6f 6c 6c 61 72 73 2e 20 20 54 68 65  ax.dollars.  The
0150: 72 65 66 6f 72 65 20 69 74 20 69 73 20 70 75 62  refore it is pub
0160: 6c 69 63 20 64 6f 6d 61 69 6e 2e 20 20 48 6f 77  lic domain.  How
0170: 65 76 65 72 2c 20 74 68 65 20 61 75 74 68 6f 72  ever, the author
0180: 20 61 6e 64 20 4e 49 53 54 0a 77 6f 75 6c 64 20   and NIST.would 
0190: 61 70 70 72 65 63 69 61 74 65 20 63 72 65 64 69  appreciate credi
01a0: 74 20 69 66 20 74 68 69 73 20 70 72 6f 67 72 61  t if this progra
01b0: 6d 20 6f 72 20 70 61 72 74 73 20 6f 66 20 69 74  m or parts of it
01c0: 20 61 72 65 20 75 73 65 64 2e 0a 0a 2a 2f 0a 0a   are used...*/..
01d0: 23 69 6e 63 6c 75 64 65 20 22 65 78 70 65 63 74  #include "expect
01e0: 5f 63 66 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20  _cf.h".#include 
01f0: 3c 73 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c 75  <stdio.h>.#inclu
0200: 64 65 20 3c 73 69 67 6e 61 6c 2e 68 3e 0a 0a 23  de <signal.h>..#
0210: 69 66 20 64 65 66 69 6e 65 64 28 53 49 47 43 4c  if defined(SIGCL
0220: 44 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53  D) && !defined(S
0230: 49 47 43 48 4c 44 29 0a 23 64 65 66 69 6e 65 20  IGCHLD).#define 
0240: 53 49 47 43 48 4c 44 20 53 49 47 43 4c 44 0a 23  SIGCHLD SIGCLD.#
0250: 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 48 41  endif..#ifdef HA
0260: 56 45 5f 55 4e 49 53 54 44 5f 48 0a 23 69 6e 63  VE_UNISTD_H.#inc
0270: 6c 75 64 65 20 3c 75 6e 69 73 74 64 2e 68 3e 0a  lude <unistd.h>.
0280: 23 65 6c 73 65 0a 65 78 74 65 72 6e 20 69 6e 74  #else.extern int
0290: 20 66 6f 72 6b 28 29 2c 20 65 78 65 63 6c 28 29   fork(), execl()
02a0: 2c 20 77 61 69 74 28 29 3b 0a 23 65 6e 64 69 66  , wait();.#endif
02b0: 0a 23 69 6e 63 6c 75 64 65 20 3c 65 72 72 6e 6f  .#include <errno
02c0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 79  .h>.#include <sy
02d0: 73 2f 74 79 70 65 73 2e 68 3e 0a 23 69 6e 63 6c  s/types.h>.#incl
02e0: 75 64 65 20 3c 73 79 73 2f 73 74 61 74 2e 68 3e  ude <sys/stat.h>
02f0: 0a 23 69 6e 63 6c 75 64 65 20 3c 73 79 73 2f 69  .#include <sys/i
0300: 6f 63 74 6c 2e 68 3e 0a 23 69 6e 63 6c 75 64 65  octl.h>.#include
0310: 20 3c 73 79 73 2f 66 69 6c 65 2e 68 3e 0a 23 69   <sys/file.h>.#i
0320: 66 64 65 66 20 48 41 56 45 5f 53 59 53 5f 46 43  fdef HAVE_SYS_FC
0330: 4e 54 4c 5f 48 0a 23 20 20 69 6e 63 6c 75 64 65  NTL_H.#  include
0340: 20 3c 73 79 73 2f 66 63 6e 74 6c 2e 68 3e 0a 23   <sys/fcntl.h>.#
0350: 65 6c 73 65 0a 23 20 20 69 6e 63 6c 75 64 65 20  else.#  include 
0360: 3c 66 63 6e 74 6c 2e 68 3e 0a 23 65 6e 64 69 66  <fcntl.h>.#endif
0370: 0a 2f 2a 23 69 66 20 43 52 41 59 3e 3d 36 30 2a  ./*#if CRAY>=60*
0380: 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 48 41  /.#if defined(HA
0390: 56 45 5f 54 45 52 4d 49 4f 53 29 0a 23 20 69 6e  VE_TERMIOS).# in
03a0: 63 6c 75 64 65 20 3c 73 79 73 2f 74 65 72 6d 69  clude <sys/termi
03b0: 6f 73 2e 68 3e 0a 23 65 6c 73 65 0a 23 20 69 6e  os.h>.#else.# in
03c0: 63 6c 75 64 65 20 3c 73 79 73 2f 74 65 72 6d 69  clude <sys/termi
03d0: 6f 2e 68 3e 0a 2f 2a 23 65 6e 64 69 66 20 2f 2a  o.h>./*#endif /*
03e0: 20 36 30 20 2a 2f 2a 2f 0a 23 65 6e 64 69 66 20   60 */*/.#endif 
03f0: 2f 2a 20 64 65 66 69 6e 65 64 28 48 41 56 45 5f  /* defined(HAVE_
0400: 54 45 52 4d 49 4f 53 29 20 2a 2f 0a 23 69 66 20  TERMIOS) */.#if 
0410: 43 52 41 59 3e 3d 37 30 20 26 26 20 64 65 66 69  CRAY>=70 && defi
0420: 6e 65 64 28 5f 43 52 41 59 32 29 0a 23 69 6e 63  ned(_CRAY2).#inc
0430: 6c 75 64 65 20 3c 73 79 73 2f 73 65 73 73 69 6f  lude <sys/sessio
0440: 6e 2e 68 3e 0a 23 65 6e 64 69 66 20 2f 2a 20 37  n.h>.#endif /* 7
0450: 30 20 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 3c 73  0 */.#include <s
0460: 79 73 2f 70 74 79 2e 68 3e 0a 23 69 6e 63 6c 75  ys/pty.h>.#inclu
0470: 64 65 20 3c 70 77 64 2e 68 3e 0a 23 69 6e 63 6c  de <pwd.h>.#incl
0480: 75 64 65 20 3c 75 74 6d 70 2e 68 3e 0a 23 69 6e  ude <utmp.h>.#in
0490: 63 6c 75 64 65 20 3c 73 69 67 6e 61 6c 2e 68 3e  clude <signal.h>
04a0: 0a 23 69 6e 63 6c 75 64 65 20 22 65 78 70 5f 74  .#include "exp_t
04b0: 74 79 5f 69 6e 2e 68 22 0a 23 69 6e 63 6c 75 64  ty_in.h".#includ
04c0: 65 20 22 65 78 70 5f 72 65 6e 61 6d 65 2e 68 22  e "exp_rename.h"
04d0: 0a 0a 23 69 66 64 65 66 20 48 41 56 45 5f 53 59  ..#ifdef HAVE_SY
04e0: 53 43 4f 4e 46 5f 48 0a 23 69 6e 63 6c 75 64 65  SCONF_H.#include
04f0: 20 3c 73 79 73 2f 73 79 73 63 6f 6e 66 69 67 2e   <sys/sysconfig.
0500: 68 3e 0a 23 65 6e 64 69 66 0a 0a 76 6f 69 64 20  h>.#endif..void 
0510: 65 78 70 44 69 61 67 4c 6f 67 28 29 3b 0a 0a 23  expDiagLog();..#
0520: 69 66 6e 64 65 66 20 54 52 55 45 0a 23 64 65 66  ifndef TRUE.#def
0530: 69 6e 65 20 54 52 55 45 20 31 0a 23 64 65 66 69  ine TRUE 1.#defi
0540: 6e 65 20 46 41 4c 53 45 20 30 0a 23 65 6e 64 69  ne FALSE 0.#endi
0550: 66 0a 0a 23 69 66 6e 64 65 66 20 4d 41 58 48 4f  f..#ifndef MAXHO
0560: 53 54 4e 41 4d 45 4c 45 4e 0a 23 64 65 66 69 6e  STNAMELEN.#defin
0570: 65 20 4d 41 58 48 4f 53 54 4e 41 4d 45 4c 45 4e  e MAXHOSTNAMELEN
0580: 20 36 34 0a 23 65 6e 64 69 66 20 2f 2a 20 4d 41   64.#endif /* MA
0590: 58 48 4f 53 54 4e 41 4d 45 4c 45 4e 20 2a 2f 0a  XHOSTNAMELEN */.
05a0: 0a 73 74 61 74 69 63 20 63 68 61 72 09 6c 69 6e  .static char.lin
05b0: 65 70 5b 5d 20 3d 20 22 5c 30 5c 30 5c 30 5c 30  ep[] = "\0\0\0\0
05c0: 5c 30 5c 30 5c 30 5c 30 5c 30 5c 30 5c 30 5c 30  \0\0\0\0\0\0\0\0
05d0: 5c 30 5c 30 5c 30 5c 30 22 3b 0a 73 74 61 74 69  \0\0\0\0";.stati
05e0: 63 20 63 68 61 72 09 6c 69 6e 65 74 5b 5d 20 3d  c char.linet[] =
05f0: 20 22 5c 30 5c 30 5c 30 5c 30 5c 30 5c 30 5c 30   "\0\0\0\0\0\0\0
0600: 5c 30 5c 30 5c 30 5c 30 5c 30 5c 30 5c 30 5c 30  \0\0\0\0\0\0\0\0
0610: 5c 30 22 3b 0a 73 74 61 74 69 63 20 69 6e 74 09  \0";.static int.
0620: 6c 6f 77 70 74 79 3b 0a 73 74 61 74 69 63 20 69  lowpty;.static i
0630: 6e 74 09 68 69 67 68 70 74 79 3b 0a 73 74 61 74  nt.highpty;.stat
0640: 69 63 20 69 6e 74 09 72 65 61 6c 75 69 64 3b 0a  ic int.realuid;.
0650: 73 74 61 74 69 63 20 69 6e 74 09 72 65 61 6c 67  static int.realg
0660: 69 64 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 09  id;.static int .
0670: 2a 70 74 79 73 3b 0a 73 74 61 74 69 63 20 63 68  *ptys;.static ch
0680: 61 72 20 6d 79 6e 61 6d 65 5b 33 32 5d 3b 0a 73  ar myname[32];.s
0690: 74 61 74 69 63 20 63 68 61 72 20 68 6f 73 74 6e  tatic char hostn
06a0: 61 6d 65 5b 4d 41 58 48 4f 53 54 4e 41 4d 45 4c  ame[MAXHOSTNAMEL
06b0: 45 4e 5d 3b 0a 63 68 61 72 20 2a 65 78 70 5f 70  EN];.char *exp_p
06c0: 74 79 5f 73 6c 61 76 65 5f 6e 61 6d 65 3b 0a 63  ty_slave_name;.c
06d0: 68 61 72 20 2a 65 78 70 5f 70 74 79 5f 65 72 72  har *exp_pty_err
06e0: 6f 72 3b 0a 0a 73 74 61 74 69 63 20 76 6f 69 64  or;..static void
06f0: 0a 70 74 79 5f 73 74 74 79 28 73 2c 6e 61 6d 65  .pty_stty(s,name
0700: 29 0a 63 68 61 72 20 2a 73 3b 09 09 2f 2a 20 61  ).char *s;../* a
0710: 72 67 73 20 74 6f 20 73 74 74 79 20 2a 2f 0a 63  rgs to stty */.c
0720: 68 61 72 20 2a 6e 61 6d 65 3b 09 09 2f 2a 20 6e  har *name;../* n
0730: 61 6d 65 20 6f 66 20 70 74 79 20 2a 2f 0a 7b 0a  ame of pty */.{.
0740: 23 64 65 66 69 6e 65 20 4d 41 58 5f 41 52 47 4c  #define MAX_ARGL
0750: 49 53 54 20 31 30 32 34 30 0a 09 63 68 61 72 20  IST 10240..char 
0760: 62 75 66 5b 4d 41 58 5f 41 52 47 4c 49 53 54 5d  buf[MAX_ARGLIST]
0770: 3b 09 2f 2a 20 6f 76 65 72 6b 69 6c 6c 20 69 73  ;./* overkill is
0780: 20 65 61 73 69 65 72 20 2a 2f 0a 09 52 45 54 53   easier */..RETS
0790: 49 47 54 59 50 45 20 28 2a 6f 6c 64 29 28 29 3b  IGTYPE (*old)();
07a0: 09 2f 2a 20 73 61 76 65 20 6f 6c 64 20 73 69 67  ./* save old sig
07b0: 61 6c 61 72 6d 20 68 61 6e 64 6c 65 72 20 2a 2f  alarm handler */
07c0: 0a 0a 23 69 66 64 65 66 20 53 54 54 59 5f 52 45  ..#ifdef STTY_RE
07d0: 41 44 53 5f 53 54 44 4f 55 54 0a 09 73 70 72 69  ADS_STDOUT..spri
07e0: 6e 74 66 28 62 75 66 2c 22 2f 62 69 6e 2f 73 74  ntf(buf,"/bin/st
07f0: 74 79 20 25 73 20 3e 20 25 73 22 2c 73 2c 6e 61  ty %s > %s",s,na
0800: 6d 65 29 3b 0a 23 65 6c 73 65 0a 09 73 70 72 69  me);.#else..spri
0810: 6e 74 66 28 62 75 66 2c 22 2f 62 69 6e 2f 73 74  ntf(buf,"/bin/st
0820: 74 79 20 25 73 20 3c 20 25 73 22 2c 73 2c 6e 61  ty %s < %s",s,na
0830: 6d 65 29 3b 0a 23 65 6e 64 69 66 0a 09 6f 6c 64  me);.#endif..old
0840: 20 3d 20 73 69 67 6e 61 6c 28 53 49 47 43 48 4c   = signal(SIGCHL
0850: 44 2c 20 53 49 47 5f 44 46 4c 29 3b 0a 09 73 79  D, SIG_DFL);..sy
0860: 73 74 65 6d 28 62 75 66 29 3b 0a 09 73 69 67 6e  stem(buf);..sign
0870: 61 6c 28 53 49 47 43 48 4c 44 2c 20 6f 6c 64 29  al(SIGCHLD, old)
0880: 3b 09 2f 2a 20 72 65 73 74 6f 72 65 20 73 69 67  ;./* restore sig
0890: 6e 61 6c 20 68 61 6e 64 6c 65 72 20 2a 2f 0a 7d  nal handler */.}
08a0: 0a 0a 69 6e 74 20 65 78 70 5f 64 65 76 5f 74 74  ..int exp_dev_tt
08b0: 79 3b 09 2f 2a 20 66 69 6c 65 20 64 65 73 63 72  y;./* file descr
08c0: 69 70 74 6f 72 20 74 6f 20 2f 64 65 76 2f 74 74  iptor to /dev/tt
08d0: 79 20 6f 72 20 2d 31 20 69 66 20 6e 6f 6e 65 20  y or -1 if none 
08e0: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 6b 6e  */.static int kn
08f0: 65 77 5f 64 65 76 5f 74 74 79 3b 2f 2a 20 74 72  ew_dev_tty;/* tr
0900: 75 65 20 69 66 20 77 65 20 68 61 64 20 6f 75 72  ue if we had our
0910: 20 68 61 6e 64 73 20 6f 6e 20 2f 64 65 76 2f 74   hands on /dev/t
0920: 74 79 20 61 74 20 61 6e 79 20 74 69 6d 65 20 2a  ty at any time *
0930: 2f 0a 0a 23 69 66 64 65 66 20 54 49 4f 43 47 57  /..#ifdef TIOCGW
0940: 49 4e 53 5a 0a 73 74 61 74 69 63 20 73 74 72 75  INSZ.static stru
0950: 63 74 20 77 69 6e 73 69 7a 65 20 77 69 6e 73 69  ct winsize winsi
0960: 7a 65 20 3d 20 7b 30 2c 20 30 7d 3b 0a 23 65 6e  ze = {0, 0};.#en
0970: 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28  dif.#if defined(
0980: 54 49 4f 43 47 53 49 5a 45 29 20 26 26 20 21 64  TIOCGSIZE) && !d
0990: 65 66 69 6e 65 64 28 54 49 4f 43 47 57 49 4e 53  efined(TIOCGWINS
09a0: 5a 29 0a 73 74 61 74 69 63 20 73 74 72 75 63 74  Z).static struct
09b0: 20 74 74 79 73 69 7a 65 20 77 69 6e 73 69 7a 65   ttysize winsize
09c0: 20 3d 20 7b 30 2c 20 30 7d 3b 0a 23 65 6e 64 69   = {0, 0};.#endi
09d0: 66 0a 0a 2f 2a 73 74 72 75 63 74 09 74 65 72 6d  f../*struct.term
09e0: 69 6f 20 65 78 70 5f 74 74 79 5f 6f 72 69 67 69  io exp_tty_origi
09f0: 6e 61 6c 3b 2a 2f 0a 65 78 70 5f 74 74 79 20 65  nal;*/.exp_tty e
0a00: 78 70 5f 74 74 79 5f 6f 72 69 67 69 6e 61 6c 3b  xp_tty_original;
0a10: 0a 0a 23 64 65 66 69 6e 65 20 47 45 54 5f 54 54  ..#define GET_TT
0a20: 59 54 59 50 45 09 30 0a 23 64 65 66 69 6e 65 20  YTYPE.0.#define 
0a30: 53 45 54 5f 54 54 59 54 59 50 45 09 31 0a 73 74  SET_TTYTYPE.1.st
0a40: 61 74 69 63 20 76 6f 69 64 0a 74 74 79 74 79 70  atic void.ttytyp
0a50: 65 28 72 65 71 75 65 73 74 2c 66 64 2c 74 74 79  e(request,fd,tty
0a60: 63 6f 70 79 2c 74 74 79 69 6e 69 74 2c 73 29 0a  copy,ttyinit,s).
0a70: 69 6e 74 20 72 65 71 75 65 73 74 3b 0a 69 6e 74  int request;.int
0a80: 20 66 64 3b 0a 09 09 2f 2a 20 66 6f 6c 6c 6f 77   fd;.../* follow
0a90: 69 6e 67 20 61 72 65 20 75 73 65 64 20 6f 6e 6c  ing are used onl
0aa0: 79 20 69 66 20 72 65 71 75 65 73 74 20 3d 3d 20  y if request == 
0ab0: 53 45 54 5f 54 54 59 54 59 50 45 20 2a 2f 0a 69  SET_TTYTYPE */.i
0ac0: 6e 74 20 74 74 79 63 6f 70 79 3b 09 2f 2a 20 74  nt ttycopy;./* t
0ad0: 72 75 65 2f 66 61 6c 73 65 2c 20 63 6f 70 79 20  rue/false, copy 
0ae0: 66 72 6f 6d 20 2f 64 65 76 2f 74 74 79 20 2a 2f  from /dev/tty */
0af0: 0a 69 6e 74 20 74 74 79 69 6e 69 74 3b 09 2f 2a  .int ttyinit;./*
0b00: 20 69 66 20 74 72 75 65 2c 20 69 6e 69 74 69 61   if true, initia
0b10: 6c 69 7a 65 20 74 6f 20 73 61 6e 65 20 73 74 61  lize to sane sta
0b20: 74 65 20 2a 2f 0a 63 68 61 72 20 2a 73 3b 09 2f  te */.char *s;./
0b30: 2a 20 73 74 74 79 20 61 72 67 73 2c 20 75 73 65  * stty args, use
0b40: 64 20 6f 6e 6c 79 20 69 66 20 72 65 71 75 65 73  d only if reques
0b50: 74 20 3d 3d 20 53 45 54 5f 54 54 59 54 59 50 45  t == SET_TTYTYPE
0b60: 20 2a 2f 0a 7b 0a 09 69 66 20 28 72 65 71 75 65   */.{..if (reque
0b70: 73 74 20 3d 3d 20 47 45 54 5f 54 54 59 54 59 50  st == GET_TTYTYP
0b80: 45 29 20 7b 0a 09 09 69 66 20 28 2d 31 20 3d 3d  E) {...if (-1 ==
0b90: 20 69 6f 63 74 6c 28 66 64 2c 20 54 43 47 45 54   ioctl(fd, TCGET
0ba0: 41 2c 20 28 63 68 61 72 20 2a 29 26 65 78 70 5f  A, (char *)&exp_
0bb0: 74 74 79 5f 6f 72 69 67 69 6e 61 6c 29 29 20 7b  tty_original)) {
0bc0: 0a 09 09 09 6b 6e 65 77 5f 64 65 76 5f 74 74 79  ....knew_dev_tty
0bd0: 20 3d 20 46 41 4c 53 45 3b 0a 09 09 09 65 78 70   = FALSE;....exp
0be0: 5f 64 65 76 5f 74 74 79 20 3d 20 2d 31 3b 0a 09  _dev_tty = -1;..
0bf0: 09 7d 0a 23 69 66 64 65 66 20 54 49 4f 43 47 57  .}.#ifdef TIOCGW
0c00: 49 4e 53 5a 0a 09 09 69 6f 63 74 6c 28 66 64 2c  INSZ...ioctl(fd,
0c10: 54 49 4f 43 47 57 49 4e 53 5a 2c 26 77 69 6e 73  TIOCGWINSZ,&wins
0c20: 69 7a 65 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66  ize);.#endif.#if
0c30: 20 64 65 66 69 6e 65 64 28 54 49 4f 43 47 53 49   defined(TIOCGSI
0c40: 5a 45 29 20 26 26 20 21 64 65 66 69 6e 65 64 28  ZE) && !defined(
0c50: 54 49 4f 43 47 57 49 4e 53 5a 29 0a 09 09 69 6f  TIOCGWINSZ)...io
0c60: 63 74 6c 28 66 64 2c 54 49 4f 43 47 53 49 5a 45  ctl(fd,TIOCGSIZE
0c70: 2c 26 77 69 6e 73 69 7a 65 29 3b 0a 23 65 6e 64  ,&winsize);.#end
0c80: 69 66 0a 09 7d 20 65 6c 73 65 20 7b 09 2f 2a 20  if..} else {./* 
0c90: 74 79 70 65 20 3d 3d 20 53 45 54 5f 54 54 59 54  type == SET_TTYT
0ca0: 59 50 45 20 2a 2f 0a 09 09 69 66 20 28 74 74 79  YPE */...if (tty
0cb0: 63 6f 70 79 20 26 26 20 6b 6e 65 77 5f 64 65 76  copy && knew_dev
0cc0: 5f 74 74 79 29 20 7b 0a 09 09 09 28 76 6f 69 64  _tty) {....(void
0cd0: 29 20 69 6f 63 74 6c 28 66 64 2c 20 54 43 53 45  ) ioctl(fd, TCSE
0ce0: 54 41 2c 20 28 63 68 61 72 20 2a 29 26 65 78 70  TA, (char *)&exp
0cf0: 5f 74 74 79 5f 63 75 72 72 65 6e 74 29 3b 0a 23  _tty_current);.#
0d00: 69 66 64 65 66 20 54 49 4f 43 53 57 49 4e 53 5a  ifdef TIOCSWINSZ
0d10: 0a 09 09 09 69 6f 63 74 6c 28 66 64 2c 54 49 4f  ....ioctl(fd,TIO
0d20: 43 53 57 49 4e 53 5a 2c 26 77 69 6e 73 69 7a 65  CSWINSZ,&winsize
0d30: 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65  );.#endif.#if de
0d40: 66 69 6e 65 64 28 54 49 4f 43 53 53 49 5a 45 29  fined(TIOCSSIZE)
0d50: 20 26 26 20 21 64 65 66 69 6e 65 64 28 54 49 4f   && !defined(TIO
0d60: 43 53 57 49 4e 53 5a 29 0a 09 09 09 69 6f 63 74  CSWINSZ)....ioct
0d70: 6c 28 66 64 2c 54 49 4f 43 47 53 49 5a 45 2c 26  l(fd,TIOCGSIZE,&
0d80: 77 69 6e 73 69 7a 65 29 3b 0a 23 65 6e 64 69 66  winsize);.#endif
0d90: 0a 09 09 7d 0a 0a 09 09 69 66 20 28 74 74 79 69  ...}....if (ttyi
0da0: 6e 69 74 29 20 7b 0a 09 09 09 2f 2a 20 6f 76 65  nit) {..../* ove
0db0: 72 6c 61 79 20 70 61 72 6d 73 20 6f 72 69 67 69  rlay parms origi
0dc0: 6e 61 6c 6c 79 20 73 75 70 70 6c 69 65 64 20 62  nally supplied b
0dd0: 79 20 4d 61 6b 65 66 69 6c 65 20 2a 2f 0a 09 09  y Makefile */...
0de0: 09 70 74 79 5f 73 74 74 79 28 44 46 4c 54 5f 53  .pty_stty(DFLT_S
0df0: 54 54 59 2c 6c 69 6e 65 74 29 3b 0a 09 09 7d 0a  TTY,linet);...}.
0e00: 0a 09 09 2f 2a 20 6c 61 73 74 6c 79 2c 20 67 69  .../* lastly, gi
0e10: 76 65 20 75 73 65 72 20 63 68 61 6e 63 65 20 74  ve user chance t
0e20: 6f 20 6f 76 65 72 72 69 64 65 20 61 6e 79 20 74  o override any t
0e30: 65 72 6d 69 6e 61 6c 20 70 61 72 6d 73 20 2a 2f  erminal parms */
0e40: 0a 09 09 69 66 20 28 73 29 20 7b 0a 09 09 09 70  ...if (s) {....p
0e50: 74 79 5f 73 74 74 79 28 73 2c 6c 69 6e 65 74 29  ty_stty(s,linet)
0e60: 3b 0a 09 09 7d 0a 09 7d 0a 7d 0a 0a 76 6f 69 64  ;...}..}.}..void
0e70: 0a 65 78 70 5f 69 6e 69 74 5f 70 74 79 28 29 0a  .exp_init_pty().
0e80: 7b 0a 09 69 6e 74 20 6e 70 74 79 3b 0a 09 63 68  {..int npty;..ch
0e90: 61 72 20 2a 6d 79 6c 69 6e 65 3b 0a 0a 09 6c 6f  ar *myline;...lo
0ea0: 77 70 74 79 3d 30 3b 0a 23 69 66 64 65 66 20 5f  wpty=0;.#ifdef _
0eb0: 53 43 5f 43 52 41 59 5f 4e 50 54 59 0a 09 68 69  SC_CRAY_NPTY..hi
0ec0: 67 68 70 74 79 3d 73 79 73 63 6f 6e 66 28 5f 53  ghpty=sysconf(_S
0ed0: 43 5f 43 52 41 59 5f 4e 50 54 59 29 3b 0a 23 65  C_CRAY_NPTY);.#e
0ee0: 6c 73 65 0a 09 68 69 67 68 70 74 79 3d 31 32 38  lse..highpty=128
0ef0: 3b 0a 23 65 6e 64 69 66 20 2f 2a 20 5f 53 43 5f  ;.#endif /* _SC_
0f00: 43 52 41 59 5f 4e 50 54 59 20 2a 2f 0a 0a 09 70  CRAY_NPTY */...p
0f10: 74 79 73 20 3d 20 28 69 6e 74 20 2a 29 20 6d 61  tys = (int *) ma
0f20: 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 69 6e 74 29  lloc(sizeof(int)
0f30: 2a 28 68 69 67 68 70 74 79 2b 31 29 29 3b 0a 09  *(highpty+1));..
0f40: 69 66 20 28 70 74 79 73 20 3d 3d 20 4e 55 4c 4c  if (ptys == NULL
0f50: 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74  ) {...fprintf(st
0f60: 64 65 72 72 2c 22 65 78 70 5f 69 6e 69 74 5f 70  derr,"exp_init_p
0f70: 74 79 3a 20 20 63 6f 75 6c 64 6e 27 74 20 61 6c  ty:  couldn't al
0f80: 6c 6f 63 61 74 65 20 70 74 79 20 61 72 72 61 79  locate pty array
0f90: 5c 6e 22 29 3b 0a 09 09 65 78 69 74 28 31 29 3b  \n");...exit(1);
0fa0: 0a 09 7d 0a 09 66 6f 72 20 28 6e 70 74 79 20 3d  ..}..for (npty =
0fb0: 20 6c 6f 77 70 74 79 3b 6e 70 74 79 20 3c 3d 20   lowpty;npty <= 
0fc0: 68 69 67 68 70 74 79 3b 6e 70 74 79 2b 2b 29 0a  highpty;npty++).
0fd0: 09 09 70 74 79 73 5b 6e 70 74 79 5d 20 3d 20 30  ..ptys[npty] = 0
0fe0: 3b 0a 0a 20 09 72 65 61 6c 75 69 64 3d 67 65 74  ;.. .realuid=get
0ff0: 75 69 64 28 29 3b 09 2f 2a 20 67 65 74 20 52 45  uid();./* get RE
1000: 41 4c 20 75 69 64 20 2a 2f 0a 20 09 72 65 61 6c  AL uid */. .real
1010: 67 69 64 3d 67 65 74 67 69 64 28 29 3b 09 2f 2a  gid=getgid();./*
1020: 20 67 65 74 20 52 45 41 4c 20 75 69 64 20 2a 2f   get REAL uid */
1030: 0a 0a 09 65 78 70 5f 64 65 76 5f 74 74 79 20 3d  ...exp_dev_tty =
1040: 20 6f 70 65 6e 28 22 2f 64 65 76 2f 74 74 79 22   open("/dev/tty"
1050: 2c 4f 5f 52 44 57 52 29 3b 0a 09 6b 6e 65 77 5f  ,O_RDWR);..knew_
1060: 64 65 76 5f 74 74 79 20 3d 20 28 65 78 70 5f 64  dev_tty = (exp_d
1070: 65 76 5f 74 74 79 20 21 3d 20 2d 31 29 3b 0a 09  ev_tty != -1);..
1080: 69 66 20 28 6b 6e 65 77 5f 64 65 76 5f 74 74 79  if (knew_dev_tty
1090: 29 20 74 74 79 74 79 70 65 28 47 45 54 5f 54 54  ) ttytype(GET_TT
10a0: 59 54 59 50 45 2c 65 78 70 5f 64 65 76 5f 74 74  YTYPE,exp_dev_tt
10b0: 79 2c 30 2c 30 2c 28 63 68 61 72 20 2a 29 30 29  y,0,0,(char *)0)
10c0: 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 41 63 71 75 69  ;.../*.. * Acqui
10d0: 72 65 20 28 61 73 20 72 6f 6f 74 29 20 63 75 72  re (as root) cur
10e0: 72 65 6e 74 20 75 73 65 72 20 6e 61 6d 65 20 61  rent user name a
10f0: 6e 64 20 68 6f 73 74 2e 0a 09 20 2a 2f 0a 09 28  nd host... */..(
1100: 76 6f 69 64 29 20 63 75 73 65 72 69 64 28 6d 79  void) cuserid(my
1110: 6e 61 6d 65 29 3b 0a 09 28 76 6f 69 64 29 20 67  name);..(void) g
1120: 65 74 68 6f 73 74 6e 61 6d 65 28 68 6f 73 74 6e  ethostname(hostn
1130: 61 6d 65 2c 73 69 7a 65 6f 66 28 68 6f 73 74 6e  ame,sizeof(hostn
1140: 61 6d 65 29 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20  ame));.../*.. * 
1150: 53 65 74 20 74 68 65 20 72 65 61 6c 20 61 6e 64  Set the real and
1160: 20 65 66 66 65 63 74 69 76 65 20 75 73 65 72 69   effective useri
1170: 64 73 20 74 6f 20 72 6f 6f 74 20 75 73 69 6e 67  ds to root using
1180: 20 27 73 65 74 75 69 64 27 2e 20 20 54 68 65 6e   'setuid'.  Then
1190: 0a 09 20 2a 20 73 65 74 20 74 68 65 20 72 65 61  .. * set the rea
11a0: 6c 20 61 6e 64 20 65 66 66 65 63 74 69 76 65 20  l and effective 
11b0: 75 73 65 72 69 64 73 20 74 6f 20 74 68 65 20 61  userids to the a
11c0: 63 74 75 61 6c 20 75 73 65 72 20 75 73 69 6e 67  ctual user using
11d0: 0a 09 20 2a 20 27 73 65 74 72 65 75 69 64 27 2e  .. * 'setreuid'.
11e0: 20 20 54 68 69 73 20 61 6c 6c 6f 77 73 20 75 73    This allows us
11f0: 69 6e 67 20 27 73 65 74 65 75 69 64 27 20 74 6f  ing 'seteuid' to
1200: 20 67 6f 20 62 61 63 6b 20 61 6e 64 20 66 6f 72   go back and for
1210: 74 68 20 66 72 6f 6d 0a 09 20 2a 20 72 6f 6f 74  th from.. * root
1220: 20 61 6e 64 20 74 68 65 20 61 63 74 75 61 6c 20   and the actual 
1230: 75 73 65 72 69 64 2e 20 20 44 6f 6e 27 74 20 61  userid.  Don't a
1240: 73 6b 20 6d 65 20 77 68 79 20 69 74 20 77 6f 72  sk me why it wor
1250: 6b 73 2e 0a 09 20 2a 2f 0a 09 73 65 74 75 69 64  ks... */..setuid
1260: 28 30 29 3b 0a 09 73 65 74 72 65 75 69 64 28 72  (0);..setreuid(r
1270: 65 61 6c 75 69 64 2c 72 65 61 6c 75 69 64 29 3b  ealuid,realuid);
1280: 0a 7d 0a 0a 2f 2a 20 72 65 74 75 72 6e 73 20 66  .}../* returns f
1290: 64 20 6f 66 20 6d 61 73 74 65 72 20 65 6e 64 20  d of master end 
12a0: 6f 66 20 70 73 65 75 64 6f 74 74 79 20 2a 2f 0a  of pseudotty */.
12b0: 69 6e 74 0a 65 78 70 5f 67 65 74 70 74 79 6d 61  int.exp_getptyma
12c0: 73 74 65 72 28 29 0a 7b 0a 09 73 74 72 75 63 74  ster().{..struct
12d0: 20 73 74 61 74 20 73 62 3b 0a 09 69 6e 74 20 6d   stat sb;..int m
12e0: 61 73 74 65 72 3b 0a 09 69 6e 74 20 6e 70 74 79  aster;..int npty
12f0: 3b 0a 0a 09 65 78 70 5f 70 74 79 5f 65 72 72 6f  ;...exp_pty_erro
1300: 72 20 3d 20 30 3b 0a 0a 09 65 78 70 44 69 61 67  r = 0;...expDiag
1310: 4c 6f 67 28 22 65 78 70 5f 67 65 74 70 74 79 6d  Log("exp_getptym
1320: 61 73 74 65 72 3a 20 20 6c 6f 77 70 74 79 3d 25  aster:  lowpty=%
1330: 64 20 20 68 69 67 68 70 74 79 3d 25 64 5c 6e 22  d  highpty=%d\n"
1340: 2c 6c 6f 77 70 74 79 2c 68 69 67 68 70 74 79 29  ,lowpty,highpty)
1350: 3b 0a 09 66 6f 72 20 28 6e 70 74 79 20 3d 20 6c  ;..for (npty = l
1360: 6f 77 70 74 79 3b 20 6e 70 74 79 20 3c 3d 20 68  owpty; npty <= h
1370: 69 67 68 70 74 79 3b 20 6e 70 74 79 2b 2b 29 20  ighpty; npty++) 
1380: 7b 0a 09 09 69 66 20 28 73 65 74 65 75 69 64 28  {...if (seteuid(
1390: 30 29 20 3d 3d 20 2d 31 29 20 7b 09 09 2f 2a 20  0) == -1) {../* 
13a0: 77 65 20 6e 65 65 64 20 74 6f 20 62 65 20 72 6f  we need to be ro
13b0: 6f 74 21 20 2a 2f 0a 09 09 09 65 78 70 44 69 61  ot! */....expDia
13c0: 67 4c 6f 67 28 22 65 78 70 5f 67 65 74 70 74 79  gLog("exp_getpty
13d0: 6d 61 73 74 65 72 3a 20 20 73 65 74 65 75 69 64  master:  seteuid
13e0: 20 72 6f 6f 74 20 65 72 72 6e 6f 3d 25 64 5c 6e   root errno=%d\n
13f0: 22 2c 0a 09 09 09 09 65 72 72 6e 6f 29 3b 0a 09  ",.....errno);..
1400: 09 7d 0a 09 09 28 76 6f 69 64 29 20 73 70 72 69  .}...(void) spri
1410: 6e 74 66 28 6c 69 6e 65 70 2c 20 22 2f 64 65 76  ntf(linep, "/dev
1420: 2f 70 74 79 2f 25 30 33 64 22 2c 20 6e 70 74 79  /pty/%03d", npty
1430: 29 3b 0a 09 09 6d 61 73 74 65 72 20 3d 20 6f 70  );...master = op
1440: 65 6e 28 6c 69 6e 65 70 2c 20 4f 5f 52 44 57 52  en(linep, O_RDWR
1450: 29 3b 0a 0a 09 09 69 66 20 28 6d 61 73 74 65 72  );....if (master
1460: 20 3c 20 30 29 20 7b 0a 09 09 09 65 78 70 44 69   < 0) {....expDi
1470: 61 67 4c 6f 67 28 22 65 78 70 5f 67 65 74 70 74  agLog("exp_getpt
1480: 79 6d 61 73 74 65 72 3a 20 20 6f 70 65 6e 20 6c  ymaster:  open l
1490: 69 6e 65 70 3d 25 73 20 65 72 72 6e 6f 3d 25 64  inep=%s errno=%d
14a0: 5c 6e 22 2c 0a 09 09 09 09 6c 69 6e 65 70 2c 65  \n",.....linep,e
14b0: 72 72 6e 6f 29 3b 0a 09 09 09 63 6f 6e 74 69 6e  rrno);....contin
14c0: 75 65 3b 0a 09 09 7d 0a 0a 09 09 28 76 6f 69 64  ue;...}....(void
14d0: 29 20 73 70 72 69 6e 74 66 28 6c 69 6e 65 74 2c  ) sprintf(linet,
14e0: 20 22 2f 64 65 76 2f 74 74 79 70 25 30 33 64 22   "/dev/ttyp%03d"
14f0: 2c 20 6e 70 74 79 29 3b 0a 09 09 69 66 28 73 74  , npty);...if(st
1500: 61 74 28 6c 69 6e 65 74 2c 20 26 73 62 29 20 3c  at(linet, &sb) <
1510: 20 30 29 20 7b 0a 09 09 09 65 78 70 44 69 61 67   0) {....expDiag
1520: 4c 6f 67 28 22 65 78 70 5f 67 65 74 70 74 79 6d  Log("exp_getptym
1530: 61 73 74 65 72 3a 20 20 73 74 61 74 20 6c 69 6e  aster:  stat lin
1540: 65 74 3d 25 73 20 65 72 72 6e 6f 3d 25 64 5c 6e  et=%s errno=%d\n
1550: 22 2c 0a 09 09 09 09 6c 69 6e 65 74 2c 65 72 72  ",.....linet,err
1560: 6e 6f 29 3b 0a 09 09 09 28 76 6f 69 64 29 20 63  no);....(void) c
1570: 6c 6f 73 65 28 6d 61 73 74 65 72 29 3b 0a 09 09  lose(master);...
1580: 09 63 6f 6e 74 69 6e 75 65 3b 0a 09 09 7d 0a 09  .continue;...}..
1590: 09 69 66 20 28 73 62 2e 73 74 5f 75 69 64 20 7c  .if (sb.st_uid |
15a0: 7c 20 73 62 2e 73 74 5f 67 69 64 20 7c 7c 20 73  | sb.st_gid || s
15b0: 62 2e 73 74 5f 6d 6f 64 65 20 21 3d 20 30 36 30  b.st_mode != 060
15c0: 30 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20  0) {.           
15d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20               if 
15e0: 28 63 68 6f 77 6e 28 6c 69 6e 65 74 2c 20 72 65  (chown(linet, re
15f0: 61 6c 75 69 64 2c 20 72 65 61 6c 67 69 64 29 20  aluid, realgid) 
1600: 3d 3d 20 2d 31 29 20 7b 0a 09 09 09 09 65 78 70  == -1) {.....exp
1610: 44 69 61 67 4c 6f 67 28 22 65 78 70 5f 67 65 74  DiagLog("exp_get
1620: 70 74 79 6d 61 73 74 65 72 3a 20 20 63 68 6f 77  ptymaster:  chow
1630: 6e 20 6c 69 6e 65 74 3d 25 73 20 65 72 72 6e 6f  n linet=%s errno
1640: 3d 25 64 5c 6e 22 2c 0a 09 09 09 09 09 6c 69 6e  =%d\n",......lin
1650: 65 74 2c 65 72 72 6e 6f 29 3b 0a 09 09 09 7d 0a  et,errno);....}.
1660: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1670: 20 20 20 20 20 20 20 20 69 66 20 28 63 68 6d 6f          if (chmo
1680: 64 28 6c 69 6e 65 74 2c 20 30 36 30 30 29 20 3d  d(linet, 0600) =
1690: 3d 20 2d 31 29 20 7b 0a 09 09 09 09 65 78 70 44  = -1) {.....expD
16a0: 69 61 67 4c 6f 67 28 22 65 78 70 5f 67 65 74 70  iagLog("exp_getp
16b0: 74 79 6d 61 73 74 65 72 3a 20 20 63 68 6d 6f 64  tymaster:  chmod
16c0: 20 6c 69 6e 65 74 3d 25 73 20 65 72 72 6e 6f 3d   linet=%s errno=
16d0: 25 64 5c 6e 22 2c 0a 09 09 09 09 09 6c 69 6e 65  %d\n",......line
16e0: 74 2c 65 72 72 6e 6f 29 3b 0a 09 09 09 7d 0a 20  t,errno);....}. 
16f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1700: 20 20 20 20 20 20 20 28 76 6f 69 64 29 63 6c 6f         (void)clo
1710: 73 65 28 6d 61 73 74 65 72 29 3b 0a 20 20 20 20  se(master);.    
1720: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1730: 20 20 20 20 6d 61 73 74 65 72 20 3d 20 6f 70 65      master = ope
1740: 6e 28 6c 69 6e 65 70 2c 20 32 29 3b 0a 20 20 20  n(linep, 2);.   
1750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1760: 20 20 20 20 20 69 66 20 28 6d 61 73 74 65 72 20       if (master 
1770: 3c 20 30 29 20 7b 0a 09 09 09 09 65 78 70 44 69  < 0) {.....expDi
1780: 61 67 4c 6f 67 28 22 65 78 70 5f 67 65 74 70 74  agLog("exp_getpt
1790: 79 6d 61 73 74 65 72 3a 20 20 72 65 6f 70 65 6e  ymaster:  reopen
17a0: 20 6c 69 6e 65 70 3d 25 73 20 65 72 72 6e 6f 3d   linep=%s errno=
17b0: 25 64 5c 6e 22 2c 0a 09 09 09 09 09 6c 69 6e 65  %d\n",......line
17c0: 70 2c 65 72 72 6e 6f 29 3b 0a 20 20 20 20 20 20  p,errno);.      
17d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
17e0: 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 69 6e            contin
17f0: 75 65 3b 0a 09 09 09 7d 0a 20 20 20 20 20 20 20  ue;....}.       
1800: 20 20 20 20 20 20 20 20 20 7d 0a 09 09 69 66 20           }...if 
1810: 28 73 65 74 65 75 69 64 28 72 65 61 6c 75 69 64  (seteuid(realuid
1820: 29 20 3d 3d 20 2d 31 29 20 7b 09 2f 2a 20 62 61  ) == -1) {./* ba
1830: 63 6b 20 74 6f 20 77 68 6f 20 77 65 20 61 72 65  ck to who we are
1840: 21 20 2a 2f 0a 09 09 09 65 78 70 44 69 61 67 4c  ! */....expDiagL
1850: 6f 67 28 22 65 78 70 5f 67 65 74 70 74 79 6d 61  og("exp_getptyma
1860: 73 74 65 72 3a 20 20 73 65 74 65 75 69 64 20 75  ster:  seteuid u
1870: 73 65 72 20 65 72 72 6e 6f 3d 25 64 5c 6e 22 2c  ser errno=%d\n",
1880: 0a 09 09 09 09 65 72 72 6e 6f 29 3b 0a 09 09 7d  .....errno);...}
1890: 0a 09 09 69 66 20 28 61 63 63 65 73 73 28 6c 69  ...if (access(li
18a0: 6e 65 74 2c 20 52 5f 4f 4b 7c 57 5f 4f 4b 29 20  net, R_OK|W_OK) 
18b0: 21 3d 20 30 29 20 7b 0a 09 09 09 65 78 70 44 69  != 0) {....expDi
18c0: 61 67 4c 6f 67 28 22 65 78 70 5f 67 65 74 70 74  agLog("exp_getpt
18d0: 79 6d 61 73 74 65 72 3a 20 20 61 63 63 65 73 73  ymaster:  access
18e0: 20 6c 69 6e 65 74 3d 25 73 20 65 72 72 6e 6f 3d   linet=%s errno=
18f0: 25 64 5c 6e 22 2c 0a 09 09 09 09 6c 69 6e 65 74  %d\n",.....linet
1900: 2c 65 72 72 6e 6f 29 3b 0a 09 09 09 28 76 6f 69  ,errno);....(voi
1910: 64 29 20 63 6c 6f 73 65 28 6d 61 73 74 65 72 29  d) close(master)
1920: 3b 0a 09 09 09 63 6f 6e 74 69 6e 75 65 3b 0a 09  ;....continue;..
1930: 09 7d 0a 09 09 65 78 70 44 69 61 67 4c 6f 67 28  .}...expDiagLog(
1940: 22 65 78 70 5f 67 65 74 70 74 79 6d 61 73 74 65  "exp_getptymaste
1950: 72 3a 20 20 61 6c 6c 6f 63 61 74 65 64 20 25 73  r:  allocated %s
1960: 5c 6e 22 2c 6c 69 6e 65 74 29 3b 0a 09 09 70 74  \n",linet);...pt
1970: 79 73 5b 6e 70 74 79 5d 20 3d 20 2d 31 3b 0a 09  ys[npty] = -1;..
1980: 09 65 78 70 5f 70 74 79 5f 73 6c 61 76 65 5f 6e  .exp_pty_slave_n
1990: 61 6d 65 20 3d 20 6c 69 6e 65 74 3b 0a 09 09 72  ame = linet;...r
19a0: 65 74 75 72 6e 28 6d 61 73 74 65 72 29 3b 0a 09  eturn(master);..
19b0: 7d 0a 09 69 66 20 28 73 65 74 65 75 69 64 28 72  }..if (seteuid(r
19c0: 65 61 6c 75 69 64 29 20 3d 3d 20 2d 31 29 20 7b  ealuid) == -1) {
19d0: 09 09 2f 2a 20 62 61 63 6b 20 74 6f 20 77 68 6f  ../* back to who
19e0: 20 77 65 20 61 72 65 21 20 2a 2f 0a 09 09 65 78   we are! */...ex
19f0: 70 44 69 61 67 4c 6f 67 28 22 65 78 70 5f 67 65  pDiagLog("exp_ge
1a00: 74 70 74 79 6d 61 73 74 65 72 3a 20 20 73 65 74  tptymaster:  set
1a10: 65 75 69 64 20 75 73 65 72 20 65 72 72 6e 6f 3d  euid user errno=
1a20: 25 64 5c 6e 22 2c 65 72 72 6e 6f 29 3b 0a 09 7d  %d\n",errno);..}
1a30: 0a 09 72 65 74 75 72 6e 28 2d 31 29 3b 0a 7d 0a  ..return(-1);.}.
1a40: 0a 2f 2a 20 73 65 65 20 63 6f 6d 6d 65 6e 74 20  ./* see comment 
1a50: 69 6e 20 70 74 79 5f 74 65 72 6d 69 6f 73 2e 63  in pty_termios.c
1a60: 20 2a 2f 0a 2f 2a 41 52 47 53 55 53 45 44 2a 2f   */./*ARGSUSED*/
1a70: 0a 76 6f 69 64 0a 65 78 70 5f 73 6c 61 76 65 5f  .void.exp_slave_
1a80: 63 6f 6e 74 72 6f 6c 28 6d 61 73 74 65 72 2c 63  control(master,c
1a90: 6f 6e 74 72 6f 6c 29 0a 69 6e 74 20 6d 61 73 74  ontrol).int mast
1aa0: 65 72 3b 0a 69 6e 74 20 63 6f 6e 74 72 6f 6c 3b  er;.int control;
1ab0: 0a 7b 0a 7d 0a 0a 69 6e 74 0a 67 65 74 70 74 79  .{.}..int.getpty
1ac0: 73 6c 61 76 65 28 74 74 79 63 6f 70 79 2c 74 74  slave(ttycopy,tt
1ad0: 79 69 6e 69 74 2c 73 74 74 79 5f 61 72 67 73 29  yinit,stty_args)
1ae0: 0a 69 6e 74 20 74 74 79 63 6f 70 79 3b 0a 69 6e  .int ttycopy;.in
1af0: 74 20 74 74 79 69 6e 69 74 3b 0a 63 68 61 72 20  t ttyinit;.char 
1b00: 2a 73 74 74 79 5f 61 72 67 73 3b 0a 7b 0a 09 69  *stty_args;.{..i
1b10: 6e 74 20 73 6c 61 76 65 3b 0a 0a 09 69 66 20 28  nt slave;...if (
1b20: 30 20 3e 20 28 73 6c 61 76 65 20 3d 20 6f 70 65  0 > (slave = ope
1b30: 6e 28 6c 69 6e 65 74 2c 20 4f 5f 52 44 57 52 29  n(linet, O_RDWR)
1b40: 29 29 20 7b 0a 09 09 65 78 70 44 69 61 67 4c 6f  )) {...expDiagLo
1b50: 67 28 22 67 65 74 70 74 79 73 6c 61 76 65 3a 20  g("getptyslave: 
1b60: 20 6f 70 65 6e 20 6c 69 6e 65 74 3d 25 73 20 65   open linet=%s e
1b70: 72 72 6e 6f 3d 25 64 5c 6e 22 2c 6c 69 6e 65 74  rrno=%d\n",linet
1b80: 2c 65 72 72 6e 6f 29 3b 0a 09 09 72 65 74 75 72  ,errno);...retur
1b90: 6e 28 2d 31 29 3b 0a 09 7d 0a 0a 09 2f 2a 20 73  n(-1);..}.../* s
1ba0: 61 6e 69 74 79 20 63 68 65 63 6b 20 2d 20 69 66  anity check - if
1bb0: 20 73 6c 61 76 65 20 6e 6f 74 20 30 2c 20 73 6b   slave not 0, sk
1bc0: 69 70 20 72 65 73 74 20 6f 66 20 74 68 69 73 20  ip rest of this 
1bd0: 61 6e 64 20 72 65 74 75 72 6e 20 2a 2f 0a 09 2f  and return */../
1be0: 2a 20 74 6f 20 77 68 61 74 20 77 69 6c 6c 20 6c  * to what will l
1bf0: 61 74 65 72 20 62 65 20 64 65 74 65 63 74 65 64  ater be detected
1c00: 20 61 73 20 61 6e 20 65 72 72 6f 72 20 69 6e 20   as an error in 
1c10: 63 61 6c 6c 65 72 20 2a 2f 0a 09 69 66 20 28 30  caller */..if (0
1c20: 20 21 3d 20 73 6c 61 76 65 29 20 7b 0a 09 09 65   != slave) {...e
1c30: 78 70 44 69 61 67 4c 6f 67 28 22 67 65 74 70 74  xpDiagLog("getpt
1c40: 79 73 6c 61 76 65 3a 20 20 73 6c 61 76 65 20 66  yslave:  slave f
1c50: 64 20 6e 6f 74 20 30 5c 6e 22 29 3b 0a 09 09 20  d not 0\n");... 
1c60: 72 65 74 75 72 6e 28 73 6c 61 76 65 29 3b 0a 09  return(slave);..
1c70: 7d 0a 0a 09 69 66 20 28 30 20 3d 3d 20 73 6c 61  }...if (0 == sla
1c80: 76 65 29 20 7b 0a 09 09 2f 2a 20 69 66 20 6f 70  ve) {.../* if op
1c90: 65 6e 65 64 20 69 6e 20 61 20 6e 65 77 20 70 72  ened in a new pr
1ca0: 6f 63 65 73 73 2c 20 73 6c 61 76 65 20 77 69 6c  ocess, slave wil
1cb0: 6c 20 62 65 20 30 20 28 61 6e 64 20 2a 2f 0a 09  l be 0 (and */..
1cc0: 09 2f 2a 20 75 6c 74 69 6d 61 74 65 6c 79 2c 20  ./* ultimately, 
1cd0: 31 20 61 6e 64 20 32 20 61 73 20 77 65 6c 6c 29  1 and 2 as well)
1ce0: 20 2a 2f 0a 0a 09 09 2f 2a 20 64 75 70 6c 69 63   */..../* duplic
1cf0: 61 74 65 20 30 20 6f 6e 74 6f 20 31 20 61 6e 64  ate 0 onto 1 and
1d00: 20 32 20 74 6f 20 70 72 65 70 61 72 65 20 66 6f   2 to prepare fo
1d10: 72 20 73 74 74 79 20 2a 2f 0a 09 09 66 63 6e 74  r stty */...fcnt
1d20: 6c 28 30 2c 46 5f 44 55 50 46 44 2c 31 29 3b 0a  l(0,F_DUPFD,1);.
1d30: 09 09 66 63 6e 74 6c 28 30 2c 46 5f 44 55 50 46  ..fcntl(0,F_DUPF
1d40: 44 2c 32 29 3b 0a 09 7d 0a 0a 09 74 74 79 74 79  D,2);..}...ttyty
1d50: 70 65 28 53 45 54 5f 54 54 59 54 59 50 45 2c 73  pe(SET_TTYTYPE,s
1d60: 6c 61 76 65 2c 74 74 79 63 6f 70 79 2c 74 74 79  lave,ttycopy,tty
1d70: 69 6e 69 74 2c 73 74 74 79 5f 61 72 67 73 29 3b  init,stty_args);
1d80: 0a 09 72 65 74 75 72 6e 28 73 6c 61 76 65 29 3b  ..return(slave);
1d90: 0a 7d 0a 0a 73 65 74 70 74 79 75 74 6d 70 28 29  .}..setptyutmp()
1da0: 0a 7b 0a 09 73 74 72 75 63 74 20 75 74 6d 70 20  .{..struct utmp 
1db0: 75 74 6d 70 3b 0a 0a 09 69 66 20 28 73 65 74 65  utmp;...if (sete
1dc0: 75 69 64 28 30 29 20 3d 3d 20 2d 31 29 20 7b 09  uid(0) == -1) {.
1dd0: 09 2f 2a 20 4e 65 65 64 20 74 6f 20 62 65 20 72  ./* Need to be r
1de0: 6f 6f 74 20 2a 2f 0a 09 09 65 78 70 44 69 61 67  oot */...expDiag
1df0: 4c 6f 67 28 22 73 65 74 70 74 79 75 74 6d 70 3a  Log("setptyutmp:
1e00: 20 20 73 65 74 75 69 64 20 72 6f 6f 74 20 65 72    setuid root er
1e10: 72 6e 6f 3d 25 64 5c 6e 22 2c 65 72 72 6e 6f 29  rno=%d\n",errno)
1e20: 3b 0a 09 09 72 65 74 75 72 6e 28 2d 31 29 3b 0a  ;...return(-1);.
1e30: 09 7d 0a 09 28 76 6f 69 64 29 20 74 69 6d 65 28  .}..(void) time(
1e40: 26 75 74 6d 70 2e 75 74 5f 74 69 6d 65 29 3b 0a  &utmp.ut_time);.
1e50: 09 75 74 6d 70 2e 75 74 5f 74 79 70 65 20 3d 20  .utmp.ut_type = 
1e60: 55 53 45 52 5f 50 52 4f 43 45 53 53 3b 0a 09 75  USER_PROCESS;..u
1e70: 74 6d 70 2e 75 74 5f 70 69 64 20 3d 20 67 65 74  tmp.ut_pid = get
1e80: 70 69 64 28 29 3b 0a 09 73 74 72 6e 63 70 79 28  pid();..strncpy(
1e90: 75 74 6d 70 2e 75 74 5f 75 73 65 72 2c 6d 79 6e  utmp.ut_user,myn
1ea0: 61 6d 65 2c 73 69 7a 65 6f 66 28 75 74 6d 70 2e  ame,sizeof(utmp.
1eb0: 75 74 5f 75 73 65 72 29 29 3b 0a 09 73 74 72 6e  ut_user));..strn
1ec0: 63 70 79 28 75 74 6d 70 2e 75 74 5f 68 6f 73 74  cpy(utmp.ut_host
1ed0: 2c 68 6f 73 74 6e 61 6d 65 2c 73 69 7a 65 6f 66  ,hostname,sizeof
1ee0: 28 75 74 6d 70 2e 75 74 5f 68 6f 73 74 29 29 3b  (utmp.ut_host));
1ef0: 0a 09 73 74 72 6e 63 70 79 28 75 74 6d 70 2e 75  ..strncpy(utmp.u
1f00: 74 5f 6c 69 6e 65 2c 6c 69 6e 65 74 2b 35 2c 73  t_line,linet+5,s
1f10: 69 7a 65 6f 66 28 75 74 6d 70 2e 75 74 5f 6c 69  izeof(utmp.ut_li
1f20: 6e 65 29 29 3b 0a 09 73 74 72 6e 63 70 79 28 75  ne));..strncpy(u
1f30: 74 6d 70 2e 75 74 5f 69 64 2c 6c 69 6e 65 74 2b  tmp.ut_id,linet+
1f40: 38 2c 73 69 7a 65 6f 66 28 75 74 6d 70 2e 75 74  8,sizeof(utmp.ut
1f50: 5f 69 64 29 29 3b 0a 09 69 66 20 28 70 75 74 75  _id));..if (putu
1f60: 74 6c 69 6e 65 28 26 75 74 6d 70 29 20 3d 3d 20  tline(&utmp) == 
1f70: 4e 55 4c 4c 29 20 7b 0a 09 09 65 78 70 44 69 61  NULL) {...expDia
1f80: 67 4c 6f 67 28 22 73 65 74 70 74 79 75 74 6d 70  gLog("setptyutmp
1f90: 3a 20 20 70 75 74 75 74 6c 69 6e 65 20 66 61 69  :  pututline fai
1fa0: 6c 65 64 5c 6e 22 29 3b 0a 09 7d 0a 09 65 6e 64  led\n");..}..end
1fb0: 75 74 65 6e 74 28 29 3b 0a 09 69 66 20 28 73 65  utent();..if (se
1fc0: 74 65 75 69 64 28 72 65 61 6c 75 69 64 29 20 3d  teuid(realuid) =
1fd0: 3d 20 2d 31 29 0a 09 09 65 78 70 44 69 61 67 4c  = -1)...expDiagL
1fe0: 6f 67 28 22 73 65 74 70 74 79 75 74 6d 70 3a 20  og("setptyutmp: 
1ff0: 20 73 65 74 65 75 69 64 20 75 73 65 72 20 65 72   seteuid user er
2000: 72 6e 6f 3d 25 64 5c 6e 22 2c 65 72 72 6e 6f 29  rno=%d\n",errno)
2010: 3b 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a  ;..return(0);.}.
2020: 0a 73 65 74 70 74 79 70 69 64 28 70 69 64 29 0a  .setptypid(pid).
2030: 69 6e 74 20 70 69 64 3b 0a 7b 0a 20 20 20 20 20  int pid;.{.     
2040: 20 20 20 69 6e 74 20 6e 70 74 79 3b 0a 0a 20 20     int npty;..  
2050: 20 20 20 20 20 20 66 6f 72 20 28 6e 70 74 79 20        for (npty 
2060: 3d 20 6c 6f 77 70 74 79 3b 20 6e 70 74 79 20 3c  = lowpty; npty <
2070: 3d 20 68 69 67 68 70 74 79 3b 20 6e 70 74 79 2b  = highpty; npty+
2080: 2b 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20  +) {.           
2090: 20 20 20 20 20 69 66 20 28 70 74 79 73 5b 6e 70       if (ptys[np
20a0: 74 79 5d 20 3c 20 30 29 20 7b 0a 20 20 20 20 20  ty] < 0) {.     
20b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
20c0: 20 20 20 65 78 70 44 69 61 67 4c 6f 67 28 22 73     expDiagLog("s
20d0: 65 74 70 74 79 70 69 64 3a 20 20 74 74 79 70 25  etptypid:  ttyp%
20e0: 30 33 64 20 70 69 64 3d 25 64 5c 6e 22 2c 6e 70  03d pid=%d\n",np
20f0: 74 79 2c 70 69 64 29 3b 0a 20 20 20 20 20 20 20  ty,pid);.       
2100: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2110: 20 70 74 79 73 5b 6e 70 74 79 5d 20 3d 20 70 69   ptys[npty] = pi
2120: 64 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  d;.             
2130: 20 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b             break
2140: 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ;.              
2150: 20 20 7d 0a 20 20 20 20 20 20 20 20 7d 0a 7d 0a    }.        }.}.
2160: 0a 74 74 79 70 5f 72 65 73 65 74 28 29 0a 7b 0a  .ttyp_reset().{.
2170: 20 20 20 20 20 20 20 20 69 6e 74 20 6e 70 74 79          int npty
2180: 3b 0a 0a 20 20 20 20 20 20 20 20 69 66 20 28 73  ;..        if (s
2190: 65 74 65 75 69 64 28 30 29 20 3d 3d 20 2d 31 29  eteuid(0) == -1)
21a0: 20 7b 09 09 2f 2a 20 77 65 20 6e 65 65 64 20 74   {../* we need t
21b0: 6f 20 62 65 20 72 6f 6f 74 21 20 2a 2f 0a 20 20  o be root! */.  
21c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 65 78                ex
21d0: 70 44 69 61 67 4c 6f 67 28 22 74 74 79 70 5f 72  pDiagLog("ttyp_r
21e0: 65 73 65 74 3a 20 20 73 65 74 65 75 69 64 20 72  eset:  seteuid r
21f0: 6f 6f 74 20 65 72 72 6e 6f 3d 25 64 5c 6e 22 2c  oot errno=%d\n",
2200: 65 72 72 6e 6f 29 3b 0a 20 20 20 20 20 20 20 20  errno);.        
2210: 7d 0a 20 20 20 20 20 20 20 20 66 6f 72 20 28 6e  }.        for (n
2220: 70 74 79 20 3d 20 6c 6f 77 70 74 79 3b 20 6e 70  pty = lowpty; np
2230: 74 79 20 3c 3d 20 68 69 67 68 70 74 79 3b 20 6e  ty <= highpty; n
2240: 70 74 79 2b 2b 29 20 7b 0a 20 20 20 20 20 20 20  pty++) {.       
2250: 20 20 20 20 20 20 20 20 20 69 66 20 28 70 74 79           if (pty
2260: 73 5b 6e 70 74 79 5d 20 3c 3d 20 30 29 0a 20 20  s[npty] <= 0).  
2270: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2280: 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a        continue;.
2290: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
22a0: 20 28 76 6f 69 64 29 20 73 70 72 69 6e 74 66 28   (void) sprintf(
22b0: 6c 69 6e 65 74 2c 20 22 2f 64 65 76 2f 74 74 79  linet, "/dev/tty
22c0: 70 25 30 33 64 22 2c 20 6e 70 74 79 29 3b 0a 20  p%03d", npty);. 
22d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 65                 e
22e0: 78 70 44 69 61 67 4c 6f 67 28 22 74 74 79 70 5f  xpDiagLog("ttyp_
22f0: 72 65 73 65 74 3a 20 20 72 65 73 65 74 74 69 6e  reset:  resettin
2300: 67 20 25 73 2c 20 6b 69 6c 6c 69 6e 67 20 25 64  g %s, killing %d
2310: 5c 6e 22 2c 0a 09 09 09 6c 69 6e 65 74 2c 70 74  \n",....linet,pt
2320: 79 73 5b 6e 70 74 79 5d 29 3b 0a 20 20 20 20 20  ys[npty]);.     
2330: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 63             if (c
2340: 68 6f 77 6e 28 6c 69 6e 65 74 2c 30 2c 30 29 20  hown(linet,0,0) 
2350: 3d 3d 20 2d 31 29 20 7b 0a 20 20 20 20 20 20 20  == -1) {.       
2360: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2370: 20 65 78 70 44 69 61 67 4c 6f 67 28 22 74 74 79   expDiagLog("tty
2380: 70 5f 72 65 73 65 74 3a 20 63 68 6f 77 6e 20 25  p_reset: chown %
2390: 73 20 65 72 72 6e 6f 3d 25 64 5c 6e 22 2c 6c 69  s errno=%d\n",li
23a0: 6e 65 74 2c 65 72 72 6e 6f 29 3b 0a 20 20 20 20  net,errno);.    
23b0: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 20              }.  
23c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66                if
23d0: 20 28 63 68 6d 6f 64 28 6c 69 6e 65 74 2c 20 30   (chmod(linet, 0
23e0: 36 36 36 29 20 3d 3d 20 2d 31 29 20 7b 0a 20 20  666) == -1) {.  
23f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2400: 20 20 20 20 20 20 65 78 70 44 69 61 67 4c 6f 67        expDiagLog
2410: 28 22 74 74 79 70 5f 72 65 73 65 74 3a 20 63 68  ("ttyp_reset: ch
2420: 6d 6f 64 20 25 73 20 65 72 72 6e 6f 3d 25 64 5c  mod %s errno=%d\
2430: 6e 22 2c 6c 69 6e 65 74 2c 65 72 72 6e 6f 29 3b  n",linet,errno);
2440: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
2450: 20 7d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20   }.             
2460: 20 20 20 72 65 73 65 74 70 74 79 75 74 6d 70 28     resetptyutmp(
2470: 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  );.             
2480: 20 20 20 69 66 20 28 6b 69 6c 6c 28 70 74 79 73     if (kill(ptys
2490: 5b 6e 70 74 79 5d 2c 53 49 47 4b 49 4c 4c 29 20  [npty],SIGKILL) 
24a0: 3d 3d 20 2d 31 29 20 7b 0a 20 20 20 20 20 20 20  == -1) {.       
24b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
24c0: 20 65 78 70 44 69 61 67 4c 6f 67 28 22 74 74 79   expDiagLog("tty
24d0: 70 5f 72 65 73 65 74 3a 20 20 6b 69 6c 6c 20 70  p_reset:  kill p
24e0: 69 64 3d 25 64 20 65 72 72 6e 6f 3d 25 64 5c 6e  id=%d errno=%d\n
24f0: 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  ",.             
2500: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2510: 20 20 20 70 74 79 73 5b 6e 70 74 79 5d 2c 65 72     ptys[npty],er
2520: 72 6e 6f 29 3b 0a 20 20 20 20 20 20 20 20 20 20  rno);.          
2530: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20        }.        
2540: 7d 0a 20 20 20 20 20 20 20 20 69 66 20 28 73 65  }.        if (se
2550: 74 65 75 69 64 28 72 65 61 6c 75 69 64 29 20 3d  teuid(realuid) =
2560: 3d 20 2d 31 29 20 7b 20 20 20 2f 2a 20 42 61 63  = -1) {   /* Bac
2570: 6b 20 74 6f 20 77 68 6f 20 77 65 20 72 65 61 6c  k to who we real
2580: 6c 79 20 61 72 65 20 2a 2f 0a 20 20 20 20 20 20  ly are */.      
2590: 20 20 20 20 20 20 20 20 20 20 65 78 70 44 69 61            expDia
25a0: 67 4c 6f 67 28 22 74 74 79 70 5f 72 65 73 65 74  gLog("ttyp_reset
25b0: 3a 20 20 73 65 74 65 75 69 64 20 75 73 65 72 20  :  seteuid user 
25c0: 65 72 72 6e 6f 3d 25 64 5c 6e 22 2c 65 72 72 6e  errno=%d\n",errn
25d0: 6f 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a 7d 0a  o);.        }.}.
25e0: 0a 76 6f 69 64 0a 65 78 70 5f 70 74 79 5f 65 78  .void.exp_pty_ex
25f0: 69 74 28 29 0a 7b 0a 09 74 74 79 70 5f 72 65 73  it().{..ttyp_res
2600: 65 74 28 29 3b 0a 7d 0a 0a 72 65 73 65 74 70 74  et();.}..resetpt
2610: 79 75 74 6d 70 28 29 0a 7b 0a 20 20 20 20 20 20  yutmp().{.      
2620: 20 20 73 74 72 75 63 74 20 75 74 6d 70 20 75 74    struct utmp ut
2630: 6d 70 3b 0a 0a 20 20 20 20 20 20 20 20 28 76 6f  mp;..        (vo
2640: 69 64 29 20 73 65 74 75 74 65 6e 74 20 28 29 3b  id) setutent ();
2650: 0a 20 20 20 20 20 20 20 20 2f 2a 20 73 65 74 20  .        /* set 
2660: 75 70 20 65 6e 74 72 79 20 74 6f 20 73 65 61 72  up entry to sear
2670: 63 68 20 66 6f 72 20 2a 2f 0a 20 20 20 20 20 20  ch for */.      
2680: 20 20 28 76 6f 69 64 29 20 73 74 72 6e 63 70 79    (void) strncpy
2690: 28 75 74 6d 70 2e 75 74 5f 69 64 2c 20 6c 69 6e  (utmp.ut_id, lin
26a0: 65 74 20 2b 20 73 74 72 6c 65 6e 28 6c 69 6e 65  et + strlen(line
26b0: 74 29 20 2d 20 34 2c 0a 20 20 20 20 20 20 20 20  t) - 4,.        
26c0: 20 20 20 20 20 20 20 20 20 73 69 7a 65 6f 66 20           sizeof 
26d0: 28 75 74 6d 70 2e 75 74 5f 69 64 29 29 3b 0a 20  (utmp.ut_id));. 
26e0: 20 20 20 20 20 20 20 75 74 6d 70 2e 75 74 5f 74         utmp.ut_t
26f0: 79 70 65 20 3d 20 55 53 45 52 5f 50 52 4f 43 45  ype = USER_PROCE
2700: 53 53 3b 0a 0a 20 20 20 20 20 20 20 20 2f 2a 20  SS;..        /* 
2710: 70 6f 73 69 74 69 6f 6e 20 74 6f 20 65 6e 74 72  position to entr
2720: 79 20 69 6e 20 75 74 6d 70 20 66 69 6c 65 20 2a  y in utmp file *
2730: 2f 0a 20 20 20 20 20 20 20 20 69 66 28 67 65 74  /.        if(get
2740: 75 74 69 64 28 26 75 74 6d 70 29 20 3d 3d 20 4e  utid(&utmp) == N
2750: 55 4c 4c 29 20 7b 0a 20 20 20 20 20 20 20 20 20  ULL) {.         
2760: 20 20 20 20 20 20 20 65 78 70 44 69 61 67 4c 6f         expDiagLo
2770: 67 28 22 72 65 73 65 74 70 74 79 75 74 6d 70 3a  g("resetptyutmp:
2780: 20 20 6e 6f 20 75 74 6d 70 20 65 6e 74 72 79 20    no utmp entry 
2790: 66 6f 72 20 25 73 5c 6e 22 2c 6c 69 6e 65 74 29  for %s\n",linet)
27a0: 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ;.              
27b0: 20 20 72 65 74 75 72 6e 28 2d 31 29 3b 20 20 20    return(-1);   
27c0: 20 20 2f 2a 20 6e 6f 20 75 74 6d 70 20 65 6e 74    /* no utmp ent
27d0: 72 79 20 66 6f 72 20 74 68 69 73 20 6c 69 6e 65  ry for this line
27e0: 20 3f 3f 3f 20 2a 2f 0a 20 20 20 20 20 20 20 20   ??? */.        
27f0: 7d 0a 0a 20 20 20 20 20 20 20 20 2f 2a 20 73 65  }..        /* se
2800: 74 20 75 70 20 74 68 65 20 6e 65 77 20 65 6e 74  t up the new ent
2810: 72 79 20 2a 2f 0a 20 20 20 20 20 20 20 20 73 74  ry */.        st
2820: 72 6e 63 70 79 28 75 74 6d 70 2e 75 74 5f 6e 61  rncpy(utmp.ut_na
2830: 6d 65 2c 22 22 2c 73 69 7a 65 6f 66 28 75 74 6d  me,"",sizeof(utm
2840: 70 2e 75 74 5f 6e 61 6d 65 29 29 3b 0a 20 20 20  p.ut_name));.   
2850: 20 20 20 20 20 73 74 72 6e 63 70 79 28 75 74 6d       strncpy(utm
2860: 70 2e 75 74 5f 68 6f 73 74 2c 22 22 2c 73 69 7a  p.ut_host,"",siz
2870: 65 6f 66 28 75 74 6d 70 2e 75 74 5f 68 6f 73 74  eof(utmp.ut_host
2880: 29 29 3b 0a 20 20 20 20 20 20 20 20 74 69 6d 65  ));.        time
2890: 28 26 75 74 6d 70 2e 75 74 5f 74 69 6d 65 29 3b  (&utmp.ut_time);
28a0: 0a 20 20 20 20 20 20 20 20 75 74 6d 70 2e 75 74  .        utmp.ut
28b0: 5f 74 79 70 65 20 3d 20 44 45 41 44 5f 50 52 4f  _type = DEAD_PRO
28c0: 43 45 53 53 3b 0a 20 20 20 20 20 20 20 20 75 74  CESS;.        ut
28d0: 6d 70 2e 75 74 5f 65 78 69 74 2e 65 5f 65 78 69  mp.ut_exit.e_exi
28e0: 74 20 3d 20 30 3b 0a 0a 20 20 20 20 20 20 20 20  t = 0;..        
28f0: 2f 2a 20 77 72 69 74 65 20 6f 75 74 20 74 68 65  /* write out the
2900: 20 65 6e 74 72 79 20 2a 2f 0a 20 20 20 20 20 20   entry */.      
2910: 20 20 70 75 74 75 74 6c 69 6e 65 28 26 75 74 6d    pututline(&utm
2920: 70 29 3b 0a 0a 20 20 20 20 20 20 20 20 2f 2a 20  p);..        /* 
2930: 63 6c 6f 73 65 20 74 68 65 20 66 69 6c 65 20 2a  close the file *
2940: 2f 0a 20 20 20 20 20 20 20 20 28 76 6f 69 64 29  /.        (void)
2950: 20 65 6e 64 75 74 65 6e 74 28 29 3b 0a 20 20 20   endutent();.   
2960: 20 20 20 20 20 72 65 74 75 72 6e 28 30 29 3b 0a       return(0);.
2970: 7d 0a                                            }.