chk_ar.cpp 19.3 KB
Newer Older
1
2
3
4
/* chk_ar.cpp */

/* Synchronet ARS checking routine */

5
/* $Id: chk_ar.cpp,v 1.32 2020/03/19 18:50:51 rswindell Exp $ */
6
7
8
9
10

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 *																			*
 * 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										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"

rswindell's avatar
rswindell committed
40
bool sbbs_t::ar_exp(const uchar **ptrptr, user_t* user, client_t* client)
41
{
42
	bool	result,_not,_or,equal;
43
44
	uint	i,n,artype,age;
	ulong	l;
45
	struct tm tm;
rswindell's avatar
rswindell committed
46
	const char*	p;
47
48
49
50
51
52
53
54

	result = true;

	for(;(**ptrptr);(*ptrptr)++) {

		if((**ptrptr)==AR_ENDNEST)
			break;

55
		_not=_or=equal = false;
56
57

		if((**ptrptr)==AR_OR) {
58
			_or=true;
59
60
			(*ptrptr)++; 
		}
61
62
		
		if((**ptrptr)==AR_NOT) {
63
			_not=true;
64
65
			(*ptrptr)++; 
		}
66
67
68

		if((**ptrptr)==AR_EQUAL) {
			equal=true;
69
70
			(*ptrptr)++; 
		}
71

72
		if((result && _or) || (!result && !_or))
73
74
75
76
			break;

		if((**ptrptr)==AR_BEGNEST) {
			(*ptrptr)++;
rswindell's avatar
rswindell committed
77
			if(ar_exp(ptrptr,user,client))
78
				result=!_not;
79
			else
80
				result=_not;
81
82
83
84
			while((**ptrptr)!=AR_ENDNEST && (**ptrptr)) /* in case of early exit */
				(*ptrptr)++;
			if(!(**ptrptr))
				break;
85
86
			continue; 
		}
87
88
89
90

		artype=(**ptrptr);
		switch(artype) {
			case AR_ANSI:				/* No arguments */
rswindell's avatar
rswindell committed
91
			case AR_PETSCII:
92
93
94
			case AR_ASCII:
			case AR_UTF8:
			case AR_CP437:
95
96
97
98
99
			case AR_RIP:
			case AR_WIP:
			case AR_LOCAL:
			case AR_EXPERT:
			case AR_SYSOP:
100
101
			case AR_GUEST:
			case AR_QNODE:
102
103
104
			case AR_QUIET:
			case AR_OS2:
			case AR_DOS:
105
106
107
			case AR_WIN32:
			case AR_UNIX:
			case AR_LINUX:
108
109
110
			case AR_ACTIVE:
			case AR_INACTIVE:
			case AR_DELETED:
111
112
113
				break;
			default:
				(*ptrptr)++;
114
115
				break; 
		}
116
117
118
119
120
121

		n=(**ptrptr);
		i=(*(short *)*ptrptr);
		switch(artype) {
			case AR_LEVEL:
				if((equal && user->level!=n) || (!equal && user->level<n))
122
					result=_not;
123
				else
124
					result=!_not;
125
126
				if(!result) {
					noaccess_str=text[NoAccessLevel];
127
128
					noaccess_val=n; 
				}
129
130
131
132
				break;
			case AR_AGE:
				age=getage(&cfg,user->birth);
				if((equal && age!=n) || (!equal && age<n))
133
					result=_not;
134
				else
135
					result=!_not;
136
137
				if(!result) {
					noaccess_str=text[NoAccessAge];
138
139
					noaccess_val=n; 
				}
140
141
142
				break;
			case AR_BPS:
				if((equal && cur_rate!=i) || (!equal && cur_rate<i))
143
					result=_not;
144
				else
145
					result=!_not;
146
147
148
				(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessBPS];
149
150
					noaccess_val=i; 
				}
151
152
				break;
			case AR_ANSI:
153
				if(!term_supports(ANSI))
154
155
					result=_not;
				else result=!_not;
rswindell's avatar
rswindell committed
156
157
158
159
160
161
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=ANSI; 
				}
				break;
			case AR_PETSCII:
162
				if((term_supports()&CHARSET_FLAGS) != CHARSET_PETSCII)
rswindell's avatar
rswindell committed
163
164
165
166
167
168
					result=_not;
				else result=!_not;
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=PETSCII; 
				}
169
				break;
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
			case AR_ASCII:
				if((term_supports()&CHARSET_FLAGS) != CHARSET_ASCII)
					result=_not;
				else result=!_not;
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=NO_EXASCII; 
				}
				break;
			case AR_UTF8:
				if((term_supports()&CHARSET_FLAGS) != CHARSET_UTF8)
					result=_not;
				else result=!_not;
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=UTF8; 
				}
				break;
			case AR_CP437:
				if((term_supports()&CHARSET_FLAGS) != CHARSET_CP437)
					result=_not;
				else result=!_not;
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=0; 
				}
				break;
197
			case AR_RIP:
198
				if(!term_supports(RIP))
199
200
					result=_not;
				else result=!_not;
rswindell's avatar
rswindell committed
201
202
203
204
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=RIP; 
				}
205
206
				break;
			case AR_WIP:
207
				if(!term_supports(WIP))
208
209
					result=_not;
				else result=!_not;
rswindell's avatar
rswindell committed
210
211
212
213
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=WIP; 
				}
214
215
216
				break;
			case AR_OS2:
				#ifndef __OS2__
217
					result=_not;
218
				#else
219
					result=!_not;
220
221
				#endif
				break;
222
			case AR_DOS:	/* DOS program support */
deuce's avatar
deuce committed
223
				result=_not;
224
225
				if(startup->options&BBS_OPT_NO_DOS)
					break;
226
				#if defined(_WIN32) || defined(__FreeBSD__)
227
					result=!_not;
228
229
230
				#elif defined(__linux__)
					if (startup->usedosemu) 
						result=!_not;
231
				#endif
232
233
234
				break;
			case AR_WIN32:
				#ifndef _WIN32
235
					result=_not;
236
				#else
237
					result=!_not;
238
239
240
241
				#endif
				break;
			case AR_UNIX:
				#ifndef __unix__
242
					result=_not;
243
				#else
244
					result=!_not;
245
246
247
248
				#endif
				break;
			case AR_LINUX:
				#ifndef __linux__
249
					result=_not;
250
				#else
251
					result=!_not;
252
253
				#endif
				break;
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
			case AR_ACTIVE:
				if(user->misc&(DELETED|INACTIVE))
					result=_not;
				else result=!_not;
				break;
			case AR_INACTIVE:
				if(!(user->misc&INACTIVE))
					result=_not;
				else result=!_not;
				break;
			case AR_DELETED:
				if(!(user->misc&DELETED))
					result=_not;
				else result=!_not;
				break;
269
270
			case AR_EXPERT:
				if(!(user->misc&EXPERT))
271
272
					result=_not;
				else result=!_not;
273
274
				break;
			case AR_SYSOP:
275
				if(user->level < SYSOP_LEVEL && !(sys_status & SS_TMPSYSOP))
276
277
					result=_not;
				else result=!_not;
278
				break;
279
280
281
282
283
284
285
286
287
288
			case AR_GUEST:
				if(!(user->rest&FLAG('G')))
					result=_not;
				else result=!_not;
				break;
			case AR_QNODE:
				if(!(user->rest&FLAG('Q')))
					result=_not;
				else result=!_not;
				break;
289
290
			case AR_QUIET:
				if(thisnode.status!=NODE_QUIET)
291
292
					result=_not;
				else result=!_not;
293
294
295
				break;
			case AR_LOCAL:
				if(online!=ON_LOCAL)
296
297
					result=_not;
				else result=!_not;
298
299
300
				break;
			case AR_DAY:
				now=time(NULL);
301
302
303
				localtime_r(&now,&tm);
				if((equal && tm.tm_wday!=(int)n) 
					|| (!equal && tm.tm_wday<(int)n))
304
					result=_not;
305
				else
306
					result=!_not;
307
308
				if(!result) {
					noaccess_str=text[NoAccessDay];
309
310
					noaccess_val=n; 
				}
311
312
313
314
315
				break;
			case AR_CREDIT:
				l=(ulong)i*1024UL;
				if((equal && user->cdt+user->freecdt!=l)
					|| (!equal && user->cdt+user->freecdt<l))
316
					result=_not;
317
				else
318
					result=!_not;
319
320
321
				(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessCredit];
322
323
					noaccess_val=l; 
				}
324
325
326
				break;
			case AR_NODE:
				if((equal && cfg.node_num!=n) || (!equal && cfg.node_num<n))
327
					result=_not;
328
				else
329
					result=!_not;
330
331
				if(!result) {
					noaccess_str=text[NoAccessNode];
332
333
					noaccess_val=n; 
				}
334
335
336
				break;
			case AR_USER:
				if((equal && user->number!=i) || (!equal && user->number<i))
337
					result=_not;
338
				else
339
					result=!_not;
340
341
342
				(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessUser];
343
344
					noaccess_val=i; 
				}
345
346
347
348
349
350
351
				break;
			case AR_GROUP:
				if((equal
					&& (cursubnum>=cfg.total_subs
						|| cfg.sub[cursubnum]->grp!=i))
					|| (!equal && cursubnum<cfg.total_subs
						&& cfg.sub[cursubnum]->grp<i))
352
					result=_not;
353
				else
354
					result=!_not;
355
356
357
				(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessGroup];
358
359
					noaccess_val=i+1; 
				}
360
361
362
				break;
			case AR_SUB:
				if((equal && cursubnum!=i) || (!equal && cursubnum<i))
363
					result=_not;
364
				else
365
					result=!_not;
366
367
368
				(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessSub];
369
370
					noaccess_val=i+1; 
				}
371
372
373
				break;
			case AR_SUBCODE:
				if(cursubnum>=cfg.total_subs
rswindell's avatar
rswindell committed
374
					|| !findstr_in_string(cfg.sub[cursubnum]->code,(char*)*ptrptr))
375
					result=_not;
376
				else
377
					result=!_not;
378
379
380
381
382
383
384
385
386
387
388
				while(*(*ptrptr))
					(*ptrptr)++;
				if(!result)
					noaccess_str=text[NoAccessSub];
				break;
			case AR_LIB:
				if((equal
					&& (curdirnum>=cfg.total_dirs
						|| cfg.dir[curdirnum]->lib!=i))
					|| (!equal && curdirnum<cfg.total_dirs
						&& cfg.dir[curdirnum]->lib<i))
389
					result=_not;
390
				else
391
					result=!_not;
392
393
394
				(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessLib];
395
396
					noaccess_val=i+1; 
				}
397
398
399
				break;
			case AR_DIR:
				if((equal && curdirnum!=i) || (!equal && curdirnum<i))
400
					result=_not;
401
				else
402
					result=!_not;
403
404
405
				(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessDir];
406
407
					noaccess_val=i+1; 
				}
408
409
410
				break;
			case AR_DIRCODE:
				if(curdirnum>=cfg.total_dirs
rswindell's avatar
rswindell committed
411
					|| !findstr_in_string(cfg.dir[curdirnum]->code,(char *)*ptrptr))
412
					result=_not;
413
				else
414
					result=!_not;
415
416
417
418
419
420
421
422
				while(*(*ptrptr))
					(*ptrptr)++;
				if(!result)
					noaccess_str=text[NoAccessSub];
				break;
			case AR_EXPIRE:
				now=time(NULL);
				if(!user->expire || now+((long)i*24L*60L*60L)>user->expire)
423
					result=_not;
424
				else
425
					result=!_not;
426
427
428
				(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessExpire];
429
430
					noaccess_val=i; 
				}
431
432
				break;
			case AR_RANDOM:
433
				n=sbbs_random(i+1);
434
				if((equal && n!=i) || (!equal && n<i))
435
					result=_not;
436
				else
437
					result=!_not;
438
439
440
441
442
				(*ptrptr)++;
				break;
			case AR_LASTON:
				now=time(NULL);
				if((now-user->laston)/(24L*60L*60L)<(long)i)
443
					result=_not;
444
				else
445
					result=!_not;
446
447
448
449
				(*ptrptr)++;
				break;
			case AR_LOGONS:
				if((equal && user->logons!=i) || (!equal && user->logons<i))
450
					result=_not;
451
				else
452
					result=!_not;
453
454
455
456
				(*ptrptr)++;
				break;
			case AR_MAIN_CMDS:
				if((equal && main_cmds!=i) || (!equal && main_cmds<i))
457
					result=_not;
458
				else
459
					result=!_not;
460
461
462
463
				(*ptrptr)++;
				break;
			case AR_FILE_CMDS:
				if((equal && xfer_cmds!=i) || (!equal && xfer_cmds<i))
464
					result=_not;
465
				else
466
					result=!_not;
467
468
469
470
				(*ptrptr)++;
				break;
			case AR_TLEFT:
				if(timeleft/60<(ulong)n)
471
					result=_not;
472
				else
473
					result=!_not;
474
475
				if(!result) {
					noaccess_str=text[NoAccessTimeLeft];
476
477
					noaccess_val=n; 
				}
478
479
480
				break;
			case AR_TUSED:
				if((time(NULL)-logontime)/60<(long)n)
481
					result=_not;
482
				else
483
					result=!_not;
484
485
				if(!result) {
					noaccess_str=text[NoAccessTimeUsed];
486
487
					noaccess_val=n; 
				}
488
489
490
				break;
			case AR_TIME:
				now=time(NULL);
491
492
				localtime_r(&now,&tm);
				if((tm.tm_hour*60)+tm.tm_min<(int)i)
493
					result=_not;
494
				else
495
					result=!_not;
496
497
498
				(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessTime];
499
500
					noaccess_val=i; 
				}
501
				break;
502
			case AR_PCR:	/* post/call ratio (by percentage) */
503
				if(user->logons>user->posts
504
					&& (!user->posts || (100/((float)user->logons/user->posts))<(long)n))
505
					result=_not;
506
				else
507
					result=!_not;
508
509
				if(!result) {
					noaccess_str=text[NoAccessPCR];
510
511
					noaccess_val=n; 
				}
512
				break;
513
			case AR_UDR:	/* up/download byte ratio (by percentage) */
514
515
516
				l=user->dlb;
				if(!l) l=1;
				if(user->dlb>user->ulb
517
					&& (!user->ulb || (100/((float)l/user->ulb))<n))
518
					result=_not;
519
				else
520
					result=!_not;
521
522
				if(!result) {
					noaccess_str=text[NoAccessUDR];
523
524
					noaccess_val=n; 
				}
525
				break;
526
			case AR_UDFR:	/* up/download file ratio (in percentage) */
527
528
529
				i=user->dls;
				if(!i) i=1;
				if(user->dls>user->uls
530
					&& (!user->uls || (100/((float)i/user->uls))<n))
531
					result=_not;
532
				else
533
					result=!_not;
534
535
				if(!result) {
					noaccess_str=text[NoAccessUDFR];
536
537
					noaccess_val=n; 
				}
538
				break;
rswindell's avatar
rswindell committed
539
540
541
542
543
544
545
			case AR_ULS:
				if((equal && user->uls!=i) || (!equal && user->uls<i))
					result=_not;
				else
					result=!_not;
				(*ptrptr)++;
				break;
546
547
548
549
550
551
552
553
554
			case AR_ULK:
				if((equal && (user->ulb/1024)!=i) || (!equal && (user->ulb/1024)<i))
					result=_not;
				else
					result=!_not;
				(*ptrptr)++;
				break;
			case AR_ULM:
				if((equal && (user->ulb/(1024*1024))!=i) || (!equal && (user->ulb/(1024*1024))<i))
rswindell's avatar
rswindell committed
555
556
557
558
559
560
561
562
563
564
565
566
					result=_not;
				else
					result=!_not;
				(*ptrptr)++;
				break;
			case AR_DLS:
				if((equal && user->dls!=i) || (!equal && user->dls<i))
					result=_not;
				else
					result=!_not;
				(*ptrptr)++;
				break;
567
568
569
570
571
572
573
574
575
			case AR_DLK:
				if((equal && user->dlb/1024!=i) || (!equal && user->dlb/1024<i))
					result=_not;
				else
					result=!_not;
				(*ptrptr)++;
				break;
			case AR_DLM:
				if((equal && user->dlb/(1024*1024)!=i) || (!equal && user->dlb/(1024*1024)<i))
rswindell's avatar
rswindell committed
576
577
578
579
580
					result=_not;
				else
					result=!_not;
				(*ptrptr)++;
				break;
581
582
583
			case AR_FLAG1:
				if((!equal && !(user->flags1&FLAG(n)))
					|| (equal && user->flags1!=FLAG(n)))
584
					result=_not;
585
				else
586
					result=!_not;
587
588
				if(!result) {
					noaccess_str=text[NoAccessFlag1];
589
590
					noaccess_val=n; 
				}
591
592
593
594
				break;
			case AR_FLAG2:
				if((!equal && !(user->flags2&FLAG(n)))
					|| (equal && user->flags2!=FLAG(n)))
595
					result=_not;
596
				else
597
					result=!_not;
598
599
				if(!result) {
					noaccess_str=text[NoAccessFlag2];
600
601
					noaccess_val=n; 
				}
602
603
604
605
				break;
			case AR_FLAG3:
				if((!equal && !(user->flags3&FLAG(n)))
					|| (equal && user->flags3!=FLAG(n)))
606
					result=_not;
607
				else
608
					result=!_not;
609
610
				if(!result) {
					noaccess_str=text[NoAccessFlag3];
611
612
					noaccess_val=n; 
				}
613
614
615
616
				break;
			case AR_FLAG4:
				if((!equal && !(user->flags4&FLAG(n)))
					|| (equal && user->flags4!=FLAG(n)))
617
					result=_not;
618
				else
619
					result=!_not;
620
621
				if(!result) {
					noaccess_str=text[NoAccessFlag4];
622
623
					noaccess_val=n; 
				}
624
625
626
627
				break;
			case AR_REST:
				if((!equal && !(user->rest&FLAG(n)))
					|| (equal && user->rest!=FLAG(n)))
628
					result=_not;
629
				else
630
					result=!_not;
631
632
				if(!result) {
					noaccess_str=text[NoAccessRest];
633
634
					noaccess_val=n; 
				}
635
636
637
638
				break;
			case AR_EXEMPT:
				if((!equal && !(user->exempt&FLAG(n)))
					|| (equal && user->exempt!=FLAG(n)))
639
					result=_not;
640
				else
641
					result=!_not;
642
643
				if(!result) {
					noaccess_str=text[NoAccessExempt];
644
645
					noaccess_val=n; 
				}
646
647
648
				break;
			case AR_SEX:
				if(user->sex!=n)
649
					result=_not;
650
				else
651
					result=!_not;
652
653
				if(!result) {
					noaccess_str=text[NoAccessSex];
654
655
					noaccess_val=n; 
				}
656
657
658
				break; 
			case AR_SHELL:
				if(user->shell>=cfg.total_shells
rswindell's avatar
rswindell committed
659
					|| !findstr_in_string(cfg.shell[user->shell]->code,(char*)*ptrptr))
660
661
662
663
664
665
					result=_not;
				else
					result=!_not;
				while(*(*ptrptr))
					(*ptrptr)++;
				break;
666
			case AR_PROT:
rswindell's avatar
rswindell committed
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
				if(client!=NULL)
					p=client->protocol;
				else
					p=user->modem;
				if(!findstr_in_string(p,(char*)*ptrptr))
					result=_not;
				else
					result=!_not;
				while(*(*ptrptr))
					(*ptrptr)++;
				break;
			case AR_HOST:
				if(client!=NULL)
					p=client->host;
				else
					p=user->comp;
				if(!findstr_in_string(p,(char*)*ptrptr))
					result=_not;
				else
					result=!_not;
				while(*(*ptrptr))
					(*ptrptr)++;
				break;
			case AR_IP:
				if(client!=NULL)
					p=client->addr;
				else
deuce's avatar
deuce committed
694
					p=user->ipaddr;
rswindell's avatar
rswindell committed
695
				if(!findstr_in_string(p,(char*)*ptrptr))
696
697
698
699
700
701
					result=_not;
				else
					result=!_not;
				while(*(*ptrptr))
					(*ptrptr)++;
				break;
rswindell's avatar
rswindell committed
702
703
704
705
706
707
708
709
710
711
712
713
714
			case AR_TERM:
				if(!findstr_in_string(terminal, (char*)*ptrptr))
					result=_not;
				else
					result=!_not;
				while(*(*ptrptr))
					(*ptrptr)++;
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=0; 
				}
				break;
			case AR_COLS:
715
				if((equal && cols != (long)n) || (!equal && cols < (long)n))
rswindell's avatar
rswindell committed
716
717
718
719
720
721
722
723
724
					result=_not;
				else
					result=!_not;
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=n; 
				}
				break;
			case AR_ROWS:
725
				if((equal && rows != (long)n) || (!equal && rows < (long)n))
rswindell's avatar
rswindell committed
726
727
728
729
730
731
732
733
					result=_not;
				else
					result=!_not;
				if(!result) {
					noaccess_str=text[NoAccessTerminal];
					noaccess_val=n; 
				}
				break;
734
735
		}
	}
736
737
738
	return(result);
}

rswindell's avatar
rswindell committed
739
bool sbbs_t::chk_ar(const uchar *ar, user_t* user, client_t* client)
740
{
741
	const uchar *p;
742
743
744
745

	if(ar==NULL)
		return(true);
	p=ar;
rswindell's avatar
rswindell committed
746
	return(ar_exp(&p,user,client));
747
748
749
750
751
752
753
754
755
756
757
758
}


/****************************************************************************/
/* This function fills the usrsub, usrsubs, usrgrps, curgrp, and cursub     */
/* variables based on the security clearance of the current user (useron)   */
/****************************************************************************/
void sbbs_t::getusrsubs()
{
    uint i,j,k,l;

	for(j=0,i=0;i<cfg.total_grps;i++) {
rswindell's avatar
rswindell committed
759
		if(!chk_ar(cfg.grp[i]->ar,&useron,&client))
760
761
762
			continue;
		for(k=0,l=0;l<cfg.total_subs;l++) {
			if(cfg.sub[l]->grp!=i) continue;
rswindell's avatar
rswindell committed
763
			if(!chk_ar(cfg.sub[l]->ar,&useron,&client))
764
				continue;
765
766
			usrsub[j][k++]=l; 
		}
767
768
769
		usrsubs[j]=k;
		if(!k)          /* No subs accessible in group */
			continue;
770
771
		usrgrp[j++]=i; 
	}
772
	usrgrps=j;
773
774
	if(usrgrps==0)
		return;
775
776
777
778
779
780
781
782
783
784
785
786
787
788
	while((curgrp>=usrgrps || !usrsubs[curgrp]) && curgrp) curgrp--;
	while(cursub[curgrp]>=usrsubs[curgrp] && cursub[curgrp]) cursub[curgrp]--;
}

/****************************************************************************/
/* This function fills the usrdir, usrdirs, usrlibs, curlib, and curdir     */
/* variables based on the security clearance of the current user (useron)   */
/****************************************************************************/
void sbbs_t::getusrdirs()
{
    uint i,j,k,l;

	if(useron.rest&FLAG('T')) {
		usrlibs=0;
789
790
		return; 
	}
791
	for(j=0,i=0;i<cfg.total_libs;i++) {
rswindell's avatar
rswindell committed
792
		if(!chk_ar(cfg.lib[i]->ar,&useron,&client))
793
794
795
			continue;
		for(k=0,l=0;l<cfg.total_dirs;l++) {
			if(cfg.dir[l]->lib!=i) continue;
rswindell's avatar
rswindell committed
796
			if(!chk_ar(cfg.dir[l]->ar,&useron,&client))
797
				continue;
798
799
			usrdir[j][k++]=l; 
		}
800
801
802
		usrdirs[j]=k;
		if(!k)          /* No dirs accessible in lib */
			continue;
803
804
		usrlib[j++]=i; 
	}
805
	usrlibs=j;
806
807
	if(usrlibs==0)
		return;
808
809
810
811
	while((curlib>=usrlibs || !usrdirs[curlib]) && curlib) curlib--;
	while(curdir[curlib]>=usrdirs[curlib] && curdir[curlib]) curdir[curlib]--;
}

812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
uint sbbs_t::getusrgrp(uint subnum)
{
	uint	ugrp;

	if(subnum==INVALID_SUB)
		return(0);

	if(usrgrps<=0)
		return(0);

	for(ugrp=0;ugrp<usrgrps;ugrp++)
		if(usrgrp[ugrp]==cfg.sub[subnum]->grp)
			break;

	return(ugrp+1);
}

uint sbbs_t::getusrsub(uint subnum)
{
	uint	usub;
	uint	ugrp;

	ugrp = getusrgrp(subnum);
	if(ugrp<=0)
		return(0);
837
	ugrp--;
838
839
840
841
842
843
844
	for(usub=0;usub<usrsubs[ugrp];usub++)
		if(usrsub[ugrp][usub]==subnum)
			break;

	return(usub+1);
}

845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
uint sbbs_t::getusrlib(uint dirnum)
{
	uint	ulib;

	if(dirnum == INVALID_DIR)
		return 0;

	if(usrlibs <= 0)
		return 0;

	for(ulib=0; ulib < usrlibs; ulib++)
		if(usrlib[ulib] == cfg.dir[dirnum]->lib)
			break;

	return ulib+1;
}

uint sbbs_t::getusrdir(uint dirnum)
{
	uint	udir;
	uint	ulib;

	ulib = getusrlib(dirnum);
	if(ulib <= 0)
		return 0;
	ulib--;
	for(udir=0; udir < usrdirs[ulib]; udir++)
		if(usrdir[ulib][udir] == dirnum)
			break;

	return udir+1;
}


879
880
int sbbs_t::dir_op(uint dirnum)
{
881
	return(SYSOP || (cfg.dir[dirnum]->op_ar!=NULL && cfg.dir[dirnum]->op_ar[0] && chk_ar(cfg.dir[dirnum]->op_ar,&useron,&client)));
882
883
884
}