ckctel.c
资源名称:cku197.tar.Z [点击查看]
上传用户:dufan58
上传日期:2007-01-05
资源大小:3407k
文件大小:158k
源码类别:
通讯/手机编程
开发平台:
Windows_Unix
- switch (sb[1]) {
- case 5: /* SRP */
- s[3] = "FORWARD";
- break;
- case 2: /* KERBEROS_V5 */
- s[3] = "FORWARD_ACCEPT";
- break;
- }
- break;
- case 6:
- switch (sb[1]) {
- case 5: /* SRP */
- s[3] = "FORWARD_ACCEPT";
- break;
- case 2: /* KERBEROS_V5 */
- s[3] = "FORWARD_REJECT";
- break;
- }
- break;
- case 7:
- switch (sb[1]) {
- case 5: /* SRP */
- s[3] = "FORWARD_REJECT";
- break;
- }
- break;
- case 8:
- switch (sb[1]) {
- case 5: /* SRP */
- s[3] = "EXP";
- break;
- }
- break;
- case 9:
- switch (sb[1]) {
- case 5: /* SRP */
- s[3] = "PARAMS";
- break;
- }
- break;
- }
- }
- }
- break;
- case 1:
- switch (opt) {
- case TELOPT_FORWARD_X:
- s[0] = "OPEN";
- break;
- case TELOPT_LFLOW:
- s[0] = "ON";
- break;
- case TELOPT_KERMIT:
- s[0] = "STOP";
- break;
- case TELOPT_AUTHENTICATION:
- s[0] = "SEND";
- hexbuf[0] = ' ';
- for (; i < n-2; i += 2) {
- sprintf(tn_msg,
- "%s %s ",
- authtype_names[sb[i]],
- authmode_names[sb[i+1]]
- );
- strcat(hexbuf,tn_msg);
- }
- s[1] = hexbuf;
- break;
- case TELOPT_ENCRYPTION:
- s[0] = "SUPPORT";
- while (i < n-2) {
- s[i] = enctype_names[sb[i]];
- i++;
- }
- break;
- case TELOPT_START_TLS:
- s[0] = "FOLLOWS";
- break;
- default:
- s[0] = "SEND";
- }
- break;
- case 2:
- switch (opt) {
- case TELOPT_FORWARD_X:
- s[0] = "CLOSE";
- break;
- case TELOPT_LFLOW:
- s[0] = "RESTART-ANY";
- break;
- case TELOPT_KERMIT:
- s[0] = "REQ-START";
- break;
- case TELOPT_NEWENVIRON:
- s[0] = "INFO";
- break;
- case TELOPT_AUTHENTICATION:
- s[0] = "REPLY";
- i=4;
- s[1] = authtype_names[sb[1]];
- s[2] = authmode_names[sb[2]];
- switch (sb[3]) {
- case 0:
- switch (sb[1]) {
- case AUTHTYPE_NTLM:
- s[3] = "NTLM_AUTH";
- break;
- default:
- s[3] = "AUTH";
- }
- break;
- case 1:
- switch (sb[1]) {
- case AUTHTYPE_NTLM:
- s[3] = "NTLM_CHALLENGE";
- break;
- default:
- s[3] = "REJECT";
- }
- break;
- case 2:
- switch (sb[1]) {
- case AUTHTYPE_NTLM:
- s[3] = "NTLM_RESPONSE";
- break;
- default:
- s[3] = "ACCEPT";
- }
- break;
- case 3:
- switch (sb[1]) {
- case AUTHTYPE_NTLM:
- s[3] = "NTLM_ACCEPT";
- break;
- case AUTHTYPE_KERBEROS_V4:
- case AUTHTYPE_SRP:
- s[3] = "CHALLENGE";
- break;
- case AUTHTYPE_KERBEROS_V5:
- s[3] = "RESPONSE";
- break;
- }
- break;
- case 4:
- switch (sb[1]) {
- case AUTHTYPE_NTLM:
- s[3] = "NTLM_REJECT";
- break;
- case AUTHTYPE_KERBEROS_V4:
- case AUTHTYPE_SRP:
- s[3] = "RESPONSE";
- break;
- case AUTHTYPE_KERBEROS_V5:
- s[3] = "FORWARD";
- break;
- }
- break;
- case 5:
- switch (sb[1]) {
- case AUTHTYPE_SRP:
- s[3] = "FORWARD";
- break;
- case AUTHTYPE_KERBEROS_V5:
- s[3] = "FORWARD_ACCEPT";
- break;
- }
- break;
- case 6:
- switch (sb[1]) {
- case AUTHTYPE_SRP:
- s[3] = "FORWARD_ACCEPT";
- break;
- case AUTHTYPE_KERBEROS_V5:
- s[3] = "FORWARD_REJECT";
- break;
- }
- break;
- case 7:
- switch (sb[1]) {
- case AUTHTYPE_SRP:
- s[3] = "FORWARD_REJECT";
- break;
- }
- break;
- case 8:
- switch (sb[1]) {
- case AUTHTYPE_SRP:
- s[3] = "EXP";
- break;
- }
- break;
- case 9:
- switch (sb[1]) {
- case AUTHTYPE_SRP:
- s[3] = "PARAMS";
- break;
- }
- break;
- }
- break;
- case TELOPT_ENCRYPTION:
- s[0] = "REPLY";
- s[1] = enctype_names[sb[1]];
- i++;
- switch (sb[2]) {
- case 1:
- i++;
- s[2] = "FB64_IV";
- break;
- case 2:
- i++;
- s[2] = "FB64_IV_OK";
- break;
- case 3:
- i++;
- s[2] = "FB64_IV_BAD";
- break;
- case 4:
- i++;
- s[2] = "FB64_CHALLENGE";
- break;
- case 5:
- i++;
- s[2] = "FB64_RESPONSE";
- break;
- }
- break;
- }
- break;
- case 3:
- switch (opt) {
- case TELOPT_FORWARD_X:
- s[0] = "DATA";
- break;
- case TELOPT_LFLOW:
- s[0] = "RESTART-XON";
- break;
- case TELOPT_KERMIT:
- s[0] = "REQ-STOP";
- break;
- case TELOPT_AUTHENTICATION:
- s[0] = "NAME";
- break;
- case TELOPT_ENCRYPTION:
- s[0] = "START";
- break;
- }
- break;
- case 4:
- switch (opt) {
- case TELOPT_KERMIT:
- s[0] = "SOP";
- break;
- case TELOPT_ENCRYPTION:
- s[0] = "END";
- break;
- }
- break;
- case 5:
- switch (opt) {
- case TELOPT_ENCRYPTION:
- s[0] = "REQUEST-START";
- break;
- }
- break;
- case 6:
- switch (opt) {
- case TELOPT_ENCRYPTION:
- s[0] = "REQUEST-END";
- break;
- }
- break;
- case 7:
- switch (opt) {
- case TELOPT_ENCRYPTION:
- s[0] = "ENC-KEYID";
- break;
- }
- break;
- case 8:
- switch (opt) {
- case TELOPT_KERMIT:
- s[0] = "RESP-START";
- break;
- case TELOPT_ENCRYPTION:
- s[0] = "DEC-KEYID";
- break;
- }
- break;
- case 9:
- switch (opt) {
- case TELOPT_KERMIT:
- s[0] = "RESP-STOP";
- break;
- }
- break;
- }
- }
- #ifdef M_XENIX
- {
- int len, param, param_len;
- sprintf(tn_msg,
- "TELNET RCVD SB %s ",
- TELOPT(opt));
- len = strlen(tn_msg);
- for (param = 0; param <= 15; param++) {
- param_len = strlen(s[param]);
- if (param_len > 0) {
- strcpy(&tn_msg[len], s[param]);
- len += param_len;
- tn_msg[len++] = ' ';
- }
- }
- tn_msg[len] = ' ';
- }
- #else
- sprintf(tn_msg,
- "TELNET RCVD SB
- %s %s %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
- TELOPT(opt),s[0],
- s[ 1], s[ 1][0]?" ":"",
- s[ 2], s[ 2][0]?" ":"",
- s[ 3], s[ 3][0]?" ":"",
- s[ 4], s[ 4][0]?" ":"",
- s[ 5], s[ 5][0]?" ":"",
- s[ 6], s[ 6][0]?" ":"",
- s[ 7], s[ 7][0]?" ":"",
- s[ 8], s[ 8][0]?" ":"",
- s[ 9], s[ 9][0]?" ":"",
- s[10], s[10][0]?" ":"",
- s[11], s[11][0]?" ":"",
- s[12], s[12][0]?" ":"",
- s[13], s[13][0]?" ":"",
- s[14], s[14][0]?" ":"",
- s[15], s[15][0]?" ":"");
- #endif /* M_XENIX */
- #ifdef HEXDISP
- {
- int was_hex = 1;
- for (; i < n-2; i++) {
- if (sb[i] < 32 || sb[i] >= 127) {
- sprintf(hexbuf,"%s%02X ",was_hex?"":"" ",sb[i]);
- was_hex = 1;
- } else {
- sprintf(hexbuf,"%s%c",was_hex?""":"",sb[i]);
- was_hex = 0;
- }
- strcat(tn_msg,hexbuf);
- }
- if (!was_hex)
- strcat(tn_msg,"" ");
- }
- #else /* HEXDISP */
- memcpy(hexbuf,&sb[i],n-i-2);
- hexbuf[n-i-2] = ' ';
- hexbuf[n-i-1] = ' ';
- strcat(tn_msg,hexbuf);
- #endif /* HEXDISP */
- if (flag == 2)
- strcat(tn_msg,"SE");
- else if (flag == 3)
- strcat(tn_msg," IAC DONT");
- else
- strcat(tn_msg," IAC SE");
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses)
- tn_debug(tn_msg);
- }
- *len = n; /* return length */
- return(1); /* success */
- }
- static char rows_buf[16] = { 0, 0 }; /* LINES Environment variable */
- static char cols_buf[16] = { 0, 0 }; /* COLUMNS Enviornment variable */
- static char term_buf[64] = { 0, 0 }; /* TERM Environment variable */
- #ifdef CK_CURSES
- #ifndef VMS
- #ifndef COHERENT
- _PROTOTYP(int tgetent,(char *, char *));
- #endif /* COHERENT */
- #else
- #ifdef __DECC
- _PROTOTYP(int tgetent,(char *, char *));
- #endif /* __DECC */
- #endif /* VMS */
- extern char * trmbuf; /* Real curses */
- #endif /* CK_CURSES */
- #ifdef CK_ENCRYPTION
- static int
- tn_no_encrypt()
- {
- /* Prevent Encryption from being negotiated */
- TELOPT_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
- TELOPT_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
- /* Cancel any negotiation that might have started */
- ck_tn_enc_stop();
- if (TELOPT_ME(TELOPT_ENCRYPTION) ||
- TELOPT_UNANSWERED_WILL(TELOPT_ENCRYPTION)) {
- TELOPT_ME(TELOPT_ENCRYPTION) = 0;
- if (tn_sopt(WONT,TELOPT_ENCRYPTION) < 0)
- return(-1);
- TELOPT_UNANSWERED_WONT(TELOPT_ENCRYPTION) = 1;
- }
- if (TELOPT_U(TELOPT_ENCRYPTION) ||
- TELOPT_UNANSWERED_DO(TELOPT_ENCRYPTION)) {
- TELOPT_U(TELOPT_ENCRYPTION) = 0;
- if (tn_sopt(DONT,TELOPT_ENCRYPTION) < 0)
- return(-1);
- TELOPT_UNANSWERED_DONT(TELOPT_ENCRYPTION) = 1;
- }
- return(0);
- }
- #endif /* CK_ENCRYPTION */
- /* The following note came from the old SGA negotiation code. This should */
- /* no longer be necessary with the New Telnet negotiation state machine. */
- /*
- Note: The following is proper behavior, and required for talking to the
- Apertus interface to the NOTIS library system, e.g. at Iowa State U:
- scholar.iastate.edu. Without this reply, the server hangs forever. This
- code should not be loop-inducing, since C-Kermit never sends WILL SGA as
- an initial bid, so if DO SGA comes, it is never an ACK.
- */
- /*
- Return values:
- -1 = Telnet Opton negotiation error
- -2 = Connection closed by peer
- -3 = Connection closed by us
- 0 = Success
- 1 = Echoing on
- 2 = Echoing off
- 3 = Quoted IAC
- 4 = IKS Event
- 5 = (unassigned)
- 6 = Logout
- */
- int
- #ifdef CK_ANSIC /* TELNET DO OPTION */
- tn_doop(CHAR z, int echo, int (*fn)(int))
- #else
- tn_doop(z, echo, fn) CHAR z; int echo; int (*fn)();
- #endif /* CK_ANSIC */
- /* tn_doop */ {
- int c, x, y, n, m, flag;
- #ifdef IKS_OPTION
- extern int server;
- extern int local;
- #ifdef NOICP
- extern int autodl;
- int inautodl = 0, cmdadl = 1;
- #else
- #ifdef CK_AUTODL
- extern int autodl, inautodl, cmdadl;
- #endif /* CK_AUTODL */
- #endif /* NOICP */
- #endif /* IKS_OPTION */
- if (z != (CHAR) IAC) {
- debug(F101,"tn_doop bad call","",z);
- return(-1);
- }
- if (ttnet != NET_TCPB) /* Check network type */
- return(0);
- if (ttnproto != NP_TELNET &&
- ttnproto != NP_NONE) /* Check protocol */
- return(0);
- /* Have IAC, read command character. */
- while ((c = (*fn)(0)) == -1); /* Read command character */
- if (c < 0)
- return(c);
- c &= 0xFF; /* Strip high bits */
- if (!TELCMD_OK(c)) {
- sprintf(tn_msg,"TELNET RCVD UNKNOWN (%d)",c);
- debug(F101,tn_msg,"",c);
- if (tn_deb || debses) tn_debug(tn_msg);
- return(0);
- }
- if (ttnproto == NP_NONE) {
- debug(F100,"tn_doop discovered a Telnet command",
- "ttnproto = NP_TELNET",0);
- ttnproto = NP_TELNET;
- }
- if (seslog && sessft == XYFT_D) { /* Copy to session log, if any. */
- logchar((char)z);
- logchar((char)c);
- }
- if (c == (CHAR) IAC) /* Quoted IAC */
- return(3);
- if (c < SB) { /* Other command with no arguments. */
- if (deblog || tn_deb || debses) {
- sprintf(tn_msg,"TELNET RCVD %s",TELCMD(c));
- debug(F101,tn_msg,"",c);
- if (tn_deb || debses) tn_debug(tn_msg);
- }
- switch (c) { /* What we would like to do here */
- case TN_GA: /* Is substitute ASCII characters */
- break; /* for the Telnet Command so that */
- case TN_EL: /* the command may be processed by */
- break; /* either the internal emulator or */
- case TN_EC: /* by the superior process or shell */
- break;
- case TN_AYT:
- ttol((CHAR *)"[Yes] 15 12",7);
- break;
- case TN_AO:
- #ifdef BETATEST
- bleep(BP_NOTE);
- #endif /* BETATEST */
- break;
- case TN_IP:
- break;
- case BREAK:
- break;
- case TN_DM:
- break;
- case TN_NOP:
- break;
- case SE:
- break;
- case TN_EOR:
- break;
- case TN_ABORT:
- break;
- case TN_SUSP:
- break;
- case TN_EOF:
- break;
- case TN_SAK:
- break;
- }
- return(0);
- }
- /* SB, WILL, WONT, DO, or DONT need more bytes... */
- if ((x = (*fn)(0)) < 0) /* Get the option. */
- return(x);
- x &= 0xff; /* Trim to 8 bits. */
- if (seslog && sessft == XYFT_D) { /* Session log */
- logchar((char) x);
- }
- if ((deblog || tn_deb || debses) && c != SB) {
- sprintf(tn_msg,"TELNET RCVD %s %s",TELCMD(c),TELOPT(x));
- debug(F101,tn_msg,"",x);
- if (tn_deb || debses) tn_debug(tn_msg);
- }
- /* Now handle the command */
- switch (c) {
- case WILL:
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows)
- return(0);
- #endif /* CK_SSL */
- if (!TELOPT_OK(x) || TELOPT_U_MODE(x) == TN_NG_RF) {
- if (tn_sopt(DONT,x) < 0)
- return(-1);
- if (TELOPT_UNANSWERED_DO(x))
- TELOPT_UNANSWERED_DO(x) = 0;
- } else if (!TELOPT_U(x)) {
- if (!TELOPT_UNANSWERED_DO(x)) {
- if (tn_sopt(DO,x) < 0)
- return -1;
- }
- if (TELOPT_UNANSWERED_DO(x))
- TELOPT_UNANSWERED_DO(x) = 0;
- TELOPT_U(x) = 1;
- switch (x) {
- #ifdef CK_SSL
- case TELOPT_START_TLS:
- /*
- If my proposal is accepted, at this point the Telnet
- protocol is turned off and a TLS negotiation takes
- place.
- Start by sending SB START_TLS FOLLOWS to signal
- we are ready. Wait for the peer to send the same
- and then start the TLS negotiation.
- If the TLS negotiation succeeds we call tn_ini()
- again to reset the telnet state machine and restart
- the negotiation process over the now secure link.
- If the TLS negotiation fails, we call ttclos()
- to terminate the connection.
- Only the server should receive a WILL START_TLS
- */
- tn_ssbopt(TELOPT_START_TLS,1,NULL,0);
- TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows = 1;
- break;
- #endif /* CK_SSL */
- #ifdef CK_AUTHENTICATION
- case TELOPT_AUTHENTICATION: {
- /* We now have to perform a SB SEND to identify the */
- /* supported authentication types to the other side. */
- extern int authentication_version;
- authentication_version = AUTHTYPE_AUTO;
- ck_tn_auth_request();
- break;
- }
- #endif /* CK_AUTHENTICATION */
- #ifdef CK_ENCRYPTION
- case TELOPT_ENCRYPTION:
- if (!(TELOPT_ME(TELOPT_AUTHENTICATION) ||
- TELOPT_U(TELOPT_AUTHENTICATION))
- ) {
- if (tn_sopt(DONT,x) < 0)
- return(-1);
- TELOPT_U(x) = 0;
- } else {
- if (ck_tn_auth_in_progress()) {
- TELOPT_SB(TELOPT_ENCRYPTION).encrypt.need_to_send = 1;
- } else {
- /* Perform subnegotiation */
- ck_encrypt_send_support();
- }
- if (!(TELOPT_ME(x) || TELOPT_UNANSWERED_WILL(x))
- && TELOPT_ME_MODE(x) != TN_NG_RF) {
- if (tn_sopt(WILL, x) < 0)
- return(-1);
- TELOPT_UNANSWERED_WILL(x) = 1;
- }
- }
- break;
- #endif /* CK_ENCRYPTION */
- #ifdef IKS_OPTION
- case TELOPT_KERMIT:
- if (!TELOPT_ME(x)) {
- /* Tell the other side what Start of Packet Character */
- tn_siks(KERMIT_SOP); /* SOP */
- if (!TELOPT_UNANSWERED_WILL(x) &&
- TELOPT_ME_MODE(x) != TN_NG_RF) {
- if (tn_sopt(WILL, x) < 0)
- return(-1);
- TELOPT_UNANSWERED_WILL(x) = 1;
- }
- }
- break;
- #endif /* IKS_OPTION */
- case TELOPT_BINARY:
- if (!TELOPT_ME(x)) {
- if (!TELOPT_UNANSWERED_WILL(x) &&
- TELOPT_ME_MODE(x) >= TN_NG_RQ) {
- if (tn_sopt(WILL, x) < 0)
- return(-1);
- TELOPT_UNANSWERED_WILL(x) = 1;
- }
- }
- break;
- case TELOPT_ECHO:
- if (echo) {
- if (TELOPT_UNANSWERED_DO(x))
- TELOPT_UNANSWERED_DO(x) = 0;
- return(2);
- }
- break;
- case TELOPT_TTYPE:
- /* SB TTYPE SEND */
- tn_ssbopt(TELOPT_TTYPE,TELQUAL_SEND,NULL,0);
- TELOPT_UNANSWERED_SB(TELOPT_TTYPE)=1;
- break;
- #ifdef CK_ENVIRONMENT
- case TELOPT_NEWENVIRON: /* SB NEW-ENVIRON SEND */
- #ifdef CK_AUTHENTICATION
- if (ck_tn_auth_valid() != AUTH_VALID)
- #endif /* CK_AUTHENTICATION */
- {
- char request[6]; /* request it */
- sprintf(request,"%cUSER",TEL_ENV_VAR);
- tn_ssbopt(TELOPT_NEWENVIRON,TELQUAL_SEND,request,5);
- TELOPT_UNANSWERED_SB(TELOPT_NEWENVIRON)=1;
- }
- break;
- #endif /* CK_ENVIRONMENT */
- #ifdef CK_FORWARD_X
- case TELOPT_FORWARD_X:
- if ( !tn_outst(0) || tn_init ) {
- if (tn_sndfwdx() < 0) {
- if (tn_sopt(DONT,x) < 0)
- return(-1);
- TELOPT_UNANSWERED_DONT(x) = 1;
- }
- } else {
- TELOPT_SB(TELOPT_FORWARD_X).forward_x.need_to_send = 1;
- }
- break;
- #endif /* CK_FORWARD_X */
- } /* switch */
- } else {
- if (TELOPT_UNANSWERED_DO(x))
- TELOPT_UNANSWERED_DO(x) = 0;
- }
- break;
- case WONT:
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows)
- return(0);
- #endif /* CK_SSL */
- if (!TELOPT_OK(x) || TELOPT_U(x) || TELOPT_UNANSWERED_DO(x)) {
- /* David Borman says we should not respond DONT when */
- /* the WONT is a response to a DO that we sent. */
- if (!(TELOPT_UNANSWERED_DO(x) || TELOPT_UNANSWERED_DONT(x)))
- if (tn_sopt(DONT,x) < 0)
- return(-1);
- if (TELOPT_UNANSWERED_DONT(x))
- TELOPT_UNANSWERED_DONT(x) = 0;
- if (TELOPT_UNANSWERED_DO(x))
- TELOPT_UNANSWERED_DO(x) = 0;
- if (TELOPT_U(x)) {
- TELOPT_U(x) = 0;
- }
- switch(x) {
- #ifdef CK_SSL
- case TELOPT_START_TLS:
- if (sstelnet && TELOPT_U_MODE(x) == TN_NG_MU) {
- printf("Telnet Start-TLS refused.n");
- ttclos(0);
- whyclosed = WC_TELOPT;
- return(-3);
- }
- break;
- #endif /* CK_SSL */
- #ifdef CK_AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- if (sstelnet && TELOPT_U_MODE(x) == TN_NG_MU) {
- printf("Telnet authentication refused.n");
- ttclos(0);
- whyclosed = WC_TELOPT;
- return(-3);
- } else if (TELOPT_U_MODE(x) == TN_NG_RQ) {
- TELOPT_U_MODE(x) = TN_NG_AC;
- }
- if (ck_tn_auth_in_progress())
- printf("Telnet authentication refused.n");
- #ifdef CK_ENCRYPTION
- if (sstelnet) {
- if (tn_no_encrypt()<0)
- return(-1);
- }
- #endif /* CK_ENCRYPTION */
- break;
- #endif /* CK_AUTHENTICATION */
- #ifdef CK_ENCRYPTION
- case TELOPT_ENCRYPTION:
- ck_tn_enc_stop();
- break;
- #endif /* CK_ENCRYPTION */
- #ifdef IKS_OPTION
- case TELOPT_KERMIT:
- TELOPT_SB(x).kermit.u_start = 0;
- TELOPT_SB(x).kermit.me_req_start = 0;
- TELOPT_SB(x).kermit.me_req_stop = 0;
- break;
- #endif /* IKS_OPTION */
- case TELOPT_NAWS: {
- /* The client does not support NAWS. */
- /* Assume a height of 24 and a width of 80 */
- if (sstelnet
- #ifdef IKSD
- || inserver
- #endif /* IKSD */
- ) {
- int w = 80, h = 24;
- if (tcp_incoming) {
- #ifdef OS2
- tt_cols[VTERM] = w;
- tt_rows[VTERM] = h;
- VscrnSetWidth(VTERM, w);
- VscrnSetHeight(VTERM, h+(tt_status?1:0));
- #else /* OS2 */
- tt_cols = w;
- tt_rows = h;
- #endif /* OS2 */
- } else {
- #ifdef OS2
- tt_cols[VCMD] = w;
- tt_rows[VCMD] = h;
- VscrnSetWidth(VCMD, w);
- VscrnSetHeight(VCMD, h);
- #endif /* OS2 */
- cmd_cols = w;
- cmd_rows = h;
- }
- /* Add LINES and COLUMNS to the environment */
- sprintf((char *)rows_buf,"LINES=%d",h);
- sprintf((char *)cols_buf,"COLUMNS=%d",w);
- #ifdef OS2ORUNIX
- #ifndef NOPUTENV
- putenv(rows_buf);
- putenv(cols_buf);
- #endif /* NOPUTENV */
- #endif /* OS2ORUNIX */
- }
- break;
- }
- case TELOPT_ECHO:
- if (!echo) {
- if (TELOPT_UNANSWERED_DO(x))
- TELOPT_UNANSWERED_DO(x) = 0;
- return(1);
- }
- break;
- }
- } else {
- if (TELOPT_UNANSWERED_DONT(x))
- TELOPT_UNANSWERED_DONT(x) = 0;
- if (TELOPT_UNANSWERED_DO(x))
- TELOPT_UNANSWERED_DO(x) = 0;
- }
- if (TELOPT_U_MODE(x) == TN_NG_MU) {
- sprintf(tn_msg,
- "Peer refuses TELNET DO %s negotiations - terminating connection",
- TELOPT(x)
- );
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses) tn_debug(tn_msg);
- printf("%sn",tn_msg);
- ttclos(0);
- whyclosed = WC_TELOPT;
- return(-3);
- }
- #ifdef COMMENT
- if (x == TELOPT_ECHO && !echo) /* Special handling for echo */
- return(1); /* because we allow 'duplex' */
- #endif /* COMMENT */
- break;
- case DO:
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows)
- return(0);
- #endif /* CK_SSL */
- if (!TELOPT_OK(x) || TELOPT_ME_MODE(x) == TN_NG_RF) {
- if (tn_sopt(WONT,x) < 0)
- return(-1);
- if (TELOPT_UNANSWERED_WILL(x))
- TELOPT_UNANSWERED_WILL(x) = 0;
- } else if (!TELOPT_ME(x)) {
- if (!TELOPT_UNANSWERED_WILL(x)) {
- if (tn_sopt(WILL,x) < 0)
- return(-1);
- }
- if (TELOPT_UNANSWERED_WILL(x))
- TELOPT_UNANSWERED_WILL(x) = 0;
- TELOPT_ME(x) = 1;
- switch (x) {
- #ifdef CK_SSL
- case TELOPT_START_TLS:
- /*
- If my proposal is accepted at this point the Telnet
- protocol is turned off and a TLS negotiation takes
- place.
- Start by sending SB START_TLS FOLLOWS to signal
- we are ready. Wait for the peer to send the same
- and then start the TLS negotiation.
- If the TLS negotiation succeeds we call tn_ini()
- again to reset the telnet state machine and restart
- the negotiation process over the now secure link.
- If the TLS negotiation fails, we call ttclos()
- to terminate the connection. Then we set the
- U_MODE and ME_MODE for TELOPT_START_TLS to REFUSE
- and then call ttopen() to create a new connection
- to the same host but this time do not attempt
- TLS security.
- Only the client should receive DO START_TLS.
- */
- tn_ssbopt(TELOPT_START_TLS,1,NULL,0);
- TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows = 1;
- break;
- #endif /* CK_SSL */
- #ifdef CK_AUTHENTICATION
- case TELOPT_AUTHENTICATION: {
- /* We don't know what authentication we are using yet */
- /* but it is not NULL until a failure is detected so */
- /* use AUTO in the meantime. */
- extern int authentication_version;
- authentication_version = AUTHTYPE_AUTO;
- break;
- }
- #endif /* CK_AUTHENTICATION */
- #ifdef CK_ENCRYPTION
- case TELOPT_ENCRYPTION:
- if (!(TELOPT_ME(TELOPT_AUTHENTICATION) ||
- TELOPT_U(TELOPT_AUTHENTICATION))
- ) {
- if (tn_sopt(WONT,x) < 0)
- return(-1);
- TELOPT_ME(x) = 0;
- } else {
- if (!(TELOPT_U(x) || TELOPT_UNANSWERED_DO(x))
- && TELOPT_U_MODE(x) != TN_NG_RF) {
- if (tn_sopt(DO, x) < 0)
- return(-1);
- TELOPT_UNANSWERED_DO(x) = 1;
- }
- }
- break;
- #endif /* CK_ENCRYPTION */
- #ifdef IKS_OPTION
- case TELOPT_KERMIT:
- /* If currently processing Kermit server packets, must tell the other side */
- debug(F111,"tn_doop","what",what);
- debug(F111,"tn_doop","server",server);
- #ifdef CK_AUTODL
- debug(F111,"tn_doop","autodl",autodl);
- debug(F111,"tn_doop","inautodl",inautodl);
- debug(F111,"tn_doop","cmdadl",cmdadl);
- #endif /* CK_AUTODL */
- if (server
- #ifdef CK_AUTODL
- || (local && ((what == W_CONNECT && autodl) ||
- (what != W_CONNECT && inautodl)))
- || (!local && cmdadl)
- #endif /* CK_AUTODL */
- ) {
- tn_siks(KERMIT_START); /* START */
- }
- if (!TELOPT_U(x)) {
- /* Tell the other side what Start of Packet Character */
- tn_siks(KERMIT_SOP); /* SOP */
- if (!TELOPT_UNANSWERED_DO(x) &&
- TELOPT_U_MODE(x) != TN_NG_RF) {
- if (tn_sopt(DO, x) < 0)
- return(-1);
- TELOPT_UNANSWERED_DO(x) = 1;
- }
- }
- break;
- #endif /* IKS_OPTION */
- case TELOPT_BINARY:
- if (!TELOPT_U(x)) {
- if (!TELOPT_UNANSWERED_DO(x) &&
- TELOPT_U_MODE(x) >= TN_NG_RQ) {
- if (tn_sopt(DO, x) < 0)
- return(-1);
- TELOPT_UNANSWERED_DO(x) = 1;
- }
- }
- break;
- case TELOPT_NAWS:
- #ifndef NOSIGWINCH
- #ifdef SIGWINCH
- #ifdef UNIX
- if (sw_armed++ < 1) { /* Catch window-size changes. */
- debug(F100,"tn_doop arming SIGWINCH","",0);
- signal(SIGWINCH,winchh);
- }
- #else
- debug(F100,"SIGWINCH defined but not used","",0);
- #endif /* UNIX */
- #else /* SIGWINCH */
- debug(F100,"SIGWINCH not defined","",0);
- #endif /* SIGWINCH */
- #else /* NOSIGWINCH */
- debug(F100,"NOSIGWINCH defined","",0);
- #endif /* NOSIGWINCH */
- #ifdef CK_NAWS
- if ( !tn_outst(0) || tn_init ) {
- if (tn_snaws() < 0)
- return(-1);
- } else {
- TELOPT_SB(TELOPT_NAWS).naws.need_to_send = 1;
- }
- #endif /* CK_NAWS */
- break;
- case TELOPT_LOGOUT:
- ttclos(0); /* And then hangup */
- whyclosed = WC_TELOPT;
- #ifdef IKSD
- if (inserver
- #ifndef NOLOCAL
- && !local
- #endif /* NOLOCAL */
- )
- doexit(GOOD_EXIT,0);
- #endif /* IKSD */
- if (TELOPT_UNANSWERED_WILL(x))
- TELOPT_UNANSWERED_WILL(x) = 0;
- return(6);
- #ifdef CK_SNDLOC
- case TELOPT_SNDLOC:
- if ( !tn_outst(0) || tn_init ) {
- if (tn_sndloc() < 0)
- return(-1);
- } else {
- TELOPT_SB(TELOPT_SNDLOC).sndloc.need_to_send = 1;
- }
- break;
- #endif /* CK_SNDLOC */
- } /* switch */
- } else {
- if (TELOPT_UNANSWERED_WILL(x))
- TELOPT_UNANSWERED_WILL(x) = 0;
- }
- break;
- case DONT:
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows)
- return(0);
- #endif /* CK_SSL */
- if (!TELOPT_OK(x) || TELOPT_ME(x) || TELOPT_UNANSWERED_WILL(x)) {
- /* David Borman says we should not respond DONT when */
- /* the WONT is a response to a WILL that we sent. */
- if (!(TELOPT_UNANSWERED_WILL(x) || TELOPT_UNANSWERED_WONT(x)))
- if (tn_sopt(WONT,x) < 0)
- return(-1);
- if (TELOPT_UNANSWERED_WILL(x))
- TELOPT_UNANSWERED_WILL(x) = 0;
- if (TELOPT_UNANSWERED_WONT(x))
- TELOPT_UNANSWERED_WONT(x) = 0;
- if (TELOPT_ME(x))
- TELOPT_ME(x) = 0;
- switch (x) {
- #ifdef CK_SSL
- case TELOPT_START_TLS:
- if (!sstelnet && TELOPT_ME_MODE(x) == TN_NG_MU) {
- printf("Telnet Start-TLS refused.n");
- ttclos(0);
- whyclosed = WC_TELOPT;
- return(-3);
- }
- break;
- #endif /* CK_SSL */
- #ifdef CK_AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- if (!sstelnet && TELOPT_ME_MODE(x) == TN_NG_MU) {
- printf("Telnet authentication refused.n");
- ttclos(0);
- whyclosed = WC_TELOPT;
- return(-3);
- } else if (TELOPT_ME_MODE(x) == TN_NG_RQ) {
- TELOPT_ME_MODE(x) = TN_NG_AC;
- }
- if (ck_tn_auth_in_progress())
- printf("Telnet authentication refused.n");
- #ifdef CK_ENCRYPTION
- if (!sstelnet) {
- if (tn_no_encrypt()<0)
- return(-1);
- }
- #endif /* CK_ENCRYPTION */
- break;
- #endif /* CK_AUTHENTICATION */
- case TELOPT_ENCRYPTION:
- #ifdef CK_ENCRYPTION
- ck_tn_enc_stop();
- #endif /* CK_ENCRYPTION */
- break;
- case TELOPT_KERMIT:
- #ifdef IKS_OPTION
- TELOPT_SB(x).kermit.me_start = 0;
- #endif /* IKS_OPTION */
- break;
- default:
- break;
- } /* switch */
- } else {
- if (TELOPT_UNANSWERED_WILL(x))
- TELOPT_UNANSWERED_WILL(x) = 0;
- if (TELOPT_UNANSWERED_WONT(x))
- TELOPT_UNANSWERED_WONT(x) = 0;
- }
- if (TELOPT_ME_MODE(x) == TN_NG_MU) {
- sprintf(tn_msg,
- "Peer refuses TELNET WILL %s negotiations - terminating connection",
- TELOPT(x)
- );
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses) tn_debug(tn_msg);
- printf("%sn",tn_msg);
- ttclos(0);
- whyclosed = WC_TELOPT;
- return(-3);
- }
- break;
- case SB:
- if ((y = tn_sb(x,&n,fn)) <= 0)
- return(y);
- #ifdef CK_SSL
- /* Do not process subnegotiations other than START_TLS after we */
- /* have agreed to begin the TLS negotiation sequence. */
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows &&
- x != TELOPT_START_TLS)
- break;
- #endif /* CK_SSL */
- if (!TELOPT_OK(x)) {
- hexdump("unknown telnet subnegotiation",sb,n);
- break;
- } else if ( !(TELOPT_ME(x) || TELOPT_U(x)) ) {
- hexdump("telnet option not negotiated",sb,n);
- if (!tn_sb_bug)
- break;
- if (TELOPT_UNANSWERED_WILL(x)) {
- TELOPT_UNANSWERED_WILL(x) = 0;
- TELOPT_U(x) = 1;
- sprintf(tn_msg,
- "TELNET DO %s (implied by receipt of SB - protocol error ignored)",
- TELOPT(x)
- );
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses) tn_debug(tn_msg);
- }
- if (TELOPT_UNANSWERED_DO(x)) {
- TELOPT_UNANSWERED_DO(x) = 0;
- TELOPT_ME(x) = 1;
- sprintf(tn_msg,
- "TELNET WILL %s (implied by receipt of SB - protocol error ignored)",
- TELOPT(x)
- );
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses) tn_debug(tn_msg);
- }
- }
- TELOPT_UNANSWERED_SB(x)=0;
- switch (x) {
- #ifdef CK_FORWARD_X
- case TELOPT_FORWARD_X:
- return(fwdx_tn_sb(sb, n));
- #endif /* CK_FORWARD_X */
- #ifdef CK_SSL
- case TELOPT_START_TLS: {
- /*
- the other side is saying SB START_TLS FOLLOWS
- the incoming channel is now ready for starting the
- TLS negotiation.
- */
- int def_tls_u_mode, def_tls_me_mode;
- int def_enc_u_mode, def_enc_me_mode;
- int rc = 0;
- TELOPT_SB(TELOPT_START_TLS).start_tls.u_follows = 1;
- /* Preserve the default modes and make sure we will */
- /* refuse START_TLS when we retry. */
- if (sstelnet) {
- def_tls_u_mode = TELOPT_DEF_S_U_MODE(TELOPT_START_TLS);
- def_tls_me_mode = TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS);
- TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) = TN_NG_RF;
- TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS)= TN_NG_RF;
- #ifdef CK_ENCRYPTION
- def_enc_u_mode = TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION);
- def_enc_me_mode = TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION);
- TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
- TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION)= TN_NG_RF;
- #endif /* CK_ENCRYPTION */
- } else {
- def_tls_u_mode = TELOPT_DEF_C_U_MODE(TELOPT_START_TLS);
- def_tls_me_mode = TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS);
- TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) = TN_NG_RF;
- TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS)= TN_NG_RF;
- #ifdef CK_ENCRYPTION
- def_enc_u_mode = TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION);
- def_enc_me_mode = TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION);
- TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
- TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION)= TN_NG_RF;
- #endif /* CK_ENCRYPTION */
- }
- /* Negotiate TLS */
- ttnproto = NP_TLS;
- tn_init = 0;
- if (ck_tn_tls_negotiate()<0) {
- /* we failed. disconnect and if we are the client */
- /* then reconnect and try without START_TLS. */
- extern char * line;
- int x = -1;
- extern int mdmtyp;
- if (sstelnet) {
- printf("TLS failed: Disconnecting.n");
- TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) = def_tls_u_mode;
- TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) = def_tls_me_mode;
- #ifdef CK_ENCRYPTION
- TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = def_enc_u_mode;
- TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = def_enc_me_mode;
- #endif /* CK_ENCRYPTION */
- ttclos(0);
- whyclosed = WC_TELOPT;
- ttnproto = NP_TELNET;
- rc = -3;
- } else {
- extern tls_norestore;
- printf("TLS failed: Disconnecting...n");
- #ifdef CK_ENCRYPTION
- TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = def_enc_u_mode;
- TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = def_enc_me_mode;
- #endif /* CK_ENCRYPTION */
- /* if START_TLS is not REQUIRED, then retry without it */
- if ( def_tls_me_mode != TN_NG_MU ) {
- tls_norestore = 1;
- ttclos(0);
- whyclosed = WC_TELOPT;
- tls_norestore = 0;
- ttnproto = NP_TELNET;
- printf("Reconnecting without TLS.n");
- sleep(2);
- if (ttopen(line,&x,mdmtyp,0)<0)
- rc = -3;
- } else {
- TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) =
- def_tls_u_mode;
- TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) =
- def_tls_me_mode;
- ttclos(0);
- whyclosed = WC_TELOPT;
- ttnproto = NP_TELNET;
- rc = -3;
- }
- }
- } else {
- /* we succeeded. restart telnet negotiations from */
- /* the beginning. However, if we have received a */
- /* client certificate and we are a server, then do */
- /* not offer TELOPT_AUTH */
- if ( ck_tn_auth_valid() == AUTH_VALID ) {
- TELOPT_DEF_S_U_MODE(TELOPT_AUTHENTICATION) = TN_NG_RF;
- TELOPT_DEF_S_ME_MODE(TELOPT_AUTHENTICATION)= TN_NG_RF;
- }
- ttnproto = NP_TELNET;
- if (tn_ini() < 0)
- if (ttchk() < 0)
- rc = -1;
- }
- /* Restore the default modes */
- if (sstelnet) {
- TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) = def_tls_u_mode;
- TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) = def_tls_me_mode;
- #ifdef CK_ENCRYPTION
- TELOPT_DEF_S_U_MODE(TELOPT_ENCRYPTION) = def_enc_u_mode;
- TELOPT_DEF_S_ME_MODE(TELOPT_ENCRYPTION) = def_enc_me_mode;
- #endif /* CK_ENCRYPTION */
- } else {
- TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) = def_tls_u_mode;
- TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) = def_tls_me_mode;
- #ifdef CK_ENCRYPTION
- TELOPT_DEF_C_U_MODE(TELOPT_ENCRYPTION) = def_enc_u_mode;
- TELOPT_DEF_C_ME_MODE(TELOPT_ENCRYPTION) = def_enc_me_mode;
- #endif /* CK_ENCRYPTION */
- }
- return(rc);
- }
- #endif /* CK_SSL */
- #ifdef CK_AUTHENTICATION
- case TELOPT_AUTHENTICATION:
- if (ck_tn_sb_auth(sb,n) < 0) {
- if (sstelnet && TELOPT_U_MODE(x) == TN_NG_MU) {
- ttclos(0);
- whyclosed = WC_TELOPT;
- return(-3);
- } else if (!sstelnet && TELOPT_ME_MODE(x) == TN_NG_MU) {
- ttclos(0);
- whyclosed = WC_TELOPT;
- return(-3);
- } else {
- if (TELOPT_ME_MODE(x) == TN_NG_RQ)
- TELOPT_ME_MODE(x) = TN_NG_AC;
- if (TELOPT_U_MODE(x) == TN_NG_RQ)
- TELOPT_U_MODE(x) = TN_NG_AC;
- }
- if (TELOPT_ME(x)) {
- TELOPT_ME(x) = 0;
- if (tn_sopt(WONT,x) < 0)
- return(-1);
- }
- if (TELOPT_U(x)) {
- TELOPT_U(x) = 0;
- if (tn_sopt(DONT,x) < 0)
- return(-1);
- }
- #ifdef CK_ENCRYPTION
- if (tn_no_encrypt()<0)
- return(-1);
- #endif /* CK_ENCRYPTION */
- } else {
- #ifdef CK_ENCRYPTION
- if (!ck_tn_auth_in_progress()) { /* we are finished */
- if (ck_tn_authenticated() == AUTHTYPE_SSL) {
- /* TLS was successful. Disable ENCRYPTION */
- TELOPT_U_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
- TELOPT_ME_MODE(TELOPT_ENCRYPTION) = TN_NG_RF;
- }
- if (TELOPT_SB(TELOPT_ENCRYPTION).encrypt.need_to_send) {
- ck_encrypt_send_support();
- TELOPT_SB(TELOPT_ENCRYPTION).encrypt.need_to_send = 0;
- }
- }
- #endif /* CK_ENCRYPTION */
- }
- break;
- #endif /* CK_AUTHENTICATION */
- #ifdef CK_ENCRYPTION
- case TELOPT_ENCRYPTION:
- if (ck_tn_sb_encrypt(sb, n) < 0) {
- if (TELOPT_U_MODE(x) == TN_NG_MU ||
- TELOPT_ME_MODE(x) == TN_NG_MU)
- {
- ttclos(0);
- whyclosed = WC_TELOPT;
- return(-3);
- } else {
- if (TELOPT_ME_MODE(x) == TN_NG_RQ)
- TELOPT_ME_MODE(x) = TN_NG_AC;
- if (TELOPT_U_MODE(x) == TN_NG_RQ)
- TELOPT_U_MODE(x) = TN_NG_AC;
- }
- if (TELOPT_ME(x)) {
- TELOPT_ME(x) = 0;
- if (tn_sopt(WONT,x) < 0)
- return(-1);
- }
- if (TELOPT_U(x)) {
- TELOPT_U(x) = 0;
- if (tn_sopt(DONT,x) < 0)
- return(-1);
- }
- }
- break;
- #endif /* CK_ENCRYPTION */
- #ifdef IKS_OPTION
- case TELOPT_KERMIT:
- return(iks_tn_sb((char *)sb, n));
- #endif /* IKS_OPTION */
- case TELOPT_TTYPE:
- switch (sb[0]) {
- case TELQUAL_SEND: /* SEND terminal type? */
- if ( !tn_outst(0) || tn_init ) {
- if (tn_sttyp() < 0) /* Yes, so send it. */
- return(-1);
- } else {
- TELOPT_SB(TELOPT_TTYPE).term.need_to_send = 1;
- }
- break;
- case TELQUAL_IS: { /* IS terminal type? */
- /* IS terminal type -- remote gave us its current type */
- int i = 0;
- #ifndef OS2
- CHAR oldterm[64], *p;
- #endif /* OS2 */
- /* Isolate the specified terminal type string */
- while (sb[i++] != IAC) {
- if (i == 40 || /* max len of term string - RFC */
- sb[i] == IAC) {
- sb[i] = ' ';
- break;
- }
- }
- #ifdef OS2
- strupr(&(sb[1])); /* Upper case it */
- for (i = 0; i <= max_tt; i++) { /* find it in our list */
- if (!strcmp(&(sb[1]),tt_info[i].x_name)
- && i != TT_VTNT) /* can't support VTNT as server */
- {
- /* Set terminal type to the one chosen */
- if (i != tt_type)
- settermtype(i,0);
- break;
- }
- }
- if (i > max_tt &&
- strcmp(&(sb[1]),TELOPT_SB(TELOPT_TTYPE).term.type)) {
- /* Couldn't find the specified term type */
- sb[40] = ' ';
- strcpy(TELOPT_SB(TELOPT_TTYPE).term.type,&(sb[1]));
- /* SB TTYPE SEND */
- tn_ssbopt(TELOPT_TTYPE,TELQUAL_SEND,NULL,0);
- TELOPT_UNANSWERED_SB(TELOPT_TTYPE)=1;
- }
- #else /* OS2 */
- p = (CHAR *) getenv("TERM");
- if (p)
- ckstrncpy((char *)oldterm,(char *)p,63);
- else
- oldterm[0] = ' ';
- cklower((char *)&(sb[1])); /* Lower case new term */
- sprintf(term_buf,"TERM=%s",&(sb[1]));
- #ifdef OS2ORUNIX
- #ifndef NOPUTENV
- putenv(term_buf);
- #endif /* NOPUTENV */
- #endif /* OS2ORUNIX */
- #ifdef CK_CURSES
- #ifndef MYCURSES
- #ifndef COHERENT
- if (trmbuf) {
- if (tgetent(trmbuf,(char *)&sb[1]) < 1) {
- /* Unsupported terminal. If new and old terminal */
- /* types do not match, ask for another type. */
- if (strcmp((char *)oldterm,(char *)&sb[1])) {
- /* SB TTYPE SEND */
- tn_ssbopt(TELOPT_TTYPE,TELQUAL_SEND,NULL,0);
- TELOPT_UNANSWERED_SB(TELOPT_TTYPE)=1;
- }
- }
- }
- #endif /* COHERENT */
- #endif /* MYCURSES */
- #endif /* CK_CURSES */
- #endif /* OS2 */
- }
- }
- break;
- #ifdef CK_ENVIRONMENT
- #ifdef CK_XDISPLOC
- case TELOPT_XDISPLOC: /* Send X-Display Location */
- if (sb[0] == TELQUAL_SEND) {/* SEND X-Display Loc? */
- if ( !tn_outst(0) || tn_init ) {
- if (tn_sxdisploc() < 0) /* Yes, so send it. */
- return(-1);
- } else {
- TELOPT_SB(TELOPT_XDISPLOC).xdisp.need_to_send = 1;
- }
- }
- /* IS -- X Display Location (not supported) */
- else if (sb[0] == TELQUAL_IS) {
- int i = 0;
- /* Isolate the specified X-display string */
- while (sb[i++] != IAC) {
- if (i >= TSBUFSIZ)
- return (-1);
- if (sb[i] == IAC) {
- sb[i] = ' ';
- break;
- }
- }
- debug(F110,"TELNET SB XDISPLOC IS",&sb[1],0);
- }
- break;
- #endif /* CK_XDISPLOC */
- #endif /* CK_ENVIRONMENT */
- case TELOPT_NAWS:
- if (sstelnet
- #ifdef IKSD
- || inserver
- #endif /* IKSD */
- ) {
- int w = 0, h = 0;
- int i = 0;
- /* At this point sb[] should contain width and height */
- if (sb[i] == IAC) i++;
- w = (sb[i++] << 8); /* save upper height */
- if (sb[i] == IAC) i++;
- w += sb[i++]; /* save the width */
- if (sb[i] == IAC) i++;
- h = (sb[i++] << 8); /* save upper height */
- if (sb[i] == IAC) i++;
- h += sb[i++];
- debug(F111,"tn_doop NAWS SB","width",w);
- debug(F111,"tn_doop NAWS SB","height",h);
- if (w == 0)
- w = 80;
- if (h == 0)
- h = 24;
- if (tcp_incoming) {
- #ifdef OS2
- tt_cols[VTERM] = w;
- tt_rows[VTERM] = h;
- VscrnSetWidth(VTERM, w);
- VscrnSetHeight(VTERM, h+(tt_status?1:0));
- #ifdef IKSD
- if (inserver) {
- cmd_cols = tt_cols[VCMD] = w;
- cmd_rows = tt_rows[VCMD] = h;
- VscrnSetWidth(VCMD, w);
- VscrnSetHeight(VCMD, h);
- }
- #endif /* IKSD */
- #else /* OS2 */
- tt_cols = w;
- tt_rows = h;
- #endif /* OS2 */
- } else {
- #ifdef OS2
- tt_cols[VCMD] = w;
- tt_rows[VCMD] = h;
- VscrnSetWidth(VCMD, w);
- VscrnSetHeight(VCMD, h);
- #endif /* OS2 */
- cmd_cols = w;
- cmd_rows = h;
- }
- /* Add LINES and COLUMNS to the environment */
- sprintf((char *)rows_buf,"LINES=%d",h);
- sprintf((char *)cols_buf,"COLUMNS=%d",w);
- #ifdef OS2ORUNIX
- #ifndef NOPUTENV
- putenv(rows_buf);
- putenv(cols_buf);
- #endif /* NOPUTENV */
- #endif /* OS2ORUNIX */
- }
- break;
- #ifdef CK_ENVIRONMENT
- case TELOPT_NEWENVIRON:
- switch (sb[0]) {
- case TELQUAL_IS: /* IS */
- case TELQUAL_INFO: /* INFO */
- if (sb[0] == TELQUAL_IS)
- debug(F101,"tn_doop NEW-ENV SB IS","",n-3);
- else
- debug(F101,"tn_doop NEW-ENV SB INFO","",n-3);
- if (sstelnet || inserver) { /* Yes, receive it. */
- if (tn_rnenv((CHAR *)&sb[1],n-3) < 0)
- return(-1);
- }
- break;
- case TELQUAL_SEND: /* SEND */
- if ( sstelnet || inserver ) /* ignore if server */
- break;
- /* We need to take the sb[] and build a structure */
- /* containing all of the variables and types that */
- /* we are supposed to keep track of and send to */
- /* the host, then call tn_snenv(). */
- /* Or we can punt ... */
- if ( !tn_outst(0) || tn_init ) {
- if (tn_snenv((CHAR *)&sb[1],n-3) < 0) /* Yes, send it. */
- return(-1);
- } else {
- #ifndef VMS
- CHAR * xxx;
- xxx = (CHAR *) malloc(n-1);
- #else
- unsigned char * xxx;
- xxx = (unsigned char *) malloc(n-1);
- #endif /* VMS */
- /* Postpone sending until end of tn_ini() */
- TELOPT_SB(TELOPT_NEWENVIRON).env.str = xxx;
- if (TELOPT_SB(TELOPT_NEWENVIRON).env.str) {
- ckmemcpy((char *)TELOPT_SB(TELOPT_NEWENVIRON).env.str,
- (char *)&sb[1],n-3);
- TELOPT_SB(TELOPT_NEWENVIRON).env.str[n-3] = IAC;
- TELOPT_SB(TELOPT_NEWENVIRON).env.str[n-2] = ' ';
- TELOPT_SB(TELOPT_NEWENVIRON).env.len = n-3;
- TELOPT_SB(TELOPT_NEWENVIRON).env.need_to_send = 1;
- }
- }
- break;
- }
- break;
- #endif /* CK_ENVIRONMENT */
- #ifdef CK_SNDLOC
- case TELOPT_SNDLOC: {
- if ( deblog ) {
- sb[n-2] = ' ';
- debug(F110,"TELNET Send-Location",sb,0);
- }
- break;
- }
- #endif /* CK_SNDLOC */
- } /* switch */
- break;
- }
- return(0);
- }
- #ifdef CK_ENVIRONMENT
- /* Telnet receive new environment */
- /* Returns -1 on error, 0 if nothing happens, 1 on success */
- /* In order for this code to work, sb[len] == IAC */
- /* We currently only support the USER environment variable */
- int
- #ifdef CK_ANSIC
- tn_rnenv(CHAR * sb, int len)
- #else
- tn_rnenv(sb, len) CHAR * sb; int len;
- #endif /* CK_ANSIC */
- /* tn_rnenv */ { /* Receive new environment */
- char varname[17];
- char value[65];
- char * reply = 0, * s = 0;
- int i,j,k,n; /* Worker. */
- int type = 0; /* 0 for NONE, 1 for VAR, 2 for USERVAR, */
- /* 3 for VALUE in progress */
- if (ttnet != NET_TCPB) return(0);
- if (ttnproto != NP_TELNET) return(0);
- if (sb == NULL) return(-1);
- if (len == 0) return(1);
- /*
- Pairs of <type> [VAR=0, VALUE=1, ESC=2, USERVAR=3] <value> "unterminated"
- follow here until done...
- */
- for (i = 0, j = 0, k = 0, type = 0, varname[0]= ' '; i <= len; i++) {
- switch (sb[i]) {
- case TEL_ENV_VAR: /* VAR */
- case TEL_ENV_USERVAR: /* USERVAR */
- case IAC: /* End of the list */
- switch (type) {
- case 0: /* Nothing in progress */
- /* If we get IAC only, then that means there were */
- /* no environment variables to send. we are done */
- if (j == 0 && sb[i] == IAC)
- return(1);
- case 1: /* VAR in progress */
- case 2: /* USERVAR in progress */
- case 3: /* VALUE in progress */
- value[k] = ' ';
- varname[j] = ' ';
- debug(F111,"tn_rnenv varname",varname,type);
- debug(F111,"tn_rnenv value",value,type);
- if (!strcmp(varname,"USER")) {
- #ifdef CK_AUTHENTICATION
- if (ck_tn_auth_valid() != AUTH_VALID) {
- extern char szUserNameRequested[];
- debug(F100,"tn_rnenv != AUTH_VALID","",0);
- ckstrncpy(szUserNameRequested,value,UIDBUFLEN);
- ckstrncpy(uidbuf,value,UIDBUFLEN);
- #ifdef CK_SSL
- if (ssl_active_flag) {
- if ( tls_is_user_valid(ssl_con, uidbuf) ) {
- extern char szUserNameAuthenticated[];
- ckstrncpy(szUserNameAuthenticated,uidbuf,
- UIDBUFLEN);
- auth_finished(AUTH_VALID);
- }
- } else if (tls_active_flag) {
- if ( tls_is_user_valid(tls_con, uidbuf) ) {
- extern char szUserNameAuthenticated[];
- ckstrncpy(szUserNameAuthenticated,uidbuf,
- UIDBUFLEN);
- auth_finished(AUTH_VALID);
- }
- }
- #endif /* CK_SSL */
- } else { /* AUTH_VALID */
- debug(F110,"tn_rnenv AUTH_VALID uidbuf",uidbuf,0);
- if ( strcmp(value,uidbuf) ) {
- extern char szUserNameRequested[];
- ckstrncpy(uidbuf,value,UIDBUFLEN);
- ckstrncpy(szUserNameRequested,value,UIDBUFLEN);
- auth_finished(AUTH_USER);
- #ifdef CK_SSL
- if (ssl_active_flag || tls_active_flag) {
- if ( tls_is_user_valid(ssl_con, uidbuf) )
- auth_finished(AUTH_VALID);
- }
- #endif /* CK_SSL */
- }
- }
- #else /* CK_AUTHENTICATION */
- ckstrncpy(uidbuf,value,UIDBUFLEN);
- #endif /* CK_AUTHENTICATION */
- }
- break;
- }
- varname[0] = ' ';
- value[0] = ' ';
- j = 0;
- k = 0;
- type = (sb[i] == TEL_ENV_USERVAR ? 2 : /* USERVAR */
- sb[i] == TEL_ENV_VAR ? 1 : /* VAR */
- 0
- );
- break;
- case TEL_ENV_VALUE: /* VALUE */
- if ( type == 1 || type == 2 )
- type = 3;
- break;
- case TEL_ENV_ESC: /* ESC */
- /* Take next character literally */
- if ( ++i >= len )
- break;
- /* otherwise, fallthrough so byte will be added to string. */
- default:
- switch (type) {
- case 1: /* VAR in progress */
- case 2: /* USERVAR in progress */
- if ( j < 16 )
- varname[j++] = sb[i];
- break;
- case 3:
- if ( k < 64 )
- value[k++] = sb[i];
- break;
- }
- }
- }
- return(0);
- }
- /* Telnet send new environment */
- /* Returns -1 on error, 0 if nothing happens, 1 on success */
- /* In order for this code to work, sb[len] == IAC */
- int
- #ifdef CK_ANSIC
- tn_snenv(CHAR * sb, int len)
- #else
- tn_snenv(sb, len) CHAR * sb; int len;
- #endif /* CK_ANSIC */
- /* tn_snenv */ { /* Send new environment */
- char varname[16];
- char * reply = 0, * s = 0;
- int i,j,n; /* Worker. */
- int type = 0; /* 0 for NONE, 1 for VAR, 2 for USERVAR in progress */
- extern int ck_lcname;
- char localuidbuf[UIDBUFLEN];
- char * uu = uidbuf;
- char * disp = NULL, tmploc[256];
- if (ttnet != NET_TCPB) return(0);
- if (ttnproto != NP_TELNET) return(0);
- if (!sb) return(-1);
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) {
- return(0);
- }
- #endif /* CK_SSL */
- /* Must compute the DISPLAY string we are going to send to the host */
- /* If one is not assigned, do not send a string unless the user has */
- /* explicitedly requested we try to send one via X-Display Location */
- if (tn_env_disp[0]) {
- int colon = ckindex(":",tn_env_disp,0,0,1);
- if ( !colon ) {
- sprintf(tmploc,"%s:%s",myipaddr,tn_env_disp);
- disp = tmploc;
- } else if ( ckindex("localhost:",tn_env_disp,0,0,0) ||
- ckindex("127.0.0.1:",tn_env_disp,0,0,0) ||
- ckindex("0:",tn_env_disp,0,0,0) ) {
- sprintf(tmploc,"%s:%s",myipaddr,&tn_env_disp[colon]);
- disp = tmploc;
- } else
- disp = tn_env_disp;
- }
- else if (TELOPT_ME_MODE(TELOPT_XDISPLOC)) {
- sprintf(tmploc,"%s:0.0",myipaddr);
- disp = tmploc;
- }
- if (ck_lcname) {
- ckstrncpy(localuidbuf,uidbuf,UIDBUFLEN);
- cklower(localuidbuf);
- uu = localuidbuf;
- }
- hexdump((CHAR *)"tn_snenv sb[]",sb,len);
- debug(F110,"tn_snenv uidbuf",uidbuf,0);
- debug(F110,"tn_snenv localuidbuf",localuidbuf,0);
- debug(F110,"tn_snenv tn_env_sys",tn_env_sys,0);
- debug(F110,"tn_snenv tn_env_disp",tn_env_disp,0);
- debug(F110,"tn_snenv disp",disp,0);
- /* First determine the size of the buffer we will need */
- for (i = 0, j = 0, n = 0, type = 0, varname[0]= ' '; i <= len; i++) {
- switch (sb[i]) {
- case TEL_ENV_VAR: /* VAR */
- case TEL_ENV_USERVAR: /* USERVAR */
- case IAC: /* End of the list */
- switch (type) {
- case 0: /* Nothing in progress */
- /* If we get IAC only, then that means send all */
- /* VAR and USERVAR. But since we don't support */
- /* USERVAR yet, we can just pass through */
- if (!(j == 0 && sb[i] == IAC))
- break;
- case 1: /* VAR in progress */
- varname[j] = ' ' ;
- if (!varname[0]) { /* Send All */
- if (uu[0])
- n += strlen(uu) + 4 + 2;
- if (tn_env_job[0])
- n += strlen(tn_env_job) + 3 + 2;
- if (tn_env_acct[0])
- n += strlen(tn_env_acct) + 4 + 2;
- if (tn_env_prnt[0])
- n += strlen(tn_env_prnt) + 7 + 2;
- if (tn_env_sys[0])
- n += strlen(tn_env_sys) + 10 + 2;
- if (tn_env_disp[0])
- n += strlen(tn_env_disp) + 7 + 2;
- } else if (!strcmp(varname,"USER") && uu[0])
- n += strlen(uu) + 4 + 2;
- else if (!strcmp(varname,"JOB") && tn_env_job[0])
- n += strlen(tn_env_job) + 3 + 2;
- else if (!strcmp(varname,"ACCT") && tn_env_acct[0])
- n += strlen(tn_env_acct) + 4 + 2;
- else if (!strcmp(varname,"PRINTER") && tn_env_prnt[0])
- n += strlen(tn_env_prnt) + 7 + 2;
- else if (!strcmp(varname,"SYSTEMTYPE") && tn_env_sys[0])
- n += strlen(tn_env_sys) + 10 + 2;
- else if (!strcmp(varname,"DISPLAY") && disp)
- n += strlen(disp) + 7 + 2;
- break;
- case 2: /* USERVAR in progress */
- break; /* We don't support this yet */
- }
- varname[0] = ' ';
- j = 0;
- type = (sb[i] == TEL_ENV_USERVAR ? 2 : /* USERVAR */
- sb[i] == TEL_ENV_VAR ? 1 : /* VAR */
- 0
- );
- break;
- case TEL_ENV_VALUE: /* VALUE */
- /* Protocol Error */
- debug(F100, "TELNET Subnegotiation error - VALUE in SEND", "",0);
- if (tn_deb || debses)
- tn_debug("TELNET Subnegotiation error - VALUE in SEND");
- return(0);
- case TEL_ENV_ESC: /* ESC */
- if (++i >= len)
- break;
- default:
- if (j < 16 )
- varname[j++] = sb[i];
- }
- }
- reply = malloc(n + 16); /* Leave room for IAC stuff */
- if (!reply) {
- debug(F100, "TELNET Subnegotiation error - malloc failed", "",0);
- if (tn_deb || debses)
- tn_debug("TELNET Subnegotiation error - malloc failed");
- /* Send a return packet with no variables so that the host */
- /* may continue with additional negotiations */
- if (tn_ssbopt(TELOPT_NEWENVIRON,TELQUAL_IS,"",0) < 0)
- return(-1);
- return(0);
- }
- /* Now construct the real reply */
- n = 0; /* Start at beginning of buffer */
- /*
- Pairs of <type> [VAR=0, VALUE=1, ESC=2, USERVAR=3] <value> "unterminated"
- follow here until done...
- */
- for (i = 0, j = 0, type = 0, varname[0]= ' '; i <= len; i++) {
- switch (sb[i]) {
- case TEL_ENV_VAR: /* VAR */
- case TEL_ENV_USERVAR: /* USERVAR */
- case IAC: /* End of the list */
- switch (type) {
- case 0: /* Nothing in progress */
- /* If we get IAC only, then that means send all */
- /* VAR and USERVAR. But since we don't support */
- /* USERVAR yet, we can just pass through */
- if (!(j == 0 && sb[i] == IAC))
- break;
- case 1: /* VAR in progress */
- varname[j] = ' ';
- if (!varname[0]) {
- /* Send All */
- if (uu[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"USER");
- reply[n+5] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+6],uu);
- n += strlen(uu) + 4 + 2;
- }
- if (tn_env_job[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"JOB");
- reply[n+4] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+5],tn_env_job);
- n += strlen(tn_env_job) + 3 + 2;
- }
- if (tn_env_acct[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"ACCT");
- reply[n+5] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+6],tn_env_acct);
- n += strlen(tn_env_acct) + 4 + 2;
- }
- if (tn_env_prnt[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"PRINTER");
- reply[n+8] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+9],tn_env_prnt);
- n += strlen(tn_env_prnt) + 7 + 2;
- }
- if (tn_env_sys[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"SYSTEMTYPE");
- reply[n+11] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+12],tn_env_sys);
- n += strlen(tn_env_sys) + 10 + 2;
- }
- if (disp) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"DISPLAY");
- reply[n+8] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+9],disp);
- n += strlen(disp) + 7 + 2;
- }
- } else if (!strcmp(varname,"USER") && uu[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"USER");
- reply[n+5] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+6],uu);
- n += strlen(uu) + 4 + 2;
- } else if (!strcmp(varname,"JOB") && tn_env_job[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"JOB");
- reply[n+4] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+5],tn_env_job);
- n += strlen(tn_env_job) + 3 + 2;
- } else if (!strcmp(varname,"ACCT") && tn_env_acct[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"ACCT");
- reply[n+5] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+6],tn_env_acct);
- n += strlen(tn_env_acct) + 4 + 2;
- } else if (!strcmp(varname,"PRINTER") && tn_env_prnt[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"PRINTER");
- reply[n+8] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+9],tn_env_prnt);
- n += strlen(tn_env_prnt) + 7 + 2;
- } else if (!strcmp(varname,"SYSTEMTYPE") && tn_env_sys[0]) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"SYSTEMTYPE");
- reply[n+11] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+12],tn_env_sys);
- n += strlen(tn_env_sys) + 10 + 2;
- } else if (!strcmp(varname,"DISPLAY") && disp) {
- reply[n] = TEL_ENV_VAR; /* VAR */
- strcpy(&reply[n+1],"DISPLAY");
- reply[n+8] = TEL_ENV_VALUE; /* VALUE */
- strcpy(&reply[n+9],disp);
- n += strlen(disp) + 7 + 2;
- }
- break;
- case 2: /* USERVAR in progress */
- /* we don't support this yet */
- break;
- }
- varname[0] = ' ';
- j = 0;
- type = (sb[i] == TEL_ENV_USERVAR ? 2 : /* USERVAR */
- sb[i] == TEL_ENV_VAR ? 1 : /* VAR */
- 0
- );
- break;
- case TEL_ENV_VALUE: /* VALUE */
- /* Protocol Error */
- debug(F100, "TELNET Subnegotiation error - VALUE in SEND", "",0);
- if (tn_deb || debses)
- tn_debug("TELNET Subnegotiation error - VALUE in SEND");
- return(0); /* Was -1 but that would be taken as */
- /* an I/O error, so absorb it and go on. */
- case TEL_ENV_ESC: /* ESC */
- /* Not sure what this for. Quote next character? */
- break;
- default:
- varname[j++] = sb[i];
- }
- }
- if (tn_ssbopt(TELOPT_NEWENVIRON,TELQUAL_IS,reply,n) < 0) {
- free(reply);
- return(-1);
- }
- free(reply);
- return(1);
- }
- #endif /* CK_ENVIRONMENT */
- /* Telnet send terminal type */
- /* Returns -1 on error, 0 if nothing happens, 1 if type sent successfully */
- int
- tn_sttyp() { /* Send telnet terminal type. */
- char *ttn; /* Name of terminal type. */
- #ifdef OS2
- static int alias = -1; /* which alias are we using ? */
- #endif /* OS2 */
- int i; /* Worker. */
- int tntermflg = 0;
- int settype = 0;
- if (ttnet != NET_TCPB) return(0);
- if (ttnproto != NP_TELNET) return(0);
- if (!TELOPT_ME(TELOPT_TTYPE)) return(0);
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) {
- return(0);
- }
- #endif /* CK_SSL */
- ttn = NULL;
- #ifdef OS2
- if (!tn_term) {
- if (ttnum == -1) {
- ttnum = tt_type;
- settype = 0;
- alias = -1;
- } else if (ttnumend) {
- ttnumend = 0;
- settype = 0;
- } else {
- if (tt_info[tt_type].x_aliases[++alias] == NULL) {
- if (--tt_type < 0)
- tt_type = max_tt;
- if (ttnum == tt_type)
- ttnumend = 1;
- settype = 1;
- alias = -1;
- }
- }
- if (tt_type >= 0 && tt_type <= max_tt) {
- if (alias == -1)
- ttn = tt_info[tt_type].x_name;
- else
- ttn = tt_info[tt_type].x_aliases[alias];
- } else
- ttn = NULL;
- }
- else settype = 0;
- #endif /* OS2 */
- if (tn_term) { /* Terminal type override? */
- debug(F110,"tn_sttyp",tn_term,0);
- if (*tn_term) {
- ttn = tn_term;
- tntermflg = 1;
- }
- } else debug(F100,"tn_sttyp no term override","",0);
- #ifndef datageneral
- if (!ttn) { /* If no override, */
- ttn = getenv("TERM"); /* get it from the environment. */
- }
- #endif /* datageneral */
- if ((ttn == ((char *)0)) || ((int)strlen(ttn) >= TSBUFSIZ))
- ttn = "UNKNOWN";
- sb[0] = (CHAR) IAC; /* I Am a Command */
- sb[1] = (CHAR) SB; /* Subnegotiation */
- sb[2] = TELOPT_TTYPE; /* Terminal Type */
- sb[3] = (CHAR) 0; /* Is... */
- for (i = 4; *ttn; ttn++,i++) { /* Copy and uppercase it */
- #ifdef VMS
- if (!tntermflg && *ttn == '-' &&
- (!strcmp(ttn,"-80") || !strcmp(ttn,"-132")))
- break;
- else
- #endif /* VMS */
- sb[i] = (char) ((!tntermflg && islower(*ttn)) ? toupper(*ttn) : *ttn);
- }
- ttn = (char *)sb; /* Point back to beginning */
- if (deblog || tn_deb || debses) {
- sb[i] = ' '; /* For debugging */
- sprintf(tn_msg,"TELNET SENT SB %s IS %s IAC SE",
- TELOPT(TELOPT_TTYPE),sb+4);
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses) tn_debug(tn_msg);
- }
- sb[i++] = (CHAR) IAC; /* End of Subnegotiation */
- sb[i++] = (CHAR) SE; /* marked by IAC SE */
- if (ttol((CHAR *)sb,i) < 0) /* Send it. */
- return(-1);
- #ifdef OS2
- if (settype)
- settermtype(tt_type,0);
- else {
- ipadl25();
- VscrnIsDirty(VTERM);
- }
- #endif /* OS2 */
- return(1);
- }
- #ifdef CK_ENVIRONMENT
- #ifdef CK_XDISPLOC
- /* Telnet send xdisplay location */
- /* Returns -1 on error, 0 if nothing happens, 1 if type sent successfully */
- int
- tn_sxdisploc() { /* Send telnet X display location. */
- char * disp=NULL;
- char tmploc[256];
- int i;
- tmploc[0] = ' ';
- if (ttnet != NET_TCPB) return(0);
- if (ttnproto != NP_TELNET) return(0);
- if (!TELOPT_ME(TELOPT_XDISPLOC)) return(0);
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) {
- return(0);
- }
- #endif /* CK_SSL */
- if (tn_env_disp[0]) {
- int colon = ckindex(":",tn_env_disp,0,0,1);
- if ( !colon ) {
- sprintf(tmploc,"%s:%s",myipaddr,tn_env_disp);
- disp = tmploc;
- } else if ( ckindex("localhost:",tn_env_disp,0,0,0) ||
- ckindex("127.0.0.1:",tn_env_disp,0,0,0) ||
- ckindex("0:",tn_env_disp,0,0,0) ) {
- sprintf(tmploc,"%s:%s",myipaddr,&tn_env_disp[colon]);
- disp = tmploc;
- } else
- disp = tn_env_disp;
- } else {
- sprintf(tmploc,"%s:0.0",myipaddr);
- disp = tmploc;
- }
- debug(F110,"tn_sxdisploc",disp,0);
- sb[0] = (CHAR) IAC; /* I Am a Command */
- sb[1] = (CHAR) SB; /* Subnegotiation */
- sb[2] = TELOPT_XDISPLOC; /* X-Display Location */
- sb[3] = (CHAR) 0; /* Is... */
- for (i = 4; *disp; disp++,i++) { /* Copy and uppercase it */
- sb[i] = (char) *disp;
- }
- if (deblog || tn_deb || debses) {
- sb[i] = ' '; /* For debugging */
- sprintf(tn_msg,
- "TELNET SENT SB %s IS %s IAC SE",
- TELOPT(TELOPT_XDISPLOC),sb+4);
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses) tn_debug(tn_msg);
- }
- sb[i++] = (CHAR) IAC; /* End of Subnegotiation */
- sb[i++] = (CHAR) SE; /* marked by IAC SE */
- if (ttol((CHAR *)sb,i) < 0) /* Send it. */
- return(-1);
- return(1);
- }
- #endif /* CK_XDISPLOC */
- #endif /* CK_ENVIRONMENT */
- #ifdef CK_FORWARD_X
- int
- tn_sndfwdx() { /* Send Fwd X Screen number to host */
- unsigned char screen = 0;
- if (!TELOPT_U(TELOPT_FORWARD_X)) return(0);
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) {
- return(0);
- }
- #endif /* CK_SSL */
- /*
- * The format of the DISPLAY variable is [<host>:]<display>[.<screen>]
- * where <host> is an optional DNS name or ip address with a default of
- * the localhost; the screen defaults to 0
- */
- if (tn_env_disp[0]) {
- int colon,dot;
- colon = ckindex(":",tn_env_disp,0,0,1);
- dot = ckindex(".",&tn_env_disp[colon],0,0,1);
- if ( dot ) {
- screen = atoi(&tn_env_disp[colon+dot]);
- }
- } else {
- return(-1);
- }
- sb[0] = (CHAR) IAC; /* I Am a Command */
- sb[1] = (CHAR) SB; /* Subnegotiation */
- sb[2] = TELOPT_FORWARD_X; /* Forward X */
- sb[3] = FWDX_SCREEN; /* Screen */
- sb[4] = screen;
- sb[5] = (CHAR) IAC; /* End of Subnegotiation */
- sb[6] = (CHAR) SE; /* marked by IAC SE */
- if (ttol((CHAR *)sb,7) < 0) /* Send it. */
- return(-1);
- #ifdef DEBUG
- if (deblog || tn_deb || debses) {
- sprintf(tn_msg,"TELNET SENT SB %s SCREEN %02x IAC SE",
- TELOPT(TELOPT_FORWARD_X),screen);
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses) tn_debug(tn_msg);
- }
- #endif /* DEBUG */
- return(0);
- }
- #endif /* CK_FORWARD_X */
- #ifdef CK_SNDLOC
- int
- tn_sndloc() { /* Send location. */
- int i; /* Worker. */
- char *ttloc;
- if (!TELOPT_ME(TELOPT_SNDLOC)) return(0);
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) {
- return(0);
- }
- #endif /* CK_SSL */
- ttloc = (tn_loc ? tn_loc : ""); /* In case we are being called even */
- /* though there is no location. */
- sb[0] = (CHAR) IAC; /* I Am a Command */
- sb[1] = (CHAR) SB; /* Subnegotiation */
- sb[2] = TELOPT_SNDLOC; /* Location */
- for (i = 3; *ttloc && i < TSBUFSIZ; ttloc++,i++) /* Copy it */
- sb[i] = (char) *ttloc;
- sb[i++] = (CHAR) IAC; /* End of Subnegotiation */
- sb[i++] = (CHAR) SE; /* marked by IAC SE */
- if (ttol((CHAR *)sb,i) < 0) /* Send it. */
- return(-1);
- sb[i-2] = ' '; /* For debugging */
- #ifdef DEBUG
- if (deblog || tn_deb || debses) {
- sprintf(tn_msg,"TELNET SENT SB %s %s IAC SE",
- TELOPT(TELOPT_SNDLOC),sb+3);
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses) tn_debug(tn_msg);
- }
- #endif /* DEBUG */
- return(0);
- }
- #endif /* CK_SNDLOC */
- #ifdef CK_NAWS /* NAWS = Negotiate About Window Size */
- int
- tn_snaws() { /* Send terminal width and height, RFC 1073 */
- int i = 0;
- #ifdef OS2
- int x = VscrnGetWidth(VTERM),
- y = VscrnGetHeight(VTERM) - (tt_status ? 1 : 0);
- #else /* OS2 */
- int x = tt_cols, y = tt_rows;
- #endif /* OS2 */
- if (ttnet != NET_TCPB) return(0);
- if (ttnproto != NP_TELNET) return(0);
- if (!TELOPT_ME(TELOPT_NAWS)) return(0);
- #ifdef CK_SSL
- if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) {
- return(0);
- }
- #endif /* CK_SSL */
- if (x < 0) x = 0;
- if (y < 0) y = 0;
- if (x == TELOPT_SB(TELOPT_NAWS).naws.x && /* Only send if changed */
- y == TELOPT_SB(TELOPT_NAWS).naws.y
- )
- return(0);
- TELOPT_SB(TELOPT_NAWS).naws.x = x; /* Remember the size */
- TELOPT_SB(TELOPT_NAWS).naws.y = y;
- sb[i++] = (CHAR) IAC; /* Send the subnegotiation */
- sb[i++] = (CHAR) SB;
- sb[i++] = TELOPT_NAWS;
- sb[i++] = (CHAR) (x >> 8) & 0xff;
- if ((CHAR) sb[i-1] == (CHAR) IAC) /* IAC in data must be doubled */
- sb[i++] = (CHAR) IAC;
- sb[i++] = (CHAR) (x & 0xff);
- if ((CHAR) sb[i-1] == (CHAR) IAC)
- sb[i++] = (CHAR) IAC;
- sb[i++] = (CHAR) (y >> 8) & 0xff;
- if ((CHAR) sb[i-1] == (CHAR) IAC)
- sb[i++] = (CHAR) IAC;
- sb[i++] = (CHAR) (y & 0xff);
- if ((CHAR) sb[i-1] == (CHAR) IAC)
- sb[i++] = (CHAR) IAC;
- sb[i++] = (CHAR) IAC;
- sb[i++] = (CHAR) SE;
- if (deblog || tn_deb || debses) {
- sprintf(tn_msg,"TELNET SENT SB NAWS %d %d IAC SE",x,y);
- debug(F100,tn_msg,"",0);
- if (tn_deb || debses) tn_debug(tn_msg);
- }
- if (ttol((CHAR *)sb,i) < 0) /* Send it. */
- return(-1);
- return (0);
- }
- #endif /* CK_NAWS */
- #endif /* TNCODE */