Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NetworkManager-l2tp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CeRiAl
NetworkManager-l2tp
Commits
19e9cb4b
Commit
19e9cb4b
authored
Feb 28, 2012
by
Сергей Прохоров
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add "import connection" feature (has no strong validation)
parent
8ac3474e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
30 deletions
+113
-30
import-export.c
properties/import-export.c
+102
-7
import-export.h
properties/import-export.h
+1
-1
ipsec-dialog.c
properties/ipsec-dialog.c
+2
-4
nm-l2tp.c
properties/nm-l2tp.c
+8
-18
No files found.
properties/import-export.c
View file @
19e9cb4b
...
@@ -112,11 +112,104 @@ static VpnImportExportProperty vpn_properties[] = {
...
@@ -112,11 +112,104 @@ static VpnImportExportProperty vpn_properties[] = {
{
NULL
,
G_TYPE_NONE
,
FALSE
}
{
NULL
,
G_TYPE_NONE
,
FALSE
}
};
};
/**
* Create new L2TP VPN connection using data from .ini - like file located at #path
*
* Returns: a newly allocated #NMConnection on success or %NULL on failure
**/
NMConnection
*
NMConnection
*
do_import
(
const
char
*
path
,
char
**
lines
,
GError
**
error
)
do_import
(
const
char
*
path
,
GError
**
error
)
{
{
return
NULL
;
NMConnection
*
connection
=
NULL
;
NMSettingConnection
*
s_con
;
NMSettingVPN
*
s_vpn
;
NMSettingIP4Config
*
s_ip4
;
GKeyFile
*
keyfile
;
int
i
;
keyfile
=
g_key_file_new
();
if
(
!
g_key_file_load_from_file
(
keyfile
,
path
,
0
,
error
))
{
g_set_error
(
error
,
0
,
0
,
_
(
"does not look like a L2TP VPN connection (parse failed)"
));
return
NULL
;
}
connection
=
nm_connection_new
();
s_con
=
NM_SETTING_CONNECTION
(
nm_setting_connection_new
());
nm_connection_add_setting
(
connection
,
NM_SETTING
(
s_con
));
s_vpn
=
NM_SETTING_VPN
(
nm_setting_vpn_new
());
g_object_set
(
s_vpn
,
NM_SETTING_VPN_SERVICE_TYPE
,
NM_DBUS_SERVICE_L2TP
,
NULL
);
nm_connection_add_setting
(
connection
,
NM_SETTING
(
s_vpn
));
s_ip4
=
NM_SETTING_IP4_CONFIG
(
nm_setting_ip4_config_new
());
nm_connection_add_setting
(
connection
,
NM_SETTING
(
s_ip4
));
/* g_message("Start importing L2TP."); */
for
(
i
=
0
;
vpn_properties
[
i
].
name
;
i
++
){
VpnImportExportProperty
prop
=
vpn_properties
[
i
];
int
int_val
;
gboolean
bool_val
;
char
*
value
;
if
(
!
g_key_file_has_key
(
keyfile
,
VPN_SECTION
,
prop
.
name
,
error
)){
if
(
!
prop
.
required
)
continue
;
g_set_error
(
error
,
0
,
0
,
_
(
"Required property %s missing"
),
prop
.
name
);
g_key_file_free
(
keyfile
);
g_object_unref
(
connection
);
return
NULL
;
}
switch
(
prop
.
type
)
{
case
G_TYPE_STRING
:
value
=
g_key_file_get_string
(
keyfile
,
VPN_SECTION
,
prop
.
name
,
error
);
break
;
case
G_TYPE_UINT
:
int_val
=
g_key_file_get_integer
(
keyfile
,
VPN_SECTION
,
prop
.
name
,
error
);
if
(
int_val
==
0
&&
*
error
){
g_set_error
(
error
,
0
,
0
,
_
(
"Property %s can't be parsed as integer."
),
prop
.
name
);
g_key_file_free
(
keyfile
);
g_object_unref
(
connection
);
return
NULL
;
}
value
=
g_strdup_printf
(
"%d"
,
int_val
);
break
;
case
G_TYPE_BOOLEAN
:
bool_val
=
g_key_file_get_boolean
(
keyfile
,
VPN_SECTION
,
prop
.
name
,
error
);
if
(
!
bool_val
&&
!
(
*
error
))
continue
;
if
(
!
bool_val
)
{
g_set_error
(
error
,
0
,
0
,
_
(
"Property %s can't be parsed as boolean. Only 'true' and 'false' allowed."
),
prop
.
name
);
g_key_file_free
(
keyfile
);
g_object_unref
(
connection
);
return
NULL
;
}
value
=
g_strdup
(
"yes"
);
break
;
}
/* TODO: add custom validators for int and string fields there, add special
"validator_flag" field to #vpn_properties and
then use switch "case validator_flag: validation_function() ..." */
/* g_message("Import [%s]%s = %s", VPN_SECTION, prop.name, value); */
nm_setting_vpn_add_data_item
(
s_vpn
,
prop
.
name
,
value
);
g_free
(
value
);
}
/* g_message("Imported L2TP."); */
return
connection
;
}
}
/**
/**
...
@@ -170,10 +263,12 @@ do_export (const char *path, NMConnection *connection, GError **error)
...
@@ -170,10 +263,12 @@ do_export (const char *path, NMConnection *connection, GError **error)
g_key_file_set_string
(
export_file
,
VPN_SECTION
,
prop
.
name
,
value
);
g_key_file_set_string
(
export_file
,
VPN_SECTION
,
prop
.
name
,
value
);
break
;
break
;
case
G_TYPE_BOOLEAN
:
case
G_TYPE_BOOLEAN
:
g_key_file_set_boolean
(
export_file
,
if
(
!
strcmp
(
value
,
"yes"
))
VPN_SECTION
,
g_key_file_set_boolean
(
export_file
,
prop
.
name
,
VPN_SECTION
,
!
strcmp
(
value
,
"yes"
)
?
TRUE
:
FALSE
);
prop
.
name
,
TRUE
);
/* if key not set - assume as "no" */
break
;
break
;
}
}
}
}
...
...
properties/import-export.h
View file @
19e9cb4b
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
#include <glib.h>
#include <glib.h>
#include <nm-connection.h>
#include <nm-connection.h>
NMConnection
*
do_import
(
const
char
*
path
,
char
**
lines
,
GError
**
error
);
NMConnection
*
do_import
(
const
char
*
path
,
GError
**
error
);
gboolean
do_export
(
const
char
*
path
,
NMConnection
*
connection
,
GError
**
error
);
gboolean
do_export
(
const
char
*
path
,
NMConnection
*
connection
,
GError
**
error
);
...
...
properties/ipsec-dialog.c
View file @
19e9cb4b
...
@@ -187,11 +187,9 @@ ipsec_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
...
@@ -187,11 +187,9 @@ ipsec_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
hash
=
g_hash_table_new_full
(
g_str_hash
,
g_str_equal
,
g_free
,
g_free
);
hash
=
g_hash_table_new_full
(
g_str_hash
,
g_str_equal
,
g_free
,
g_free
);
widget
=
GTK_WIDGET
(
gtk_builder_get_object
(
builder
,
"ipsec_enable"
));
widget
=
GTK_WIDGET
(
gtk_builder_get_object
(
builder
,
"ipsec_enable"
));
if
(
gtk_toggle_button_get_active
(
GTK_TOGGLE_BUTTON
(
widget
)))
{
if
(
gtk_toggle_button_get_active
(
GTK_TOGGLE_BUTTON
(
widget
)))
g_hash_table_insert
(
hash
,
g_strdup
(
NM_L2TP_KEY_IPSEC_ENABLE
),
g_strdup
(
"yes"
));
g_hash_table_insert
(
hash
,
g_strdup
(
NM_L2TP_KEY_IPSEC_ENABLE
),
g_strdup
(
"yes"
));
}
else
{
g_hash_table_insert
(
hash
,
g_strdup
(
NM_L2TP_KEY_IPSEC_ENABLE
),
g_strdup
(
"no"
));
}
widget
=
GTK_WIDGET
(
gtk_builder_get_object
(
builder
,
"ipsec_gateway_id"
));
widget
=
GTK_WIDGET
(
gtk_builder_get_object
(
builder
,
"ipsec_gateway_id"
));
g_hash_table_insert
(
hash
,
g_strdup
(
NM_L2TP_KEY_IPSEC_GATEWAY_ID
),
g_hash_table_insert
(
hash
,
g_strdup
(
NM_L2TP_KEY_IPSEC_GATEWAY_ID
),
g_strdup
(
gtk_entry_get_text
(
GTK_ENTRY
(
widget
))));
g_strdup
(
gtk_entry_get_text
(
GTK_ENTRY
(
widget
))));
...
...
properties/nm-l2tp.c
View file @
19e9cb4b
...
@@ -723,8 +723,6 @@ static NMConnection *
...
@@ -723,8 +723,6 @@ static NMConnection *
import
(
NMVpnPluginUiInterface
*
iface
,
const
char
*
path
,
GError
**
error
)
import
(
NMVpnPluginUiInterface
*
iface
,
const
char
*
path
,
GError
**
error
)
{
{
NMConnection
*
connection
=
NULL
;
NMConnection
*
connection
=
NULL
;
char
*
contents
=
NULL
;
char
**
lines
=
NULL
;
char
*
ext
;
char
*
ext
;
ext
=
strrchr
(
path
,
'.'
);
ext
=
strrchr
(
path
,
'.'
);
...
@@ -733,35 +731,27 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
...
@@ -733,35 +731,27 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
L2TP_PLUGIN_UI_ERROR
,
L2TP_PLUGIN_UI_ERROR
,
L2TP_PLUGIN_UI_ERROR_FILE_NOT_L2TP
,
L2TP_PLUGIN_UI_ERROR_FILE_NOT_L2TP
,
_
(
"unknown L2TP file extension"
));
_
(
"unknown L2TP file extension"
));
goto
out
;
return
NULL
;
}
}
if
(
strcmp
(
ext
,
".conf"
)
&&
strcmp
(
ext
,
".cnf"
))
{
if
(
strcmp
(
ext
,
".conf"
)
&&
strcmp
(
ext
,
".cnf"
))
{
g_set_error
(
error
,
g_set_error
(
error
,
L2TP_PLUGIN_UI_ERROR
,
L2TP_PLUGIN_UI_ERROR
,
L2TP_PLUGIN_UI_ERROR_FILE_NOT_L2TP
,
L2TP_PLUGIN_UI_ERROR_FILE_NOT_L2TP
,
_
(
"unknown L2TP file extension"
));
_
(
"unknown L2TP file extension. Allowed .conf or .cnf"
));
goto
out
;
}
if
(
!
g_file_get_contents
(
path
,
&
contents
,
NULL
,
error
))
return
NULL
;
return
NULL
;
}
lines
=
g_strsplit_set
(
contents
,
"
\r\n
"
,
0
);
if
(
!
strstr
(
path
,
"l2tp"
))
{
if
(
g_strv_length
(
lines
)
<=
1
)
{
g_set_error
(
error
,
g_set_error
(
error
,
L2TP_PLUGIN_UI_ERROR
,
L2TP_PLUGIN_UI_ERROR
,
L2TP_PLUGIN_UI_ERROR_FILE_NOT_
READABLE
,
L2TP_PLUGIN_UI_ERROR_FILE_NOT_
L2TP
,
_
(
"
not a valid L2TP configuration file
"
));
_
(
"
Filename doesn't contains 'l2tp' substring.
"
));
goto
out
;
return
NULL
;
}
}
connection
=
do_import
(
path
,
lines
,
error
);
connection
=
do_import
(
path
,
error
);
out:
if
(
lines
)
g_strfreev
(
lines
);
g_free
(
contents
);
return
connection
;
return
connection
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment