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 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 optimize-policy return OPTIMIZE_POLICY; 58 "[load_policy]" return LOAD_POLICY_START; 59 "[setfiles]" return SETFILES_START; 60 "[sefcontext_compile]" return SEFCONTEXT_COMPILE_START; 61 "[verify module]" return VERIFY_MOD_START; 62 "[verify linked]" return VERIFY_LINKED_START; 63 "[verify kernel]" return VERIFY_KERNEL_START; 64 "[end]" return BLOCK_END; 65 path return PROG_PATH; 66 args return PROG_ARGS; 67 [ \t]*=[ \t]* BEGIN arg; return '='; 68 [ \t\n]+ /* ignore */ 69 . return semanage_text[0]; 70 <arg>\"\" BEGIN INITIAL; semanage_lval.s = NULL; return ARG; 71 <arg>\".+\" BEGIN INITIAL; semanage_lval.s = my_qstrdup(semanage_text); return ARG; 72 <arg>.*[^\"\n] BEGIN INITIAL; semanage_lval.s = my_strdup(semanage_text); return ARG; 73 <arg>.|\n BEGIN INITIAL; semanage_lval.s = NULL; return ARG; 74 75 %% 76 77 /* Like strdup(), but also trim leading and trailing whitespace. 78 * Returns NULL on error. */ 79 static char *my_strdup(char *s) { 80 char *t; 81 while (isspace(*s)) { 82 s++; 83 } 84 t = s + strlen(s) - 1; 85 while (t >= s && isspace(*t)) { 86 *t = '\0'; 87 t--; 88 } 89 return strdup(s); 90 } 91 92 /* strdup() a string sans initial and trailing characters. Does /not/ 93 * trim any whitespace. Returns NULL on error. */ 94 static char *my_qstrdup(char *s) { 95 s++; 96 s[strlen(s) - 1] = '\0'; 97 return strdup(s); 98 } 99 100