FreeBSD/contrib/openbsm/bin/auditfilterd/auditfilterd_conf.c
/*
 * Given a configuration line, generate an auditfilter_module structure that
 * describes it; caller will not pass comments in, so they are not looked
 * for.  Do not attempt to instantiate it.  Will destroy the contents of
 * 'buffer'.
 *
 * Configuration lines consist of two parts: the module name and arguments
 * separated by a ':', and then a ','-delimited list of arguments.
 *
 * XXXRW: Need to decide where to send the warning output -- stderr for now.
 */
Given a configuration line, generate an auditfilter_module structure that
describes it; caller will not pass comments in, so they are not looked
for.  Do not attempt to instantiate it.  Will destroy the contents of
'buffer'.

Configuration lines consist of two parts: the module name and arguments
separated by a ':', and then a ','-delimited list of arguments.

Need to decide where to send the warning output -- stderr for now.
Given a configuration line generate an auditfilter_module structure that describes it ; caller will not pass comments in so they are not looked for . Do not attempt to instantiate it . Will destroy the contents of ' buffer ' . Configuration lines consist of two parts : the module name and arguments separated by a ' : ' and then a ' ' - delimited list of arguments . Need to decide where to send the warning output -- stderr for now .
struct auditfilter_module *
auditfilter_module_parse(const char *filename, int linenumber, char *buffer)
{
	char *arguments, *module, **ap;
	struct auditfilter_module *am;
	am = malloc(sizeof(*am));
	if (am == NULL) {
		warn("auditfilter_module_parse: %s:%d", filename, linenumber);
		return (NULL);
	}
	bzero(am, sizeof(*am));
	arguments = buffer;
	module = strsep(&arguments, ":");
	if (module == NULL || arguments == NULL) {
		warnx("auditfilter_module_parse: %s:%d: parse error",
		    filename, linenumber);
		return (NULL);
	}
	am->am_modulename = strdup(module);
	if (am->am_modulename == NULL) {
		warn("auditfilter_module_parse: %s:%d", filename, linenumber);
		auditfilter_module_free(am);
		return (NULL);
	}
	am->am_arg_buffer = strdup(buffer);
	if (am->am_arg_buffer == NULL) {
		warn("auditfilter_module_parse: %s:%d", filename, linenumber);
		auditfilter_module_free(am);
		return (NULL);
	}
	am->am_argv = malloc(sizeof(char *) * AUDITFILTERD_CONF_MAXARGS);
	if (am->am_argv == NULL) {
		warn("auditfilter_module_parse: %s:%d", filename, linenumber);
		auditfilter_module_free(am);
		return (NULL);
	}
	bzero(am->am_argv, sizeof(char *) * AUDITFILTERD_CONF_MAXARGS);
	am->am_argc = 0;
	for (ap = am->am_argv; (*ap = strsep(&arguments, " \t")) != NULL;) {
		if (**ap != '\0') {
			am->am_argc++;
			if (++ap >= &am->am_argv[AUDITFILTERD_CONF_MAXARGS])
				break;
		}
	}
	if (ap >= &am->am_argv[AUDITFILTERD_CONF_MAXARGS]) {
		warnx("auditfilter_module_parse: %s:%d: too many arguments",
		    filename, linenumber);
		auditfilter_module_free(am);
		return (NULL);
	}
	return (am);
}
struct auditfilter_module * auditfilter_module_parse ( const char * filename , int linenumber , char * buffer ) { char * arguments , * module , * * ap ; struct auditfilter_module * am ; am = malloc ( sizeof ( * am ) ) ; if ( am == NULL ) { warn ( " " , filename , linenumber ) ; return ( NULL ) ; } bzero ( am , sizeof ( * am ) ) ; arguments = buffer ; module = strsep ( & arguments , " " ) ; if ( module == NULL || arguments == NULL ) { warnx ( " " , filename , linenumber ) ; return ( NULL ) ; } am -> am_modulename = strdup ( module ) ; if ( am -> am_modulename == NULL ) { warn ( " " , filename , linenumber ) ; auditfilter_module_free ( am ) ; return ( NULL ) ; } am -> am_arg_buffer = strdup ( buffer ) ; if ( am -> am_arg_buffer == NULL ) { warn ( " " , filename , linenumber ) ; auditfilter_module_free ( am ) ; return ( NULL ) ; } am -> am_argv = malloc ( sizeof ( char * ) * AUDITFILTERD_CONF_MAXARGS ) ; if ( am -> am_argv == NULL ) { warn ( " " , filename , linenumber ) ; auditfilter_module_free ( am ) ; return ( NULL ) ; } bzero ( am -> am_argv , sizeof ( char * ) * AUDITFILTERD_CONF_MAXARGS ) ; am -> am_argc = 0 ; for ( ap = am -> am_argv ; ( * ap = strsep ( & arguments , " \t " ) ) != NULL ; ) { if ( * * ap != ' \0 ' ) { am -> am_argc ++ ; if ( ++ ap >= & am -> am_argv [ AUDITFILTERD_CONF_MAXARGS ] ) break ; } } if ( ap >= & am -> am_argv [ AUDITFILTERD_CONF_MAXARGS ] ) { warnx ( " " , filename , linenumber ) ; auditfilter_module_free ( am ) ; return ( NULL ) ; } return ( am ) ; }
Given a configuration line, generate an auditfilter_module structure that
 describes it; caller will not pass comments in, so they are not looked
 for.
Given a configuration line generate an auditfilter_module structure that describes it ; caller will not pass comments in so they are not looked for .
/*
	 * First, break out the module and arguments strings.  We look for
	 * one extra argument to make sure there are no more :'s in the line.
	 * That way, we prevent modules from using argument strings that, in
	 * the future, may cause problems for adding additional columns.
	 */ /*
	 * Now, break out the arguments string into a series of arguments.
	 * This is a bit more complicated, and requires cleanup if things go
	 * wrong.
	 */