]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
To prevent crash in case when conf file does not know about pwd_qlty plugin
authorZhanna Tsitkov <tsitkova@mit.edu>
Thu, 3 Jun 2010 17:07:01 +0000 (17:07 +0000)
committerZhanna Tsitkov <tsitkova@mit.edu>
Thu, 3 Jun 2010 17:07:01 +0000 (17:07 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/plugins@24116 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/kadm5/srv/server_misc.c
src/plugin_core/impl/plugin_default_factory.c
src/plugin_core/impl/plugin_default_manager.c
src/plugin_core/impl/plugin_default_manager.h
src/plugin_core/plugin_factory.c
src/plugin_core/plugin_manager.c
src/plugin_core/plugin_manager.h
src/plugins/pwd_qlty/plugin_pwd_qlty.c

index 3f51c0d7d3027ce3d9ac357c98ebf868e2725801..d89699a17ca32d39f088ce6c44ee646298fb9edd 100644 (file)
@@ -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;
 }
index a006cabd7eaae6439020458f8efc2659ee891b96..1711240d5219c2ff87e6c21aa17ac0d0160e11dd 100644 (file)
@@ -8,7 +8,6 @@
 
 #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"
@@ -16,7 +15,6 @@
 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},
index c1c0de1edf14d2670be307e6b86312d08b406919..7bddeb2c05bd0de7da6a9b508b476e8c1f142317 100644 (file)
@@ -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}
@@ -84,6 +81,14 @@ _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)
@@ -91,7 +96,7 @@ _register_api(registry_data* data, const char* api_name,
     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);
@@ -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));
@@ -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;
@@ -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) {
@@ -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;
@@ -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);
@@ -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
@@ -302,7 +306,6 @@ _configure_krb5(manager_data* data, const char* path)
             krb5_free_plugin_string(profile, plugin);
         }
     }
-
 }
 
 #endif
index 2c539fe2c4072ea58753424e3bf100c314a145de..1df5c9ba45b9d1d56519a2609e2e178cf5e807f2 100644 (file)
@@ -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_ */
index 255883f2cc4d8cf442bac76bdbf92b1e6aceeb44..6bbb9ec685d332c80dbdbd94dff3be4f698ed2de 100644 (file)
@@ -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;
 }
index 599abd503f082686df539fcddd63239e308bc259..2ce0c1a30507c7177029ed5f243420318e8c1a78 100644 (file)
@@ -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;
 }
 
 
index 8a4bda9cc7d7be63b0908a8ec69e53f07d2bd707..4f1afe2b10c453044c46b9699610ef50075b1f25 100644 (file)
@@ -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*);
index 2306be51333f7c6e855ef12bdf37848dfaf6eb29..6103c8443397af5a8529c0ab0720f17acf5dc7f1 100644 (file)
@@ -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;
 }
 
@@ -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;
 }