Debian Codegraph @

libsemanage/src/conf-scan.l

raw
1 /* Authors: Jason Tang <[email protected]>
2 * James Athey <[email protected]>
3 *
4 * Copyright (C) 2004-2006 Tresys Technology, LLC
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 %{
22 #include "conf-parse.h"
23
24 #include <ctype.h>
25 #include <string.h>
26
27 static char *my_strdup (char * s);
28 static char *my_qstrdup (char * s);
29
30 %}
31
32 %option stack prefix="semanage_"
33 %option noinput nounput noyy_push_state noyy_pop_state noyy_top_state noyywrap
34
35 %x arg
36
37 %%
38
39 #.* /* ignore comments */
40 module-store return MODULE_STORE;
41 store-root return STORE_ROOT;
42 compiler-directory return COMPILER_DIR;
43 ignore-module-cache return IGNORE_MODULE_CACHE;
44 policy-version return VERSION;
45 target-platform return TARGET_PLATFORM;
46 expand-check return EXPAND_CHECK;
47 file-mode return FILE_MODE;
48 save-previous return SAVE_PREVIOUS;
49 save-linked return SAVE_LINKED;
50 disable-genhomedircon return DISABLE_GENHOMEDIRCON;
51 usepasswd return USEPASSWD;
52 ignoredirs return IGNOREDIRS;
53 handle-unknown return HANDLE_UNKNOWN;
54 bzip-blocksize return BZIP_BLOCKSIZE;
55 bzip-small return BZIP_SMALL;
56 remove-hll return REMOVE_HLL;
57 "[load_policy]" return LOAD_POLICY_START;
58 "[setfiles]" return SETFILES_START;
59 "[sefcontext_compile]" return SEFCONTEXT_COMPILE_START;
60 "[verify module]" return VERIFY_MOD_START;
61 "[verify linked]" return VERIFY_LINKED_START;
62 "[verify kernel]" return VERIFY_KERNEL_START;
63 "[end]" return BLOCK_END;
64 path return PROG_PATH;
65 args return PROG_ARGS;
66 [ \t]*=[ \t]* BEGIN arg; return '=';
67 [ \t\n]+ /* ignore */
68 . return semanage_text[0];
69 <arg>\"\" BEGIN INITIAL; semanage_lval.s = NULL; return ARG;
70 <arg>\".+\" BEGIN INITIAL; semanage_lval.s = my_qstrdup(semanage_text); return ARG;
71 <arg>.*[^\"\n] BEGIN INITIAL; semanage_lval.s = my_strdup(semanage_text); return ARG;
72 <arg>.|\n BEGIN INITIAL; semanage_lval.s = NULL; return ARG;
73
74 %%
75
76 /* Like strdup(), but also trim leading and trailing whitespace.
77 * Returns NULL on error. */
78 static char *my_strdup(char *s) {
79 char *t;
80 while (isspace(*s)) {
81 s++;
82 }
83 t = s + strlen(s) - 1;
84 while (t >= s && isspace(*t)) {
85 *t = '\0';
86 t--;
87 }
88 return strdup(s);
89 }
90
91 /* strdup() a string sans initial and trailing characters. Does /not/
92 * trim any whitespace. Returns NULL on error. */
93 static char *my_qstrdup(char *s) {
94 s++;
95 s[strlen(s) - 1] = '\0';
96 return strdup(s);
97 }
98