• Home
  • Raw
  • Download

Lines Matching +full:- +full:- +full:disable +full:- +full:telnet

21  * SPDX-License-Identifier: curl
53 #include "telnet.h"
69 #define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer
72 x->subend = x->subpointer; \
77 if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) \
78 *x->subpointer++ = (c); \
81 #define CURL_SB_GET(x) ((*x->subpointer++)&0xff)
82 #define CURL_SB_LEN(x) (x->subend - x->subpointer)
85 #define CURL_SB_PEEK(x) ((*x->subpointer)&0xff)
86 #define CURL_SB_EOF(x) (x->subpointer >= x->subend) */
132 * Telnet receiver states for fsm
143 CURL_TS_SB, /* sub-option collection */
144 CURL_TS_SE /* looking for sub-option end */
147 struct TELNET { struct
167 unsigned char *subpointer, *subend; /* buffer for sub-options */
172 * TELNET protocol handler. argument
176 "telnet", /* scheme */
203 struct TELNET *tn; in init_telnet()
205 tn = calloc(1, sizeof(struct TELNET)); in init_telnet()
209 Curl_dyn_init(&tn->out, 0xffff); in init_telnet()
210 data->req.p.telnet = tn; /* make us known */ in init_telnet()
212 tn->telrcv_state = CURL_TS_DATA; in init_telnet()
218 tn->us_preferred[CURL_TELOPT_SGA] = CURL_YES; in init_telnet()
219 tn->him_preferred[CURL_TELOPT_SGA] = CURL_YES; in init_telnet()
226 tn->us_preferred[CURL_TELOPT_BINARY] = CURL_YES; in init_telnet()
227 tn->him_preferred[CURL_TELOPT_BINARY] = CURL_YES; in init_telnet()
235 tn->him_preferred[CURL_TELOPT_ECHO] = CURL_YES; in init_telnet()
245 Telnet server is operating system specific (it will probably be in init_telnet()
247 using the TERMINAL TYPE Telnet option). */ in init_telnet()
248 tn->subnegotiation[CURL_TELOPT_NAWS] = CURL_YES; in init_telnet()
255 struct TELNET *tn = data->req.p.telnet; in negotiate()
261 if(tn->us_preferred[i] == CURL_YES) in negotiate()
264 if(tn->him_preferred[i] == CURL_YES) in negotiate()
273 if(data->set.verbose) { in printoption()
310 struct connectdata *conn = data->conn; in send_negotiation()
316 bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3); in send_negotiation()
328 struct TELNET *tn = data->req.p.telnet; in set_remote_option()
330 switch(tn->him[option]) { in set_remote_option()
332 tn->him[option] = CURL_WANTYES; in set_remote_option()
341 switch(tn->himq[option]) { in set_remote_option()
344 tn->himq[option] = CURL_OPPOSITE; in set_remote_option()
353 switch(tn->himq[option]) { in set_remote_option()
358 tn->himq[option] = CURL_EMPTY; in set_remote_option()
365 switch(tn->him[option]) { in set_remote_option()
371 tn->him[option] = CURL_WANTNO; in set_remote_option()
376 switch(tn->himq[option]) { in set_remote_option()
381 tn->himq[option] = CURL_EMPTY; in set_remote_option()
387 switch(tn->himq[option]) { in set_remote_option()
389 tn->himq[option] = CURL_OPPOSITE; in set_remote_option()
402 struct TELNET *tn = data->req.p.telnet; in rec_will()
403 switch(tn->him[option]) { in rec_will()
405 if(tn->him_preferred[option] == CURL_YES) { in rec_will()
406 tn->him[option] = CURL_YES; in rec_will()
419 switch(tn->himq[option]) { in rec_will()
422 tn->him[option] = CURL_NO; in rec_will()
426 tn->him[option] = CURL_YES; in rec_will()
427 tn->himq[option] = CURL_EMPTY; in rec_will()
433 switch(tn->himq[option]) { in rec_will()
435 tn->him[option] = CURL_YES; in rec_will()
438 tn->him[option] = CURL_WANTNO; in rec_will()
439 tn->himq[option] = CURL_EMPTY; in rec_will()
450 struct TELNET *tn = data->req.p.telnet; in rec_wont()
451 switch(tn->him[option]) { in rec_wont()
457 tn->him[option] = CURL_NO; in rec_wont()
462 switch(tn->himq[option]) { in rec_wont()
464 tn->him[option] = CURL_NO; in rec_wont()
468 tn->him[option] = CURL_WANTYES; in rec_wont()
469 tn->himq[option] = CURL_EMPTY; in rec_wont()
476 switch(tn->himq[option]) { in rec_wont()
478 tn->him[option] = CURL_NO; in rec_wont()
481 tn->him[option] = CURL_NO; in rec_wont()
482 tn->himq[option] = CURL_EMPTY; in rec_wont()
492 struct TELNET *tn = data->req.p.telnet; in set_local_option()
494 switch(tn->us[option]) { in set_local_option()
496 tn->us[option] = CURL_WANTYES; in set_local_option()
505 switch(tn->usq[option]) { in set_local_option()
508 tn->usq[option] = CURL_OPPOSITE; in set_local_option()
517 switch(tn->usq[option]) { in set_local_option()
522 tn->usq[option] = CURL_EMPTY; in set_local_option()
529 switch(tn->us[option]) { in set_local_option()
535 tn->us[option] = CURL_WANTNO; in set_local_option()
540 switch(tn->usq[option]) { in set_local_option()
545 tn->usq[option] = CURL_EMPTY; in set_local_option()
551 switch(tn->usq[option]) { in set_local_option()
553 tn->usq[option] = CURL_OPPOSITE; in set_local_option()
566 struct TELNET *tn = data->req.p.telnet; in rec_do()
567 switch(tn->us[option]) { in rec_do()
569 if(tn->us_preferred[option] == CURL_YES) { in rec_do()
570 tn->us[option] = CURL_YES; in rec_do()
572 if(tn->subnegotiation[option] == CURL_YES) in rec_do()
576 else if(tn->subnegotiation[option] == CURL_YES) { in rec_do()
578 tn->us[option] = CURL_YES; in rec_do()
591 switch(tn->usq[option]) { in rec_do()
594 tn->us[option] = CURL_NO; in rec_do()
598 tn->us[option] = CURL_YES; in rec_do()
599 tn->usq[option] = CURL_EMPTY; in rec_do()
605 switch(tn->usq[option]) { in rec_do()
607 tn->us[option] = CURL_YES; in rec_do()
608 if(tn->subnegotiation[option] == CURL_YES) { in rec_do()
614 tn->us[option] = CURL_WANTNO; in rec_do()
615 tn->himq[option] = CURL_EMPTY; in rec_do()
626 struct TELNET *tn = data->req.p.telnet; in rec_dont()
627 switch(tn->us[option]) { in rec_dont()
633 tn->us[option] = CURL_NO; in rec_dont()
638 switch(tn->usq[option]) { in rec_dont()
640 tn->us[option] = CURL_NO; in rec_dont()
644 tn->us[option] = CURL_WANTYES; in rec_dont()
645 tn->usq[option] = CURL_EMPTY; in rec_dont()
652 switch(tn->usq[option]) { in rec_dont()
654 tn->us[option] = CURL_NO; in rec_dont()
657 tn->us[option] = CURL_NO; in rec_dont()
658 tn->usq[option] = CURL_EMPTY; in rec_dont()
671 if(data->set.verbose) { in printsub()
678 i = pointer[length-2]; in printsub()
679 j = pointer[length-1]; in printsub()
698 length -= 2; in printsub()
779 #pragma warning(disable:4706)
798 struct TELNET *tn = data->req.p.telnet; in check_telnet_options()
803 if(data->state.aptr.user) { in check_telnet_options()
805 if(str_is_nonascii(data->conn->user)) { in check_telnet_options()
806 DEBUGF(infof(data, "set a non ASCII user name in telnet")); in check_telnet_options()
809 msnprintf(buffer, sizeof(buffer), "USER,%s", data->conn->user); in check_telnet_options()
810 beg = curl_slist_append(tn->telnet_vars, buffer); in check_telnet_options()
812 curl_slist_free_all(tn->telnet_vars); in check_telnet_options()
813 tn->telnet_vars = NULL; in check_telnet_options()
816 tn->telnet_vars = beg; in check_telnet_options()
817 tn->us_preferred[CURL_TELOPT_NEW_ENVIRON] = CURL_YES; in check_telnet_options()
820 for(head = data->set.telnet_options; head && !result; head = head->next) { in check_telnet_options()
822 char *option = head->data; in check_telnet_options()
826 olen = sep - option; in check_telnet_options()
835 if(l < sizeof(tn->subopt_ttype)) { in check_telnet_options()
836 strcpy(tn->subopt_ttype, arg); in check_telnet_options()
837 tn->us_preferred[CURL_TELOPT_TTYPE] = CURL_YES; in check_telnet_options()
848 if(l < sizeof(tn->subopt_xdisploc)) { in check_telnet_options()
849 strcpy(tn->subopt_xdisploc, arg); in check_telnet_options()
850 tn->us_preferred[CURL_TELOPT_XDISPLOC] = CURL_YES; in check_telnet_options()
860 beg = curl_slist_append(tn->telnet_vars, arg); in check_telnet_options()
865 tn->telnet_vars = beg; in check_telnet_options()
866 tn->us_preferred[CURL_TELOPT_NEW_ENVIRON] = CURL_YES; in check_telnet_options()
882 tn->subopt_wsx = (unsigned short)x; in check_telnet_options()
883 tn->subopt_wsy = (unsigned short)y; in check_telnet_options()
884 tn->us_preferred[CURL_TELOPT_NAWS] = CURL_YES; in check_telnet_options()
888 failf(data, "Syntax error in telnet option: %s", head->data); in check_telnet_options()
901 tn->us_preferred[CURL_TELOPT_BINARY] = CURL_NO; in check_telnet_options()
902 tn->him_preferred[CURL_TELOPT_BINARY] = CURL_NO; in check_telnet_options()
909 failf(data, "Unknown telnet option %s", head->data); in check_telnet_options()
915 failf(data, "Syntax error in telnet option: %s", head->data); in check_telnet_options()
921 curl_slist_free_all(tn->telnet_vars); in check_telnet_options()
922 tn->telnet_vars = NULL; in check_telnet_options()
931 * Look at the sub-option buffer, and try to be helpful to the other
942 struct TELNET *tn = data->req.p.telnet; in suboption()
943 struct connectdata *conn = data->conn; in suboption()
945 printsub(data, '<', (unsigned char *)tn->subbuffer, CURL_SB_LEN(tn) + 2); in suboption()
948 len = strlen(tn->subopt_ttype) + 4 + 2; in suboption()
951 CURL_TELQUAL_IS, tn->subopt_ttype, CURL_IAC, CURL_SE); in suboption()
952 bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); in suboption()
957 printsub(data, '>', &temp[2], len-2); in suboption()
960 len = strlen(tn->subopt_xdisploc) + 4 + 2; in suboption()
963 CURL_TELQUAL_IS, tn->subopt_xdisploc, CURL_IAC, CURL_SE); in suboption()
964 bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); in suboption()
969 printsub(data, '>', &temp[2], len-2); in suboption()
977 for(v = tn->telnet_vars; v; v = v->next) { in suboption()
978 size_t tmplen = (strlen(v->data) + 1); in suboption()
980 if(len + tmplen < (int)sizeof(temp)-6) { in suboption()
981 char *s = strchr(v->data, ','); in suboption()
983 len += msnprintf((char *)&temp[len], sizeof(temp) - len, in suboption()
984 "%c%s", CURL_NEW_ENV_VAR, v->data); in suboption()
986 size_t vlen = s - v->data; in suboption()
987 len += msnprintf((char *)&temp[len], sizeof(temp) - len, in suboption()
989 (int)vlen, v->data, CURL_NEW_ENV_VALUE, ++s); in suboption()
993 msnprintf((char *)&temp[len], sizeof(temp) - len, in suboption()
996 bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len); in suboption()
1001 printsub(data, '>', &temp[2], len-2); in suboption()
1020 struct TELNET *tn = data->req.p.telnet; in sendsuboption()
1021 struct connectdata *conn = data->conn; in sendsuboption()
1032 x = htons(tn->subopt_wsx); in sendsuboption()
1033 y = htons(tn->subopt_wsy); in sendsuboption()
1046 printsub(data, '>', (unsigned char *)tn->subbuffer + 2, in sendsuboption()
1047 CURL_SB_LEN(tn)-2); in sendsuboption()
1050 bytes_written = swrite(conn->sock[FIRSTSOCKET], tn->subbuffer, 3); in sendsuboption()
1057 send_telnet_data(data, (char *)tn->subbuffer + 3, 4); in sendsuboption()
1059 bytes_written = swrite(conn->sock[FIRSTSOCKET], tn->subbuffer + 7, 2); in sendsuboption()
1077 int startwrite = -1; in telrcv()
1078 struct TELNET *tn = data->req.p.telnet; in telrcv()
1085 in-startwrite); \ in telrcv()
1089 startwrite = -1 in telrcv()
1097 while(count--) { in telrcv()
1100 switch(tn->telrcv_state) { in telrcv()
1102 tn->telrcv_state = CURL_TS_DATA; in telrcv()
1112 tn->telrcv_state = CURL_TS_IAC; in telrcv()
1117 tn->telrcv_state = CURL_TS_CR; in telrcv()
1126 tn->telrcv_state = CURL_TS_WILL; in telrcv()
1129 tn->telrcv_state = CURL_TS_WONT; in telrcv()
1132 tn->telrcv_state = CURL_TS_DO; in telrcv()
1135 tn->telrcv_state = CURL_TS_DONT; in telrcv()
1139 tn->telrcv_state = CURL_TS_SB; in telrcv()
1142 tn->telrcv_state = CURL_TS_DATA; in telrcv()
1149 tn->telrcv_state = CURL_TS_DATA; in telrcv()
1157 tn->please_negotiate = 1; in telrcv()
1159 tn->telrcv_state = CURL_TS_DATA; in telrcv()
1164 tn->please_negotiate = 1; in telrcv()
1166 tn->telrcv_state = CURL_TS_DATA; in telrcv()
1171 tn->please_negotiate = 1; in telrcv()
1173 tn->telrcv_state = CURL_TS_DATA; in telrcv()
1178 tn->please_negotiate = 1; in telrcv()
1180 tn->telrcv_state = CURL_TS_DATA; in telrcv()
1185 tn->telrcv_state = CURL_TS_SE; in telrcv()
1204 tn->subpointer -= 2; in telrcv()
1208 suboption(data); /* handle sub-option */ in telrcv()
1209 tn->telrcv_state = CURL_TS_IAC; in telrcv()
1213 tn->telrcv_state = CURL_TS_SB; in telrcv()
1218 tn->subpointer -= 2; in telrcv()
1220 suboption(data); /* handle sub-option */ in telrcv()
1221 tn->telrcv_state = CURL_TS_DATA; in telrcv()
1231 /* Escape and send a telnet data block */
1240 struct connectdata *conn = data->conn; in send_telnet_data()
1241 struct TELNET *tn = data->req.p.telnet; in send_telnet_data()
1250 Curl_dyn_reset(&tn->out); in send_telnet_data()
1253 result = Curl_dyn_addn(&tn->out, &buffer[i], 1); in send_telnet_data()
1256 result = Curl_dyn_addn(&tn->out, "\xff", 1); in send_telnet_data()
1259 outlen = Curl_dyn_len(&tn->out); in send_telnet_data()
1260 outbuf = Curl_dyn_uptr(&tn->out); in send_telnet_data()
1269 pfd[0].fd = conn->sock[FIRSTSOCKET]; in send_telnet_data()
1271 switch(Curl_poll(pfd, 1, -1)) { in send_telnet_data()
1272 case -1: /* error, abort writing */ in send_telnet_data()
1279 outlen - total_written, &bytes_written); in send_telnet_data()
1291 struct TELNET *tn = data->req.p.telnet; in telnet_done()
1298 curl_slist_free_all(tn->telnet_vars); in telnet_done()
1299 tn->telnet_vars = NULL; in telnet_done()
1300 Curl_dyn_free(&tn->out); in telnet_done()
1307 struct connectdata *conn = data->conn; in telnet_do()
1308 curl_socket_t sockfd = conn->sock[FIRSTSOCKET]; in telnet_do()
1329 struct TELNET *tn; in telnet_do()
1337 tn = data->req.p.telnet; in telnet_do()
1372 data->set.is_fread_set) { in telnet_do()
1393 if(data->set.is_fread_set) { in telnet_do()
1395 /* read from user-supplied method */ in telnet_do()
1396 n = data->state.fread_func(buffer, 1, buf_size, data->state.in); in telnet_do()
1476 /* returned not-zero, this an error */ in telnet_do()
1495 otherwise don't. We don't want to speak telnet with in telnet_do()
1496 non-telnet servers, like POP or SMTP. */ in telnet_do()
1497 if(tn->please_negotiate && !tn->already_negotiated) { in telnet_do()
1499 tn->already_negotiated = 1; in telnet_do()
1510 if(data->set.timeout) { in telnet_do()
1512 if(Curl_timediff(now, conn->created) >= data->set.timeout) { in telnet_do()
1513 failf(data, "Time-out"); in telnet_do()
1528 if(data->set.is_fread_set) { in telnet_do()
1530 interval_ms = 100; /* poll user-supplied read function */ in telnet_do()
1534 pfd[1].fd = fileno((FILE *)data->state.in); in telnet_do()
1548 case -1: /* error, stop reading */ in telnet_do()
1562 /* returned not-zero, this an error */ in telnet_do()
1566 * Is this the telnet test server not shutting down the socket in telnet_do()
1569 if(data->state.os_errno == ECONNRESET) { in telnet_do()
1591 otherwise don't. We don't want to speak telnet with in telnet_do()
1592 non-telnet servers, like POP or SMTP. */ in telnet_do()
1593 if(tn->please_negotiate && !tn->already_negotiated) { in telnet_do()
1595 tn->already_negotiated = 1; in telnet_do()
1606 /* read from user-supplied method */ in telnet_do()
1607 nread = (int)data->state.fread_func(buffer, 1, sizeof(buffer), in telnet_do()
1608 data->state.in); in telnet_do()
1632 if(data->set.timeout) { in telnet_do()
1634 if(Curl_timediff(now, conn->created) >= data->set.timeout) { in telnet_do()
1635 failf(data, "Time-out"); in telnet_do()
1648 Curl_xfer_setup(data, -1, -1, FALSE, -1); in telnet_do()