|
|
1.1 root 1: /* ars.c */
2:
3: /* Synchronet Access Requirement String (ARS) functions */
4:
1.1.1.2 ! root 5: /* $Id: ars.c,v 1.19 2009/03/22 02:27:18 rswindell Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
1.1.1.2 ! root 11: * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39:
40: const uchar* nular=(uchar*)""; /* AR_NULL */
41:
1.1.1.2 ! root 42: static BOOL ar_string_arg(int artype)
! 43: {
! 44: switch(artype) {
! 45: case AR_SUBCODE:
! 46: case AR_DIRCODE:
! 47: case AR_SHELL:
! 48: case AR_PROT:
! 49: case AR_HOST:
! 50: case AR_IP:
! 51: return TRUE; /* These ARS Keywords expect a string argument */
! 52: }
! 53: return FALSE;
! 54: }
! 55:
1.1 root 56: /* Converts ASCII ARS string into binary ARS buffer */
57:
58: #ifdef __BORLANDC__ /* Eliminate warning when buildling Baja */
59: #pragma argsused
60: #endif
61: uchar* arstr(ushort* count, char* str, scfg_t* cfg)
62: {
1.1.1.2 ! root 63: char* p;
! 64: char* np;
! 65: char ch;
! 66: uchar ar[1024],*ar_buf;
! 67: int artype=AR_INVALID;
! 68: uint i,j,n,not=0,equal=0;
! 69: uint maxlen;
! 70: BOOL arg_expected=FALSE;
1.1 root 71:
72: for(i=j=0;str[i];i++) {
73: if(str[i]==' ')
74: continue;
75:
76: if(str[i]=='(') {
77: if(not)
78: ar[j++]=AR_NOT;
79: not=equal=0;
80: ar[j++]=AR_BEGNEST;
1.1.1.2 ! root 81: continue;
! 82: }
1.1 root 83:
84: if(str[i]==')') {
85: ar[j++]=AR_ENDNEST;
1.1.1.2 ! root 86: continue;
! 87: }
1.1 root 88:
89: if(str[i]=='|') {
90: ar[j++]=AR_OR;
1.1.1.2 ! root 91: continue;
! 92: }
1.1 root 93:
94: if(str[i]=='!') {
95: not=1;
1.1.1.2 ! root 96: continue;
! 97: }
1.1 root 98:
99: if(str[i]=='=') {
100: equal=1;
1.1.1.2 ! root 101: continue;
! 102: }
1.1 root 103:
104: if(str[i]=='&')
105: continue;
106:
107: if(isalpha(str[i])) {
1.1.1.2 ! root 108: p=np=str+i;
! 109: SKIP_ALPHA(np);
! 110: n=np-p;
! 111: if(n==2 && !strnicmp(p,"OR",2)) {
1.1 root 112: ar[j++]=AR_OR;
113: i++;
1.1.1.2 ! root 114: continue;
! 115: }
1.1 root 116:
1.1.1.2 ! root 117: if(n==3 && !strnicmp(p,"AND",3)) { /* AND is ignored */
1.1 root 118: i+=2;
1.1.1.2 ! root 119: continue;
! 120: }
1.1 root 121:
1.1.1.2 ! root 122: if(n==3 && !strnicmp(p,"NOT",3)) {
1.1 root 123: not=1;
124: i+=2;
1.1.1.2 ! root 125: continue;
! 126: }
1.1 root 127:
1.1.1.2 ! root 128: if(n==2 && equal && !strnicmp(p,"TO",2)) { /* EQUAL TO */
! 129: i++;
! 130: continue;
! 131: }
1.1 root 132:
1.1.1.2 ! root 133: if(n==5 && !strnicmp(p,"EQUAL",5)) {
1.1 root 134: equal=1;
135: i+=4;
1.1.1.2 ! root 136: continue;
! 137: }
1.1 root 138:
1.1.1.2 ! root 139: if(n==6 && !strnicmp(p,"EQUALS",6)) {
1.1 root 140: equal=1;
141: i+=5;
1.1.1.2 ! root 142: continue;
! 143: }
! 144: }
1.1 root 145:
146: if(str[i]=='$') {
1.1.1.2 ! root 147: arg_expected=TRUE;
! 148: switch((ch=toupper(str[++i]))) {
1.1 root 149: case 'A':
150: artype=AR_AGE;
151: break;
152: case 'B':
153: artype=AR_BPS;
154: break;
155: case 'C':
156: artype=AR_CREDIT;
157: break;
158: case 'D':
159: artype=AR_UDFR;
160: break;
161: case 'E':
162: artype=AR_EXPIRE;
163: break;
164: case 'F':
165: artype=AR_FLAG1;
166: break;
167: case 'H':
168: artype=AR_SUB;
169: break;
170: case 'I':
171: artype=AR_LIB;
172: break;
173: case 'J':
174: artype=AR_DIR;
175: break;
176: case 'K':
177: artype=AR_UDR;
178: break;
179: case 'L':
180: artype=AR_LEVEL;
181: break;
182: case 'M':
183: artype=AR_GROUP;
184: break;
185: case 'N':
186: artype=AR_NODE;
187: break;
188: case 'O':
189: artype=AR_TUSED;
190: break;
191: case 'P':
192: artype=AR_PCR;
193: break;
194: case 'Q':
195: artype=AR_RANDOM;
196: break;
197: case 'R':
198: artype=AR_TLEFT;
199: break;
200: case 'S':
201: artype=AR_SEX;
202: break;
203: case 'T':
204: artype=AR_TIME;
205: break;
206: case 'U':
207: artype=AR_USER;
208: break;
209: case 'V':
210: artype=AR_LOGONS;
211: break;
212: case 'W':
213: artype=AR_DAY;
214: break;
215: case 'X':
216: artype=AR_EXEMPT;
217: break;
218: case 'Y': /* Days since last on */
219: artype=AR_LASTON;
220: break;
221: case 'Z':
222: artype=AR_REST;
1.1.1.2 ! root 223: /* Boolean (no argument) symbols */
1.1 root 224: case '0':
1.1.1.2 ! root 225: case 'G':
1.1 root 226: case '*':
1.1.1.2 ! root 227: case '[':
! 228: switch(ch) {
! 229: case '0':
! 230: artype=AR_NULL;
! 231: break;
! 232: case 'G':
! 233: artype=AR_LOCAL;
! 234: break;
! 235: case '*':
! 236: artype=AR_RIP;
! 237: break;
! 238: case '[':
! 239: artype=AR_ANSI;
! 240: break;
! 241: }
1.1 root 242: if(not)
243: ar[j++]=AR_NOT;
244: not=0;
245: ar[j++]=artype;
1.1.1.2 ! root 246: artype=AR_INVALID;
! 247: arg_expected=FALSE;
1.1 root 248: break;
1.1.1.2 ! root 249: }
! 250: continue;
! 251: }
1.1 root 252:
1.1.1.2 ! root 253: if(!arg_expected && isalpha(str[i])) {
1.1 root 254: n=i;
255: if(!strnicmp(str+i,"AGE",3)) {
256: artype=AR_AGE;
1.1.1.2 ! root 257: i+=2;
! 258: }
1.1 root 259: else if(!strnicmp(str+i,"BPS",3)) {
260: artype=AR_BPS;
1.1.1.2 ! root 261: i+=2;
! 262: }
1.1 root 263: else if(!strnicmp(str+i,"PCR",3)) {
264: artype=AR_PCR;
1.1.1.2 ! root 265: i+=2;
! 266: }
1.1 root 267: else if(!strnicmp(str+i,"SEX",3)) {
268: artype=AR_SEX;
1.1.1.2 ! root 269: i+=2;
! 270: }
1.1 root 271: else if(!strnicmp(str+i,"UDR",3)) {
272: artype=AR_UDR;
1.1.1.2 ! root 273: i+=2;
! 274: }
! 275: else if(!strnicmp(str+i,"ULS",3)) {
! 276: artype=AR_ULS;
! 277: i+=2;
! 278: }
! 279: else if(!strnicmp(str+i,"ULK",3)) {
! 280: artype=AR_ULK;
! 281: i+=2;
! 282: }
! 283: else if(!strnicmp(str+i,"ULM",3)) {
! 284: artype=AR_ULM;
! 285: i+=2;
! 286: }
! 287: else if(!strnicmp(str+i,"DLS",3)) {
! 288: artype=AR_DLS;
! 289: i+=2;
! 290: }
! 291: else if(!strnicmp(str+i,"DLK",3)) {
! 292: artype=AR_DLK;
! 293: i+=2;
! 294: }
! 295: else if(!strnicmp(str+i,"DLM",3)) {
! 296: artype=AR_DLM;
! 297: i+=2;
! 298: }
1.1 root 299: else if(!strnicmp(str+i,"DAY",3)) {
300: artype=AR_DAY;
1.1.1.2 ! root 301: i+=2;
! 302: }
1.1 root 303: else if(!strnicmp(str+i,"RIP",3)) {
304: artype=AR_RIP;
1.1.1.2 ! root 305: i+=2;
! 306: }
1.1 root 307: else if(!strnicmp(str+i,"WIP",3)) {
308: artype=AR_WIP;
1.1.1.2 ! root 309: i+=2;
! 310: }
1.1 root 311: else if(!strnicmp(str+i,"OS2",3)) {
312: artype=AR_OS2;
1.1.1.2 ! root 313: i+=2;
! 314: }
1.1 root 315: else if(!strnicmp(str+i,"DOS",3)) {
316: artype=AR_DOS;
1.1.1.2 ! root 317: i+=2;
! 318: }
1.1 root 319: else if(!strnicmp(str+i,"WIN32",5)) {
320: artype=AR_WIN32;
1.1.1.2 ! root 321: i+=4;
! 322: }
1.1 root 323: else if(!strnicmp(str+i,"UNIX",4)) {
324: artype=AR_UNIX;
1.1.1.2 ! root 325: i+=3;
! 326: }
1.1 root 327: else if(!strnicmp(str+i,"LINUX",5)) {
328: artype=AR_LINUX;
1.1.1.2 ! root 329: i+=4;
! 330: }
1.1 root 331: else if(!strnicmp(str+i,"PROT",4)) {
332: artype=AR_PROT;
1.1.1.2 ! root 333: i+=3;
! 334: }
! 335: else if(!strnicmp(str+i,"HOST",4)) {
! 336: artype=AR_HOST;
! 337: i+=3;
! 338: }
! 339: else if(!strnicmp(str+i,"IP",2)) {
! 340: artype=AR_IP;
! 341: i++;
! 342: }
1.1 root 343: else if(!strnicmp(str+i,"SUBCODE",7)) {
344: artype=AR_SUBCODE;
1.1.1.2 ! root 345: i+=6;
! 346: }
1.1 root 347: else if(!strnicmp(str+i,"SUB",3)) {
348: artype=AR_SUB;
1.1.1.2 ! root 349: i+=2;
! 350: }
1.1 root 351: else if(!strnicmp(str+i,"LIB",3)) {
352: artype=AR_LIB;
1.1.1.2 ! root 353: i+=2;
! 354: }
1.1 root 355: else if(!strnicmp(str+i,"DIRCODE",7)) {
356: artype=AR_DIRCODE;
1.1.1.2 ! root 357: i+=6;
! 358: }
1.1 root 359: else if(!strnicmp(str+i,"DIR",3)) {
360: artype=AR_DIR;
1.1.1.2 ! root 361: i+=2;
! 362: }
1.1 root 363: else if(!strnicmp(str+i,"ANSI",4)) {
364: artype=AR_ANSI;
1.1.1.2 ! root 365: i+=3;
! 366: }
1.1 root 367: else if(!strnicmp(str+i,"UDFR",4)) {
368: artype=AR_UDFR;
1.1.1.2 ! root 369: i+=3;
! 370: }
1.1 root 371: else if(!strnicmp(str+i,"FLAG",4)) {
372: artype=AR_FLAG1;
1.1.1.2 ! root 373: i+=3;
! 374: }
1.1 root 375: else if(!strnicmp(str+i,"NODE",4)) {
376: artype=AR_NODE;
1.1.1.2 ! root 377: i+=3;
! 378: }
1.1 root 379: else if(!strnicmp(str+i,"NULL",4)) {
380: artype=AR_NULL;
1.1.1.2 ! root 381: i+=3;
! 382: }
1.1 root 383: else if(!strnicmp(str+i,"USER",4)) {
384: artype=AR_USER;
1.1.1.2 ! root 385: i+=3;
! 386: }
1.1 root 387: else if(!strnicmp(str+i,"TIME",4)) {
388: artype=AR_TIME;
1.1.1.2 ! root 389: i+=3;
! 390: }
1.1 root 391: else if(!strnicmp(str+i,"REST",4)) {
392: artype=AR_REST;
1.1.1.2 ! root 393: i+=3;
! 394: }
1.1 root 395: else if(!strnicmp(str+i,"LEVEL",5)) {
396: artype=AR_LEVEL;
1.1.1.2 ! root 397: i+=4;
! 398: }
1.1 root 399: else if(!strnicmp(str+i,"TLEFT",5)) {
400: artype=AR_TLEFT;
1.1.1.2 ! root 401: i+=4;
! 402: }
1.1 root 403: else if(!strnicmp(str+i,"TUSED",5)) {
404: artype=AR_TUSED;
1.1.1.2 ! root 405: i+=4;
! 406: }
1.1 root 407: else if(!strnicmp(str+i,"LOCAL",5)) {
408: artype=AR_LOCAL;
1.1.1.2 ! root 409: i+=4;
! 410: }
1.1 root 411: else if(!strnicmp(str+i,"GROUP",5)) {
412: artype=AR_GROUP;
1.1.1.2 ! root 413: i+=4;
! 414: }
1.1 root 415: else if(!strnicmp(str+i,"EXPIRE",6)) {
416: artype=AR_EXPIRE;
1.1.1.2 ! root 417: i+=5;
! 418: }
1.1 root 419: else if(!strnicmp(str+i,"ACTIVE",6)) {
420: artype=AR_ACTIVE;
1.1.1.2 ! root 421: i+=5;
! 422: }
1.1 root 423: else if(!strnicmp(str+i,"INACTIVE",8)) {
424: artype=AR_INACTIVE;
1.1.1.2 ! root 425: i+=7;
! 426: }
1.1 root 427: else if(!strnicmp(str+i,"DELETED",7)) {
428: artype=AR_DELETED;
1.1.1.2 ! root 429: i+=6;
! 430: }
1.1 root 431: else if(!strnicmp(str+i,"EXPERT",6)) {
432: artype=AR_EXPERT;
1.1.1.2 ! root 433: i+=5;
! 434: }
1.1 root 435: else if(!strnicmp(str+i,"SYSOP",5)) {
436: artype=AR_SYSOP;
1.1.1.2 ! root 437: i+=4;
! 438: }
1.1 root 439: else if(!strnicmp(str+i,"GUEST",5)) {
440: artype=AR_GUEST;
1.1.1.2 ! root 441: i+=4;
! 442: }
1.1 root 443: else if(!strnicmp(str+i,"QNODE",5)) {
444: artype=AR_QNODE;
1.1.1.2 ! root 445: i+=4;
! 446: }
1.1 root 447: else if(!strnicmp(str+i,"QUIET",5)) {
448: artype=AR_QUIET;
1.1.1.2 ! root 449: i+=4;
! 450: }
1.1 root 451: else if(!strnicmp(str+i,"EXEMPT",6)) {
452: artype=AR_EXEMPT;
1.1.1.2 ! root 453: i+=5;
! 454: }
1.1 root 455: else if(!strnicmp(str+i,"RANDOM",6)) {
456: artype=AR_RANDOM;
1.1.1.2 ! root 457: i+=5;
! 458: }
1.1 root 459: else if(!strnicmp(str+i,"LASTON",6)) {
460: artype=AR_LASTON;
1.1.1.2 ! root 461: i+=5;
! 462: }
1.1 root 463: else if(!strnicmp(str+i,"LOGONS",6)) {
464: artype=AR_LOGONS;
1.1.1.2 ! root 465: i+=5;
! 466: }
1.1 root 467: else if(!strnicmp(str+i,"CREDIT",6)) {
468: artype=AR_CREDIT;
1.1.1.2 ! root 469: i+=5;
! 470: }
1.1 root 471: else if(!strnicmp(str+i,"MAIN_CMDS",9)) {
472: artype=AR_MAIN_CMDS;
1.1.1.2 ! root 473: i+=8;
! 474: }
1.1 root 475: else if(!strnicmp(str+i,"FILE_CMDS",9)) {
476: artype=AR_FILE_CMDS;
1.1.1.2 ! root 477: i+=8;
! 478: }
1.1 root 479: else if(!strnicmp(str+i,"SHELL",5)) {
480: artype=AR_SHELL;
1.1.1.2 ! root 481: i+=4;
! 482: }
! 483:
! 484: if(n!=i) /* one of the above */
! 485: {
! 486: arg_expected=TRUE;
! 487: switch(artype) {
! 488: case AR_RIP:
! 489: case AR_WIP:
! 490: case AR_ANSI:
! 491: case AR_DOS:
! 492: case AR_OS2:
! 493: case AR_UNIX:
! 494: case AR_LINUX:
! 495: case AR_WIN32:
! 496: case AR_LOCAL:
! 497: case AR_ACTIVE:
! 498: case AR_INACTIVE:
! 499: case AR_DELETED:
! 500: case AR_EXPERT:
! 501: case AR_SYSOP:
! 502: case AR_GUEST:
! 503: case AR_QNODE:
! 504: case AR_QUIET:
! 505: /* Boolean (No arguments) */
! 506: if(not)
! 507: ar[j++]=AR_NOT;
! 508: not=0;
! 509: ar[j++]=artype;
! 510: artype=AR_INVALID;
! 511: arg_expected=FALSE;
! 512: break;
! 513: }
1.1 root 514: continue;
1.1.1.2 ! root 515: }
1.1 root 516: }
517: if(not)
518: ar[j++]=AR_NOT;
1.1.1.2 ! root 519: if(equal && !ar_string_arg(artype))
1.1 root 520: ar[j++]=AR_EQUAL;
521: not=equal=0;
522:
523: if(artype==AR_FLAG1 && isdigit(str[i])) { /* flag set specified */
524: switch(str[i]) {
525: case '2':
526: artype=AR_FLAG2;
527: break;
528: case '3':
529: artype=AR_FLAG3;
530: break;
531: case '4':
532: artype=AR_FLAG4;
1.1.1.2 ! root 533: break;
! 534: }
! 535: continue;
! 536: }
! 537:
! 538: arg_expected=FALSE;
1.1 root 539:
540: if(artype==AR_SUB && !isdigit(str[i]))
541: artype=AR_SUBCODE;
542: if(artype==AR_DIR && !isdigit(str[i]))
543: artype=AR_DIRCODE;
544:
1.1.1.2 ! root 545: if(artype==AR_INVALID)
! 546: artype=AR_LEVEL;
1.1 root 547: ar[j++]=artype;
1.1.1.2 ! root 548: if(isdigit(str[i]) && !ar_string_arg(artype)) {
1.1 root 549: if(artype==AR_TIME) {
550: n=atoi(str+i)*60;
551: p=strchr(str+i,':');
552: if(p)
553: n+=atoi(p+1);
554: *((short *)(ar+j))=n;
555: j+=2;
556: while(isdigit(str[i+1]) || str[i+1]==':') i++;
1.1.1.2 ! root 557: continue;
! 558: }
1.1 root 559: n=atoi(str+i);
560: switch(artype) {
561: case AR_DAY:
562: if(n>6) /* not past saturday */
563: n=6;
564: case AR_AGE: /* byte operands */
565: case AR_PCR:
566: case AR_UDR:
567: case AR_UDFR:
568: case AR_NODE:
569: case AR_LEVEL:
570: case AR_TLEFT:
571: case AR_TUSED:
572: ar[j++]=n;
573: break;
574: case AR_BPS: /* int operands */
575: if(n<300)
576: n*=100;
577: case AR_MAIN_CMDS:
578: case AR_FILE_CMDS:
579: case AR_EXPIRE:
580: case AR_CREDIT:
581: case AR_USER:
582: case AR_RANDOM:
583: case AR_LASTON:
584: case AR_LOGONS:
1.1.1.2 ! root 585: case AR_ULS:
! 586: case AR_ULK:
! 587: case AR_ULM:
! 588: case AR_DLS:
! 589: case AR_DLK:
! 590: case AR_DLM:
1.1 root 591: *((short *)(ar+j))=n;
1.1.1.2 ! root 592: j+=sizeof(short);
1.1 root 593: break;
594: case AR_GROUP:
595: case AR_LIB:
596: case AR_DIR:
597: case AR_SUB:
598: if(n) n--; /* convert to 0 base */
599: *((short *)(ar+j))=n;
600: j+=2;
601: break;
602: default: /* invalid numeric AR type */
603: j--;
1.1.1.2 ! root 604: break;
! 605: }
1.1 root 606: while(isdigit(str[i+1])) i++;
607: continue;
608: }
1.1.1.2 ! root 609: maxlen=128;
1.1 root 610: switch(artype) {
1.1.1.2 ! root 611: case AR_SUBCODE:
! 612: case AR_DIRCODE:
! 613: case AR_SHELL:
! 614: maxlen=LEN_EXTCODE;
! 615: case AR_PROT:
! 616: case AR_HOST:
! 617: case AR_IP:
! 618: /* String argument */
! 619: for(n=0;n<maxlen
! 620: && str[i]
! 621: && str[i]!=' '
! 622: && str[i]!='('
! 623: && str[i]!=')'
! 624: && str[i]!='='
! 625: && str[i]!='|'
! 626: && str[i]!='&'
! 627: ;n++)
! 628: ar[j++]=toupper(str[i++]);
! 629: ar[j++]=0;
! 630: i--;
! 631: break;
1.1 root 632: case AR_FLAG1:
633: case AR_FLAG2:
634: case AR_FLAG3:
635: case AR_FLAG4:
636: case AR_EXEMPT:
637: case AR_SEX:
638: case AR_REST:
639: ar[j++]=toupper(str[i]);
640: break;
641: case AR_SUB:
1.1.1.2 ! root 642: for(n=0;n<(uint)cfg->total_subs;n++)
1.1 root 643: if(!strnicmp(str+i,cfg->sub[n]->code,strlen(cfg->sub[n]->code)))
644: break;
1.1.1.2 ! root 645: if(n<(uint)cfg->total_subs) {
1.1 root 646: *((short *)(ar+j))=n;
1.1.1.2 ! root 647: j+=2;
! 648: }
1.1 root 649: else /* Unknown sub-board */
650: j--;
651: while(isalpha(str[i+1])) i++;
652: break;
653: case AR_DIR:
1.1.1.2 ! root 654: for(n=0;n<(uint)cfg->total_dirs;n++)
1.1 root 655: if(!strnicmp(str+i,cfg->dir[n]->code,strlen(cfg->dir[n]->code)))
656: break;
1.1.1.2 ! root 657: if(n<(uint)cfg->total_dirs) {
1.1 root 658: *((short *)(ar+j))=n;
1.1.1.2 ! root 659: j+=2;
! 660: }
1.1 root 661: else /* Unknown directory */
662: j--;
663: while(isalpha(str[i+1])) i++;
664: break;
665: case AR_DAY:
666: if(toupper(str[i])=='S'
667: && toupper(str[i+1])=='U') /* Sunday */
668: ar[j++]=0;
669: else if(toupper(str[i])=='M') /* Monday */
670: ar[j++]=1;
671: else if(toupper(str[i])=='T'
672: && toupper(str[i+1])=='U') /* Tuesday */
673: ar[j++]=2;
674: else if(toupper(str[i])=='W') /* Wednesday */
675: ar[j++]=3;
676: else if(toupper(str[i])=='T'
677: && toupper(str[i+1])=='H') /* Thursday */
678: ar[j++]=4;
679: else if(toupper(str[i])=='F') /* Friday */
680: ar[j++]=5;
681: else ar[j++]=6; /* Saturday */
682: while(isalpha(str[i+1])) i++;
683: break;
684: default: /* Badly formed ARS, digit expected */
685: j--;
686: break;
687: }
688: }
689: if(!j)
690: return((uchar*)nular); /* Save memory */
691:
692: ar[j++]=AR_NULL;
693: /** DEBUG stuff
694: for(i=0;i<j;i++)
1.1.1.2 ! root 695: lprintf(LOG_DEBUG,"%02X ",(uint)ar[i]);
1.1 root 696: lputs("\r\n");
697: ***/
698: if((ar_buf=(uchar *)calloc(j+4,1))==NULL) /* Padded for ushort dereferencing */
699: return(NULL);
700: memcpy(ar_buf,ar,j);
701: if(count)
702: (*count)=j;
703: return(ar_buf);
704: }
705:
1.1.1.2 ! root 706: #ifdef ARS_VERIFY /* Verification for arstr() */
! 707:
! 708: char *decompile_ars(uchar *ars, int len)
! 709: {
! 710: static char buf[1024];
! 711: char *out;
! 712: uchar *in;
! 713: uint n;
! 714: int equals=0;
! 715: int not=0;
! 716:
! 717: out=buf;
! 718: buf[0]=0;
! 719: for(in=ars;in<ars+len;in++) {
! 720: switch(*in) {
! 721: case AR_NULL:
! 722: break;
! 723: case AR_OR:
! 724: *(out++)='|';
! 725:
! 726: break;
! 727: case AR_NOT:
! 728: not=1;
! 729: break;
! 730: case AR_EQUAL:
! 731: equals=1;
! 732: break;
! 733: case AR_BEGNEST:
! 734: if(not)
! 735: *(out++)='!';
! 736: not=0;
! 737: *(out++)='(';
! 738:
! 739: break;
! 740: case AR_ENDNEST:
! 741: *(out++)=')';
! 742:
! 743: break;
! 744: case AR_LEVEL:
! 745: *(out++)='$';
! 746: *(out++)='L';
! 747:
! 748: break;
! 749: case AR_AGE:
! 750: *(out++)='$';
! 751: *(out++)='A';
! 752:
! 753: break;
! 754: case AR_BPS:
! 755: *(out++)='$';
! 756: *(out++)='B';
! 757:
! 758: break;
! 759: case AR_NODE:
! 760: *(out++)='$';
! 761: *(out++)='N';
! 762:
! 763: break;
! 764: case AR_TLEFT:
! 765: *(out++)='$';
! 766: *(out++)='R';
! 767:
! 768: break;
! 769: case AR_TUSED:
! 770: *(out++)='$';
! 771: *(out++)='O';
! 772:
! 773: break;
! 774: case AR_USER:
! 775: *(out++)='$';
! 776: *(out++)='U';
! 777:
! 778: break;
! 779: case AR_TIME:
! 780: *(out++)='$';
! 781: *(out++)='T';
! 782:
! 783: break;
! 784: case AR_PCR:
! 785: *(out++)='$';
! 786: *(out++)='P';
! 787:
! 788: break;
! 789: case AR_FLAG1:
! 790: *(out++)='$';
! 791: *(out++)='F';
! 792: *(out++)='1';
! 793:
! 794: break;
! 795: case AR_FLAG2:
! 796: *(out++)='$';
! 797: *(out++)='F';
! 798: *(out++)='2';
! 799:
! 800: break;
! 801: case AR_FLAG3:
! 802: *(out++)='$';
! 803: *(out++)='F';
! 804: *(out++)='3';
! 805:
! 806: break;
! 807: case AR_FLAG4:
! 808: *(out++)='$';
! 809: *(out++)='F';
! 810: *(out++)='4';
! 811:
! 812: break;
! 813: case AR_EXEMPT:
! 814: *(out++)='$';
! 815: *(out++)='X';
! 816:
! 817: break;
! 818: case AR_REST:
! 819: *(out++)='$';
! 820: *(out++)='Z';
! 821:
! 822: break;
! 823: case AR_SEX:
! 824: *(out++)='$';
! 825: *(out++)='S';
! 826:
! 827: break;
! 828: case AR_UDR:
! 829: *(out++)='$';
! 830: *(out++)='K';
! 831:
! 832: break;
! 833: case AR_UDFR:
! 834: *(out++)='$';
! 835: *(out++)='D';
! 836:
! 837: break;
! 838: case AR_EXPIRE:
! 839: *(out++)='$';
! 840: *(out++)='E';
! 841:
! 842: break;
! 843: case AR_CREDIT:
! 844: *(out++)='$';
! 845: *(out++)='C';
! 846:
! 847: break;
! 848: case AR_DAY:
! 849: *(out++)='$';
! 850: *(out++)='W';
! 851:
! 852: break;
! 853: case AR_ANSI:
! 854: if(not)
! 855: *(out++)='!';
! 856: not=0;
! 857: *(out++)='$';
! 858: *(out++)='[';
! 859:
! 860: break;
! 861: case AR_RIP:
! 862: if(not)
! 863: *(out++)='!';
! 864: not=0;
! 865: *(out++)='$';
! 866: *(out++)='*';
! 867:
! 868: break;
! 869: case AR_LOCAL:
! 870: if(not)
! 871: *(out++)='!';
! 872: not=0;
! 873: *(out++)='$';
! 874: *(out++)='G';
! 875:
! 876: break;
! 877: case AR_GROUP:
! 878: *(out++)='$';
! 879: *(out++)='M';
! 880:
! 881: break;
! 882: case AR_SUB:
! 883: *(out++)='$';
! 884: *(out++)='H';
! 885:
! 886: break;
! 887: case AR_LIB:
! 888: *(out++)='$';
! 889: *(out++)='I';
! 890:
! 891: break;
! 892: case AR_DIR:
! 893: *(out++)='$';
! 894: *(out++)='J';
! 895:
! 896: break;
! 897: case AR_EXPERT :
! 898: if(not)
! 899: *(out++)='!';
! 900: not=0;
! 901: *out=0;
! 902: strcat(out,"EXPERT");
! 903: out=strchr(out,0);
! 904:
! 905: break;
! 906: case AR_SYSOP:
! 907: if(not)
! 908: *(out++)='!';
! 909: not=0;
! 910: *out=0;
! 911: strcat(out,"SYSOP");
! 912: out=strchr(out,0);
! 913:
! 914: break;
! 915: case AR_QUIET:
! 916: if(not)
! 917: *(out++)='!';
! 918: not=0;
! 919: *out=0;
! 920: strcat(out,"QUIET");
! 921: out=strchr(out,0);
! 922:
! 923: break;
! 924: case AR_MAIN_CMDS:
! 925: *out=0;
! 926: strcat(out,"MAIN_CMDS");
! 927: out=strchr(out,0);
! 928:
! 929: break;
! 930: case AR_FILE_CMDS:
! 931: *out=0;
! 932: strcat(out,"FILE_CMDS");
! 933: out=strchr(out,0);
! 934:
! 935: break;
! 936: case AR_RANDOM:
! 937: *(out++)='$';
! 938: *(out++)='Q';
! 939:
! 940: break;
! 941: case AR_LASTON:
! 942: *(out++)='$';
! 943: *(out++)='Y';
! 944:
! 945: break;
! 946: case AR_LOGONS:
! 947: *(out++)='$';
! 948: *(out++)='V';
! 949:
! 950: break;
! 951: case AR_WIP:
! 952: if(not)
! 953: *(out++)='!';
! 954: not=0;
! 955: *out=0;
! 956: strcat(out,"WIP");
! 957: out=strchr(out,0);
! 958:
! 959: break;
! 960: case AR_SUBCODE:
! 961: *out=0;
! 962: strcat(out,"SUB ");
! 963: out=strchr(out,0);
! 964:
! 965: break;
! 966: case AR_DIRCODE:
! 967: *out=0;
! 968: strcat(out,"DIR ");
! 969: out=strchr(out,0);
! 970:
! 971: break;
! 972: case AR_OS2:
! 973: if(not)
! 974: *(out++)='!';
! 975: not=0;
! 976: *out=0;
! 977: strcat(out,"OS2");
! 978: out=strchr(out,0);
! 979:
! 980: break;
! 981: case AR_DOS:
! 982: if(not)
! 983: *(out++)='!';
! 984: not=0;
! 985: *out=0;
! 986: strcat(out,"DOS");
! 987: out=strchr(out,0);
! 988:
! 989: break;
! 990: case AR_WIN32:
! 991: if(not)
! 992: *(out++)='!';
! 993: not=0;
! 994: *out=0;
! 995: strcat(out,"WIN32");
! 996: out=strchr(out,0);
! 997:
! 998: break;
! 999: case AR_UNIX:
! 1000: if(not)
! 1001: *(out++)='!';
! 1002: not=0;
! 1003: *out=0;
! 1004: strcat(out,"UNIX");
! 1005: out=strchr(out,0);
! 1006:
! 1007: break;
! 1008: case AR_LINUX :
! 1009: if(not)
! 1010: *(out++)='!';
! 1011: not=0;
! 1012: *out=0;
! 1013: strcat(out,"LINUX");
! 1014: out=strchr(out,0);
! 1015:
! 1016: break;
! 1017: case AR_SHELL:
! 1018: *out=0;
! 1019: strcat(out,"SHELL ");
! 1020: out=strchr(out,0);
! 1021:
! 1022: break;
! 1023: case AR_PROT:
! 1024: *out=0;
! 1025: strcat(out,"PROT ");
! 1026: out=strchr(out,0);
! 1027:
! 1028: break;
! 1029: case AR_HOST:
! 1030: *out=0;
! 1031: strcat(out,"HOST ");
! 1032: out=strchr(out,0);
! 1033:
! 1034: break;
! 1035: case AR_IP:
! 1036: *out=0;
! 1037: strcat(out,"IP ");
! 1038: out=strchr(out,0);
! 1039:
! 1040: break;
! 1041: case AR_GUEST:
! 1042: if(not)
! 1043: *(out++)='!';
! 1044: not=0;
! 1045: *out=0;
! 1046: strcat(out,"GUEST");
! 1047: out=strchr(out,0);
! 1048:
! 1049: break;
! 1050: case AR_QNODE:
! 1051: if(not)
! 1052: *(out++)='!';
! 1053: not=0;
! 1054: *out=0;
! 1055: strcat(out,"QNODE");
! 1056: out=strchr(out,0);
! 1057:
! 1058: break;
! 1059: default:
! 1060: printf("Error decoding AR: %02Xh, offset: %u\n", *in, in-ars);
! 1061: return("Unknown ARS String");
! 1062: }
! 1063: switch(*in) {
! 1064: case AR_TIME:
! 1065: if(not)
! 1066: *(out++)='!';
! 1067: if(equals)
! 1068: *(out++)='=';
! 1069: not=equals=0;
! 1070: in++;
! 1071: n=*((short *)in);
! 1072: in++;
! 1073: out+=sprintf(out,"%02d:%02d",n/60,n%60);
! 1074: break;
! 1075: case AR_AGE: /* byte operands */
! 1076: case AR_PCR:
! 1077: case AR_UDR:
! 1078: case AR_UDFR:
! 1079: case AR_NODE:
! 1080: case AR_LEVEL:
! 1081: case AR_TLEFT:
! 1082: case AR_TUSED:
! 1083: if(not)
! 1084: *(out++)='!';
! 1085: if(equals)
! 1086: *(out++)='=';
! 1087: not=equals=0;
! 1088: in++;
! 1089: out+=sprintf(out,"%d",*in);
! 1090: break;
! 1091: case AR_BPS: /* int operands */
! 1092: case AR_MAIN_CMDS:
! 1093: case AR_FILE_CMDS:
! 1094: case AR_EXPIRE:
! 1095: case AR_CREDIT:
! 1096: case AR_USER:
! 1097: case AR_RANDOM:
! 1098: case AR_LASTON:
! 1099: case AR_LOGONS:
! 1100: if(not)
! 1101: *(out++)='!';
! 1102: if(equals)
! 1103: *(out++)='=';
! 1104: not=equals=0;
! 1105: in++;
! 1106: n=*((short *)in);
! 1107: in++;
! 1108: out+=sprintf(out,"%d",n);
! 1109: break;
! 1110: case AR_GROUP:
! 1111: case AR_LIB:
! 1112: case AR_DIR:
! 1113: case AR_SUB:
! 1114: if(not)
! 1115: *(out++)='!';
! 1116: if(equals)
! 1117: *(out++)='=';
! 1118: not=equals=0;
! 1119: in++;
! 1120: n=*((short *)in);
! 1121: n++; /* convert from to 0 base */
! 1122: in++;
! 1123: out+=sprintf(out,"%d",n);
! 1124: break;
! 1125: case AR_SUBCODE:
! 1126: case AR_DIRCODE:
! 1127: case AR_SHELL:
! 1128: case AR_PROT:
! 1129: case AR_HOST:
! 1130: case AR_IP:
! 1131: if(not)
! 1132: *(out++)='!';
! 1133: if(equals)
! 1134: *(out++)='=';
! 1135: not=equals=0;
! 1136: in++;
! 1137: n=sprintf(out,"%s ",in);
! 1138: out+=n;
! 1139: in+=n-1;
! 1140: break;
! 1141: case AR_FLAG1:
! 1142: case AR_FLAG2:
! 1143: case AR_FLAG3:
! 1144: case AR_FLAG4:
! 1145: case AR_EXEMPT:
! 1146: case AR_SEX:
! 1147: case AR_REST:
! 1148: if(not)
! 1149: *(out++)='!';
! 1150: if(equals)
! 1151: *(out++)='=';
! 1152: not=equals=0;
! 1153: in++;
! 1154: *(out++)=*in;
! 1155: break;
! 1156: }
! 1157: }
! 1158: *out=0;
! 1159: return(buf);
! 1160: }
! 1161:
! 1162: void main(void)
! 1163: {
! 1164: char* example[] =
! 1165: {
! 1166: "LEVEL 60"
! 1167: ,"LEVEL60"
! 1168: ,"$L60"
! 1169: ,"60"
! 1170: ,"NOT LEVEL 60"
! 1171: ,"LEVEL NOT 60"
! 1172: ,"LEVEL !60"
! 1173: ,"$L!60"
! 1174: ,"!60"
! 1175: ,"LEVEL EQUAL 60"
! 1176: ,"LEVEL EQUALS 60"
! 1177: ,"LEVEL EQUAL TO 60"
! 1178: ,"LEVEL = 60"
! 1179: ,"LEVEL=60"
! 1180: ,"=60"
! 1181: ,"LEVEL 60 AND FLAG 1A"
! 1182: ,"LEVEL 60 FLAG 1A"
! 1183: ,"LEVEL 60 AND FLAG A"
! 1184: ,"LEVEL 60 AND FLAG1 A"
! 1185: ,"LEVEL 60 AND FLAG 1 A"
! 1186: ,"LEVEL 60 AND FLAG1A"
! 1187: ,"LEVEL 60 & $F A"
! 1188: ,"$L60 AND $FA"
! 1189: ,"$L60$FA"
! 1190: ,"60$FA"
! 1191: ,"SEX F OR LEVEL 90"
! 1192: ,"SEX F | LEVEL 90"
! 1193: ,"SEXF|LEVEL90"
! 1194: ,"$SF | $L90"
! 1195: ,"$SF|$L90"
! 1196: ,"USER NOT EQUAL TO 20"
! 1197: ,"$U!=20"
! 1198: ,"BPS 9600 OR NOT TIME 19:00"
! 1199: ,"BPS 9600 OR NOT TIME 19"
! 1200: ,"BPS 96 OR NOT TIME 19"
! 1201: ,"$B 9600 OR NOT $T19"
! 1202: ,"BPS9600|!TIME19"
! 1203: ,"$B96|!$T19"
! 1204: ,"BPS 9600 OR TIME NOT 18:00 OR TIME 21:30"
! 1205: ,"BPS 9600 OR TIME NOT 18:00 OR 21:30"
! 1206: ,"$B 9600 OR NOT $T 18 OR 21:30"
! 1207: ,"$B96|$T!18|21:30"
! 1208: ,"FLAG A OR FLAG B OR FLAG C OR LEVEL 90"
! 1209: ,"FLAG A OR B OR C OR LEVEL 90"
! 1210: ,"FLAG A|B|C OR LEVEL 90"
! 1211: ,"$FA|B|C|$L90"
! 1212: ,"USER EQUALS 145 OR LEVEL 90"
! 1213: ,"USER=145 OR LEVEL 90"
! 1214: ,"$U=145|$L90"
! 1215: ,"LEVEL 60 AND FLAG X AND FLAG Y AND FLAG Z"
! 1216: ,"LEVEL 60 AND FLAG X AND Y AND Z"
! 1217: ,"LEVEL 60 AND FLAG X Y Z"
! 1218: ,"LEVEL 60 FLAG XYZ"
! 1219: ,"LEVEL60 FLAGXYZ"
! 1220: ,"$L60 $FXYZ"
! 1221: ,"60$FXYZ"
! 1222: ,"FLAG 2A OR FLAG 2B OR FLAG 4Z"
! 1223: ,"FLAG 2A OR B OR FLAG 4Z"
! 1224: ,"FLAG 2A OR FLAG B OR FLAG 4Z" /* not the same as above and below */
! 1225: ,"FLAG2A|B OR FLAG4Z"
! 1226: ,"$F2A|B|$F4Z"
! 1227: ,"NOT FLAG 2G"
! 1228: ,"FLAG NOT 2G"
! 1229: ,"FLAG 2 NOT G"
! 1230: ,"!$F2G"
! 1231: ,"$F!2G"
! 1232: ,"$F2!G"
! 1233: ,"BPS 9600 OR (BPS 2400 AND TIME NOT 15:00)"
! 1234: ,"$B9600|($B2400$T!15)"
! 1235: ,"(SEX M AND AGE 21) OR (SEX F AND AGE 18)"
! 1236: ,"($SM$A21)|($SF$A18)"
! 1237: ,"AGE 21 OR (SEX F AND AGE 18)"
! 1238: ,"(BPS 2400 AND PCR 20) OR LEVEL 90"
! 1239: ,"(BPS 2400 AND PCR 20) OR 90"
! 1240: ,"($B 2400 $P 20) | $L 90"
! 1241: ,"($B2400$P20)|$L90"
! 1242: ,"NOT (USER=1 OR USER=20)"
! 1243: ,"NOT USER=1 AND NOT USER=20"
! 1244: ,"LEVEL 90 OR (TIME 12:00 AND TIME NOT 18:00)"
! 1245: ,"(TIME 12:00 AND TIME NOT 18:00) OR LEVEL 90"
! 1246: ,"(TIME 12:00 AND NOT 18:00) OR LEVEL 90"
! 1247: ,"($T12!18)|90"
! 1248: ,"PROT NOTIFY"
! 1249: ,"PROT NOT IFY"
! 1250: ,"PROT NOT NOTIFY"
! 1251: ,"NOT PROT NOTIFY"
! 1252: ,"HOST NOT SEXY"
! 1253: ,"HOST !*.YAHOO.COM"
! 1254: ,"FLAGA SEXY"
! 1255: ,"FLAGA SEX Y"
! 1256: ,"FLAGA AND SEX Y"
! 1257: ,"FLAG SEXY"
! 1258: ,"FLAG SEX2Y"
! 1259: ,"FLAG 2 SEXY"
! 1260: ,"FLAG2SEXY"
! 1261: ,"FLAG2ASEXY"
! 1262: ,"IP192.168.1.*"
! 1263: ,"HOST!=LOCALHOST&IP!=127.0.0.1"
! 1264: /* terminator */
! 1265: ,NULL
! 1266: };
! 1267: int i,j;
! 1268: uchar* ar;
! 1269: ushort cnt;
! 1270:
! 1271: for(i=0;example[i]!=NULL;i++) {
! 1272: printf("Example : %s\n", example[i]);
! 1273: ar=arstr(&cnt, example[i], NULL);
! 1274: printf("Compiled : ");
! 1275: for(j=0;j<cnt;j++)
! 1276: printf("%02X ",ar[j]);
! 1277: printf("\n");
! 1278: printf("Decompiled: %s\n\n", decompile_ars(ar,cnt));
! 1279: }
! 1280: }
! 1281:
! 1282: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.