dispatcher: pass CONNECTION_FILENAME to dispatcher scripts
authorDan Winship <danw@redhat.com>
Tue, 16 Dec 2014 19:08:38 +0000 (14:08 -0500)
committerDan Winship <danw@redhat.com>
Mon, 12 Jan 2015 14:53:21 +0000 (09:53 -0500)
callouts/nm-dispatcher-api.h
callouts/nm-dispatcher-utils.c
callouts/tests/dispatcher-old-down
callouts/tests/dispatcher-old-up
callouts/tests/dispatcher-old-vpn-down
callouts/tests/dispatcher-old-vpn-up
callouts/tests/test-dispatcher-envp.c
man/NetworkManager.xml
src/nm-dispatcher.c

index df1bced..9b2c3b3 100644 (file)
@@ -31,6 +31,7 @@
 #define NM_DISPATCHER_DBUS_PATH      "/org/freedesktop/nm_dispatcher"
 
 #define NMD_CONNECTION_PROPS_PATH         "path"
+#define NMD_CONNECTION_PROPS_FILENAME     "filename"
 
 #define NMD_DEVICE_PROPS_INTERFACE        "interface"
 #define NMD_DEVICE_PROPS_IP_INTERFACE     "ip-interface"
index 99616c1..e84b566 100644 (file)
@@ -334,6 +334,7 @@ nm_dispatcher_utils_construct_envp (const char *action,
 {
        const char *iface = NULL, *ip_iface = NULL;
        const char *uuid = NULL, *id = NULL, *path;
+       const char *filename = NULL;
        NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN;
        GVariant *value;
        char **envp = NULL, *path_item;
@@ -349,6 +350,10 @@ nm_dispatcher_utils_construct_envp (const char *action,
        if (!strcmp (action, "hostname"))
                goto done;
 
+       /* config filename */
+       if (g_variant_lookup (connection_props, NMD_CONNECTION_PROPS_FILENAME, "&s", &filename))
+               items = g_slist_prepend (items, g_strdup_printf ("CONNECTION_FILENAME=%s", filename));
+
        /* Canonicalize the VPN interface name; "" is used when passing it through
         * D-Bus so make sure that's fixed up here.
         */
index 836f353..8098085 100644 (file)
@@ -15,6 +15,7 @@ path=/org/freedesktop/NetworkManager/Devices/0
 PATH=
 CONNECTION_UUID=3fd2a33a-d81b-423f-ae99-e6baba742311
 CONNECTION_ID=Random Connection
+CONNECTION_FILENAME=/callouts/tests/dispatcher-old-down
 DEVICE_IFACE=wlan0
 DEVICE_IP_IFACE=wlan0
 
index 53f35ac..e4eb8e6 100644 (file)
@@ -34,6 +34,7 @@ domains=hsd1.mn.comcast.net.
 PATH=
 CONNECTION_UUID=3fd2a33a-d81b-423f-ae99-e6baba742311
 CONNECTION_ID=Random Connection
+CONNECTION_FILENAME=/callouts/tests/dispatcher-old-up
 DEVICE_IFACE=wlan0
 DEVICE_IP_IFACE=wlan0
 IP4_ADDRESS_0=192.168.1.119/24 192.168.1.1
index 1f1cf2b..e702445 100644 (file)
@@ -34,6 +34,7 @@ domains=hsd1.mn.comcast.net.
 PATH=
 CONNECTION_UUID=355653c0-34d3-4777-ad25-f9a498b7ef8e
 CONNECTION_ID=Random Connection
+CONNECTION_FILENAME=/callouts/tests/dispatcher-old-vpn-down
 DEVICE_IFACE=wlan0
 DEVICE_IP_IFACE=tun0
 IP4_ADDRESS_0=192.168.1.119/24 192.168.1.1
index 7cda8a6..619c6fe 100644 (file)
@@ -34,6 +34,7 @@ domains=hsd1.mn.comcast.net.
 PATH=
 CONNECTION_UUID=355653c0-34d3-4777-ad25-f9a498b7ef8e
 CONNECTION_ID=Random Connection
+CONNECTION_FILENAME=/callouts/tests/dispatcher-old-vpn-up
 DEVICE_IFACE=wlan0
 DEVICE_IP_IFACE=tun0
 IP4_ADDRESS_0=192.168.1.119/24 192.168.1.1
index 460174b..a715b62 100644 (file)
@@ -34,6 +34,7 @@
 
 static gboolean
 parse_main (GKeyFile *kf,
+            const char *filename,
             GVariant **out_con_dict,
             GVariant **out_con_props,
             char **out_expected_iface,
@@ -82,6 +83,11 @@ parse_main (GKeyFile *kf,
        g_variant_builder_add (&props, "{sv}",
                               "connection-path",
                               g_variant_new_object_path ("/org/freedesktop/NetworkManager/Connections/5"));
+       /* Strip out the non-fixed portion of the filename */
+       filename = strstr (filename, "/callouts");
+       g_variant_builder_add (&props, "{sv}",
+                              "filename",
+                              g_variant_new_string (filename));
        *out_con_props = g_variant_builder_end (&props);
 
        return TRUE;
@@ -358,6 +364,7 @@ get_dispatcher_file (const char *file,
                return FALSE;
 
        if (!parse_main (kf,
+                        file,
                         out_con_dict,
                         out_con_props,
                         out_expected_iface,
index d1a807f..26f84e5 100644 (file)
             The name (ID) of the connection profile.
           </para></listitem>
         </varlistentry>
+        <varlistentry>
+          <term><varname>CONNECTION_FILENAME</varname></term>
+          <listitem><para>
+            The backing file name of the connection profile (if any).
+          </para></listitem>
+        </varlistentry>
         <varlistentry>
           <term><varname>DEVICE_IFACE</varname></term>
           <listitem><para>
index ae45176..4e20026 100644 (file)
@@ -37,6 +37,7 @@
 #include "nm-dhcp6-config.h"
 #include "nm-dbus-glib-types.h"
 #include "nm-glib-compat.h"
+#include "nm-settings-connection.h"
 
 #define CALL_TIMEOUT (1000 * 60 * 10)  /* 10 minutes for all scripts */
 
@@ -474,6 +475,7 @@ _dispatcher_call (DispatcherAction action,
 
        if (connection) {
                GVariant *connection_dict;
+               const char *filename;
 
                connection_dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_NO_SECRETS);
                connection_hash = nm_utils_connection_dict_to_hash (connection_dict);
@@ -483,6 +485,12 @@ _dispatcher_call (DispatcherAction action,
                value_hash_add_object_path (connection_props,
                                            NMD_CONNECTION_PROPS_PATH,
                                            nm_connection_get_path (connection));
+               filename = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection));
+               if (filename) {
+                       value_hash_add_str (connection_props,
+                                           NMD_CONNECTION_PROPS_FILENAME,
+                                           filename);
+               }
        } else {
                connection_hash = value_hash_create ();
                connection_props = value_hash_create ();