OpenVAS Scanner 22.7.9
user_agent.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Greenbone AG
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
11#include "user_agent.h"
12
13#include "ipc_openvas.h"
14#include "plugutils.h" /* plug_get_host_fqdn */
15#include "vendorversion.h"
16
17#include <glib.h>
18#include <gvm/base/prefs.h> /* for prefs_get */
19
20#undef G_LOG_DOMAIN
24#define G_LOG_DOMAIN "lib misc"
25
29static gchar *user_agent = NULL;
30
31static void
33{
34 struct ipc_data *ua = NULL;
35 const char *json = NULL;
36
38 json = ipc_data_to_json (ua);
39 ipc_data_destroy (&ua);
40 if (ipc_send (ipc_context, IPC_MAIN, json, strlen (json)) < 0)
41 g_warning ("Unable to send %s to host process", user_agent);
42}
43
52static void
54{
55 gchar *ua = NULL;
56
57 ua = get_plugin_preference ("1.3.6.1.4.1.25623.1.0.12288", "HTTP User-Agent",
58 -1);
59 if (!ua || strlen (g_strstrip (ua)) == 0)
60 {
61 g_free (ua);
62 if (!vendor_version_get () || *vendor_version_get () == '\0')
63 ua = g_strdup_printf ("Mozilla/5.0 [en] (X11, U; OpenVAS-VT %s)",
64 OPENVAS_MISC_VERSION);
65 else
66 ua = g_strdup_printf ("Mozilla/5.0 [en] (X11, U; %s)",
68 }
69
70 user_agent = ua;
71}
72
84gchar *
85user_agent_set (const gchar *ua)
86{
87 gchar *ua_aux = NULL;
88
89 ua_aux = g_strdup (user_agent);
90
91 if (ua != NULL && ua[0] != '\0')
92 {
93 g_free (user_agent);
94 user_agent = g_strdup (ua);
95 }
96
97 return ua_aux;
98}
99
105const gchar *
107{
108 if (!user_agent || user_agent[0] == '\0')
109 {
112 }
113
114 return user_agent ? user_agent : "";
115}
int ipc_send(struct ipc_context *context, enum ipc_relation to, const char *msg, size_t len)
sends given msg to the target based on the given context
Definition: ipc.c:46
@ IPC_MAIN
Definition: ipc.h:18
void ipc_data_destroy(ipc_data_t **data)
destroys ipc_data.
Definition: ipc_openvas.c:224
struct ipc_data * ipc_data_type_from_user_agent(const char *user_agent, size_t user_agent_len)
initializes ipc_data for the User-Agent.
Definition: ipc_openvas.c:173
const char * ipc_data_to_json(struct ipc_data *data)
transforms ipc_data to a json string
Definition: ipc_openvas.c:251
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
Definition: plugutils.c:743
Header file for module plugutils.
const gchar * user_agent_get(struct ipc_context *ipc_context)
Get user-agent.
Definition: user_agent.c:106
static void send_user_agent_via_ipc(struct ipc_context *ipc_context)
Definition: user_agent.c:32
gchar * user_agent_set(const gchar *ua)
Set user-agent.
Definition: user_agent.c:85
static gchar * user_agent
user-agent, or NULL.
Definition: user_agent.c:29
static void user_agent_create()
Create and set the global User-Agent variable.
Definition: user_agent.c:53
Header file: user agent functions prototypes.
const gchar * vendor_version_get()
Get vendor version.
Definition: vendorversion.c:38
Header file: vendor version functions prototypes.