get_interface(krb5_context context, int id)
{
if (context == NULL || id < 0 || id >= PLUGIN_NUM_INTERFACES)
- return NULL;
+ return NULL;
return &context->plugins[id];
}
free_plugin_mapping(struct plugin_mapping *map)
{
if (map == NULL)
- return;
+ return;
free(map->modname);
if (map->dyn_handle != NULL)
- krb5int_close_plugin(map->dyn_handle);
+ krb5int_close_plugin(map->dyn_handle);
free(map);
}
/* If a mapping already exists for modname, remove it. */
for (pmap = &interface->modules; *pmap != NULL; pmap = &(*pmap)->next) {
- map = *pmap;
- if (strcmp(map->modname, modname) == 0) {
- *pmap = map->next;
- free_plugin_mapping(map);
- break;
- }
+ map = *pmap;
+ if (strcmp(map->modname, modname) == 0) {
+ *pmap = map->next;
+ free_plugin_mapping(map);
+ break;
+ }
}
/* Create a new mapping structure. */
map = malloc(sizeof(*map));
if (map == NULL)
- return ENOMEM;
+ return ENOMEM;
map->modname = strdup(modname);
if (map->modname == NULL) {
- free(map);
- return ENOMEM;
+ free(map);
+ return ENOMEM;
}
map->module = module;
map->dyn_handle = dyn_handle;
* component parts. */
static krb5_error_code
parse_modstr(krb5_context context, const char *modstr,
- char **modname, char **modpath)
+ char **modname, char **modpath)
{
const char *sep;
char *name = NULL, *path = NULL;
sep = strchr(modstr, ':');
if (sep == NULL) {
- krb5_set_error_message(context, EINVAL, "Invalid module string %s",
- modstr);
- return EINVAL; /* XXX create specific error code */
+ krb5_set_error_message(context, EINVAL, "Invalid module string %s",
+ modstr);
+ return EINVAL; /* XXX create specific error code */
}
/* Copy the module name. */
name = malloc(sep - modstr + 1);
if (name == NULL)
- return ENOMEM;
+ return ENOMEM;
memcpy(name, modstr, sep - modstr);
name[sep - modstr] = '\0';
/* Copy the module path. */
path = strdup(sep + 1);
if (path == NULL) {
- free(name);
- return ENOMEM;
+ free(name);
+ return ENOMEM;
}
*modname = name;
* the resulting init function as modname. */
static krb5_error_code
open_and_register(krb5_context context, struct plugin_interface *interface,
- const char *modname, const char *modpath,
- const char *symname)
+ const char *modname, const char *modpath,
+ const char *symname)
{
krb5_error_code ret;
struct plugin_file_handle *handle;
ret = krb5int_open_plugin(modpath, &handle, &context->err);
if (ret != 0)
- return ret;
+ return ret;
ret = krb5int_get_plugin_func(handle, symname, &initvt_fn, &context->err);
if (ret != 0) {
- krb5int_close_plugin(handle);
- return ret;
+ krb5int_close_plugin(handle);
+ return ret;
}
ret = register_module(context, interface, modname,
(krb5_plugin_initvt_fn)initvt_fn, handle);
if (ret != 0)
- krb5int_close_plugin(handle);
+ krb5int_close_plugin(handle);
return ret;
}
/* Register the plugins given by the profile strings in modules. */
static krb5_error_code
register_dyn_modules(krb5_context context, struct plugin_interface *interface,
- const char *iname, char **modules)
+ const char *iname, char **modules)
{
krb5_error_code ret;
char *modname = NULL, *modpath = NULL, *symname = NULL;
for (; *modules != NULL; modules++) {
- ret = parse_modstr(context, *modules, &modname, &modpath);
- if (ret != 0)
- return ret;
+ ret = parse_modstr(context, *modules, &modname, &modpath);
+ if (ret != 0)
+ return ret;
if (asprintf(&symname, "%s_%s_initvt", iname, modname) < 0) {
- free(modname);
- free(modpath);
- return ENOMEM;
- }
- /* XXX should errors here be fatal, or just ignore the module? */
- ret = open_and_register(context, interface, modname, modpath, symname);
- free(modname);
- free(modpath);
- free(symname);
- if (ret != 0)
- return ret;
+ free(modname);
+ free(modpath);
+ return ENOMEM;
+ }
+ /* XXX should errors here be fatal, or just ignore the module? */
+ ret = open_and_register(context, interface, modname, modpath, symname);
+ free(modname);
+ free(modpath);
+ free(symname);
+ if (ret != 0)
+ return ret;
}
return 0;
}
find_in_list(char **list, const char *value)
{
for (; *list != NULL; list++) {
- if (strcmp(*list, value) == 0)
- return TRUE;
+ if (strcmp(*list, value) == 0)
+ return TRUE;
}
return FALSE;
}
/* Remove any registered modules whose names are not present in enable. */
static void
filter_enable(krb5_context context, struct plugin_interface *interface,
- char **enable)
+ char **enable)
{
struct plugin_mapping *map, **pmap;
pmap = &interface->modules;
while (*pmap != NULL) {
- map = *pmap;
- if (!find_in_list(enable, map->modname)) {
- *pmap = map->next;
- free_plugin_mapping(map);
- } else
- pmap = &map->next;
+ map = *pmap;
+ if (!find_in_list(enable, map->modname)) {
+ *pmap = map->next;
+ free_plugin_mapping(map);
+ } else
+ pmap = &map->next;
}
}
/* Remove any registered modules whose names are present in disable. */
static void
filter_disable(krb5_context context, struct plugin_interface *interface,
- char **disable)
+ char **disable)
{
struct plugin_mapping *map, **pmap;
pmap = &interface->modules;
while (*pmap != NULL) {
- map = *pmap;
- if (find_in_list(disable, map->modname)) {
- *pmap = map->next;
- free_plugin_mapping(map);
- } else
- pmap = &map->next;
+ map = *pmap;
+ if (find_in_list(disable, map->modname)) {
+ *pmap = map->next;
+ free_plugin_mapping(map);
+ } else
+ pmap = &map->next;
}
}
static const char *path[4];
if (interface->configured)
- return 0;
+ return 0;
/* Read the configuration variables for this interface. */
path[0] = KRB5_CONF_PLUGINS;
goto cleanup;
if (modules != NULL) {
- ret = register_dyn_modules(context, interface, iname, modules);
- if (ret != 0)
- return ret;
+ ret = register_dyn_modules(context, interface, iname, modules);
+ if (ret != 0)
+ return ret;
}
if (enable != NULL)
- filter_enable(context, interface, enable);
+ filter_enable(context, interface, enable);
if (disable != NULL)
- filter_disable(context, interface, disable);
+ filter_disable(context, interface, disable);
ret = 0;
cleanup:
struct plugin_mapping *map;
if (interface == NULL)
- return EINVAL;
+ return EINVAL;
ret = configure_interface(context, interface_id);
if (ret != 0)
- return ret;
+ return ret;
for (map = interface->modules; map != NULL; map = map->next) {
- if (strcmp(map->modname, modname) == 0) {
- *module = map->module;
- return 0;
- }
+ if (strcmp(map->modname, modname) == 0) {
+ *module = map->module;
+ return 0;
+ }
}
return ENOENT; /* XXX Create error code? */
}
size_t count;
if (interface == NULL)
- return EINVAL;
+ return EINVAL;
ret = configure_interface(context, interface_id);
if (ret != 0)
- return ret;
+ return ret;
/* Count the modules and allocate a list to hold them. */
count = 0;
for (map = interface->modules; map != NULL; map = map->next)
- count++;
+ count++;
list = malloc((count + 1) * sizeof(*list));
if (list == NULL)
- return ENOMEM;
+ return ENOMEM;
/* Place each module's initvt function into list. */
count = 0;
for (map = interface->modules; map != NULL; map = map->next)
- list[count++] = map->module;
+ list[count++] = map->module;
list[count] = NULL;
*modules = list;
struct plugin_interface *interface = get_interface(context, interface_id);
if (interface == NULL)
- return EINVAL;
+ return EINVAL;
/* Disallow registering plugins after load. We may need to reconsider
* this, but it simplifies the design. */
if (interface->configured)
- return EINVAL;
+ return EINVAL;
return register_module(context, interface, modname, module, NULL);
}
struct plugin_mapping *map, *next;
for (i = 0; i < PLUGIN_NUM_INTERFACES; i++) {
- interface = &context->plugins[i];
- for (map = interface->modules; map != NULL; map = next) {
- next = map->next;
- free_plugin_mapping(map);
- }
- interface->modules = NULL;
- interface->configured = FALSE;
+ interface = &context->plugins[i];
+ for (map = interface->modules; map != NULL; map = next) {
+ next = map->next;
+ free_plugin_mapping(map);
+ }
+ interface->modules = NULL;
+ interface->configured = FALSE;
}
}