svn rev #24116: branches/plugins/src/ lib/kadm5/srv/ plugin_core/ plugin_core/impl/ ...

tsitkova@MIT.EDU tsitkova at MIT.EDU
Thu Jun 3 13:07:01 EDT 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=24116
Commit By: tsitkova
Log Message:
To prevent crash in case when conf file does not know about pwd_qlty plugin.




Changed Files:
U   branches/plugins/src/lib/kadm5/srv/server_misc.c
U   branches/plugins/src/plugin_core/impl/plugin_default_factory.c
U   branches/plugins/src/plugin_core/impl/plugin_default_manager.c
U   branches/plugins/src/plugin_core/impl/plugin_default_manager.h
U   branches/plugins/src/plugin_core/plugin_factory.c
U   branches/plugins/src/plugin_core/plugin_manager.c
U   branches/plugins/src/plugin_core/plugin_manager.h
U   branches/plugins/src/plugins/pwd_qlty/plugin_pwd_qlty.c
Modified: branches/plugins/src/lib/kadm5/srv/server_misc.c
===================================================================
--- branches/plugins/src/lib/kadm5/srv/server_misc.c	2010-05-31 16:11:06 UTC (rev 24115)
+++ branches/plugins/src/lib/kadm5/srv/server_misc.c	2010-06-03 17:07:01 UTC (rev 24116)
@@ -48,12 +48,17 @@
              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");
+        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);
-
+        ret = plugin_pwd_qlty_check(plugin_handle,
+                                    srv_handle, password, use_policy, pol, principal);
+    }
     return ret;
 }

Modified: branches/plugins/src/plugin_core/impl/plugin_default_factory.c
===================================================================
--- branches/plugins/src/plugin_core/impl/plugin_default_factory.c	2010-05-31 16:11:06 UTC (rev 24115)
+++ branches/plugins/src/plugin_core/impl/plugin_default_factory.c	2010-06-03 17:07:01 UTC (rev 24116)
@@ -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},

Modified: branches/plugins/src/plugin_core/impl/plugin_default_manager.c
===================================================================
--- branches/plugins/src/plugin_core/impl/plugin_default_manager.c	2010-05-31 16:11:06 UTC (rev 24115)
+++ branches/plugins/src/plugin_core/impl/plugin_default_manager.c	2010-06-03 17:07:01 UTC (rev 24116)
@@ -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 @@
     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 @@
     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 @@
 #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 @@
             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 @@
     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 @@
     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 @@
     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 @@
             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 @@
             krb5_free_plugin_string(profile, plugin);
         }
     }
-
 }
 
 #endif

Modified: branches/plugins/src/plugin_core/impl/plugin_default_manager.h
===================================================================
--- branches/plugins/src/plugin_core/impl/plugin_default_manager.h	2010-05-31 16:11:06 UTC (rev 24115)
+++ branches/plugins/src/plugin_core/impl/plugin_default_manager.h	2010-06-03 17:07:01 UTC (rev 24116)
@@ -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_ */

Modified: branches/plugins/src/plugin_core/plugin_factory.c
===================================================================
--- branches/plugins/src/plugin_core/plugin_factory.c	2010-05-31 16:11:06 UTC (rev 24115)
+++ branches/plugins/src/plugin_core/plugin_factory.c	2010-06-03 17:07:01 UTC (rev 24116)
@@ -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;
 }

Modified: branches/plugins/src/plugin_core/plugin_manager.c
===================================================================
--- branches/plugins/src/plugin_core/plugin_manager.c	2010-05-31 16:11:06 UTC (rev 24115)
+++ branches/plugins/src/plugin_core/plugin_manager.c	2010-06-03 17:07:01 UTC (rev 24116)
@@ -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;
 }
 
 

Modified: branches/plugins/src/plugin_core/plugin_manager.h
===================================================================
--- branches/plugins/src/plugin_core/plugin_manager.h	2010-05-31 16:11:06 UTC (rev 24115)
+++ branches/plugins/src/plugin_core/plugin_manager.h	2010-06-03 17:07:01 UTC (rev 24116)
@@ -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*);

Modified: branches/plugins/src/plugins/pwd_qlty/plugin_pwd_qlty.c
===================================================================
--- branches/plugins/src/plugins/pwd_qlty/plugin_pwd_qlty.c	2010-05-31 16:11:06 UTC (rev 24115)
+++ branches/plugins/src/plugins/pwd_qlty/plugin_pwd_qlty.c	2010-06-03 17:07:01 UTC (rev 24116)
@@ -12,8 +12,9 @@
 {
     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 @@
 {
     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;
 }
 




More information about the cvs-krb5 mailing list