]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
CSD XML tag and nostub are entirely protocol-specific and used in only one place
authorDaniel Lenski <dlenski@gmail.com>
Mon, 4 May 2020 04:12:12 +0000 (21:12 -0700)
committerDaniel Lenski <dlenski@gmail.com>
Tue, 8 Dec 2020 22:47:40 +0000 (14:47 -0800)
This patch replaces them with inline functions (modeled after gpst_os_name),
instead of storing them in the global `struct openconnect_info` object.

TODO: further clarify, separate, and consolidate protocol-specific data in
`struct openconnect_info`.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
auth.c
library.c
openconnect-internal.h

diff --git a/auth.c b/auth.c
index 9756018b6d5a423896db22390f92031ab57d91d8..643cfc61863fd828678ab4c984510f2548d8975f 100644 (file)
--- a/auth.c
+++ b/auth.c
@@ -386,6 +386,29 @@ static int xmlnode_get_text(xmlNode *xml_node, const char *name, char **var)
  * 2) The new <form> tag tends to omit the method/action properties.
  */
 
+/* Translate platform names (derived from AnyConnect) into the relevant
+ * CSD tag names
+ */
+static inline const char *csd_tag_name(struct openconnect_info *vpninfo)
+{
+       if (!strcmp(vpninfo->platname, "mac-intel"))
+               return "csdMac";
+       else if (!strcmp(vpninfo->platname, "win"))
+               return "csd";
+       else
+               /* linux, linux-64, android, apple-ios */
+               return "csdLinux";
+}
+
+/* Ignore stubs on mobile platforms */
+static inline int csd_use_stub(struct openconnect_info *vpninfo)
+{
+       if (!strcmp(vpninfo->platname, "android") || !strcmp(vpninfo->platname, "apple-ios"))
+               return 0;
+       else
+               return 1;
+}
+
 static int parse_auth_node(struct openconnect_info *vpninfo, xmlNode *xml_node,
                           struct oc_auth_form *form)
 {
@@ -434,9 +457,9 @@ static int parse_auth_node(struct openconnect_info *vpninfo, xmlNode *xml_node,
                   nodes; one with token/ticket and one with the URLs. Process them both
                   the same and rely on the fact that xmlnode_get_prop() will not *clear*
                   the variable if no such property is found. */
-               if (!vpninfo->csd_scriptname && xmlnode_is_named(xml_node, vpninfo->csd_xmltag)) {
+               if (!vpninfo->csd_scriptname && xmlnode_is_named(xml_node, csd_tag_name(vpninfo))) {
                        /* ignore the CSD trojan binary on mobile platforms */
-                       if (!vpninfo->csd_nostub)
+                       if (csd_use_stub(vpninfo))
                                xmlnode_get_prop(xml_node, "stuburl", &vpninfo->csd_stuburl);
                        xmlnode_get_prop(xml_node, "starturl", &vpninfo->csd_starturl);
                        xmlnode_get_prop(xml_node, "waiturl", &vpninfo->csd_waiturl);
index 4146e8f1828f8a18a97546a1b5bd96fa1de4afad..bf8402d35a0c35f5047d87539152d32071d9c746 100644 (file)
--- a/library.c
+++ b/library.c
@@ -305,18 +305,6 @@ int openconnect_set_reported_os(struct openconnect_info *vpninfo,
 #endif
        }
 
-       if (!strcmp(os, "mac-intel"))
-               vpninfo->csd_xmltag = "csdMac";
-       else if (!strcmp(os, "linux") || !strcmp(os, "linux-64"))
-               vpninfo->csd_xmltag = "csdLinux";
-       else if (!strcmp(os, "android") || !strcmp(os, "apple-ios")) {
-               vpninfo->csd_xmltag = "csdLinux";
-               vpninfo->csd_nostub = 1;
-       } else if (!strcmp(os, "win"))
-               vpninfo->csd_xmltag = "csd";
-       else
-               return -EINVAL;
-
        STRDUP(vpninfo->platname, os);
        return 0;
 }
index 0db75b272b82cef70604acaf840a59a6c913a9ac..e67ac26c9716c4ad16f759d496065053a09c465d 100644 (file)
@@ -393,8 +393,6 @@ struct openconnect_info {
        uint32_t esp_magic;  /* GlobalProtect magic ping address (network-endian) */
 
        int tncc_fd; /* For Juniper TNCC */
-       const char *csd_xmltag;
-       int csd_nostub;
        char *platname;
        char *mobile_platform_version;
        char *mobile_device_type;
@@ -1065,7 +1063,7 @@ int do_gen_hotp_code(struct openconnect_info *vpninfo,
                     struct oc_auth_form *form,
                     struct oc_form_opt *opt);
 
-int set_oidc_token(struct openconnect_info *vpninfo, 
+int set_oidc_token(struct openconnect_info *vpninfo,
                     const char *token_str);
 
 /* stoken.c */