Code

sysdb: Fixed a memory leak on EOF from the server.
[sysdb.git] / src / tools / sysdbd / configfile.c
index 9c7308d1bc2d0c1bd8efd172f128922c2193db61..31bfd9bae4375c8ad86507615a010acee09e0943 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_CONFIG_H
+#      include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #include "tools/sysdbd/configfile.h"
 
 #include "sysdb.h"
@@ -61,6 +65,7 @@ enum {
  */
 
 static sdb_time_t default_interval = 0;
+static char *plugin_dir = NULL;
 
 /*
  * private helper functions
@@ -148,6 +153,19 @@ daemon_set_interval(oconfig_item_t *ci)
        return config_get_interval(ci, &default_interval);
 } /* daemon_set_interval */
 
+static int
+daemon_set_plugindir(oconfig_item_t *ci)
+{
+       if (oconfig_get_string(ci, &plugin_dir)) {
+               sdb_log(SDB_LOG_ERR, "config: PluginDir requires a single "
+                               "string argument\n"
+                               "\tUsage: PluginDir DIR");
+               return ERR_INVALID_ARG;
+       }
+       plugin_dir = strdup(plugin_dir);
+       return 0;
+} /* daemon_set_plugindir */
+
 static int
 daemon_load_plugin(oconfig_item_t *ci)
 {
@@ -172,7 +190,7 @@ daemon_load_plugin(oconfig_item_t *ci)
        }
 
        /* returns a negative value on error */
-       return sdb_plugin_load(name, NULL);
+       return sdb_plugin_load(plugin_dir, name, NULL);
 } /* daemon_load_plugin */
 
 static int
@@ -180,7 +198,7 @@ daemon_load_backend(oconfig_item_t *ci)
 {
        sdb_plugin_ctx_t ctx = SDB_PLUGIN_CTX_INIT;
 
-       char  plugin_name[1024];
+       char plugin_name[1024];
        char *name;
 
        int i;
@@ -211,12 +229,13 @@ daemon_load_backend(oconfig_item_t *ci)
                }
        }
 
-       return sdb_plugin_load(plugin_name, &ctx);
+       return sdb_plugin_load(plugin_dir, plugin_name, &ctx);
 } /* daemon_load_backend */
 
 static int
 daemon_configure_plugin(oconfig_item_t *ci)
 {
+       char plugin_name[1024];
        char *name;
 
        assert(ci);
@@ -224,17 +243,22 @@ daemon_configure_plugin(oconfig_item_t *ci)
        if (oconfig_get_string(ci, &name)) {
                sdb_log(SDB_LOG_ERR, "config: %s requires a single "
                                "string argument\n"
-                               "\tUsage: LoadBackend BACKEND",
-                               ci->key);
+                               "\tUsage: <%s NAME>...</%s>",
+                               ci->key, ci->key, ci->key);
                return ERR_INVALID_ARG;
        }
 
-       return sdb_plugin_configure(name, ci);
+       if (!strcasecmp(ci->key, "Backend"))
+               snprintf(plugin_name, sizeof(plugin_name), "Backend::%s", name);
+       else
+               strncpy(plugin_name, name, sizeof(plugin_name));
+       return sdb_plugin_configure(plugin_name, ci);
 } /* daemon_configure_backend */
 
 static token_parser_t token_parser_list[] = {
        { "Listen", daemon_add_listener },
        { "Interval", daemon_set_interval },
+       { "PluginDir", daemon_set_plugindir },
        { "LoadPlugin", daemon_load_plugin },
        { "LoadBackend", daemon_load_backend },
        { "Backend", daemon_configure_plugin },
@@ -246,6 +270,22 @@ static token_parser_t token_parser_list[] = {
  * public API
  */
 
+void
+daemon_free_listen_addresses(void)
+{
+       size_t i;
+
+       if (! listen_addresses)
+               return;
+
+       for (i = 0; i < listen_addresses_num; ++i)
+               free(listen_addresses[i]);
+       free(listen_addresses);
+
+       listen_addresses = NULL;
+       listen_addresses_num = 0;
+} /* daemon_free_listen_addresses */
+
 int
 daemon_parse_config(const char *filename)
 {
@@ -277,6 +317,14 @@ daemon_parse_config(const char *filename)
                        retval = status;
                }
        }
+
+       oconfig_free(ci);
+       free(ci);
+
+       if (plugin_dir) {
+               free(plugin_dir);
+               plugin_dir = NULL;
+       }
        return retval;
 } /* daemon_parse_config */