[Openvas-commits] r11705 - in trunk/gsa: . src src/html

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Sep 27 18:40:57 CEST 2011


Author: mattm
Date: 2011-09-27 18:40:55 +0200 (Tue, 27 Sep 2011)
New Revision: 11705

Modified:
   trunk/gsa/ChangeLog
   trunk/gsa/src/gsad.c
   trunk/gsa/src/gsad_base.c
   trunk/gsa/src/gsad_base.h
   trunk/gsa/src/gsad_oap.c
   trunk/gsa/src/gsad_omp.c
   trunk/gsa/src/gsad_omp.h
   trunk/gsa/src/html/gsad.xsl
Log:
	Use the timezone given in the OMP AUTHENTICATE.  Store this timezone in
	the session.  Similarly for the user role, adding the role to the
	page header.

	* src/gsad_base.c (ctime_r_strip_newline): Use strftime to include
	timezone.

	* src/gsad_base.h (credentials_t): Add role and timezone.

	* src/gsad.c: Increase size of buffers passed to ctime_r_strip_newline.
	(struct user): Add role and timezone.
	(user_add): Add role and timezone args.
	(exec_omp_post): Pass role and timezone from authenticate_omp to user_add.
	(request_handler): Set role and timezone in credentials for page handlers.

	* src/gsad_oap.c: Increase size of buffers passed to
	ctime_r_strip_newline.
	(xsl_transform_oap): Set timezone if present.  Add role to ENVELOPE.

	* src/gsad_omp.c: Increase size of buffers passed to
	ctime_r_strip_newline.
	(xsl_transform_oap): Set timezone if present.  Add role to ENVELOPE.
	(authenticate_omp): Add role and timezone return args.  Call
	omp_authenticate_info to set them.

	* src/gsad_omp.h: Update header accordingly.

	* src/html/gsad.xsl (html-gsa-logo): Add role.  Remove timezone.
	(role): New template.

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2011-09-27 16:26:55 UTC (rev 11704)
+++ trunk/gsa/ChangeLog	2011-09-27 16:40:55 UTC (rev 11705)
@@ -1,5 +1,37 @@
 2011-09-27  Matthew Mundell <matthew.mundell at greenbone.net>
 
+	Use the timezone given in the OMP AUTHENTICATE.  Store this timezone in
+	the session.  Similarly for the user role, adding the role to the
+	page header.
+
+	* src/gsad_base.c (ctime_r_strip_newline): Use strftime to include
+	timezone.
+
+	* src/gsad_base.h (credentials_t): Add role and timezone.
+
+	* src/gsad.c: Increase size of buffers passed to ctime_r_strip_newline.
+	(struct user): Add role and timezone.
+	(user_add): Add role and timezone args.
+	(exec_omp_post): Pass role and timezone from authenticate_omp to user_add.
+	(request_handler): Set role and timezone in credentials for page handlers.
+
+	* src/gsad_oap.c: Increase size of buffers passed to
+	ctime_r_strip_newline.
+	(xsl_transform_oap): Set timezone if present.  Add role to ENVELOPE.
+
+	* src/gsad_omp.c: Increase size of buffers passed to
+	ctime_r_strip_newline.
+	(xsl_transform_oap): Set timezone if present.  Add role to ENVELOPE.
+	(authenticate_omp): Add role and timezone return args.  Call
+	omp_authenticate_info to set them.
+
+	* src/gsad_omp.h: Update header accordingly.
+
+	* src/html/gsad.xsl (html-gsa-logo): Add role.  Remove timezone.
+	(role): New template.
+
+2011-09-27  Matthew Mundell <matthew.mundell at greenbone.net>
+
 	* src/html/omp/xsl (get_info_cve_lnk, nvt): Flush trailing whitespace.
 	(report [details]): Turn result icons back on for normal cases.  These
 	were accidentally turned off during addition of prognostic results.

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c	2011-09-27 16:26:55 UTC (rev 11704)
+++ trunk/gsa/src/gsad.c	2011-09-27 16:40:55 UTC (rev 11705)
@@ -210,6 +210,8 @@
   char *token;        ///< Request session token.
   gchar *username;    ///< Login name.
   gchar *password;    ///< Password.
+  gchar *role;        ///< Role.
+  gchar *timezone;    ///< Timezone.
   time_t time;        ///< Login time.
 };
 
@@ -230,11 +232,13 @@
  *
  * @param[in]  username  Name of user.
  * @param[in]  password  Password for user.
+ * @param[in]  timezone  Timezone of user, or NULL.
  *
  * @return Added user.
  */
 user_t *
-user_add (const gchar *username, const gchar *password)
+user_add (const gchar *username, const gchar *password, const gchar *timezone,
+          const gchar *role)
 {
   user_t *user = NULL;
   int index;
@@ -257,6 +261,10 @@
       user->cookie = openvas_uuid_make ();
       g_free (user->password);
       user->password = g_strdup (password);
+      g_free (user->role);
+      user->role = g_strdup (role);
+      g_free (user->timezone);
+      user->timezone = g_strdup (timezone);
     }
   else
     {
@@ -265,6 +273,8 @@
       user->token = openvas_uuid_make ();
       user->username = g_strdup (username);
       user->password = g_strdup (password);
+      user->role = g_strdup (role);
+      user->timezone = g_strdup (timezone);
       g_ptr_array_add (users, (gpointer) user);
     }
   user->time = time (NULL);
@@ -1085,14 +1095,17 @@
           && params_value (con_info->params, "password"))
         {
           int ret;
+          gchar *timezone, *role;
           ret = authenticate_omp (params_value (con_info->params, "login"),
-                                  params_value (con_info->params, "password"));
+                                  params_value (con_info->params, "password"),
+                                  &role,
+                                  &timezone);
           if (ret)
             {
               time_t now;
               gchar *xml;
               char *res;
-              char ctime_now[27];
+              char ctime_now[200];
 
               now = time (NULL);
               ctime_r_strip_newline (&now, ctime_now);
@@ -1114,9 +1127,13 @@
             {
               user_t *user;
               user = user_add (params_value (con_info->params, "login"),
-                               params_value (con_info->params, "password"));
+                               params_value (con_info->params, "password"),
+                               timezone,
+                               role);
               /* Redirect to get_tasks. */
               *user_return = user;
+              g_free (timezone);
+              g_free (role);
               return 1;
             }
         }
@@ -1167,7 +1184,7 @@
     {
       time_t now;
       gchar *xml;
-      char ctime_now[27];
+      char ctime_now[200];
 
       now = time (NULL);
       ctime_r_strip_newline (&now, ctime_now);
@@ -1198,7 +1215,7 @@
     {
       time_t now;
       gchar *xml;
-      char ctime_now[27];
+      char ctime_now[200];
 
       now = time (NULL);
       ctime_r_strip_newline (&now, ctime_now);
@@ -1995,7 +2012,7 @@
       time_t now;
       gchar *xml;
       char *res;
-      char ctime_now[27];
+      char ctime_now[200];
 
       now = time (NULL);
       ctime_r_strip_newline (&now, ctime_now);
@@ -2388,7 +2405,7 @@
           gchar *xml;
           char *res;
           gchar *full_url;
-          char ctime_now[27];
+          char ctime_now[200];
           const char *cmd, *report_format_id;
           int export;
 
@@ -2450,7 +2467,7 @@
           time_t now;
           gchar *xml;
           char *res;
-          char ctime_now[27];
+          char ctime_now[200];
 
           now = time (NULL);
           ctime_r_strip_newline (&now, ctime_now);
@@ -2481,9 +2498,13 @@
       if (credentials == NULL) abort ();
       assert (user->username);
       assert (user->password);
+      assert (user->role);
+      assert (user->timezone);
       assert (user->token);
       credentials->username = strdup (user->username);
       credentials->password = strdup (user->password);
+      credentials->role = strdup (user->role);
+      credentials->timezone = strdup (user->timezone);
       credentials->token = strdup (user->token);
       credentials->caller = reconstruct_url (connection, url);
 
@@ -2581,7 +2602,7 @@
               // XXX: url subsearch could be nicer and xsl transform could
               // be generalized with the other transforms.
               time_t now;
-              char ctime_now[27];
+              char ctime_now[200];
               gchar *xml;
 
               assert (credentials->token);

Modified: trunk/gsa/src/gsad_base.c
===================================================================
--- trunk/gsa/src/gsad_base.c	2011-09-27 16:26:55 UTC (rev 11704)
+++ trunk/gsa/src/gsad_base.c	2011-09-27 16:40:55 UTC (rev 11705)
@@ -85,10 +85,20 @@
 char*
 ctime_r_strip_newline (time_t *time, char *string)
 {
-  char* ret = ctime_r (time, string);
-  if (ret && strlen (ret) > 0)
-    ret[strlen (ret) - 1] = '\0';
-  return ret;
+  struct tm *tm;
+
+  tm = localtime (time);
+  if (tm == NULL
+      || (strftime (string,
+                    199,
+                    "%c %Z",
+                    tm)
+          == 0))
+    {
+      string[0] = '\0';
+      return string;
+    }
+  return string;
 }
 
 /**

Modified: trunk/gsa/src/gsad_base.h
===================================================================
--- trunk/gsa/src/gsad_base.h	2011-09-27 16:26:55 UTC (rev 11704)
+++ trunk/gsa/src/gsad_base.h	2011-09-27 16:40:55 UTC (rev 11705)
@@ -64,6 +64,8 @@
 {
   char *username;  ///< Name of user.
   char *password;  ///< User's password.
+  char *role;      ///< User's role.
+  char *timezone;  ///< User's timezone.
   char *token;     ///< Session token.
   char *caller;    ///< Caller URL, for POST relogin.
 } credentials_t;

Modified: trunk/gsa/src/gsad_oap.c
===================================================================
--- trunk/gsa/src/gsad_oap.c	2011-09-27 16:26:55 UTC (rev 11704)
+++ trunk/gsa/src/gsad_oap.c	2011-09-27 16:40:55 UTC (rev 11705)
@@ -92,7 +92,7 @@
       time_t now;
       gchar *xml;
       char *res;
-      char ctime_now[27];
+      char ctime_now[200];
       int ret;
 
       tracef ("socket is not there!\n");
@@ -185,10 +185,15 @@
   gchar *res;
   GString *string;
   char *html;
-  char ctime_now[27];
+  char ctime_now[200];
 
   assert (credentials);
 
+  if (credentials->timezone)
+    {
+      setenv ("TZ", credentials->timezone, 1);
+      tzset ();
+    }
   now = time (NULL);
   ctime_r_strip_newline (&now, ctime_now);
 
@@ -198,11 +203,13 @@
                                  "<token>%s</token>"
                                  "<caller>%s</caller>"
                                  "<time>%s</time>"
-                                 "<login>%s</login>",
+                                 "<login>%s</login>"
+                                 "<role>%s</role>",
                                  credentials->token,
                                  credentials->caller ? credentials->caller : "",
                                  ctime_now,
-                                 credentials->username);
+                                 credentials->username,
+                                 credentials->role);
   g_string_append (string, res);
   g_free (res);
   g_string_append_printf (string, "%s</envelope>", xml);

Modified: trunk/gsa/src/gsad_omp.c
===================================================================
--- trunk/gsa/src/gsad_omp.c	2011-09-27 16:26:55 UTC (rev 11704)
+++ trunk/gsa/src/gsad_omp.c	2011-09-27 16:40:55 UTC (rev 11705)
@@ -133,10 +133,15 @@
   gchar *res;
   GString *string;
   char *html;
-  char ctime_now[27];
+  char ctime_now[200];
 
   assert (credentials);
 
+  if (credentials->timezone)
+    {
+      setenv ("TZ", credentials->timezone, 1);
+      tzset ();
+    }
   now = time (NULL);
   ctime_r_strip_newline (&now, ctime_now);
 
@@ -146,11 +151,13 @@
                                  "<token>%s</token>"
                                  "<caller>%s</caller>"
                                  "<time>%s</time>"
-                                 "<login>%s</login>",
+                                 "<login>%s</login>"
+                                 "<role>%s</role>",
                                  credentials->token,
                                  credentials->caller ? credentials->caller : "",
                                  ctime_now,
-                                 credentials->username);
+                                 credentials->username,
+                                 credentials->role);
   g_string_append (string, res);
   g_free (res);
   g_string_append_printf (string, "%s</envelope>", xml);
@@ -13788,11 +13795,14 @@
  *
  * @param[in]  username  Username.
  * @param[in]  password  Password.
+ * @param[out] role      Role.
+ * @param[out] timezone  Timezone.
  *
  * @return 0 if valid, 1 failed, 2 manager down.
  */
 int
-authenticate_omp (const gchar * username, const gchar * password)
+authenticate_omp (const gchar * username, const gchar * password,
+                  char **role, char **timezone)
 {
   gnutls_session_t session;
   int socket;
@@ -13821,7 +13831,7 @@
   sleep (20);
 #endif
 
-  auth = omp_authenticate (&session, username, password);
+  auth = omp_authenticate_info (&session, username, password, role, timezone);
   if (auth == 0)
     {
       openvas_server_close (socket, session);
@@ -13863,7 +13873,7 @@
       time_t now;
       gchar *xml;
       char *res;
-      char ctime_now[27];
+      char ctime_now[200];
       int ret;
 
       if (html == NULL)

Modified: trunk/gsa/src/gsad_omp.h
===================================================================
--- trunk/gsa/src/gsad_omp.h	2011-09-27 16:26:55 UTC (rev 11704)
+++ trunk/gsa/src/gsad_omp.h	2011-09-27 16:40:55 UTC (rev 11705)
@@ -159,7 +159,7 @@
 char * restore_omp (credentials_t *, params_t *);
 char * empty_trashcan_omp (credentials_t *, params_t *);
 
-int authenticate_omp (const gchar *, const gchar *);
+int authenticate_omp (const gchar *, const gchar *, gchar **, gchar **);
 
 char * get_info_omp (credentials_t *, params_t *);
 char * get_nvts_omp (credentials_t *, params_t *);

Modified: trunk/gsa/src/html/gsad.xsl
===================================================================
--- trunk/gsa/src/html/gsad.xsl	2011-09-27 16:26:55 UTC (rev 11704)
+++ trunk/gsa/src/html/gsad.xsl	2011-09-27 16:40:55 UTC (rev 11705)
@@ -513,13 +513,14 @@
           <xsl:when test="$username = ''">
           </xsl:when>
           <xsl:otherwise>
-            Logged in as <b><xsl:value-of select="$username"/></b> |
+            Logged in as <div style="display: inline;"><xsl:value-of select="/envelope/role"/></div>
+            <b><xsl:value-of select="$username"/></b> |
           </xsl:otherwise>
         </xsl:choose>
         <a href="/logout?token={/envelope/token}" title="Logout" style="margin-left:3px;">Logout</a>
         <br/>
         <br/>
-        <xsl:value-of select="$time"/> (UTC)
+        <xsl:value-of select="$time"/>
       </div>
       <div class="status_panel">
         <xsl:apply-templates select="gsad_msg"
@@ -1015,6 +1016,9 @@
 <xsl:template match="time">
 </xsl:template>
 
+<xsl:template match="role">
+</xsl:template>
+
 <xsl:template match="envelope">
   <div class="envelope">
     <xsl:call-template name="html-gsa-logo">



More information about the Openvas-commits mailing list