|
version 1.1.1.1.2.17, 2010/06/04 11:30:31
|
version 1.2.2.1, 2010/06/04 11:46:40
|
|
Line 33 static void cli_Null_Prep_Term(int meta)
|
Line 33 static void cli_Null_Prep_Term(int meta)
|
| { |
{ |
| } |
} |
| |
|
| |
#include <syslog.h> |
| static int cli_Net_rl_GetCh(FILE *s) |
static int cli_Net_rl_GetCh(FILE *s) |
| { |
{ |
| int ch = rl_getc(s); |
int ch = rl_getc(s); |
|
Line 50 static int cli_Net_rl_GetCh(FILE *s)
|
Line 51 static int cli_Net_rl_GetCh(FILE *s)
|
| return ch; |
return ch; |
| } |
} |
| |
|
| |
syslog(LOG_CRIT, "+++++ getc=%0x\n", ch); |
| cli_pending_special_char = 0; |
cli_pending_special_char = 0; |
| fputc(ch, rl_outstream); |
fputc(ch, rl_outstream); |
| fflush(rl_outstream); |
fflush(rl_outstream); |
|
Line 271 void cliNetInit(const char *csProg, int pty, struct te
|
Line 273 void cliNetInit(const char *csProg, int pty, struct te
|
| * @win = window size of tty |
* @win = window size of tty |
| * return: -1 error, 0 = exit w/^+D, 1 done. |
* return: -1 error, 0 = exit w/^+D, 1 done. |
| */ |
*/ |
| int cliNetExec(cliCommands_t *cmdList, const char *csPrompt, int sock, struct termios *term, struct winsize *win) | int |
| | cliNetExec(cliCommands_t *cmdList, const char *csPrompt, int sock, struct termios *term, struct winsize *win) |
| { |
{ |
| int pty, ret = 0, alen, attrlen, flg; | int pty, ret = 0, r, s, alen, attrlen, flg; |
| fd_set fds; |
fd_set fds; |
| struct timeval tv = { DEFAULT_SOCK_TIMEOUT, 0 }; |
struct timeval tv = { DEFAULT_SOCK_TIMEOUT, 0 }; |
| u_char buf[BUFSIZ]; |
u_char buf[BUFSIZ]; |
|
Line 286 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
Line 289 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
| case 0: |
case 0: |
| close(sock); |
close(sock); |
| |
|
| rl_prep_term_function = cli_Null_Prep_Term; |
|
| rl_getc_function = cli_Net_rl_GetCh; |
|
| |
|
| cliNetInit(getprogname(), STDIN_FILENO, term); |
|
| ret = cliExec(cmdList, csPrompt) < 0 ? 1 : 0; |
ret = cliExec(cmdList, csPrompt) < 0 ? 1 : 0; |
| /* spawn Shell mode */ |
/* spawn Shell mode */ |
| /* |
/* |
|
Line 297 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
Line 296 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
| */ |
*/ |
| _exit(ret); |
_exit(ret); |
| default: |
default: |
| cliNetInit(getprogname(), pty, term); |
|
| |
|
| /* spawn Shell mode */ |
/* spawn Shell mode */ |
| /* |
|
| telnet_SetCmd(Attr + 0, DO, TELOPT_TTYPE); |
telnet_SetCmd(Attr + 0, DO, TELOPT_TTYPE); |
| telnet_SetCmd(Attr + 1, WILL, TELOPT_ECHO); |
telnet_SetCmd(Attr + 1, WILL, TELOPT_ECHO); |
| telnet_Set_SubOpt(Attr + 2, TELOPT_LFLOW, LFLOW_OFF, NULL, 0); |
telnet_Set_SubOpt(Attr + 2, TELOPT_LFLOW, LFLOW_OFF, NULL, 0); |
| telnet_Set_SubOpt(Attr + 3, TELOPT_LFLOW, LFLOW_RESTART_XON, NULL, 0); |
telnet_Set_SubOpt(Attr + 3, TELOPT_LFLOW, LFLOW_RESTART_XON, NULL, 0); |
| telnet_SetCmd(Attr + 4, DO, TELOPT_LINEMODE); |
telnet_SetCmd(Attr + 4, DO, TELOPT_LINEMODE); |
| */ |
|
| telnet_SetCmd(Attr + 0, DO, TELOPT_TTYPE); |
|
| telnet_SetCmd(Attr + 1, WILL, TELOPT_ECHO); |
|
| telnet_Set_SubOpt(Attr + 2, TELOPT_LFLOW, LFLOW_OFF, NULL, 0); |
|
| telnet_Set_SubOpt(Attr + 3, TELOPT_LFLOW, LFLOW_RESTART_XON, NULL, 0); |
|
| telnet_SetCmd(Attr + 4, DO, TELOPT_LINEMODE); |
|
| if ((ret = telnetSend(sock, Attr, 5, NULL, 0, 0)) == -1) { |
if ((ret = telnetSend(sock, Attr, 5, NULL, 0, 0)) == -1) { |
| cli_Errno = telnet_GetErrno(); |
cli_Errno = telnet_GetErrno(); |
| strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
|
Line 330 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
Line 320 int cliNetExec(cliCommands_t *cmdList, const char *csP
|
| break; |
break; |
| } |
} |
| |
|
| if (FD_ISSET(sock, &fds)) { | r = FD_ISSET(sock, &fds) ? sock : pty; |
| memset(buf, 0, BUFSIZ); | s = FD_ISSET(sock, &fds) ? pty : sock; |
| if ((ret = telnetRecv(sock, &a, &alen, buf, BUFSIZ)) < 0) { | |
| if (a) | |
| free(a); | |
| |
|
| if (-2 == ret) | if ((ret = telnetRecv(r, &a, &alen, buf, BUFSIZ)) < 0) { |
| continue; | |
| // EOF | |
| if (-3 == ret) | |
| shutdown(sock, SHUT_RD); | |
| else { | |
| cli_Errno = telnet_GetErrno(); | |
| strlcpy(cli_Error, telnet_GetError(), STRSIZ); | |
| } | |
| break; | |
| } | |
| if (a) |
if (a) |
| free(a); |
free(a); |
| if (alen) { |
|
| attrlen = 0; |
|
| if (1 == flg && alen) { |
|
| telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_SGA); |
|
| telnet_SetCmd(&Attr[attrlen++], DO, TELOPT_ECHO); |
|
| } |
|
| if (2 == flg && alen) { |
|
| telnet_SetCmd(&Attr[attrlen++], WILL, TELOPT_ECHO); |
|
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, |
|
| LFLOW_OFF, NULL, 0); |
|
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, |
|
| LFLOW_RESTART_XON, NULL, 0); |
|
| telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_LINEMODE); |
|
| } |
|
| if ((ret = telnetSend(sock, Attr, attrlen, buf, ret, 0)) == -1) { |
|
| cli_Errno = telnet_GetErrno(); |
|
| strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
|
| break; |
|
| } |
|
| } |
|
| |
|
| if ((ret = write(pty, buf, ret)) == -1) { | if (-2 == ret) |
| LOGERR; | continue; |
| break; | // EOF |
| } | if (-3 == ret) |
| } | shutdown(r, SHUT_RD); |
| else { |
| if (FD_ISSET(pty, &fds)) { | |
| memset(buf, 0, BUFSIZ); | |
| if ((ret = read(pty, buf, BUFSIZ)) < 1) { | |
| if (!ret) | |
| shutdown(sock, SHUT_WR); | |
| else | |
| LOGERR; | |
| break; | |
| } | |
| attrlen = 0; | |
| if (1 == flg && alen) { | |
| telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_SGA); | |
| telnet_SetCmd(&Attr[attrlen++], DO, TELOPT_ECHO); | |
| } | |
| if (2 == flg && alen) { | |
| telnet_SetCmd(&Attr[attrlen++], WILL, TELOPT_ECHO); | |
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, | |
| LFLOW_OFF, NULL, 0); | |
| telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, | |
| LFLOW_RESTART_XON, NULL, 0); | |
| telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_LINEMODE); | |
| } | |
| if ((ret = telnetSend(sock, Attr, attrlen, buf, ret, 0)) == -1) { | |
| cli_Errno = telnet_GetErrno(); |
cli_Errno = telnet_GetErrno(); |
| strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
| break; |
|
| } |
} |
| |
break; |
| } |
} |
| |
attrlen = 0; |
| |
if (1 == flg && alen) { |
| |
telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_SGA); |
| |
telnet_SetCmd(&Attr[attrlen++], DO, TELOPT_ECHO); |
| |
} |
| |
if (2 == flg && alen) { |
| |
telnet_SetCmd(&Attr[attrlen++], WILL, TELOPT_ECHO); |
| |
telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, |
| |
LFLOW_OFF, NULL, 0); |
| |
telnet_Set_SubOpt(&Attr[attrlen++], TELOPT_LFLOW, |
| |
LFLOW_RESTART_XON, NULL, 0); |
| |
telnet_SetCmd(&Attr[attrlen++], DONT, TELOPT_LINEMODE); |
| |
} |
| |
if (a) |
| |
free(a); |
| |
|
| |
if ((ret = telnetSend(s, Attr, pty == s ? 0 : attrlen, buf, ret, 0)) == -1) { |
| |
cli_Errno = telnet_GetErrno(); |
| |
strlcpy(cli_Error, telnet_GetError(), STRSIZ); |
| |
break; |
| |
} else |
| |
flg++; |
| } |
} |
| |
|
| close(pty); |
close(pty); |