]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Provide $HOSTNAME variable in UCL
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Jun 2018 07:28:05 +0000 (08:28 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Jun 2018 07:28:05 +0000 (08:28 +0100)
src/libserver/cfg_utils.c

index e606139cf10c23271bfa6802d589a85ef36b7698..e58232a007aaa4014a7e1dcf7aa8c1c31976ed83 100644 (file)
@@ -1112,12 +1112,15 @@ rspamd_include_map_handler (const guchar *data, gsize len,
 #define RSPAMD_VERSION_MINOR_MACRO "VERSION_MINOR"
 #define RSPAMD_VERSION_PATCH_MACRO "VERSION_PATCH"
 #define RSPAMD_BRANCH_VERSION_MACRO "BRANCH_VERSION"
+#define RSPAMD_HOSTNAME_MACRO "HOSTNAME"
 
 void
 rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars)
 {
        GHashTableIter it;
        gpointer k, v;
+       gchar *hostbuf;
+       gsize hostlen;
 
        ucl_parser_register_variable (parser,
                        RSPAMD_CONFDIR_MACRO,
@@ -1159,6 +1162,23 @@ rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars)
                        "no");
 #endif
 
+       hostlen = sysconf (_SC_HOST_NAME_MAX);
+
+       if (hostlen <= 0) {
+               hostlen = 256;
+       }
+       else {
+               hostlen ++;
+       }
+
+       hostbuf = g_alloca (hostlen);
+       memset (hostbuf, 0, hostlen);
+       gethostname (hostbuf, hostlen - 1);
+
+       /* UCL copies variables, so it is safe to pass an ephemeral buffer here */
+       ucl_parser_register_variable (parser, RSPAMD_HOSTNAME_MACRO,
+                       hostbuf);
+
        if (vars != NULL) {
                g_hash_table_iter_init (&it, vars);