[Openvas-commits] r11703 - in trunk/openvas-libraries: . base omp
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Sep 27 18:16:25 CEST 2011
Author: mattm
Date: 2011-09-27 18:16:23 +0200 (Tue, 27 Sep 2011)
New Revision: 11703
Modified:
trunk/openvas-libraries/ChangeLog
trunk/openvas-libraries/base/credentials.c
trunk/openvas-libraries/base/credentials.h
trunk/openvas-libraries/omp/omp.c
trunk/openvas-libraries/omp/omp.h
Log:
* omp/omp.c (omp_authenticate_info): New function.
* omp/omp.h: Add header accordingly.
* base/credentials.h (credentials_t): Add timezone and role.
* base/credentials.c (free_credentials): Free timezone and role.
Modified: trunk/openvas-libraries/ChangeLog
===================================================================
--- trunk/openvas-libraries/ChangeLog 2011-09-27 15:29:53 UTC (rev 11702)
+++ trunk/openvas-libraries/ChangeLog 2011-09-27 16:16:23 UTC (rev 11703)
@@ -1,3 +1,13 @@
+2011-09-27 Matthew Mundell <matthew.mundell at greenbone.net>
+
+ * omp/omp.c (omp_authenticate_info): New function.
+
+ * omp/omp.h: Add header accordingly.
+
+ * base/credentials.h (credentials_t): Add timezone and role.
+
+ * base/credentials.c (free_credentials): Free timezone and role.
+
2011-09-22 Matthew Mundell <matthew.mundell at greenbone.net>
* misc/openvas_auth.c (openvas_is_user_observer): New function.
Modified: trunk/openvas-libraries/base/credentials.c
===================================================================
--- trunk/openvas-libraries/base/credentials.c 2011-09-27 15:29:53 UTC (rev 11702)
+++ trunk/openvas-libraries/base/credentials.c 2011-09-27 16:16:23 UTC (rev 11703)
@@ -46,6 +46,12 @@
credentials->password = NULL;
/** @todo Check whether uuid has to be freed, too. */
+
+ g_free (credentials->timezone);
+ credentials->timezone = NULL;
+
+ g_free (credentials->role);
+ credentials->role = NULL;
}
/**
Modified: trunk/openvas-libraries/base/credentials.h
===================================================================
--- trunk/openvas-libraries/base/credentials.h 2011-09-27 15:29:53 UTC (rev 11702)
+++ trunk/openvas-libraries/base/credentials.h 2011-09-27 16:16:23 UTC (rev 11703)
@@ -43,6 +43,10 @@
///< Password of user.
/*@null@ */ gchar *uuid;
///< UUID of user.
+ /*@null@ */ gchar *timezone;
+ ///< Timezone of user. Set in OpenVAS Manager.
+ /*@null@ */ gchar *role;
+ ///< Timezone of role. Set in OpenVAS Manager.
} credentials_t;
void free_credentials (credentials_t * credentials);
Modified: trunk/openvas-libraries/omp/omp.c
===================================================================
--- trunk/openvas-libraries/omp/omp.c 2011-09-27 15:29:53 UTC (rev 11702)
+++ trunk/openvas-libraries/omp/omp.c 2011-09-27 16:16:23 UTC (rev 11703)
@@ -232,6 +232,80 @@
}
/**
+ * @brief Authenticate with the manager.
+ *
+ * @param[in] session Pointer to GNUTLS session.
+ * @param[in] username Username.
+ * @param[in] password Password.
+ * @param[out] role Role.
+ * @param[out] timezone Timezone if any, else NULL.
+ *
+ * @return 0 on success, 1 if manager closed connection, 2 if auth failed,
+ * -1 on error.
+ */
+int
+omp_authenticate_info (gnutls_session_t *session,
+ const char *username,
+ const char *password,
+ char **role,
+ char **timezone)
+{
+ entity_t entity;
+ const char* status;
+ char first;
+ gchar* msg;
+
+ *timezone = NULL;
+
+ /* Send the auth request. */
+
+ msg = g_markup_printf_escaped ("<authenticate><credentials>"
+ "<username>%s</username>"
+ "<password>%s</password>"
+ "</credentials></authenticate>",
+ username,
+ password);
+ int ret = openvas_server_send (session, msg);
+ g_free (msg);
+ if (ret) return ret;
+
+ /* Read the response. */
+
+ entity = NULL;
+ if (read_entity (session, &entity)) return -1;
+
+ /* Check the response. */
+
+ status = entity_attribute (entity, "status");
+ if (status == NULL)
+ {
+ free_entity (entity);
+ return -1;
+ }
+ if (strlen (status) == 0)
+ {
+ free_entity (entity);
+ return -1;
+ }
+ first = status[0];
+ if (first == '2')
+ {
+ entity_t timezone_entity, role_entity;
+ /* Get the extra info. */
+ timezone_entity = entity_child (entity, "timezone");
+ if (timezone_entity)
+ *timezone = g_strdup (entity_text (timezone_entity));
+ role_entity = entity_child (entity, "role");
+ if (role_entity)
+ *role = g_strdup (entity_text (role_entity));
+ free_entity (entity);
+ return 0;
+ }
+ free_entity (entity);
+ return 2;
+}
+
+/**
* @brief Authenticate, getting credentials from the environment.
*
* Get the user name from environment variable OPENVAS_TEST_USER if that is
Modified: trunk/openvas-libraries/omp/omp.h
===================================================================
--- trunk/openvas-libraries/omp/omp.h 2011-09-27 15:29:53 UTC (rev 11702)
+++ trunk/openvas-libraries/omp/omp.h 2011-09-27 16:16:23 UTC (rev 11703)
@@ -53,6 +53,9 @@
int omp_authenticate (gnutls_session_t * session, const char *username,
const char *password);
+int omp_authenticate_info (gnutls_session_t * session, const char *username,
+ const char *, char **, char **);
+
int omp_authenticate_env (gnutls_session_t * session);
int omp_create_task_rc (gnutls_session_t *, const char *, unsigned int,
More information about the Openvas-commits
mailing list