OpenVAS Scanner 23.40.3
user_agent.c File Reference

Functions to set and get the User-Agent. More...

#include "user_agent.h"
#include "ipc_openvas.h"
#include "plugutils.h"
#include "vendorversion.h"
#include <glib.h>
#include <gvm/base/prefs.h>
Include dependency graph for user_agent.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "lib misc"
 GLib logging domain.

Functions

static int send_user_agent_via_ipc (struct ipc_context *ipc_context)
static void user_agent_create (void)
 Create and set the global User-Agent variable.
gchar * user_agent_set (const gchar *ua)
 Set user-agent.
int user_agent_get (struct ipc_context *ipc_context, char **useragent)
 Get user-agent.

Variables

static gchar * user_agent = NULL
 user-agent, or NULL.

Detailed Description

Functions to set and get the User-Agent.

Definition in file user_agent.c.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib misc"

GLib logging domain.

Definition at line 24 of file user_agent.c.

Function Documentation

◆ send_user_agent_via_ipc()

int send_user_agent_via_ipc ( struct ipc_context * ipc_context)
static

Definition at line 32 of file user_agent.c.

33{
34 struct ipc_data *ua = NULL;
35 const char *json = NULL;
36 int ret = 0;
38 json = ipc_data_to_json (ua);
39 ipc_data_destroy (&ua);
40 ret = ipc_send (ipc_context, IPC_MAIN, json, strlen (json));
41 if (-1 == ret)
42 {
43 g_warning ("Unable to send %s to host process", user_agent);
44 }
45 return ret;
46}
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.
const char * ipc_data_to_json(ipc_data_t *data)
transforms ipc_data to a json string
ipc_data_t * ipc_data_type_from_user_agent(const char *user_agent, size_t user_agent_len)
initializes ipc_data for the User-Agent.
static gchar * user_agent
user-agent, or NULL.
Definition user_agent.c:29

References ipc_data_destroy(), ipc_data_to_json(), ipc_data_type_from_user_agent(), IPC_MAIN, ipc_send(), and user_agent.

Referenced by user_agent_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ user_agent_create()

void user_agent_create ( void )
static

Create and set the global User-Agent variable.

@description Gets the User-Agent from the globals_settings.nasl script preferences. If it is not set, it uses the Vendor version. In case that there is no Vendor version, it creates one with a fix string and the nasl library version.

Definition at line 57 of file user_agent.c.

58{
59 gchar *ua = NULL;
60
61 ua = get_plugin_preference ("1.3.6.1.4.1.25623.1.0.12288", "HTTP User-Agent",
62 -1);
63 if (!ua || strlen (g_strstrip (ua)) == 0)
64 {
65 g_free (ua);
66 if (!vendor_version_get () || *vendor_version_get () == '\0')
67 ua = g_strdup_printf ("Mozilla/5.0 [en] (X11, U; OpenVAS-VT %s)",
68 OPENVAS_MISC_VERSION);
69 else
70 ua = g_strdup_printf ("Mozilla/5.0 [en] (X11, U; %s)",
72 }
73
74 user_agent = ua;
75}
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
Definition plugutils.c:837
const gchar * vendor_version_get()
Get vendor version.

References get_plugin_preference(), user_agent, and vendor_version_get().

Referenced by user_agent_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ user_agent_get()

int user_agent_get ( struct ipc_context * ipc_context,
char ** useragent )

Get user-agent.

param[in] ipc_context IPC context for sending data to the parent process param[out] useragent the user agent if any set or an empty string.

Returns
0 on success, -1 on error when sending the message, -2 if the context does not exists

Definition at line 114 of file user_agent.c.

115{
116 int ret = 0;
117 if (!user_agent || user_agent[0] == '\0')
118 {
121 }
122
123 *useragent = user_agent ? g_strdup (user_agent) : "";
124 return ret;
125}
static int send_user_agent_via_ipc(struct ipc_context *ipc_context)
Definition user_agent.c:32
static void user_agent_create(void)
Create and set the global User-Agent variable.
Definition user_agent.c:57

References send_user_agent_via_ipc(), user_agent, and user_agent_create().

Referenced by _http2_req(), and _http_req().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ user_agent_set()

gchar * user_agent_set ( const gchar * ua)

Set user-agent.

Set the global user agent. This function overwrite the existing UA. Null or empty string are not allowed.

Parameters
[in]uauser-agent to be set.

Return the old User-Agent. It must be free by the caller

Definition at line 89 of file user_agent.c.

90{
91 gchar *ua_aux = NULL;
92
93 ua_aux = g_strdup (user_agent);
94
95 if (ua != NULL && ua[0] != '\0')
96 {
97 g_free (user_agent);
98 user_agent = g_strdup (ua);
99 }
100
101 return ua_aux;
102}

References user_agent.

Referenced by process_ipc_data().

Here is the caller graph for this function:

Variable Documentation

◆ user_agent

gchar* user_agent = NULL
static