Skip to content

Commit

Permalink
To prevent crash in case when conf file does not know about pwd_qlty …
Browse files Browse the repository at this point in the history
…plugin.

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/plugins@24116 dc483132-0cff-0310-8789-dd5450dbe970
  • Loading branch information
tsitkova committed Jun 3, 2010
1 parent c0c9465 commit c6e4908
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 79 deletions.
13 changes: 9 additions & 4 deletions src/lib/kadm5/srv/server_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ passwd_check(kadm5_server_handle_t srv_handle,
char *password, int use_policy, kadm5_policy_ent_t pol,
krb5_principal principal)
{
plhandle plugin_handle;
int ret = KADM5_OK;

int ret = 0;
if (srv_handle != NULL && srv_handle->context != NULL &&
srv_handle->context->pl_handle != NULL ){

plhandle plugin_handle = plugin_manager_get_service(srv_handle->context->pl_handle, "plugin_pwd_qlty");

ret = plugin_pwd_qlty_check(plugin_handle, srv_handle, password, use_policy, pol, principal);
plugin_handle = plugin_manager_get_service(srv_handle->context->pl_handle,
"plugin_pwd_qlty");

ret = plugin_pwd_qlty_check(plugin_handle,
srv_handle, password, use_policy, pol, principal);
}
return ret;
}
2 changes: 0 additions & 2 deletions src/plugin_core/impl/plugin_default_factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

#include "plugin_manager.h"
#include "plugin_factory.h"
//#include "plugin_prng_impl.h"
#include "plugin_pa_impl.h"
#include "plugin_pwd_qlty_impl.h"
#include "plugin_default_factory.h"

static plugin_factory* _default_factory_instance = NULL;

static plugin_descr plugin_default_factory_table[] = {
// {"plugin_yarrow_prng", plugin_yarrow_prng_create},
{"plugin_pwd_qlty_krb", plugin_pwd_qlty_krb_create},
{"plugin_encrypted_challenge_pa", plugin_encrypted_challenge_pa_create},
{"plugin_ldap_audit", NULL},
Expand Down
47 changes: 25 additions & 22 deletions src/plugin_core/impl/plugin_default_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include "krb5_parser.h"
#endif


//static plugin_manager* _instance = NULL;

static plugin_factory_descr _table[] = {
{"plugin_default_factory", plugin_default_factory_get_instance},
{NULL, NULL}
Expand Down Expand Up @@ -84,14 +81,22 @@ _create_api(const char* plugin_name, const char* factory_name,
return(p_handle);
}

#define API_REGISTER_OK 0
#define API_REGISTER_FAILED 1
#define API_ALREADY_REGISTERED 2

/* _register_api - returns API_REGISTER_OK on success,
* API_REGISTER_FAILED - on failure,
* API_ALREADY_REGISTERED if api is already registered
*/
static int
_register_api(registry_data* data, const char* api_name,
const char* plugin_type, plhandle handle)
{
const int extension_size = 32;
reg_entry* entry = NULL;
plhandle* next;
int ret = 0;
int ret = API_REGISTER_FAILED;

if(data->registry_size == data->registry_max_size) {
_extend_registry(data, extension_size);
Expand All @@ -105,7 +110,7 @@ _register_api(registry_data* data, const char* api_name,
#ifdef DEBUG_PLUGINS
printf("%s is already registered, only one plugin is allowed per service\n", api_name);
#endif
ret = 2;
ret = API_ALREADY_REGISTERED;
} else {
strcpy(entry->api_name, api_name);
next = (plhandle*) malloc(sizeof(plhandle));
Expand All @@ -119,13 +124,13 @@ _register_api(registry_data* data, const char* api_name,
entry->last = next;
}
entry->size++;
ret = 1;
ret = API_REGISTER_OK;
}
return ret;
}

#ifdef CONFIG_IN_YAML
static void
static int
_configure_plugin_yaml(manager_data* mdata, config_node* plugin_node)
{
config_node* p = NULL;
Expand All @@ -136,7 +141,7 @@ _configure_plugin_yaml(manager_data* mdata, config_node* plugin_node)
const char* plugin_name = NULL;
const char* plugin_type = NULL;
plhandle handle;
int ret = 0;
int ret = API_REGISTER_FAILED;

for (p = plugin_node->node_value.seq_value.start; p != NULL; p = p->next) {
if(strcmp(p->node_name, "api") == 0) {
Expand Down Expand Up @@ -171,25 +176,23 @@ _configure_plugin_yaml(manager_data* mdata, config_node* plugin_node)
handle = _create_api(plugin_name, factory_name, factory_type/*, properties*/);
if(handle.api != NULL) {
ret = _register_api(mdata->registry,plugin_api, plugin_type, handle);
if (ret != 1) {
if (ret != API_REGISTER_OK) {
#ifdef DEBUG_PLUGINS
printf("Failed to register %s for %s(factory=%s,plugin_type=%s)\n",
plugin_name, plugin_api, factory_name, plugin_type);
#endif
if (ret == 0) exit(1);
}
} else {
#ifdef DEBUG_PLUGINS
printf("Failed to configure plugin: api=%s, plugin_name=%s,factory=%s\n",
plugin_api, plugin_name, factory_name);
#endif

}
return;
return ret;
}

/* Plugin API implementation */
static void
static int
_configure_yaml(void* data, const char* path)
{
manager_data* mdata = (manager_data*) data;
Expand Down Expand Up @@ -228,18 +231,20 @@ _configure_krb5(manager_data* data, const char* path)
char **factory_name, **factory_type, **plugin_name, **plugin_type;
plhandle handle;

// retval = os_get_default_config_files(&files, FALSE); // TRUE - goes to /etc/krb5.conf
retval = krb5_get_default_config_files(&files); // TRUE - goes to /etc/krb5.conf
retval = profile_init((const_profile_filespec_t *) files, &profile);
/* if (files)
retval = krb5_get_default_config_files(&files);
#if 0
if (files)
free_filespecs(files);
if (retval)
ctx->profile = 0;
*/
#endif

if (retval == ENOENT)
return; // KRB5_CONFIG_CANTOPEN;

retval = profile_init((const_profile_filespec_t *) files, &profile);
if (retval == ENOENT)
return;

if ((retval = krb5_plugin_iterator_create(profile, &iter))) {
com_err("krb5_PLUGIN_iterator_create", retval, 0);
Expand Down Expand Up @@ -285,12 +290,11 @@ _configure_krb5(manager_data* data, const char* path)
handle = _create_api(*plugin_name, *factory_name, *factory_type/*, properties*/);
if(handle.api != NULL) {
retval = _register_api(mdata->registry,plugin, *plugin_type, handle);
if( retval != 1) {
if( retval != API_REGISTER_OK) {
#ifdef DEBUG_PLUGINS
printf("Failed to register %s for %s(factory=%s,plugin_type=%s)\n",
*plugin_name, plugin, *factory_name, *plugin_type);
#endif
if (retval == 0) exit(1);
}
} else {
#ifdef DEBUG_PLUGINS
Expand All @@ -302,7 +306,6 @@ _configure_krb5(manager_data* data, const char* path)
krb5_free_plugin_string(profile, plugin);
}
}

}

#endif
Expand Down
19 changes: 0 additions & 19 deletions src/plugin_core/impl/plugin_default_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,7 @@
#define PLUGIN_DEFAULT_MANAGER_H_

#include <plugin_manager.h>
#if 0
typedef struct {
char api_name[512];
plhandle* first;
plhandle* last;
int size;
} reg_entry;

typedef struct {
reg_entry* table;
long registry_size;
long registry_max_size;
} registry_data;

typedef struct {
registry_data* registry;
} manager_data;
#endif

plugin_manager* plugin_default_manager_get_instance(plugin_manager** plugin_mngr_instance);
//plugin_manager* plugin_default_manager_get_instance(void);

#endif /* PLUGIN_DEFAULT_MANAGER_H_ */
14 changes: 10 additions & 4 deletions src/plugin_core/plugin_factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
void
get_factory_content (factory_handle handle, const char* container[])
{
plugin_factory* factory = (plugin_factory*) handle.api;
factory->get_factory_content(container);
plugin_factory* factory = (plugin_factory*) handle.api;
if (factory != NULL) {
return factory->get_factory_content(container);
}
return;
}

plhandle
create_api (factory_handle handle, const char* plugin_name)
{
plugin_factory* factory = (plugin_factory*) handle.api;
return factory->create_api(plugin_name);
plugin_factory* factory = (plugin_factory*) handle.api;
if (factory != NULL) {
return factory->create_api(plugin_name);
}
return;
}
43 changes: 20 additions & 23 deletions src/plugin_core/plugin_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,45 @@
*/
#include "plugin_manager.h"
#include <k5-int.h>
#include "string.h"


//static plugin_manager* _instance = NULL;

void
set_plugin_manager_instance(plugin_manager **_instance, plugin_manager* manager) {
*_instance = manager;
set_plugin_manager_instance(plugin_manager **_instance, plugin_manager* manager)
{
*_instance = manager;
}

void
int
plugin_manager_configure(plugin_manager* _instance,const char* path)
{
if(_instance != NULL) {
_instance->configure(_instance->data, path);
}
if (_instance != NULL) {
_instance->configure(_instance->data, path);
}
}

void plugin_manager_start(plugin_manager* _instance)
{
if(_instance != NULL) {
_instance->start(_instance->data);
}
if (_instance != NULL) {
_instance->start(_instance->data);
}
}

void plugin_manager_stop(plugin_manager* _instance)
{
if(_instance != NULL) {
_instance->stop(_instance->data);
}
if (_instance != NULL) {
_instance->stop(_instance->data);
}
}

plhandle
plugin_manager_get_service(plugin_manager* _instance, const char* service_name)
{
plhandle handle;
if(_instance != NULL) {
handle = _instance->getService(_instance->data, service_name);
} else {
handle.api = NULL;
}
return handle;
plhandle handle;
if (_instance != NULL) {
handle = _instance->getService(_instance->data, service_name);
} else {
handle.api = NULL;
}
return handle;
}


Expand Down
2 changes: 1 addition & 1 deletion src/plugin_core/plugin_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
void set_plugin_manager_instance(plugin_manager** _instance,plugin_manager*);

/* Utility functions */
void plugin_manager_configure(plugin_manager* _instance,const char*);
int plugin_manager_configure(plugin_manager* _instance,const char*);
void plugin_manager_start(plugin_manager* _instance);
void plugin_manager_stop(plugin_manager* _instance);
plhandle plugin_manager_get_service(plugin_manager* _instance,const char*);
Expand Down
10 changes: 6 additions & 4 deletions src/plugins/pwd_qlty/plugin_pwd_qlty.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ plugin_pwd_qlty_check(plhandle handle, kadm5_server_handle_t srv_handle,
{
kadm5_ret_t ret = KADM5_OK;
plugin_pwd_qlty* api = (plugin_pwd_qlty*) handle.api;
ret = api->pwd_qlty_check(srv_handle, password, use_policy, pol, principal);

if (api != NULL) {
ret = api->pwd_qlty_check(srv_handle, password, use_policy, pol, principal);
}
return ret;
}

Expand All @@ -23,8 +24,9 @@ plugin_pwd_qlty_init(plhandle handle, kadm5_server_handle_t srv_handle)
{
kadm5_ret_t ret = KADM5_OK;
plugin_pwd_qlty* api = (plugin_pwd_qlty*) handle.api;
ret = api->pwd_qlty_init(srv_handle);

if (api != NULL) {
ret = api->pwd_qlty_init(srv_handle);
}
return ret;
}

Expand Down

0 comments on commit c6e4908

Please sign in to comment.