conf-scan.l revision 915b5f885f030aa24a2ca648a184fa02cb5bbdcd
1/* Authors: Jason Tang     <jtang@tresys.com>
2 *          James Athey    <jathey@tresys.com>
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
27static char *my_strdup (char * s);
28static char *my_qstrdup (char * s);
29
30int yywrap(void);
31
32%}
33
34%option stack prefix="semanage_"
35%option noinput nounput noyy_push_state noyy_pop_state noyy_top_state
36
37%x arg
38
39%%
40
41#.*               /* ignore comments */
42module-store      return MODULE_STORE;
43policy-version    return VERSION;
44expand-check      return EXPAND_CHECK;
45file-mode         return FILE_MODE;
46save-previous     return SAVE_PREVIOUS;
47save-linked       return SAVE_LINKED;
48disable-genhomedircon return DISABLE_GENHOMEDIRCON;
49usepasswd return USEPASSWD;
50ignoredirs        return IGNOREDIRS;
51handle-unknown    return HANDLE_UNKNOWN;
52bzip-blocksize	return BZIP_BLOCKSIZE;
53bzip-small	return BZIP_SMALL;
54"[load_policy]"   return LOAD_POLICY_START;
55"[setfiles]"      return SETFILES_START;
56"[verify module]" return VERIFY_MOD_START;
57"[verify linked]" return VERIFY_LINKED_START;
58"[verify kernel]" return VERIFY_KERNEL_START;
59"[end]"           return BLOCK_END;
60path              return PROG_PATH;
61args              return PROG_ARGS;
62[ \t]*=[ \t]*     BEGIN arg; return '=';
63[ \t\n]+          /* ignore */
64.                 return semanage_text[0];
65<arg>\"\"         BEGIN INITIAL; semanage_lval.s = NULL; return ARG;
66<arg>\".+\"       BEGIN INITIAL; semanage_lval.s = my_qstrdup(semanage_text); return ARG;
67<arg>.*[^\"\n]    BEGIN INITIAL; semanage_lval.s = my_strdup(semanage_text); return ARG;
68<arg>.|\n         BEGIN INITIAL; semanage_lval.s = NULL; return ARG;
69
70%%
71
72int yywrap(void) {
73	return 1;
74}
75
76/* Like strdup(), but also trim leading and trailing whitespace.
77 * Returns NULL on error. */
78static 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. */
93static char *my_qstrdup(char *s) {
94	s++;
95	s[strlen(s) - 1] = '\0';
96	return strdup(s);
97}
98
99