summaryrefslogtreecommitdiff
blob: ed366702b1ce237a873936dd90614aedc20a3da6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
From 58944a3ef9c92f7afa07cbb539d062e1956bafc0 Mon Sep 17 00:00:00 2001
From: David Woodhouse <David.Woodhouse@intel.com>
Date: Thu, 30 Oct 2014 23:09:14 +0000
Subject: [PATCH 25/34] Support libopenconnect.so.4

---
 auth-dialog/main.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/auth-dialog/main.c b/auth-dialog/main.c
index 7171247..8285bf4 100644
--- a/auth-dialog/main.c
+++ b/auth-dialog/main.c
@@ -89,6 +89,21 @@
 #define OC_FORM_RESULT_NEWGROUP		2
 #endif
 
+#if OPENCONNECT_CHECK_VER(4,0)
+#define dup_option_value(opt)		g_strdup((opt)->_value);
+#define OC3DUP(x)			(x)
+#define write_config_const		const
+#else
+#define dup_option_value(opt)		g_strdup((opt)->value);
+#define openconnect_set_option_value(opt, val) do { \
+		struct oc_form_opt *_o = (opt);				\
+		free(_o->value); _o->value = g_strdup(val);		\
+	} while (0)
+#define openconnect_free_cert_info(v, x) free(x)
+#define OC3DUP(x)			g_strdup(x)
+#define write_config_const		/* */
+#endif
+
 #ifdef OPENCONNECT_OPENSSL
 #include <openssl/ssl.h>
 #include <openssl/bio.h>
@@ -712,7 +727,7 @@ static gboolean ui_form (struct oc_auth_form *form)
 				data->entry_text = g_strdup (find_form_answer(ui_data->secrets,
 									      form, opt));
 				if (!data->entry_text)
-					data->entry_text = g_strdup (opt->value);
+					data->entry_text = dup_option_value(opt);
 			} else {
 				GHashTable *attrs;
 
@@ -776,8 +791,7 @@ static gboolean set_initial_authgroup (auth_ui_data *ui_data, struct oc_auth_for
 		for (i = 0; i < sopt->nr_choices; i++) {
 			struct oc_choice *ch = FORMCHOICE(sopt, i);
 			if (!strcmp(saved_group, ch->name) && i != AUTHGROUP_SELECTION(form)) {
-				free(opt->value);
-				opt->value = g_strdup(saved_group);
+				openconnect_set_option_value(opt, saved_group);
 				return TRUE;
 			}
 		}
@@ -823,7 +837,7 @@ static int nm_process_auth_form (void *cbdata, struct oc_auth_form *form)
 				g_cancellable_cancel(data->cancel);
 
 			if (data->entry_text) {
-				data->opt->value = g_strdup (data->entry_text);
+				openconnect_set_option_value(data->opt, data->entry_text);
 
 				if (data->opt->type == OC_FORM_OPT_TEXT ||
 				    data->opt->type == OC_FORM_OPT_SELECT) {
@@ -932,7 +946,7 @@ static gboolean user_validate_cert(cert_data *data)
 	text = gtk_text_view_new();
 	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
 	gtk_text_buffer_set_text(buffer, details, -1);
-	free(details);
+	openconnect_free_cert_info(data->ui_data->vpninfo, details);
 	gtk_text_view_set_editable(GTK_TEXT_VIEW(text), 0);
 	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
 	gtk_container_add(GTK_CONTAINER(scroll), text);
@@ -1166,7 +1180,7 @@ static int get_config (GHashTable *options, GHashTable *secrets,
 
 	cafile = g_hash_table_lookup (options, NM_OPENCONNECT_KEY_CACERT);
 	if (cafile)
-		openconnect_set_cafile(vpninfo, g_strdup (cafile));
+		openconnect_set_cafile(vpninfo, OC3DUP (cafile));
 
 	csd = g_hash_table_lookup (options, NM_OPENCONNECT_KEY_CSD_ENABLE);
 	if (csd && !strcmp(csd, "yes")) {
@@ -1176,16 +1190,16 @@ static int get_config (GHashTable *options, GHashTable *secrets,
 		if (csd_wrapper && !csd_wrapper[0])
 			csd_wrapper = NULL;
 
-		openconnect_setup_csd(vpninfo, getuid(), 1, g_strdup (csd_wrapper));
+		openconnect_setup_csd(vpninfo, getuid(), 1, OC3DUP (csd_wrapper));
 	}
 
 	proxy = g_hash_table_lookup (options, NM_OPENCONNECT_KEY_PROXY);
-	if (proxy && proxy[0] && openconnect_set_http_proxy(vpninfo, g_strdup (proxy)))
+	if (proxy && proxy[0] && openconnect_set_http_proxy(vpninfo, OC3DUP (proxy)))
 		return -EINVAL;
 
 	cert = g_hash_table_lookup (options, NM_OPENCONNECT_KEY_USERCERT);
 	sslkey = g_hash_table_lookup (options, NM_OPENCONNECT_KEY_PRIVKEY);
-	openconnect_set_client_cert (vpninfo, g_strdup (cert), g_strdup (sslkey));
+	openconnect_set_client_cert (vpninfo, OC3DUP (cert), OC3DUP (sslkey));
 
 	pem_passphrase_fsid = g_hash_table_lookup (options,
 						   NM_OPENCONNECT_KEY_PEM_PASSPHRASE_FSID);
@@ -1245,7 +1259,7 @@ static int update_token(void *cbdata, const char *tok)
 }
 #endif
 
-static int write_new_config(void *cbdata, char *buf, int buflen)
+static int write_new_config(void *cbdata, write_config_const char *buf, int buflen)
 {
 	auth_ui_data *ui_data = cbdata;
 	g_hash_table_insert (ui_data->secrets, g_strdup ("xmlconfig"),
@@ -1472,11 +1486,11 @@ static void connect_host(auth_ui_data *ui_data)
 	if (openconnect_parse_url(ui_data->vpninfo, host->hostaddress)) {
 		fprintf(stderr, "Failed to parse server URL '%s'\n",
 			host->hostaddress);
-		openconnect_set_hostname (ui_data->vpninfo, g_strdup(host->hostaddress));
+		openconnect_set_hostname (ui_data->vpninfo, OC3DUP (host->hostaddress));
 	}
 
 	if (!openconnect_get_urlpath(ui_data->vpninfo) && host->usergroup)
-		openconnect_set_urlpath(ui_data->vpninfo, g_strdup(host->usergroup));
+		openconnect_set_urlpath(ui_data->vpninfo, OC3DUP (host->usergroup));
 
 
 	g_hash_table_insert (ui_data->success_secrets, g_strdup("lasthost"),
-- 
2.2.0