[PATCH app-xdm 4/9] config: integrate check for arc4random in appropriate sections

Gaetan Nadon memsize at videotron.ca
Fri Nov 12 16:59:29 PST 2010


The AC_SEARCH_LIBS is done in "Check for libraries" section.
Move AC_SUBST and AM_CONDITIONAL over there as well.
Move AC_CHECK_FUNCS for arc4random to "library functions" section
No function change.

Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
---
 Makefile.am  |    4 ++--
 configure.ac |   14 ++++----------
 dm.c         |    6 +++---
 dm.h         |    2 +-
 dm_auth.h    |    2 +-
 genauth.c    |   12 ++++++------
 resource.c   |    6 +++---
 7 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 15abb8c..b5c6859 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -83,7 +83,7 @@ xdm_CFLAGS +=  -DHASXDMAUTH
 xdm_SOURCES += xdmauth.c
 endif
 
-if !HAS_ARC4_RANDOM
+if !HAVE_ARC4RANDOM
 xdm_SOURCES += prngc.c
 endif
 
@@ -119,7 +119,7 @@ MAN_SUBSTS +=	-e 's|CHOOSERPATH|$(xdmlibdir)/chooser|g' \
 		-e 's|DEF_SYSTEM_PATH|$(DEF_SYSTEM_PATH)|g' \
 		-e 's|DEF_GREETER_LIB|$(DEF_GREETER_LIB)|g' \
 		-e 's|DEV_RANDOM|$(DEV_RANDOM)|g' \
-		-e 's|ARC4_RANDOM|$(ARC4_RANDOM)|g'
+		-e 's|ARC4_RANDOM|$(HAVE_ARC4RANDOM)|g'
 
 .man.cpp.$(APP_MAN_SUFFIX):
 	$(AM_V_GEN)$(SED) $(MAN_SUBSTS) < $< > $@
diff --git a/configure.ac b/configure.ac
index 6765f2f..03e6e53 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,7 +74,9 @@ AC_SEARCH_LIBS([setproctitle], [util bsd])
 AC_SEARCH_LIBS([setusercontext], [util])
 
 # Function arc4random() is in BSD standard C or GNU systems -lbsd
-AC_SEARCH_LIBS([arc4random], [bsd])
+AC_SEARCH_LIBS([arc4random], [bsd], [HAVE_ARC4RANDOM="yes"])
+AC_SUBST(HAVE_ARC4RANDOM)
+AM_CONDITIONAL(HAVE_ARC4RANDOM, test x$HAVE_ARC4RANDOM = xyes)
 
 # Function crypt() comes from the C library or the -lcrypt data encryption library
 AC_SEARCH_LIBS(crypt, crypt)
@@ -92,7 +94,7 @@ AC_TYPE_SIGNAL
 # Required system libraries have been searched for and are listed in $LIBS
 #------------------------------------------------------------------------------
 AC_CHECK_FUNCS([daemon sigaction openlog asprintf setproctitle setusercontext \
-                mkstemp getifaddrs getspnam])
+                mkstemp getifaddrs getspnam arc4random])
 
 #------------------------------------------------------------------------------
 
@@ -194,14 +196,6 @@ if test x$RANDOM_DEVICE != xno ; then
 fi
 AC_SUBST(DEV_RANDOM)
 
-AC_CHECK_FUNC(arc4random, [HAS_ARC4_RANDOM="yes"], [HAS_ARC4_RANDOM="no"])
-AM_CONDITIONAL(HAS_ARC4_RANDOM, test x$HAS_ARC4_RANDOM = xyes)
-if test x$HAS_ARC4_RANDOM = xyes ; then
-	AC_DEFINE(ARC4_RANDOM, 1, [Define to use arc4random() function])
-	ARC4_RANDOM=1
-fi
-AC_SUBST(ARC4_RANDOM)
-
 # FIXME: find out how to check for these things. Note that Kerberos was
 # turned off everywhere but on OpenBSD.
 AM_CONDITIONAL(HAS_KERBEROS_FIVE, false)
diff --git a/dm.c b/dm.c
index 858a06e..0699f38 100644
--- a/dm.c
+++ b/dm.c
@@ -179,7 +179,7 @@ main (int argc, char **argv)
 	snprintf(cmdbuf, sizeof(cmdbuf), "/bin/rm -f %s/authdir/authfiles/A*", authDir);
 	system(cmdbuf);
     }
-#if!defined(ARC4_RANDOM) && !defined(DEV_RANDOM)
+#if!defined(HAVE_ARC4RANDOM) && !defined(DEV_RANDOM)
     AddOtherEntropy ();
 #endif
 #ifdef XDMCP
@@ -205,7 +205,7 @@ main (int argc, char **argv)
 #endif
     ScanServers ();
     StartDisplays ();
-#if !defined(ARC4_RANDOM) && !defined(DEV_RANDOM)
+#if !defined(HAVE_ARC4RANDOM) && !defined(DEV_RANDOM)
     AddOtherEntropy();
 #endif
     (void) Signal (SIGHUP, RescanNotify);
@@ -540,7 +540,7 @@ WaitForChild (void)
 			  " removing display %s\n",d->name);
 		    LogError("Server crash rate too high:"
 			     " removing display %s\n",d->name);
-#if !defined(ARC4_RANDOM) && !defined(DEV_RANDOM)
+#if !defined(HAVE_ARC4RANDOM) && !defined(DEV_RANDOM)
 		    AddTimerEntropy();
 #endif
 		    RemoveDisplay (d);
diff --git a/dm.h b/dm.h
index 7c67906..109f157 100644
--- a/dm.h
+++ b/dm.h
@@ -318,7 +318,7 @@ extern int	removeDomainname;
 extern char	*keyFile;
 extern char	*accessFile;
 extern char	**exportList;
-# if !defined(ARC4_RANDOM)
+# if !defined(HAVE_ARC4RANDOM)
 extern char	*randomFile;
 extern char	*prngdSocket;
 extern int	prngdPort;
diff --git a/dm_auth.h b/dm_auth.h
index b824861..d475f77 100644
--- a/dm_auth.h
+++ b/dm_auth.h
@@ -87,7 +87,7 @@ extern void SetUserAuthorization (struct display *d, struct verify_info *verify)
 
 /* genauth.c */
 extern int GenerateAuthData (char *auth, int len);
-# if !defined(ARC4_RANDOM)
+# if !defined(HAVE_ARC4RANDOM)
 extern void AddPreGetEntropy (void);
 extern void AddOtherEntropy (void);
 extern void AddTimerEntropy (void);
diff --git a/genauth.c b/genauth.c
index b70c41a..5db7315 100644
--- a/genauth.c
+++ b/genauth.c
@@ -89,7 +89,7 @@ pollRandomDevice (int fd)
 # define pollRandomDevice(fd) 1
 #endif
 
-#if !defined(ARC4_RANDOM)
+#if !defined(HAVE_ARC4RANDOM)
 
 /* ####################################################################### */
 
@@ -337,7 +337,7 @@ AddPreGetEntropy (void)
     }
     LogError("Cannot read randomFile \"%s\"; X cookies may be easily guessable\n", randomFile);
 }
-#endif /* !ARC4_RANDOM && !DEV_RANDOM */
+#endif /* !HAVE_ARC4RANDOM && !DEV_RANDOM */
 
 
 #ifdef HASXDMAUTH
@@ -346,7 +346,7 @@ InitXdmcpWrapper (void)
 {
     CARD32 sum[4];
 
-# ifdef	ARC4_RANDOM
+# ifdef	HAVE_ARC4RANDOM
     sum[0] = arc4random();
     sum[1] = arc4random();
     *(u_char *)sum = 0;
@@ -437,14 +437,14 @@ GenerateAuthData (char *auth, int len)
     }
     return 1;
 #else /* !XDMAUTH */
-# ifdef ARC4_RANDOM
+# ifdef HAVE_ARC4RANDOM
     CARD32 *rnd = (CARD32 *)auth;
     int i;
 
     for (i = 0; i < len; i += 4)
 	rnd[i / 4] = arc4random();
     return 1;
-# else /* !ARC4_RANDOM */
+# else /* !HAVE_ARC4RANDOM */
     CARD32 tmp[4] = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 };
 #  ifdef DEV_RANDOM
     int fd;
@@ -476,6 +476,6 @@ GenerateAuthData (char *auth, int len)
     add_entropy (tmp + 2, 1);
     memcpy (auth, tmp, len);
     return 1;
-# endif /* !ARC4_RANDOM */
+# endif /* !HAVE_ARC4RANDOM */
 #endif /* !HASXDMAUTH */
 }
diff --git a/resource.c b/resource.c
index 5c02da7..57a0edc 100644
--- a/resource.c
+++ b/resource.c
@@ -55,13 +55,13 @@ int	removeDomainname;
 char	*keyFile;
 char	*accessFile;
 char	**exportList;
-#if !defined(ARC4_RANDOM)
+#if !defined(HAVE_ARC4RANDOM)
 char	*randomFile;
 #endif
 #ifdef DEV_RANDOM
 char	*randomDevice;
 #endif
-#if !defined(ARC4_RANDOM)
+#if !defined(HAVE_ARC4RANDOM)
 char	*prngdSocket;
 int	prngdPort;
 #endif
@@ -176,7 +176,7 @@ struct dmResources {
 				DEF_ACCESS_FILE} ,
 { "exportList",	"ExportList",	DM_ARGV,	(char **) &exportList,
 				""} ,
-#if !defined(ARC4_RANDOM)
+#if !defined(HAVE_ARC4RANDOM)
 { "randomFile",	"RandomFile",	DM_STRING,	&randomFile,
 				DEF_RANDOM_FILE} ,
 { "prngdSocket", "PrngdSocket", DM_STRING,	&prngdSocket,
-- 
1.6.0.4



More information about the xorg-devel mailing list