Commit 8ff2afb3 authored by deuce's avatar deuce
Browse files

Add support for [+-][A-?] for flags?, exemption, and restriction fields of

user.security and move a general function to support it into str_util.c
parent 4b48688e
......@@ -271,37 +271,10 @@ static JSBool js_console_set(JSContext *cx, JSObject *obj, jsid id, JSBool stric
break;
case CON_PROP_CTRLKEY_PASSTHRU:
if(JSVAL_IS_STRING(*vp)) {
/* op can be 0 for replace, + for add, or - for remove */
int op=0;
char *s;
char ctrl;
if((str=JS_ValueToString(cx, *vp))==NULL)
break;
val=sbbs->cfg.ctrlkey_passthru;
JSSTRING_TO_STRING(cx, str, s, NULL);
for(; *s; s++) {
if(*s=='+')
op=1;
else if(*s=='-')
op=2;
else {
if(!op) {
val=0;
op=1;
}
ctrl=toupper(*s);
ctrl&=0x1f; /* Ensure it fits */
switch(op) {
case 1: /* Add to the set */
val |= 1<<ctrl;
break;
case 2: /* Remove from the set */
val &= ~(1<<ctrl);
break;
}
}
}
val=str_to_bits(sbbs->cfg.ctrlkey_passthru, s);
}
sbbs->cfg.ctrlkey_passthru=val;
break;
......
......@@ -583,43 +583,73 @@ static JSBool js_user_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict,
break;
case USER_PROP_FLAGS1:
JS_RESUMEREQUEST(cx, rc);
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
if(JSVAL_IS_STRING(*vp)) {
val=str_to_bits(p->user->flags1, str);
}
else {
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
}
putuserrec(p->cfg,p->user->number,U_FLAGS1,0,ultoa(p->user->flags1=val,tmp,16));
rc=JS_SUSPENDREQUEST(cx);
break;
case USER_PROP_FLAGS2:
JS_RESUMEREQUEST(cx, rc);
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
if(JSVAL_IS_STRING(*vp)) {
val=str_to_bits(p->user->flags1, str);
}
else {
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
}
putuserrec(p->cfg,p->user->number,U_FLAGS2,0,ultoa(p->user->flags2=val,tmp,16));
rc=JS_SUSPENDREQUEST(cx);
break;
case USER_PROP_FLAGS3:
JS_RESUMEREQUEST(cx, rc);
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
if(JSVAL_IS_STRING(*vp)) {
val=str_to_bits(p->user->flags1, str);
}
else {
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
}
putuserrec(p->cfg,p->user->number,U_FLAGS3,0,ultoa(p->user->flags3=val,tmp,16));
rc=JS_SUSPENDREQUEST(cx);
break;
case USER_PROP_FLAGS4:
JS_RESUMEREQUEST(cx, rc);
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
if(JSVAL_IS_STRING(*vp)) {
val=str_to_bits(p->user->flags1, str);
}
else {
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
}
putuserrec(p->cfg,p->user->number,U_FLAGS4,0,ultoa(p->user->flags4=val,tmp,16));
rc=JS_SUSPENDREQUEST(cx);
break;
case USER_PROP_EXEMPT:
JS_RESUMEREQUEST(cx, rc);
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
if(JSVAL_IS_STRING(*vp)) {
val=str_to_bits(p->user->flags1, str);
}
else {
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
}
putuserrec(p->cfg,p->user->number,U_EXEMPT,0,ultoa(p->user->exempt=val,tmp,16));
rc=JS_SUSPENDREQUEST(cx);
break;
case USER_PROP_REST:
JS_RESUMEREQUEST(cx, rc);
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
if(JSVAL_IS_STRING(*vp)) {
val=str_to_bits(p->user->flags1, str);
}
else {
if(!JS_ValueToInt32(cx,*vp,&val))
return JS_FALSE;
}
putuserrec(p->cfg,p->user->number,U_REST,0,ultoa(p->user->rest=val,tmp,16));
rc=JS_SUSPENDREQUEST(cx);
break;
......@@ -774,12 +804,12 @@ static char* user_security_prop_desc[] = {
"password"
,"date password last modified (time_t format)"
,"security level (0-99)"
,"flag set #1 (bitfield)"
,"flag set #2 (bitfield)"
,"flag set #3 (bitfield)"
,"flag set #4 (bitfield)"
,"exemption flags (bitfield)"
,"restriction flags (bitfield)"
,"flag set #1 (bitfield) can use +/-[A-?] notation"
,"flag set #2 (bitfield) can use +/-[A-?] notation"
,"flag set #3 (bitfield) can use +/-[A-?] notation"
,"flag set #4 (bitfield) can use +/-[A-?] notation"
,"exemption flags (bitfield) can use +/-[A-?] notation"
,"restriction flags (bitfield) can use +/-[A-?] notation"
,"credits"
,"free credits (for today only)"
,"extra minutes (time bank)"
......
......@@ -921,6 +921,7 @@ extern "C" {
DLLEXPORT size_t DLLCALL strip_invalid_attr(char *str);
DLLEXPORT char * DLLCALL ultoac(ulong l,char *str);
DLLEXPORT char * DLLCALL rot13(char* str);
DLLEXPORT uint32_t DLLCALL str_to_bits(uint32_t currval, const char *str);
/* msg_id.c */
DLLEXPORT char * DLLCALL ftn_msgid(sub_t* sub, smbmsg_t* msg, char* msgid, size_t);
......
......@@ -699,6 +699,36 @@ char* replace_keyed_values(const char* src
return(buf);
}
uint32_t DLLCALL str_to_bits(uint32_t val, const char *str)
{
/* op can be 0 for replace, + for add, or - for remove */
int op=0;
char *s;
char ctrl;
for(s=str; *s; s++) {
if(*s=='+')
op=1;
else if(*s=='-')
op=2;
else {
if(!op) {
val=0;
op=1;
}
ctrl=toupper(*s);
ctrl&=0x1f; /* Ensure it fits */
switch(op) {
case 1: /* Add to the set */
val |= 1<<ctrl;
break;
case 2: /* Remove from the set */
val &= ~(1<<ctrl);
break;
}
}
}
}
#if 0 /* replace_*_values test */
......
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