[network-manager-openswan/dcbw/libreswan: 1/16] core: make find_ipsec() generic



commit 6bd86093fead65744324bbedb731ad760fc21fa6
Author: Dan Williams <dcbw redhat com>
Date:   Mon Oct 20 14:05:47 2014 -0500

    core: make find_ipsec() generic

 src/nm-openswan-service.c |   48 ++++++++++++++++++++++++++++----------------
 1 files changed, 30 insertions(+), 18 deletions(-)
---
diff --git a/src/nm-openswan-service.c b/src/nm-openswan-service.c
index a35e4d7..35821ee 100644
--- a/src/nm-openswan-service.c
+++ b/src/nm-openswan-service.c
@@ -255,28 +255,40 @@ nm_openswan_secrets_validate (NMSettingVPN *s_vpn, GError **error)
 static gboolean connect_step (NMOpenSwanPlugin *self, GError **error);
 static gboolean pr_cb (GIOChannel *source, GIOCondition condition, gpointer user_data);
 
-static const char *ipsec_paths[] =
-{
-       "/usr/sbin/ipsec",
-       "/sbin/ipsec",
-       "/usr/local/sbin/ipsec",
-       NULL
-};
-
 static const char *
-find_ipsec (GError **error)
+find_helper (const char *progname, GError **error)
 {
+       static const char *paths[] = {
+               PREFIX "/sbin/",
+               PREFIX "/bin/",
+               "/sbin/",
+               "/usr/sbin/",
+               "/usr/local/sbin/",
+               "/usr/bin/",
+               "/usr/local/bin/",
+       };
        guint i;
-
-       for (i = 0; i < G_N_ELEMENTS (ipsec_paths); i++) {
-               if (g_file_test (ipsec_paths[i], G_FILE_TEST_EXISTS))
-                       return ipsec_paths[i];
+       GString *tmp;
+       const char *ret;
+
+       if (error)
+               g_return_val_if_fail (*error == NULL, NULL);
+
+       tmp = g_string_sized_new (50);
+       for (i = 0; i < G_N_ELEMENTS (paths); i++) {
+               g_string_append_printf (tmp, "%s%s", paths[i], progname);
+               if (g_file_test (tmp->str, G_FILE_TEST_EXISTS)) {
+                       ret = g_intern_string (tmp->str);
+                       g_string_free (tmp, TRUE);
+                       return ret;
+               }
+               g_string_set_size (tmp, 0);
        }
+       g_string_free (tmp, TRUE);
 
-       g_set_error_literal (error,
-                            NM_VPN_PLUGIN_ERROR,
-                            NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED,
-                            "Could not find ipsec binary.");
+       g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED,
+                    "Could not find %s binary",
+                    progname);
        return NULL;
 }
 
@@ -978,7 +990,7 @@ _connect_common (NMVPNPlugin   *plugin,
                return FALSE;
        }
 
-       priv->ipsec_path = find_ipsec (error);
+       priv->ipsec_path = find_helper ("ipsec", error);
        if (!priv->ipsec_path)
                return FALSE;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]