FreeBSD/contrib/openbsm/bin/auditfilterd/auditfilterd_conf.c
/*
 * Apply changes necessary to bring a new configuration into force.  The new
 * configuration data is passed in, and the current configuration is updated
 * to match it.  The contents of 'list' are freed or otherwise disposed of
 * before return.
 *
 * The algorithms here are not very efficient, but this is an infrequent
 * operation on very short lists.
 */
Apply changes necessary to bring a new configuration into force.  The new
configuration data is passed in, and the current configuration is updated
to match it.  The contents of 'list' are freed or otherwise disposed of
before return.

The algorithms here are not very efficient, but this is an infrequent
operation on very short lists.
Apply changes necessary to bring a new configuration into force . The new configuration data is passed in and the current configuration is updated to match it . The contents of ' list ' are freed or otherwise disposed of before return . The algorithms here are not very efficient but this is an infrequent operation on very short lists .
static void
auditfilterd_conf_apply(struct auditfilter_module_list *list)
{
	struct auditfilter_module *am1, *am2, *am_tmp;
	int argc_tmp, found;
	char **argv_tmp;
	TAILQ_FOREACH_SAFE(am1, &filter_list, am_list, am_tmp) {
		found = 0;
		TAILQ_FOREACH(am2, list, am_list) {
			if (strcmp(am1->am_modulename, am2->am_modulename)
			    == 0) {
				found = 1;
				break;
			}
		}
		if (found)
			continue;
		warnx("detaching module %s", am1->am_modulename);
		TAILQ_REMOVE(&filter_list, am1, am_list);
		auditfilter_module_detach(am1);
		auditfilter_module_free(am1);
	}
	TAILQ_FOREACH(am1, &filter_list, am_list) {
		found = 0;
		TAILQ_FOREACH(am2, list, am_list) {
			if (strcmp(am1->am_modulename, am2->am_modulename)
			    == 0) {
				found = 1;
				break;
			}
		}
		if (!found)
			continue;
		argc_tmp = am1->am_argc;
		argv_tmp = am1->am_argv;
		am1->am_argc = am2->am_argc;
		am1->am_argv = am2->am_argv;
		am2->am_argc = argc_tmp;
		am2->am_argv = argv_tmp;
		warnx("reiniting module %s", am1->am_modulename);
		if (auditfilter_module_reinit(am1) != 0) {
			warnx("reinit failed for module %s, detaching",
			    am1->am_modulename);
			TAILQ_REMOVE(&filter_list, am1, am_list);
			auditfilter_module_detach(am1);
			auditfilter_module_free(am1);
		}
		TAILQ_REMOVE(list, am2, am_list);
		auditfilter_module_free(am2);
	}
	TAILQ_FOREACH(am1, list, am_list) {
		found = 0;
		TAILQ_FOREACH(am2, &filter_list, am_list) {
			if (strcmp(am1->am_modulename, am2->am_modulename)
			    == 0) {
				found = 1;
				break;
			}
		}
		if (found)
			continue;
		warnx("attaching module %s", am1->am_modulename);
		TAILQ_REMOVE(list, am1, am_list);
		if (auditfilter_module_attach(am1) != 0) {
			warnx("attaching module %s failed",
			    am1->am_modulename);
			auditfilter_module_free(am1);
		} else
			TAILQ_INSERT_HEAD(&filter_list, am1, am_list);
	}
	if (TAILQ_FIRST(list) != NULL)
		warnx("auditfilterd_conf_apply: new list not empty\n");
}
static void auditfilterd_conf_apply ( struct auditfilter_module_list * list ) { struct auditfilter_module * am1 , * am2 , * am_tmp ; int argc_tmp , found ; char * * argv_tmp ; TAILQ_FOREACH_SAFE ( am1 , & filter_list , am_list , am_tmp ) { found = 0 ; TAILQ_FOREACH ( am2 , list , am_list ) { if ( strcmp ( am1 -> am_modulename , am2 -> am_modulename ) == 0 ) { found = 1 ; break ; } } if ( found ) continue ; warnx ( " " , am1 -> am_modulename ) ; TAILQ_REMOVE ( & filter_list , am1 , am_list ) ; auditfilter_module_detach ( am1 ) ; auditfilter_module_free ( am1 ) ; } TAILQ_FOREACH ( am1 , & filter_list , am_list ) { found = 0 ; TAILQ_FOREACH ( am2 , list , am_list ) { if ( strcmp ( am1 -> am_modulename , am2 -> am_modulename ) == 0 ) { found = 1 ; break ; } } if ( ! found ) continue ; argc_tmp = am1 -> am_argc ; argv_tmp = am1 -> am_argv ; am1 -> am_argc = am2 -> am_argc ; am1 -> am_argv = am2 -> am_argv ; am2 -> am_argc = argc_tmp ; am2 -> am_argv = argv_tmp ; warnx ( " " , am1 -> am_modulename ) ; if ( auditfilter_module_reinit ( am1 ) != 0 ) { warnx ( " " , am1 -> am_modulename ) ; TAILQ_REMOVE ( & filter_list , am1 , am_list ) ; auditfilter_module_detach ( am1 ) ; auditfilter_module_free ( am1 ) ; } TAILQ_REMOVE ( list , am2 , am_list ) ; auditfilter_module_free ( am2 ) ; } TAILQ_FOREACH ( am1 , list , am_list ) { found = 0 ; TAILQ_FOREACH ( am2 , & filter_list , am_list ) { if ( strcmp ( am1 -> am_modulename , am2 -> am_modulename ) == 0 ) { found = 1 ; break ; } } if ( found ) continue ; warnx ( " " , am1 -> am_modulename ) ; TAILQ_REMOVE ( list , am1 , am_list ) ; if ( auditfilter_module_attach ( am1 ) != 0 ) { warnx ( " " , am1 -> am_modulename ) ; auditfilter_module_free ( am1 ) ; } else TAILQ_INSERT_HEAD ( & filter_list , am1 , am_list ) ; } if ( TAILQ_FIRST ( list ) != NULL ) warnx ( " \n " ) ; }
Apply changes necessary to bring a new configuration into force.
Apply changes necessary to bring a new configuration into force .
/*
	 * First, remove remove and detach any entries that appear in the
	 * current configuration, but not the new configuration.
	 */ /*
		 * am1 appears in filter_list, but not the new list, detach
		 * and free the module.
		 */ /*
	 * Next, update the configuration of any modules that appear in both
	 * lists.  We do this by swapping the two argc and argv values and
	 * freeing the new one, rather than detaching the old one and
	 * attaching the new one.  That way module state is preserved.
	 */ /*
		 * Swap the arguments.
		 */ /*
		 * The reinit is a bit tricky: if reinit fails, we actually
		 * remove the old entry and detach that, as we don't allow
		 * running modules to be out of sync with the configuration
		 * file.
		 */ /*
		 * Free the entry from the new list, which will discard the
		 * old arguments.  No need to detach, as it was never
		 * attached in the first place.
		 */ /*
	 * Finally, attach any new entries that don't appear in the old
	 * configuration, and if they attach successfully, move them to the
	 * real configuration list.
	 */ /*
		 * Attach the entry.  If it succeeds, add to filter_list,
		 * otherwise, free.  No need to detach if attach failed.
		 */