Commit 04d2b5d4 authored by mcmlxxix's avatar mcmlxxix
Browse files

removed TG_SENDPASS flag from bbs.telnet_gate/sbbsdefs.h

added bbs.rlogin_gate method: bbs.rlogin(addr,user,pass,mode);
disable "raw input" mode for rlogin_gate connections. not sure why this is the fix or why it was the problem, but no side effects are noted at this time.
parent 4739760c
......@@ -2620,6 +2620,80 @@ js_telnet_gate(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
static JSBool
js_rlogin_gate(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
char* addr;
char* alias;
char* pass;
bool fail;
int32 mode = 0;
JSString* js_addr;
JSString* js_alias;
JSString* js_pass;
sbbs_t* sbbs;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if(!js_argc(cx, argc, 1))
return(JS_FALSE);
if((sbbs=js_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
if((js_addr=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
JSSTRING_TO_MSTRING(cx, js_addr, addr, NULL);
if(addr==NULL)
return(JS_FALSE);
/* if remote username & password supplied */
if(argc>2) {
if((js_alias=JS_ValueToString(cx, argv[1]))==NULL) {
fail = true;
}
if((js_pass=JS_ValueToString(cx, argv[2]))==NULL) {
fail = true;
}
JSSTRING_TO_MSTRING(cx, js_alias, alias, NULL);
JSSTRING_TO_MSTRING(cx, js_pass, pass, NULL);
if(argc>3 && JSVAL_IS_NUMBER(argv[3])) {
if(!JS_ValueToInt32(cx,argv[3],&mode)) {
fail = true;
}
}
}
else if(argc>1 && JSVAL_IS_NUMBER(argv[1])) {
if(!JS_ValueToInt32(cx,argv[1],&mode)) {
fail = true;
}
}
if(fail == true) {
lprintf(LOG_NOTICE,"fail!");
free(addr);
free(alias);
free(pass);
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
sbbs->rlogin_gate(addr,alias,pass,mode);
free(addr);
free(alias);
free(pass);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_pagesysop(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -3685,6 +3759,10 @@ static jsSyncMethodSpec js_bbs_functions[] = {
,JSDOCSTR("external telnet/rlogin gateway (see <tt>TG_*</tt> in <tt>sbbsdefs.js</tt> for valid <i>mode</i> bits)")
,310
},
{"rlogin_gate", js_rlogin_gate, 1, JSTYPE_VOID, JSDOCSTR("address [user=<tt>user.alias</tt>,pass=<tt>user.pass</tt>,mode=<tt>TG_NONE</tt>]")
,JSDOCSTR("external rlogin gateway (see <tt>TG_*</tt> in <tt>sbbsdefs.js</tt> for valid <i>mode</i> bits)")
,310
},
/* security */
{"check_syspass", js_chksyspass, 0, JSTYPE_BOOLEAN, JSDOCSTR("")
,JSDOCSTR("prompt for and verify system password")
......
......@@ -939,6 +939,7 @@ public:
/* telgate.cpp */
void telnet_gate(char* addr, ulong mode); // See TG_* for mode bits
void rlogin_gate(char* addr, char* alias, char* pw, ulong mode); // See TG_* for mode bits
};
......
......@@ -777,7 +777,6 @@ enum { /* readmail and delmailidx which types */
#define TG_RLOGIN (1<<6) /* Use BSD RLogin protocol */
#define TG_NOCHKTIME (1<<7) /* Don't check time left while gated */
#define TG_NOTERMTYPE (1<<8) /* Request client "DONT TERM_TYPE" */
#define TG_SENDPASS (1<<9) /* Send password instead of real name (RLogin) */
enum { /* Values for 'mode' in listfileinfo */
FI_INFO /* Just list file information */
......
......@@ -123,11 +123,7 @@ void sbbs_t::telnet_gate(char* destaddr, ulong mode)
*(p++)=0;
p+=sprintf(p,"%s",useron.alias);
p++; // Add NULL
if(mode&TG_SENDPASS) {
p+=sprintf(p,"%s",useron.pass);
} else {
p+=sprintf(p,"%s",useron.name);
}
p+=sprintf(p,"%s",useron.pass);
p++; // Add NULL
p+=sprintf(p,"%s/57600",terminal);
p++; // Add NULL
......@@ -270,3 +266,197 @@ void sbbs_t::telnet_gate(char* destaddr, ulong mode)
lprintf(LOG_INFO,"Node %d Telnet gate to %s finished",cfg.node_num,destaddr);
}
void sbbs_t::rlogin_gate(char* destaddr, char* alias, char* pass, ulong mode)
{
char* p;
uchar buf[512];
int i;
int rd;
uint attempts;
ulong l;
bool gotline;
ushort port = 513;
ulong ip_addr;
ulong save_console;
SOCKET remote_socket;
SOCKADDR_IN addr;
/* if port was specified with address, use it */
p=strchr(destaddr,':');
if(p!=NULL) {
*p=0;
port=atoi(p+1);
}
ip_addr=resolve_ip(destaddr);
if(ip_addr==INADDR_NONE) {
lprintf(LOG_NOTICE,"!RLOGIN Failed to resolve address: %s",destaddr);
bprintf("!Failed to resolve address: %s\r\n",destaddr);
return;
}
if((remote_socket = open_socket(SOCK_STREAM, client.protocol)) == INVALID_SOCKET) {
errormsg(WHERE,ERR_OPEN,"socket",0);
return;
}
/* todo: figure this shit out */
memset(&addr,0,sizeof(addr));
addr.sin_addr.s_addr = htonl(startup->telnet_interface);
addr.sin_family = AF_INET;
if((i=bind(remote_socket, (struct sockaddr *) &addr, sizeof (addr)))!=0) {
lprintf(LOG_NOTICE,"!RLOGIN ERROR %d (%d) binding to socket %d",i, ERROR_VALUE, remote_socket);
bprintf("!ERROR %d (%d) binding to socket\r\n",i, ERROR_VALUE);
close_socket(remote_socket);
return;
}
memset(&addr,0,sizeof(addr));
addr.sin_addr.s_addr = ip_addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
if((i=connect(remote_socket, (struct sockaddr *)&addr, sizeof(addr)))!=0) {
lprintf(LOG_NOTICE,"!RLOGIN ERROR %d (%d) connecting to server: %s"
,i,ERROR_VALUE, destaddr);
bprintf("!ERROR %d (%d) connecting to server: %s\r\n"
,i,ERROR_VALUE, destaddr);
close_socket(remote_socket);
return;
}
l=1;
if((i = ioctlsocket(remote_socket, FIONBIO, &l))!=0) {
lprintf(LOG_NOTICE,"!RLOGIN ERROR %d (%d) disabling socket blocking"
,i, ERROR_VALUE);
close_socket(remote_socket);
return;
}
lprintf(LOG_INFO,"Node %d %s gate to %s port %u on socket %d"
,cfg.node_num
,"RLogin"
,destaddr,port,remote_socket);
/* rlogin handshake */
lprintf(LOG_NOTICE,"!RLOGIN terminal: %s",terminal);
p=(char*)buf;
*(p++)=0;
if(alias != NULL) {
p+=sprintf(p,"%s",alias);
}
else {
p+=sprintf(p,"%s",useron.alias);
}
p++; // Add NULL
if(pass != NULL) {
p+=sprintf(p,"%s",pass);
} else {
p+=sprintf(p,"%s",useron.pass);
}
p++; // Add NULL
p+=sprintf(p,"%s/57600",terminal);
p++; // Add NULL
l=p-(char*)buf;
sendsocket(remote_socket,(char*)buf,l);
while(online) {
if(!(mode&TG_NOCHKTIME))
gettimeleft();
rd=RingBufRead(&inbuf,buf,sizeof(buf));
if(rd) {
if(telnet_remote_option[TELNET_BINARY_TX]!=TELNET_WILL) {
if(*buf==0x1d) { // ^]
save_console=console;
console&=~CON_RAW_IN; // Allow Ctrl-U/Ctrl-P
CRLF;
while(online) {
SYNC;
mnemonics("\1n\r\n\1h\1bTelnet Gate: \1y~D\1wisconnect, "
"\1y~E\1wcho toggle, \1y~L\1wist Users, \1y~P\1wrivate message, "
"\1y~Q\1wuit: ");
switch(getkeys("DELPQ",0)) {
case 'D':
closesocket(remote_socket);
break;
case 'E':
mode^=TG_ECHO;
bprintf(text[EchoIsNow]
,mode&TG_ECHO
? text[ON]:text[OFF]);
continue;
case 'L':
whos_online(true);
continue;
case 'P':
nodemsg();
continue;
}
break;
}
attr(LIGHTGRAY);
console=save_console;
}
else if(*buf<' ' && mode&TG_CTRLKEYS)
handle_ctrlkey(*buf, K_NONE);
gotline=false;
if(mode&TG_LINEMODE && buf[0]!='\r') {
ungetkey(buf[0]);
l=K_CHAT;
if(!(mode&TG_ECHO))
l|=K_NOECHO;
rd=getstr((char*)buf,sizeof(buf)-1,l);
if(!rd)
continue;
strcat((char*)buf,crlf);
rd+=2;
gotline=true;
}
if(!gotline && mode&TG_ECHO) {
RingBufWrite(&outbuf,buf,rd);
}
}
for(attempts=0;attempts<60 && online; attempts++) {
if((i=sendsocket(remote_socket,(char*)buf,rd))>=0)
break;
if(ERROR_VALUE!=EWOULDBLOCK)
break;
mswait(500);
}
if(i<0) {
lprintf(LOG_NOTICE,"!RLOGIN ERROR %d sending on socket %d",ERROR_VALUE,remote_socket);
break;
}
}
rd=recv(remote_socket,(char*)buf,sizeof(buf),0);
if(rd<0) {
if(ERROR_VALUE==EWOULDBLOCK) {
if(mode&TG_NODESYNC) {
SYNC;
} else {
// Check if the node has been interrupted
getnodedat(cfg.node_num,&thisnode,0);
if(thisnode.misc&NODE_INTR)
break;
}
YIELD();
continue;
}
lprintf(LOG_NOTICE,"!RLOGIN ERROR %d receiving on socket %d",ERROR_VALUE,remote_socket);
break;
}
if(!rd) {
lprintf(LOG_INFO,"Node %d RLogin gate disconnected",cfg.node_num);
break;
}
RingBufWrite(&outbuf,buf,rd);
}
close_socket(remote_socket);
lprintf(LOG_INFO,"Node %d RLogin gate to %s finished",cfg.node_num,destaddr);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment