Commit c9c05123 authored by mcmlxxix's avatar mcmlxxix

make system.matchuserdata return an array of all matches if match_all==true,...

make system.matchuserdata return an array of all matches if match_all==true, starting at usernumber if specified. (userdatdupe now takes an additional paremeter)
parent 61ae5763
......@@ -108,7 +108,7 @@ bool sbbs_t::answer()
,startup->options&BBS_OPT_USE_2ND_RLOGIN ? str2 : str);
SAFECOPY(rlogin_pass
,startup->options&BBS_OPT_USE_2ND_RLOGIN ? str : str2);
useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name, 0);
useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name, 0, 0);
if(useron.number) {
getuserdat(&cfg,&useron);
useron.misc&=~TERM_FLAGS;
......@@ -192,7 +192,7 @@ bool sbbs_t::answer()
rlogin_pass[i]=0;
lprintf(LOG_DEBUG,"Node %d SSH login: '%s'"
,cfg.node_num, rlogin_name);
useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name, 0);
useron.number=userdatdupe(0, U_ALIAS, LEN_ALIAS, rlogin_name, 0, 0);
if(useron.number) {
getuserdat(&cfg,&useron);
useron.misc&=~TERM_FLAGS;
......@@ -338,7 +338,7 @@ bool sbbs_t::answer()
/* 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, 0);
useron.number=userdatdupe(0, U_NOTE, LEN_NOTE, cid, 0, 0);
if(useron.number) {
getuserdat(&cfg, &useron);
if(!(useron.misc&AUTOLOGON) || !(useron.exempt&FLAG('V')))
......
......@@ -1282,7 +1282,7 @@ int sbbs_t::getnodetopage(int all, int telegram)
return(-1);
if(str[0]=='\'') {
j=userdatdupe(0,U_HANDLE,LEN_HANDLE,str+1,0);
j=userdatdupe(0,U_HANDLE,LEN_HANDLE,str+1,0,0);
if(!j) {
bputs(text[UnknownUser]);
return(0);
......
......@@ -159,15 +159,16 @@ extern "C" BOOL DLLCALL putmsgptrs(scfg_t* cfg, uint usernumber, subscan_t* subs
/****************************************************************************/
/* Checks for a duplicate user field starting at user record offset */
/* 'offset', reading in 'datlen' chars, comparing to 'str' for each user */
/* except 'usernumber' if it is non-zero. Comparison is NOT case sensitive. */
/* except 'usernumber' if it is non-zero, or starting at 'usernumber' if */
/* 'next' is true. Comparison is NOT case sensitive. */
/* 'del' is true if the search is to include deleted/inactive users */
/* Returns the usernumber of the dupe if found, 0 if not */
/****************************************************************************/
uint sbbs_t::userdatdupe(uint usernumber, uint offset, uint datlen, char *dat
,bool del)
,bool del, bool next)
{
bputs(text[SearchingForDupes]);
uint i=::userdatdupe(&cfg, usernumber, offset, datlen, dat, del);
uint i=::userdatdupe(&cfg, usernumber, offset, datlen, dat, del, next);
bputs(text[SearchedForDupes]);
return(i);
}
......
......@@ -1604,7 +1604,7 @@ int sbbs_t::exec(csi_t *csi)
break;
if(cfg.uq&UQ_DUPREAL
&& userdatdupe(useron.number,U_NAME,LEN_NAME
,csi->str,0))
,csi->str,0,0))
break;
sprintf(useron.name,"%.*s",LEN_NAME,csi->str);
putuserrec(&cfg,useron.number,U_NAME,LEN_NAME
......@@ -1616,7 +1616,7 @@ int sbbs_t::exec(csi_t *csi)
break;
if(cfg.uq&UQ_DUPHAND
&& userdatdupe(useron.number,U_HANDLE,LEN_HANDLE
,csi->str,0))
,csi->str,0,0))
break;
sprintf(useron.handle,"%.*s",LEN_HANDLE,csi->str);
putuserrec(&cfg,useron.number,U_HANDLE,LEN_HANDLE
......
......@@ -184,7 +184,7 @@ int sbbs_t::exec_function(csi_t *csi)
netmail(csi->str,nulstr,0);
}
else if((i=finduser(csi->str))!=0
|| (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str,false))!=0))
|| (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str,false,false))!=0))
email(i,nulstr,nulstr,WM_EMAIL);
csi->logic=!i;
return(0);
......@@ -219,7 +219,7 @@ int sbbs_t::exec_function(csi_t *csi)
netmail(csi->str,nulstr,WM_FILE);
}
else if((i=finduser(csi->str))!=0
|| (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str,false))!=0))
|| (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str,false,false))!=0))
email(i,nulstr,nulstr,WM_EMAIL|WM_FILE);
csi->logic=!i;
return(0);
......
......@@ -813,6 +813,7 @@ js_matchuserdata(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
int len;
scfg_t* cfg;
jsrefcount rc;
BOOL match_all=FALSE;
if((cfg=(scfg_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
......@@ -831,15 +832,43 @@ js_matchuserdata(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
if(argc>2)
JS_ValueToInt32(cx,argv[2],&usernumber);
if((p=JS_GetStringBytes(js_str))==NULL) {
*rval = INT_TO_JSVAL(0);
return(JS_TRUE);
}
rc=JS_SUSPENDREQUEST(cx);
*rval = INT_TO_JSVAL(userdatdupe(cfg,usernumber,offset,len,p,FALSE /* deleted users */));
JS_RESUMEREQUEST(cx, rc);
if(argc > 3)
JS_ValueToBoolean(cx,argv[3],&match_all);
if(match_all == FALSE) {
rc=JS_SUSPENDREQUEST(cx);
*rval = INT_TO_JSVAL(userdatdupe(cfg,usernumber,offset,len,p,FALSE,FALSE));
JS_RESUMEREQUEST(cx, rc);
} else {
JSObject* array;
jsval val;
int retval;
jsint line=0;
if((array=JS_NewArrayObject(cx,0,NULL))==NULL)
return(JS_FALSE);
while(1) {
rc=JS_SUSPENDREQUEST(cx);
retval=userdatdupe(cfg,usernumber++,offset,len,p,FALSE,TRUE);
if(retval > 0) {
val = INT_TO_JSVAL(retval);
if(!JS_SetElement(cx, array, line++, &val)) {
JS_RESUMEREQUEST(cx, rc);
break;
}
usernumber=retval;
retval=0;
} else
break;
JS_RESUMEREQUEST(cx, rc);
}
*rval = OBJECT_TO_JSVAL(array);
}
return(JS_TRUE);
}
......@@ -1528,9 +1557,10 @@ static jsSyncMethodSpec js_system_functions[] = {
" or 0 if not found, matches well-known sysop aliases by default")
,310
},
{"matchuserdata", js_matchuserdata, 2, JSTYPE_NUMBER, JSDOCSTR("field, data [,usernumber]")
{"matchuserdata", js_matchuserdata, 2, JSTYPE_ARRAY, JSDOCSTR("field, data [,usernumber, match_all=<tt>false</tt>]")
,JSDOCSTR("search user database for data in a specific field (specified by offset), "
"returns first matching user record number, optional <i>usernumber</i> specifies user record to skip")
"returns first matching user record number, optional <i>usernumber</i> specifies user record to skip, "
"or record at which to begin searching if optional match_all is <i>true</i>")
,310
},
{"trashcan", js_trashcan, 2, JSTYPE_BOOLEAN, JSDOCSTR("path/filename, find_string")
......
......@@ -70,7 +70,7 @@ int sbbs_t::login(char *username, char *pw)
useron.number=matchuser(&cfg,str,FALSE);
if(!useron.number && (uchar)str[0]<0x7f && str[1]
&& isalpha(str[0]) && strchr(str,' ') && cfg.node_misc&NM_LOGON_R)
useron.number=userdatdupe(0,U_NAME,LEN_NAME,str,0);
useron.number=userdatdupe(0,U_NAME,LEN_NAME,str,0,0);
if(useron.number) {
getuserdat(&cfg,&useron);
if(useron.number && useron.misc&(DELETED|INACTIVE))
......
......@@ -301,7 +301,7 @@ bool sbbs_t::logon()
|| strchr(useron.name,0xff)
|| (cfg.uq&UQ_DUPREAL
&& userdatdupe(useron.number,U_NAME,LEN_NAME
,useron.name,0)))
,useron.name,0,0)))
bputs(text[YouCantUseThatName]);
else
break;
......@@ -318,7 +318,7 @@ bool sbbs_t::logon()
|| strchr(useron.handle,0xff)
|| (cfg.uq&UQ_DUPHAND
&& userdatdupe(useron.number,U_HANDLE,LEN_HANDLE
,useron.handle,0))
,useron.handle,0,0))
|| trashcan(useron.handle,"name"))
bputs(text[YouCantUseThatName]);
else
......
......@@ -1421,7 +1421,7 @@ static BOOL email_addr_is_exempt(const char* addr)
if(*(p=netmail)=='<')
p++;
truncstr(p,">");
return userdatdupe(&scfg, 0, U_NETMAIL, LEN_NETMAIL, p, FALSE);
return userdatdupe(&scfg, 0, U_NETMAIL, LEN_NETMAIL, p, FALSE, FALSE);
}
static void exempt_email_addr(const char* comment
......@@ -2120,7 +2120,7 @@ static uint smtp_matchuser(scfg_t *scfg, char *str, BOOL aliases, BOOL datdupe)
goto end;
if(datdupe)
usernum=userdatdupe(scfg, 0, U_NAME, LEN_NAME, name, FALSE);
usernum=userdatdupe(scfg, 0, U_NAME, LEN_NAME, name, FALSE, FALSE);
else
usernum=matchuser(scfg, name, aliases);
......@@ -3600,7 +3600,7 @@ static void smtp_thread(void* arg)
SAFEPRINTF(relay_list,"%srelay.cfg",scfg.ctrl_dir);
if(relay_user.number==0 /* not authenticated, search for IP */
&& startup->options&MAIL_OPT_SMTP_AUTH_VIA_IP) {
relay_user.number=userdatdupe(&scfg, 0, U_NOTE, LEN_NOTE, host_ip, FALSE);
relay_user.number=userdatdupe(&scfg, 0, U_NOTE, LEN_NOTE, host_ip, FALSE, FALSE);
if(relay_user.number) {
getuserdat(&scfg,&relay_user);
if(relay_user.laston < time(NULL)-(60*60)) /* logon in past hour? */
......
......@@ -115,7 +115,7 @@ BOOL sbbs_t::newuser()
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,true))!=0) { /* Duplicate IP address */
if((i=userdatdupe(0,U_NOTE,LEN_NOTE,cid,true,false))!=0) { /* Duplicate IP address */
sprintf(useron.comment,"Warning: same IP address as user #%d %s"
,i,username(&cfg,i,str));
logline(LOG_NOTICE,"N!",useron.comment);
......@@ -219,7 +219,7 @@ BOOL sbbs_t::newuser()
|| !strchr(useron.name,' ')
|| (cfg.uq&UQ_DUPREAL
&& userdatdupe(useron.number,U_NAME,LEN_NAME
,useron.name,0)))
,useron.name,0,0)))
bputs(text[YouCantUseThatName]);
else
break;
......@@ -242,7 +242,7 @@ BOOL sbbs_t::newuser()
,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,0))
&& userdatdupe(0,U_HANDLE,LEN_HANDLE,useron.handle,0,0))
|| trashcan(useron.handle,"name"))
bputs(text[YouCantUseThatName]);
else
......
......@@ -135,7 +135,7 @@ bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
if(stricmp(touser,"ALL")
&& !(cfg.sub[subnum]->misc&(SUB_PNET|SUB_FIDO|SUB_QNET|SUB_INET|SUB_ANON))) {
if(cfg.sub[subnum]->misc&SUB_NAME) {
if(!userdatdupe(useron.number,U_NAME,LEN_NAME,touser,0)) {
if(!userdatdupe(useron.number,U_NAME,LEN_NAME,touser,0,0)) {
bputs(text[UnknownUser]);
return(false);
}
......
......@@ -891,7 +891,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
i=atoi(str);
if(!i) {
if(cfg.sub[subnum]->misc&SUB_NAME)
i=userdatdupe(0,U_NAME,LEN_NAME,str,0);
i=userdatdupe(0,U_NAME,LEN_NAME,str,0,0);
else
i=matchuser(&cfg,str,TRUE /* sysop_alias */);
}
......@@ -957,7 +957,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
if(noyes(text[AreYouSureQ]))
break;
purgeuser(cfg.sub[subnum]->misc&SUB_NAME
? userdatdupe(0,U_NAME,LEN_NAME,msg.from,0)
? userdatdupe(0,U_NAME,LEN_NAME,msg.from,0,0)
: matchuser(&cfg,msg.from,FALSE));
break;
case 'C': /* Change message attributes */
......@@ -1023,7 +1023,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
break;
case 'U': /* User edit */
useredit(cfg.sub[subnum]->misc&SUB_NAME
? userdatdupe(0,U_NAME,LEN_NAME,msg.from,0)
? userdatdupe(0,U_NAME,LEN_NAME,msg.from,0,0)
: matchuser(&cfg,msg.from,TRUE /* sysop_alias */));
break;
case 'V': /* Validate message */
......
......@@ -440,7 +440,7 @@ public:
uint getusrgrp(uint subnum);
uint userdatdupe(uint usernumber, uint offset, uint datlen, char *dat
,bool del);
,bool del, bool next);
ulong gettimeleft(bool handle_out_of_time=true);
bool gettimeleft_inside;
......
......@@ -1047,7 +1047,7 @@ void DLLCALL printnodedat(scfg_t* cfg, uint number, node_t* node)
/****************************************************************************/
uint DLLCALL userdatdupe(scfg_t* cfg, uint usernumber, uint offset, uint datlen
,char *dat, BOOL del)
,char *dat, BOOL del, BOOL next)
{
char str[MAX_PATH+1];
uint i;
......@@ -1062,8 +1062,12 @@ uint DLLCALL userdatdupe(scfg_t* cfg, uint usernumber, uint offset, uint datlen
if((file=nopen(str,O_RDONLY|O_DENYNONE))==-1)
return(0);
length=(long)filelength(file);
for(l=0;l<length;l+=U_LEN) {
if(usernumber && l/U_LEN==(long)usernumber-1)
if(usernumber && next)
l=((long)usernumber) * U_LEN;
else
l=0;
for(;l<length;l+=U_LEN) {
if(usernumber && l/U_LEN==(long)usernumber-1)
continue;
lseek(file,l+offset,SEEK_SET);
i=0;
......
......@@ -96,7 +96,7 @@ DLLEXPORT char* DLLCALL getnmsg(scfg_t* cfg, int node_num);
DLLEXPORT int DLLCALL putnmsg(scfg_t* cfg, int num, char *strin);
DLLEXPORT uint DLLCALL userdatdupe(scfg_t* cfg, uint usernumber, uint offset, uint datlen, char *dat
,BOOL del);
,BOOL del, BOOL next);
DLLEXPORT BOOL DLLCALL chk_ar(scfg_t* cfg, uchar* str, user_t*, client_t*); /* checks access requirements */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment