1 /* 2 By accepting this notice, you agree to be bound by the following 3 agreements: 4 5 This software product, squidGuard, is copyrighted (C) 1998-2008 6 by Christine Kronberg, Shalla Secure Services. All rights reserved. 7 8 This program is free software; you can redistribute it and/or modify it 9 under the terms of the GNU General Public License (version 2) as 10 published by the Free Software Foundation. It is distributed in the 11 hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 PURPOSE. See the GNU General Public License (GPL) for more details. 14 15 You should have received a copy of the GNU General Public License 16 (GPL) along with this program. 17 */ 18 19 %{ 20 21 #include "y.tab.h" 22 #include "sg.h" 23 24 %} 25 26 ignore [,\t\r ]+ 27 s [\t ] 28 d [0-9] 29 ip {d}{1,3}\.{d}{1,3}\.{d}{1,3}\.{d}{1,3} 30 tval {d}{d}[:]{d}{d} 31 dval {d}{d}{d}{d}[\.-]{d}{d}[\.-]{d}{d} 32 dvalcron ({d}{d}{d}{d}|[\*])[\.-]({d}{d}|[\*])[\.-]({d}{d}|[\*]) 33 weekday (mon|mondays?|tue|tuesdays?|wed|wednesdays?|thu|thursdays?|fri|fridays?|sat|saturdays?|sun|sundays?) 34 weekdays (({weekday}{s}*[, \t]+{s}*)*{weekday})|[\*] 35 36 /* from RFC1779: 37 38 <name> ::= <name-component> ( <spaced-separator> ) 39 | <name-component> <spaced-separator> <name> 40 41 <spaced-separator> ::= <optional-space> 42 <separator> 43 <optional-space> 44 45 <separator> ::= "," | ";" 46 47 <optional-space> ::= ( <CR> ) *( " " ) 48 49 <name-component> ::= <attribute> 50 | <attribute> <optional-space> "+" 51 <optional-space> <name-component> 52 53 <attribute> ::= <string> 54 | <key> <optional-space> "=" <optional-space> <string> 55 56 <key> ::= 1*( <keychar> ) | "OID." <oid> | "oid." <oid> 57 <keychar> ::= letters, numbers, and space 58 59 <oid> ::= <digitstring> | <digitstring> "." <oid> 60 <digitstring> ::= 1*<digit> 61 <digit> ::= digits 0-9 62 63 <string> ::= *( <stringchar> | <pair> ) 64 | '"' *( <stringchar> | <special> | <pair> ) '"' 65 | "#" <hex> 66 67 <special> ::= "," | "=" | <CR> | "+" | "<" | ">" 68 | "#" | ";" 69 70 <pair> ::= "\" ( <special> | "\" | '"') 71 <stringchar> ::= any character except <special> or "\" or '"' 72 73 <hex> ::= 2*<hexchar> 74 <hexchar> ::= 0-9, a-f, A-F 75 */ 76 77 ldaphexchar [0-9a-fA-f] 78 ldaphex {ldaphexchar}{ldaphexchar} 79 ldapspecial [,=+<>#;\r\n] 80 ldapstringchar [^,=+<>#;\r\n] 81 ldappair \\({ldapspecial}|\\|\") 82 ldapstring (({ldapstringchar}|{ldappair})*|\"({ldapstringchar}|{ldapspecial}|{ldappair})*\"|#{ldaphex}) 83 ldapkey [a-zA-Z0-9][a-zA-Z0-9 ]* 84 ldapattribute {ldapkey}{s}*={s}*{ldapstring} 85 ldapnamecomponent ({ldapattribute}{s}*+{s}*)*{ldapattribute} 86 ldapspacedseparator \ *[,;]\ * 87 ldapdn ({ldapnamecomponent}{ldapspacedseparator})*{ldapnamecomponent} 88 89 %x REDIRECT_STATE 90 %x EXEC_STATE 91 %x LDAPDN_STATE 92 93 %% 94 95 [ \t]*#.* ; 96 "{" return START_BRACKET; 97 "}" return STOP_BRACKET; 98 ^dest return DESTINATION; 99 ^destination return DESTINATION; 100 ^src return SOURCE; 101 ^source return SOURCE; 102 ^rew return REWRITE; 103 ^rewrite return REWRITE; 104 ^time return TIME; 105 ^acl return ACL; 106 ^dbhome return DBHOME; 107 ^logdir return LOGDIR; 108 ^ldapcachetime return LDAPCACHETIME; 109 ^ldapprotover return LDAPPROTOVER; 110 ^ldapbinddn { BEGIN LDAPDN_STATE; return LDAPBINDDN; } 111 ^ldapbindpass return LDAPBINDPASS; 112 ^mysqlusername return MYSQLUSERNAME; 113 ^mysqlpassword return MYSQLPASSWORD; 114 ^mysqldb return DATABASE; 115 domainlist return DOMAINLIST; 116 urllist return URLLIST; 117 expressionlist return EXPRESSIONLIST; 118 iplist return IPLIST; 119 user return USER; 120 userlist return USERLIST; 121 userquery { 122 BEGIN REDIRECT_STATE; 123 return USERQUERY; 124 } 125 ldapusersearch { 126 /* use the REDIRECT_STATE logic, since it handles URLs nicely */ 127 BEGIN REDIRECT_STATE; 128 return LDAPUSERSEARCH; 129 } 130 execuserlist { 131 BEGIN EXEC_STATE; 132 return EXECUSERLIST; 133 } 134 userquota return USERQUOTA; 135 domain return DOMAIN; 136 pass return PASS; 137 rewrite return REWRITE; 138 redirect { BEGIN REDIRECT_STATE; return REDIRECT; } 139 minutely return MINUTELY; 140 hourly return HOURLY; 141 daily return DAILY; 142 weekly return WEEKLY; 143 continuous return CONTINIOUS; 144 continue return CONTINUE; 145 sporadic return SPORADIC; 146 date return DATE; 147 anonymous return ANONYMOUS; 148 verbose return VERBOSE; 149 log return LOGFILE; 150 logfile return LOGFILE; 151 {weekdays} {yylval.string = yytext; return WEEKDAY;} 152 within return WITHIN; 153 outside return OUTSIDE; 154 else return ELSE; 155 ip return IP; 156 {ip} {yylval.string = yytext; return IPADDR;} 157 [/]{d}+ {yylval.string = yytext; return CIDR;} 158 [/]{ip} {yylval.string = yytext; return IPCLASS;} 159 {tval} {yylval.string = yytext; return TVAL;} 160 {dval} {yylval.string = yytext; return DVAL;} 161 {dvalcron} {yylval.string = yytext; return DVALCRON;} 162 {d}+ {yylval.string = yytext; return NUMBER;} 163 164 <REDIRECT_STATE>[a-zA-Z3\/][a-zA-Z0-9/_\-\.\,\(\)\/\:\%\+\?=&~!]* { yylval.string = yytext ; BEGIN 0; return WORD;} 165 <REDIRECT_STATE>[ \t]+ ; 166 <REDIRECT_STATE>\n {lineno++;} 167 <REDIRECT_STATE>. {return yytext[0];} 168 169 <EXEC_STATE>[^\n]* { yylval.string = yytext; BEGIN 0; return EXECCMD; } 170 <EXEC_STATE>\n {lineno++;} 171 172 <LDAPDN_STATE>{ldapdn} {yylval.string = yytext; BEGIN 0; return LDAPDNSTR;} 173 <LDAPDN_STATE>\n {lineno++;} 174 175 [a-zA-Z\/][a-zA-Z0-9/_\-\.\/\:\%\+\?=&]* {yylval.string = yytext ; return WORD;} 176 s@(([^@}]|\\@|\\\})+)@(([^@}]|\\@|\\\})+)@[girR]* {yylval.string = yytext; return SUBST;} 177 [ \t]+ ; 178 \n {lineno++;} 179 . {return yytext[0];} 180 181 182 %% 183 184