2008-11-17 18:29:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-05 09:52:00 -05:00
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
2008-11-17 18:29:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
namespace Microsoft.Singularity.Security.AccessControl
|
|
|
|
{
|
|
|
|
using System;
|
|
|
|
using Microsoft.Contracts;
|
2008-11-17 18:29:00 -05:00
|
|
|
// test
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
internal class AclParser
|
|
|
|
{
|
|
|
|
private const int YY_BUFFER_SIZE = 512;
|
|
|
|
private const int YY_F = -1;
|
|
|
|
private const int YY_NO_STATE = -1;
|
|
|
|
private const int YY_NOT_ACCEPT = 0;
|
|
|
|
private const int YY_START = 1;
|
|
|
|
private const int YY_END = 2;
|
|
|
|
private const int YY_NO_ANCHOR = 4;
|
|
|
|
delegate AclToken AcceptMethod();
|
|
|
|
AcceptMethod[]! accept_dispatch;
|
|
|
|
private const int YY_BOL = 128;
|
|
|
|
private const int YY_EOF = 129;
|
|
|
|
private StringReader! yy_reader;
|
|
|
|
private int yy_buffer_index;
|
|
|
|
private int yy_buffer_read;
|
|
|
|
private int yy_buffer_start;
|
|
|
|
private int yy_buffer_end;
|
|
|
|
private char[]! yy_buffer;
|
|
|
|
private int yychar;
|
|
|
|
private int yyline;
|
|
|
|
private bool yy_at_bol;
|
|
|
|
private int yy_lexical_state;
|
|
|
|
|
|
|
|
// [NotDelayed]
|
|
|
|
internal AclParser(string data)
|
|
|
|
{
|
|
|
|
yy_reader = new StringReader(data);
|
|
|
|
yy_buffer = new char[YY_BUFFER_SIZE];
|
|
|
|
yy_buffer_read = 0;
|
|
|
|
yy_buffer_index = 0;
|
|
|
|
yy_buffer_start = 0;
|
|
|
|
yy_buffer_end = 0;
|
|
|
|
yychar = 0;
|
|
|
|
yyline = 0;
|
|
|
|
yy_at_bol = true;
|
|
|
|
yy_lexical_state = YYINITIAL;
|
|
|
|
base();
|
|
|
|
|
|
|
|
accept_dispatch = new[Delayed] AcceptMethod[]
|
|
|
|
{
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
new AcceptMethod(this.Accept_2),
|
|
|
|
new AcceptMethod(this.Accept_3),
|
|
|
|
new AcceptMethod(this.Accept_4),
|
|
|
|
new AcceptMethod(this.Accept_5),
|
|
|
|
new AcceptMethod(this.Accept_6),
|
|
|
|
new AcceptMethod(this.Accept_7),
|
|
|
|
null,
|
|
|
|
new AcceptMethod(this.Accept_9),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
AclToken Accept_2()
|
|
|
|
{ // begin accept action #2
|
|
|
|
{
|
|
|
|
String! str = (!)yytext().Substring(0, yytext().Length);
|
2008-11-17 18:29:00 -05:00
|
|
|
if (str.Equals("!")) {
|
2008-03-05 09:52:00 -05:00
|
|
|
return (new AclToken(AclTokenType.Any, str, yychar, yychar + 1));
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
2008-03-05 09:52:00 -05:00
|
|
|
return (new AclToken(AclTokenType.Arc, str, yychar, yychar + str.Length));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end accept action #2
|
|
|
|
|
|
|
|
AclToken Accept_3()
|
|
|
|
{ // begin accept action #3
|
|
|
|
{yybegin(GROUPNAME); return null;}
|
|
|
|
} // end accept action #3
|
|
|
|
|
|
|
|
AclToken Accept_4()
|
|
|
|
{ // begin accept action #4
|
|
|
|
{ return (new AclToken(AclTokenType.Escape, yytext(), yychar, yychar+1)); }
|
|
|
|
} // end accept action #4
|
|
|
|
|
|
|
|
AclToken Accept_5()
|
|
|
|
{ // begin accept action #5
|
|
|
|
{ return (new AclToken(AclTokenType.Literal, yytext(), yychar, yychar+1)); }
|
|
|
|
} // end accept action #5
|
|
|
|
|
|
|
|
AclToken Accept_6()
|
|
|
|
{ // begin accept action #6
|
|
|
|
{yybegin(YYINITIAL); return null;}
|
|
|
|
} // end accept action #6
|
|
|
|
|
|
|
|
AclToken Accept_7()
|
|
|
|
{ // begin accept action #7
|
|
|
|
{
|
|
|
|
String! str = (!)yytext().Substring(0, yytext().Length);
|
|
|
|
return (new AclToken(AclTokenType.GroupName, str, yychar, yychar + str.Length));
|
|
|
|
}
|
|
|
|
} // end accept action #7
|
|
|
|
|
|
|
|
AclToken Accept_9()
|
|
|
|
{ // begin accept action #9
|
|
|
|
{
|
|
|
|
String! str = (!)yytext().Substring(0, yytext().Length);
|
2008-11-17 18:29:00 -05:00
|
|
|
if (str.Equals("!")) {
|
2008-03-05 09:52:00 -05:00
|
|
|
return (new AclToken(AclTokenType.Any, str, yychar, yychar + 1));
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
2008-03-05 09:52:00 -05:00
|
|
|
return (new AclToken(AclTokenType.Arc, str, yychar, yychar + str.Length));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end accept action #9
|
|
|
|
|
|
|
|
private const int YYINITIAL = 0;
|
|
|
|
private const int GROUPNAME = 1;
|
|
|
|
private static int[]! yy_state_dtrans = new int[]
|
|
|
|
{ 0,
|
|
|
|
8
|
|
|
|
};
|
|
|
|
private void yybegin (int mystate)
|
|
|
|
{
|
|
|
|
yy_lexical_state = mystate;
|
|
|
|
}
|
|
|
|
|
|
|
|
private char yy_advance ()
|
|
|
|
{
|
|
|
|
int next_read;
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
if (yy_buffer_index < yy_buffer_read) {
|
2008-03-05 09:52:00 -05:00
|
|
|
return yy_buffer[yy_buffer_index++];
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
if (0 != yy_buffer_start) {
|
2008-03-05 09:52:00 -05:00
|
|
|
i = yy_buffer_start;
|
|
|
|
j = 0;
|
2008-11-17 18:29:00 -05:00
|
|
|
while (i < yy_buffer_read) {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_buffer[j] = yy_buffer[i];
|
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
yy_buffer_end = yy_buffer_end - yy_buffer_start;
|
|
|
|
yy_buffer_start = 0;
|
|
|
|
yy_buffer_read = j;
|
|
|
|
yy_buffer_index = j;
|
|
|
|
next_read = yy_reader.Read(yy_buffer,yy_buffer_read,
|
|
|
|
yy_buffer.Length - yy_buffer_read);
|
2008-11-17 18:29:00 -05:00
|
|
|
if (next_read <= 0) {
|
2008-03-05 09:52:00 -05:00
|
|
|
return (char) YY_EOF;
|
|
|
|
}
|
|
|
|
yy_buffer_read = yy_buffer_read + next_read;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
while (yy_buffer_index >= yy_buffer_read) {
|
|
|
|
if (yy_buffer_index >= yy_buffer.Length) {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_buffer = yy_double(yy_buffer);
|
|
|
|
}
|
|
|
|
next_read = yy_reader.Read(yy_buffer,yy_buffer_read,
|
|
|
|
yy_buffer.Length - yy_buffer_read);
|
2008-11-17 18:29:00 -05:00
|
|
|
if (next_read <= 0) {
|
2008-03-05 09:52:00 -05:00
|
|
|
return (char) YY_EOF;
|
|
|
|
}
|
|
|
|
yy_buffer_read = yy_buffer_read + next_read;
|
|
|
|
}
|
|
|
|
return yy_buffer[yy_buffer_index++];
|
|
|
|
}
|
|
|
|
private void yy_move_end ()
|
|
|
|
{
|
|
|
|
if (yy_buffer_end > yy_buffer_start &&
|
|
|
|
'\n' == yy_buffer[yy_buffer_end-1])
|
|
|
|
yy_buffer_end--;
|
|
|
|
if (yy_buffer_end > yy_buffer_start &&
|
|
|
|
'\r' == yy_buffer[yy_buffer_end-1])
|
|
|
|
yy_buffer_end--;
|
|
|
|
}
|
|
|
|
private bool yy_last_was_cr=false;
|
|
|
|
private void yy_mark_start ()
|
|
|
|
{
|
|
|
|
int i;
|
2008-11-17 18:29:00 -05:00
|
|
|
for (i = yy_buffer_start; i < yy_buffer_index; i++) {
|
|
|
|
if (yy_buffer[i] == '\n' && !yy_last_was_cr) {
|
2008-03-05 09:52:00 -05:00
|
|
|
yyline++;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
if (yy_buffer[i] == '\r') {
|
2008-03-05 09:52:00 -05:00
|
|
|
yyline++;
|
|
|
|
yy_last_was_cr=true;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_last_was_cr=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yychar = yychar + yy_buffer_index - yy_buffer_start;
|
|
|
|
yy_buffer_start = yy_buffer_index;
|
|
|
|
}
|
|
|
|
private void yy_mark_end ()
|
|
|
|
{
|
|
|
|
yy_buffer_end = yy_buffer_index;
|
|
|
|
}
|
|
|
|
private void yy_to_mark ()
|
|
|
|
{
|
|
|
|
yy_buffer_index = yy_buffer_end;
|
|
|
|
yy_at_bol = (yy_buffer_end > yy_buffer_start) &&
|
|
|
|
(yy_buffer[yy_buffer_end-1] == '\r' ||
|
|
|
|
yy_buffer[yy_buffer_end-1] == '\n');
|
|
|
|
}
|
|
|
|
internal string! yytext()
|
|
|
|
{
|
|
|
|
return (new string(yy_buffer,
|
|
|
|
yy_buffer_start,
|
|
|
|
yy_buffer_end - yy_buffer_start)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
private int yylength ()
|
|
|
|
{
|
|
|
|
return yy_buffer_end - yy_buffer_start;
|
|
|
|
}
|
|
|
|
private char[]! yy_double (char[]! buf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char[] newbuf;
|
|
|
|
newbuf = new char[2*buf.Length];
|
2008-11-17 18:29:00 -05:00
|
|
|
for (i = 0; i < buf.Length; i++) {
|
2008-03-05 09:52:00 -05:00
|
|
|
newbuf[i] = buf[i];
|
|
|
|
}
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
private const int YY_E_INTERNAL = 0;
|
|
|
|
private const int YY_E_MATCH = 1;
|
|
|
|
private static string[]! yy_error_string = new string[]
|
|
|
|
{
|
|
|
|
"Error: Internal error.\n",
|
|
|
|
"Error: Unmatched input.\n"
|
|
|
|
};
|
|
|
|
private void yy_error (int code,bool fatal)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
DebugStub.WriteLine("AclParser: {0}", __arglist(yy_error_string[code]));
|
|
|
|
if (fatal) {
|
|
|
|
throw new System.ApplicationException("An error occurred while parsing an ACL: "
|
|
|
|
+ yy_error_string[code]);
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private static int[]! yy_acpt = new int[]
|
|
|
|
{
|
|
|
|
/* 0 */ YY_NOT_ACCEPT,
|
|
|
|
/* 1 */ YY_NO_ANCHOR,
|
|
|
|
/* 2 */ YY_NO_ANCHOR,
|
|
|
|
/* 3 */ YY_NO_ANCHOR,
|
|
|
|
/* 4 */ YY_NO_ANCHOR,
|
|
|
|
/* 5 */ YY_NO_ANCHOR,
|
|
|
|
/* 6 */ YY_NO_ANCHOR,
|
|
|
|
/* 7 */ YY_NO_ANCHOR,
|
|
|
|
/* 8 */ YY_NOT_ACCEPT,
|
|
|
|
/* 9 */ YY_NO_ANCHOR
|
|
|
|
};
|
|
|
|
private static int[]! yy_cmap = new int[]
|
|
|
|
{
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 2, 4, 4, 4, 4, 4, 4,
|
|
|
|
6, 6, 6, 5, 4, 4, 5, 6,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
6, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 3, 6, 1, 4, 4,
|
|
|
|
0, 0
|
|
|
|
};
|
|
|
|
private static int[]! yy_rmap = new int[]
|
|
|
|
{
|
|
|
|
0, 1, 2, 1, 1, 1, 1, 3,
|
|
|
|
4, 1
|
|
|
|
};
|
|
|
|
private static int[,]! yy_nxt = new int[,]
|
|
|
|
{
|
|
|
|
{ 1, 2, 9, 3, 2, 4, 5 },
|
|
|
|
{ -1, -1, -1, -1, -1, -1, -1 },
|
|
|
|
{ -1, 2, -1, -1, 2, -1, -1 },
|
|
|
|
{ -1, -1, 7, 7, 7, 7, 7 },
|
|
|
|
{ 1, 6, 7, 7, 7, 7, 7 }
|
|
|
|
};
|
|
|
|
public AclToken NextToken()
|
|
|
|
{
|
|
|
|
char yy_lookahead;
|
|
|
|
int yy_anchor = YY_NO_ANCHOR;
|
|
|
|
int yy_state = yy_state_dtrans[yy_lexical_state];
|
|
|
|
int yy_next_state = YY_NO_STATE;
|
|
|
|
int yy_last_accept_state = YY_NO_STATE;
|
|
|
|
bool yy_initial = true;
|
|
|
|
int yy_this_accept;
|
|
|
|
|
|
|
|
yy_mark_start();
|
|
|
|
yy_this_accept = yy_acpt[yy_state];
|
2008-11-17 18:29:00 -05:00
|
|
|
if (YY_NOT_ACCEPT != yy_this_accept) {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_last_accept_state = yy_state;
|
|
|
|
yy_mark_end();
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
while (true) {
|
2008-03-05 09:52:00 -05:00
|
|
|
if (yy_initial && yy_at_bol)
|
|
|
|
yy_lookahead = (char) YY_BOL;
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_lookahead = yy_advance();
|
|
|
|
}
|
|
|
|
yy_next_state = yy_nxt[yy_rmap[yy_state],yy_cmap[yy_lookahead]];
|
2008-11-17 18:29:00 -05:00
|
|
|
if (YY_EOF == yy_lookahead && yy_initial) {
|
2008-03-05 09:52:00 -05:00
|
|
|
return null;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
if (YY_F != yy_next_state) {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_state = yy_next_state;
|
|
|
|
yy_initial = false;
|
|
|
|
yy_this_accept = yy_acpt[yy_state];
|
2008-11-17 18:29:00 -05:00
|
|
|
if (YY_NOT_ACCEPT != yy_this_accept) {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_last_accept_state = yy_state;
|
|
|
|
yy_mark_end();
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
|
|
|
if (YY_NO_STATE == yy_last_accept_state) {
|
2008-03-05 09:52:00 -05:00
|
|
|
throw new System.ApplicationException("Lexical Error: Unmatched Input.");
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_anchor = yy_acpt[yy_last_accept_state];
|
2008-11-17 18:29:00 -05:00
|
|
|
if (0 != (YY_END & yy_anchor)) {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_move_end();
|
|
|
|
}
|
|
|
|
yy_to_mark();
|
2008-11-17 18:29:00 -05:00
|
|
|
if (yy_last_accept_state < 0) {
|
2008-03-05 09:52:00 -05:00
|
|
|
if (yy_last_accept_state < 10)
|
|
|
|
yy_error(YY_E_INTERNAL, false);
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
2008-03-05 09:52:00 -05:00
|
|
|
AcceptMethod m = accept_dispatch[yy_last_accept_state];
|
2008-11-17 18:29:00 -05:00
|
|
|
if (m != null) {
|
2008-03-05 09:52:00 -05:00
|
|
|
AclToken tmp = m();
|
|
|
|
if (tmp != null)
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yy_initial = true;
|
|
|
|
yy_state = yy_state_dtrans[yy_lexical_state];
|
|
|
|
yy_next_state = YY_NO_STATE;
|
|
|
|
yy_last_accept_state = YY_NO_STATE;
|
|
|
|
yy_mark_start();
|
|
|
|
yy_this_accept = yy_acpt[yy_state];
|
2008-11-17 18:29:00 -05:00
|
|
|
if (YY_NOT_ACCEPT != yy_this_accept) {
|
2008-03-05 09:52:00 -05:00
|
|
|
yy_last_accept_state = yy_state;
|
|
|
|
yy_mark_end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|