Fix windows fork detection
authorSam Hartman <hartmans@mit.edu>
Fri, 14 Oct 2011 14:40:20 +0000 (14:40 +0000)
committerSam Hartman <hartmans@mit.edu>
Fri, 14 Oct 2011 14:40:20 +0000 (14:40 +0000)
Signed-off-by: Kevin Wasserman <kevin.wasserman@painless-security.com>
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25334 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/crypto/krb/prng_fortuna.c

index d54d6529a26980ea44c240705dea411d4e835171..8b96a40c9229b0084e3d4fa60490d293b65c1b4e 100644 (file)
@@ -343,7 +343,9 @@ accumulator_output(struct fortuna_state *st, unsigned char *dst, size_t len)
 
 static k5_mutex_t fortuna_lock = K5_MUTEX_PARTIAL_INITIALIZER;
 static struct fortuna_state main_state;
-#ifndef _WIN32
+#ifdef _WIN32
+static DWORD last_pid;
+#else
 static pid_t last_pid;
 #endif
 static krb5_boolean have_entropy = FALSE;
@@ -359,7 +361,9 @@ k5_prng_init(void)
         return ret;
 
     init_state(&main_state);
-#ifndef _WIN32
+#ifdef _WIN32
+    last_pid = GetCurrentProcessId();
+#else
     last_pid = getpid();
 #endif
     if (k5_get_os_entropy(osbuf, sizeof(osbuf))) {
@@ -411,10 +415,12 @@ krb5_error_code KRB5_CALLCONV
 krb5_c_random_make_octets(krb5_context context, krb5_data *outdata)
 {
     krb5_error_code ret;
-#ifndef _WIN32
+#ifdef _WIN32
+    DWORD pid = GetCurrentProcessId();
+#else
     pid_t pid = getpid();
-    unsigned char pidbuf[4];
 #endif
+    unsigned char pidbuf[4];
 
     ret = k5_mutex_lock(&fortuna_lock);
     if (ret)
@@ -425,14 +431,12 @@ krb5_c_random_make_octets(krb5_context context, krb5_data *outdata)
         return KRB5_CRYPTO_INTERNAL;
     }
 
-#ifndef _WIN32 /* no 'fork' on windows; does not apply */
     if (pid != last_pid) {
         /* We forked; make sure child's PRNG stream differs from parent's. */
         store_32_be(pid, pidbuf);
         generator_reseed(&main_state, pidbuf, 4);
         last_pid = pid;
     }
-#endif
 
     accumulator_output(&main_state, (unsigned char *)outdata->data,
                        outdata->length);