Blame src/conf-scan.l

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