2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static const char sccsid[] = "@(#)sys_term.c 8.4+1 (Berkeley) 5/30/95";
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
42 #include <sys/types.h>
48 #include "pathnames.h"
51 #include <libtelnet/auth.h>
54 int cleanopen(char *);
58 extern char **environ;
60 #define SCPYN(a, b) (void) strncpy(a, b, sizeof(a))
61 #define SCMPN(a, b) strncmp(a, b, sizeof(a))
88 # define cfsetospeed(tp, val) (tp)->sg.sg_ospeed = (val)
89 # define cfsetispeed(tp, val) (tp)->sg.sg_ispeed = (val)
90 # define cfgetospeed(tp) (tp)->sg.sg_ospeed
91 # define cfgetispeed(tp) (tp)->sg.sg_ispeed
92 #else /* USE_TERMIO */
95 # define TCSANOW TCSETS
96 # define TCSADRAIN TCSETSW
97 # define tcgetattr(f, t) ioctl(f, TCGETS, (char *)t)
100 # define TCSANOW TCSETA
101 # define TCSADRAIN TCSETAW
102 # define tcgetattr(f, t) ioctl(f, TCGETA, (char *)t)
104 # define TCSANOW TIOCSETA
105 # define TCSADRAIN TIOCSETAW
106 # define tcgetattr(f, t) ioctl(f, TIOCGETA, (char *)t)
109 # define tcsetattr(f, a, t) ioctl(f, a, t)
110 # define cfsetospeed(tp, val) (tp)->c_cflag &= ~CBAUD; \
111 (tp)->c_cflag |= (val)
112 # define cfgetospeed(tp) ((tp)->c_cflag & CBAUD)
114 # define cfsetispeed(tp, val) (tp)->c_cflag &= ~CIBAUD; \
115 (tp)->c_cflag |= ((val)<<IBSHIFT)
116 # define cfgetispeed(tp) (((tp)->c_cflag & CIBAUD)>>IBSHIFT)
118 # define cfsetispeed(tp, val) (tp)->c_cflag &= ~CBAUD; \
119 (tp)->c_cflag |= (val)
120 # define cfgetispeed(tp) ((tp)->c_cflag & CBAUD)
122 # endif /* TCSANOW */
123 struct termios termbuf, termbuf2; /* pty control structure */
124 #endif /* USE_TERMIO */
126 #include <sys/types.h>
129 int cleanopen(char *);
130 void scrub_env(void);
131 static char **addarg(char **, const char *);
138 * These three routines are used to get and set the "termbuf" structure
139 * to and from the kernel. init_termbuf() gets the current settings.
140 * copy_termbuf() hands in a new "termbuf" to write to the kernel, and
141 * set_termbuf() writes the structure into the kernel.
148 (void) ioctl(pty, TIOCGETP, (char *)&termbuf.sg);
149 (void) ioctl(pty, TIOCGETC, (char *)&termbuf.tc);
150 (void) ioctl(pty, TIOCGLTC, (char *)&termbuf.ltc);
152 (void) ioctl(pty, TIOCGSTATE, (char *)&termbuf.state);
155 (void) tcgetattr(pty, &termbuf);
160 #if defined(LINEMODE) && defined(TIOCPKT_IOCTL)
162 copy_termbuf(char *cp, size_t len)
164 if (len > sizeof(termbuf))
165 len = sizeof(termbuf);
166 memmove((char *)&termbuf, cp, len);
169 #endif /* defined(LINEMODE) && defined(TIOCPKT_IOCTL) */
175 * Only make the necessary changes.
178 if (memcmp((char *)&termbuf.sg, (char *)&termbuf2.sg,
180 (void) ioctl(pty, TIOCSETN, (char *)&termbuf.sg);
181 if (memcmp((char *)&termbuf.tc, (char *)&termbuf2.tc,
183 (void) ioctl(pty, TIOCSETC, (char *)&termbuf.tc);
184 if (memcmp((char *)&termbuf.ltc, (char *)&termbuf2.ltc,
185 sizeof(termbuf.ltc)))
186 (void) ioctl(pty, TIOCSLTC, (char *)&termbuf.ltc);
187 if (termbuf.lflags != termbuf2.lflags)
188 (void) ioctl(pty, TIOCLSET, (char *)&termbuf.lflags);
189 #else /* USE_TERMIO */
190 if (memcmp((char *)&termbuf, (char *)&termbuf2, sizeof(termbuf)))
191 (void) tcsetattr(pty, TCSANOW, &termbuf);
192 #endif /* USE_TERMIO */
197 * spcset(func, valp, valpp)
199 * This function takes various special characters (func), and
200 * sets *valp to the current value of that character, and
201 * *valpp to point to where in the "termbuf" structure that
204 * It returns the SLC_ level of support for this function.
209 spcset(int func, cc_t *valp, cc_t **valpp)
213 *valp = termbuf.tc.t_eofc;
214 *valpp = (cc_t *)&termbuf.tc.t_eofc;
215 return(SLC_VARIABLE);
217 *valp = termbuf.sg.sg_erase;
218 *valpp = (cc_t *)&termbuf.sg.sg_erase;
219 return(SLC_VARIABLE);
221 *valp = termbuf.sg.sg_kill;
222 *valpp = (cc_t *)&termbuf.sg.sg_kill;
223 return(SLC_VARIABLE);
225 *valp = termbuf.tc.t_intrc;
226 *valpp = (cc_t *)&termbuf.tc.t_intrc;
227 return(SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
229 *valp = termbuf.tc.t_quitc;
230 *valpp = (cc_t *)&termbuf.tc.t_quitc;
231 return(SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
233 *valp = termbuf.tc.t_startc;
234 *valpp = (cc_t *)&termbuf.tc.t_startc;
235 return(SLC_VARIABLE);
237 *valp = termbuf.tc.t_stopc;
238 *valpp = (cc_t *)&termbuf.tc.t_stopc;
239 return(SLC_VARIABLE);
241 *valp = termbuf.ltc.t_flushc;
242 *valpp = (cc_t *)&termbuf.ltc.t_flushc;
243 return(SLC_VARIABLE);
245 *valp = termbuf.ltc.t_suspc;
246 *valpp = (cc_t *)&termbuf.ltc.t_suspc;
247 return(SLC_VARIABLE);
249 *valp = termbuf.ltc.t_werasc;
250 *valpp = (cc_t *)&termbuf.ltc.t_werasc;
251 return(SLC_VARIABLE);
253 *valp = termbuf.ltc.t_rprntc;
254 *valpp = (cc_t *)&termbuf.ltc.t_rprntc;
255 return(SLC_VARIABLE);
257 *valp = termbuf.ltc.t_lnextc;
258 *valpp = (cc_t *)&termbuf.ltc.t_lnextc;
259 return(SLC_VARIABLE);
261 *valp = termbuf.tc.t_brkc;
262 *valpp = (cc_t *)&termbuf.ltc.t_lnextc;
263 return(SLC_VARIABLE);
274 return(SLC_NOSUPPORT);
278 #else /* USE_TERMIO */
281 #define setval(a, b) *valp = termbuf.c_cc[a]; \
282 *valpp = &termbuf.c_cc[a]; \
284 #define defval(a) *valp = ((cc_t)a); *valpp = (cc_t *)0; return(SLC_DEFAULT);
287 spcset(int func, cc_t *valp, cc_t **valpp)
291 setval(VEOF, SLC_VARIABLE);
293 setval(VERASE, SLC_VARIABLE);
295 setval(VKILL, SLC_VARIABLE);
297 setval(VINTR, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
299 setval(VQUIT, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
302 setval(VSTART, SLC_VARIABLE);
308 setval(VSTOP, SLC_VARIABLE);
314 setval(VWERASE, SLC_VARIABLE);
320 setval(VREPRINT, SLC_VARIABLE);
326 setval(VLNEXT, SLC_VARIABLE);
331 #if !defined(VDISCARD) && defined(VFLUSHO)
332 # define VDISCARD VFLUSHO
335 setval(VDISCARD, SLC_VARIABLE|SLC_FLUSHOUT);
341 setval(VSUSP, SLC_VARIABLE|SLC_FLUSHIN);
347 setval(VEOL, SLC_VARIABLE);
351 setval(VEOL2, SLC_VARIABLE);
355 setval(VSTATUS, SLC_VARIABLE);
368 return(SLC_NOSUPPORT);
371 #endif /* USE_TERMIO */
376 * Allocate a pty. As a side effect, the external character
377 * array "line" contains the name of the slave side.
379 * Returns the file descriptor of the opened pty.
384 getpty(int *ptynum __unused)
389 p = posix_openpt(O_RDWR|O_NOCTTY);
393 if (grantpt(p) == -1)
396 if (unlockpt(p) == -1)
403 if (strlcpy(line, pn, sizeof line) >= sizeof line)
411 * tty_flowmode() Find out if flow control is enabled or disabled.
412 * tty_linemode() Find out if linemode (external processing) is enabled.
413 * tty_setlinemod(on) Turn on/off linemode.
414 * tty_isecho() Find out if echoing is turned on.
415 * tty_setecho(on) Enable/disable character echoing.
416 * tty_israw() Find out if terminal is in RAW mode.
417 * tty_binaryin(on) Turn on/off BINARY on input.
418 * tty_binaryout(on) Turn on/off BINARY on output.
419 * tty_isediting() Find out if line editing is enabled.
420 * tty_istrapsig() Find out if signal trapping is enabled.
421 * tty_setedit(on) Turn on/off line editing.
422 * tty_setsig(on) Turn on/off signal trapping.
423 * tty_issofttab() Find out if tab expansion is enabled.
424 * tty_setsofttab(on) Turn on/off soft tab expansion.
425 * tty_islitecho() Find out if typed control chars are echoed literally
426 * tty_setlitecho() Turn on/off literal echo of control chars
427 * tty_tspeed(val) Set transmit speed to val.
428 * tty_rspeed(val) Set receive speed to val.
436 return(termbuf.state & TS_EXTPROC);
438 return(termbuf.c_lflag & EXTPROC);
443 tty_setlinemode(int on)
447 (void) ioctl(pty, TIOCEXT, (char *)&on);
452 termbuf.c_lflag |= EXTPROC;
454 termbuf.c_lflag &= ~EXTPROC;
458 #endif /* LINEMODE */
464 return (termbuf.sg.sg_flags & ECHO);
466 return (termbuf.c_lflag & ECHO);
474 return(((termbuf.tc.t_startc) > 0 && (termbuf.tc.t_stopc) > 0) ? 1 : 0);
476 return((termbuf.c_iflag & IXON) ? 1 : 0);
485 return((termbuf.lflags & DECCTQ) ? 0 : 1);
490 return((termbuf.c_iflag & IXANY) ? 1 : 0);
499 termbuf.sg.sg_flags |= ECHO|CRMOD;
501 termbuf.sg.sg_flags &= ~(ECHO|CRMOD);
504 termbuf.c_lflag |= ECHO;
506 termbuf.c_lflag &= ~ECHO;
514 return(termbuf.sg.sg_flags & RAW);
516 return(!(termbuf.c_lflag & ICANON));
520 #ifdef AUTHENTICATION
521 #if defined(NO_LOGIN_F) && defined(LOGIN_R)
527 termbuf.sg.sg_flags |= RAW;
529 termbuf.sg.sg_flags &= ~RAW;
532 termbuf.c_lflag &= ~ICANON;
534 termbuf.c_lflag |= ICANON;
538 #endif /* AUTHENTICATION */
545 termbuf.lflags |= LPASS8;
547 termbuf.lflags &= ~LPASS8;
550 termbuf.c_iflag &= ~ISTRIP;
552 termbuf.c_iflag |= ISTRIP;
558 tty_binaryout(int on)
562 termbuf.lflags |= LLITOUT;
564 termbuf.lflags &= ~LLITOUT;
567 termbuf.c_cflag &= ~(CSIZE|PARENB);
568 termbuf.c_cflag |= CS8;
569 termbuf.c_oflag &= ~OPOST;
571 termbuf.c_cflag &= ~CSIZE;
572 termbuf.c_cflag |= CS7|PARENB;
573 termbuf.c_oflag |= OPOST;
582 return(termbuf.lflags & LPASS8);
584 return(!(termbuf.c_iflag & ISTRIP));
589 tty_isbinaryout(void)
592 return(termbuf.lflags & LLITOUT);
594 return(!(termbuf.c_oflag&OPOST));
603 return(!(termbuf.sg.sg_flags & (CBREAK|RAW)));
605 return(termbuf.c_lflag & ICANON);
613 return(!(termbuf.sg.sg_flags&RAW));
615 return(termbuf.c_lflag & ISIG);
624 termbuf.sg.sg_flags &= ~CBREAK;
626 termbuf.sg.sg_flags |= CBREAK;
629 termbuf.c_lflag |= ICANON;
631 termbuf.c_lflag &= ~ICANON;
643 termbuf.c_lflag |= ISIG;
645 termbuf.c_lflag &= ~ISIG;
648 #endif /* LINEMODE */
654 return (termbuf.sg.sg_flags & XTABS);
657 return (termbuf.c_oflag & OXTABS);
660 return ((termbuf.c_oflag & TABDLY) == TAB3);
666 tty_setsofttab(int on)
670 termbuf.sg.sg_flags |= XTABS;
672 termbuf.sg.sg_flags &= ~XTABS;
676 termbuf.c_oflag |= OXTABS;
679 termbuf.c_oflag &= ~TABDLY;
680 termbuf.c_oflag |= TAB3;
684 termbuf.c_oflag &= ~OXTABS;
687 termbuf.c_oflag &= ~TABDLY;
688 termbuf.c_oflag |= TAB0;
698 return (!(termbuf.lflags & LCTLECH));
701 return (!(termbuf.c_lflag & ECHOCTL));
704 return (!(termbuf.c_lflag & TCTLECH));
706 # if !defined(ECHOCTL) && !defined(TCTLECH)
707 return (0); /* assumes ctl chars are echoed '^x' */
713 tty_setlitecho(int on)
717 termbuf.lflags &= ~LCTLECH;
719 termbuf.lflags |= LCTLECH;
723 termbuf.c_lflag &= ~ECHOCTL;
725 termbuf.c_lflag |= ECHOCTL;
729 termbuf.c_lflag &= ~TCTLECH;
731 termbuf.c_lflag |= TCTLECH;
740 return (termbuf.sg.sg_flags & CRMOD);
742 return (termbuf.c_iflag & ICRNL);
747 * Try to guess whether speeds are "encoded" (4.2BSD) or just numeric (4.4BSD).
756 * A table of available terminal speeds
762 { 0, B0 }, { 50, B50 }, { 75, B75 },
763 { 110, B110 }, { 134, B134 }, { 150, B150 },
764 { 200, B200 }, { 300, B300 }, { 600, B600 },
765 { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 },
794 #endif /* DECODE_BAUD */
800 struct termspeeds *tp;
802 for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++)
804 if (tp->speed == -1) /* back up to last valid value */
806 cfsetospeed(&termbuf, tp->value);
807 #else /* DECODE_BAUD */
808 cfsetospeed(&termbuf, val);
809 #endif /* DECODE_BAUD */
816 struct termspeeds *tp;
818 for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++)
820 if (tp->speed == -1) /* back up to last valid value */
822 cfsetispeed(&termbuf, tp->value);
823 #else /* DECODE_BAUD */
824 cfsetispeed(&termbuf, val);
825 #endif /* DECODE_BAUD */
831 * Open the slave side of the pty, and do any initialization
845 extern int def_row, def_col;
847 extern int def_tspeed, def_rspeed;
849 * Opening the slave side may cause initilization of the
850 * kernel tty structure. We need remember the state of
851 * if linemode was turned on
852 * terminal window size
855 * so that we can re-set them if we need to.
858 waslm = tty_linemode();
860 erase = termbuf.c_cc[VERASE];
863 * Make sure that we don't have a controlling tty, and
864 * that we are the session (process group) leader.
867 t = open(_PATH_TTY, O_RDWR);
869 (void) ioctl(t, TIOCNOTTY, (char *)0);
876 fatalperror(net, line);
880 * set up the tty modes as we like them to be.
884 if (def_row || def_col) {
885 memset((char *)&ws, 0, sizeof(ws));
888 (void)ioctl(t, TIOCSWINSZ, (char *)&ws);
893 * Settings for sgtty based systems
896 termbuf.sg.sg_flags |= CRMOD|ANYP|ECHO|XTABS;
897 # endif /* USE_TERMIO */
900 * Settings for all other termios/termio based
901 * systems, other than 4.4BSD. In 4.4BSD the
902 * kernel does the initial terminal setup.
904 tty_rspeed((def_rspeed > 0) ? def_rspeed : 9600);
905 tty_tspeed((def_tspeed > 0) ? def_tspeed : 9600);
907 termbuf.c_cc[VERASE] = erase;
911 # endif /* LINEMODE */
914 * Set the tty modes, and make this our controlling tty.
917 if (login_tty(t) == -1)
918 fatalperror(net, "login_tty");
921 #ifdef AUTHENTICATION
922 #if defined(NO_LOGIN_F) && defined(LOGIN_R)
924 * Leave the pty open so that we can write out the rlogin
925 * protocol for /bin/login, if the authentication works.
933 #endif /* AUTHENTICATION */
940 * Open the specified slave side of the pty,
941 * making sure that we have a clean tty.
949 * Make sure that other people can't open the
950 * slave side of the connection.
952 (void) chown(li, 0, 0);
953 (void) chmod(li, 0600);
957 t = open(line, O_RDWR|O_NOCTTY);
968 * Given a hostname, do whatever
969 * is necessary to startup the login process on the slave side of the pty.
974 startslave(char *host, int autologin, char *autoname)
978 #ifdef AUTHENTICATION
979 if (!autoname || !autoname[0])
982 if (autologin < auth_level) {
983 fatal(net, "Authorization failed");
989 if ((i = fork()) < 0)
990 fatalperror(net, "fork");
994 start_login(host, autologin, autoname);
1005 if ((*envp = getenv("TZ")))
1015 * Assuming that we are now running as a child processes, this
1016 * function will turn us into the login process.
1019 #ifndef AUTHENTICATION
1020 #define undef1 __unused
1026 start_login(char *host undef1, int autologin undef1, char *name undef1)
1031 user = getenv("USER");
1032 user = (user != NULL) ? strdup(user) : NULL;
1037 * -h : pass on name of host.
1038 * WARNING: -h is accepted by login if and only if
1040 * -p : don't clobber the environment (so terminal type stays set).
1042 * -f : force this login, he has already been authenticated
1044 argv = addarg(0, "login");
1046 #if !defined(NO_LOGIN_H)
1047 #ifdef AUTHENTICATION
1048 # if defined(NO_LOGIN_F) && defined(LOGIN_R)
1050 * Don't add the "-h host" option if we are going
1051 * to be adding the "-r host" option down below...
1053 if ((auth_level < 0) || (autologin != AUTH_VALID))
1055 #endif /* AUTHENTICATION */
1057 argv = addarg(argv, "-h");
1058 argv = addarg(argv, host);
1061 #if !defined(NO_LOGIN_P)
1062 argv = addarg(argv, "-p");
1066 * Set the environment variable "LINEMODE" to either
1067 * "real" or "kludge" if we are operating in either
1068 * real or kludge linemode.
1070 if (lmodetype == REAL_LINEMODE)
1071 setenv("LINEMODE", "real", 1);
1072 # ifdef KLUDGELINEMODE
1073 else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK)
1074 setenv("LINEMODE", "kludge", 1);
1079 * Are we working as the bftp daemon? If so, then ask login
1080 * to start bftp instead of shell.
1083 argv = addarg(argv, "-e");
1084 argv = addarg(argv, BFTPPATH);
1087 #ifdef AUTHENTICATION
1088 if (auth_level >= 0 && autologin == AUTH_VALID) {
1089 # if !defined(NO_LOGIN_F)
1090 argv = addarg(argv, "-f");
1091 argv = addarg(argv, "--");
1092 argv = addarg(argv, name);
1094 # if defined(LOGIN_R)
1096 * We don't have support for "login -f", but we
1097 * can fool /bin/login into thinking that we are
1098 * rlogind, and allow us to log in without a
1099 * password. The rlogin protocol expects
1100 * local-user\0remote-user\0term/speed\0
1106 int isecho, israw, xpty, len;
1107 extern int def_rspeed;
1110 * Tell login that we are coming from "localhost".
1111 * If we passed in the real host name, then the
1112 * user would have to allow .rhost access from
1113 * every machine that they want authenticated
1114 * access to work from, which sort of defeats
1115 * the purpose of an authenticated login...
1116 * So, we tell login that the session is coming
1117 * from "localhost", and the user will only have
1118 * to have "localhost" in their .rhost file.
1120 # define LOGIN_HOST "localhost"
1122 argv = addarg(argv, "-r");
1123 argv = addarg(argv, LOGIN_HOST);
1128 isecho = tty_isecho();
1129 israw = tty_israw();
1130 if (isecho || !israw) {
1131 tty_setecho(0); /* Turn off echo */
1132 tty_setraw(1); /* Turn on raw */
1135 len = strlen(name)+1;
1136 write(xpty, name, len);
1137 write(xpty, name, len);
1138 snprintf(speed, sizeof(speed),
1139 "%s/%d", (cp = getenv("TERM")) ? cp : "",
1140 (def_rspeed > 0) ? def_rspeed : 9600);
1141 len = strlen(speed)+1;
1142 write(xpty, speed, len);
1144 if (isecho || !israw) {
1146 tty_setecho(isecho);
1151 * Write a newline to ensure
1152 * that login will be able to
1155 write(xpty, "\n", 1);
1161 argv = addarg(argv, "--");
1162 argv = addarg(argv, name);
1168 argv = addarg(argv, "--");
1169 argv = addarg(argv, user);
1170 #if defined(LOGIN_ARGS) && defined(NO_LOGIN_P)
1173 for (cpp = environ; *cpp; cpp++)
1174 argv = addarg(argv, *cpp);
1178 #ifdef AUTHENTICATION
1179 #if defined(NO_LOGIN_F) && defined(LOGIN_R)
1183 #endif /* AUTHENTICATION */
1189 if (altlogin == NULL) {
1190 altlogin = _PATH_LOGIN;
1192 execv(altlogin, argv);
1194 syslog(LOG_ERR, "%s: %m", altlogin);
1195 fatalperror(net, altlogin);
1200 addarg(char **argv, const char *val)
1206 * 10 entries, a leading length, and a null
1208 argv = (char **)malloc(sizeof(*argv) * 12);
1211 *argv++ = (char *)10;
1214 for (cpp = argv; *cpp; cpp++)
1216 if (cpp == &argv[(long)argv[-1]]) {
1218 *argv = (char *)((long)(*argv) + 10);
1219 argv = (char **)realloc(argv, sizeof(*argv)*((long)(*argv) + 2));
1223 cpp = &argv[(long)argv[-1] - 10];
1225 *cpp++ = strdup(val);
1233 * We only accept the environment variables listed below.
1238 static const char *rej[] = {
1243 static const char *acc[] = {
1244 "XAUTH=", "XAUTHORITY=", "DISPLAY=",
1256 char ** new_environ;
1259 /* Allocate space for scrubbed environment. */
1260 for (count = 1, cpp = environ; *cpp; count++, cpp++)
1262 if ((new_environ = malloc(count * sizeof(char *))) == NULL) {
1267 for (cpp2 = new_environ, cpp = environ; *cpp; cpp++) {
1270 for(p = rej; *p; p++)
1271 if(strncmp(*cpp, *p, strlen(*p)) == 0) {
1278 for(p = acc; *p; p++)
1279 if(strncmp(*cpp, *p, strlen(*p)) == 0)
1282 if ((*cpp2++ = strdup(*cpp)) == NULL) {
1283 environ = new_environ;
1289 environ = new_environ;
1295 * This is the routine to call when we are all through, to
1296 * clean up anything that needs to be cleaned up.
1300 cleanup(int sig __unused)
1303 (void) shutdown(net, SHUT_RDWR);