Blame src/conf-scan.l

Packit Service 102278
/* Authors: Jason Tang     <jtang@tresys.com>
Packit Service 102278
 *          James Athey    <jathey@tresys.com>
Packit Service 102278
 *
Packit Service 102278
 * Copyright (C) 2004-2006 Tresys Technology, LLC
Packit Service 102278
 *
Packit Service 102278
 *  This library is free software; you can redistribute it and/or
Packit Service 102278
 *  modify it under the terms of the GNU Lesser General Public
Packit Service 102278
 *  License as published by the Free Software Foundation; either
Packit Service 102278
 *  version 2.1 of the License, or (at your option) any later version.
Packit Service 102278
 *
Packit Service 102278
 *  This library is distributed in the hope that it will be useful,
Packit Service 102278
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 102278
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 102278
 *  Lesser General Public License for more details.
Packit Service 102278
 *
Packit Service 102278
 *  You should have received a copy of the GNU Lesser General Public
Packit Service 102278
 *  License along with this library; if not, write to the Free Software
Packit Service 102278
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit Service 102278
 */
Packit Service 102278
Packit Service 102278
%{
Packit Service 102278
#include "conf-parse.h"
Packit Service 102278
Packit Service 102278
#include <ctype.h>
Packit Service 102278
#include <string.h>
Packit Service 102278
Packit Service 102278
static char *my_strdup (char * s);
Packit Service 102278
static char *my_qstrdup (char * s);
Packit Service 102278
Packit Service 102278
%}
Packit Service 102278
Packit Service 102278
%option stack prefix="semanage_"
Packit Service 102278
%option noinput nounput noyy_push_state noyy_pop_state noyy_top_state noyywrap
Packit Service 102278
Packit Service 102278
%x arg
Packit Service 102278
Packit Service 102278
%%
Packit Service 102278
Packit Service 102278
#.*               /* ignore comments */
Packit Service 102278
module-store      return MODULE_STORE;
Packit Service 102278
store-root        return STORE_ROOT;
Packit Service 102278
compiler-directory	return COMPILER_DIR;
Packit Service 102278
ignore-module-cache return IGNORE_MODULE_CACHE;
Packit Service 102278
policy-version    return VERSION;
Packit Service 102278
target-platform   return TARGET_PLATFORM;
Packit Service 102278
expand-check      return EXPAND_CHECK;
Packit Service 102278
file-mode         return FILE_MODE;
Packit Service 102278
save-previous     return SAVE_PREVIOUS;
Packit Service 102278
save-linked       return SAVE_LINKED;
Packit Service 102278
disable-genhomedircon return DISABLE_GENHOMEDIRCON;
Packit Service 102278
usepasswd return USEPASSWD;
Packit Service 102278
ignoredirs        return IGNOREDIRS;
Packit Service 102278
handle-unknown    return HANDLE_UNKNOWN;
Packit Service 102278
bzip-blocksize	return BZIP_BLOCKSIZE;
Packit Service 102278
bzip-small	return BZIP_SMALL;
Packit Service 102278
remove-hll	return REMOVE_HLL;
Packit Service 102278
"[load_policy]"   return LOAD_POLICY_START;
Packit Service 102278
"[setfiles]"      return SETFILES_START;
Packit Service 102278
"[sefcontext_compile]"      return SEFCONTEXT_COMPILE_START;
Packit Service 102278
"[verify module]" return VERIFY_MOD_START;
Packit Service 102278
"[verify linked]" return VERIFY_LINKED_START;
Packit Service 102278
"[verify kernel]" return VERIFY_KERNEL_START;
Packit Service 102278
"[end]"           return BLOCK_END;
Packit Service 102278
path              return PROG_PATH;
Packit Service 102278
args              return PROG_ARGS;
Packit Service 102278
[ \t]*=[ \t]*     BEGIN arg; return '=';
Packit Service 102278
[ \t\n]+          /* ignore */
Packit Service 102278
.                 return semanage_text[0];
Packit Service 102278
<arg>\"\"         BEGIN INITIAL; semanage_lval.s = NULL; return ARG;
Packit Service 102278
<arg>\".+\"       BEGIN INITIAL; semanage_lval.s = my_qstrdup(semanage_text); return ARG;
Packit Service 102278
<arg>.*[^\"\n]    BEGIN INITIAL; semanage_lval.s = my_strdup(semanage_text); return ARG;
Packit Service 102278
<arg>.|\n         BEGIN INITIAL; semanage_lval.s = NULL; return ARG;
Packit Service 102278
Packit Service 102278
%%
Packit Service 102278
Packit Service 102278
/* Like strdup(), but also trim leading and trailing whitespace.
Packit Service 102278
 * Returns NULL on error. */
Packit Service 102278
static char *my_strdup(char *s) {
Packit Service 102278
	char *t;
Packit Service 102278
	while (isspace(*s)) {
Packit Service 102278
		s++;
Packit Service 102278
	}
Packit Service 102278
	t = s + strlen(s) - 1;
Packit Service 102278
	while (t >= s && isspace(*t)) {
Packit Service 102278
		*t = '\0';
Packit Service 102278
		t--;
Packit Service 102278
	}
Packit Service 102278
	return strdup(s);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
/* strdup() a string sans initial and trailing characters.  Does /not/
Packit Service 102278
 * trim any whitespace.	 Returns NULL on error. */
Packit Service 102278
static char *my_qstrdup(char *s) {
Packit Service 102278
	s++;
Packit Service 102278
	s[strlen(s) - 1] = '\0';
Packit Service 102278
	return strdup(s);
Packit Service 102278
}
Packit Service 102278