Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

js_user.c 45.8 KB
Newer Older
1 2 3 4 5 6
/* Synchronet JavaScript "User" Object */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
rswindell's avatar
rswindell committed
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"
23
#include "js_request.h"
24 25 26

#ifdef JAVASCRIPT

27 28
typedef struct
{
29 30
	user_t*		user;
	user_t		storage;
rswindell's avatar
rswindell committed
31 32
	BOOL		cached;
	client_t*	client;
33
	int			file;		// for fast read operations, only
34 35 36

} private_t;

37
/* User Object Properties */
38
enum {
rswindell's avatar
rswindell committed
39 40
	 USER_PROP_NUMBER
	,USER_PROP_ALIAS 	
41 42 43
	,USER_PROP_NAME		
	,USER_PROP_HANDLE	
	,USER_PROP_NOTE		
deuce's avatar
deuce committed
44
	,USER_PROP_IPADDR
45 46 47
	,USER_PROP_COMP		
	,USER_PROP_COMMENT	
	,USER_PROP_NETMAIL	
48
	,USER_PROP_EMAIL	/* READ ONLY */
49 50
	,USER_PROP_ADDRESS	
	,USER_PROP_LOCATION	
rswindell's avatar
rswindell committed
51 52
	,USER_PROP_ZIPCODE
	,USER_PROP_PASS
53
	,USER_PROP_PHONE  	
54 55 56 57
	,USER_PROP_BIRTH
	,USER_PROP_BIRTHYEAR
	,USER_PROP_BIRTHMONTH
	,USER_PROP_BIRTHDAY
58
	,USER_PROP_AGE		/* READ ONLY */
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
	,USER_PROP_MODEM     
	,USER_PROP_LASTON	
	,USER_PROP_FIRSTON	
	,USER_PROP_EXPIRE    
	,USER_PROP_PWMOD     
	,USER_PROP_LOGONS    
	,USER_PROP_LTODAY    
	,USER_PROP_TIMEON    
	,USER_PROP_TEXTRA  	
	,USER_PROP_TTODAY    
	,USER_PROP_TLAST     
	,USER_PROP_POSTS     
	,USER_PROP_EMAILS    
	,USER_PROP_FBACKS    
	,USER_PROP_ETODAY	
74 75
	,USER_PROP_PTODAY
	,USER_PROP_MAIL_WAITING
76 77 78
	,USER_PROP_READ_WAITING
	,USER_PROP_UNREAD_WAITING
	,USER_PROP_SPAM_WAITING
79
	,USER_PROP_MAIL_PENDING
80 81 82 83 84 85 86 87 88 89 90 91 92
	,USER_PROP_ULB       
	,USER_PROP_ULS       
	,USER_PROP_DLB       
	,USER_PROP_DLS       
	,USER_PROP_CDT		
	,USER_PROP_MIN		
	,USER_PROP_LEVEL 	
	,USER_PROP_FLAGS1	
	,USER_PROP_FLAGS2	
	,USER_PROP_FLAGS3	
	,USER_PROP_FLAGS4	
	,USER_PROP_EXEMPT	
	,USER_PROP_REST		
93 94
	,USER_PROP_ROWS
	,USER_PROP_COLS
95 96 97 98 99
	,USER_PROP_SEX		
	,USER_PROP_MISC		
	,USER_PROP_LEECH 	
	,USER_PROP_CURSUB	
	,USER_PROP_CURDIR	
100
	,USER_PROP_CURXTRN
101 102 103 104 105 106 107 108
	,USER_PROP_FREECDT	
	,USER_PROP_XEDIT 	
	,USER_PROP_SHELL 	
	,USER_PROP_QWK		
	,USER_PROP_TMPEXT	
	,USER_PROP_CHAT		
	,USER_PROP_NS_TIME	
	,USER_PROP_PROT		
109
	,USER_PROP_LOGONTIME
110 111 112 113 114 115 116
	,USER_PROP_TIMEPERCALL
	,USER_PROP_TIMEPERDAY
	,USER_PROP_CALLSPERDAY
	,USER_PROP_LINESPERMSG
	,USER_PROP_EMAILPERDAY
	,USER_PROP_POSTSPERDAY
	,USER_PROP_FREECDTPERDAY
117
	,USER_PROP_CACHED
118
	,USER_PROP_IS_SYSOP
119 120
};

121
static void js_getuserdat(scfg_t* scfg, private_t* p)
122
{
123
	if(p->user->number != 0 && !p->cached) {
124 125 126
		if(p->file < 1)
			p->file = openuserdat(scfg, /* for_modify: */FALSE);
		if(fgetuserdat(scfg, p->user, p->file)==0)
127 128 129 130
			p->cached=TRUE;
	}
}

131
static JSBool js_user_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
132
{
133
	jsval idval;
134 135
	char*		s=NULL;
	char		tmp[128];
136
	int64_t		val=0;
137
    jsint       tiny;
138
	JSString*	js_str;
139
	private_t*	p;
deuce's avatar
deuce committed
140
	jsrefcount	rc;
141 142 143
	scfg_t*			scfg;

	scfg=JS_GetRuntimePrivate(JS_GetRuntime(cx));
144

145 146
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_TRUE);
147

148
	rc=JS_SUSPENDREQUEST(cx);
149
	js_getuserdat(scfg,p);
150

151 152
    JS_IdToValue(cx, id, &idval);
    tiny = JSVAL_TO_INT(idval);
153 154

	switch(tiny) {
rswindell's avatar
rswindell committed
155
		case USER_PROP_NUMBER:
156
			val=p->user->number;
rswindell's avatar
rswindell committed
157
			break;
158
		case USER_PROP_ALIAS: 
159
			s=p->user->alias;
160 161
			break;
		case USER_PROP_NAME:
162
			s=p->user->name;
163 164
			break;
		case USER_PROP_HANDLE:
165
			s=p->user->handle;
166 167
			break;
		case USER_PROP_NOTE:
168
			s=p->user->note;
169
			break;
deuce's avatar
deuce committed
170 171 172
		case USER_PROP_IPADDR:
			s=p->user->ipaddr;
			break;
173
		case USER_PROP_COMP:
174
			s=p->user->comp;
175 176
			break;
		case USER_PROP_COMMENT:
177
			s=p->user->comment;
178 179
			break;
		case USER_PROP_NETMAIL:
180
			s=p->user->netmail;
181
			break;
182
		case USER_PROP_EMAIL:
183 184
			s=usermailaddr(scfg, tmp
				,scfg->inetmail_misc&NMAIL_ALIAS ? p->user->alias : p->user->name);
185
			break;
186
		case USER_PROP_ADDRESS:
187
			s=p->user->address;
188 189
			break;
		case USER_PROP_LOCATION:
190
			s=p->user->location;
191 192
			break;
		case USER_PROP_ZIPCODE:
193
			s=p->user->zipcode;
194 195
			break;
		case USER_PROP_PASS:
196
			s=p->user->pass;
197 198
			break;
		case USER_PROP_PHONE:
199
			s=p->user->phone;
200 201
			break;
		case USER_PROP_BIRTH:
202
			s=p->user->birth;
203
			break;
204 205 206 207 208 209 210 211 212
		case USER_PROP_BIRTHYEAR:
			val = getbirthyear(p->user->birth);
			break;
		case USER_PROP_BIRTHMONTH:
			val = getbirthmonth(scfg, p->user->birth);
			break;
		case USER_PROP_BIRTHDAY:
			val = getbirthday(scfg, p->user->birth);
			break;
213
		case USER_PROP_AGE:
214
			val=getage(scfg,p->user->birth);
215 216
			break;
		case USER_PROP_MODEM:
217
			s=p->user->modem;
218 219
			break;
		case USER_PROP_LASTON:
220
			val=p->user->laston;
221 222
			break;
		case USER_PROP_FIRSTON:
223
			val=p->user->firston;
224 225
			break;
		case USER_PROP_EXPIRE:
226
			val=p->user->expire;
227 228
			break;
		case USER_PROP_PWMOD: 
229
			val=p->user->pwmod;
230 231
			break;
		case USER_PROP_LOGONS:
232
			val=p->user->logons;
233 234
			break;
		case USER_PROP_LTODAY:
235
			val=p->user->ltoday;
236 237
			break;
		case USER_PROP_TIMEON:
238
			val=p->user->timeon;
239 240
			break;
		case USER_PROP_TEXTRA:
241
			val=p->user->textra;
242 243
			break;
		case USER_PROP_TTODAY:
244
			val=p->user->ttoday;
245 246
			break;
		case USER_PROP_TLAST: 
247
			val=p->user->tlast;
248 249
			break;
		case USER_PROP_POSTS: 
250
			val=p->user->posts;
251 252
			break;
		case USER_PROP_EMAILS: 
253
			val=p->user->emails;
254 255
			break;
		case USER_PROP_FBACKS: 
256
			val=p->user->fbacks;
257 258
			break;
		case USER_PROP_ETODAY:	
259
			val=p->user->etoday;
260 261
			break;
		case USER_PROP_PTODAY:
262
			val=p->user->ptoday;
263 264
			break;
		case USER_PROP_ULB:
265
			val=p->user->ulb;
266 267
			break;
		case USER_PROP_ULS:
268
			val=p->user->uls;
269 270
			break;
		case USER_PROP_DLB:
271
			val=p->user->dlb;
272 273
			break;
		case USER_PROP_DLS:
274
			val=p->user->dls;
275 276
			break;
		case USER_PROP_CDT:
277
			val=p->user->cdt;
278 279
			break;
		case USER_PROP_MIN:
280
			val=p->user->min;
281 282
			break;
		case USER_PROP_LEVEL:
283
			val=p->user->level;
284 285
			break;
		case USER_PROP_FLAGS1:
286
			val=p->user->flags1;
287 288
			break;
		case USER_PROP_FLAGS2:
289
			val=p->user->flags2;
290 291
			break;
		case USER_PROP_FLAGS3:
292
			val=p->user->flags3;
293 294
			break;
		case USER_PROP_FLAGS4:
295
			val=p->user->flags4;
296 297
			break;
		case USER_PROP_EXEMPT:
298
			val=p->user->exempt;
299 300
			break;
		case USER_PROP_REST:
301
			val=p->user->rest;
302 303
			break;
		case USER_PROP_ROWS:
304
			val=p->user->rows;
305
			break;
306 307 308
		case USER_PROP_COLS:
			val=p->user->cols;
			break;
309
		case USER_PROP_SEX:
310
			sprintf(tmp,"%c",p->user->sex);
311 312
			s=tmp;
			break;
313
		case USER_PROP_MISC:
314
			val=p->user->misc;
315 316
			break;
		case USER_PROP_LEECH:
317
			val=p->user->leech;
318 319
			break;
		case USER_PROP_CURSUB:
320
			s=p->user->cursub;
321 322
			break;
		case USER_PROP_CURDIR:
323
			s=p->user->curdir;
324
			break;
325
		case USER_PROP_CURXTRN:
326
			s=p->user->curxtrn;
327 328
			break;

329
		case USER_PROP_FREECDT:
330
			val=p->user->freecdt;
331 332
			break;
		case USER_PROP_XEDIT:
333 334
			if(p->user->xedit>0 && p->user->xedit<=scfg->total_xedits)
				s=scfg->xedit[p->user->xedit-1]->code;
335 336
			else
				s=""; /* internal editor */
337 338
			break;
		case USER_PROP_SHELL:
339
			s=scfg->shell[p->user->shell]->code;
340
			break;
341
		case USER_PROP_QWK:
342
			val=p->user->qwk;
343 344
			break;
		case USER_PROP_TMPEXT:
345
			s=p->user->tmpext;
346 347
			break;
		case USER_PROP_CHAT:
348
			val=p->user->chat;
349 350
			break;
		case USER_PROP_NS_TIME:
351
			val=p->user->ns_time;
352 353
			break;
		case USER_PROP_PROT:
354
			sprintf(tmp,"%c",p->user->prot);
355 356
			s=tmp;
			break;
357
		case USER_PROP_LOGONTIME:
358
			val=p->user->logontime;
359
			break;
360
		case USER_PROP_TIMEPERCALL:
361
			val=scfg->level_timepercall[p->user->level];
362 363
			break;
		case USER_PROP_TIMEPERDAY:
364
			val=scfg->level_timeperday[p->user->level];
365 366
			break;
		case USER_PROP_CALLSPERDAY:
367
			val=scfg->level_callsperday[p->user->level];
368 369
			break;
		case USER_PROP_LINESPERMSG:
370
			val=scfg->level_linespermsg[p->user->level];
371 372
			break;
		case USER_PROP_POSTSPERDAY:
373
			val=scfg->level_postsperday[p->user->level];
374 375
			break;
		case USER_PROP_EMAILPERDAY:
376
			val=scfg->level_emailperday[p->user->level];
377 378
			break;
		case USER_PROP_FREECDTPERDAY:
379
			val=scfg->level_freecdtperday[p->user->level];
380
			break;
381
		case USER_PROP_MAIL_WAITING:
382 383 384 385 386 387 388 389 390 391
			val=getmail(scfg,p->user->number,/* sent? */FALSE, /* attr: */0);
			break;
		case USER_PROP_READ_WAITING:
			val=getmail(scfg,p->user->number,/* sent? */FALSE, /* attr: */MSG_READ);
			break;
		case USER_PROP_UNREAD_WAITING:
			val=getmail(scfg,p->user->number,/* sent? */FALSE, /* attr: */~MSG_READ);
			break;
		case USER_PROP_SPAM_WAITING:
			val=getmail(scfg,p->user->number,/* sent? */FALSE, /* attr: */MSG_SPAM);
392 393
			break;
		case USER_PROP_MAIL_PENDING:
394
			val=getmail(scfg,p->user->number,/* sent? */TRUE, /* SPAM: */FALSE);
395
			break;
396

397 398
		case USER_PROP_CACHED:
			*vp = BOOLEAN_TO_JSVAL(p->cached);
399
			JS_RESUMEREQUEST(cx, rc);
400 401
			return(JS_TRUE);	/* intentional early return */

402
		case USER_PROP_IS_SYSOP:
403
			*vp = BOOLEAN_TO_JSVAL(p->user->level >= SYSOP_LEVEL);
404
			JS_RESUMEREQUEST(cx, rc);
405 406
			return(JS_TRUE);	/* intentional early return */

407 408
		default:	
			/* This must not set vp in order for child objects to work (stats and security) */
409
			JS_RESUMEREQUEST(cx, rc);
410
			return(JS_TRUE);
411
	}
412
	JS_RESUMEREQUEST(cx, rc);
413 414 415 416
	if(s!=NULL) {
		if((js_str=JS_NewStringCopyZ(cx, s))==NULL)
			return(JS_FALSE);
		*vp = STRING_TO_JSVAL(js_str);
417
	} else
418
		*vp=DOUBLE_TO_JSVAL((double)val);
419

420
	return(JS_TRUE);
421 422
}

423
static JSBool js_user_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
424
{
425
	jsval idval;
426
	char*		str = NULL;
427
	char		tmp[64];
428
	uint32		val;
rswindell's avatar
rswindell committed
429
	ulong		usermisc;
430
    jsint       tiny;
431
	private_t*	p;
432
	int32		usernumber;
deuce's avatar
deuce committed
433
	jsrefcount	rc;
434 435 436
	scfg_t*			scfg;

	scfg=JS_GetRuntimePrivate(JS_GetRuntime(cx));
437

438 439
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_TRUE);
440

deuce's avatar
deuce committed
441
	JSVALUE_TO_MSTRING(cx, *vp, str, NULL);
442
	HANDLE_PENDING(cx, str);
deuce's avatar
deuce committed
443
	if(str==NULL)
444
		return(JS_FALSE);
445

446 447
    JS_IdToValue(cx, id, &idval);
    tiny = JSVAL_TO_INT(idval);
448

449
	rc=JS_SUSPENDREQUEST(cx);
450
	switch(tiny) {
rswindell's avatar
rswindell committed
451
		case USER_PROP_NUMBER:
452
			JS_RESUMEREQUEST(cx, rc);
deuce's avatar
deuce committed
453 454
			if(!JS_ValueToInt32(cx, *vp, &usernumber)) {
				free(str);
455
				return JS_FALSE;
deuce's avatar
deuce committed
456
			}
457
			rc=JS_SUSPENDREQUEST(cx);
458
			if(usernumber!=p->user->number) {
459
				p->user->number=(ushort)usernumber;
460 461
				p->cached=FALSE;
			}
rswindell's avatar
rswindell committed
462
			break;
463
		case USER_PROP_ALIAS:
464
			SAFECOPY(p->user->alias,str);
rswindell's avatar
rswindell committed
465
			/* update USER.DAT */
466
			putuserrec(scfg,p->user->number,U_ALIAS,LEN_ALIAS,str);
rswindell's avatar
rswindell committed
467 468

			/* update NAME.DAT */
469
			getuserrec(scfg,p->user->number,U_MISC,8,tmp);
rswindell's avatar
rswindell committed
470 471
			usermisc=ahtoul(tmp);
			if(!(usermisc&DELETED))
472
				putusername(scfg,p->user->number,str);
473 474
			break;
		case USER_PROP_NAME:
475
			SAFECOPY(p->user->name,str);
476
			putuserrec(scfg,p->user->number,U_NAME,LEN_NAME,str);
477 478
			break;
		case USER_PROP_HANDLE:
479
			SAFECOPY(p->user->handle,str);
480
			putuserrec(scfg,p->user->number,U_HANDLE,LEN_HANDLE,str);
481 482
			break;
		case USER_PROP_NOTE:		 
483
			SAFECOPY(p->user->note,str);
484
			putuserrec(scfg,p->user->number,U_NOTE,LEN_NOTE,str);
485
			break;
deuce's avatar
deuce committed
486 487 488 489
		case USER_PROP_IPADDR:		 
			SAFECOPY(p->user->ipaddr,str);
			putuserrec(scfg,p->user->number,U_IPADDR,LEN_IPADDR,str);
			break;
490 491
		case USER_PROP_COMP:
			SAFECOPY(p->user->comp,str);
492
			putuserrec(scfg,p->user->number,U_COMP,LEN_COMP,str);
493 494
			break;
		case USER_PROP_COMMENT:	 
495
			SAFECOPY(p->user->comment,str);
496
			putuserrec(scfg,p->user->number,U_COMMENT,LEN_COMMENT,str);
497 498
			break;
		case USER_PROP_NETMAIL:	 
499
			SAFECOPY(p->user->netmail,str);
500
			putuserrec(scfg,p->user->number,U_NETMAIL,LEN_NETMAIL,str);
501 502
			break;
		case USER_PROP_ADDRESS:	 
503
			SAFECOPY(p->user->address,str);
504
			putuserrec(scfg,p->user->number,U_ADDRESS,LEN_ADDRESS,str);
505 506
			break;
		case USER_PROP_LOCATION:	 
507
			SAFECOPY(p->user->location,str);
508
			putuserrec(scfg,p->user->number,U_LOCATION,LEN_LOCATION,str);
509 510
			break;
		case USER_PROP_ZIPCODE:	 
511
			SAFECOPY(p->user->zipcode,str);
512
			putuserrec(scfg,p->user->number,U_ZIPCODE,LEN_ZIPCODE,str);
513 514
			break;
		case USER_PROP_PHONE:  	 
515
			SAFECOPY(p->user->phone,str);
516
			putuserrec(scfg,p->user->number,U_PHONE,LEN_PHONE,str);
517 518
			break;
		case USER_PROP_BIRTH:  	 
519
			SAFECOPY(p->user->birth,str);
520
			putuserrec(scfg,p->user->number,U_BIRTH,LEN_BIRTH,str);
521
			break;
522 523 524 525 526 527 528 529 530 531 532 533
		case USER_PROP_BIRTHYEAR:
			SAFEPRINTF(tmp, "%04u", atoi(str));
			putuserrec(scfg,p->user->number, U_BIRTH, 4, tmp);
			break;
		case USER_PROP_BIRTHMONTH:
			SAFEPRINTF(tmp, "%02u", atoi(str));
			putuserrec(scfg,p->user->number, U_BIRTH + 4, 2, tmp);
			break;
		case USER_PROP_BIRTHDAY:
			SAFEPRINTF(tmp, "%02u", atoi(str));
			putuserrec(scfg,p->user->number, U_BIRTH + 6, 2, tmp);
			break;
534
		case USER_PROP_MODEM:     
535
			SAFECOPY(p->user->modem,str);
536
			putuserrec(scfg,p->user->number,U_MODEM,LEN_MODEM,str);
537
			break;
538 539
		case USER_PROP_ROWS:	
			p->user->rows=atoi(str);
540
			putuserrec(scfg,p->user->number,U_ROWS,0,str);	/* base 10 */
541
			break;
542 543 544 545
		case USER_PROP_COLS:	
			p->user->cols=atoi(str);
			putuserrec(scfg,p->user->number,U_COLS,0,str);	/* base 10 */
			break;
546
		case USER_PROP_SEX:		 
547
			p->user->sex=toupper(str[0]);
548
			putuserrec(scfg,p->user->number,U_SEX,0,strupr(str));	/* single char */
549 550
			break;
		case USER_PROP_CURSUB:	 
551
			SAFECOPY(p->user->cursub,str);
552
			putuserrec(scfg,p->user->number,U_CURSUB,0,str);
553 554
			break;
		case USER_PROP_CURDIR:	 
555
			SAFECOPY(p->user->curdir,str);
556
			putuserrec(scfg,p->user->number,U_CURDIR,0,str);
557
			break;
558
		case USER_PROP_CURXTRN:	 
559
			SAFECOPY(p->user->curxtrn,str);
560
			putuserrec(scfg,p->user->number,U_CURXTRN,0,str);
561
			break;
562
		case USER_PROP_XEDIT: 	 
563
			putuserrec(scfg,p->user->number,U_XEDIT,0,str);
564 565
			break;
		case USER_PROP_SHELL: 	 
566
			putuserrec(scfg,p->user->number,U_SHELL,0,str);
567 568
			break;
		case USER_PROP_MISC:
569
			JS_RESUMEREQUEST(cx, rc);
570
			if(!JS_ValueToECMAUint32(cx,*vp,&val)) {
deuce's avatar
deuce committed
571
				free(str);
572
				return JS_FALSE;
deuce's avatar
deuce committed
573
			}
574
			putuserrec(scfg,p->user->number,U_MISC,0,ultoa(p->user->misc=val,tmp,16));
575
			rc=JS_SUSPENDREQUEST(cx);
576 577
			break;
		case USER_PROP_QWK:		 
578
			JS_RESUMEREQUEST(cx, rc);
579
			if(!JS_ValueToECMAUint32(cx,*vp,&val)) {
deuce's avatar
deuce committed
580
				free(str);
581
				return JS_FALSE;
deuce's avatar
deuce committed
582
			}
583
			putuserrec(scfg,p->user->number,U_QWK,0,ultoa(p->user->qwk=val,tmp,16));
584
			rc=JS_SUSPENDREQUEST(cx);
585 586
			break;
		case USER_PROP_CHAT:		 
587
			JS_RESUMEREQUEST(cx, rc);
588
			if(!JS_ValueToECMAUint32(cx,*vp,&val)) {
deuce's avatar
deuce committed
589
				free(str);
590
				return JS_FALSE;
deuce's avatar
deuce committed
591
			}
592
			putuserrec(scfg,p->user->number,U_CHAT,0,ultoa(p->user->chat=val,tmp,16));
593
			rc=JS_SUSPENDREQUEST(cx);
594 595
			break;
		case USER_PROP_TMPEXT:	 
596
			SAFECOPY(p->user->tmpext,str);
597
			putuserrec(scfg,p->user->number,U_TMPEXT,0,str);
598 599
			break;
		case USER_PROP_NS_TIME:	 
600
			JS_RESUMEREQUEST(cx, rc);
601
			if(!JS_ValueToECMAUint32(cx,*vp,&val)) {
deuce's avatar
deuce committed
602
				free(str);
603
				return JS_FALSE;
deuce's avatar
deuce committed
604
			}
605
			putuserrec(scfg,p->user->number,U_NS_TIME,0,ultoa((ulong)(p->user->ns_time=val),tmp,16));
606
			rc=JS_SUSPENDREQUEST(cx);
607 608
			break;
		case USER_PROP_PROT:	
609
			p->user->prot=toupper(str[0]);
610
			putuserrec(scfg,p->user->number,U_PROT,0,strupr(str)); /* single char */
611
			break;
612
		case USER_PROP_LOGONTIME:	 
613
			JS_RESUMEREQUEST(cx, rc);
614
			if(!JS_ValueToECMAUint32(cx,*vp,&val)) {
deuce's avatar
deuce committed
615
				free(str);
616
				return JS_FALSE;
deuce's avatar
deuce committed
617
			}
618
			putuserrec(scfg,p->user->number,U_LOGONTIME,0,ultoa(p->user->logontime=val,tmp,16));
619
			rc=JS_SUSPENDREQUEST(cx);
620
			break;
621 622 623
			
		/* security properties*/
		case USER_PROP_PASS:	
624
			SAFECOPY(p->user->pass,str);
625
			putuserrec(scfg,p->user->number,U_PASS,LEN_PASS,strupr(str));
626 627
			break;
		case USER_PROP_PWMOD:
628
			JS_RESUMEREQUEST(cx, rc);
629
			if(!JS_ValueToECMAUint32(cx,*vp,&val)) {
deuce's avatar
deuce committed
630
				free(str);
631
				return JS_FALSE;
deuce's avatar
deuce committed
632
			}
633
			putuserrec(scfg,p->user->number,U_PWMOD,0,ultoa(p->user->pwmod=val,tmp,16));
634
			rc=JS_SUSPENDREQUEST(cx);
635 636
			break;
		case USER_PROP_LEVEL: 
637
			p->user->level=atoi(str);
638
			putuserrec(scfg,p->user->number,U_LEVEL,0,str);
639 640
			break;
		case USER_PROP_FLAGS1:
641
			JS_RESUMEREQUEST(cx, rc);
642
			if(JSVAL_IS_STRING(*vp)) {
643
				val=str_to_bits(p->user->flags1 << 1, str) >> 1;
644 645
			}
			else {
646
				if(!JS_ValueToECMAUint32(cx,*vp,&val)) {
deuce's avatar
deuce committed
647
					free(str);
648
					return JS_FALSE;
deuce's avatar
deuce committed
649
				}
650
			}
651
			putuserrec(scfg,p->user->number,U_FLAGS1,0,ultoa(p->user->flags1=val,tmp,16));
652
			rc=JS_SUSPENDREQUEST(cx);
653 654
			break;
		case USER_PROP_FLAGS2:
655
			JS_RESUMEREQUEST(cx, rc);
656
			if(JSVAL_IS_STRING(*vp)) {
657
				val=str_to_bits(p->user->flags2 << 1, str) >> 1;
658 659
			}
			else {
660
				if(!JS_ValueToECMAUint32(cx,*vp,&val)) {
deuce's avatar
deuce committed
661
					free(str);
662
					return JS_FALSE;
deuce's avatar
deuce committed
663
				}
664
			}
665
			putuserrec(scfg,p->user->number,U_FLAGS2,0,ultoa(p->user->flags2=val,tmp,16));
666
			rc=JS_SUSPENDREQUEST(cx);
667 668
			break;
		case USER_PROP_FLAGS3:
669
			JS_RESUMEREQUEST(cx, rc);
670
			if(JSVAL_IS_STRING(*vp)) {
671
				val=str_to_bits(p->user->flags3 << 1, str) >> 1;
672 673
			}
			else {
674
				if(!JS_ValueToECMAUint32(cx,*vp,&val)) {
deuce's avatar
deuce committed
675
					free(str);
676
					return JS_FALSE;
deuce's avatar
deuce committed
677
				}
678
			}
679
			putuserrec(scfg,p->user->number,U_FLAGS3,0,ultoa(p->user->flags3=val,tmp,16));
680
			rc=JS_SUSPENDREQUEST(cx);
681 682
			break;
		case USER_PROP_FLAGS4:
683
			JS_RESUMEREQUEST(cx, rc);
684
			if(JSVAL_IS_STRING(*vp)) {
685
				val=str_to_bits(p->user->flags4 << 1, str</