/* * Select from tty and network... */ void my_telnet(char *user) { int printed_encrypt = 0; sys_telnet_init(); #if defined(AUTHENTICATION) || defined(ENCRYPTION) { static char local_host[256] = { 0 }; if (!local_host[0]) { /* XXX - should be k_gethostname? */ gethostname(local_host, sizeof(local_host)); local_host[sizeof(local_host)-1] = 0; } auth_encrypt_init(local_host, hostname, "TELNET", 0); auth_encrypt_user(user); } #endif if (telnetport) { #if defined(AUTHENTICATION) if (autologin) send_will(TELOPT_AUTHENTICATION, 1); #endif #if defined(ENCRYPTION) send_do(TELOPT_ENCRYPT, 1); send_will(TELOPT_ENCRYPT, 1); #endif send_do(TELOPT_SGA, 1); send_will(TELOPT_TTYPE, 1); send_will(TELOPT_NAWS, 1); send_will(TELOPT_TSPEED, 1); send_will(TELOPT_LFLOW, 1); send_will(TELOPT_LINEMODE, 1); send_will(TELOPT_NEW_ENVIRON, 1); send_do(TELOPT_STATUS, 1); if (env_getvalue((unsigned char *)"DISPLAY")) send_will(TELOPT_XDISPLOC, 1); if (binary) tel_enter_binary(binary); } #ifdef ENCRYPTION /* * Note: we assume a tie to the authentication option here. This * is necessary so that authentication fails, we don't spin * forever. */ if (telnetport && wantencryption) { time_t timeout = time(0) + 60; send_do(TELOPT_ENCRYPT, 1); send_will(TELOPT_ENCRYPT, 1); while (1) { if (my_want_state_is_wont(TELOPT_AUTHENTICATION)) { if (wantencryption == -1) { break; } else { printf("\nServer refused to negotiate authentication,\n"); printf("which is required for encryption.\n"); Exit(1); } } if (auth_has_failed) { printf("\nAuthentication negotiation has failed,\n"); printf("which is required for encryption.\n"); Exit(1); } if (my_want_state_is_dont(TELOPT_ENCRYPT) || my_want_state_is_wont(TELOPT_ENCRYPT)) { printf("\nServer refused to negotiate encryption.\n"); Exit(1); } if (encrypt_is_encrypting()) break; if (time(0) > timeout) { printf("\nEncryption could not be enabled.\n"); Exit(1); } if (printed_encrypt == 0) { printed_encrypt = 1; printf("Waiting for encryption to be negotiated...\n"); /* * Turn on MODE_TRAPSIG and then turn off localchars * so that ^C will cause telnet to exit. */ TerminalNewMode(getconnmode()|MODE_TRAPSIG); intr_waiting = 1; } if (intr_happened) { printf("\nUser interrupt.\n"); Exit(1); } if (telnet_spin()) { printf("\nServer disconnected.\n"); Exit(1); } } if (printed_encrypt) { printf("Encryption negotiated.\n"); intr_waiting = 0; setconnmode(0); } } #endif for (;;) { int schedValue; while ((schedValue = Scheduler(0)) != 0) { if (schedValue == -1) { setcommandmode(); return; } } if (Scheduler(1) == -1) { setcommandmode(); return; } } }
/* * Get a pty, scan input lines. */ static void doit(struct sockaddr_in *who) { const char *host; struct hostent *hp; int level; char user_name[256]; char portnum[8]; /* * Find an available pty to use. */ pty = getpty(); if (pty < 0) fatal(net, "All network ports in use"); /* get name of connected client */ hp = gethostbyaddr((char *)&who->sin_addr, sizeof (struct in_addr), who->sin_family); if (hp) host = hp->h_name; else host = inet_ntoa(who->sin_addr); /* * We must make a copy because Kerberos is probably going * to also do a gethost* and overwrite the static data... */ { int i; strncpy(remote_host_name, host, sizeof(remote_host_name)-1); remote_host_name[sizeof(remote_host_name)-1] = 0; /* Disallow funnies. */ for (i=0; remote_host_name[i]; i++) { if (remote_host_name[i]<=32 || remote_host_name[i]>126) remote_host_name[i] = '?'; } } host = remote_host_name; /* Get local host name */ { struct hostent *h; gethostname(host_name, sizeof(host_name)); h = gethostbyname(host_name); if (h) { strncpy(host_name, h->h_name, sizeof(host_name)); host_name[sizeof(host_name)-1] = 0; } } #if defined(AUTHENTICATE) || defined(ENCRYPT) auth_encrypt_init(host_name, host, "TELNETD", 1); #endif init_env(); /* * get terminal type. */ *user_name = 0; level = getterminaltype(user_name); setenv("HOME", "/opt/mud/plogin",1); setenv("TERM", terminaltype ? terminaltype : "network", 1); /* TODO list stuff provided by Laszlo Vecsey <*****@*****.**> */ /* * Set REMOTEHOST environment variable */ setproctitle("%s", host); sprintf(portnum, "%d", ntohs(who->sin_port)); setenv("REMOTEADDR", inet_ntoa(who->sin_addr), 1); setenv("REMOTEHOST", host, 1); setenv("REMOTEPORT", portnum, 1); /* * Start up the login process on the slave side of the terminal */ startslave(host, level, user_name); telnet(net, pty); /* begin server processing */ /*NOTREACHED*/ } /* end of doit */
/* * Get a pty, scan input lines. */ static void doit(struct sockaddr_in *who) { const char *host; #ifndef REALLY_SMALL_TELNETD struct hostent *hp; #endif int level; char user_name[256]; /* * Find an available pty to use. */ #ifndef convex pty = getpty(); if (pty < 0) fatal(net, "All network ports in use"); #else for (;;) { char *lp; extern char *line, *getpty(); if ((lp = getpty()) == NULL) fatal(net, "Out of ptys"); if ((pty = open(lp, 2)) >= 0) { strcpy(line,lp); line[5] = 't'; break; } } #endif #ifndef REALLY_SMALL_TELNETD /* get name of connected client */ hp = gethostbyaddr((char *)&who->sin_addr, sizeof (struct in_addr), who->sin_family); if (hp) host = hp->h_name; else #endif host = inet_ntoa(who->sin_addr); #ifndef REALLY_SMALL_TELNETD /* * We must make a copy because Kerberos is probably going * to also do a gethost* and overwrite the static data... */ strncpy(remote_host_name, host, sizeof(remote_host_name)-1); remote_host_name[sizeof(remote_host_name)-1] = 0; host = remote_host_name; { struct hostent *h; gethostname(host_name, sizeof(host_name)); h = gethostbyname(host_name); if (h) { strncpy(host_name, h->h_name, sizeof(host_name)); host_name[sizeof(host_name)-1] = 0; } } #endif #if defined(AUTHENTICATE) || defined(ENCRYPT) auth_encrypt_init(host_name, host, "TELNETD", 1); #endif init_env(); /* * get terminal type. */ *user_name = 0; level = getterminaltype(user_name); #ifdef ENV setenv("TERM", terminaltype ? terminaltype : "network", 1); #endif /* * Start up the login process on the slave side of the terminal */ #ifndef convex startslave(host, level, user_name); telnet(net, pty); /* begin server processing */ #else telnet(net, pty, host); #endif /*NOTREACHED*/ } /* end of doit */
/* * Get a pty, scan input lines. */ static void doit(struct sockaddr *who, socklen_t who_len) { char *host; int level; char user_name[256]; int i; struct addrinfo hints, *res; /* * Find an available pty to use. */ pty = getpty(); if (pty < 0) fatalperror(net, "getpty"); /* get name of connected client */ if (getnameinfo(who, who_len, remote_host_name, sizeof(remote_host_name), 0, 0, numeric_hosts ? NI_NUMERICHOST : 0)) { syslog(LOG_ERR, "doit: getnameinfo: %m"); *remote_host_name = 0; } /* Disallow funnies. */ for (i=0; remote_host_name[i]; i++) { if (remote_host_name[i]<=32 || remote_host_name[i]>126) remote_host_name[i] = '?'; } host = remote_host_name; /* Get local host name */ gethostname(host_name, sizeof(host_name)); memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_flags = AI_CANONNAME; if ((i = getaddrinfo(host_name, 0, &hints, &res))) syslog(LOG_WARNING, "doit: getaddrinfo: %s", gai_strerror(i)); else { strncpy(host_name, res->ai_canonname, sizeof(host_name)-1); host_name[sizeof(host_name)-1] = 0; } #if defined(AUTHENTICATE) || defined(ENCRYPT) auth_encrypt_init(host_name, host, "TELNETD", 1); #endif init_env(); /* * get terminal type. */ *user_name = 0; level = getterminaltype(user_name); setenv("TERM", terminaltype ? terminaltype : "network", 1); /* TODO list stuff provided by Laszlo Vecsey <*****@*****.**> */ #ifdef USE_SSL if (debug) { fprintf(stderr,"doit - ALIVE\n"); fflush(stderr); sleep(2); } #endif /* USE_SSL */ /* * Set REMOTEHOST environment variable */ setproctitle("%s", host); setenv("REMOTEHOST", host, 0); #ifdef USE_SSL if (debug) { fprintf(stderr,"doit - starting telnet protocol itself\n"); fflush(stderr); sleep(2); } #endif /* USE_SSL */ /* * Start up the login process on the slave side of the terminal */ startslave(host, level, user_name); telnet(net, pty); /* begin server processing */ /*NOTREACHED*/ } /* end of doit */