OpenVAS Scanner  22.7.9
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. More...
 

Functions

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

Variables

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

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()

static void 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 
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 }

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()

static void user_agent_create ( )
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 53 of file user_agent.c.

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 }

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()

const gchar* user_agent_get ( struct ipc_context ipc_context)

Get user-agent.

Returns
Get user-agent.

Definition at line 106 of file user_agent.c.

107 {
108  if (!user_agent || user_agent[0] == '\0')
109  {
112  }
113 
114  return user_agent ? user_agent : "";
115 }

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

Referenced by _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 85 of file user_agent.c.

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 }

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
vendor_version_get
const gchar * vendor_version_get()
Get vendor version.
Definition: vendorversion.c:38
send_user_agent_via_ipc
static void send_user_agent_via_ipc(struct ipc_context *ipc_context)
Definition: user_agent.c:32
ipc_data_destroy
void ipc_data_destroy(ipc_data_t **data)
destroys ipc_data.
Definition: ipc_openvas.c:224
user_agent_create
static void user_agent_create()
Create and set the global User-Agent variable.
Definition: user_agent.c:53
ipc_send
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_data_type_from_user_agent
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
get_plugin_preference
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
Definition: plugutils.c:743
ipc_data_to_json
const char * ipc_data_to_json(struct ipc_data *data)
transforms ipc_data to a json string
Definition: ipc_openvas.c:251
IPC_MAIN
@ IPC_MAIN
Definition: ipc.h:18
ipc_context
Definition: ipc.h:32
ipc_data
Definition: ipc_openvas.c:39
user_agent
static gchar * user_agent
user-agent, or NULL.
Definition: user_agent.c:29