/* * 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 */