[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-httpd-dev
Subject:    apr_generate_random_bytes() is not generated for AIX4 (with no /dev/random) - httpd 2.X.X cannot bui
From:       Michael Felt <mamfelt () gmail ! com>
Date:       2012-03-31 11:36:25
Message-ID: CAN9c_NS9wLZwcaBSTzBFpE2peNEdda-WM_utxhnriayxe=A=kw () mail ! gmail ! com
[Download RAW message or body]

A very quick hack - for something that has been around for a long time, but
I have "fixed" in the past by "hacking" my local copy of httpd (last time
was for 2.2.16, htpasswd.c).

Will working on a test of the proposed httpd-2.4.2 I came across this again
when I tried to build for AIX 4.3.3 - which lacks a /dev/random device.

Result of configure is APR_HAS_RANDOM = 0, so the routine
apr_generate_random_bytes() is not built and so httpd 2.X which use this
routine - cannot be built.

There is nothing officially "random" in my hack, but it gets the routine
built. I expect there is a much better way to do this (and hopefully be
backported into 1.4.x) - than putting it into an #else block.

Anyway, here is a starting point.

Index: apr-1.5.x/misc/unix/rand.c
===================================================================
--- apr-1.5.x/misc/unix/rand.c  (revision 1307078)
+++ apr-1.5.x/misc/unix/rand.c  (working copy)
@@ -247,4 +247,28 @@
 #include "randbyte_os2.inc"
 #endif

+#else
+/*
+ * APR_HAS_RANDOM == 0
+ *      quick hack for AIX4 which lacks /dev/random
+ *      apr is not creating a substitute routine
+ */
+#ifdef _AIX
+
+APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf,
+                                                    apr_size_t length)
+{
+#include <time.h>
+        struct timespec tp;
+       int seed = 0;
+#ifdef CLOCK_MONOTONIC
+        clock_gettime(CLOCK_MONOTONIC,&tp);
+#else
+        clock_gettime(CLOCK_REALTIME,&tp);
+#endif
+        seed = tp.tv_nsec % 10000;
+        memcpy(buf, &seed, length);
+    return APR_SUCCESS;
+}
+#endif
 #endif /* APR_HAS_RANDOM */

[Attachment #3 (text/html)]

<span style="font-family:courier new,monospace">A very quick hack - for something \
that has been around for a long time, but I have &quot;fixed&quot; in the past by \
&quot;hacking&quot; my local copy of httpd (last time was for 2.2.16, \
htpasswd.c).<br> <br>Will working on a test of the proposed httpd-2.4.2 I came across \
this again when I tried to build for AIX 4.3.3 - which lacks a /dev/random \
device.<br><br>Result of configure is APR_HAS_RANDOM = 0, so the routine \
apr_generate_random_bytes() is not built and so httpd 2.X which use this routine - \
cannot be built.<br> <br>There is nothing officially &quot;random&quot; in my hack, \
but it gets the routine built. I expect there is a much better way to do this (and \
hopefully be backported into 1.4.x) - than putting it into an #else block.<br> \
<br>Anyway, here is a starting point.<br><br style="font-family:courier \
new,monospace"></span><span style="font-family:courier new,monospace">Index: \
apr-1.5.x/misc/unix/rand.c</span><br style="font-family:courier new,monospace"> <span \
style="font-family:courier \
new,monospace">===================================================================</span><br \
style="font-family:courier new,monospace"><span style="font-family:courier \
new,monospace">--- apr-1.5.x/misc/unix/rand.c  (revision 1307078)</span><br \
style="font-family:courier new,monospace"> <span style="font-family:courier \
new,monospace">+++ apr-1.5.x/misc/unix/rand.c  (working copy)</span><br \
style="font-family:courier new,monospace"><span style="font-family:courier \
new,monospace">@@ -247,4 +247,28 @@</span><br style="font-family:courier \
new,monospace"> <span style="font-family:courier new,monospace"> #include \
&quot;randbyte_os2.inc&quot;</span><br style="font-family:courier \
new,monospace"><span style="font-family:courier new,monospace"> #endif</span><br \
style="font-family:courier new,monospace"> <span style="font-family:courier \
new,monospace"> </span><br style="font-family:courier new,monospace"><span \
style="font-family:courier new,monospace">+#else</span><br style="font-family:courier \
new,monospace"><span style="font-family:courier new,monospace">+/*</span><br \
style="font-family:courier new,monospace"> <span style="font-family:courier \
new,monospace">+ * APR_HAS_RANDOM == 0</span><br style="font-family:courier \
new,monospace"><span style="font-family:courier new,monospace">+ *      quick hack \
for AIX4 which lacks /dev/random</span><br style="font-family:courier new,monospace"> \
<span style="font-family:courier new,monospace">+ *      apr is not creating a \
substitute routine</span><br style="font-family:courier new,monospace"><span \
style="font-family:courier new,monospace">+ */</span><br style="font-family:courier \
new,monospace"> <span style="font-family:courier new,monospace">+#ifdef \
_AIX</span><br style="font-family:courier new,monospace"><span \
style="font-family:courier new,monospace">+</span><br style="font-family:courier \
new,monospace"><span style="font-family:courier \
new,monospace">+APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char \
*buf, </span><br style="font-family:courier new,monospace"> <span \
style="font-family:courier new,monospace">+                                           \
apr_size_t length)</span><br style="font-family:courier new,monospace"><span \
style="font-family:courier new,monospace">+{</span><br style="font-family:courier \
new,monospace"> <span style="font-family:courier new,monospace">+#include \
&lt;time.h&gt;</span><br style="font-family:courier new,monospace"><span \
style="font-family:courier new,monospace">+        struct timespec tp;</span><br \
style="font-family:courier new,monospace"> <span style="font-family:courier \
new,monospace">+       int seed = 0;</span><br style="font-family:courier \
new,monospace"><span style="font-family:courier new,monospace">+#ifdef \
CLOCK_MONOTONIC</span><br style="font-family:courier new,monospace"> <span \
style="font-family:courier new,monospace">+        \
clock_gettime(CLOCK_MONOTONIC,&amp;tp);</span><br style="font-family:courier \
new,monospace"><span style="font-family:courier new,monospace">+#else</span><br \
style="font-family:courier new,monospace"> <span style="font-family:courier \
new,monospace">+        clock_gettime(CLOCK_REALTIME,&amp;tp);</span><br \
style="font-family:courier new,monospace"><span style="font-family:courier \
new,monospace">+#endif</span><br style="font-family:courier new,monospace"> <span \
style="font-family:courier new,monospace">+        seed = tp.tv_nsec % \
10000;</span><br style="font-family:courier new,monospace"><span \
style="font-family:courier new,monospace">+        memcpy(buf, &amp;seed, \
length);</span><br style="font-family:courier new,monospace"> <span \
style="font-family:courier new,monospace">+    return APR_SUCCESS;</span><br \
style="font-family:courier new,monospace"><span style="font-family:courier \
new,monospace">+}</span><br style="font-family:courier new,monospace"> <span \
style="font-family:courier new,monospace">+#endif</span><br \
style="font-family:courier new,monospace"><span style="font-family:courier \
new,monospace"> #endif /* APR_HAS_RANDOM */</span><br><br>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic