Greenbone Security Assistant  9.0.1
gsad_gmp_auth.h File Reference

Authentication GMP. More...

#include <glib.h>
Include dependency graph for gsad_gmp_auth.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int authenticate_gmp (const gchar *, const gchar *, gchar **, gchar **, gchar **, gchar **, gchar **, gchar **)
 Check authentication credentials. More...
 

Detailed Description

Authentication GMP.

Definition in file gsad_gmp_auth.h.

Function Documentation

◆ authenticate_gmp()

int authenticate_gmp ( const gchar *  username,
const gchar *  password,
gchar **  role,
gchar **  timezone,
gchar **  severity,
gchar **  capabilities,
gchar **  language,
gchar **  pw_warning 
)

Check authentication credentials.

Parameters
[in]usernameUsername.
[in]passwordPassword.
[out]roleRole.
[out]timezoneTimezone.
[out]severitySeverity class.
[out]capabilitiesCapabilities of manager.
[out]languageUser Interface Language, or NULL.
[out]pw_warningPassword warning message, NULL if password is OK.
Returns
0 if valid, 1 manager down, 2 failed, 3 timeout, -1 error.

Definition at line 17223 of file gsad_gmp.c.

17226 {
17227  gvm_connection_t connection;
17228  int auth;
17229  gmp_authenticate_info_opts_t auth_opts;
17230 
17231  if (gvm_connection_open (&connection, manager_address, manager_port))
17232  {
17233  g_debug ("%s failed to acquire socket!\n", __FUNCTION__);
17234  return 1;
17235  }
17236 
17237  auth_opts = gmp_authenticate_info_opts_defaults;
17238  auth_opts.username = username;
17239  auth_opts.password = password;
17240  auth_opts.role = role;
17241  auth_opts.severity = severity;
17242  auth_opts.timezone = timezone;
17243  auth_opts.pw_warning = pw_warning;
17244 
17245  auth = gmp_authenticate_info_ext_c (&connection, auth_opts);
17246  if (auth == 0)
17247  {
17248  entity_t entity;
17249  const char *status;
17250  char first;
17251  gchar *response;
17252  int ret;
17253 
17254  /* Get language setting. */
17255 
17256  ret = setting_get_value (
17257  &connection, "6765549a-934e-11e3-b358-406186ea4fc5", language, NULL);
17258 
17259  switch (ret)
17260  {
17261  case 0:
17262  break;
17263  case 1:
17264  case 2:
17265  gvm_connection_close (&connection);
17266  return 1;
17267  default:
17268  gvm_connection_close (&connection);
17269  return -1;
17270  }
17271 
17272  /* Request help. */
17273 
17274  ret = gvm_connection_sendf (&connection,
17275  "<help format=\"XML\" type=\"brief\"/>");
17276  if (ret)
17277  {
17278  gvm_connection_close (&connection);
17279  return 1;
17280  }
17281 
17282  /* Read the response. */
17283 
17284  entity = NULL;
17285  if (read_entity_and_text_c (&connection, &entity, &response))
17286  {
17287  gvm_connection_close (&connection);
17288  return 1;
17289  }
17290 
17291  /* Check the response. */
17292 
17293  status = entity_attribute (entity, "status");
17294  if (status == NULL || strlen (status) == 0)
17295  {
17296  g_free (response);
17297  free_entity (entity);
17298  return -1;
17299  }
17300 
17301  first = status[0];
17302  free_entity (entity);
17303 
17304  if (first == '2')
17305  {
17306  *capabilities = response;
17307  }
17308  else
17309  {
17310  gvm_connection_close (&connection);
17311  g_free (response);
17312  return -1;
17313  }
17314 
17315  gvm_connection_close (&connection);
17316  return 0;
17317  }
17318  else
17319  {
17320  gvm_connection_close (&connection);
17321 
17322  switch (auth)
17323  {
17324  case 1: /* manager closed connection */
17325  case 2: /* auth failed */
17326  case 3: /* timeout */
17327  return auth;
17328  default:
17329  return -1;
17330  }
17331  }
17332 }

References gvm_connection_open(), manager_address, manager_port, and setting_get_value().

Referenced by login().

Here is the call graph for this function:
Here is the caller graph for this function:
manager_address
gchar * manager_address
The address the manager is on.
Definition: gsad_gmp.c:137
gvm_connection_open
int gvm_connection_open(gvm_connection_t *connection, const gchar *address, int port)
Connect to an address.
Definition: gsad_gmp.c:17185
setting_get_value
static int setting_get_value(gvm_connection_t *connection, const char *setting_id, gchar **value, cmd_response_data_t *response_data)
Get a setting by UUID for the current user of an GMP connection.
Definition: gsad_gmp.c:648
manager_port
int manager_port
The port the manager is on.
Definition: gsad_gmp.c:142