Skip to content

Latest commit

 

History

History
242 lines (224 loc) · 5.21 KB

dbusaccess_policy1.y

File metadata and controls

242 lines (224 loc) · 5.21 KB
 
Jul 8, 2020
Jul 8, 2020
2
3
* Copyright (C) 2017-2020 Jolla Ltd.
* Copyright (C) 2017-2020 Slava Monich <slava.monich@jolla.com>
4
5
6
7
8
9
10
11
12
13
14
15
*
* You may use this file under the terms of BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
Mar 29, 2019
Mar 29, 2019
16
17
18
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
%{
#include "dbusaccess_parser_p.h"
Mar 29, 2017
Mar 29, 2017
35
#include "dbusaccess_system.h"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "dbusaccess_log.h"
#define FORMAT_VERSION 1
%}
%union
{
int number;
const char* string;
DA_ACCESS access;
DAParserEntry* entry;
DAParserExpr* expr;
GSList* list;
}
/* BISON Declarations */
%pure-parser
%name-prefix "da_parser_"
%lex-param { void* yyscanner }
%lex-param { DAParser* parser }
%parse-param { DAParser* parser }
%parse-param { DAScanner* yyscanner }
%token <number> NUMBER
%token <string> ID
%token <string> WORD
%token <string> WILDCARD
%token <string> STRING /* Quoted string, may include spaces */
%token USER
%token GROUP
%token ALLOW
%token DENY
%token ERROR
%type <number> version
%type <number> user
%type <number> group
%type <access> access
%type <list> entries
%type <entry> entry
%type <expr> expr
%type <expr> term
%type <string> param
%left '!'
/* Grammar follows */
%%
policy:
version
| version ';' entries
{
da_parser_add_entries(parser, $3);
}
| version ';' entries ';'
{
da_parser_add_entries(parser, $3);
}
Nov 2, 2019
Nov 2, 2019
93
94
95
96
97
98
99
100
| entries
{
da_parser_add_entries(parser, $1);
}
| entries ';'
{
da_parser_add_entries(parser, $1);
}
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
version:
NUMBER
{
if ($1 != FORMAT_VERSION) {
GDEBUG("Unsupported version %d", $1);
YYERROR;
}
}
entries:
entry
{
$$ = da_parser_new_link(parser, $1);
}
| entries ';' entry
{
$$ = g_slist_concat($1, da_parser_new_link(parser, $3));
}
entry:
'*' '=' access
{
$$ = da_parser_new_entry(parser, NULL, $3);
}
| expr '=' access
{
$$ = da_parser_new_entry(parser, $1, $3);
}
| expr
{
$$ = da_parser_new_entry(parser, $1, DA_ACCESS_ALLOW);
}
access:
ALLOW
{
$$ = DA_ACCESS_ALLOW;
}
| DENY
{
$$ = DA_ACCESS_DENY;
}
user:
NUMBER
Mar 29, 2019
Mar 29, 2019
147
148
149
{
$$ = ($1 < 0) ? DA_WILDCARD : $1;
}
150
151
| WILDCARD
{
Mar 29, 2019
Mar 29, 2019
152
$$ = DA_WILDCARD;
153
154
155
156
157
}
| WORD
{
$$ = da_system_uid($1);
if ($$ < 0) {
Jul 8, 2020
Jul 8, 2020
158
GDEBUG("Unknown user \"%s\"", $1);
Mar 29, 2019
Mar 29, 2019
159
$$ = DA_INVALID;
160
161
162
163
164
}
}
group:
NUMBER
Mar 29, 2019
Mar 29, 2019
165
166
167
{
$$ = ($1 < 0) ? DA_WILDCARD : $1;
}
168
169
| WILDCARD
{
Mar 29, 2019
Mar 29, 2019
170
$$ = DA_WILDCARD;
171
172
173
174
175
}
| WORD
{
$$ = da_system_gid($1);
if ($$ < 0) {
Jul 8, 2020
Jul 8, 2020
176
GDEBUG("Unknown group \"%s\"", $1);
Mar 29, 2019
Mar 29, 2019
177
$$ = DA_INVALID;
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
}
}
expr:
term
| '!' expr
{
$$ = da_parser_new_expr(parser, DA_PARSER_EXPR_NOT, $2, NULL);
}
| '(' expr ')'
{
$$ = $2;
}
| expr '|' expr
{
$$ = da_parser_new_expr(parser, DA_PARSER_EXPR_OR, $1, $3);
}
| expr '&' expr
{
$$ = da_parser_new_expr(parser, DA_PARSER_EXPR_AND, $1, $3);
}
term:
USER '(' user ')'
{
Mar 29, 2019
Mar 29, 2019
203
$$ = da_parser_new_expr_identity(parser, $3, DA_WILDCARD);
204
205
206
207
208
209
210
}
| USER '(' user ':' group ')'
{
$$ = da_parser_new_expr_identity(parser, $3, $5);
}
| GROUP '(' group ')'
{
Mar 29, 2019
Mar 29, 2019
211
$$ = da_parser_new_expr_identity(parser, DA_WILDCARD, $3);
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
}
| ID '(' ')'
{
$$ = da_parser_new_expr_custom(parser, $1, NULL);
if (!$$) {
YYERROR;
}
}
| ID '(' param ')'
{
$$ = da_parser_new_expr_custom(parser, $1, $3);
if (!$$) {
YYERROR;
}
}
param:
WORD
| STRING
| WILDCARD
;
%%
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/