File nm-openvpn-sscanf.patch of Package NetworkManager-openvpn
commit 27192957d887915a23f186a34c3bb85af3faba3a
Author: Dan Williams <dcbw@redhat.com>
Date: Tue Jul 14 06:51:33 2009 -0400
don't use sscanf
besides the fact that for some reason sscanf wasn't working, it's evil
and confusing, and we don't even need to use it. Also add the ability
to set OPENVPN_DEBUG to get more info out of openvpn.
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 346df20..6cde642 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -287,6 +287,35 @@ ovpn_quote_string (const char *unquoted)
return quoted;
}
+/* sscanf is evil, and since we can't use glib regexp stuff since it's still
+ * too new for some distros, do a simple match here.
+ */
+static char *
+get_detail (const char *input, const char *prefix)
+{
+ char *ret = NULL;
+ guint32 i = 0;
+ const char *p, *start;
+
+ g_return_val_if_fail (prefix != NULL, NULL);
+
+ if (!g_str_has_prefix (input, prefix))
+ return NULL;
+
+ /* Grab characters until the next ' */
+ p = start = input + strlen (prefix);
+ while (*p) {
+ if (*p == '\'') {
+ ret = g_malloc0 (i + 1);
+ strncpy (ret, start, i);
+ break;
+ }
+ p++, i++;
+ }
+
+ return ret;
+}
+
static gboolean
handle_management_socket (NMVPNPlugin *plugin,
GIOChannel *source,
@@ -295,7 +324,7 @@ handle_management_socket (NMVPNPlugin *plugin,
{
NMOpenvpnPluginIOData *io_data = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin)->io_data;
gboolean again = TRUE;
- char *str = NULL, *auth, *buf;
+ char *str = NULL, *auth = NULL, *buf;
gsize written;
if (!(condition & G_IO_IN))
@@ -307,7 +336,8 @@ handle_management_socket (NMVPNPlugin *plugin,
if (strlen (str) < 1)
goto out;
- if (sscanf (str, ">PASSWORD:Need '%a[^']'", &auth) > 0) {
+ auth = get_detail (str, ">PASSWORD:Need '");
+ if (auth) {
if (strcmp (auth, "Auth") == 0) {
if (io_data->username != NULL && io_data->password != NULL) {
char *quser, *qpass;
@@ -351,8 +381,11 @@ handle_management_socket (NMVPNPlugin *plugin,
*out_failure = NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED;
again = FALSE;
}
- free (auth);
- } else if (sscanf (str, ">PASSWORD:Verification Failed: '%a[^']'", &auth) > 0) {
+ g_free (auth);
+ }
+
+ auth = get_detail (str, ">PASSWORD:Verification Failed: '");
+ if (auth) {
if (!strcmp (auth, "Auth"))
nm_warning ("Password verification failed");
else if (!strcmp (auth, "Private Key"))
@@ -360,7 +393,7 @@ handle_management_socket (NMVPNPlugin *plugin,
else
nm_warning ("Unknown verification failed: %s", auth);
- free (auth);
+ g_free (auth);
if (out_failure)
*out_failure = NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED;
@@ -688,6 +721,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
add_openvpn_arg (args, "--auth");
add_openvpn_arg (args, auth);
}
+ add_openvpn_arg (args, "--auth-nocache");
/* TA */
tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TA);
@@ -700,9 +734,14 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
add_openvpn_arg (args, tmp);
}
- /* Syslog */
- add_openvpn_arg (args, "--syslog");
- add_openvpn_arg (args, "nm-openvpn");
+ if (getenv ("OPENVPN_DEBUG")) {
+ add_openvpn_arg (args, "--verb");
+ add_openvpn_arg (args, "10");
+ } else {
+ /* Syslog */
+ add_openvpn_arg (args, "--syslog");
+ add_openvpn_arg (args, "nm-openvpn");
+ }
/* Punch script security in the face; this option was added to OpenVPN 2.1-rc9
* and defaults to disallowing any scripts, a behavior change from previous