handle plugin loading failures
authorMartin Willi <martin@strongswan.org>
Tue, 1 Sep 2009 14:20:45 +0000 (16:20 +0200)
committerMartin Willi <martin@strongswan.org>
Tue, 1 Sep 2009 14:20:45 +0000 (16:20 +0200)
src/charon/daemon.c
src/charon/plugins/sql/pool.c
src/manager/main.c
src/medsrv/main.c
src/openac/openac.c
src/pki/pki.c
src/pluto/plutomain.c
src/scepclient/scepclient.c

index 0689c44..cf2b1c7 100644 (file)
@@ -491,8 +491,11 @@ static bool initialize(private_daemon_t *this, bool syslog, level_t levels[])
        this->public.traps = trap_manager_create();
        
        /* load plugins, further infrastructure may need it */
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, 
-               lib->settings->get_str(lib->settings, "charon.load", PLUGINS));
+       if (!lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, 
+                       lib->settings->get_str(lib->settings, "charon.load", PLUGINS)))
+       {
+               return FALSE;
+       }
        
        print_plugins();
 
index 6c0c1f5..ef119c9 100644 (file)
@@ -634,20 +634,23 @@ int main(int argc, char *argv[])
                fprintf(stderr, "integrity check of pool failed\n");
                exit(SS_RC_DAEMON_INTEGRITY);
        }
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
-               lib->settings->get_str(lib->settings, "pool.load", PLUGINS));
+       if (!lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
+                       lib->settings->get_str(lib->settings, "pool.load", PLUGINS)))
+       {
+               exit(SS_RC_INITIALIZATION_FAILED);
+       }
        
        uri = lib->settings->get_str(lib->settings, "charon.plugins.sql.database", NULL);
        if (!uri)
        {
                fprintf(stderr, "database URI charon.plugins.sql.database not set.\n");
-               exit(-1);
+               exit(SS_RC_INITIALIZATION_FAILED);
        }
        db = lib->db->create(lib->db, uri);
        if (!db)
        {
                fprintf(stderr, "opening database failed.\n");
-               exit(-1);
+               exit(SS_RC_INITIALIZATION_FAILED);
        }
        atexit(cleanup);
        
@@ -677,7 +680,7 @@ int main(int argc, char *argv[])
                switch (c)
                {
                        case EOF:
-                       break;
+                               break;
                        case 'h':
                                break;
                        case 'w':
index 6fef0bf..3d2c4de 100644 (file)
@@ -35,8 +35,11 @@ int main (int arc, char *argv[])
        int threads, timeout;
 
        library_init(STRONGSWAN_CONF);
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
-               lib->settings->get_str(lib->settings, "manager.load", PLUGINS));
+       if (!lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
+                       lib->settings->get_str(lib->settings, "manager.load", PLUGINS)))
+       {
+               return 1;
+       }
        
        socket = lib->settings->get_str(lib->settings, "manager.socket", NULL);
        debug = lib->settings->get_bool(lib->settings, "manager.debug", FALSE);
index 20dec9d..e4f8783 100644 (file)
@@ -34,8 +34,11 @@ int main(int arc, char *argv[])
        int timeout, threads;
        
        library_init(STRONGSWAN_CONF);
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
-           lib->settings->get_str(lib->settings, "medsrv.load", PLUGINS));
+       if (!lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
+                       lib->settings->get_str(lib->settings, "medsrv.load", PLUGINS)))
+       {
+               return 1;
+       }
        
        socket = lib->settings->get_str(lib->settings, "medsrv.socket", NULL);
        debug = lib->settings->get_bool(lib->settings, "medsrv.debug", FALSE);
index db99598..d6e75ef 100755 (executable)
@@ -220,20 +220,22 @@ int main(int argc, char **argv)
        openlog("openac", 0, LOG_AUTHPRIV);
 
        /* initialize library */
+       atexit(library_deinit);
        if (!library_init(STRONGSWAN_CONF))
        {
-               library_deinit();
                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
        }
        if (lib->integrity &&
                !lib->integrity->check_file(lib->integrity, "openac", argv[0]))
        {
                fprintf(stderr, "integrity check of openac failed\n");
-               library_deinit();
                exit(SS_RC_DAEMON_INTEGRITY);
        }
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, 
-               lib->settings->get_str(lib->settings, "openac.load", PLUGINS));
+       if (!lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, 
+                       lib->settings->get_str(lib->settings, "openac.load", PLUGINS)))
+       {
+               exit(SS_RC_INITIALIZATION_FAILED);
+       }
 
        /* initialize optionsfrom */
        options_t *options = options_create();
index 13f2627..a612a1b 100644 (file)
@@ -747,8 +747,11 @@ int main(int argc, char *argv[])
                fprintf(stderr, "integrity check of pki failed\n");
                exit(SS_RC_DAEMON_INTEGRITY);
        }
-       lib->plugins->load(lib->plugins, PLUGINDIR,
-               lib->settings->get_str(lib->settings, "pki.load", PLUGINS));
+       if (!lib->plugins->load(lib->plugins, PLUGINDIR,
+                       lib->settings->get_str(lib->settings, "pki.load", PLUGINS)))
+       {
+               exit(SS_RC_INITIALIZATION_FAILED);
+       }
        
        switch (getopt_long(argc, argv, "", long_opts, NULL))
        {
index b3d75e8..550bda9 100644 (file)
@@ -652,8 +652,11 @@ int main(int argc, char **argv)
        }
 
        /* load plugins, further infrastructure may need it */
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, 
-               lib->settings->get_str(lib->settings, "pluto.load", PLUGINS));
+       if (!lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, 
+                       lib->settings->get_str(lib->settings, "pluto.load", PLUGINS)))
+       {
+               exit(SS_RC_INITIALIZATION_FAILED);
+       }
        print_plugins();
 
        init_builder();
index e01997c..f2b49f2 100644 (file)
@@ -759,8 +759,11 @@ int main(int argc, char **argv)
        init_log("scepclient");
 
        /* load plugins, further infrastructure may need it */
-       lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, 
-               lib->settings->get_str(lib->settings, "scepclient.load", PLUGINS));
+       if (!lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR, 
+                       lib->settings->get_str(lib->settings, "scepclient.load", PLUGINS)))
+       {
+               exit_scepclient("plugin loading failed");
+       }
        print_plugins();
 
        if ((filetype_out == 0) && (!request_ca_certificate))