From b72e252a0180e401fa4d5bd71ab4374f6f6e2735 Mon Sep 17 00:00:00 2001 From: markm Date: Fri, 30 Nov 2001 22:03:20 +0000 Subject: After running a "make unifdef", commit the resultant diffs. This code is now a complete sunset of the crypto (master) code. --- libexec/telnetd/ext.h | 21 +- libexec/telnetd/slc.c | 80 ++--- libexec/telnetd/state.c | 94 +++--- libexec/telnetd/sys_term.c | 772 +++++++-------------------------------------- libexec/telnetd/telnetd.c | 274 ++++------------ libexec/telnetd/telnetd.h | 4 +- libexec/telnetd/termstat.c | 33 +- libexec/telnetd/utility.c | 109 +++---- 8 files changed, 324 insertions(+), 1063 deletions(-) (limited to 'libexec/telnetd') diff --git a/libexec/telnetd/ext.h b/libexec/telnetd/ext.h index 94b2080..e506145 100644 --- a/libexec/telnetd/ext.h +++ b/libexec/telnetd/ext.h @@ -56,9 +56,6 @@ extern int diagnostic; /* telnet diagnostic capabilities */ #ifdef BFTPDAEMON extern int bftpd; /* behave as bftp daemon */ #endif /* BFTPDAEMON */ -#if defined(SecurID) -extern int require_SecurID; -#endif extern slcfun slctab[NSLC + 1]; /* slc mapping table */ @@ -90,12 +87,12 @@ extern int SYNCHing; /* we are in TELNET SYNCH mode */ extern void _termstat P((void)), - add_slc P((int, int, int)), + add_slc P((char, char, cc_t)), check_slc P((void)), - change_slc P((int, int, int)), + change_slc P((char, char, cc_t)), cleanup P((int)), clientstat P((int, int, int)), - copy_termbuf P((char *, int)), + copy_termbuf P((char *, size_t)), deferslc P((void)), defer_terminit P((void)), do_opt_slc P((unsigned char *, int)), @@ -103,8 +100,8 @@ extern void dooption P((int)), dontoption P((int)), edithost P((char *, char *)), - fatal P((int, char *)), - fatalperror P((int, char *)), + fatal P((int, const char *)), + fatalperror P((int, const char *)), get_slc_defaults P((void)), init_env P((void)), init_termbuf P((void)), @@ -114,10 +111,11 @@ extern void netclear P((void)), netflush P((void)), #ifdef DIAGNOSTICS - printoption P((char *, int)), - printdata P((char *, char *, int)), - printsub P((int, unsigned char *, int)), + printoption P((const char *, int)), + printdata P((const char *, char *, int)), + printsub P((char, unsigned char *, int)), #endif + process_slc P((unsigned char, unsigned char, cc_t)), ptyflush P((void)), putchr P((int)), putf P((char *, char *)), @@ -179,6 +177,7 @@ extern void int output_data __P((const char *, ...)) __printflike(1, 2); void output_datalen __P((const char *, int)); +void startslave __P((char *, int, char *)); diff --git a/libexec/telnetd/slc.c b/libexec/telnetd/slc.c index 780adf1..d4eee1a 100644 --- a/libexec/telnetd/slc.c +++ b/libexec/telnetd/slc.c @@ -31,13 +31,13 @@ * SUCH DAMAGE. */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)slc.c 8.2 (Berkeley) 5/30/95"; #endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ #include "telnetd.h" @@ -56,10 +56,10 @@ static unsigned char slcbuf[NSLC*6]; /* buffer for slc negotiation */ * * Write out the current special characters to the client. */ - void -send_slc() +void +send_slc(void) { - register int i; + int i; /* * Send out list of triplets of special characters @@ -80,10 +80,10 @@ send_slc() * * Set pty special characters to all the defaults. */ - void -default_slc() +static void +default_slc(void) { - register int i; + int i; for (i = 1; i <= NSLC; i++) { slctab[i].current.val = slctab[i].defset.val; @@ -105,10 +105,10 @@ default_slc() * * Initialize the slc mapping table. */ - void -get_slc_defaults() +void +get_slc_defaults(void) { - register int i; + int i; init_termbuf(); @@ -127,10 +127,8 @@ get_slc_defaults() * * Add an slc triplet to the slc buffer. */ - void -add_slc(func, flag, val) - register char func, flag; - register cc_t val; +void +add_slc(char func, char flag, cc_t val) { if ((*slcptr++ = (unsigned char)func) == 0xff) @@ -152,9 +150,8 @@ add_slc(func, flag, val) * The parameter getit is non-zero if it is necessary to grab a copy * of the terminal control structures. */ - void -start_slc(getit) - register int getit; +void +start_slc(int getit) { slcchange = 0; @@ -171,11 +168,10 @@ start_slc(getit) * * Finish up the slc negotiation. If something to send, then send it. */ - int -end_slc(bufp) - register unsigned char **bufp; +int +end_slc(unsigned char **bufp) { - register int len; + int len; /* * If a change has occured, store the new terminal control @@ -217,12 +213,10 @@ end_slc(bufp) * * Figure out what to do about the client's slc */ - void -process_slc(func, flag, val) - register unsigned char func, flag; - register cc_t val; +void +process_slc(unsigned char func, unsigned char flag, cc_t val) { - register int hislevel, mylevel, ack; + int hislevel, mylevel, ack; /* * Ensure that we know something about this function @@ -283,12 +277,10 @@ process_slc(func, flag, val) * Process a request to change one of our special characters. * Compare client's request with what we are capable of supporting. */ - void -change_slc(func, flag, val) - register char func, flag; - register cc_t val; +void +change_slc(char func, char flag, cc_t val) { - register int hislevel, mylevel; + int hislevel, mylevel; hislevel = flag & SLC_LEVELBITS; mylevel = slctab[(int)func].defset.flag & SLC_LEVELBITS; @@ -393,10 +385,10 @@ cc_t oldeofc = '\004'; * likely to have changed. If a local change occurs, kick the support level * and flags up to the defaults. */ - void -check_slc() +void +check_slc(void) { - register int i; + int i; for (i = 1; i <= NSLC; i++) { #if defined(USE_TERMIO) && (VEOF == VMIN) @@ -436,14 +428,12 @@ check_slc() * * ptr points to the beginning of the buffer, len is the length. */ - void -do_opt_slc(ptr, len) - register unsigned char *ptr; - register int len; +void +do_opt_slc(unsigned char *ptr, int len) { - register unsigned char func, flag; + unsigned char func, flag; cc_t val; - register unsigned char *end = ptr + len; + unsigned char *end = ptr + len; if (terminit()) { /* go ahead */ while (ptr < end) { @@ -477,8 +467,8 @@ do_opt_slc(ptr, len) * * Do slc stuff that was deferred. */ - void -deferslc() +void +deferslc(void) { if (def_slcbuf) { start_slc(1); diff --git a/libexec/telnetd/state.c b/libexec/telnetd/state.c index 21dbacf..229b6d9 100644 --- a/libexec/telnetd/state.c +++ b/libexec/telnetd/state.c @@ -31,13 +31,13 @@ * SUCH DAMAGE. */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)state.c 8.5 (Berkeley) 5/30/95"; #endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ #include #include "telnetd.h" @@ -83,10 +83,12 @@ unsigned char *subsave; #define TS_DO 7 /* do " */ #define TS_DONT 8 /* dont " */ - void -telrcv() +static void doclientstat(void); + +void +telrcv(void) { - register int c; + int c; static int state = TS_DATA; while (ncc > 0) { @@ -404,9 +406,8 @@ gotiac: switch (c) { * is complete. * */ - void -send_do(option, init) - int option, init; +void +send_do(int option, int init) { if (init) { if ((do_dont_resp[option] == 0 && his_state_is_will(option)) || @@ -428,16 +429,11 @@ send_do(option, init) DIAG(TD_OPTIONS, printoption("td: send do", option)); } -#ifdef LINEMODE -extern void doclientstat(); -#endif - - void -willoption(option) - int option; +void +willoption(int option) { int changeok = 0; - void (*func)() = 0; + void (*func)(void) = 0; /* * process input from peer. @@ -603,9 +599,8 @@ willoption(option) (*func)(); } /* end of willoption */ - void -send_dont(option, init) - int option, init; +void +send_dont(int option, int init) { if (init) { if ((do_dont_resp[option] == 0 && his_state_is_wont(option)) || @@ -619,9 +614,8 @@ send_dont(option, init) DIAG(TD_OPTIONS, printoption("td: send dont", option)); } - void -wontoption(option) - int option; +void +wontoption(int option) { /* * Process client input. @@ -742,9 +736,8 @@ wontoption(option) } /* end of wontoption */ - void -send_will(option, init) - int option, init; +void +send_will(int option, int init) { if (init) { if ((will_wont_resp[option] == 0 && my_state_is_will(option))|| @@ -769,9 +762,8 @@ send_will(option, init) int turn_on_sga = 0; #endif - void -dooption(option) - int option; +void +dooption(int option) { int changeok = 0; @@ -895,9 +887,8 @@ dooption(option) } /* end of dooption */ - void -send_wont(option, init) - int option, init; +void +send_wont(int option, int init) { if (init) { if ((will_wont_resp[option] == 0 && my_state_is_wont(option)) || @@ -911,9 +902,8 @@ send_wont(option, init) DIAG(TD_OPTIONS, printoption("td: send wont", option)); } - void -dontoption(option) - int option; +void +dontoption(int option) { /* * Process client input. @@ -1017,17 +1007,17 @@ int env_ovalue = -1; * Window size * Terminal speed */ - void -suboption() +void +suboption(void) { - register int subchar; + int subchar; DIAG(TD_OPTIONS, {netflush(); printsub('<', subpointer, SB_LEN()+2);}); subchar = SB_GET(); switch (subchar) { case TELOPT_TSPEED: { - register int xspeed, rspeed; + int xspeed, rspeed; if (his_state_is_wont(TELOPT_TSPEED)) /* Ignore if option disabled */ break; @@ -1065,7 +1055,7 @@ suboption() while ((terminaltype < (terminalname + sizeof terminalname-1)) && !SB_EOF()) { - register int c; + int c; c = SB_GET(); if (isupper(c)) { @@ -1079,7 +1069,7 @@ suboption() } /* end of case TELOPT_TTYPE */ case TELOPT_NAWS: { - register int xwinsize, ywinsize; + int xwinsize, ywinsize; if (his_state_is_wont(TELOPT_NAWS)) /* Ignore if option disabled */ break; @@ -1104,7 +1094,7 @@ suboption() #ifdef LINEMODE case TELOPT_LINEMODE: { - register int request; + int request; if (his_state_is_wont(TELOPT_LINEMODE)) /* Ignore if option disabled */ break; @@ -1184,8 +1174,8 @@ suboption() case TELOPT_NEW_ENVIRON: #endif case TELOPT_OLD_ENVIRON: { - register int c; - register char *cp, *varp, *valp; + int c; + char *cp, *varp, *valp; if (SB_EOF()) return; @@ -1216,7 +1206,7 @@ suboption() * reversed. */ if (env_ovar < 0) { - register int last = -1; /* invalid value */ + int last = -1; /* invalid value */ int empty = 0; int got_var = 0, got_value = 0, got_uservar = 0; @@ -1373,20 +1363,20 @@ suboption() } /* end of suboption */ - void -doclientstat() +static void +doclientstat(void) { clientstat(TELOPT_LINEMODE, WILL, 0); } #define ADD(c) *ncp++ = c #define ADD_DATA(c) { *ncp++ = c; if (c == SE || c == IAC) *ncp++ = c; } - void -send_status() +void +send_status(void) { unsigned char statusbuf[256]; - register unsigned char *ncp; - register unsigned char i; + unsigned char *ncp; + unsigned char i; ncp = statusbuf; diff --git a/libexec/telnetd/sys_term.c b/libexec/telnetd/sys_term.c index 282eea0..5fb0b39 100644 --- a/libexec/telnetd/sys_term.c +++ b/libexec/telnetd/sys_term.c @@ -1,4 +1,4 @@ -/* + /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * @@ -31,64 +31,46 @@ * SUCH DAMAGE. */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)sys_term.c 8.4+1 (Berkeley) 5/30/95"; #endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ + +#include +#include +#include +#include +#include #include "telnetd.h" #include "pathnames.h" -extern char *altlogin; -int cleanopen(char *line); +int cleanopen(char *); void scrub_env(void); -#ifdef NEWINIT -#include -#else /* NEWINIT*/ -# ifdef UTMPX -# include -struct utmpx wtmp; -# else -# include struct utmp wtmp; -# endif /* UTMPX */ -# ifndef PARENT_DOES_UTMP #ifdef _PATH_WTMP char wtmpf[] = _PATH_WTMP; #else -char wtmpf[] = "/usr/adm/wtmp"; +char wtmpf[] = "/var/log/wtmp"; #endif #ifdef _PATH_UTMP char utmpf[] = _PATH_UTMP; #else -char utmpf[] = "/etc/utmp"; +char utmpf[] = "/var/run/utmp"; #endif -# else /* PARENT_DOES_UTMP */ -char wtmpf[] = "/etc/wtmp"; -# endif /* PARENT_DOES_UTMP */ - -#include - -#endif /* NEWINIT */ -#ifdef STREAMSPTY -#include -#include -#endif +char *envinit[3]; +extern char **environ; #define SCPYN(a, b) (void) strncpy(a, b, sizeof(a)) #define SCMPN(a, b) strncmp(a, b, sizeof(a)) -#ifdef STREAMS -#include -#endif -#include #ifdef t_erase #undef t_erase #undef t_kill @@ -119,9 +101,6 @@ struct termbuf { # define cfgetospeed(tp) (tp)->sg.sg_ospeed # define cfgetispeed(tp) (tp)->sg.sg_ispeed #else /* USE_TERMIO */ -# ifdef SYSV_TERMIO -# define termios termio -# endif # ifndef TCSANOW # ifdef TCSETS # define TCSANOW TCSETS @@ -153,9 +132,6 @@ struct termbuf { # endif # endif /* TCSANOW */ struct termios termbuf, termbuf2; /* pty control structure */ -# ifdef STREAMSPTY -int ttyfd = -1; -# endif #endif /* USE_TERMIO */ #include @@ -163,6 +139,7 @@ int ttyfd = -1; int cleanopen __P((char *)); void scrub_env __P((void)); +static char **addarg __P((char **, const char *)); /* * init_termbuf() @@ -175,8 +152,8 @@ void scrub_env __P((void)); * set_termbuf() writes the structure into the kernel. */ - void -init_termbuf() +void +init_termbuf(void) { #ifndef USE_TERMIO (void) ioctl(pty, TIOCGETP, (char *)&termbuf.sg); @@ -186,20 +163,14 @@ init_termbuf() (void) ioctl(pty, TIOCGSTATE, (char *)&termbuf.state); # endif #else -# ifdef STREAMSPTY - (void) tcgetattr(ttyfd, &termbuf); -# else (void) tcgetattr(pty, &termbuf); -# endif #endif termbuf2 = termbuf; } #if defined(LINEMODE) && defined(TIOCPKT_IOCTL) - void -copy_termbuf(cp, len) - char *cp; - int len; +void +copy_termbuf(char *cp, size_t len) { if (len > sizeof(termbuf)) len = sizeof(termbuf); @@ -208,8 +179,8 @@ copy_termbuf(cp, len) } #endif /* defined(LINEMODE) && defined(TIOCPKT_IOCTL) */ - void -set_termbuf() +void +set_termbuf(void) { /* * Only make the necessary changes. @@ -228,11 +199,7 @@ set_termbuf() (void) ioctl(pty, TIOCLSET, (char *)&termbuf.lflags); #else /* USE_TERMIO */ if (memcmp((char *)&termbuf, (char *)&termbuf2, sizeof(termbuf))) -# ifdef STREAMSPTY - (void) tcsetattr(ttyfd, TCSANOW, &termbuf); -# else (void) tcsetattr(pty, TCSANOW, &termbuf); -# endif #endif /* USE_TERMIO */ } @@ -249,11 +216,8 @@ set_termbuf() */ #ifndef USE_TERMIO - int -spcset(func, valp, valpp) - int func; - cc_t *valp; - cc_t **valpp; +int +spcset(int func, cc_t *valp, cc_t **valpp) { switch(func) { case SLC_EOF: @@ -324,18 +288,15 @@ spcset(func, valp, valpp) #else /* USE_TERMIO */ - int -spcset(func, valp, valpp) - int func; - cc_t *valp; - cc_t **valpp; -{ #define setval(a, b) *valp = termbuf.c_cc[a]; \ *valpp = &termbuf.c_cc[a]; \ return(b); #define defval(a) *valp = ((cc_t)a); *valpp = (cc_t *)0; return(SLC_DEFAULT); +int +spcset(int func, cc_t *valp, cc_t **valpp) +{ switch(func) { case SLC_EOF: setval(VEOF, SLC_VARIABLE); @@ -420,7 +381,6 @@ spcset(func, valp, valpp) } #endif /* USE_TERMIO */ -#ifndef convex /* * getpty() * @@ -429,28 +389,16 @@ spcset(func, valp, valpp) * * Returns the file descriptor of the opened pty. */ +char alpha[] = "0123456789abcdefghijklmnopqrstuv"; char line[16]; - int -getpty(ptynum) -int *ptynum; +int +getpty(int *ptynum __unused) { - register int p; -#ifdef STREAMSPTY - int t; - char *ptsname(); - - p = open("/dev/ptmx", 2); - if (p > 0) { - grantpt(p); - unlockpt(p); - strcpy(line, ptsname(p)); - return(p); - } - -#else /* ! STREAMSPTY */ - register char *cp, *p1, *p2; - register int i; + int p; + const char *cp; + char *p1, *p2; + int i; (void) strcpy(line, _PATH_DEV); (void) strcat(line, "ptyXX"); @@ -470,7 +418,7 @@ int *ptynum; if (stat(line, &stb) < 0) break; for (i = 0; i < 32; i++) { - *p2 = "0123456789abcdefghijklmnopqrstuv"[i]; + *p2 = alpha[i]; p = open(line, 2); if (p > 0) { line[5] = 't'; @@ -480,10 +428,8 @@ int *ptynum; } } } -#endif /* STREAMSPTY */ return(-1); } -#endif /* convex */ #ifdef LINEMODE /* @@ -507,38 +453,24 @@ int *ptynum; * tty_rspeed(val) Set receive speed to val. */ -#ifdef convex -static int linestate; -#endif - int -tty_linemode() +int +tty_linemode(void) { -#ifndef convex #ifndef USE_TERMIO return(termbuf.state & TS_EXTPROC); #else return(termbuf.c_lflag & EXTPROC); #endif -#else - return(linestate); -#endif } - void -tty_setlinemode(on) - int on; +void +tty_setlinemode(int on) { #ifdef TIOCEXT -# ifndef convex set_termbuf(); -# else - linestate = on; -# endif (void) ioctl(pty, TIOCEXT, (char *)&on); -# ifndef convex init_termbuf(); -# endif #else /* !TIOCEXT */ # ifdef EXTPROC if (on) @@ -550,8 +482,8 @@ tty_setlinemode(on) } #endif /* LINEMODE */ - int -tty_isecho() +int +tty_isecho(void) { #ifndef USE_TERMIO return (termbuf.sg.sg_flags & ECHO); @@ -560,8 +492,8 @@ tty_isecho() #endif } - int -tty_flowmode() +int +tty_flowmode(void) { #ifndef USE_TERMIO return(((termbuf.tc.t_startc) > 0 && (termbuf.tc.t_stopc) > 0) ? 1 : 0); @@ -570,8 +502,8 @@ tty_flowmode() #endif } - int -tty_restartany() +int +tty_restartany(void) { #ifndef USE_TERMIO # ifdef DECCTQ @@ -584,9 +516,8 @@ tty_restartany() #endif } - void -tty_setecho(on) - int on; +void +tty_setecho(int on) { #ifndef USE_TERMIO if (on) @@ -601,8 +532,8 @@ tty_setecho(on) #endif } - int -tty_israw() +int +tty_israw(void) { #ifndef USE_TERMIO return(termbuf.sg.sg_flags & RAW); @@ -612,9 +543,8 @@ tty_israw() } - void -tty_binaryin(on) - int on; +void +tty_binaryin(int on) { #ifndef USE_TERMIO if (on) @@ -630,9 +560,8 @@ tty_binaryin(on) #endif } - void -tty_binaryout(on) - int on; +void +tty_binaryout(int on) { #ifndef USE_TERMIO if (on) @@ -652,8 +581,8 @@ tty_binaryout(on) #endif } - int -tty_isbinaryin() +int +tty_isbinaryin(void) { #ifndef USE_TERMIO return(termbuf.lflags & LPASS8); @@ -662,8 +591,8 @@ tty_isbinaryin() #endif } - int -tty_isbinaryout() +int +tty_isbinaryout(void) { #ifndef USE_TERMIO return(termbuf.lflags & LLITOUT); @@ -673,8 +602,8 @@ tty_isbinaryout() } #ifdef LINEMODE - int -tty_isediting() +int +tty_isediting(void) { #ifndef USE_TERMIO return(!(termbuf.sg.sg_flags & (CBREAK|RAW))); @@ -683,8 +612,8 @@ tty_isediting() #endif } - int -tty_istrapsig() +int +tty_istrapsig(void) { #ifndef USE_TERMIO return(!(termbuf.sg.sg_flags&RAW)); @@ -693,9 +622,8 @@ tty_istrapsig() #endif } - void -tty_setedit(on) - int on; +void +tty_setedit(int on) { #ifndef USE_TERMIO if (on) @@ -710,9 +638,8 @@ tty_setedit(on) #endif } - void -tty_setsig(on) - int on; +void +tty_setsig(int on) { #ifndef USE_TERMIO if (on) @@ -726,8 +653,8 @@ tty_setsig(on) } #endif /* LINEMODE */ - int -tty_issofttab() +int +tty_issofttab(void) { #ifndef USE_TERMIO return (termbuf.sg.sg_flags & XTABS); @@ -741,9 +668,8 @@ tty_issofttab() #endif } - void -tty_setsofttab(on) - int on; +void +tty_setsofttab(int on) { #ifndef USE_TERMIO if (on) @@ -771,8 +697,8 @@ tty_setsofttab(on) #endif } - int -tty_islitecho() +int +tty_islitecho(void) { #ifndef USE_TERMIO return (!(termbuf.lflags & LCTLECH)); @@ -789,9 +715,8 @@ tty_islitecho() #endif } - void -tty_setlitecho(on) - int on; +void +tty_setlitecho(int on) { #ifndef USE_TERMIO if (on) @@ -814,8 +739,8 @@ tty_setlitecho(on) #endif } - int -tty_iscrnl() +int +tty_iscrnl(void) { #ifndef USE_TERMIO return (termbuf.sg.sg_flags & CRMOD); @@ -874,12 +799,11 @@ struct termspeeds { }; #endif /* DECODE_BAUD */ - void -tty_tspeed(val) - int val; +void +tty_tspeed(int val) { #ifdef DECODE_BAUD - register struct termspeeds *tp; + struct termspeeds *tp; for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++) ; @@ -891,12 +815,11 @@ tty_tspeed(val) #endif /* DECODE_BAUD */ } - void -tty_rspeed(val) - int val; +void +tty_rspeed(int val) { #ifdef DECODE_BAUD - register struct termspeeds *tp; + struct termspeeds *tp; for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++) ; @@ -908,42 +831,16 @@ tty_rspeed(val) #endif /* DECODE_BAUD */ } -#ifdef PARENT_DOES_UTMP -# ifndef NEWINIT -extern struct utmp wtmp; -extern char wtmpf[]; -# else /* NEWINIT */ -int gotalarm; - - /* ARGSUSED */ - void -nologinproc(sig) - int sig; -{ - gotalarm++; -} -# endif /* NEWINIT */ -#endif /* PARENT_DOES_UTMP */ - -#ifndef NEWINIT -# ifdef PARENT_DOES_UTMP -extern void utmp_sig_init P((void)); -extern void utmp_sig_reset P((void)); -extern void utmp_sig_wait P((void)); -extern void utmp_sig_notify P((int)); -# endif /* PARENT_DOES_UTMP */ -#endif - /* * getptyslave() * * Open the slave side of the pty, and do any initialization * that is necessary. */ - void -getptyslave() +static void +getptyslave(void) { - register int t = -1; + int t = -1; char erase; # ifdef LINEMODE @@ -980,31 +877,10 @@ getptyslave() } # endif - -# ifdef PARENT_DOES_UTMP - /* - * Wait for our parent to get the utmp stuff to get done. - */ - utmp_sig_wait(); -# endif - t = cleanopen(line); if (t < 0) fatalperror(net, line); -#ifdef STREAMSPTY -#ifdef USE_TERMIO - ttyfd = t; -#endif - if (ioctl(t, I_PUSH, "ptem") < 0) - fatal(net, "I_PUSH ptem"); - if (ioctl(t, I_PUSH, "ldterm") < 0) - fatal(net, "I_PUSH ldterm"); - if (ioctl(t, I_PUSH, "ttcompat") < 0) - fatal(net, "I_PUSH ttcompat"); - if (ioctl(pty, I_PUSH, "pckt") < 0) - fatal(net, "I_PUSH pckt"); -#endif /* * set up the tty modes as we like them to be. @@ -1031,15 +907,6 @@ getptyslave() * systems, other than 4.4BSD. In 4.4BSD the * kernel does the initial terminal setup. */ -# if defined(USE_TERMIO) && (BSD <= 43) -# ifndef OXTABS -# define OXTABS 0 -# endif - termbuf.c_lflag |= ECHO; - termbuf.c_oflag |= ONLCR|OXTABS; - termbuf.c_iflag |= ICRNL; - termbuf.c_iflag &= ~IXOFF; -# endif /* defined(USE_TERMIO) && (BSD <= 43) */ tty_rspeed((def_rspeed > 0) ? def_rspeed : 9600); tty_tspeed((def_tspeed > 0) ? def_tspeed : 9600); if (erase) @@ -1057,10 +924,6 @@ getptyslave() fatalperror(net, "login_tty"); if (net > 2) (void) close(net); - if (pty > 2) { - (void) close(pty); - pty = -1; - } } #ifndef O_NOCTTY @@ -1070,90 +933,28 @@ getptyslave() * Open the specified slave side of the pty, * making sure that we have a clean tty. */ - int -cleanopen(line) - char *line; +int +cleanopen(char *li) { - register int t; + int t; -#ifndef STREAMSPTY /* * Make sure that other people can't open the * slave side of the connection. */ - (void) chown(line, 0, 0); - (void) chmod(line, 0600); -#endif + (void) chown(li, 0, 0); + (void) chmod(li, 0600); - (void) revoke(line); + (void) revoke(li); t = open(line, O_RDWR|O_NOCTTY); if (t < 0) return(-1); - /* - * Hangup anybody else using this ttyp, then reopen it for - * ourselves. - */ -# if (BSD <= 43) && !defined(STREAMSPTY) - (void) signal(SIGHUP, SIG_IGN); - vhangup(); - (void) signal(SIGHUP, SIG_DFL); - t = open(line, O_RDWR|O_NOCTTY); - if (t < 0) - return(-1); -# endif return(t); } -#if BSD <= 43 - - int -login_tty(t) - int t; -{ - if (setsid() < 0) { -#ifdef ultrix - /* - * The setsid() may have failed because we - * already have a pgrp == pid. Zero out - * our pgrp and try again... - */ - if ((setpgrp(0, 0) < 0) || (setsid() < 0)) -#endif - fatalperror(net, "setsid()"); - } -# ifdef TIOCSCTTY - if (ioctl(t, TIOCSCTTY, (char *)0) < 0) - fatalperror(net, "ioctl(sctty)"); -# else - /* - * We get our controlling tty assigned as a side-effect - * of opening up a tty device. But on BSD based systems, - * this only happens if our process group is zero. The - * setsid() call above may have set our pgrp, so clear - * it out before opening the tty... - */ - (void) setpgrp(0, 0); - close(open(line, O_RDWR)); -# endif - if (t != 0) - (void) dup2(t, 0); - if (t != 1) - (void) dup2(t, 1); - if (t != 2) - (void) dup2(t, 2); - if (t > 2) - close(t); - return(0); -} -#endif /* BSD <= 43 */ - -#ifdef NEWINIT -char *gen_id = "fe"; -#endif - /* * startslave(host) * @@ -1162,124 +963,26 @@ char *gen_id = "fe"; */ /* ARGSUSED */ - void -startslave(host, autologin, autoname) - char *host; - int autologin; - char *autoname; +void +startslave(char *host, int autologin, char *autoname) { - register int i; -#ifdef NEWINIT - extern char *ptyip; - struct init_request request; - void nologinproc(); - register int n; -#endif /* NEWINIT */ + int i; -#ifndef NEWINIT -# ifdef PARENT_DOES_UTMP - utmp_sig_init(); -# endif /* PARENT_DOES_UTMP */ if ((i = fork()) < 0) fatalperror(net, "fork"); if (i) { -# ifdef PARENT_DOES_UTMP - /* - * Cray parent will create utmp entry for child and send - * signal to child to tell when done. Child waits for signal - * before doing anything important. - */ - register int pid = i; - void sigjob P((int)); - - setpgrp(); - utmp_sig_reset(); /* reset handler to default */ - /* - * Create utmp entry for child - */ - (void) time(&wtmp.ut_time); - wtmp.ut_type = LOGIN_PROCESS; - wtmp.ut_pid = pid; - SCPYN(wtmp.ut_user, "LOGIN"); - SCPYN(wtmp.ut_host, host); - SCPYN(wtmp.ut_line, line + sizeof(_PATH_DEV) - 1); - SCPYN(wtmp.ut_id, wtmp.ut_line+3); - pututline(&wtmp); - endutent(); - if ((i = open(wtmpf, O_WRONLY|O_APPEND)) >= 0) { - (void) write(i, (char *)&wtmp, sizeof(struct utmp)); - (void) close(i); - } - utmp_sig_notify(pid); -# endif /* PARENT_DOES_UTMP */ } else { - getptyslave(autologin); + getptyslave(); start_login(host, autologin, autoname); /*NOTREACHED*/ } -#else /* NEWINIT */ - - /* - * Init will start up login process if we ask nicely. We only wait - * for it to start up and begin normal telnet operation. - */ - if ((i = open(INIT_FIFO, O_WRONLY)) < 0) { - char tbuf[128]; - (void) snprintf(tbuf, sizeof(tbuf), "Can't open %s\n", INIT_FIFO); - fatalperror(net, tbuf); - } - memset((char *)&request, 0, sizeof(request)); - request.magic = INIT_MAGIC; - SCPYN(request.gen_id, gen_id); - SCPYN(request.tty_id, &line[8]); - SCPYN(request.host, host); - SCPYN(request.term_type, terminaltype ? terminaltype : "network"); - request.signal = SIGCLD; - request.pid = getpid(); -#ifdef BFTPDAEMON - /* - * Are we working as the bftp daemon? - */ - if (bftpd) { - SCPYN(request.exec_name, BFTPPATH); - } -#endif /* BFTPDAEMON */ - if (write(i, (char *)&request, sizeof(request)) < 0) { - char tbuf[128]; - (void) snprintf(tbuf, sizeof(tbuf), "Can't write to %s\n", INIT_FIFO); - fatalperror(net, tbuf); - } - (void) close(i); - (void) signal(SIGALRM, nologinproc); - for (i = 0; ; i++) { - char tbuf[128]; - alarm(15); - n = read(pty, ptyip, BUFSIZ); - if (i == 3 || n >= 0 || !gotalarm) - break; - gotalarm = 0; - snprintf(tbuf, sizeof(tbuf), "telnetd: waiting for /etc/init to start login process on %s\r\n", line); - (void) write(net, tbuf, strlen(tbuf)); - } - if (n < 0 && gotalarm) - fatal(net, "/etc/init didn't start login process"); - pcc += n; - alarm(0); - (void) signal(SIGALRM, SIG_DFL); - - return; -#endif /* NEWINIT */ } -char *envinit[3]; -extern char **environ; - - void -init_env() +void +init_env(void) { - extern char *getenv(); char **envp; envp = envinit; @@ -1289,7 +992,6 @@ init_env() environ = envinit; } -#ifndef NEWINIT /* * start_login(host) @@ -1298,42 +1000,12 @@ init_env() * function will turn us into the login process. */ - void -start_login(host, autologin, name) - char *host; - int autologin; - char *name; -{ - register char **argv; - char **addarg(), *user; - extern char *getenv(); -#ifdef UTMPX - register int pid = getpid(); - struct utmpx utmpx; -#endif -#ifdef SOLARIS - char *term; - char termbuf[64]; -#endif +#define undef1 __unused -#ifdef UTMPX - /* - * Create utmp entry for child - */ - - memset(&utmpx, 0, sizeof(utmpx)); - SCPYN(utmpx.ut_user, ".telnet"); - SCPYN(utmpx.ut_line, line + sizeof(_PATH_DEV) - 1); - utmpx.ut_pid = pid; - utmpx.ut_id[0] = 't'; - utmpx.ut_id[1] = 'n'; - utmpx.ut_id[2] = SC_WILDC; - utmpx.ut_id[3] = SC_WILDC; - utmpx.ut_type = LOGIN_PROCESS; - (void) time(&utmpx.ut_tv.tv_sec); - if (makeutx(&utmpx) == NULL) - fatal(net, "makeutx failed"); -#endif +void +start_login(char *host undef1, int autologin undef1, char *name undef1) +{ + char **argv; scrub_env(); @@ -1348,25 +1020,6 @@ start_login(host, autologin, name) argv = addarg(0, "login"); #if !defined(NO_LOGIN_H) - - { - argv = addarg(argv, "-h"); - argv = addarg(argv, host); -#ifdef SOLARIS - /* - * SVR4 version of -h takes TERM= as second arg, or - - */ - term = getenv("TERM"); - if (term == NULL || term[0] == 0) { - term = "-"; - } else { - strcpy(termbuf, "TERM="); - strncat(termbuf, term, sizeof(termbuf) - 6); - term = termbuf; - } - argv = addarg(argv, term); -#endif - } #endif #if !defined(NO_LOGIN_P) argv = addarg(argv, "-p"); @@ -1394,20 +1047,12 @@ start_login(host, autologin, name) argv = addarg(argv, BFTPPATH); } else #endif -#if defined (SecurID) - /* - * don't worry about the -f that might get sent. - * A -s is supposed to override it anyhow. - */ - if (require_SecurID) - argv = addarg(argv, "-s"); -#endif if (getenv("USER")) { argv = addarg(argv, "--"); argv = addarg(argv, getenv("USER")); #if defined(LOGIN_ARGS) && defined(NO_LOGIN_P) { - register char **cpp; + char **cpp; for (cpp = environ; *cpp; cpp++) argv = addarg(argv, *cpp); } @@ -1424,16 +1069,6 @@ start_login(host, autologin, name) */ unsetenv("USER"); } -#ifdef SOLARIS - else { - char **p; - - argv = addarg(argv, ""); /* no login name */ - for (p = environ; *p; p++) { - argv = addarg(argv, *p); - } - } -#endif /* SOLARIS */ closelog(); if (altlogin == NULL) { @@ -1446,12 +1081,10 @@ start_login(host, autologin, name) /*NOTREACHED*/ } - char ** -addarg(argv, val) - register char **argv; - register char *val; +static char ** +addarg(char **argv, const char *val) { - register char **cpp; + char **cpp; if (argv == NULL) { /* @@ -1474,26 +1107,25 @@ addarg(argv, val) argv++; cpp = &argv[(int)argv[-1] - 10]; } - *cpp++ = val; + *cpp++ = strdup(val); *cpp = 0; return(argv); } -#endif /* NEWINIT */ /* * scrub_env() * * We only accept the environment variables listed below. */ - void -scrub_env() +void +scrub_env(void) { - static const char *reject[] = { + static const char *rej[] = { "TERMCAP=/", NULL }; - static const char *accept[] = { + static const char *acc[] = { "XAUTH=", "XAUTHORITY=", "DISPLAY=", "TERM=", "EDITOR=", @@ -1510,7 +1142,7 @@ scrub_env() for (cpp2 = cpp = environ; *cpp; cpp++) { int reject_it = 0; - for(p = reject; *p; p++) + for(p = rej; *p; p++) if(strncmp(*cpp, *p, strlen(*p)) == 0) { reject_it = 1; break; @@ -1518,7 +1150,7 @@ scrub_env() if (reject_it) continue; - for(p = accept; *p; p++) + for(p = acc; *p; p++) if(strncmp(*cpp, *p, strlen(*p)) == 0) break; if(*p != NULL) @@ -1533,13 +1165,10 @@ scrub_env() * This is the routine to call when we are all through, to * clean up anything that needs to be cleaned up. */ - /* ARGSUSED */ - void -cleanup(sig) - int sig; +/* ARGSUSED */ +void +cleanup(int sig __unused) { -#ifndef PARENT_DOES_UTMP -# if (BSD > 43) || defined(convex) char *p; p = line + sizeof(_PATH_DEV) - 1; @@ -1552,173 +1181,4 @@ cleanup(sig) (void)chown(line, 0, 0); (void) shutdown(net, 2); exit(1); -# else - void rmut(); - - rmut(); - vhangup(); /* XXX */ - (void) shutdown(net, 2); - exit(1); -# endif -#else /* PARENT_DOES_UTMP */ -# ifdef NEWINIT - (void) shutdown(net, 2); - exit(1); -# else /* NEWINIT */ - rmut(line); - close(pty); - (void) shutdown(net, 2); - exit(1); -# endif /* NEWINT */ -#endif /* PARENT_DOES_UTMP */ -} - -#if defined(PARENT_DOES_UTMP) && !defined(NEWINIT) -/* - * _utmp_sig_rcv - * utmp_sig_init - * utmp_sig_wait - * These three functions are used to coordinate the handling of - * the utmp file between the server and the soon-to-be-login shell. - * The server actually creates the utmp structure, the child calls - * utmp_sig_wait(), until the server calls utmp_sig_notify() and - * signals the future-login shell to proceed. - */ -static int caught=0; /* NZ when signal intercepted */ -static void (*func)(); /* address of previous handler */ - - void -_utmp_sig_rcv(sig) - int sig; -{ - caught = 1; - (void) signal(SIGUSR1, func); } - - void -utmp_sig_init() -{ - /* - * register signal handler for UTMP creation - */ - if ((int)(func = signal(SIGUSR1, _utmp_sig_rcv)) == -1) - fatalperror(net, "telnetd/signal"); -} - - void -utmp_sig_reset() -{ - (void) signal(SIGUSR1, func); /* reset handler to default */ -} - - void -utmp_sig_wait() -{ - /* - * Wait for parent to write our utmp entry. - */ - sigoff(); - while (caught == 0) { - pause(); /* wait until we get a signal (sigon) */ - sigoff(); /* turn off signals while we check caught */ - } - sigon(); /* turn on signals again */ -} - - void -utmp_sig_notify(pid) -{ - kill(pid, SIGUSR1); -} - -#endif /* defined(PARENT_DOES_UTMP) && !defined(NEWINIT) */ - -/* - * rmut() - * - * This is the function called by cleanup() to - * remove the utmp entry for this person. - */ - -#ifdef UTMPX - void -rmut() -{ - register f; - int found = 0; - struct utmp *u, *utmp; - int nutmp; - struct stat statbf; - - struct utmpx *utxp, utmpx; - - /* - * This updates the utmpx and utmp entries and make a wtmp/x entry - */ - - SCPYN(utmpx.ut_line, line + sizeof(_PATH_DEV) - 1); - utxp = getutxline(&utmpx); - if (utxp) { - utxp->ut_type = DEAD_PROCESS; - utxp->ut_exit.e_termination = 0; - utxp->ut_exit.e_exit = 0; - (void) time(&utmpx.ut_tv.tv_sec); - utmpx.ut_tv.tv_usec = 0; - modutx(utxp); - } - endutxent(); -} /* end of rmut */ -#endif - -#if !defined(UTMPX) && BSD <= 43 - void -rmut() -{ - register f; - int found = 0; - struct utmp *u, *utmp; - int nutmp; - struct stat statbf; - - f = open(utmpf, O_RDWR); - if (f >= 0) { - (void) fstat(f, &statbf); - utmp = (struct utmp *)malloc((unsigned)statbf.st_size); - if (!utmp) - syslog(LOG_ERR, "utmp malloc failed"); - if (statbf.st_size && utmp) { - nutmp = read(f, (char *)utmp, (int)statbf.st_size); - nutmp /= sizeof(struct utmp); - - for (u = utmp ; u < &utmp[nutmp] ; u++) { - if (SCMPN(u->ut_line, line+5) || - u->ut_name[0]==0) - continue; - (void) lseek(f, ((long)u)-((long)utmp), L_SET); - SCPYN(u->ut_name, ""); - SCPYN(u->ut_host, ""); - (void) time(&u->ut_time); - (void) write(f, (char *)u, sizeof(wtmp)); - found++; - } - } - (void) close(f); - } - if (found) { - f = open(wtmpf, O_WRONLY|O_APPEND); - if (f >= 0) { - SCPYN(wtmp.ut_line, line+5); - SCPYN(wtmp.ut_name, ""); - SCPYN(wtmp.ut_host, ""); - (void) time(&wtmp.ut_time); - (void) write(f, (char *)&wtmp, sizeof(wtmp)); - (void) close(f); - } - } - (void) chmod(line, 0666); - (void) chown(line, 0, 0); - line[strlen(_PATH_DEV)] = 'p'; - (void) chmod(line, 0666); - (void) chown(line, 0, 0); -} /* end of rmut */ -#endif diff --git a/libexec/telnetd/telnetd.c b/libexec/telnetd/telnetd.c index f25eced..887002e 100644 --- a/libexec/telnetd/telnetd.c +++ b/libexec/telnetd/telnetd.c @@ -31,59 +31,32 @@ * SUCH DAMAGE. */ -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1989, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ +#include + +__FBSDID("$FreeBSD$"); #ifndef lint -#if 0 static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95"; #endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ #include "telnetd.h" #include "pathnames.h" -#include -#include - #include +#include #include #include +#include #include -#if defined(SecurID) -int require_SecurID = 0; -#endif +#include + +#include char remote_hostname[MAXHOSTNAMELEN]; -int utmp_len = sizeof(remote_hostname) - 1; +size_t utmp_len = sizeof(remote_hostname) - 1; int registerd_host_only = 0; -#ifdef STREAMSPTY -# include -# include -/* make sure we don't get the bsd version */ -# include "/usr/include/sys/tty.h" -# include - -/* - * Because of the way ptyibuf is used with streams messages, we need - * ptyibuf+1 to be on a full-word boundary. The following weirdness - * is simply to make that happen. - */ -long ptyibufbuf[BUFSIZ/sizeof(long)+1]; -char *ptyibuf = ((char *)&ptyibufbuf[1])-1; -char *ptyip = ((char *)&ptyibufbuf[1])-1; -char ptyibuf2[BUFSIZ]; -unsigned char ctlbuf[BUFSIZ]; -struct strbuf strbufc, strbufd; - -#else /* ! STREAMPTY */ /* * I/O data buffers, @@ -92,25 +65,21 @@ struct strbuf strbufc, strbufd; char ptyibuf[BUFSIZ], *ptyip = ptyibuf; char ptyibuf2[BUFSIZ]; -# include - -int readstream(int p, char *ibuf, int bufsize); -void doit(struct sockaddr *who); -int terminaltypeok(char *s); -void startslave(char *host, int autologin, char *autoname); - -#endif /* ! STREAMPTY */ +int readstream(int, char *, int); +void doit(struct sockaddr *); +int terminaltypeok(char *); int hostinfo = 1; /* do we print login banner? */ int debug = 0; int keepalive = 1; -char *altlogin; +const char *altlogin; void doit __P((struct sockaddr *)); int terminaltypeok __P((char *)); void startslave __P((char *, int, char *)); extern void usage P((void)); +static void _gettermname __P((void)); /* * The string to pass to getopt(). We do it this way so @@ -129,21 +98,29 @@ char valid_opts[] = { #ifdef LINEMODE 'l', #endif -#ifdef SecurID - 's', -#endif '\0' }; int family = AF_INET; +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 256 +#endif /* MAXHOSTNAMELEN */ + +char *hostname; +char host_name[MAXHOSTNAMELEN]; + +extern void telnet P((int, int, char *)); + +int level; +char user_name[256]; + int -main(argc, argv) - char *argv[]; +main(int argc, char *argv[]) { struct sockaddr_storage from; int on = 1, fromlen; - register int ch; + int ch; #if defined(IPPROTO_IP) && defined(IP_TOS) int tos = -1; #endif @@ -236,12 +213,6 @@ main(argc, argv) altlogin = optarg; break; -#ifdef SecurID - case 's': - /* SecurID required */ - require_SecurID = 1; - break; -#endif /* SecurID */ case 'S': #ifdef HAS_GETTOS if ((tos = parsetos(optarg, "tcp")) < 0) @@ -254,9 +225,7 @@ main(argc, argv) break; case 'u': - utmp_len = atoi(optarg); - if (utmp_len < 0) - utmp_len = -utmp_len; + utmp_len = (size_t)atoi(optarg); if (utmp_len >= sizeof(remote_hostname)) utmp_len = sizeof(remote_hostname) - 1; break; @@ -290,7 +259,7 @@ main(argc, argv) if (debug) { int s, ns, foo, error; - char *service = "telnet"; + const char *service = "telnet"; struct addrinfo hints, *res; if (argc > 1) { @@ -392,9 +361,6 @@ usage() #endif fprintf(stderr, " [-n]"); fprintf(stderr, "\n\t"); -#ifdef SecurID - fprintf(stderr, " [-s]"); -#endif #ifdef HAS_GETTOS fprintf(stderr, " [-S tos]"); #endif @@ -413,12 +379,13 @@ static unsigned char ttytype_sbbuf[] = { IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE }; - int -getterminaltype(name) - char *name; + +#define undef2 __unused + +static int +getterminaltype(char *name undef2) { int retval = -1; - void _gettermname(); settimer(baseline); @@ -533,8 +500,8 @@ getterminaltype(name) return(retval); } /* end of getterminaltype */ - void -_gettermname() +static void +_gettermname(void) { /* * If the client turned off the option, @@ -551,9 +518,8 @@ _gettermname() ttloop(); } - int -terminaltypeok(s) - char *s; +int +terminaltypeok(char *s) { char buf[1024]; @@ -572,25 +538,13 @@ terminaltypeok(s) return(1); } -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 256 -#endif /* MAXHOSTNAMELEN */ - -char *hostname; -char host_name[MAXHOSTNAMELEN]; - -extern void telnet P((int, int, char *)); - -int level; -char user_name[256]; /* * Get a pty, scan input lines. */ - void -doit(who) - struct sockaddr *who; +void +doit(struct sockaddr *who) { - int err; + int err_; /* XXX */ int ptynum; /* @@ -624,10 +578,10 @@ doit(who) trimdomain(remote_hostname, UT_HOSTSIZE); if (!isdigit(remote_hostname[0]) && strlen(remote_hostname) > utmp_len) - err = getnameinfo(who, who->sa_len, remote_hostname, + err_ = getnameinfo(who, who->sa_len, remote_hostname, sizeof(remote_hostname), NULL, 0, NI_NUMERICHOST|NI_WITHSCOPEID); - /* XXX: do 'err' check */ + /* XXX: do 'err_' check */ (void) gethostname(host_name, sizeof(host_name) - 1); host_name[sizeof(host_name) - 1] = '\0'; @@ -651,10 +605,8 @@ doit(who) * Main loop. Select from pty and network, and * hand data to telnet receiver finite state machine. */ - void -telnet(f, p, host) - int f, p; - char *host; +void +telnet(int f, int p, char *host) { int on = 1; #define TABBUFSIZ 512 @@ -761,12 +713,10 @@ telnet(f, p, host) if (my_state_is_wont(TELOPT_ECHO)) send_will(TELOPT_ECHO, 1); -#ifndef STREAMSPTY /* * Turn on packet mode */ (void) ioctl(p, TIOCPKT, (char *)&on); -#endif #if defined(LINEMODE) && defined(KLUDGELINEMODE) /* @@ -808,7 +758,7 @@ telnet(f, p, host) #ifdef TIOCNOTTY { - register int t; + int t; t = open(_PATH_TTY, O_RDWR); if (t >= 0) { (void) ioctl(t, TIOCNOTTY, (char *)0); @@ -826,7 +776,6 @@ telnet(f, p, host) */ if (getent(defent, "default") == 1) { - char *Getstr(); char *cp=defstrs; HE = Getstr("he", &cp); @@ -835,9 +784,9 @@ telnet(f, p, host) if (HN && *HN) (void) strlcpy(host_name, HN, sizeof(host_name)); if (IM == 0) - IM = ""; + IM = strdup(""); } else { - IM = DEFAULT_IM; + IM = strdup(DEFAULT_IM); HE = 0; } edithost(HE, host_name); @@ -868,7 +817,7 @@ telnet(f, p, host) nfd = ((f > p) ? f : p) + 1; for (;;) { fd_set ibits, obits, xbits; - register int c; + int c; if (ncc < 0 && pcc < 0) break; @@ -989,11 +938,7 @@ telnet(f, p, host) * Something to read from the pty... */ if (FD_ISSET(p, &ibits)) { -#ifndef STREAMSPTY pcc = read(p, ptyibuf, BUFSIZ); -#else - pcc = readstream(p, ptyibuf, BUFSIZ); -#endif /* * On some systems, if we try to read something * off the master side before the slave side is @@ -1088,114 +1033,16 @@ telnet(f, p, host) # endif #endif -#ifdef STREAMSPTY - -int flowison = -1; /* current state of flow: -1 is unknown */ - -int readstream(p, ibuf, bufsize) - int p; - char *ibuf; - int bufsize; -{ - int flags = 0; - int ret = 0; - struct termios *tsp; - struct termio *tp; - struct iocblk *ip; - char vstop, vstart; - int ixon; - int newflow; - - strbufc.maxlen = BUFSIZ; - strbufc.buf = (char *)ctlbuf; - strbufd.maxlen = bufsize-1; - strbufd.len = 0; - strbufd.buf = ibuf+1; - ibuf[0] = 0; - - ret = getmsg(p, &strbufc, &strbufd, &flags); - if (ret < 0) /* error of some sort -- probably EAGAIN */ - return(-1); - - if (strbufc.len <= 0 || ctlbuf[0] == M_DATA) { - /* data message */ - if (strbufd.len > 0) { /* real data */ - return(strbufd.len + 1); /* count header char */ - } else { - /* nothing there */ - errno = EAGAIN; - return(-1); - } - } - - /* - * It's a control message. Return 1, to look at the flag we set - */ - - switch (ctlbuf[0]) { - case M_FLUSH: - if (ibuf[1] & FLUSHW) - ibuf[0] = TIOCPKT_FLUSHWRITE; - return(1); - - case M_IOCTL: - ip = (struct iocblk *) (ibuf+1); - - switch (ip->ioc_cmd) { - case TCSETS: - case TCSETSW: - case TCSETSF: - tsp = (struct termios *) - (ibuf+1 + sizeof(struct iocblk)); - vstop = tsp->c_cc[VSTOP]; - vstart = tsp->c_cc[VSTART]; - ixon = tsp->c_iflag & IXON; - break; - case TCSETA: - case TCSETAW: - case TCSETAF: - tp = (struct termio *) (ibuf+1 + sizeof(struct iocblk)); - vstop = tp->c_cc[VSTOP]; - vstart = tp->c_cc[VSTART]; - ixon = tp->c_iflag & IXON; - break; - default: - errno = EAGAIN; - return(-1); - } - - newflow = (ixon && (vstart == 021) && (vstop == 023)) ? 1 : 0; - if (newflow != flowison) { /* it's a change */ - flowison = newflow; - ibuf[0] = newflow ? TIOCPKT_DOSTOP : TIOCPKT_NOSTOP; - return(1); - } - } - - /* nothing worth doing anything about */ - errno = EAGAIN; - return(-1); -} -#endif /* STREAMSPTY */ - /* * Send interrupt to process on other side of pty. * If it is in raw mode, just write NULL; * otherwise, write intr char. */ - void -interrupt() +void +interrupt(void) { ptyflush(); /* half-hearted */ -#if defined(STREAMSPTY) && defined(TIOCSIGNAL) - /* Streams PTY style ioctl to post a signal */ - { - int sig = SIGINT; - (void) ioctl(pty, TIOCSIGNAL, &sig); - (void) ioctl(pty, I_FLUSH, FLUSHR); - } -#else #ifdef TCSIG (void) ioctl(pty, TCSIG, (char *)SIGINT); #else /* TCSIG */ @@ -1203,7 +1050,6 @@ interrupt() *pfrontp++ = slctab[SLC_IP].sptr ? (unsigned char)*slctab[SLC_IP].sptr : '\177'; #endif /* TCSIG */ -#endif } /* @@ -1211,8 +1057,8 @@ interrupt() * If it is in raw mode, just write NULL; * otherwise, write quit char. */ - void -sendbrk() +void +sendbrk(void) { ptyflush(); /* half-hearted */ #ifdef TCSIG @@ -1224,8 +1070,8 @@ sendbrk() #endif /* TCSIG */ } - void -sendsusp() +void +sendsusp(void) { #ifdef SIGTSTP ptyflush(); /* half-hearted */ @@ -1242,8 +1088,8 @@ sendsusp() * When we get an AYT, if ^T is enabled, use that. Otherwise, * just send back "[Yes]". */ - void -recv_ayt() +void +recv_ayt(void) { #if defined(SIGINFO) && defined(TCSIG) if (slctab[SLC_AYT].sptr && *slctab[SLC_AYT].sptr != _POSIX_VDISABLE) { @@ -1254,8 +1100,8 @@ recv_ayt() output_data("\r\n[Yes]\r\n"); } - void -doeof() +void +doeof(void) { init_termbuf(); diff --git a/libexec/telnetd/telnetd.h b/libexec/telnetd/telnetd.h index 234b973..5bfc572 100644 --- a/libexec/telnetd/telnetd.h +++ b/libexec/telnetd/telnetd.h @@ -31,6 +31,7 @@ * SUCH DAMAGE. * * @(#)telnetd.h 8.1 (Berkeley) 6/4/93 + * $FreeBSD$ */ @@ -45,5 +46,4 @@ /* other external variables */ extern char **environ; -extern int errno; - +extern const char *altlogin; diff --git a/libexec/telnetd/termstat.c b/libexec/telnetd/termstat.c index b4fb137..14719a2 100644 --- a/libexec/telnetd/termstat.c +++ b/libexec/telnetd/termstat.c @@ -31,16 +31,17 @@ * SUCH DAMAGE. */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) 5/30/95"; #endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ #include "telnetd.h" + /* * local variables */ @@ -129,8 +130,8 @@ static int _terminit = 0; * then linemode is off, if server won't SGA, then linemode * is on. */ - void -localstat() +void +localstat(void) { int need_will_echo = 0; @@ -181,6 +182,7 @@ localstat() } } + /* * Do echo mode handling as soon as we know what the * linemode is going to be. @@ -333,8 +335,8 @@ done: * * Check for changes to flow control */ - void -flowstat() +void +flowstat(void) { if (his_state_is_will(TELOPT_LFLOW)) { if (tty_flowmode() != flowmode) { @@ -363,9 +365,8 @@ flowstat() * at a time, and if using kludge linemode, then only linemode may be * affected. */ - void -clientstat(code, parm1, parm2) - register int code, parm1, parm2; +void +clientstat(int code, int parm1, int parm2) { /* @@ -440,7 +441,7 @@ clientstat(code, parm1, parm2) case LM_MODE: { - register int ack, changed; + int ack, changed; /* * Client has sent along a mode mask. If it agrees with @@ -565,8 +566,8 @@ clientstat(code, parm1, parm2) * function is called when the pty state has been processed for the first time. * It calls other functions that do things that were deferred in each module. */ - void -defer_terminit() +void +defer_terminit(void) { /* @@ -600,8 +601,8 @@ defer_terminit() * * Returns true if the pty state has been processed yet. */ - int -terminit() +int +terminit(void) { return(_terminit); diff --git a/libexec/telnetd/utility.c b/libexec/telnetd/utility.c index e544fb1..c835269 100644 --- a/libexec/telnetd/utility.c +++ b/libexec/telnetd/utility.c @@ -47,6 +47,7 @@ static const char rcsid[] = #define PRINTOPTIONS #include "telnetd.h" + /* * utility functions performing io related tasks */ @@ -88,11 +89,10 @@ ttloop() /* * Check a descriptor to see if out of band data exists on it. */ - int -stilloob(s) - int s; /* socket number */ +int +stilloob(int s) { - static struct timeval timeout = { 0 }; + static struct timeval timeout = { 0, 0 }; fd_set excepts; int value; @@ -113,8 +113,8 @@ stilloob(s) } } - void -ptyflush() +void +ptyflush(void) { int n; @@ -144,9 +144,8 @@ ptyflush() * if the current address is a TELNET IAC ("I Am a Command") * character. */ - char * -nextitem(current) - char *current; +static char * +nextitem(char *current) { if ((*current&0xff) != IAC) { return current+1; @@ -159,7 +158,7 @@ nextitem(current) return current+3; case SB: /* loop forever looking for the SE */ { - register char *look = current+2; + char *look = current+2; for (;;) { if ((*look++&0xff) == IAC) { @@ -174,7 +173,6 @@ nextitem(current) } } /* end of nextitem */ - /* * netclear() * @@ -191,10 +189,10 @@ nextitem(current) * caller should be setting the urgent data pointer AFTER calling * us in any case. */ - void -netclear() +void +netclear(void) { - register char *thisitem, *next; + char *thisitem, *next; char *good; #define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \ ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL)) @@ -236,8 +234,8 @@ netclear() * Send as much data as possible to the network, * handling requests for urgent data. */ - void -netflush() +void +netflush(void) { int n; extern int not42; @@ -295,10 +293,8 @@ netflush() */ - void -fatal(f, msg) - int f; - char *msg; +void +fatal(int f, const char *msg) { char buf[BUFSIZ]; @@ -308,12 +304,10 @@ fatal(f, msg) exit(1); } - void -fatalperror(f, msg) - int f; - char *msg; +void +fatalperror(int f, const char *msg) { - char buf[BUFSIZ], *strerror(); + char buf[BUFSIZ]; (void) snprintf(buf, sizeof(buf), "%s: %s", msg, strerror(errno)); fatal(f, buf); @@ -321,15 +315,13 @@ fatalperror(f, msg) char editedhost[32]; - void -edithost(pat, host) - register char *pat; - register char *host; +void +edithost(char *pat, char *host) { - register char *res = editedhost; + char *res = editedhost; if (!pat) - pat = ""; + pat = strdup(""); while (*pat) { switch (*pat) { @@ -363,18 +355,16 @@ edithost(pat, host) static char *putlocation; - void -putstr(s) - register char *s; +static void +putstr(const char *s) { while (*s) putchr(*s++); } - void -putchr(cc) - int cc; +void +putchr(int cc) { *putlocation++ = cc; } @@ -382,18 +372,11 @@ putchr(cc) #ifdef __FreeBSD__ static char fmtstr[] = { "%+" }; #else -/* - * This is split on two lines so that SCCS will not see the M - * between two % signs and expand it... - */ -static char fmtstr[] = { "%l:%M\ -%P on %A, %d %B %Y" }; +static char fmtstr[] = { "%l:%M%P on %A, %d %B %Y" }; #endif - void -putf(cp, where) - register char *cp; - char *where; +void +putf(char *cp, char *where) { char *slash; time_t t; @@ -474,10 +457,8 @@ putf(cp, where) /* * Print telnet options and commands in plain text, if possible. */ - void -printoption(fmt, option) - register char *fmt; - register int option; +void +printoption(const char *fmt, int option) { if (TELOPT_OK(option)) output_data("%s %s\r\n", fmt, TELOPT(option)); @@ -488,13 +469,10 @@ printoption(fmt, option) return; } - void -printsub(direction, pointer, length) - char direction; /* '<' or '>' */ - unsigned char *pointer; /* where suboption data sits */ - int length; /* length of suboption data */ +void +printsub(char direction, unsigned char *pointer, int length) { - register int i = 0; + int i = 0; if (!(diagnostic & TD_OPTIONS)) return; @@ -503,7 +481,7 @@ printsub(direction, pointer, length) output_data("td: %s suboption ", direction == '<' ? "recv" : "send"); if (length >= 3) { - register int j; + int j; i = pointer[length-2]; j = pointer[length-1]; @@ -723,8 +701,8 @@ printsub(direction, pointer, length) break; case TELOPT_STATUS: { - register char *cp; - register int j, k; + const char *cp; + int j, k; output_data("STATUS"); @@ -825,7 +803,7 @@ printsub(direction, pointer, length) output_data("INFO "); env_common: { - register int noquote = 2; + int noquote = 2; for (i = 2; i < length; i++ ) { switch (pointer[i]) { case NEW_ENV_VAR: @@ -888,13 +866,10 @@ printsub(direction, pointer, length) /* * Dump a data buffer in hex and ascii to the output data stream. */ - void -printdata(tag, ptr, cnt) - register char *tag; - register char *ptr; - register int cnt; +void +printdata(const char *tag, char *ptr, int cnt) { - register int i; + int i; char xbuf[30]; while (cnt) { -- cgit v1.1