ssl_expr_scan.l revision 031b91a62d25106ae69d4693475c79618dd5e884
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff/* Licensed to the Apache Software Foundation (ASF) under one or more
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * contributor license agreements. See the NOTICE file distributed with
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * this work for additional information regarding copyright ownership.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * The ASF licenses this file to You under the Apache License, Version 2.0
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * (the "License"); you may not use this file except in compliance with
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * the License. You may obtain a copy of the License at
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff *
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * http://www.apache.org/licenses/LICENSE-2.0
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff *
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * Unless required by applicable law or agreed to in writing, software
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * distributed under the License is distributed on an "AS IS" BASIS,
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * See the License for the specific language governing permissions and
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff * limitations under the License.
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff */
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff/* _ _
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * _ __ ___ ___ __| | ___ ___| |
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * | '_ ` _ \ / _ \ / _` | / __/ __| |
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * | | | | | | (_) | (_| | \__ \__ \ | mod_ssl - Apache Interface to OpenSSL
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * |_| |_| |_|\___/ \__,_|___|___/___/_| http://www.modssl.org/
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff * |_____|
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * ssl_expr_scan.l
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * Expression Scanner
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /* ``Killing for peace is
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff like fucking for virginity.''
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff -- Unknown */
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff/* _________________________________________________________________
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff**
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff** Expression Scanner
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff** _________________________________________________________________
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff*/
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff%{
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff#include "ssl_private.h"
3024dbecbac365171bc6de0f3fa04951d6558be3Michael Graff
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff#include "ssl_expr_parse.h"
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff#define YY_NO_UNPUT 1
e45d323a2a0f4ca08d4b139546e60a5fa7bd3f0cMichael Graffint yyinput(char *buf, int max_size);
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graff
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff#undef YY_INPUT
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff#define YY_INPUT(buf,result,max_size) \
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff (result = yyinput(buf, max_size))
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff#define MAX_STR_LEN 2048
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff%}
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff
439c0011e642fb1d26011116144af698125262dbMichael Graff%pointer
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff/* %option stack */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff%option never-interactive
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff%option noyywrap
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff%x str
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff%x regex regex_flags
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff%%
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff char caStr[MAX_STR_LEN];
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff char *cpStr = NULL;
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff char caRegex[MAX_STR_LEN];
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff char *cpRegex = NULL;
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff char cRegexDel = NUL;
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff /*
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff * Whitespaces
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff */
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff[ \t\n]+ {
31fab17bcdbe302592a6c0dc5374ef56333ee879Michael Graff /* NOP */
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff}
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff /*
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff * C-style strings ("...")
ebdd11e84734e28ddd64562e82a7c646a58a04f4Michael Graff */
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff\" {
ebdd11e84734e28ddd64562e82a7c646a58a04f4Michael Graff cpStr = caStr;
ebdd11e84734e28ddd64562e82a7c646a58a04f4Michael Graff BEGIN(str);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff}
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff<str>\" {
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff BEGIN(INITIAL);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff *cpStr = NUL;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, caStr);
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff return T_STRING;
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff}
64828244e04e86dfa40f0a4f0c05f27923da499dMichael Graff<str>\n {
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff yyerror("Unterminated string");
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff}
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff<str>\\[0-7]{1,3} {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff int result;
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff (void)sscanf(yytext+1, "%o", &result);
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff if (result > 0xff)
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff yyerror("Escape sequence out of bound");
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff else
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff *cpStr++ = result;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff}
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff<str>\\[0-9]+ {
439c0011e642fb1d26011116144af698125262dbMichael Graff yyerror("Bad escape sequence");
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff}
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff<str>\\n { *cpStr++ = '\n'; }
11efdeb076d65fa9f0c5fc067dc040e7c99dfba6Michael Graff<str>\\r { *cpStr++ = '\r'; }
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff<str>\\t { *cpStr++ = '\t'; }
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff<str>\\b { *cpStr++ = '\b'; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff<str>\\f { *cpStr++ = '\f'; }
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff<str>\\(.|\n) {
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff *cpStr++ = yytext[1];
e51511aa3281f8dc384eb1283115c7f8d5c402aeMichael Graff}
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff<str>[^\\\n\"]+ {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff char *cp = yytext;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff while (*cp != NUL)
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff *cpStr++ = *cp++;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff}
2992344aacdb08e4af936c176d49ef789f5673ddMichael Graff<str>. {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff *cpStr++ = yytext[1];
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff}
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff /*
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff * Regular Expression
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff */
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff"m". {
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff cRegexDel = yytext[1];
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff cpRegex = caRegex;
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff BEGIN(regex);
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff}
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff<regex>.|\n {
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff if (yytext[0] == cRegexDel) {
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff *cpRegex = NUL;
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff BEGIN(regex_flags);
213973a334f92d4aef4ef62b4538fc2e4d0e8082Michael Graff }
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff else {
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff *cpRegex++ = yytext[0];
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff }
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff}
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff<regex_flags>i {
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, caRegex);
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff BEGIN(INITIAL);
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff return T_REGEX_I;
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff}
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff<regex_flags>.|\n {
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, caRegex);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff yyless(0);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff BEGIN(INITIAL);
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff return T_REGEX;
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff}
1f90c108282533a23b8362c34bcde4267c1eb4b1Michael Graff<regex_flags><<EOF>> {
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, caRegex);
a253e35c2451818fb39f9b808c7641adb5275fb3Michael Graff BEGIN(INITIAL);
ebdd11e84734e28ddd64562e82a7c646a58a04f4Michael Graff return T_REGEX;
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff}
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff /*
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff * Operators
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff */
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff"eq" { return T_OP_EQ; }
59e22acc4f79ff481f7bfa46ef0558957ae53cfcMichael Graff"==" { return T_OP_EQ; }
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff"ne" { return T_OP_NE; }
d43c2cc7bc4022701f141e299ea8f3fb1d0640c2Michael Graff"!=" { return T_OP_NE; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"lt" { return T_OP_LT; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"<" { return T_OP_LT; }
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff"le" { return T_OP_LE; }
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff"<=" { return T_OP_LE; }
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff"gt" { return T_OP_GT; }
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff">" { return T_OP_GT; }
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff"ge" { return T_OP_GE; }
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff">=" { return T_OP_GE; }
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff"=~" { return T_OP_REG; }
bb143613cf26e0f27dfd9caf1a7336065d064b26Michael Graff"!~" { return T_OP_NRE; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"and" { return T_OP_AND; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"&&" { return T_OP_AND; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"or" { return T_OP_OR; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"||" { return T_OP_OR; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"not" { return T_OP_NOT; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"!" { return T_OP_NOT; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"in" { return T_OP_IN; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff[Pp][Ee][Ee][Rr][Ee][Xx][Tt][Ll][Ii][Ss][Tt] { return T_OP_PEEREXTLIST; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /*
d43c2cc7bc4022701f141e299ea8f3fb1d0640c2Michael Graff * Functions
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff */
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff"file" { return T_FUNC_FILE; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff /*
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * Specials
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"true" { return T_TRUE; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff"false" { return T_FALSE; }
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff /*
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * Digits
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
439c0011e642fb1d26011116144af698125262dbMichael Graff[0-9]+ {
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, yytext);
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff return T_DIGIT;
d43c2cc7bc4022701f141e299ea8f3fb1d0640c2Michael Graff}
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff /*
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff * Identifiers
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff[a-zA-Z][a-zA-Z0-9_:-]* {
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff yylval.cpVal = apr_pstrdup(ssl_expr_info.pool, yytext);
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff return T_ID;
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff}
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff /*
439c0011e642fb1d26011116144af698125262dbMichael Graff * Anything else is returned as is...
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff */
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff.|\n {
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff return yytext[0];
f181f94ec8da8b1dbcc6353e8be965ea4a5ea282Michael Graff}
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff%%
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graffint yyinput(char *buf, int max_size)
d43c2cc7bc4022701f141e299ea8f3fb1d0640c2Michael Graff{
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff int n;
66bd3b3c6b171271c705b897823dcdcf29464698Michael Graff
11fcc67616fac1bc6a28b3d4fed24641137888e7Michael Graff if ((n = MIN(max_size, ssl_expr_info.inputbuf
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff + ssl_expr_info.inputlen
ad3a5c4b7e21af04d1b872f933c2e19e5c0a135bMichael Graff - ssl_expr_info.inputptr)) <= 0)
d8590892d10fc9528b0dde7e2781935e7b8d7a87Michael Graff return YY_NULL;
439c0011e642fb1d26011116144af698125262dbMichael Graff memcpy(buf, ssl_expr_info.inputptr, n);
439c0011e642fb1d26011116144af698125262dbMichael Graff ssl_expr_info.inputptr += n;
439c0011e642fb1d26011116144af698125262dbMichael Graff return n;
439c0011e642fb1d26011116144af698125262dbMichael Graff}
f36a81c88493985ee2d1c53cc6fe88f4b00dbbc8Michael Graff
439c0011e642fb1d26011116144af698125262dbMichael Graff