From 49385a98b2878ae6f19dd0925e0dc90fcc3d6372 Mon Sep 17 00:00:00 2001 From: Sebastian Köhler Date: Thu, 2 Aug 2012 13:53:46 +0200 Subject: Implemented hashed cloaked hostnames for +x CloakHostModeX can now contain '%x'. It will be replace by the hash of the original client hostname. The new config option CloakHostModeXSalt defines the salt for the hash function. When CloakHostModeXSalt is not set a random salt will be generated after each server restart. Spelling fix in defines.h --- src/tool/tool.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/tool/tool.c') diff --git a/src/tool/tool.c b/src/tool/tool.c index ef3fb5d7..31c6fb41 100644 --- a/src/tool/tool.c +++ b/src/tool/tool.c @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include @@ -129,6 +131,34 @@ ngt_TrimLastChr( char *String, const char Chr) } /* ngt_TrimLastChr */ +/** + * Fill a String with random chars + */ +GLOBAL char * +ngt_RandomStr( char *String, const size_t len) +{ + assert(String != NULL); + + static const char chars[] = + "0123456789ABCDEFGHIJKLMNO" + "PQRSTUVWXYZabcdefghijklmn" + "opqrstuvwxyz!\"#$&'()*+,-" + "./:;<=>?@[\\]^_`"; + + struct timeval t; + gettimeofday(&t, NULL); + srand(t.tv_usec * t.tv_sec); + + for (size_t i = 0; i < len; ++i) { + String[i] = chars[rand() % (sizeof(chars) - 1)]; + } + + String[len] = '\0'; + + return String; +} /* ngt_RandomStr */ + + #ifdef SYSLOG -- cgit 1.4.1