[network-manager-libreswan/th/vpn-plugin-debug-bgo766872: 1/22] service: show better error message when /etc/ipsec.d/ does not exist



commit f6e26654dfe82783892e2e156e83a480544c6fba
Author: Thomas Haller <thaller redhat com>
Date:   Fri May 27 11:03:31 2016 +0200

    service: show better error message when /etc/ipsec.d/ does not exist
    
    The service wants to write the secrets there. Show a better error
    message when that fails due to a non-existing target directory.

 src/nm-libreswan-service.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/src/nm-libreswan-service.c b/src/nm-libreswan-service.c
index b5355d5..df28b3e 100644
--- a/src/nm-libreswan-service.c
+++ b/src/nm-libreswan-service.c
@@ -653,6 +653,7 @@ nm_libreswan_config_psk_write (NMSettingVpn *s_vpn,
 {
        const char *pw_type, *psk, *leftid, *right;
        int fd;
+       int errsv;
 
        /* Check for ignored group password */
        pw_type = nm_setting_vpn_get_data_item (s_vpn, NM_LIBRESWAN_PSK_INPUT_MODES);
@@ -667,11 +668,26 @@ nm_libreswan_config_psk_write (NMSettingVpn *s_vpn,
        errno = 0;
        fd = open (secrets_path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
        if (fd < 0) {
+               errsv = errno;
+
+               if (errsv == ENOENT) {
+                       gs_free char *dirname = g_path_get_dirname (secrets_path);
+
+                       if (!g_file_test (dirname, G_FILE_TEST_IS_DIR)) {
+                               g_set_error (error,
+                                            NM_VPN_PLUGIN_ERROR,
+                                            NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED,
+                                            "Failed to open secrets file: no directory %s",
+                                            dirname);
+                               return FALSE;
+                       }
+               }
+
                g_set_error (error,
                             NM_VPN_PLUGIN_ERROR,
                             NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED,
                             "Failed to open secrets file: (%d) %s.",
-                            errno, g_strerror (errno));
+                            errsv, g_strerror (errsv));
                return FALSE;
        }
 


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