[evolution-data-server] Return hash-like IDs from camel_header_msgid_generate()



commit 3be50a11cfe19e7c6cf87c56aecb33f16f065d46
Author: Milan Crha <mcrha redhat com>
Date:   Mon Oct 23 18:28:33 2017 +0200

    Return hash-like IDs from camel_header_msgid_generate()
    
    Replace <time_t>.<pid>.<counter> part of the generated ID with
    a SHA1 hash of the similar information, to not expose any private
    information in the generated IDs.
    
    This is discussed, and partly related, to bug 702703.

 src/camel/camel-mime-utils.c |   58 ++++++++++++++++++++++++++++++++++--------
 1 files changed, 47 insertions(+), 11 deletions(-)
---
diff --git a/src/camel/camel-mime-utils.c b/src/camel/camel-mime-utils.c
index d6b29fb..808f662 100644
--- a/src/camel/camel-mime-utils.c
+++ b/src/camel/camel-mime-utils.c
@@ -4489,18 +4489,21 @@ gchar *
 camel_header_msgid_generate (const gchar *domain)
 {
        static GMutex count_lock;
-#define COUNT_LOCK() g_mutex_lock (&count_lock)
-#define COUNT_UNLOCK() g_mutex_unlock (&count_lock)
-       gchar host[MAXHOSTNAMELEN];
-       const gchar *name;
-       static gint count = 0;
-       gchar *msgid;
-       gint retval;
-       struct addrinfo *ai = NULL, hints = { 0 };
+#define LOOKUP_LOCK() g_mutex_lock (&count_lock)
+#define LOOKUP_UNLOCK() g_mutex_unlock (&count_lock)
+       static volatile gint counter = 0;
        static gchar *cached_hostname = NULL;
+       struct addrinfo *ai = NULL;
+       GChecksum *checksum;
+       gchar *msgid;
 
-       COUNT_LOCK ();
+       LOOKUP_LOCK ();
        if (!cached_hostname && (!domain || !*domain)) {
+               gchar host[MAXHOSTNAMELEN];
+               struct addrinfo hints = { 0 };
+               const gchar *name;
+               gint retval;
+
                domain = NULL;
 
                retval = gethostname (host, sizeof (host));
@@ -4518,8 +4521,41 @@ camel_header_msgid_generate (const gchar *domain)
                cached_hostname = g_strdup (name);
        }
 
-       msgid = g_strdup_printf ("%d.%d.%d.camel@%s", (gint) time (NULL), getpid (), count++, domain ? domain 
: cached_hostname);
-       COUNT_UNLOCK ();
+       checksum = g_checksum_new (G_CHECKSUM_SHA1);
+
+       #define add_i64(_x) G_STMT_START { \
+               gint64 i64 = (_x); \
+               g_checksum_update (checksum, (const guchar *) &i64, sizeof (gint64)); \
+       } G_STMT_END
+
+       #define add_str(_x, _def) G_STMT_START { \
+               const gchar *str = (_x); \
+               if (!str) \
+                       str = (_def); \
+               g_checksum_update (checksum, (const guchar *) str, strlen (str)); \
+       } G_STMT_END
+
+       add_i64 (g_get_monotonic_time ());
+       add_i64 (g_get_real_time ());
+       add_i64 (getpid ());
+       add_i64 (getgid ());
+       add_i64 (getppid ());
+       add_i64 (g_atomic_int_add (&counter, 1));
+
+       add_str (domain, "localhost");
+       add_str (cached_hostname, "localhost");
+       add_str (g_get_host_name (), "localhost");
+       add_str (g_get_user_name (), "user");
+       add_str (g_get_real_name (), "User");
+
+       #undef add_i64
+       #undef add_str
+
+       msgid = g_strdup_printf ("%s.camel@%s", g_checksum_get_string (checksum), domain ? domain : 
cached_hostname);
+
+       g_checksum_free (checksum);
+
+       LOOKUP_UNLOCK ();
 
        if (ai)
                camel_freeaddrinfo (ai);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]