int printFile (const char* fileName) { FILE* file; file = fopen(fileName,"r"); if (!file) { perror("unable to open file"); return -1; } tty_mode(0); int i = 0; int usrinput; printfile(file); printf("\033[7m"); printf("%s",fileName); printf("\033[m"); setNodelay(); while((usrinput = fgetc(stdin))!= 'q' && fgetc(file) != EOF) { if(usrinput == ' '){ printf("\b \b"); printfile(file); } else if(usrinput == '\n'){ printline(file); } } tty_mode(1); if (fclose (file)) { perror("unable to close file"); return -1; } return 0; }
int main() { gfxInitDefault(); consoleInit(GFX_TOP, NULL); Result rc = romfsInit(); if (rc) printf("romfsInit: %08lX\n", rc); else { printf("romfs Init Successful!\n"); printfile("romfs:/folder/file.txt"); // Test reading a file with non-ASCII characters in the name printfile("romfs:/フォルダ/ファイル.txt"); } // Main loop while (aptMainLoop()) { gspWaitForVBlank(); hidScanInput(); u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu } romfsExit(); gfxExit(); return 0; }
void sbbs_t::sys_info() { char tmp[128]; uint i; stats_t stats; bputs(text[SiHdr]); getstats(&cfg,0,&stats); bprintf(text[SiSysName],cfg.sys_name); bprintf(text[SiSysID],cfg.sys_id); /* QWK ID */ for(i=0;i<cfg.total_faddrs;i++) bprintf(text[SiSysFaddr],smb_faddrtoa(&cfg.faddr[i],tmp)); if(cfg.sys_psname[0]) /* PostLink/PCRelay */ bprintf(text[SiSysPsite],cfg.sys_psname,cfg.sys_psnum); bprintf(text[SiSysLocation],cfg.sys_location); bprintf(text[SiSysop],cfg.sys_op); bprintf(text[SiSysNodes],cfg.sys_nodes); // bprintf(text[SiNodeNumberName],cfg.node_num,cfg.node_name); bprintf(text[SiNodePhone],cfg.node_phone); bprintf(text[SiTotalLogons],ultoac(stats.logons,tmp)); bprintf(text[SiLogonsToday],ultoac(stats.ltoday,tmp)); bprintf(text[SiTotalTime],ultoac(stats.timeon,tmp)); bprintf(text[SiTimeToday],ultoac(stats.ttoday,tmp)); ver(); if(yesno(text[ViewSysInfoFileQ])) { CLS; sprintf(tmp,"%ssystem.msg", cfg.text_dir); printfile(tmp,0); } if(yesno(text[ViewLogonMsgQ])) { CLS; menu("logon"); } }
int main(int argc, char* argv[]) { char buf[200]; //some local variables, making sure there is enough place on the stack for the paylaod for(int i=0;i<200;i++) buf[i] = 'b'; //use local variables so compiler won't remove them if(argc!=2) { printf("Usage: %s <filename>\n", argv[0]); return 0; } //needed for the rop payload if(!LoadLibrary("msvcr71.dll")) { printf("msvcr71.dll not found\n"); return 0; } //buffer overflow happens in this function printfile(argv[1]); if(buf[199]) { //use local variables so compiler won't remove them return 0; } return 0; }
void printfile(File* fifo){ if(fifo == NULL){ printf("\n"); } else{ printf("%c \t", fifo->noeud->id); printfile(fifo->next); } }
void printfile(be_node *n, int indent) { int i = 0; if (n -> type == BE_INT) { printindent(indent); printf("[Integer: %lld]\n", n -> val.i); } else if (n -> type == BE_STR) { printindent(indent); printf("[String: \'%s\']\n", n -> val.s); } else if (n -> type == BE_DICT) { be_dict * d = n -> val.d; putchar('\n'); printindent(indent); printf("[Dictionary:]\n"); for (i = 0; ; ++i) { if (d[i].val) { printindent(indent+2); printf("[Key: \'%s\'], ", d[i].key); printfile(d[i].val, indent+2); } else { break; } } printindent(indent); printf("[Dictionary End]\n"); } else if (n -> type == BE_LIST) { be_node ** l = n -> val.l; putchar('\n'); printindent(indent); printf("[List:]\n"); for (i = 0; ; ++i) { if (l[i]) { printfile(l[i], indent+2); } else { break; } } printindent(indent); printf("[List End]\n"); } else { assert(0); } }
void print_index_header(FILE *fp, char *label, char *dir, char *subject, char *filename) { if (ihtmlheaderfile) #ifdef HAVE_ICONV if (set_i18n){ printfile(fp, ihtmlheaderfile, label, subject, dir, NULL, NULL, "UTF-8", NULL, NULL, filename); }else{ printfile(fp, ihtmlheaderfile, label, subject, dir, NULL, NULL, NULL, NULL, NULL, filename); } #else printfile(fp, ihtmlheaderfile, label, subject, dir, NULL, NULL, NULL, NULL, NULL, filename); #endif else { /* print the navigation bar to upper levels */ #ifdef HAVE_ICONV if (set_i18n){
void TextStreamBuffer::printfile(const char *filename, unsigned long offset, int lines) { FILE *file = fopen(filename, "r"); if(file != NULL) { fseek(file, offset, SEEK_SET); printfile(file, lines); fclose(file); } }
void print_msg_header(FILE *fp, char *label, char *subject, char *dir, char *name, char *email, char *msgid, char *charset, time_t date, char *filename,int is_deleted) { if (mhtmlheaderfile) printfile(fp, mhtmlheaderfile, set_label, subject, set_dir, name, email, msgid, charset, secs_to_iso_meta(date), filename); else { print_main_header(fp, FALSE, set_label, name, email, subject, charset, secs_to_iso_meta(date), filename, is_deleted); } }
void sbbs_t::dirinfo(uint dirnum) { char str[256]; bputs(text[DirInfoHdr]); bprintf(text[DirInfoLongName],cfg.dir[dirnum]->lname); bprintf(text[DirInfoShortName],cfg.dir[dirnum]->sname); if(cfg.dir[dirnum]->exts[0]) bprintf(text[DirInfoAllowedExts],cfg.dir[dirnum]->exts); bprintf(text[DirInfoMaxFiles],cfg.dir[dirnum]->maxfiles); sprintf(str,"%s%s.msg",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code); if(fexist(str) && yesno(text[DirInfoViewFileQ])) printfile(str,0); }
void sbbs_t::logonlist(void) { char str[MAX_PATH+1]; sprintf(str,"%slogon.lst", cfg.data_dir); if(flength(str)<1) { bputs("\r\n\r\n"); bputs(text[NoOneHasLoggedOnToday]); } else { bputs(text[CallersToday]); printfile(str,P_NOATCODES|P_OPENCLOSE); CRLF; } }
static void tile ( int row, int col) { static int page=1; if (verbose) fprintf( stderr, "print page %d\n", page); printf ("\n%%%%Page: %d %d\n", page, page); printf ("%d %d tileprolog\n", row, col); printf ("%%%%BeginDocument: %s\n", infile); printfile (); printf ("\n%%%%EndDocument\n"); printf ("tileepilog\n"); page++; }
int main(int argc,char *argv[]) { void printfile(char *filename); int i; if(argc == 1) { fprintf(stderr,"%s Usage:%s filename1 filename2 ...",argv[0],argv[0]); exit(1); } else { for(i=1;i < argc;i++) { printfile(argv[i]); } } }
bool sbbs_t::trashcan(char *insearchof, char *name) { char str[MAX_PATH+1]; bool result; result=::trashcan(&cfg, insearchof, name) ? true:false; // This is a dumb bool conversion to make BC++ happy if(result) { sprintf(str,"%sbad%s.msg",cfg.text_dir,name); if(fexistcase(str)) { printfile(str,0); mswait(500); // give time for tx buffer to clear before disconnect } } return(result); }
int main(int argc, char *argv[]){ char *arg; FILE *fp; while(--argc > 0){ arg = *++argv; fp = fopen(arg, "r"); if(fp == NULL){ fprintf(stderr, "can not open file: %s\n", arg); continue; } printfile(fp, arg); fclose(fp); } return 0; }
void dir() { CBM_Sector s; int track=40,sector=3; cbm_read(&s,40,0); printdiskname(&s.h); do { cbm_read(&s,track,sector); printfile(&s.f.f1); printfile(&s.f.f2); printfile(&s.f.f3); printfile(&s.f.f4); printfile(&s.f.f5); printfile(&s.f.f6); printfile(&s.f.f7); printfile(&s.f.f8); track=s.next_track; sector=s.next_sector; } while(track!=0); }
void sbbs_t::subinfo(uint subnum) { char str[256]; bputs(text[SubInfoHdr]); bprintf(text[SubInfoLongName],cfg.sub[subnum]->lname); bprintf(text[SubInfoShortName],cfg.sub[subnum]->sname); bprintf(text[SubInfoQWKName],cfg.sub[subnum]->qwkname); bprintf(text[SubInfoMaxMsgs],cfg.sub[subnum]->maxmsgs); if(cfg.sub[subnum]->misc&SUB_QNET) bprintf(text[SubInfoTagLine],cfg.sub[subnum]->tagline); if(cfg.sub[subnum]->misc&SUB_FIDO) bprintf(text[SubInfoFidoNet] ,cfg.sub[subnum]->origline ,smb_faddrtoa(&cfg.sub[subnum]->faddr,str)); sprintf(str,"%s%s.msg",cfg.sub[subnum]->data_dir,cfg.sub[subnum]->code); if(fexist(str) && yesno(text[SubInfoViewFileQ])) printfile(str,0); }
int main(){ FILE *fp; FILE *fp_out; char line[LSIZE]; int i = 1; if((fp = fopen(FILE_IN, "rw+")) == NULL) printf("ERROR. CANNOT OPEN FILE"); if((fp_out = fopen(FILE_OUT, "rw+")) == NULL) printf("E"); while(fgets(line, LSIZE, fp)) { printf("%s", line); if(i%2 != 0) mod(fp_out, line); i++; } fclose(fp); fclose(fp_out); printfile(FILE_OUT); return 0; }
int http_router(pConnInfo conn_info) { if(conn_info->status_code != 0) send_error_response(conn_info); int sockfd = conn_info->clientfd; char path[PATH_LEN]; struct stat stat_buff; int i = 0; strcpy(path, conn_info->request_header->path); while(path[i] != 0) { if(path[i] == '?' || path[i] == '#') { path[i] = 0; break; } i++; } if(lstat(path, &stat_buff) != -1) { if( S_ISDIR(stat_buff.st_mode) ) { mime = uws_strdup("text/html"); printdir(path, conn_info); } else { mime = get_mime(path); printfile(path, conn_info); } } else { conn_info->status_code = 404; send_error_response(conn_info); return; } set_header(conn_info); write_response(conn_info, &header_body); //uws_free(header_body.header); sorry, reponse_header will be freed at the end of request uws_free(header_body.content); free_header_params(conn_info->response_header); }
int main(int argc, char ** argv) { int i; be_node * ben_res; FILE * f; int flen; char * data; f = fopen(argv[1], "r"); if (!f) { printf("file open fail\n"); exit(1); } flen = file_len(f); data = (char *) malloc ( sizeof(char) * flen ); fread(data, sizeof(char), flen, f); fclose(f); ben_res = be_decoden(data, flen); printfile(ben_res, 0); return 0; }
bool sbbs_t::answer() { char str[MAX_PATH+1],str2[MAX_PATH+1],c; char tmp[(MAX_PATH > CRYPT_MAX_TEXTSIZE ? MAX_PATH:CRYPT_MAX_TEXTSIZE)+1]; char tmpname[CRYPT_MAX_TEXTSIZE+1]; char path[MAX_PATH+1]; int i,l,in; struct tm tm; useron.number=0; answertime=logontime=starttime=now=time(NULL); /* Caller ID is IP address */ SAFECOPY(cid,client_ipaddr); memset(&tm,0,sizeof(tm)); localtime_r(&now,&tm); safe_snprintf(str,sizeof(str),"%s %s %s %02d %u Node %3u" ,hhmmtostr(&cfg,&tm,str2) ,wday[tm.tm_wday] ,mon[tm.tm_mon],tm.tm_mday,tm.tm_year+1900,cfg.node_num); logline("@ ",str); safe_snprintf(str,sizeof(str),"%s %s [%s]", connection, client_name, cid); logline("@+:",str); if(client_ident[0]) { safe_snprintf(str,sizeof(str),"Identity: %s",client_ident); logline("@*",str); } online=ON_REMOTE; if(sys_status&SS_RLOGIN) { if(incom(1000)==0) { for(i=0;i<(int)sizeof(str)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; str[i]=in; } str[i]=0; for(i=0;i<(int)sizeof(str2)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; str2[i]=in; } str2[i]=0; for(i=0;i<(int)sizeof(terminal)-1;i++) { in=incom(1000); if(in==0 || in==NOINP) break; terminal[i]=in; } terminal[i]=0; lprintf(LOG_DEBUG,"Node %d RLogin: '******' / '%.*s' / '%s'" ,cfg.node_num ,LEN_ALIAS*2,str ,LEN_ALIAS*2,str2 ,terminal); SAFECOPY(rlogin_term, terminal); SAFECOPY(rlogin_name, str2); SAFECOPY(rlogin_pass, str); /* Truncate terminal speed (e.g. "/57600") from terminal-type string (but keep full terminal type/speed string in rlogin_term): */ truncstr(terminal,"/"); useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name); if(useron.number) { getuserdat(&cfg,&useron); useron.misc&=~TERM_FLAGS; SAFEPRINTF(path,"%srlogin.cfg",cfg.ctrl_dir); if(!findstr(client.addr,path)) { SAFECOPY(tmp, rlogin_pass); for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); console&=~(CON_R_ECHOX|CON_L_ECHOX); } else { if(REALSYSOP) { rioctl(IOFI); /* flush input buffer */ if(!chksyspass()) bputs(text[InvalidLogon]); else { i=0; break; } } else break; } } if(i) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); } lprintf(LOG_WARNING,"Node %d !CLIENT IP NOT LISTED in %s" ,cfg.node_num,path); useron.number=0; hangup(); } } } else lprintf(LOG_INFO,"Node %d RLogin: Unknown user: %s",cfg.node_num,rlogin_name); } if(rlogin_name[0]==0) { lprintf(LOG_NOTICE,"Node %d !RLogin: No user name received",cfg.node_num); sys_status&=~SS_RLOGIN; } } if(!(telnet_mode&TELNET_MODE_OFF)) { /* Disable Telnet Terminal Echo */ request_telnet_opt(TELNET_WILL,TELNET_ECHO); /* Will suppress Go Ahead */ request_telnet_opt(TELNET_WILL,TELNET_SUP_GA); /* Retrieve terminal type and speed from telnet client --RS */ request_telnet_opt(TELNET_DO,TELNET_TERM_TYPE); request_telnet_opt(TELNET_DO,TELNET_TERM_SPEED); request_telnet_opt(TELNET_DO,TELNET_SEND_LOCATION); request_telnet_opt(TELNET_DO,TELNET_NEGOTIATE_WINDOW_SIZE); request_telnet_opt(TELNET_DO,TELNET_NEW_ENVIRON); } #ifdef USE_CRYPTLIB if(sys_status&SS_SSH) { pthread_mutex_lock(&ssh_mutex); cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_USERNAME, tmpname, &i); tmpname[i]=0; SAFECOPY(rlogin_name, tmpname); cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_PASSWORD, tmp, &i); tmp[i]=0; SAFECOPY(rlogin_pass, tmp); pthread_mutex_unlock(&ssh_mutex); lprintf(LOG_DEBUG,"Node %d SSH login: '******'" ,cfg.node_num, tmpname); useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, tmpname); if(useron.number) { getuserdat(&cfg,&useron); useron.misc&=~TERM_FLAGS; for(i=0;i<3;i++) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); rioctl(IOFI); /* flush input buffer */ bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); /* crash here Sept-12-2010 str 0x06b3fc4c "(0000) Guest FAILED Password attempt: '*****@*****.**'" and Oct-6-2010 str 0x070ffc4c "(0000) Woot903 FAILED Password attempt: 'p67890pppsdsjhsdfhhfhnhnfhfhfdhjksdjkfdskw3902391=`'" char [261] */ logline(LOG_NOTICE,"+!",str); bputs(text[PasswordPrompt]); console|=CON_R_ECHOX; getstr(tmp,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB); console&=~(CON_R_ECHOX|CON_L_ECHOX); } else { if(REALSYSOP) { rioctl(IOFI); /* flush input buffer */ if(!chksyspass()) bputs(text[InvalidLogon]); else { i=0; break; } } else break; } } if(i) { if(stricmp(tmp,useron.pass)) { badlogin(useron.alias, tmp); bputs(text[InvalidLogon]); if(cfg.sys_misc&SM_ECHO_PW) safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt: '%s'" ,0,useron.alias,tmp); else safe_snprintf(str,sizeof(str),"(%04u) %-25s FAILED Password attempt" ,0,useron.alias); logline(LOG_NOTICE,"+!",str); } useron.number=0; hangup(); } } else lprintf(LOG_INFO,"Node %d SSH: Unknown user: %s",cfg.node_num,rlogin_name); } #endif /* Detect terminal type */ mswait(200); rioctl(IOFI); /* flush input buffer */ putcom( "\r\n" /* locate cursor at column 1 */ "\x1b[s" /* save cursor position (necessary for HyperTerm auto-ANSI) */ "\x1b[255B" /* locate cursor as far down as possible */ "\x1b[255C" /* locate cursor as far right as possible */ "\b_" /* need a printable at this location to actually move cursor */ "\x1b[6n" /* Get cursor position */ "\x1b[u" /* restore cursor position */ "\x1b[!_" /* RIP? */ "\x1b[30;40m\xc2\x9f""Zuul.connection.write('\\x1b""Are you the gatekeeper?')\xc2\x9c" /* ZuulTerm? */ "\x1b[0m_" /* "Normal" colors */ "\x1b[2J" /* clear screen */ "\x1b[H" /* home cursor */ "\xC" /* clear screen (in case not ANSI) */ "\r" /* Move cursor left (in case previous char printed) */ ); i=l=0; tos=1; lncntr=0; safe_snprintf(str, sizeof(str), "%s %s", VERSION_NOTICE, COPYRIGHT_NOTICE); strip_ctrl(str, str); center(str); while(i++<50 && l<(int)sizeof(str)-1) { /* wait up to 5 seconds for response */ c=incom(100)&0x7f; if(c==0) continue; i=0; if(l==0 && c!=ESC) // response must begin with escape char continue; str[l++]=c; if(c=='R') { /* break immediately if ANSI response */ mswait(500); break; } } while((c=(incom(100)&0x7f))!=0 && l<(int)sizeof(str)-1) str[l++]=c; str[l]=0; if(l) { c_escape_str(str,tmp,sizeof(tmp),TRUE); lprintf(LOG_DEBUG,"Node %d received terminal auto-detection response: '%s'" ,cfg.node_num,tmp); if(str[0]==ESC && str[1]=='[' && str[l-1]=='R') { int x,y; if(terminal[0]==0) SAFECOPY(terminal,"ANSI"); autoterm|=(ANSI|COLOR); if(sscanf(str+2,"%u;%u",&y,&x)==2) { lprintf(LOG_DEBUG,"Node %d received ANSI cursor position report: %ux%u" ,cfg.node_num, x, y); /* Sanity check the coordinates in the response: */ if(x>=40 && x<=255) cols=x; if(y>=10 && y<=255) rows=y; } } truncsp(str); if(strstr(str,"RIPSCRIP")) { if(terminal[0]==0) SAFECOPY(terminal,"RIP"); logline("@R",strstr(str,"RIPSCRIP")); autoterm|=(RIP|COLOR|ANSI); } else if(strstr(str,"Are you the gatekeeper?")) { if(terminal[0]==0) SAFECOPY(terminal,"HTML"); logline("@H",strstr(str,"Are you the gatekeeper?")); autoterm|=HTML; } } else if(terminal[0]==0) SAFECOPY(terminal,"DUMB"); rioctl(IOFI); /* flush left-over or late response chars */ if(!autoterm && str[0]) { c_escape_str(str,tmp,sizeof(tmp),TRUE); lprintf(LOG_NOTICE,"Node %d terminal auto-detection failed, response: '%s'" ,cfg.node_num, tmp); } /* AutoLogon via IP or Caller ID here */ if(!useron.number && !(sys_status&SS_RLOGIN) && (startup->options&BBS_OPT_AUTO_LOGON) && cid[0]) { useron.number=userdatdupe(0, U_NOTE, LEN_NOTE, cid); if(useron.number) { getuserdat(&cfg, &useron); if(!(useron.misc&AUTOLOGON) || !(useron.exempt&FLAG('V'))) useron.number=0; } } if(!online) return(false); if(stricmp(terminal,"sexpots")==0) { /* dial-up connection (via SexPOTS) */ SAFEPRINTF2(str,"%s connection detected at %lu bps", terminal, cur_rate); logline("@S",str); node_connection = (ushort)cur_rate; SAFEPRINTF(connection,"%lu",cur_rate); SAFECOPY(cid,"Unknown"); SAFECOPY(client_name,"Unknown"); if(telnet_location[0]) { /* Caller-ID info provided */ SAFEPRINTF(str, "CID: %s", telnet_location); logline("@*",str); SAFECOPY(cid,telnet_location); truncstr(cid," "); /* Only include phone number in CID */ char* p=telnet_location; FIND_WHITESPACE(p); SKIP_WHITESPACE(p); if(*p) { SAFECOPY(client_name,p); /* CID name, if provided (maybe 'P' or 'O' if private or out-of-area) */ } } SAFECOPY(client.addr,cid); SAFECOPY(client.host,client_name); client_on(client_socket,&client,TRUE /* update */); } else { if(telnet_location[0]) { /* Telnet Location info provided */ SAFEPRINTF(str, "Telnet Location: %s", telnet_location); logline("@*",str); } } useron.misc&=~TERM_FLAGS; useron.misc|=autoterm; SAFECOPY(useron.comp,client_name); if(!useron.number && rlogin_name[0]!=0 && !(cfg.sys_misc&SM_CLOSED) && !matchuser(&cfg, rlogin_name, /* Sysop alias: */FALSE)) { lprintf(LOG_INFO,"Node %d UNKNOWN %s-specified USERNAME: %s, starting new user signup",cfg.node_num,client.protocol,rlogin_name); bprintf("%s: %s\r\n", text[UNKNOWN_USER], rlogin_name); newuser(); } if(!useron.number) { /* manual/regular logon */ /* Display ANSWER screen */ rioctl(IOSM|PAUSE); sys_status|=SS_PAUSEON; SAFEPRINTF(str,"%sanswer",cfg.text_dir); SAFEPRINTF(path,"%s.rip",str); if((autoterm&RIP) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.html",str); if((autoterm&HTML) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.ans",str); if((autoterm&ANSI) && fexistcase(path)) printfile(path,P_NOABORT); else { SAFEPRINTF(path,"%s.asc",str); if(fexistcase(path)) printfile(path, P_NOABORT); } } } sys_status&=~SS_PAUSEON; exec_bin(cfg.login_mod,&main_csi); } else /* auto logon here */ if(logon()==false) return(false); if(!useron.number) hangup(); /* Save the IP to the user's note */ if(cid[0]) { SAFECOPY(useron.note,cid); putuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE,useron.note); } /* Save host name to the user's computer description */ if(client_name[0]) { SAFECOPY(useron.comp,client_name); putuserrec(&cfg,useron.number,U_COMP,LEN_COMP,useron.comp); } if(!online) return(false); if(!(sys_status&SS_USERON)) { errormsg(WHERE,ERR_CHK,"User not logged on",0); hangup(); return(false); } if(useron.pass[0]) loginSuccess(startup->login_attempt_list, &client_addr); return(true); }
int sbbs_t::exec(csi_t *csi) { char str[256],*path; char tmp[512]; uchar buf[1025],ch; int i,j,file; long l; FILE *stream; if(usrgrps) cursubnum=usrsub[curgrp][cursub[curgrp]]; /* Used for ARS */ else cursubnum=INVALID_SUB; if(usrlibs) { curdirnum=usrdir[curlib][curdir[curlib]]; /* Used for ARS */ path=cfg.dir[usrdir[curlib][curdir[curlib]]]->path; } else { curdirnum=INVALID_DIR; path=nulstr; } now=time(NULL); if(csi->ip>=csi->cs+csi->length) return(1); if(*csi->ip>=CS_FUNCTIONS) return(exec_function(csi)); /**********************************************/ /* Miscellaneous variable length instructions */ /**********************************************/ if(*csi->ip>=CS_MISC) return(exec_misc(csi,path)); /********************************/ /* ASCIIZ argument instructions */ /********************************/ if(*csi->ip>=CS_ASCIIZ) { switch(*(csi->ip++)) { case CS_STR_FUNCTION: switch(*(csi->ip++)) { case CS_LOGIN: csi->logic=login(csi->str,(char*)csi->ip); break; case CS_LOAD_TEXT: csi->logic=LOGIC_FALSE; for(i=0;i<TOTAL_TEXT;i++) if(text[i]!=text_sav[i]) { if(text[i]!=nulstr) free(text[i]); text[i]=text_sav[i]; } SAFEPRINTF2(str,"%s%s.dat" ,cfg.ctrl_dir,cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); if((stream=fnopen(&file,str,O_RDONLY))==NULL) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); break; } for(i=0;i<TOTAL_TEXT && !feof(stream);i++) { if((text[i]=readtext((long *)NULL,stream,i))==NULL) { i--; continue; } if(!strcmp(text[i],text_sav[i])) { /* If identical */ free(text[i]); /* Don't alloc */ text[i]=text_sav[i]; } else if(text[i][0]==0) { free(text[i]); text[i]=nulstr; } } if(i<TOTAL_TEXT) { fclose(stream); errormsg(WHERE,ERR_READ,str,TOTAL_TEXT); break; } fclose(stream); csi->logic=LOGIC_TRUE; break; default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); break; } while(*(csi->ip++)); /* Find NULL */ return(0); case CS_LOG: log(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_GETCMD: csi->cmd=(uchar)getkeys((char*)csi->ip,0); if((char)csi->cmd==-1) csi->cmd=3; break; case CS_CMDSTR: if(stricmp(csi->str,(char*)csi->ip)) { while(*(csi->ip++)); /* Find NULL */ skipto(csi,CS_END_CMD); csi->ip++; return(0); } break; case CS_CMDKEYS: for(i=0;csi->ip[i];i++) if(csi->cmd==csi->ip[i]) break; if(!csi->ip[i]) { while(*(csi->ip++)); /* Find NULL */ skipto(csi,CS_END_CMD); csi->ip++; return(0); } break; case CS_GET_TEMPLATE: gettmplt(csi->str,(char*)csi->ip,K_LINE); if(sys_status&SS_ABORT) csi->str[0]=0; csi->cmd=csi->str[0]; break; case CS_TRASHCAN: csi->logic=!trashcan(csi->str,(char*)csi->ip); break; case CS_CREATE_SIF: create_sif_dat((char*)csi->ip,csi->str); break; case CS_READ_SIF: read_sif_dat((char*)csi->ip,csi->str); break; case CS_MNEMONICS: mnemonics((char*)csi->ip); break; case CS_PRINT: putmsg(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),P_SAVEATR|P_NOABORT); break; case CS_PRINT_LOCAL: if(online==ON_LOCAL) eprintf(LOG_INFO,"%s",cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); else lputs(LOG_INFO,cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_PRINT_REMOTE: putcom(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_PRINTFILE: printfile(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),P_SAVEATR); break; case CS_PRINTFILE_REMOTE: if(online!=ON_REMOTE || !(console&CON_R_ECHO)) break; console&=~CON_L_ECHO; printfile(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),P_SAVEATR); console|=CON_L_ECHO; break; case CS_PRINTFILE_LOCAL: if(!(console&CON_L_ECHO)) break; console&=~CON_R_ECHO; printfile(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),P_SAVEATR); console|=CON_R_ECHO; break; case CS_CHKFILE: csi->logic=!fexistcase(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_EXEC: external(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),0); break; case CS_EXEC_INT: external(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),EX_STDIO); break; case CS_EXEC_XTRN: for(i=0;i<cfg.total_xtrns;i++) if(!stricmp(cfg.xtrn[i]->code,(char*)csi->ip)) break; if(i<cfg.total_xtrns) exec_xtrn(i); break; case CS_EXEC_BIN: exec_bin(cmdstr((char*)csi->ip,path,csi->str,(char*)buf),csi,/* startup_dir: */NULL); break; case CS_YES_NO: csi->logic=!yesno(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_NO_YES: csi->logic=!noyes(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_MENU: menu(cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_SETSTR: strcpy(csi->str,cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_SET_MENU_DIR: cmdstr((char*)csi->ip,path,csi->str,menu_dir); break; case CS_SET_MENU_FILE: cmdstr((char*)csi->ip,path,csi->str,menu_file); break; case CS_COMPARE_STR: csi->logic=stricmp(csi->str,cmdstr((char*)csi->ip,path,csi->str,(char*)buf)); break; case CS_COMPARE_KEYS: for(i=0;csi->ip[i];i++) if(csi->cmd==csi->ip[i]) break; if(csi->ip[i]) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; break; case CS_COMPARE_WORD: csi->logic=strnicmp(csi->str,(char*)csi->ip,strlen((char*)csi->ip)); break; default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); break; } while(*(csi->ip++)); /* Find NULL */ return(0); } if(*csi->ip>=CS_THREE_BYTE) { switch(*(csi->ip++)) { case CS_THREE_MORE_BYTES: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); case CS_GOTO: csi->ip=csi->cs+*((ushort *)(csi->ip)); return(0); case CS_CALL: if(csi->rets<MAX_RETS) { csi->ret[csi->rets++]=csi->ip+2; csi->ip=csi->cs+*((ushort *)(csi->ip)); } return(0); case CS_MSWAIT: mswait(*(ushort *)csi->ip); csi->ip+=2; return(0); case CS_TOGGLE_NODE_MISC: if(getnodedat(cfg.node_num,&thisnode,true)==0) { thisnode.misc^=*(ushort *)csi->ip; putnodedat(cfg.node_num,&thisnode); } csi->ip+=2; return(0); case CS_COMPARE_NODE_MISC: getnodedat(cfg.node_num,&thisnode,0); if((thisnode.misc&*(ushort *)csi->ip)==*(ushort *)csi->ip) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; csi->ip+=2; return(0); case CS_ADJUST_USER_CREDITS: i=*(short *)csi->ip; l=i*1024L; if(l<0) subtract_cdt(&cfg,&useron,-l); else useron.cdt=adjustuserrec(&cfg,useron.number,U_CDT,10,l); csi->ip+=2; return(0); case CS_ADJUST_USER_MINUTES: i=*(short *)csi->ip; useron.min=adjustuserrec(&cfg,useron.number,U_MIN,10,i); csi->ip+=2; return(0); case CS_GETNUM: i=*(short *)csi->ip; csi->ip+=2; l=getnum(i); if(l<=0) { csi->str[0]=0; csi->logic=LOGIC_FALSE; } else { sprintf(csi->str,"%lu",l); csi->logic=LOGIC_TRUE; } return(0); case CS_TOGGLE_USER_FLAG: i=*(csi->ip++); ch=*(csi->ip++); switch(i) { case '1': useron.flags1^=FLAG(ch); putuserrec(&cfg,useron.number,U_FLAGS1,8 ,ultoa(useron.flags1,tmp,16)); break; case '2': useron.flags2^=FLAG(ch); putuserrec(&cfg,useron.number,U_FLAGS2,8 ,ultoa(useron.flags2,tmp,16)); break; case '3': useron.flags3^=FLAG(ch); putuserrec(&cfg,useron.number,U_FLAGS3,8 ,ultoa(useron.flags3,tmp,16)); break; case '4': useron.flags4^=FLAG(ch); putuserrec(&cfg,useron.number,U_FLAGS4,8 ,ultoa(useron.flags4,tmp,16)); break; case 'R': useron.rest^=FLAG(ch); putuserrec(&cfg,useron.number,U_REST,8 ,ultoa(useron.rest,tmp,16)); break; case 'E': useron.exempt^=FLAG(ch); putuserrec(&cfg,useron.number,U_EXEMPT,8 ,ultoa(useron.exempt,tmp,16)); break; default: errormsg(WHERE,ERR_CHK,"user flag type",*(csi->ip-2)); return(0); } return(0); case CS_REVERT_TEXT: i=*(ushort *)csi->ip; csi->ip+=2; if((ushort)i==0xffff) { for(i=0;i<TOTAL_TEXT;i++) { if(text[i]!=text_sav[i] && text[i]!=nulstr) free(text[i]); text[i]=text_sav[i]; } return(0); } i--; if(i>=TOTAL_TEXT) { errormsg(WHERE,ERR_CHK,"revert text #",i); return(0); } if(text[i]!=text_sav[i] && text[i]!=nulstr) free(text[i]); text[i]=text_sav[i]; return(0); default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); } } if(*csi->ip>=CS_TWO_BYTE) { switch(*(csi->ip++)) { case CS_TWO_MORE_BYTES: switch(*(csi->ip++)) { case CS_USER_EVENT: user_event((user_event_t)*(csi->ip++)); return(0); } errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); case CS_SETLOGIC: csi->logic=*csi->ip++; return(0); case CS_CMDKEY: if( ((*csi->ip)==CS_DIGIT && isdigit(csi->cmd)) || ((*csi->ip)==CS_EDIGIT && csi->cmd&0x80 && isdigit(csi->cmd&0x7f))) { csi->ip++; return(0); } if(csi->cmd!=*csi->ip) { csi->ip++; skipto(csi,CS_END_CMD); /* skip code */ } csi->ip++; /* skip key */ return(0); case CS_CMDCHAR: if(csi->cmd!=*csi->ip) { csi->ip++; skipto(csi,CS_END_CMD); /* skip code */ } csi->ip++; /* skip key */ return(0); case CS_NODE_ACTION: action=*csi->ip++; return(0); case CS_NODE_STATUS: if(getnodedat(cfg.node_num,&thisnode,true)==0) { thisnode.status=*csi->ip++; putnodedat(cfg.node_num,&thisnode); } else csi->ip++; return(0); case CS_MULTINODE_CHAT: multinodechat(*csi->ip++); return(0); case CS_GETSTR: csi->logic=LOGIC_TRUE; getstr(csi->str,*csi->ip++,0); if(sys_status&SS_ABORT) { csi->str[0]=0; csi->logic=LOGIC_FALSE; } if(csi->str[0]=='/' && csi->str[1]) csi->cmd=csi->str[1]|0x80; else csi->cmd=csi->str[0]; return(0); case CS_GETLINE: getstr(csi->str,*csi->ip++,K_LINE); if(sys_status&SS_ABORT) csi->str[0]=0; if(csi->str[0]=='/' && csi->str[1]) csi->cmd=csi->str[1]|0x80; else csi->cmd=csi->str[0]; return(0); case CS_GETSTRUPR: getstr(csi->str,*csi->ip++,K_UPPER); if(sys_status&SS_ABORT) csi->str[0]=0; if(csi->str[0]=='/' && csi->str[1]) csi->cmd=csi->str[1]|0x80; else csi->cmd=csi->str[0]; return(0); case CS_GETNAME: getstr(csi->str,*csi->ip++,K_UPRLWR); if(sys_status&SS_ABORT) csi->str[0]=0; return(0); case CS_SHIFT_STR: i=*(csi->ip++); j=strlen(csi->str); if(i>j) i=j; if(i) memmove(csi->str,csi->str+i,j+1); return(0); case CS_COMPARE_KEY: if( ((*csi->ip)==CS_DIGIT && isdigit(csi->cmd)) || ((*csi->ip)==CS_EDIGIT && csi->cmd&0x80 && isdigit(csi->cmd&0x7f))) { csi->ip++; csi->logic=LOGIC_TRUE; } else { if(csi->cmd==*(csi->ip++)) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; } return(0); case CS_COMPARE_CHAR: if(csi->cmd==*(csi->ip++)) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_SET_USER_LEVEL: useron.level=*(csi->ip++); putuserrec(&cfg,useron.number,U_LEVEL,2,ultoa(useron.level,tmp,10)); return(0); case CS_SET_USER_STRING: csi->logic=LOGIC_FALSE; if(!csi->str[0]) { csi->ip++; return(0); } switch(*(csi->ip++)) { case USER_STRING_ALIAS: if(!isalpha(csi->str[0]) || trashcan(csi->str,"name")) break; i=matchuser(&cfg,csi->str,TRUE /*sysop_alias*/); if(i && i!=useron.number) break; sprintf(useron.alias,"%.*s",LEN_ALIAS,csi->str); putuserrec(&cfg,useron.number,U_ALIAS,LEN_ALIAS,useron.alias); putusername(&cfg,useron.number,useron.alias); csi->logic=LOGIC_TRUE; break; case USER_STRING_REALNAME: if(trashcan(csi->str,"name")) break; if(cfg.uq&UQ_DUPREAL && userdatdupe(useron.number,U_NAME,LEN_NAME,csi->str)) break; sprintf(useron.name,"%.*s",LEN_NAME,csi->str); putuserrec(&cfg,useron.number,U_NAME,LEN_NAME ,useron.name); csi->logic=LOGIC_TRUE; break; case USER_STRING_HANDLE: if(trashcan(csi->str,"name")) break; if(cfg.uq&UQ_DUPHAND && userdatdupe(useron.number,U_HANDLE,LEN_HANDLE,csi->str)) break; sprintf(useron.handle,"%.*s",LEN_HANDLE,csi->str); putuserrec(&cfg,useron.number,U_HANDLE,LEN_HANDLE ,useron.handle); csi->logic=LOGIC_TRUE; break; case USER_STRING_COMPUTER: sprintf(useron.comp,"%.*s",LEN_COMP,csi->str); putuserrec(&cfg,useron.number,U_COMP,LEN_COMP ,useron.comp); csi->logic=LOGIC_TRUE; break; case USER_STRING_NOTE: sprintf(useron.note,"%.*s",LEN_NOTE,csi->str); putuserrec(&cfg,useron.number,U_NOTE,LEN_NOTE ,useron.note); csi->logic=LOGIC_TRUE; break; case USER_STRING_ADDRESS: sprintf(useron.address,"%.*s",LEN_ADDRESS,csi->str); putuserrec(&cfg,useron.number,U_ADDRESS,LEN_ADDRESS ,useron.address); csi->logic=LOGIC_TRUE; break; case USER_STRING_LOCATION: sprintf(useron.location,"%.*s",LEN_LOCATION,csi->str); putuserrec(&cfg,useron.number,U_LOCATION,LEN_LOCATION ,useron.location); csi->logic=LOGIC_TRUE; break; case USER_STRING_ZIPCODE: sprintf(useron.zipcode,"%.*s",LEN_ZIPCODE,csi->str); putuserrec(&cfg,useron.number,U_ZIPCODE,LEN_ZIPCODE ,useron.zipcode); csi->logic=LOGIC_TRUE; break; case USER_STRING_PASSWORD: sprintf(useron.pass,"%.*s",LEN_PASS,csi->str); putuserrec(&cfg,useron.number,U_PASS,LEN_PASS ,useron.pass); csi->logic=LOGIC_TRUE; break; case USER_STRING_BIRTHDAY: if(!getage(&cfg,csi->str)) break; sprintf(useron.birth,"%.*s",LEN_BIRTH,csi->str); putuserrec(&cfg,useron.number,U_BIRTH,LEN_BIRTH ,useron.birth); csi->logic=LOGIC_TRUE; break; case USER_STRING_PHONE: if(trashcan(csi->str,"phone")) break; sprintf(useron.phone,"%.*s",LEN_PHONE,csi->str); putuserrec(&cfg,useron.number,U_PHONE,LEN_PHONE ,useron.phone); csi->logic=LOGIC_TRUE; break; case USER_STRING_MODEM: sprintf(useron.modem,"%.*s",LEN_MODEM,csi->str); putuserrec(&cfg,useron.number,U_MODEM,LEN_MODEM ,useron.phone); csi->logic=LOGIC_TRUE; break; case USER_STRING_COMMENT: sprintf(useron.comment,"%.*s",LEN_COMMENT,csi->str); putuserrec(&cfg,useron.number,U_COMMENT,LEN_COMMENT ,useron.comment); csi->logic=LOGIC_TRUE; break; case USER_STRING_NETMAIL: sprintf(useron.netmail,"%.*s",LEN_NETMAIL,csi->str); putuserrec(&cfg,useron.number,U_NETMAIL,LEN_NETMAIL ,useron.netmail); csi->logic=LOGIC_TRUE; break; default: errormsg(WHERE,ERR_CHK,"user string type",*(csi->ip-1)); return(0); } return(0); default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); } } /*********************************/ /* Single Byte Instrcutions ONLY */ /*********************************/ switch(*(csi->ip++)) { case CS_ONE_MORE_BYTE: /* Just one MORE byte */ switch(*(csi->ip++)) { case CS_OFFLINE: csi->misc|=CS_OFFLINE_EXEC; return(0); case CS_ONLINE: csi->misc&=~CS_OFFLINE_EXEC; return(0); case CS_NEWUSER: if(newuser()) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_LOGON: if(logon()) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_LOGOUT: logout(); return(0); case CS_EXIT: return(1); case CS_LOOP_BEGIN: if(csi->loops<MAX_LOOPDEPTH) csi->loop_home[csi->loops++]=(csi->ip-1); return(0); case CS_BREAK_LOOP: if(csi->loops) { skipto(csi,CS_END_LOOP); csi->ip+=2; csi->loops--; } return(0); case CS_END_LOOP: case CS_CONTINUE_LOOP: if(csi->loops) csi->ip=csi->loop_home[csi->loops-1]; return(0); default: errormsg(WHERE,ERR_CHK,"one byte extended function" ,*(csi->ip-1)); return(0); } case CS_CRLF: CRLF; return(0); case CS_CLS: CLS; return(0); case CS_PAUSE: pause(); return(0); case CS_PAUSE_RESET: lncntr=0; return(0); case CS_GETLINES: ansi_getlines(); return(0); case CS_HANGUP: hangup(); return(0); case CS_LOGKEY: logch(csi->cmd,0); return(0); case CS_LOGKEY_COMMA: logch(csi->cmd,1); return(0); case CS_LOGSTR: log(csi->str); return(0); case CS_CHKSYSPASS: csi->logic=!chksyspass(); return(0); case CS_PUT_NODE: if(getnodedat(cfg.node_num,&thisnode,true)==0) putnodedat(cfg.node_num,&thisnode); return(0); case CS_SYNC: SYNC; return(0); case CS_ASYNC: ASYNC; return(0); case CS_GETTIMELEFT: gettimeleft(); return(0); case CS_RETURN: if(!csi->rets) return(1); csi->ip=csi->ret[--csi->rets]; return(0); case CS_GETKEY: csi->cmd=getkey(K_UPPER); return(0); case CS_GETCHAR: csi->cmd=getkey(0); return(0); case CS_INKEY: csi->cmd=toupper(inkey(K_NONE,1)); if(csi->cmd) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_INCHAR: csi->cmd=inkey(K_NONE,1); if(csi->cmd) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_GETKEYE: csi->cmd=getkey(K_UPPER); if(csi->cmd=='/') { outchar('/'); csi->cmd=getkey(K_UPPER); csi->cmd|=0x80; } return(0); case CS_GETFILESPEC: if(getfilespec(csi->str)) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case CS_SAVELINE: SAVELINE; return(0); case CS_RESTORELINE: RESTORELINE; return(0); case CS_SELECT_SHELL: csi->logic=select_shell() ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_SET_SHELL: csi->logic=LOGIC_TRUE; for(i=0;i<cfg.total_shells;i++) if(!stricmp(csi->str,cfg.shell[i]->code) && chk_ar(cfg.shell[i]->ar,&useron,&client)) break; if(i<cfg.total_shells) { useron.shell=i; putuserrec(&cfg,useron.number,U_SHELL,8,cfg.shell[i]->code); } else csi->logic=LOGIC_FALSE; return(0); case CS_SELECT_EDITOR: csi->logic=select_editor() ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_SET_EDITOR: csi->logic=LOGIC_TRUE; for(i=0;i<cfg.total_xedits;i++) if(!stricmp(csi->str,cfg.xedit[i]->code) && chk_ar(cfg.xedit[i]->ar,&useron,&client)) break; if(i<cfg.total_xedits) { useron.xedit=i+1; putuserrec(&cfg,useron.number,U_XEDIT,8,cfg.xedit[i]->code); } else csi->logic=LOGIC_FALSE; return(0); case CS_CLEAR_ABORT: sys_status&=~SS_ABORT; return(0); case CS_FINDUSER: i=finduser(csi->str); if(i) { csi->logic=LOGIC_TRUE; username(&cfg,i,csi->str); } else csi->logic=LOGIC_FALSE; return(0); case CS_UNGETKEY: ungetkey(csi->cmd&0x7f); return(0); case CS_UNGETSTR: j=strlen(csi->str); for(i=0;i<j;i++) ungetkey(csi->str[i]); return(0); case CS_PRINTKEY: if((csi->cmd&0x7f)>=' ') outchar(csi->cmd&0x7f); return(0); case CS_PRINTSTR: putmsg(csi->str,P_SAVEATR|P_NOABORT|P_NOATCODES); return(0); case CS_CMD_HOME: if(csi->cmdrets<MAX_CMDRETS) csi->cmdret[csi->cmdrets++]=(csi->ip-1); return(0); case CS_END_CMD: if(csi->cmdrets) csi->ip=csi->cmdret[--csi->cmdrets]; return(0); case CS_CMD_POP: if(csi->cmdrets) csi->cmdrets--; return(0); case CS_IF_TRUE: if(csi->logic!=LOGIC_TRUE) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_GREATER: if(csi->logic!=LOGIC_GREATER) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_GREATER_OR_EQUAL: if(csi->logic!=LOGIC_GREATER && csi->logic!=LOGIC_EQUAL) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_LESS: if(csi->logic!=LOGIC_LESS) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_LESS_OR_EQUAL: if(csi->logic!=LOGIC_LESS && csi->logic!=LOGIC_EQUAL) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_IF_FALSE: if(csi->logic==LOGIC_TRUE) { skipto(csi,CS_ELSEORENDIF); csi->ip++; } return(0); case CS_ELSE: skipto(csi,CS_ENDIF); csi->ip++; return(0); case CS_END_CASE: skipto(csi,CS_END_SWITCH); csi->misc&=~CS_IN_SWITCH; csi->ip++; return(0); case CS_DEFAULT: case CS_END_SWITCH: csi->misc&=~CS_IN_SWITCH; return(0); case CS_ENDIF: return(0); default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); } }
int main(int argc, char **argv) { char str[81],compiler[32],*p; int i,file; FILE *stream; node_dir[0]=0; for(i=1;i<argc;i++) if(!stricmp(argv[i],"/L")) logit=1; else if(!stricmp(argv[i],"/T")) tutor=2; else if(!stricmp(argv[i],"/S")) tutor=1; else strcpy(node_dir,argv[i]); p=getenv("SBBSNODE"); if(!node_dir[0] && p) strcpy(node_dir,p); if(!node_dir[0]) { /* node directory not specified */ printf("usage: sbj <node directory> [/options]\r\n"); printf("\r\noptions: L = log wins/losses for each day\r\n"); getch(); return(1); } if(node_dir[strlen(node_dir)-1]!='\\' && node_dir[strlen(node_dir)-1]!='/') /* make sure node_dir ends in '\' */ strcat(node_dir,"/"); initdata(); /* read XTRN.DAT and more */ credits=user_cdt; total_nodes=sys_nodes; remove("debug.log"); if((file=nopen("sbj.cfg",O_RDONLY))==-1) { /* open config file */ bputs("Error opening sbj.cfg\r\n"); pause(); return(1); } if((stream=fdopen(file,"rb"))==NULL) { /* convert to stream */ bputs("Error converting sbj.cfg handle to stream\r\n"); pause(); return(1); } fgets(str,81,stream); /* number of decks in shoe */ total_decks=sys_decks=atoi(str); fgets(str,81,stream); /* min bet (in k) */ min_bet=atoi(str); fgets(str,81,stream); /* max bet (in k) */ max_bet=atoi(str); fgets(str,81,stream); /* default bet (in k) */ ibet=atoi(str); fclose(stream); if(!total_decks || total_decks>MAX_DECKS) { bputs("Invalid number of decks in sbj.cfg\r\n"); pause(); return(1); } if(!max_bet) { bputs("Invalid max bet in sbj.cfg\r\n"); pause(); return(1); } if(min_bet>max_bet) { bputs("Invalid min bet in sbj.cfg\r\n"); pause(); return(1); } if(ibet>max_bet || ibet<min_bet) { bputs("Invalid default bet in sbj.cfg\r\n"); pause(); return(1); } if(!fexist("card.dab")) { cur_card=0; dc=0; memset(dealer,0,sizeof(dealer)); memset(card,0,sizeof(card)); putcarddat(); } else { getcarddat(); if(total_decks!=sys_decks) { remove("card.dab"); total_decks=sys_decks; putcarddat(); } } if(!fexist("game.dab")) /* File's not there */ create_gamedab(); open_gamedab(); getgamedat(0); if(total_nodes!=sys_nodes) { /* total nodes changed */ close(gamedab); total_nodes=sys_nodes; create_gamedab(); open_gamedab(); } srand((unsigned)time(NULL)); #ifdef __16BIT__ while(_bios_keybrd(1)) /* clear input buffer */ _bios_keybrd(0); #endif putchar(5); /* ctrl-e */ mswait(500); if(keyhit()) { #ifdef __16BIT__ while(_bios_keybrd(1)) _bios_keybrd(0); #else getkey(0); #endif bputs("\r\n\1r\1h\1i*** ATTENTION ***\1n\1h\r\n"); bputs("\r\nSynchronet Blackjack uses Ctrl-E (ENQ) for the 'club' card " "symbol."); bputs("\r\nYour terminal responded to this control character with an " "answerback string."); bputs("\r\nYou will need to disable all Ctrl-E (ENQ) answerback " "strings (Including \r\nCompuserve Quick B transfers) if you wish to " "toggle card symbols on.\r\n\r\n"); symbols=0; pause(); } getgamedat(1); node[node_num-1]=0; putgamedat(); /* Override default mnemonic colors */ mnehigh=RED|HIGH; mnelow=CYAN|HIGH; /* Override default inactivity timeout values */ sec_warn=120; sec_timeout=180; COMPILER_DESC(compiler); #define SBJ_INDENT " " while(1) { cls(); sprintf(str,"\1n\1h\1cSynchronet \1rBlackjack! \1cv3.20 for %s\r\n" ,PLATFORM_DESC); center(str); sprintf(str,"\1w(XSDK v%s %s %s)\r\n\r\n" ,xsdk_ver,compiler,__DATE__); center(str); aborted=0; mnemonics(SBJ_INDENT"~Instructions\r\n"); mnemonics(SBJ_INDENT"~Join/Begin Game\r\n"); mnemonics(SBJ_INDENT"~List Players\r\n"); mnemonics(SBJ_INDENT"~Rules of the Game\r\n"); mnemonics(SBJ_INDENT"~Toggle Card Symbols\r\n"); sprintf(str,SBJ_INDENT"~Quit to %s\r\n",sys_name); mnemonics(str); nodesync(); bprintf("\1_\r\n"SBJ_INDENT"\1y\1hWhich: \1n"); switch(getkeys("IJBLRTQ|!",0)) { #if DEBUG case '!': if(!com_port) autoplay=1; break; case '|': debug(); break; #endif case 'I': cls(); printfile("sbj.msg"); break; case 'L': listplayers(); bprintf(ShoeStatus,cur_card,total_decks*52); break; case 'R': bprintf("\1n\1c\r\nMinimum bet: \1h%uk",min_bet); bprintf("\1n\1c\r\nMaximum bet: \1h%uk\r\n",max_bet); bprintf("\1w\1h\r\nCard decks in shoe: \1h%u\r\n",sys_decks); break; case 'T': symbols=!symbols; bprintf("\1_\1w\r\nCard symbols now: %s\r\n",symbols ? "ON":"OFF"); break; case 'Q': exit(0); case 'J': case 'B': sec_warn=60; /* Override default inactivity timeout values */ sec_timeout=90; play(); sec_warn=120; sec_timeout=180; break; } } }
EXPORTED void dlist_print(const struct dlist *dl, int printkeys, struct protstream *out) { struct dlist *di; if (printkeys) { prot_printastring(out, dl->name); prot_putc(' ', out); } switch (dl->type) { case DL_NIL: prot_printf(out, "NIL"); break; case DL_ATOM: prot_printastring(out, dl->sval); break; case DL_FLAG: prot_printf(out, "%s", dl->sval); break; case DL_NUM: case DL_DATE: /* for now, we will format it later */ prot_printf(out, "%llu", dl->nval); break; case DL_FILE: printfile(out, dl); break; case DL_BUF: if (strlen(dl->sval) == dl->nval) prot_printastring(out, dl->sval); else prot_printliteral(out, dl->sval, dl->nval); break; case DL_GUID: prot_printf(out, "%s", message_guid_encode(dl->gval)); break; case DL_HEX: { char buf[17]; snprintf(buf, 17, "%016llx", dl->nval); prot_printf(out, "%s", buf); } break; case DL_KVLIST: prot_printf(out, "%%("); for (di = dl->head; di; di = di->next) { dlist_print(di, 1, out); if (di->next) { prot_printf(out, " "); } } prot_printf(out, ")"); break; case DL_ATOMLIST: prot_printf(out, "("); for (di = dl->head; di; di = di->next) { dlist_print(di, dl->nval, out); if (di->next) prot_printf(out, " "); } prot_printf(out, ")"); break; } }
void InterpretCommand(MenuInstanceData * pMenuData, const char *pszScript) { char szCmd[31], szParam1[51], szParam2[51]; char szTempScript[ 255 ]; memset(szTempScript, 0, sizeof(szTempScript)); strncpy(szTempScript, pszScript, 250); if (pszScript[0] == 0) { return; } char* pszScriptPointer = szTempScript; while (pszScriptPointer && !hangup) { pszScriptPointer = MenuParseLine(pszScriptPointer, szCmd, szParam1, szParam2); if (szCmd[0] == 0) { // || !pszScriptPointer || !*pszScriptPointer break; } // ------------------------- // Run a new menu instance int nCmdID = GetMenuIndex(szCmd); switch (nCmdID) { case 0: { // "MENU" // Spawn a new menu MenuInstanceData *pNewMenuData = static_cast<MenuInstanceData *>(malloc(sizeof(MenuInstanceData))); memset(pNewMenuData, 0, sizeof(MenuInstanceData)); pNewMenuData->nFinished = 0; pNewMenuData->nReload = 0; Menus(pNewMenuData, pMenuData->szPath, szParam1); free(pNewMenuData); } break; case 1: { // ------------------------- // Exit out of this instance // of the menu // ------------------------- // "ReturnFromMenu" InterpretCommand(pMenuData, pMenuData->header.szExitScript); pMenuData->nFinished = 1; } break; case 2: { // "EditMenuSet" EditMenus(); // flag if we are editing this menu pMenuData->nFinished = 1; pMenuData->nReload = 1; } break; case 3: { // "DLFreeFile" align(szParam2); MenuDownload(szParam1, szParam2, true, true); } break; case 4: { // "DLFile" align(szParam2); MenuDownload(szParam1, szParam2, false, true); } break; case 5: { // "RunDoor" MenuRunDoorName(szParam1, false); } break; case 6: { // "RunDoorFree" MenuRunDoorName(szParam1, true); } break; case 7: { // "RunDoorNumber" int nTemp = atoi(szParam1); MenuRunDoorNumber(nTemp, false); } break; case 8: { // "RunDoorNumberFree" int nTemp = atoi(szParam1); MenuRunDoorNumber(nTemp, true); } break; case 9: { // "PrintFile" printfile(szParam1, true); } break; case 10: { // "PrintFileNA" printfile(szParam1, false); } break; case 11: { // "SetSubNumber" SetSubNumber(szParam1); } break; case 12: { // "SetDirNumber" SetDirNumber(szParam1); } break; case 13: { // "SetMsgConf" SetMsgConf(szParam1[0]); } break; case 14: { // "SetDirConf" SetDirConf(szParam1[0]); } break; case 15: { // "EnableConf" EnableConf(); } break; case 16: { // "DisableConf" DisableConf(); } break; case 17: { // "Pause" pausescr(); } break; case 18: { // "ConfigUserMenuSet" ConfigUserMenuSet(); pMenuData->nFinished = 1; pMenuData->nReload = 1; } break; case 19: { // "DisplayHelp" if (GetSession()->GetCurrentUser()->IsExpert()) { AMDisplayHelp(pMenuData); } } break; case 20: { // "SelectSub" ChangeSubNumber(); } break; case 21: { // "SelectDir" ChangeDirNumber(); } break; case 22: { // "SubList" SubList(); } break; case 23: { // "UpSubConf" UpSubConf(); } break; case 24: { // "DownSubConf" DownSubConf(); } break; case 25: { // "UpSub" UpSub(); } break; case 26: { // "DownSub" DownSub(); } break; case 27: { // "ValidateUser" ValidateUser(); } break; case 28: { // "Doors" Chains(); } break; case 29: { // "TimeBank" TimeBank(); } break; case 30: { // "AutoMessage" AutoMessage(); } break; case 31: { // "BBSList" BBSList(); } break; case 32: { // "RequestChat" RequestChat(); } break; case 33: { // "Defaults" Defaults(pMenuData); } break; case 34: { // "SendEMail" SendEMail(); } break; case 35: { // "Feedback" FeedBack(); } break; case 36: { // "Bulletins" Bulletins(); } break; case 37: { // "HopSub" HopSub(); } break; case 38: { // "SystemInfo" SystemInfo(); } break; case 39: { // "JumpSubConf" JumpSubConf(); } break; case 40: { // "KillEMail" KillEMail(); } break; case 41: { // "LastCallers" LastCallers(); } break; case 42: { // "ReadEMail" ReadEMail(); } break; case 43: { // "NewMessageScan" NewMessageScan(); } break; case 44: { // "Goodbye" GoodBye(); } break; case 45: { // "PostMessage" WWIV_PostMessage(); } break; case 46: { // "NewMsgScanCurSub" ScanSub(); } break; case 47: { // "RemovePost" RemovePost(); } break; case 48: { // "TitleScan" TitleScan(); } break; case 49: { // "ListUsers" ListUsers(); } break; case 50: { // "Vote" Vote(); } break; case 51: { // "ToggleExpert" ToggleExpert(); } break; case 52: { // "YourInfo" YourInfo(); } break; case 53: { // "ExpressScan" ExpressScan(); } break; case 54: { // "WWIVVer" WWIVVersion(); } break; case 55: { // "InstanceEdit" InstanceEdit(); } break; case 56: { // "ConferenceEdit" JumpEdit(); } break; case 57: { // "SubEdit" BoardEdit(); } break; case 58: { // "ChainEdit" ChainEdit(); } break; case 59: { // "ToggleAvailable" ToggleChat(); } break; case 60: { // "ChangeUser" ChangeUser(); } break; case 61: { // "CLOUT" CallOut(); } break; case 62: { // "Debug" Debug(); } break; case 63: { // "DirEdit" DirEdit(); } break; case 65: { // "Edit" EditText(); } break; case 66: { // "BulletinEdit" EditBulletins(); } break; case 67: { // "LoadText" // LoadText and LoadTextFile are the same, so they are now merged. LoadTextFile(); } break; case 68: { // "ReadAllMail" ReadAllMail(); } break; case 69: { // "Reboot" RebootComputer(); } break; case 70: { // "ReloadMenus" ReloadMenus(); } break; case 71: { // "ResetUserIndex" ResetFiles(); } break; case 72: { // "ResetQScan" ResetQscan(); } break; case 73: { // "MemStat" MemoryStatus(); } break; case 74: { // "PackMsgs" PackMessages(); } break; case 75: { // "VoteEdit" InitVotes(); } break; case 76: { // "Log" ReadLog(); } break; case 77: { // "NetLog" ReadNetLog(); } break; case 78: { // "Pending" PrintPending(); } break; case 79: { // "Status" PrintStatus(); } break; case 80: { // "TextEdit" TextEdit(); } break; case 81: { // "UserEdit" UserEdit(); } break; case 82: { // "VotePrint" VotePrint(); } break; case 83: { // "YLog" YesturdaysLog(); } break; case 84: { // "ZLog" ZLog(); } break; case 85: { // "ViewNetDataLog" ViewNetDataLog(); } break; case 86: { // "UploadPost" UploadPost(); } break; case 87: { // "ClearScreen" GetSession()->bout.ClearScreen(); } break; case 88: { // "NetListing" NetListing(); } break; case 89: { // "WHO" WhoIsOnline(); } break; case 90: { // /A "NewMsgsAllConfs" NewMsgsAllConfs(); } break; case 91: { // /E "MultiEMail" MultiEmail(); } break; case 92: { // "NewMsgScanFromHere" NewMsgScanFromHere(); } break; case 93: { // "ValidatePosts" ValidateScan(); } break; case 94: { // "ChatRoom" ChatRoom(); } break; case 95: { // "DownloadPosts" DownloadPosts(); } break; case 96: { // "DownloadFileList" DownloadFileList(); } break; case 97: { // "ClearQScan" ClearQScan(); } break; case 98: { // "FastGoodBye" FastGoodBye(); } break; case 99: { // "NewFilesAllConfs" NewFilesAllConfs(); } break; case 100: { // "ReadIDZ" ReadIDZ(); } break; case 101: { // "UploadAllDirs" UploadAllDirs(); } break; case 102: { // "UploadCurDir" UploadCurDir(); } break; case 103: { // "RenameFiles" RenameFiles(); } break; case 104: { // "MoveFiles" MoveFiles(); } break; case 105: { // "SortDirs" SortDirs(); } break; case 106: { // "ReverseSortDirs" ReverseSort(); } break; case 107: { // "AllowEdit" AllowEdit(); } break; case 109: { // "UploadFilesBBS" UploadFilesBBS(); } break; case 110: { // "DirList" DirList(); } break; case 111: { // "UpDirConf" UpDirConf(); } break; case 112: { // "UpDir" UpDir(); } break; case 113: { // "DownDirConf" DownDirConf(); } break; case 114: { // "DownDir" DownDir(); } break; case 115: { // "ListUsersDL" ListUsersDL(); } break; case 116: { // "PrintDSZLog" PrintDSZLog(); } break; case 117: { // "PrintDevices" PrintDevices(); } break; case 118: { // "ViewArchive" ViewArchive(); } break; case 119: { // "BatchMenu" BatchMenu(); } break; case 120: { // "Download" Download(); } break; case 121: { // "TempExtract" TempExtract(); } break; case 122: { // "FindDescription" FindDescription(); } break; case 123: { // "ArchiveMenu" TemporaryStuff(); } break; case 124: { // "HopDir" HopDir(); } break; case 125: { // "JumpDirConf" JumpDirConf(); } break; case 126: { // "ListFiles" ListFiles(); } break; case 127: { // "NewFileScan" NewFileScan(); } break; case 128: { // "SetNewFileScanDate" SetNewFileScanDate(); } break; case 129: { // "RemoveFiles" RemoveFiles(); } break; case 130: { // "SearchAllFiles" SearchAllFiles(); } break; case 131: { // "XferDefaults" XferDefaults(); } break; case 132: { // "Upload" Upload(); } break; case 133: { // "YourInfoDL" YourInfoDL(); } break; case 134: { // "UploadToSysop" UploadToSysop(); } break; case 135: { // "ReadAutoMessage" ReadAutoMessage(); } break; case 136: { // "SetNewScanMsg" SetNewScanMsg(); } break; case 137: { // "ReadMessages" ReadMessages(); } break; /* case 138: { // "RUN" ExecuteBasic(szParam1); } break; */ case 139: { // "EventEdit" EventEdit(); } break; case 140: { // "LoadTextFile" LoadTextFile(); } break; case 141: { // "GuestApply" GuestApply(); } break; case 142: { // "ConfigFileList" ConfigFileList(); } break; case 143: { // "ListAllColors" ListAllColors(); } break; #ifdef QUESTIONS case 144: { // "EditQuestions" EditQuestions(); } break; case 145: { // "Questions" Questions(); } break; #endif case 146: { // "RemoveNotThere" RemoveNotThere(); } break; case 147: { // "AttachFile" AttachFile(); } break; case 148: { // "InternetEmail" InternetEmail(); } break; case 149: { // "UnQScan" UnQScan(); } break; // ppMenuStringsIndex[150] thru ppMenuStringsIndex[153] not used..... case 154: { // "Packers" Packers(); } break; case 155: { // Color_Config color_config(); } break; //------------------------------------------------------------------ // ppMenuStringsIndex[156] and [157] are reserved for SDS Systems and systems // that distribute modifications. DO NOT reuse these strings for // other menu options. //------------------------------------------------------------------ // case 156: // { // ModAccess // ModsAccess(); // } break; // case 157: // { // SDSAccess // SDSAccess(); // } break; //------------------------------------------------------------------ case 158: { // InitVotes InitVotes(); } break; case 161: { // TurnMCIOn TurnMCIOn(); } break; case 162: { // TurnMCIOff TurnMCIOff(); } break; default: { MenuSysopLog("The following command was not recognized"); MenuSysopLog(szCmd); } break; } } }
int sbbs_t::exec_misc(csi_t* csi, char *path) { char str[512],tmp[512],buf[1025],ch,op,*p,**pp,**pp1,**pp2; ushort w; uint i=0,j; long l,*lp=NULL,*lp1=NULL,*lp2=NULL; void *vp; struct dirent *de; struct tm tm; switch(*(csi->ip++)) { case CS_VAR_INSTRUCTION: switch(*(csi->ip++)) { /* sub-op-code stored as next byte */ case PRINT_VAR: pp=getstrvar(csi,*(long *)csi->ip); if(!pp || !*pp) { lp=getintvar(csi,*(long *)csi->ip); if(lp) bprintf("%ld",*lp); } else putmsg(cmdstr(*pp,path,csi->str,buf) ,P_SAVEATR|P_NOABORT|P_NOATCODES); csi->ip+=4; return(0); case VAR_PRINTF: case VAR_PRINTF_LOCAL: op=*(csi->ip-1); p=format_string(this, csi); if(op==VAR_PRINTF) putmsg(cmdstr(p,path,csi->str,buf),P_SAVEATR|P_NOABORT|P_NOATCODES); else { if(online==ON_LOCAL) eprintf(LOG_INFO,"%s",cmdstr(p,path,csi->str,buf)); else lputs(LOG_INFO,cmdstr(p,path,csi->str,buf)); } free(p); return(0); case SHOW_VARS: bprintf("shell str=(%08lX) %s\r\n" ,csi->str,csi->str); for(i=0;i<csi->str_vars;i++) bprintf("local str[%d]=(%08lX) (%08lX) %s\r\n" ,i,csi->str_var_name[i] ,csi->str_var[i] ,csi->str_var[i]); for(i=0;i<csi->int_vars;i++) bprintf("local int[%d]=(%08lX) (%08lX) %ld\r\n" ,i,csi->int_var_name[i] ,csi->int_var[i] ,csi->int_var[i]); for(i=0;i<global_str_vars;i++) bprintf("global str[%d]=(%08lX) (%08lX) %s\r\n" ,i,global_str_var_name[i] ,global_str_var[i] ,global_str_var[i]); for(i=0;i<global_int_vars;i++) bprintf("global int[%d]=(%08lX) (%08lX) %ld\r\n" ,i,global_int_var_name[i] ,global_int_var[i] ,global_int_var[i]); return(0); case DEFINE_STR_VAR: if(getstrvar(csi,*(long *)csi->ip)) { csi->ip+=4; return(0); } csi->str_vars++; csi->str_var=(char **)realloc(csi->str_var ,sizeof(char *)*csi->str_vars); csi->str_var_name=(long *)realloc(csi->str_var_name ,sizeof(long)*csi->str_vars); if(csi->str_var==NULL || csi->str_var_name==NULL) { /* REALLOC failed */ errormsg(WHERE,ERR_ALLOC,"local str var" ,sizeof(char *)*csi->str_vars); if(csi->str_var_name) { free(csi->str_var_name); csi->str_var_name=0; } if(csi->str_var) { free(csi->str_var); csi->str_var=0; } csi->str_vars=0; } else { csi->str_var_name[csi->str_vars-1]=*(long *)csi->ip; csi->str_var[csi->str_vars-1]=0; } csi->ip+=4; /* Skip variable name */ return(0); case DEFINE_INT_VAR: if(getintvar(csi,*(long *)csi->ip)) { csi->ip+=4; return(0); } csi->int_vars++; csi->int_var=(long *)realloc(csi->int_var ,sizeof(char *)*csi->int_vars); csi->int_var_name=(long *)realloc(csi->int_var_name ,sizeof(long)*csi->int_vars); if(csi->int_var==NULL || csi->int_var_name==NULL) { /* REALLOC failed */ errormsg(WHERE,ERR_ALLOC,"local int var" ,sizeof(char *)*csi->int_vars); if(csi->int_var_name) { free(csi->int_var_name); csi->int_var_name=0; } if(csi->int_var) { free(csi->int_var); csi->int_var=0; } csi->int_vars=0; } else { csi->int_var_name[csi->int_vars-1]=*(long *)csi->ip; csi->int_var[csi->int_vars-1]=0; } csi->ip+=4; /* Skip variable name */ return(0); case DEFINE_GLOBAL_STR_VAR: if(getstrvar(csi,*(long *)csi->ip)) { csi->ip+=4; return(0); } global_str_vars++; global_str_var=(char **)realloc(global_str_var ,sizeof(char *)*global_str_vars); global_str_var_name=(long *)realloc(global_str_var_name ,sizeof(long)*global_str_vars); if(global_str_var==NULL || global_str_var_name==NULL) { /* REALLOC failed */ errormsg(WHERE,ERR_ALLOC,"global str var" ,sizeof(char *)*global_str_vars); if(global_str_var_name) { free(global_str_var_name); global_str_var_name=0; } if(global_str_var) { free(global_str_var); global_str_var=0; } global_str_vars=0; } else { global_str_var_name[global_str_vars-1]= *(long *)csi->ip; global_str_var[global_str_vars-1]=0; } csi->ip+=4; /* Skip variable name */ return(0); case DEFINE_GLOBAL_INT_VAR: if(getintvar(csi,*(long *)csi->ip)) { csi->ip+=4; return(0); } global_int_vars++; global_int_var=(long *)realloc(global_int_var ,sizeof(char *)*global_int_vars); global_int_var_name=(long *)realloc(global_int_var_name ,sizeof(long)*global_int_vars); if(global_int_var==NULL || global_int_var_name==NULL) { /* REALLOC failed */ errormsg(WHERE,ERR_ALLOC,"local int var" ,sizeof(char *)*global_int_vars); if(global_int_var_name) { free(global_int_var_name); global_int_var_name=0; } if(global_int_var) { free(global_int_var); global_int_var=0; } global_int_vars=0; } else { global_int_var_name[global_int_vars-1] =*(long *)csi->ip; global_int_var[global_int_vars-1]=0; } csi->ip+=4; /* Skip variable name */ return(0); case SET_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(pp) *pp=copystrvar(csi,*pp ,cmdstr((char *)csi->ip,path,csi->str,buf)); while(*(csi->ip++)); /* Find NULL */ return(0); case SET_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(lp) *lp=*(long *)csi->ip; csi->ip+=4; /* Skip value */ return(0); case COMPARE_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(pp && *pp) csi->logic=stricmp(*pp ,cmdstr((char *)csi->ip,path,csi->str,buf)); else { /* Uninitialized str var */ if(*(csi->ip)==0) /* Blank static str */ csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; } while(*(csi->ip++)); /* Find NULL */ return(0); case STRSTR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(pp && *pp && strstr(*pp ,cmdstr((char *)csi->ip,path,csi->str,buf))) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; while(*(csi->ip++)); /* Find NULL */ return(0); case STRNCMP_VAR: i=*csi->ip++; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(pp && *pp) csi->logic=strnicmp(*pp ,cmdstr((char *)csi->ip,path,csi->str,buf),i); else csi->logic=LOGIC_FALSE; while(*(csi->ip++)); /* Find NULL */ return(0); case STRNCMP_VARS: i=*csi->ip++; pp1=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp1 && *pp1 && pp2 && *pp2) csi->logic=strnicmp(*pp1,*pp2,i); else csi->logic=LOGIC_FALSE; return(0); case STRSTR_VARS: pp1=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp1 && *pp1 && pp2 && *pp2 && strstr(*pp1,*pp2)) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case COMPARE_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ l=*(long *)csi->ip; csi->ip+=4; /* Skip static value */ if(!lp) { /* Unknown variable */ csi->logic=LOGIC_FALSE; return(0); } if(*lp>l) csi->logic=LOGIC_GREATER; else if(*lp<l) csi->logic=LOGIC_LESS; else csi->logic=LOGIC_EQUAL; return(0); case COMPARE_VARS: lp1=lp2=0; pp1=getstrvar(csi,*(long *)csi->ip); if(!pp1) lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); if(!pp2) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(((!pp1 || !*pp1) && !lp1) || ((!pp2 || !*pp2) && !lp2)) { if(pp1 && pp2) /* Both unitialized or blank */ csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); } if(pp1) { /* ASCII */ if(!pp2) { ultoa(*lp2,tmp,10); csi->logic=stricmp(*pp1,tmp); } else csi->logic=stricmp(*pp1,*pp2); return(0); } /* Binary */ if(!lp2) { l=strtol(*pp2,0,0); if(*lp1>l) csi->logic=LOGIC_GREATER; else if(*lp1<l) csi->logic=LOGIC_LESS; else csi->logic=LOGIC_EQUAL; return(0); } if(*lp1>*lp2) csi->logic=LOGIC_GREATER; else if(*lp1<*lp2) csi->logic=LOGIC_LESS; else csi->logic=LOGIC_EQUAL; return(0); case COPY_VAR: lp1=lp2=0; pp1=getstrvar(csi,*(long *)csi->ip); if(!pp1) lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); if(!pp2) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if((!pp1 && !lp1) || ((!pp2 || !*pp2) && !lp2)) { csi->logic=LOGIC_FALSE; return(0); } csi->logic=LOGIC_TRUE; if(pp1) { /* ASCII */ if(!pp2) ultoa(*lp2,tmp,10); else strcpy(tmp,*pp2); *pp1=copystrvar(csi,*pp1,tmp); return(0); } if(!lp2) *lp1=strtol(*pp2,0,0); else *lp1=*lp2; return(0); case SWAP_VARS: lp1=lp2=0; pp1=getstrvar(csi,*(long *)csi->ip); if(!pp1) lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); if(!pp2) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ if(((!pp1 || !*pp1) && !lp1) || ((!pp2 || !*pp2) && !lp2)) { csi->logic=LOGIC_FALSE; return(0); } csi->logic=LOGIC_TRUE; if(pp1) { /* ASCII */ if(!pp2) { if(!strnicmp(*pp2,"0x",2)) { l=strtol((*pp1)+2,0,16); ultoa(*lp2,tmp,16); } else { l=atol(*pp1); ultoa(*lp2,tmp,10); } *pp1=copystrvar(csi,*pp1,tmp); *lp2=l; } else { p=*pp1; *pp1=*pp2; *pp2=p; } return(0); } /* Binary */ if(!lp2) { if(!strnicmp(*pp2,"0x",2)) { l=strtol((*pp2)+2,0,16); ultoa(*lp1,tmp,16); } else { l=atol(*pp2); ultoa(*lp1,tmp,10); } *pp2=copystrvar(csi,*pp2,tmp); *lp1=l; } else { l=*lp1; *lp1=*lp2; *lp2=l; } return(0); case CAT_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ strcpy(tmp,(char *)csi->ip); while(*(csi->ip++)); if(pp && *pp) for(i=0;i<MAX_SYSVARS;i++) if(*pp==sysvar_p[i]) break; if(pp && *pp!=csi->str && i==MAX_SYSVARS) { if(*pp) *pp=(char *)realloc(*pp,strlen(*pp)+strlen(tmp)+1); else *pp=(char *)realloc(*pp,strlen(tmp)+1); } if(pp && *pp) strcat(*pp,tmp); return(0); case CAT_STR_VARS: pp1=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip dest variable name */ pp2=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip source variable name */ /* Concatenate an int var to a str var (as char) */ if(pp2==NULL) { lp=getintvar(csi,*(long *)(csi->ip-4)); if(lp==NULL) { csi->logic=LOGIC_FALSE; return(0); } pp=pp1; tmp[0]=(uchar)*lp; tmp[1]=0; if(pp && *pp) for(i=0;i<MAX_SYSVARS;i++) if(*pp==sysvar_p[i]) break; if(pp && *pp!=csi->str && i==MAX_SYSVARS) { if(*pp) *pp=(char *)realloc(*pp,strlen(*pp)+strlen(tmp)+1); else *pp=(char *)realloc(*pp,strlen(tmp)+1); } if(pp && *pp) strcat(*pp,tmp); return(0); } if(!pp1 || !pp2 || !*pp2) { csi->logic=LOGIC_FALSE; return(0); } csi->logic=LOGIC_TRUE; if(*pp1) for(i=0;i<MAX_SYSVARS;i++) if(*pp1==sysvar_p[i]) break; if(*pp1!=csi->str && (!*pp1 || i==MAX_SYSVARS)) { if(*pp1) *pp1=(char *)realloc(*pp1,strlen(*pp1)+strlen(*pp2)+1); else *pp1=(char *)realloc(*pp1,strlen(*pp2)+1); } strcat(*pp1,*pp2); return(0); case FORMAT_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ p=format_string(this, csi); cmdstr(p,path,csi->str,str); if(pp) *pp=copystrvar(csi,*pp,str); free(p); return(0); case FORMAT_TIME_STR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ strcpy(str,(char *)csi->ip); while(*(csi->ip++)); /* Find NULL */ lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && lp) { if(localtime_r((time_t *)lp,&tm)!=NULL) { strftime(buf,128,str,&tm); *pp=copystrvar(csi,*pp,buf); } } return(0); case TIME_STR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip str variable name */ lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip int variable name */ if(pp && lp) { strcpy(str,timestr((time_t *)lp)); *pp=copystrvar(csi,*pp,str); } return(0); case DATE_STR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip str variable name */ lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip int variable name */ if(pp && lp) { unixtodstr(&cfg,*lp,str); *pp=copystrvar(csi,*pp,str); } return(0); case SECOND_STR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip str variable name */ lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip int variable name */ if(pp && lp) { sectostr(*lp,str); *pp=copystrvar(csi,*pp,str); } return(0); case STRUPR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) strupr(*pp); return(0); case STRLWR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) strlwr(*pp); return(0); case TRUNCSP_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) truncsp(*pp); return(0); case STRIP_CTRL_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) strip_ctrl(*pp); return(0); case ADD_INT_VAR: case SUB_INT_VAR: case MUL_INT_VAR: case DIV_INT_VAR: case MOD_INT_VAR: case AND_INT_VAR: case OR_INT_VAR: case NOT_INT_VAR: case XOR_INT_VAR: i=*(csi->ip-1); lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; l=*(long *)csi->ip; csi->ip+=4; if(!lp) return(0); switch(i) { case ADD_INT_VAR: *lp+=l; break; case SUB_INT_VAR: *lp-=l; break; case MUL_INT_VAR: *lp*=l; break; case DIV_INT_VAR: *lp/=l; break; case MOD_INT_VAR: *lp%=l; break; case AND_INT_VAR: *lp&=l; break; case OR_INT_VAR: *lp|=l; break; case NOT_INT_VAR: *lp&=~l; break; case XOR_INT_VAR: *lp^=l; break; } return(0); case COMPARE_ANY_BITS: case COMPARE_ALL_BITS: i=*(csi->ip-1); lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; l=*(long *)csi->ip; csi->ip+=4; csi->logic=LOGIC_FALSE; if(!lp) return(0); if(i==COMPARE_ANY_BITS) { if(((*lp)&l)!=0) csi->logic=LOGIC_TRUE; } else { if(((*lp)&l)==l) csi->logic=LOGIC_TRUE; } return(0); case ADD_INT_VARS: case SUB_INT_VARS: case MUL_INT_VARS: case DIV_INT_VARS: case MOD_INT_VARS: case AND_INT_VARS: case OR_INT_VARS: case NOT_INT_VARS: case XOR_INT_VARS: i=*(csi->ip-1); lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); if(!lp2) { pp=getstrvar(csi,*(long *)csi->ip); if(!pp || !*pp) return(0); l=strtol(*pp,0,0); } else l=*lp2; csi->ip+=4; if(!lp1) return(0); switch(i) { case ADD_INT_VARS: *lp1+=l; break; case SUB_INT_VARS: *lp1-=l; break; case MUL_INT_VARS: *lp1*=l; break; case DIV_INT_VARS: *lp1/=l; break; case MOD_INT_VARS: *lp1%=l; break; case AND_INT_VARS: *lp1&=l; break; case OR_INT_VARS: *lp1|=l; break; case NOT_INT_VARS: *lp1&=~l; break; case XOR_INT_VARS: *lp1^=l; break; } return(0); case RANDOM_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; l=*(long *)csi->ip; csi->ip+=4; if(lp) *lp=sbbs_random(l); return(0); case TIME_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) *lp=time(NULL); return(0); case DATE_STR_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp && pp && *pp) *lp=dstrtounix(&cfg,*pp); return(0); case STRLEN_INT_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=strlen(*pp); else *lp=0; } return(0); case CRC16_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=crc16(*pp,0); else *lp=0; } return(0); case CRC32_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=crc32(*pp,0); else *lp=0; } return(0); case CHKSUM_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { *lp=0; if(pp && *pp) { i=0; while(*((*pp)+i)) *lp+=(uchar)*((*pp)+(i++)); } } return(0); case FLENGTH_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=flength(*pp); else *lp=0; } return(0); case FTIME_TO_INT: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=fdate(*pp); else *lp=0; } return(0); case CHARVAL_TO_INT: case COPY_FIRST_CHAR: // duplicate functionality - doh! lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=**pp; else *lp=0; } return(0); case GETSTR_VAR: case GETLINE_VAR: case GETNAME_VAR: case GETSTRUPR_VAR: case GETSTR_MODE: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(csi->ip++); csi->logic=LOGIC_FALSE; switch(*(csi->ip-6)) { case GETNAME_VAR: getstr(buf,i,K_UPRLWR); break; case GETSTRUPR_VAR: getstr(buf,i,K_UPPER); break; case GETLINE_VAR: getstr(buf,i,K_LINE); break; case GETSTR_MODE: l=*(long *)csi->ip; csi->ip+=4; if(l&K_EDIT) { if(pp && *pp) strcpy(buf,*pp); else buf[0]=0; } getstr(buf,i,l); break; default: getstr(buf,i,0); } if(sys_status&SS_ABORT) return(0); if(pp) { *pp=copystrvar(csi,*pp,buf); csi->logic=LOGIC_TRUE; } return(0); case GETNUM_VAR: pp=getstrvar(csi,*(long *)csi->ip); if(!pp) lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(short *)csi->ip; csi->ip+=2; csi->logic=LOGIC_FALSE; l=getnum(i); if(!pp && !lp) return(0); if(pp) { if(l<=0) str[0]=0; else ultoa(l,str,10); *pp=copystrvar(csi,*pp,str); csi->logic=LOGIC_TRUE; return(0); } if(lp) { *lp=l; csi->logic=LOGIC_TRUE; } return(0); case SHIFT_STR_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(csi->ip++); if(!pp || !*pp) return(0); if(strlen(*pp)>=i) memmove(*pp,*pp+i,strlen(*pp)+1); return(0); case SHIFT_TO_FIRST_CHAR: case SHIFT_TO_LAST_CHAR: i=*(csi->ip-1); pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; ch=*(csi->ip++); csi->logic=LOGIC_FALSE; if(!pp || !*pp) return(0); if(i==SHIFT_TO_FIRST_CHAR) p=strchr(*pp,ch); else /* _TO_LAST_CHAR */ p=strrchr(*pp,ch); if(p==NULL) return(0); csi->logic=LOGIC_TRUE; i=p-*pp; if(i>0) memmove(*pp,*pp+i,strlen(p)+1); return(0); case CHKFILE_VAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp && fexistcase(cmdstr(*pp,path,csi->str,buf))) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case PRINTFILE_VAR_MODE: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(short *)(csi->ip); csi->ip+=2; if(pp && *pp) printfile(*pp,i); return(0); case PRINTTAIL_VAR_MODE: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; i=*(short *)(csi->ip); csi->ip+=2; j=*csi->ip; csi->ip++; if(pp && *pp) printtail(*pp,j,i); return(0); case TELNET_GATE_VAR: l=*(ulong *)(csi->ip); // Mode csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) telnet_gate(*pp,l); return(0); case TELNET_GATE_STR: l=*(ulong *)(csi->ip); // Mode csi->ip+=4; strcpy(str,(char *)csi->ip); while(*(csi->ip++)); /* Find NULL */ telnet_gate(str,l); return(0); case COPY_CHAR: pp=getstrvar(csi,*(long *)csi->ip); if(pp==NULL) lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp==NULL && lp!=NULL) *lp=csi->cmd; else if(pp!=NULL) { sprintf(tmp,"%c",csi->cmd); *pp=copystrvar(csi,*pp,tmp); } return(0); case COMPARE_FIRST_CHAR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; ch=*(csi->ip++); /* char const */ if(pp==NULL || *pp==NULL) csi->logic=LOGIC_FALSE; else { if(**pp==ch) csi->logic=LOGIC_EQUAL; else if(**pp>ch) csi->logic=LOGIC_GREATER; else csi->logic=LOGIC_LESS; } return(0); case SEND_FILE_VIA: case RECEIVE_FILE_VIA: j=*(csi->ip-1); ch=*(csi->ip++); /* Protocol */ cmdstr((char *)csi->ip,csi->str,csi->str,str); while(*(csi->ip++)); /* Find NULL */ for(i=0;i<cfg.total_prots;i++) if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron)) break; csi->logic=LOGIC_FALSE; if(i<cfg.total_prots) if(protocol(cfg.prot[i],j==SEND_FILE_VIA ? XFER_DOWNLOAD : XFER_UPLOAD ,str,str,true)==0) csi->logic=LOGIC_TRUE; return(0); case SEND_FILE_VIA_VAR: case RECEIVE_FILE_VIA_VAR: j=*(csi->ip-1); ch=*(csi->ip++); /* Protocol */ pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; for(i=0;i<cfg.total_prots;i++) if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron)) break; csi->logic=LOGIC_FALSE; if(!pp || !(*pp)) return(0); if(i<cfg.total_prots) if(protocol(cfg.prot[i] ,j==SEND_FILE_VIA_VAR ? XFER_DOWNLOAD : XFER_UPLOAD ,*pp,*pp,true)==0) csi->logic=LOGIC_TRUE; return(0); case MATCHUSER: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { if(pp && *pp) *lp=matchuser(&cfg, *pp, TRUE /*sysop_alias*/); else *lp=0; } return(0); default: errormsg(WHERE,ERR_CHK,"var sub-instruction",*(csi->ip-1)); return(0); } case CS_FIO_FUNCTION: switch(*(csi->ip++)) { /* sub-op-code stored as next byte */ case FIO_OPEN: case FIO_OPEN_VAR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; w=*(ushort *)csi->ip; csi->ip+=2; csi->logic=LOGIC_FALSE; if(*(csi->ip-7)==FIO_OPEN) { cmdstr((char *)csi->ip,path,csi->str,str); while(*(csi->ip++)); } /* skip filename */ else { pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(!pp || !*pp) return(0); strcpy(str,*pp); } if(csi->files>=MAX_FOPENS) return(0); if(lp) { /* Access flags are not cross-platform, so convert */ i=0; if(w&0x001) i|=O_RDONLY; if(w&0x002) i|=O_WRONLY; if(w&0x004) i|=O_RDWR; if(w&0x040) i|=O_DENYNONE; if(w&0x100) i|=O_CREAT; if(w&0x200) i|=O_TRUNC; if(w&0x400) i|=O_EXCL; if(w&0x800) i|=O_APPEND; *lp=(long)fnopen((int *)&j,str,i); if(*lp) { for(i=0;i<csi->files;i++) if(!csi->file[i]) break; csi->file[i]=(FILE *)*lp; if(i==csi->files) csi->files++; csi->logic=LOGIC_TRUE; } } return(0); case FIO_CLOSE: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp && *lp) { csi->logic=fclose((FILE *)*lp); for(i=0;i<csi->files;i++) if(csi->file[i]==(FILE *)*lp) csi->file[i]=0; *lp=0; } else csi->logic=LOGIC_FALSE; return(0); case FIO_FLUSH: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp && *lp) csi->logic=fflush((FILE *)*lp); else csi->logic=LOGIC_FALSE; return(0); case FIO_READ: case FIO_READ_VAR: lp1=getintvar(csi,*(long *)csi->ip); /* Handle */ csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); if(!pp) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-9)==FIO_READ) { i=*(short *)csi->ip; csi->ip+=2; /* Length */ } else { /* FIO_READ_VAR */ vp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!vp) return(0); i=*(short *)vp; } if(i>sizeof(buf)-1) i=sizeof(buf)-1; if(!lp1 || !(*lp1) || (!pp && !lp2)) return(0); if(pp) { if(i<1) { if(*pp && **pp) i=strlen(*pp); else i=128; } if((j=fread(buf,1,i,(FILE *)*lp1))==i) csi->logic=LOGIC_TRUE; buf[j]=0; if(csi->etx) { p=strchr(buf,csi->etx); if(p) *p=0; } *pp=copystrvar(csi,*pp,buf); } else { *lp2=0; if(i>4 || i<1) i=4; if(fread(lp2,1,i,(FILE *)*lp1)==i) csi->logic=LOGIC_TRUE; } return(0); case FIO_READ_LINE: lp1=getintvar(csi,*(long *)csi->ip); /* Handle */ csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); if(!pp) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(!lp1 || !(*lp1) || feof((FILE *)*lp1) || (!pp && !lp2)) return(0); csi->logic=LOGIC_TRUE; for(i=0;i<sizeof(buf)-1;i++) { if(!fread(buf+i,1,1,(FILE *)*lp1)) break; if(*(buf+i)==LF) { i++; break; } } buf[i]=0; if(csi->etx) { p=strchr(buf,csi->etx); if(p) *p=0; } if(pp) *pp=copystrvar(csi,*pp,buf); else *lp2=strtol(buf,0,0); return(0); case FIO_WRITE: case FIO_WRITE_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); if(!pp) lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-9)==FIO_WRITE) { i=*(short *)csi->ip; csi->ip+=2; /* Length */ } else { /* FIO_WRITE_VAR */ vp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!vp) return(0); i=*(short *)vp; } if(i>sizeof(buf)-1) i=sizeof(buf)-1; if(!lp1 || !(*lp1) || (!pp && !lp2) || (pp && !*pp)) return(0); if(pp) { j=strlen(*pp); if(i<1) i=j; if(j>i) j=i; if(fwrite(*pp,1,j,(FILE *)*lp1)!=j) csi->logic=LOGIC_FALSE; else { if(j<i) { memset(buf,csi->etx,i-j); fwrite(buf,1,i-j,(FILE *)*lp1); } csi->logic=LOGIC_TRUE; } } else { if(i<1 || i>4) i=4; if(fwrite(lp2,1,i,(FILE *)*lp1)==i) csi->logic=LOGIC_TRUE; } return(0); case FIO_GET_LENGTH: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp1 && *lp1 && lp2) *lp2=filelength(fileno((FILE *)*lp1)); return(0); case FIO_GET_TIME: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp1 && *lp1 && lp2) *lp2=filetime(fileno((FILE *)*lp1)); return(0); case FIO_SET_TIME: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; #if 0 /* ftime */ if(lp1 && *lp1 && lp2) { ft=unixtoftime(*lp2); setftime(fileno((FILE *)*lp1),&ft); } #endif return(0); case FIO_EOF: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(lp && *lp) if(ftell((FILE *)*lp)>=filelength(fileno((FILE *)*lp))) csi->logic=LOGIC_TRUE; return(0); case FIO_GET_POS: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp1 && *lp1 && lp2) *lp2=ftell((FILE *)*lp1); return(0); case FIO_SEEK: case FIO_SEEK_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-5)==FIO_SEEK) { l=*(long *)csi->ip; csi->ip+=4; } else { lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp2) { csi->ip+=2; return(0); } l=*lp2; } i=*(short *)csi->ip; csi->ip+=2; if(lp1 && *lp1) if(fseek((FILE *)*lp1,l,i)!=-1) csi->logic=LOGIC_TRUE; return(0); case FIO_LOCK: case FIO_LOCK_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-5)==FIO_LOCK) { l=*(long *)csi->ip; csi->ip+=4; } else { lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp2) return(0); l=*lp2; } if(lp1 && *lp1) { fflush((FILE *)*lp1); csi->logic=!lock(fileno((FILE *)*lp1),ftell((FILE*)*lp1),l); } return(0); case FIO_UNLOCK: case FIO_UNLOCK_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-5)==FIO_UNLOCK) { l=*(long *)csi->ip; csi->ip+=4; } else { lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp2) return(0); l=*lp2; } if(lp1 && *lp1) { fflush((FILE *)*lp1); csi->logic=!unlock(fileno((FILE *)*lp1),ftell((FILE*)*lp1),l); } return(0); case FIO_SET_LENGTH: case FIO_SET_LENGTH_VAR: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(*(csi->ip-5)==FIO_SET_LENGTH) { l=*(long *)csi->ip; csi->ip+=4; } else { lp2=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp2) return(0); l=*lp2; } if(lp1 && *lp1) csi->logic=chsize(fileno((FILE *)*lp1),l); return(0); case FIO_PRINTF: lp1=getintvar(csi,*(long *)csi->ip); csi->ip+=4; p=format_string(this, csi); if(lp1 && *lp1) { cmdstr(p,path,csi->str,str); fwrite(str,1,strlen(str),(FILE *)*lp1); } free(p); return(0); case FIO_SET_ETX: csi->etx=*(csi->ip++); return(0); case REMOVE_FILE: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp && remove(*pp)==0) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); case RENAME_FILE: case COPY_FILE: case MOVE_FILE: pp1=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; /* Skip variable name */ pp2=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp1 && *pp1 && pp2 && *pp2) switch(*(csi->ip-9)) { case RENAME_FILE: csi->logic=rename(*pp1,*pp2); break; case COPY_FILE: csi->logic=mv(*pp1,*pp2,1); break; case MOVE_FILE: csi->logic=mv(*pp1,*pp2,0); break; } else csi->logic=LOGIC_FALSE; return(0); case GET_FILE_ATTRIB: case SET_FILE_ATTRIB: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp && lp) { if(*(csi->ip-9)==GET_FILE_ATTRIB) *lp=getfattr(*pp); else *lp=CHMOD(*pp,(int)*lp); } return(0); case MAKE_DIR: case REMOVE_DIR: case CHANGE_DIR: pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; if(pp && *pp) switch(*(csi->ip-5)) { case MAKE_DIR: csi->logic=MKDIR(*pp); break; case REMOVE_DIR: csi->logic=rmdir(*pp); break; case CHANGE_DIR: csi->logic=chdir(*pp); break; } else csi->logic=LOGIC_FALSE; return(0); case OPEN_DIR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(pp && *pp && lp) { *lp=(long)opendir((char *)*pp); if(*lp) csi->logic=LOGIC_TRUE; } return(0); case READ_DIR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; pp=getstrvar(csi,*(long *)csi->ip); csi->ip+=4; csi->logic=LOGIC_FALSE; if(pp && lp) { de=readdir((DIR *)(*lp)); if(de!=NULL) { csi->logic=LOGIC_TRUE; *pp=copystrvar(csi,*pp,de->d_name); } } return(0); case REWIND_DIR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp) { rewinddir((DIR *)(*lp)); csi->logic=LOGIC_TRUE; } else csi->logic=LOGIC_FALSE; return(0); case CLOSE_DIR: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(lp && closedir((DIR *)(*lp))==0) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; return(0); default: errormsg(WHERE,ERR_CHK,"fio sub-instruction",*(csi->ip-1)); return(0); } case CS_NET_FUNCTION: return(exec_net(csi)); case CS_SWITCH: lp=getintvar(csi,*(long *)csi->ip); csi->ip+=4; if(!lp) { skipto(csi,CS_END_SWITCH); csi->ip++; } else { csi->misc|=CS_IN_SWITCH; csi->switch_val=*lp; } return(0); case CS_CASE: l=*(long *)csi->ip; csi->ip+=4; if(csi->misc&CS_IN_SWITCH && csi->switch_val!=l) skipto(csi,CS_NEXTCASE); else csi->misc&=~CS_IN_SWITCH; return(0); case CS_COMPARE_ARS: i=*(csi->ip++); /* Length of ARS stored as byte before ARS */ csi->logic=!chk_ar(csi->ip,&useron); csi->ip+=i; return(0); case CS_TOGGLE_USER_MISC: useron.misc^=*(ulong *)csi->ip; putuserrec(&cfg,useron.number,U_MISC,8,ultoa(useron.misc,tmp,16)); csi->ip+=4; return(0); case CS_COMPARE_USER_MISC: if((useron.misc&*(ulong *)csi->ip)==*(ulong *)csi->ip) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; csi->ip+=4; return(0); case CS_TOGGLE_USER_CHAT: useron.chat^=*(ulong *)csi->ip; putuserrec(&cfg,useron.number,U_CHAT,8,ultoa(useron.chat,tmp,16)); csi->ip+=4; return(0); case CS_COMPARE_USER_CHAT: if((useron.chat&*(ulong *)csi->ip)==*(ulong *)csi->ip) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; csi->ip+=4; return(0); case CS_TOGGLE_USER_QWK: useron.qwk^=*(ulong *)csi->ip; putuserrec(&cfg,useron.number,U_QWK,8,ultoa(useron.qwk,tmp,16)); csi->ip+=4; return(0); case CS_COMPARE_USER_QWK: if((useron.qwk&*(ulong *)csi->ip)==*(ulong *)csi->ip) csi->logic=LOGIC_TRUE; else csi->logic=LOGIC_FALSE; csi->ip+=4; return(0); case CS_REPLACE_TEXT: i=*(ushort *)csi->ip; csi->ip+=2; i--; if(i>=TOTAL_TEXT) { errormsg(WHERE,ERR_CHK,"replace text #",i); while(*(csi->ip++)); /* Find NULL */ return(0); } if(text[i]!=text_sav[i] && text[i]!=nulstr) free(text[i]); j=strlen(cmdstr((char *)csi->ip,path,csi->str,buf)); if(!j) text[i]=nulstr; else text[i]=(char *)malloc(j+1); if(!text[i]) { errormsg(WHERE,ERR_ALLOC,"replacement text",j); while(*(csi->ip++)); /* Find NULL */ text[i]=text_sav[i]; return(0); } if(j) strcpy(text[i],buf); while(*(csi->ip++)); /* Find NULL */ return(0); case CS_USE_INT_VAR: // Self-modifying code! pp=getstrvar(csi,*(long *)csi->ip); if(pp && *pp) l=strtol(*pp,0,0); else { lp=getintvar(csi,*(long *)csi->ip); if(lp) l=*lp; else l=0; } csi->ip+=4; // Variable i=*(csi->ip++); // Offset if(i<1 || csi->ip+1+i>=csi->cs+csi->length) { errormsg(WHERE,ERR_CHK,"offset",i); csi->ip++; return(0); } switch(*(csi->ip++)) { // Length case sizeof(char): *(csi->ip+i)=(char)l; break; case sizeof(short): *((short *)(csi->ip+i))=(short)l; break; case sizeof(long): *((long *)(csi->ip+i))=l; break; default: errormsg(WHERE,ERR_CHK,"length",*(csi->ip-1)); break; } return(0); default: errormsg(WHERE,ERR_CHK,"shell instruction",*(csi->ip-1)); return(0); } }
int main(int argc, char** argv) { int c; int verbose = 0; int fileid = 0; int quiet = 0; char* filename = NULL; char* modname = NULL; char* p; while ((c = getopt(argc, argv, "i:m:n:qv")) != -1) switch (c) { case 'i': fileid = (int)strtoul(optarg, &p, 10); if (*p != '\0') usage(); break; case 'm': modname = optarg; break; case 'n': filename = optarg; break; case 'q': quiet = 1; break; case 'v': verbose = 1; break; default: usage(); } argc -= optind; argv += optind; if (argc != 0) usage(); if (modname != NULL) { int modid; struct module_stat stat; if ((modid = modfind(modname)) < 0) { if (!quiet) warn("can't find module %s", modname); return 1; } else if (quiet) { return 0; } stat.version = sizeof(struct module_stat); if (modstat(modid, &stat) < 0) warn("can't stat module id %d", modid); else { printf("Id Refs Name\n"); printf("%3d %4d %s\n", stat.id, stat.refs, stat.name); } return 0; } if (filename != NULL) { if ((fileid = kldfind(filename)) < 0) err(1, "can't find file %s", filename); } printf("Id Refs Address%*c Size Name\n", POINTER_WIDTH - 7, ' '); if (fileid != 0) printfile(fileid, verbose); else for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) printfile(fileid, verbose); return 0; }
int sbbs_t::text_sec() { char str[256],usemenu ,*file[MAX_TXTFILES],addpath[83],addstr[83],*buf,ch; char tmp[512]; long i,j,usrsec[MAX_TXTSECS],usrsecs,cursec; long l,length; FILE *stream; for(i=j=0;i<cfg.total_txtsecs;i++) { if(!chk_ar(cfg.txtsec[i]->ar,&useron,&client)) continue; usrsec[j++]=i; } usrsecs=j; if(!usrsecs) { bputs(text[NoTextSections]); return(1); } action=NODE_RTXT; while(online) { sprintf(str,"%smenu/text_sec.*",cfg.text_dir); if(fexist(str)) menu("text_sec"); else { bputs(text[TextSectionLstHdr]); for(i=0;i<usrsecs && !msgabort();i++) { sprintf(str,text[TextSectionLstFmt],i+1,cfg.txtsec[usrsec[i]]->name); if(i<9) outchar(' '); bputs(str); } } ASYNC; mnemonics(text[WhichTextSection]); if((cursec=getnum(usrsecs))<1) break; cursec--; while(online) { sprintf(str,"%smenu/text%lu.*",cfg.text_dir,cursec+1); if(fexist(str)) { sprintf(str,"text%lu",cursec+1); menu(str); usemenu=1; } else { bprintf(text[TextFilesLstHdr],cfg.txtsec[usrsec[cursec]]->name); usemenu=0; } sprintf(str,"%stext/%s.ixt",cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); j=0; if(fexist(str)) { if((stream=fnopen((int *)&i,str,O_RDONLY))==NULL) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); return(0); } while(!ferror(stream) && !msgabort()) { /* file open too long */ if(!fgets(str,81,stream)) break; str[strlen(str)-2]=0; /* chop off CRLF */ if((file[j]=(char *)malloc(strlen(str)+1))==NULL) { errormsg(WHERE,ERR_ALLOC,nulstr,strlen(str)+1); continue; } strcpy(file[j],str); fgets(str,81,stream); if(!usemenu) bprintf(text[TextFilesLstFmt],j+1,str); j++; } fclose(stream); } ASYNC; if(SYSOP) { strcpy(str,"QARE?"); mnemonics(text[WhichTextFileSysop]); } else { strcpy(str,"Q?"); mnemonics(text[WhichTextFile]); } i=getkeys(str,j); if(!(i&0x80000000L)) { /* no file number */ for(l=0;l<j;l++) free(file[l]); if((i=='E' || i=='R') && !j) continue; } if(i=='Q' || !i) break; if(i==-1) { /* ctrl-c */ for(i=0;i<j;i++) free(file[i]); return(0); } if(i=='?') /* ? means re-list */ continue; if(i=='A') { /* Add text file */ if(j) { bputs(text[AddTextFileBeforeWhich]); i=getnum(j+1); if(i<1) continue; i--; /* number of file entries to skip */ } else i=0; bprintf(text[AddTextFilePath] ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); if(!getstr(addpath,80,0)) continue; strcat(addpath,crlf); bputs(text[AddTextFileDesc]); if(!getstr(addstr,74,0)) continue; strcat(addstr,crlf); sprintf(str,"%stext/%s.ixt" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); if(i==j) { /* just add to end */ if((i=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) { errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT); return(0); } write(i,addpath,strlen(addpath)); write(i,addstr,strlen(addstr)); close(i); continue; } j=i; /* inserting in middle of file */ if((stream=fnopen((int *)&i,str,O_RDWR))==NULL) { errormsg(WHERE,ERR_OPEN,str,O_RDWR); return(0); } length=(long)filelength(i); for(i=0;i<j;i++) { /* skip two lines for each entry */ fgets(tmp,81,stream); fgets(tmp,81,stream); } l=(long)ftell(stream); if((buf=(char *)malloc(length-l))==NULL) { fclose(stream); errormsg(WHERE,ERR_ALLOC,str,length-l); return(0); } fread(buf,1,length-l,stream); fseek(stream,l,SEEK_SET); /* go back to where we need to insert */ fputs(addpath,stream); fputs(addstr,stream); fwrite(buf,1,length-l,stream); fclose(stream); free(buf); continue; } if(i=='R' || i=='E') { /* Remove or Edit text file */ ch=(char)i; if(ch=='R') bputs(text[RemoveWhichTextFile]); else bputs(text[EditWhichTextFile]); i=getnum(j); if(i<1) continue; sprintf(str,"%stext/%s.ixt" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); j=i-1; if((stream=fnopen(NULL,str,O_RDONLY))==NULL) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); return(0); } for(i=0;i<j;i++) { /* skip two lines for each entry */ fgets(tmp,81,stream); fgets(tmp,81,stream); } fgets(addpath,81,stream); truncsp(addpath); fclose(stream); if(!strchr(addpath,'\\') && !strchr(addpath,'/')) sprintf(tmp,"%stext/%s/%s" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code,addpath); else strcpy(tmp,addpath); if(ch=='R') { /* Remove */ if(fexist(tmp)) { sprintf(str,text[DeleteTextFileQ],tmp); if(!noyes(str)) if(remove(tmp)) errormsg(WHERE,ERR_REMOVE,tmp,0); } sprintf(str,"%stext/%s.ixt" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); removeline(str,addpath,2,0); } else { /* Edit */ strcpy(str,tmp); editfile(str); } continue; } i=(i&~0x80000000L)-1; if(!strchr(file[i],'\\') && !strchr(file[i],'/')) sprintf(str,"%stext/%s/%s" ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code,file[i]); else strcpy(str,file[i]); fexistcase(str); attr(LIGHTGRAY); printfile(str,0); sprintf(str,"%s read text file: %s" ,useron.alias,file[i]); logline("T-",str); pause(); sys_status&=~SS_ABORT; for(i=0;i<j;i++) free(file[i]); } } return(0); }
BOOL sbbs_t::newuser() { char c,str[512]; char tmp[512]; uint i; long kmode; bool usa; bputs(text[StartingNewUserRegistration]); getnodedat(cfg.node_num,&thisnode,0); if(thisnode.misc&NODE_LOCK) { bputs(text[NodeLocked]); logline(LOG_WARNING,"N!","New user locked node logon attempt"); hangup(); return(FALSE); } if(cfg.sys_misc&SM_CLOSED) { bputs(text[NoNewUsers]); hangup(); return(FALSE); } getnodedat(cfg.node_num,&thisnode,1); thisnode.status=NODE_NEWUSER; thisnode.connection=node_connection; putnodedat(cfg.node_num,&thisnode); memset(&useron,0,sizeof(user_t)); /* Initialize user info to null */ if(cfg.new_pass[0] && online==ON_REMOTE) { c=0; while(++c<4) { bputs(text[NewUserPasswordPrompt]); getstr(str,40,K_UPPER); if(!strcmp(str,cfg.new_pass)) break; SAFEPRINTF(tmp,"NUP Attempted: '%s'",str); logline(LOG_NOTICE,"N!",tmp); } if(c==4) { SAFEPRINTF(str,"%snupguess.msg",cfg.text_dir); if(fexist(str)) printfile(str,P_NOABORT); hangup(); return(FALSE); } } /* Sets defaults per sysop config */ useron.misc|=(cfg.new_misc&~(DELETED|INACTIVE|QUIET|NETMAIL)); useron.qwk=QWK_DEFAULT; useron.firston=useron.laston=useron.pwmod=time32(NULL); if(cfg.new_expire) { now=time(NULL); useron.expire=(time32_t)(now+((long)cfg.new_expire*24L*60L*60L)); } else useron.expire=0; useron.sex=' '; useron.prot=cfg.new_prot; SAFECOPY(useron.comp,client_name); /* hostname or CID name */ SAFECOPY(useron.note,cid); /* IP address or CID number */ if((i=userdatdupe(0,U_NOTE,LEN_NOTE,cid, /* del */true))!=0) { /* Duplicate IP address */ SAFEPRINTF2(useron.comment,"Warning: same IP address as user #%d %s" ,i,username(&cfg,i,str)); logline(LOG_NOTICE,"N!",useron.comment); } SAFECOPY(useron.alias,"New"); /* just for status line */ SAFECOPY(useron.modem,connection); if(!lastuser(&cfg)) { /* Automatic sysop access for first user */ bprintf("Creating sysop account... System password required.\r\n"); if(!chksyspass()) return(FALSE); useron.level=99; useron.exempt=useron.flags1=useron.flags2=0xffffffffUL; useron.flags3=useron.flags4=0xffffffffUL; useron.rest=0L; } else { useron.level=cfg.new_level; useron.flags1=cfg.new_flags1; useron.flags2=cfg.new_flags2; useron.flags3=cfg.new_flags3; useron.flags4=cfg.new_flags4; useron.rest=cfg.new_rest; useron.exempt=cfg.new_exempt; } useron.cdt=cfg.new_cdt; useron.min=cfg.new_min; useron.freecdt=cfg.level_freecdtperday[useron.level]; if(cfg.total_fcomps) SAFECOPY(useron.tmpext,cfg.fcomp[0]->ext); else SAFECOPY(useron.tmpext,"ZIP"); useron.shell=cfg.new_shell; useron.alias[0]=0; kmode=(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL; if(!(cfg.uq&UQ_NOUPRLWR)) kmode|=K_UPRLWR; while(online) { if(autoterm || (text[AutoTerminalQ][0] && yesno(text[AutoTerminalQ]))) { useron.misc|=AUTOTERM; useron.misc|=autoterm; } else useron.misc&=~AUTOTERM; if(!(useron.misc&AUTOTERM)) { if(text[AnsiTerminalQ][0] && yesno(text[AnsiTerminalQ])) useron.misc|=ANSI; else useron.misc&=~ANSI; } if(useron.misc&ANSI) { useron.rows=0; /* Auto-rows */ if(!(cfg.uq&UQ_COLORTERM) || useron.misc&(RIP|WIP|HTML) || text[ColorTerminalQ][0]==0 || yesno(text[ColorTerminalQ])) useron.misc|=COLOR; else useron.misc&=~COLOR; } else useron.rows=24; if(text[ExAsciiTerminalQ][0] && !yesno(text[ExAsciiTerminalQ])) useron.misc|=NO_EXASCII; else useron.misc&=~NO_EXASCII; if(rlogin_name[0]) SAFECOPY(useron.alias,rlogin_name); while(online) { if(cfg.uq&UQ_ALIASES) bputs(text[EnterYourAlias]); else bputs(text[EnterYourRealName]); getstr(useron.alias,LEN_ALIAS,kmode); truncsp(useron.alias); if (!check_name(&cfg,useron.alias) || (!(cfg.uq&UQ_ALIASES) && !strchr(useron.alias,' '))) { bputs(text[YouCantUseThatName]); if(text[ContinueQ][0] && !yesno(text[ContinueQ])) return(FALSE); continue; } break; } if(!online) return(FALSE); if((cfg.uq&UQ_ALIASES) && (cfg.uq&UQ_REALNAME)) { while(online) { bputs(text[EnterYourRealName]); getstr(useron.name,LEN_NAME,kmode); if (!check_name(&cfg,useron.name) || !strchr(useron.name,' ') || ((cfg.uq&UQ_DUPREAL) && userdatdupe(useron.number,U_NAME,LEN_NAME,useron.name))) bputs(text[YouCantUseThatName]); else break; if(text[ContinueQ][0] && !yesno(text[ContinueQ])) return(FALSE); } } else if(cfg.uq&UQ_COMPANY) { bputs(text[EnterYourCompany]); getstr(useron.name,LEN_NAME,(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL); } if(!useron.name[0]) SAFECOPY(useron.name,useron.alias); if(!online) return(FALSE); if(!useron.handle[0]) SAFECOPY(useron.handle,useron.alias); while((cfg.uq&UQ_HANDLE) && online) { bputs(text[EnterYourHandle]); if(!getstr(useron.handle,LEN_HANDLE ,K_LINE|K_EDIT|K_AUTODEL|(cfg.uq&UQ_NOEXASC)) || strchr(useron.handle,0xff) || ((cfg.uq&UQ_DUPHAND) && userdatdupe(0,U_HANDLE,LEN_HANDLE,useron.handle)) || trashcan(useron.handle,"name")) bputs(text[YouCantUseThatName]); else break; if(text[ContinueQ][0] && !yesno(text[ContinueQ])) return(FALSE); } if(!online) return(FALSE); if(cfg.uq&UQ_ADDRESS) while(online) { /* Get address and zip code */ bputs(text[EnterYourAddress]); if(getstr(useron.address,LEN_ADDRESS,kmode)) break; } if(!online) return(FALSE); while((cfg.uq&UQ_LOCATION) && online) { bputs(text[EnterYourCityState]); if(getstr(useron.location,LEN_LOCATION,kmode) && ((cfg.uq&UQ_NOCOMMAS) || strchr(useron.location,','))) break; bputs(text[CommaInLocationRequired]); useron.location[0]=0; } if(cfg.uq&UQ_ADDRESS) while(online) { bputs(text[EnterYourZipCode]); if(getstr(useron.zipcode,LEN_ZIPCODE ,K_UPPER|(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL)) break; } if(!online) return(FALSE); if(cfg.uq&UQ_PHONE) { if(text[CallingFromNorthAmericaQ][0]) usa=yesno(text[CallingFromNorthAmericaQ]); else usa=false; while(online && text[EnterYourPhoneNumber][0]) { bputs(text[EnterYourPhoneNumber]); if(!usa) { if(getstr(useron.phone,LEN_PHONE ,K_UPPER|K_LINE|(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL)<5) continue; } else { if(gettmplt(useron.phone,cfg.sys_phonefmt ,K_LINE|(cfg.uq&UQ_NOEXASC)|K_EDIT)<strlen(cfg.sys_phonefmt)) continue; } if(!trashcan(useron.phone,"phone")) break; } } if(!online) return(FALSE); if(cfg.uq&UQ_SEX) { bputs(text[EnterYourSex]); useron.sex=(char)getkeys("MF",0); } while((cfg.uq&UQ_BIRTH) && online) { bprintf(text[EnterYourBirthday] ,cfg.sys_misc&SM_EURODATE ? "DD/MM/YY" : "MM/DD/YY"); if(gettmplt(useron.birth,"nn/nn/nn",K_EDIT)==8 && getage(&cfg,useron.birth)) break; } if(!online) return(FALSE); while(!(cfg.uq&UQ_NONETMAIL) && online) { bputs(text[EnterNetMailAddress]); if(getstr(useron.netmail,LEN_NETMAIL,K_EDIT|K_AUTODEL|K_LINE) && !trashcan(useron.netmail,"email")) break; } if(useron.netmail[0] && cfg.sys_misc&SM_FWDTONET && text[ForwardMailQ][0] && yesno(text[ForwardMailQ])) useron.misc|=NETMAIL; else useron.misc&=~NETMAIL; if(text[UserInfoCorrectQ][0]==0 || yesno(text[UserInfoCorrectQ])) break; } if(!online) return(FALSE); SAFEPRINTF(str,"New user: %s",useron.alias); logline("N",str); if(!online) return(FALSE); CLS; SAFEPRINTF(str,"%ssbbs.msg",cfg.text_dir); printfile(str,P_NOABORT); if(lncntr) pause(); CLS; SAFEPRINTF(str,"%ssystem.msg",cfg.text_dir); printfile(str,P_NOABORT); if(lncntr) pause(); CLS; SAFEPRINTF(str,"%snewuser.msg",cfg.text_dir); printfile(str,P_NOABORT); if(lncntr) pause(); CLS; answertime=time(NULL); /* could take 10 minutes to get this far */ /* Default editor (moved here, after terminal type setup Jan-2003) */ for(i=0;i<cfg.total_xedits;i++) if(!stricmp(cfg.xedit[i]->code,cfg.new_xedit) && chk_ar(cfg.xedit[i]->ar,&useron,&client)) break; if(i<cfg.total_xedits) useron.xedit=i+1; if(cfg.total_xedits && (cfg.uq&UQ_XEDIT) && text[UseExternalEditorQ][0]) { if(yesno(text[UseExternalEditorQ])) { for(i=0;i<cfg.total_xedits;i++) uselect(1,i,text[ExternalEditorHeading],cfg.xedit[i]->name,cfg.xedit[i]->ar); if((int)(i=uselect(0,useron.xedit ? useron.xedit-1 : 0,0,0,0))>=0) useron.xedit=i+1; } else useron.xedit=0; } if(cfg.total_shells>1 && (cfg.uq&UQ_CMDSHELL)) { for(i=0;i<cfg.total_shells;i++) uselect(1,i,text[CommandShellHeading],cfg.shell[i]->name,cfg.shell[i]->ar); if((int)(i=uselect(0,useron.shell,0,0,0))>=0) useron.shell=i; } if(rlogin_pass[0] && chkpass(rlogin_pass,&useron,true)) { CRLF; SAFECOPY(useron.pass, rlogin_pass); strupr(useron.pass); /* passwords are case insensitive, but assumed (in some places) to be uppercase in the user database */ } else { c=0; while(c<LEN_PASS) { /* Create random password */ useron.pass[c]=sbbs_random(43)+'0'; if(isalnum(useron.pass[c])) c++; } useron.pass[c]=0; bprintf(text[YourPasswordIs],useron.pass); if(cfg.sys_misc&SM_PWEDIT && text[NewPasswordQ][0] && yesno(text[NewPasswordQ])) while(online) { bputs(text[NewPassword]); getstr(str,LEN_PASS,K_UPPER|K_LINE); truncsp(str); if(chkpass(str,&useron,true)) { SAFECOPY(useron.pass,str); CRLF; bprintf(text[YourPasswordIs],useron.pass); break; } CRLF; } c=0; while(online) { bprintf(text[NewUserPasswordVerify]); console|=CON_R_ECHOX; str[0]=0; getstr(str,LEN_PASS*2,K_UPPER); console&=~(CON_R_ECHOX|CON_L_ECHOX); if(!strcmp(str,useron.pass)) break; if(cfg.sys_misc&SM_ECHO_PW) SAFEPRINTF3(tmp,"%s FAILED Password verification: '%s' instead of '%s'" ,useron.alias ,str ,useron.pass); else SAFEPRINTF(tmp,"%s FAILED Password verification" ,useron.alias); logline(LOG_NOTICE,nulstr,tmp); if(++c==4) { logline(LOG_NOTICE,"N!","Couldn't figure out password."); hangup(); } bputs(text[IncorrectPassword]); bprintf(text[YourPasswordIs],useron.pass); } } if(!online) return(FALSE); if(cfg.new_magic[0]) { bputs(text[MagicWordPrompt]); str[0]=0; getstr(str,50,K_UPPER); if(strcmp(str,cfg.new_magic)) { bputs(text[FailedMagicWord]); SAFEPRINTF2(tmp,"%s failed magic word: '%s'",useron.alias,str); logline("N!",tmp); hangup(); } if(!online) return(FALSE); } bputs(text[CheckingSlots]); if((i=newuserdat(&cfg,&useron))!=0) { SAFEPRINTF(str,"user record #%u",useron.number); errormsg(WHERE,ERR_CREATE,str,i); hangup(); return(FALSE); } SAFEPRINTF2(str,"Created user record #%u: %s",useron.number,useron.alias); logline(nulstr,str); if(cfg.new_sif[0]) { SAFEPRINTF2(str,"%suser/%4.4u.dat",cfg.data_dir,useron.number); create_sif_dat(cfg.new_sif,str); } if(!(cfg.uq&UQ_NODEF)) maindflts(&useron); delallmail(useron.number, MAIL_ANY); if(useron.number!=1 && cfg.node_valuser) { SAFEPRINTF(str,"%sfeedback.msg",cfg.text_dir); CLS; printfile(str,P_NOABORT); safe_snprintf(str,sizeof(str),text[NewUserFeedbackHdr] ,nulstr,getage(&cfg,useron.birth),useron.sex,useron.birth ,useron.name,useron.phone,useron.comp,useron.modem); email(cfg.node_valuser,str,"New User Validation",WM_EMAIL|WM_SUBJ_RO|WM_FORCEFWD); if(!useron.fbacks && !useron.emails) { if(online) { /* didn't hang up */ bprintf(text[NoFeedbackWarning],username(&cfg,cfg.node_valuser,tmp)); email(cfg.node_valuser,str,"New User Validation",WM_EMAIL|WM_SUBJ_RO|WM_FORCEFWD); } /* give 'em a 2nd try */ if(!useron.fbacks && !useron.emails) { bprintf(text[NoFeedbackWarning],username(&cfg,cfg.node_valuser,tmp)); logline(LOG_NOTICE,"N!","Aborted feedback"); hangup(); putuserrec(&cfg,useron.number,U_COMMENT,60,"Didn't leave feedback"); putuserrec(&cfg,useron.number,U_MISC,8 ,ultoa(useron.misc|DELETED,tmp,16)); putusername(&cfg,useron.number,nulstr); return(FALSE); } } } answertime=starttime=time(NULL); /* set answertime to now */ #ifdef JAVASCRIPT js_create_user_objects(); #endif if(cfg.newuser_mod[0]) exec_bin(cfg.newuser_mod,&main_csi); user_event(EVENT_NEWUSER); getuserdat(&cfg,&useron); // In case event(s) modified user data logline("N+","Successful new user logon"); sys_status|=SS_NEWUSER; return(TRUE); }
main() { int error; int i; int pagenum,*buf; int *buf1,*buf2; int fd1,fd2; /* create a few files */ if ((error=PF_CreateFile(FILE1))!= PFE_OK){ PF_PrintError("file1"); exit(1); } printf("file1 created\n"); if ((error=PF_CreateFile(FILE2))!= PFE_OK){ PF_PrintError("file2"); exit(1); } printf("file2 created\n"); /* write to file1 */ writefile(FILE1); /* print it out */ readfile(FILE1); /* write to file2 */ writefile(FILE2); /* print it out */ readfile(FILE2); /* open both files */ if ((fd1=PF_OpenFile(FILE1))<0){ PF_PrintError("open file1\n"); exit(1); } printf("opened file1\n"); if ((fd2=PF_OpenFile(FILE2))<0 ){ PF_PrintError("open file2\n"); exit(1); } printf("opened file2\n"); /* get rid of records 1, 3, 5, etc from file 1, and 0,2,4,6 from file2 */ for (i=0; i < PF_MAX_BUFS; i++){ if (i & 1){ if ((error=PF_DisposePage(fd1,i))!= PFE_OK){ PF_PrintError("dispose\n"); exit(1); } printf("disposed %d of file1\n",i); } else { if ((error=PF_DisposePage(fd2,i))!= PFE_OK){ PF_PrintError("dispose\n"); exit(1); } printf("disposed %d of file2\n",i); } } if ((error=PF_CloseFile(fd1))!= PFE_OK){ PF_PrintError("close fd1"); exit(1); } printf("closed file1\n"); if ((error=PF_CloseFile(fd2))!= PFE_OK){ PF_PrintError("close fd2"); exit(1); } printf("closed file2\n"); /* print the files */ readfile(FILE1); readfile(FILE2); /* destroy the two files */ if ((error=PF_DestroyFile(FILE1))!= PFE_OK){ PF_PrintError("destroy file1"); exit(1); } if ((error=PF_DestroyFile(FILE2))!= PFE_OK){ PF_PrintError("destroy file2"); exit(1); } /* create them again */ if ((fd1=PF_CreateFile(FILE1))< 0){ PF_PrintError("create file1"); exit(1); } printf("file1 created\n"); if ((fd2=PF_CreateFile(FILE2))< 0){ PF_PrintError("create file2"); exit(1); } printf("file2 created\n"); /* put stuff into the two files */ writefile(FILE1); writefile(FILE2); /* Open the files, and see how the buffer manager handles more insertions, and deletions */ /* open both files */ if ((fd1=PF_OpenFile(FILE1))<0){ PF_PrintError("open file1\n"); exit(1); } printf("opened file1\n"); if ((fd2=PF_OpenFile(FILE2))<0 ){ PF_PrintError("open file2\n"); exit(1); } printf("opened file2\n"); for (i=PF_MAX_BUFS; i < PF_MAX_BUFS*2 ; i++){ if ((error=PF_AllocPage(fd2,&pagenum,&buf))!= PFE_OK){ PF_PrintError("first buffer\n"); exit(1); } *((int *)buf) = i; if ((error=PF_UnfixPage(fd2,pagenum,TRUE))!= PFE_OK){ PF_PrintError("unfix file1"); exit(1); } printf("alloc %d file1\n",i,pagenum); if ((error=PF_AllocPage(fd1,&pagenum,&buf))!= PFE_OK){ PF_PrintError("first buffer\n"); exit(1); } *((int *)buf) = i; if ((error=PF_UnfixPage(fd1,pagenum,TRUE))!= PFE_OK){ PF_PrintError("dispose file1"); exit(1); } printf("alloc %d file2\n",i,pagenum); } for (i= PF_MAX_BUFS; i < PF_MAX_BUFS*2; i++){ if (i & 1){ if ((error=PF_DisposePage(fd1,i))!= PFE_OK){ PF_PrintError("dispose fd1"); exit(1); } printf("dispose fd1 page %d\n",i); } else { if ((error=PF_DisposePage(fd2,i))!= PFE_OK){ PF_PrintError("dispose fd2"); exit(1); } printf("dispose fd2 page %d\n",i); } } printf("getting file2\n"); for (i=PF_MAX_BUFS; i < PF_MAX_BUFS*2; i++){ if (i & 1){ if ((error=PF_GetThisPage(fd2,i,&buf))!=PFE_OK){ PF_PrintError("get this on fd2"); exit(1); } printf("%d %d\n",i,*buf); if ((error=PF_UnfixPage(fd2,i,FALSE))!= PFE_OK){ PF_PrintError("get this on fd2"); exit(1); } } } printf("getting file1\n"); for (i=PF_MAX_BUFS; i < PF_MAX_BUFS*2; i++){ if (!(i & 1)){ if ((error=PF_GetThisPage(fd1,i,&buf))!=PFE_OK){ PF_PrintError("get this on fd2"); exit(1); } printf("%d %d\n",i,*buf); if ((error=PF_UnfixPage(fd1,i,FALSE))!= PFE_OK){ PF_PrintError("get this on fd2"); exit(1); } } } /* print the files */ printfile(fd2); printfile(fd1); /*put some more stuff into file1 */ printf("putting stuff into holes in fd1\n"); for (i=0; i < (PF_MAX_BUFS/2 -1); i++){ if (PF_AllocPage(fd1,&pagenum,&buf)!= PFE_OK){ PF_PrintError("PF_AllocPage"); exit(1); } *buf =pagenum; if (PF_UnfixPage(fd1,pagenum,TRUE)!= PFE_OK){ PF_PrintError("PF_UnfixPage"); exit(1); } } printf("printing fd1"); printfile(fd1); PF_CloseFile(fd1); printf("closed file1\n"); PF_CloseFile(fd2); printf("closed file2\n"); /* open file1 twice */ if ((fd1=PF_OpenFile(FILE1))<0){ PF_PrintError("open file1"); exit(1); } printf("opened file1\n"); /* try to destroy it while it's still open*/ error=PF_DestroyFile(FILE1); PF_PrintError("destroy file1, should not succeed"); /* get rid of some invalid page */ error=PF_DisposePage(fd1,100); PF_PrintError("dispose page 100, should fail"); /* get a valid page, and try to dispose it without unfixing.*/ if ((error=PF_GetThisPage(fd1,1,&buf))!=PFE_OK){ PF_PrintError("get this on fd2"); exit(1); } printf("got page%d\n",*buf); error=PF_DisposePage(fd1,1); PF_PrintError("dispose page1, should fail"); /* Now unfix it */ if ((error=PF_UnfixPage(fd1,1,FALSE))!= PFE_OK){ PF_PrintError("get this on fd2"); exit(1); } error=PF_UnfixPage(fd1,1,FALSE); PF_PrintError("unfix fd1 again, should fail"); if ((fd2=PF_OpenFile(FILE1))<0 ){ PF_PrintError("open file1 again"); exit(1); } printf("opened file1 again\n"); printfile(fd1); printfile(fd2); if (PF_CloseFile(fd1) != PFE_OK){ PF_PrintError("close fd1"); exit(1); } if (PF_CloseFile(fd2)!= PFE_OK){ PF_PrintError("close fd2"); exit(1); } /* print the buffer */ printf("buffer:\n"); PFbufPrint(); /* print the hash table */ printf("hash table:\n"); PFhashPrint(); }