Author: timopollmeier
Date: 2016-10-14 17:42:24 +0200 (Fri, 14 Oct 2016)
New Revision: 26412

Modified:
   trunk/gsa/CMakeLists.txt
   trunk/gsa/ChangeLog
   trunk/gsa/src/CMakeLists.txt
   trunk/gsa/src/gsad.c
   trunk/gsa/src/gsad_base.c
   trunk/gsa/src/gsad_base.h
   trunk/gsa/src/xslt_i18n.c
Log:
        Install locale .mo files in a different location to make them
        accessible if --do-chroot is used.

        * CMakeLists.txt: Change GSA_LOCALE_DIR to a subdirectory of
        GSA_DATA_DIR instead of DATADIR.  Add variables GSA_LOCALE_SUBDIR and
        GSA_CHROOT_LOCALE_DIR.

        * src/CMakeLists.txt: Add add_definitions for GSA_CHROOT_LOCALE_DIR.

        * src/gsad_base.c: Add static variable chroot_state.
        (get_chroot_state, set_chroot_state): New functions.

        * src/gsad_base.h (get_chroot_state, set_chroot_state): New prototypes.

        * src/xslt_i18n.c: Add #include "gsad_base.h".
        (register_i18n_ext_module, init_language_lists): Adapt locale directory
        to whether chroot is used.


Modified: trunk/gsa/CMakeLists.txt
===================================================================
--- trunk/gsa/CMakeLists.txt    2016-10-14 13:19:06 UTC (rev 26411)
+++ trunk/gsa/CMakeLists.txt    2016-10-14 15:42:24 UTC (rev 26412)
@@ -228,7 +228,9 @@
 set (OPENVAS_STATE_DIR "${LOCALSTATEDIR}/lib/openvas")
 set (OPENVAS_LOG_DIR   "${LOCALSTATEDIR}/log/openvas")
 set (GSA_DATA_DIR "${DATADIR}/openvas/gsa")
-set (GSA_LOCALE_DIR "${DATADIR}/locale")
+set (GSA_LOCALE_SUBDIR "locale")
+set (GSA_LOCALE_DIR "${GSA_DATA_DIR}/${GSA_LOCALE_SUBDIR}")
+set (GSA_CHROOT_LOCALE_DIR "/${GSA_LOCALE_SUBDIR}")
 
 # TODO: Eventually use own certificates
 set (OPENVAS_SERVER_CERTIFICATE "${OPENVAS_STATE_DIR}/CA/servercert.pem")

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog 2016-10-14 13:19:06 UTC (rev 26411)
+++ trunk/gsa/ChangeLog 2016-10-14 15:42:24 UTC (rev 26412)
@@ -1,3 +1,23 @@
+2016-10-14  Timo Pollmeier <timo.pollme...@greenbone.net>
+
+       Install locale .mo files in a different location to make them
+       accessible if --do-chroot is used.
+
+       * CMakeLists.txt: Change GSA_LOCALE_DIR to a subdirectory of
+       GSA_DATA_DIR instead of DATADIR.  Add variables GSA_LOCALE_SUBDIR and
+       GSA_CHROOT_LOCALE_DIR.
+
+       * src/CMakeLists.txt: Add add_definitions for GSA_CHROOT_LOCALE_DIR.
+
+       * src/gsad_base.c: Add static variable chroot_state.
+       (get_chroot_state, set_chroot_state): New functions.
+
+       * src/gsad_base.h (get_chroot_state, set_chroot_state): New prototypes.
+
+       * src/xslt_i18n.c: Add #include "gsad_base.h".
+       (register_i18n_ext_module, init_language_lists): Adapt locale directory
+       to whether chroot is used.
+
 2016-10-14 Bj�rn Ricks <bjoern.ri...@greenbone.net>
 
        * src/gsad_omp.c (edit_user): Fix passing the extra_xml to 
edit_resource.

Modified: trunk/gsa/src/CMakeLists.txt
===================================================================
--- trunk/gsa/src/CMakeLists.txt        2016-10-14 13:19:06 UTC (rev 26411)
+++ trunk/gsa/src/CMakeLists.txt        2016-10-14 15:42:24 UTC (rev 26412)
@@ -142,6 +142,10 @@
   add_definitions (-DGSA_LOCALE_DIR=\\\"${GSA_LOCALE_DIR}\\\")
 endif (GSA_LOCALE_DIR)
 
+if (GSA_CHROOT_LOCALE_DIR)
+  add_definitions (-DGSA_CHROOT_LOCALE_DIR=\\\"${GSA_CHROOT_LOCALE_DIR}\\\")
+endif (GSA_CHROOT_LOCALE_DIR)
+
 add_definitions (-DOPENVAS_OS_NAME=\\\"${CMAKE_SYSTEM}\\\")
 add_definitions (-DPREFIX=\\\"${CMAKE_INSTALL_PREFIX}\\\")
 

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c        2016-10-14 13:19:06 UTC (rev 26411)
+++ trunk/gsa/src/gsad.c        2016-10-14 15:42:24 UTC (rev 26412)
@@ -339,6 +339,11 @@
 gboolean ignore_http_x_real_ip;
 
 /**
+ * @brief Whether chroot is used
+ */
+int chroot_state = 0;
+
+/**
  * @brief Add security headers to a MHD response.
  */
 void
@@ -5238,6 +5243,7 @@
                       strerror (errno));
           return 1;
         }
+      set_chroot_state (1);
     }
 
   if (user_pw && (drop_privileges (user_pw) == FALSE))

Modified: trunk/gsa/src/gsad_base.c
===================================================================
--- trunk/gsa/src/gsad_base.c   2016-10-14 13:19:06 UTC (rev 26411)
+++ trunk/gsa/src/gsad_base.c   2016-10-14 15:42:24 UTC (rev 26412)
@@ -69,6 +69,11 @@
 gchar *label_name = NULL;
 
 /**
+ * @brief The chroot state: 0 = no chroot, 1 = chroot used
+ */
+static int chroot_state = 0;
+
+/**
  * @brief Base init.
  *
  * @return 0 success, 1 XML needs thread support.
@@ -101,6 +106,28 @@
 }
 
 /**
+ * @brief Gets the chroot state.
+ *
+ * @return  The chroot state: 0 = no chroot, 1 = chroot in effect
+ */
+int
+get_chroot_state () 
+{
+  return chroot_state;
+}
+
+/**
+ * @brief Sets the chroot state.
+ *
+ * @param[in]  state The new chroot state.
+ */
+void
+set_chroot_state (int state)
+{
+  chroot_state = state;
+}
+
+/**
  * @brief Set the vendor version.
  *
  * @param[in]  version  Vendor version.

Modified: trunk/gsa/src/gsad_base.h
===================================================================
--- trunk/gsa/src/gsad_base.h   2016-10-14 13:19:06 UTC (rev 26411)
+++ trunk/gsa/src/gsad_base.h   2016-10-14 15:42:24 UTC (rev 26412)
@@ -96,6 +96,8 @@
 
 int gsad_base_init ();
 int gsad_base_cleanup ();
+int get_chroot_state ();
+void set_chroot_state (int);
 void vendor_version_set (const gchar *);
 const gchar *vendor_version_get ();
 int label_name_set (const gchar *);

Modified: trunk/gsa/src/xslt_i18n.c
===================================================================
--- trunk/gsa/src/xslt_i18n.c   2016-10-14 13:19:06 UTC (rev 26411)
+++ trunk/gsa/src/xslt_i18n.c   2016-10-14 15:42:24 UTC (rev 26412)
@@ -24,6 +24,7 @@
  */
 
 #include "xslt_i18n.h"
+#include "gsad_base.h"
 #include <assert.h>
 #include <dirent.h>
 #include <errno.h>
@@ -537,7 +538,10 @@
                         init_i18n_module,
                         shutdown_i18n_module);
 
-  if (bindtextdomain (GSA_XSL_TEXTDOMAIN, GSA_LOCALE_DIR) == NULL)
+  if (bindtextdomain (GSA_XSL_TEXTDOMAIN,
+                      get_chroot_state () ? GSA_CHROOT_LOCALE_DIR
+                                          : GSA_LOCALE_DIR)
+      == NULL)
     {
       g_critical ("%s: Failed to bind text domain for gettext", __FUNCTION__);
       abort ();
@@ -576,6 +580,7 @@
 init_language_lists ()
 {
   FILE *lang_names_file;
+  const char *locale_dir_name;
   DIR *locale_dir;
   struct dirent *entry;
 
@@ -649,7 +654,9 @@
     }
 
   /* Get installed translations */
-  locale_dir = opendir (GSA_LOCALE_DIR);
+  locale_dir_name = get_chroot_state () ? GSA_CHROOT_LOCALE_DIR 
+                                        : GSA_LOCALE_DIR;
+  locale_dir = opendir (locale_dir_name);
 
   if (locale_dir == NULL)
     {
@@ -668,7 +675,7 @@
         {
           FILE *mo_file;
           gchar *lang_mo_path;
-          lang_mo_path = g_build_filename (GSA_LOCALE_DIR,
+          lang_mo_path = g_build_filename (locale_dir_name,
                                            entry->d_name,
                                            "LC_MESSAGES",
                                            GSA_XSL_TEXTDOMAIN ".mo",

_______________________________________________
Openvas-commits mailing list
Openvas-commits@wald.intevation.org
https://lists.wald.intevation.org/cgi-bin/mailman/listinfo/openvas-commits

Reply via email to