|
|
1.1 root 1: /* answer.cpp */
2:
3: /* Synchronet answer "caller" function */
4:
1.1.1.2 ! root 5: /* $Id: answer.cpp,v 1.73 2011/09/14 03:09:44 rswindell Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
1.1.1.2 ! root 11: * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39: #include "telnet.h"
40:
1.1.1.2 ! root 41: extern "C" void client_on(SOCKET sock, client_t* client, BOOL update);
! 42:
1.1 root 43: bool sbbs_t::answer()
44: {
45: char str[MAX_PATH+1],str2[MAX_PATH+1],c;
46: char tmp[MAX_PATH+1];
47: char path[MAX_PATH+1];
48: int i,l,in;
49: struct tm tm;
50:
51: useron.number=0;
52: answertime=logontime=starttime=now=time(NULL);
53: /* Caller ID is IP address */
1.1.1.2 ! root 54: SAFECOPY(cid,inet_ntoa(client_addr.sin_addr));
1.1 root 55:
56: memset(&tm,0,sizeof(tm));
57: localtime_r(&now,&tm);
58:
59: sprintf(str,"%s %s %s %02d %u Node %3u"
60: ,hhmmtostr(&cfg,&tm,str2)
61: ,wday[tm.tm_wday]
62: ,mon[tm.tm_mon],tm.tm_mday,tm.tm_year+1900,cfg.node_num);
63: logline("@ ",str);
64:
65: sprintf(str,"%s %s [%s]", connection, client_name, cid);
66: logline("@+:",str);
67:
68: if(client_ident[0]) {
69: sprintf(str,"Identity: %s",client_ident);
70: logline("@*",str);
71: }
72:
73: online=ON_REMOTE;
74:
75: rlogin_name[0]=0;
76: if(sys_status&SS_RLOGIN) {
77: if(incom(1000)==0) {
78: for(i=0;i<(int)sizeof(str)-1;i++) {
79: in=incom(1000);
80: if(in==0 || in==NOINP)
81: break;
82: str[i]=in;
83: }
84: str[i]=0;
85: for(i=0;i<(int)sizeof(str2)-1;i++) {
86: in=incom(1000);
87: if(in==0 || in==NOINP)
88: break;
89: str2[i]=in;
90: }
91: str2[i]=0;
92: for(i=0;i<(int)sizeof(terminal)-1;i++) {
93: in=incom(1000);
94: if(in==0 || in==NOINP)
95: break;
96: terminal[i]=in;
97: }
98: terminal[i]=0;
99: truncstr(terminal,"/");
100: lprintf(LOG_DEBUG,"Node %d RLogin: '%.*s' / '%.*s' / '%s'"
101: ,cfg.node_num
102: ,LEN_ALIAS*2,str
103: ,LEN_ALIAS*2,str2
104: ,terminal);
105: SAFECOPY(rlogin_name
106: ,startup->options&BBS_OPT_USE_2ND_RLOGIN ? str2 : str);
107: SAFECOPY(rlogin_pass
108: ,startup->options&BBS_OPT_USE_2ND_RLOGIN ? str : str2);
1.1.1.2 ! root 109: useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name);
1.1 root 110: if(useron.number) {
111: getuserdat(&cfg,&useron);
1.1.1.2 ! root 112: useron.misc&=~TERM_FLAGS;
1.1 root 113: SAFEPRINTF(path,"%srlogin.cfg",cfg.ctrl_dir);
114: if(!findstr(client.addr,path)) {
115: SAFECOPY(tmp
116: ,rlogin_pass);
117: for(i=0;i<3;i++) {
118: if(stricmp(tmp,useron.pass)) {
1.1.1.2 ! root 119: badlogin(useron.alias, tmp);
1.1 root 120: rioctl(IOFI); /* flush input buffer */
121: bputs(text[InvalidLogon]);
122: if(cfg.sys_misc&SM_ECHO_PW)
123: sprintf(str,"(%04u) %-25s FAILED Password attempt: '%s'"
124: ,0,useron.alias,tmp);
125: else
126: sprintf(str,"(%04u) %-25s FAILED Password attempt"
127: ,0,useron.alias);
1.1.1.2 ! root 128: logline(LOG_NOTICE,"+!",str);
1.1 root 129: bputs(text[PasswordPrompt]);
130: console|=CON_R_ECHOX;
131: getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB);
132: console&=~(CON_R_ECHOX|CON_L_ECHOX);
133: }
134: else {
135: if(REALSYSOP) {
136: rioctl(IOFI); /* flush input buffer */
137: if(!chksyspass())
138: bputs(text[InvalidLogon]);
139: else {
140: i=0;
141: break;
142: }
143: }
144: else
145: break;
146: }
147: }
148: if(i) {
149: if(stricmp(tmp,useron.pass)) {
1.1.1.2 ! root 150: badlogin(useron.alias, tmp);
1.1 root 151: bputs(text[InvalidLogon]);
152: if(cfg.sys_misc&SM_ECHO_PW)
153: sprintf(str,"(%04u) %-25s FAILED Password attempt: '%s'"
154: ,0,useron.alias,tmp);
155: else
156: sprintf(str,"(%04u) %-25s FAILED Password attempt"
157: ,0,useron.alias);
1.1.1.2 ! root 158: logline(LOG_NOTICE,"+!",str);
1.1 root 159: }
1.1.1.2 ! root 160: lprintf(LOG_WARNING,"Node %d !CLIENT IP NOT LISTED in %s"
! 161: ,cfg.node_num,path);
1.1 root 162: useron.number=0;
163: hangup();
164: }
165: }
166: }
167: else
1.1.1.2 ! root 168: lprintf(LOG_INFO,"Node %d RLogin: Unknown user: %s",cfg.node_num,rlogin_name);
1.1 root 169: }
170: if(rlogin_name[0]==0) {
1.1.1.2 ! root 171: lprintf(LOG_NOTICE,"Node %d !RLogin: No user name received",cfg.node_num);
1.1 root 172: sys_status&=~SS_RLOGIN;
173: }
174: }
175:
176: if(!(telnet_mode&TELNET_MODE_OFF)) {
177: /* Disable Telnet Terminal Echo */
178: request_telnet_opt(TELNET_WILL,TELNET_ECHO);
179: /* Will suppress Go Ahead */
180: request_telnet_opt(TELNET_WILL,TELNET_SUP_GA);
1.1.1.2 ! root 181: /* Retrieve terminal type and speed from telnet client --RS */
1.1 root 182: request_telnet_opt(TELNET_DO,TELNET_TERM_TYPE);
1.1.1.2 ! root 183: request_telnet_opt(TELNET_DO,TELNET_TERM_SPEED);
! 184: request_telnet_opt(TELNET_DO,TELNET_SEND_LOCATION);
! 185: request_telnet_opt(TELNET_DO,TELNET_NEGOTIATE_WINDOW_SIZE);
1.1 root 186: }
187: #ifdef USE_CRYPTLIB
188: if(sys_status&SS_SSH) {
189: cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_USERNAME, rlogin_name, &i);
190: rlogin_name[i]=0;
191: cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_PASSWORD, rlogin_pass, &i);
192: rlogin_pass[i]=0;
193: lprintf(LOG_DEBUG,"Node %d SSH login: '%s'"
194: ,cfg.node_num, rlogin_name);
1.1.1.2 ! root 195: useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name);
1.1 root 196: if(useron.number) {
197: getuserdat(&cfg,&useron);
1.1.1.2 ! root 198: useron.misc&=~TERM_FLAGS;
1.1 root 199: SAFECOPY(tmp
200: ,rlogin_pass);
201: for(i=0;i<3;i++) {
202: if(stricmp(tmp,useron.pass)) {
1.1.1.2 ! root 203: badlogin(useron.alias, tmp);
1.1 root 204: rioctl(IOFI); /* flush input buffer */
205: bputs(text[InvalidLogon]);
206: if(cfg.sys_misc&SM_ECHO_PW)
207: sprintf(str,"(%04u) %-25s FAILED Password attempt: '%s'"
208: ,0,useron.alias,tmp);
209: else
210: sprintf(str,"(%04u) %-25s FAILED Password attempt"
211: ,0,useron.alias);
1.1.1.2 ! root 212: /* crash here Sept-12-2010
! 213: str 0x06b3fc4c "(0000) Guest FAILED Password attempt: '[email protected]'"
! 214:
! 215: and Oct-6-2010
! 216: str 0x070ffc4c "(0000) Woot903 FAILED Password attempt: 'p67890pppsdsjhsdfhhfhnhnfhfhfdhjksdjkfdskw3902391=`'" char [261]
! 217: */
! 218: logline(LOG_NOTICE,"+!",str);
1.1 root 219: bputs(text[PasswordPrompt]);
220: console|=CON_R_ECHOX;
221: getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB);
222: console&=~(CON_R_ECHOX|CON_L_ECHOX);
223: }
224: else {
225: if(REALSYSOP) {
226: rioctl(IOFI); /* flush input buffer */
227: if(!chksyspass())
228: bputs(text[InvalidLogon]);
229: else {
230: i=0;
231: break;
232: }
233: }
234: else
235: break;
236: }
237: }
238: if(i) {
239: if(stricmp(tmp,useron.pass)) {
1.1.1.2 ! root 240: badlogin(useron.alias, tmp);
1.1 root 241: bputs(text[InvalidLogon]);
242: if(cfg.sys_misc&SM_ECHO_PW)
243: sprintf(str,"(%04u) %-25s FAILED Password attempt: '%s'"
244: ,0,useron.alias,tmp);
245: else
246: sprintf(str,"(%04u) %-25s FAILED Password attempt"
247: ,0,useron.alias);
1.1.1.2 ! root 248: logline(LOG_NOTICE,"+!",str);
1.1 root 249: }
250: useron.number=0;
251: hangup();
252: }
253: }
254: else
1.1.1.2 ! root 255: lprintf(LOG_INFO,"Node %d SSH: Unknown user: %s",cfg.node_num,rlogin_name);
1.1 root 256: }
257: #endif
258:
259: /* Detect terminal type */
260: mswait(200);
261: rioctl(IOFI); /* flush input buffer */
262: putcom( "\r\n" /* locate cursor at column 1 */
263: "\x1b[s" /* save cursor position (necessary for HyperTerm auto-ANSI) */
1.1.1.2 ! root 264: "\x1b[255B" /* locate cursor as far down as possible */
! 265: "\x1b[255C" /* locate cursor as far right as possible */
! 266: "\b_" /* need a printable at this location to actually move cursor */
1.1 root 267: "\x1b[6n" /* Get cursor position */
268: "\x1b[u" /* restore cursor position */
269: "\x1b[!_" /* RIP? */
1.1.1.2 ! root 270: "\x1b[30;40m\xc2\x9f""Zuul.connection.write('\\x1b""Are you the gatekeeper?')\xc2\x9c" /* ZuulTerm?
1.1 root 271: "\x1b[0m_" /* "Normal" colors */
272: "\x1b[2J" /* clear screen */
273: "\x1b[H" /* home cursor */
274: "\xC" /* clear screen (in case not ANSI) */
275: "\r" /* Move cursor left (in case previous char printed) */
276: );
277: i=l=0;
278: tos=1;
279: lncntr=0;
280: strcpy(str,VERSION_NOTICE);
281: strcat(str," ");
282: strcat(str,COPYRIGHT_NOTICE);
1.1.1.2 ! root 283: strip_ctrl(str, str);
1.1 root 284: center(str);
285:
286: while(i++<50 && l<(int)sizeof(str)-1) { /* wait up to 5 seconds for response */
287: c=incom(100)&0x7f;
288: if(c==0)
289: continue;
290: i=0;
291: if(l==0 && c!=ESC) // response must begin with escape char
292: continue;
293: str[l++]=c;
294: if(c=='R') { /* break immediately if ANSI response */
295: mswait(500);
296: break;
297: }
298: }
299:
300: while((c=(incom(100)&0x7f))!=0 && l<(int)sizeof(str)-1)
301: str[l++]=c;
302: str[l]=0;
303:
304: if(l) {
1.1.1.2 ! root 305: c_escape_str(str,tmp,sizeof(tmp),TRUE);
! 306: lprintf(LOG_DEBUG,"Node %d received terminal auto-detection response: '%s'"
! 307: ,cfg.node_num,tmp);
! 308: if(str[0]==ESC && str[1]=='[' && str[l-1]=='R') {
! 309: int x,y;
! 310:
1.1 root 311: if(terminal[0]==0)
312: SAFECOPY(terminal,"ANSI");
313: autoterm|=(ANSI|COLOR);
1.1.1.2 ! root 314: if(sscanf(str+2,"%u;%u",&y,&x)==2) {
! 315: lprintf(LOG_DEBUG,"Node %d received ANSI cursor position report: %ux%u"
! 316: ,cfg.node_num, x, y);
! 317: /* Sanity check the coordinates in the response: */
! 318: if(x>=40 && x<=255) cols=x;
! 319: if(y>=10 && y<=255) rows=y;
! 320: }
1.1 root 321: }
322: truncsp(str);
323: if(strstr(str,"RIPSCRIP")) {
324: if(terminal[0]==0)
325: SAFECOPY(terminal,"RIP");
326: logline("@R",strstr(str,"RIPSCRIP"));
327: autoterm|=(RIP|COLOR|ANSI); }
1.1.1.2 ! root 328: else if(strstr(str,"Are you the gatekeeper?")) {
1.1 root 329: if(terminal[0]==0)
330: SAFECOPY(terminal,"HTML");
1.1.1.2 ! root 331: logline("@H",strstr(str,"Are you the gatekeeper?"));
1.1 root 332: autoterm|=HTML;
333: }
334: }
335: else if(terminal[0]==0)
336: SAFECOPY(terminal,"DUMB");
337:
338: rioctl(IOFI); /* flush left-over or late response chars */
339:
340: if(!autoterm && str[0]) {
1.1.1.2 ! root 341: c_escape_str(str,tmp,sizeof(tmp),TRUE);
! 342: lprintf(LOG_NOTICE,"Node %d terminal auto-detection failed, response: '%s'"
! 343: ,cfg.node_num, tmp);
1.1 root 344: }
345:
346: /* AutoLogon via IP or Caller ID here */
347: if(!useron.number && !(sys_status&SS_RLOGIN)
348: && startup->options&BBS_OPT_AUTO_LOGON && cid[0]) {
1.1.1.2 ! root 349: useron.number=userdatdupe(0, U_NOTE, LEN_NOTE, cid);
1.1 root 350: if(useron.number) {
351: getuserdat(&cfg, &useron);
352: if(!(useron.misc&AUTOLOGON) || !(useron.exempt&FLAG('V')))
353: useron.number=0;
354: }
355: }
356:
357: if(!online)
358: return(false);
359:
1.1.1.2 ! root 360: if(stricmp(terminal,"sexpots")==0) { /* dial-up connection (via SexPOTS) */
! 361: SAFEPRINTF2(str,"%s connection detected at %lu bps", terminal, cur_rate);
! 362: logline("@S",str);
! 363: node_connection = (ushort)cur_rate;
! 364: SAFEPRINTF(connection,"%lu",cur_rate);
! 365: SAFECOPY(cid,"Unknown");
! 366: SAFECOPY(client_name,"Unknown");
! 367: if(telnet_location[0]) { /* Caller-ID info provided */
! 368: SAFEPRINTF(str, "CID: %s", telnet_location);
! 369: logline("@*",str);
! 370: SAFECOPY(cid,telnet_location);
! 371: truncstr(cid," "); /* Only include phone number in CID */
! 372: char* p=telnet_location;
! 373: FIND_WHITESPACE(p);
! 374: SKIP_WHITESPACE(p);
! 375: if(*p) {
! 376: SAFECOPY(client_name,p); /* CID name, if provided (maybe 'P' or 'O' if private or out-of-area) */
! 377: }
! 378: }
! 379: SAFECOPY(client.addr,cid);
! 380: SAFECOPY(client.host,client_name);
! 381: client_on(client_socket,&client,TRUE /* update */);
! 382: } else {
! 383: if(telnet_location[0]) { /* Telnet Location info provided */
! 384: SAFEPRINTF(str, "Telnet Location: %s", telnet_location);
! 385: logline("@*",str);
! 386: }
! 387: }
! 388:
! 389:
! 390: useron.misc&=~TERM_FLAGS;
1.1 root 391: useron.misc|=autoterm;
392: SAFECOPY(useron.comp,client_name);
393:
394: if(!useron.number && sys_status&SS_RLOGIN) {
395: CRLF;
396: newuser();
397: }
398:
399: if(!useron.number) { /* manual/regular logon */
400:
401: /* Display ANSWER screen */
402: sprintf(str,"%sanswer",cfg.text_dir);
1.1.1.2 ! root 403: sprintf(tmp,"%s.rip",str);
1.1 root 404: sprintf(path,"%s.html",str);
405: sprintf(str2,"%s.ans",str);
1.1.1.2 ! root 406: if(autoterm&RIP && fexist(tmp))
! 407: strcat(str,".rip");
1.1 root 408: else if(autoterm&HTML && fexist(path))
409: strcat(str,".html");
410: else if(autoterm&ANSI && fexist(str2))
411: strcat(str,".ans");
412: else
413: strcat(str,".asc");
414: rioctl(IOSM|PAUSE);
415: sys_status|=SS_PAUSEON;
416: printfile(str,P_NOABORT);
417: sys_status&=~SS_PAUSEON;
418: exec_bin(cfg.login_mod,&main_csi);
419: } else /* auto logon here */
420: if(logon()==false)
421: return(false);
422:
423:
424: if(!useron.number)
425: hangup();
426:
427: /* Save the IP to the user's note */
428: if(cid[0]) {
429: SAFECOPY(useron.note,cid);
430: putuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE,useron.note);
431: }
432:
433: /* Save host name to the user's computer description */
434: if(client_name[0]) {
435: SAFECOPY(useron.comp,client_name);
436: putuserrec(&cfg,useron.number,U_COMP,LEN_COMP,useron.comp);
437: }
438:
1.1.1.2 ! root 439: if(!online)
! 440: return(false);
! 441:
1.1 root 442: if(!(sys_status&SS_USERON)) {
443: errormsg(WHERE,ERR_CHK,"User not logged on",0);
444: hangup();
1.1.1.2 ! root 445: return(false);
! 446: }
! 447:
! 448: if(useron.pass[0])
! 449: loginSuccess(startup->login_attempt_list, &client_addr);
1.1 root 450:
451: return(true);
452: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.