Re: [PATCH] Support default path for importing openvpn configuration file
- From: "Bin Li" <libin charles gmail com>
- To: "Dan Williams" <dcbw redhat com>, networkmanager-list gnome org
- Subject: Re: [PATCH] Support default path for importing openvpn configuration file
- Date: Sat, 25 Oct 2008 07:37:56 +0800
On Sat, Oct 25, 2008 at 5:36 AM, Dan Williams <dcbw redhat com> wrote:
> On Fri, 2008-10-24 at 23:41 +0800, Bin Li wrote:
>> On Fri, Oct 24, 2008 at 10:53 PM, Dan Williams <dcbw redhat com> wrote:
>> > On Fri, 2008-10-24 at 11:36 +0300, Tambet Ingo wrote:
>> >> It leaks 'default_path' variable in do_import(). I'd also use
>> >> g_build_filename() in handle_path_item() in case the path isn't
>> >> absolute.
>> >
>> > Yeah, other than that, looks good though. If you could post it again
>> > when this is cleaned up, then we can commit.
>>
>> Tambet, do you commit your change? Do you need I change it like your said?
>
> Yeah, if you could provide an updated patch that would be great.
Update the new patch. Feel free to change it, :)
> Thanks!
> Dan
>
>
>
--- import-export.c.orig 2008-09-16 10:53:41.000000000 +0800
+++ import-export.c 2008-10-25 07:33:22.000000000 +0800
@@ -61,9 +61,10 @@
const char *tag,
const char *key,
GHashTable *hash,
+ const char *path,
char **leftover)
{
- char *tmp, *file, *unquoted, *p;
+ char *tmp, *file, *unquoted, *p, *full_path;
gboolean quoted = FALSE;
if (leftover)
@@ -77,6 +78,12 @@
if (!strlen (file))
goto out;
+ /* If file isn't an absolute file name, add the default path */
+ if (!g_path_is_absolute (file)) {
+ full_path = g_build_filename (path, file);
+ file = full_path;
+ }
+
/* Simple unquote */
if ((file[0] == '"') || (file[0] == '\'')) {
quoted = TRUE;
@@ -108,6 +115,8 @@
out:
g_free (tmp);
+ if (full_path)
+ g_free (full_path);
return TRUE;
}
@@ -162,6 +171,7 @@
gboolean have_client = FALSE, have_remote = FALSE;
gboolean have_pass = FALSE, have_sk = FALSE;
const char *ctype = NULL;
+ char *default_path;
connection = nm_connection_new ();
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
@@ -170,6 +180,10 @@
s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
s_vpn->service_type = g_strdup (NM_DBUS_SERVICE_OPENVPN);
+ /* Get the default path for ca, cert, key file, these files maybe
+ * in same path with the configuration file */
+ default_path = g_path_get_dirname (path);
+
s_con->id = g_path_get_basename (path);
last_dot = strrchr (s_con->id, '.');
if (last_dot)
@@ -252,17 +266,17 @@
continue;
}
- if (handle_path_item (*line, CA_TAG, NM_OPENVPN_KEY_CA, s_vpn->data, NULL))
+ if (handle_path_item (*line, CA_TAG, NM_OPENVPN_KEY_CA, s_vpn->data, default_path, NULL))
continue;
- if (handle_path_item (*line, CERT_TAG, NM_OPENVPN_KEY_CERT, s_vpn->data, NULL))
+ if (handle_path_item (*line, CERT_TAG, NM_OPENVPN_KEY_CERT, s_vpn->data, default_path, NULL))
continue;
- if (handle_path_item (*line, KEY_TAG, NM_OPENVPN_KEY_KEY, s_vpn->data, NULL))
+ if (handle_path_item (*line, KEY_TAG, NM_OPENVPN_KEY_KEY, s_vpn->data, default_path, NULL))
continue;
if (handle_path_item (*line, SECRET_TAG, NM_OPENVPN_KEY_STATIC_KEY,
- s_vpn->data, &leftover)) {
+ s_vpn->data, default_path, &leftover)) {
handle_direction ("secret",
NM_OPENVPN_KEY_STATIC_KEY_DIRECTION,
leftover,
@@ -271,7 +285,7 @@
}
if (handle_path_item (*line, TLS_AUTH_TAG, NM_OPENVPN_KEY_TA,
- s_vpn->data, &leftover)) {
+ s_vpn->data, default_path, &leftover)) {
handle_direction ("tls-auth",
NM_OPENVPN_KEY_TA_DIR,
leftover,
@@ -315,6 +329,9 @@
have_pass = TRUE;
}
+ if (default_path)
+ g_free (default_path);
+
if (g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_STATIC_KEY))
have_sk = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]