chk_ar.cpp 18.5 KB
Newer Older
1
2
3
4
5
6
/* Synchronet ARS checking routine */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
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
23
 *																			*
 * 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"

rswindell's avatar
rswindell committed
24
bool sbbs_t::ar_exp(const uchar **ptrptr, user_t* user, client_t* client)
25
{
26
	bool	result,_not,_or,equal;
27
28
	uint	i,n,artype,age;
	ulong	l;
29
	struct tm tm;
rswindell's avatar
rswindell committed
30
	const char*	p;
31
32
33
34
35
36
37
38

	result = true;

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

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

39
		_not=_or=equal = false;
40
41

		if((**ptrptr)==AR_OR) {
42
			_or=true;
43
44
			(*ptrptr)++; 
		}
45
46
		
		if((**ptrptr)==AR_NOT) {
47
			_not=true;
48
49
			(*ptrptr)++; 
		}
50
51
52

		if((**ptrptr)==AR_EQUAL) {
			equal=true;
53
54
			(*ptrptr)++; 
		}
55

56
		if((result && _or) || (!result && !_or))
57
58
59
60
			break;

		if((**ptrptr)==AR_BEGNEST) {
			(*ptrptr)++;
rswindell's avatar
rswindell committed
61
			if(ar_exp(ptrptr,user,client))
62
				result=!_not;
63
			else
64
				result=_not;
65
66
67
68
			while((**ptrptr)!=AR_ENDNEST && (**ptrptr)) /* in case of early exit */
				(*ptrptr)++;
			if(!(**ptrptr))
				break;
69
70
			continue; 
		}
71
72
73
74

		artype=(**ptrptr);
		switch(artype) {
			case AR_ANSI:				/* No arguments */
rswindell's avatar
rswindell committed
75
			case AR_PETSCII:
76
77
78
			case AR_ASCII:
			case AR_UTF8:
			case AR_CP437:
79
80
81
82
83
			case AR_RIP:
			case AR_WIP:
			case AR_LOCAL:
			case AR_EXPERT:
			case AR_SYSOP:
84
85
			case AR_GUEST:
			case AR_QNODE:
86
87
88
			case AR_QUIET:
			case AR_OS2:
			case AR_DOS:
89
90
91
			case AR_WIN32:
			case AR_UNIX:
			case AR_LINUX:
92
93
94
			case AR_ACTIVE:
			case AR_INACTIVE:
			case AR_DELETED:
95
96
97
				break;
			default:
				(*ptrptr)++;
98
99
				break; 
		}
100
101
102
103
104
105

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

rswindell's avatar
rswindell committed
723
bool sbbs_t::chk_ar(const uchar *ar, user_t* user, client_t* client)
724
{
725
	const uchar *p;
726
727
728
729

	if(ar==NULL)
		return(true);
	p=ar;
rswindell's avatar
rswindell committed
730
	return(ar_exp(&p,user,client));
731
732
733
734
735
736
737
738
739
740
741
742
}


/****************************************************************************/
/* 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
743
		if(!chk_ar(cfg.grp[i]->ar,&useron,&client))
744
745
746
			continue;
		for(k=0,l=0;l<cfg.total_subs;l++) {
			if(cfg.sub[l]->grp!=i) continue;
rswindell's avatar
rswindell committed
747
			if(!chk_ar(cfg.sub[l]->ar,&useron,&client))
748
				continue;
749
750
			usrsub[j][k++]=l; 
		}
751
752
753
		usrsubs[j]=k;
		if(!k)          /* No subs accessible in group */
			continue;
754
755
		usrgrp[j++]=i; 
	}
756
	usrgrps=j;
757
758
	if(usrgrps==0)
		return;
759
760
761
762
763
764
765
766
767
768
769
770
771
772
	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;
773
774
		return; 
	}
775
	for(j=0,i=0;i<cfg.total_libs;i++) {
rswindell's avatar
rswindell committed
776
		if(!chk_ar(cfg.lib[i]->ar,&useron,&client))
777
778
779
			continue;
		for(k=0,l=0;l<cfg.total_dirs;l++) {
			if(cfg.dir[l]->lib!=i) continue;
rswindell's avatar
rswindell committed
780
			if(!chk_ar(cfg.dir[l]->ar,&useron,&client))
781
				continue;
782
783
			usrdir[j][k++]=l; 
		}
784
785
786
		usrdirs[j]=k;
		if(!k)          /* No dirs accessible in lib */
			continue;
787
788
		usrlib[j++]=i; 
	}
789
	usrlibs=j;
790
791
	if(usrlibs==0)
		return;
792
793
794
795
	while((curlib>=usrlibs || !usrdirs[curlib]) && curlib) curlib--;
	while(curdir[curlib]>=usrdirs[curlib] && curdir[curlib]) curdir[curlib]--;
}

796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
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);
821
	ugrp--;
822
823
824
825
826
827
828
	for(usub=0;usub<usrsubs[ugrp];usub++)
		if(usrsub[ugrp][usub]==subnum)
			break;

	return(usub+1);
}

829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
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;
}


863
864
int sbbs_t::dir_op(uint dirnum)
{
Rob Swindell's avatar
Rob Swindell committed
865
	return(SYSOP || (cfg.dir[dirnum]->op_ar[0] && chk_ar(cfg.dir[dirnum]->op_ar,&useron,&client)));
866
}