Commit Diff


commit - d9b944c72df6401d9aa2cdf40a196bb1b6066113
commit + 206be139b57622a9d9d2fe28a7d2c1eb62109136
blob - 7c49534770b41e67040582c04fef1e6b345e50db
blob + 7e6b79ae62757d1c015a7205088eafd1ddfbfaa0
--- compat/Makefile.am
+++ compat/Makefile.am
@@ -2,9 +2,11 @@ noinst_LIBRARIES = libopenbsd-compat.a
 
 include $(top_builddir)/Makefile.common
 
+LDADD = $(libbsd_LIBS)
+AM_CPPFLAGS += $(libbsd_CFLAGS)
+
 libopenbsd_compat_a_SOURCES =  \
 	asprintf.c \
-	base64.c \
 	fmt_scaled.c \
 	freezero.c \
 	getdtablecount.c \
@@ -30,6 +32,11 @@ if HOST_DARWIN
 libopenbsd_compat_a_SOURCES += uuid.c bsd-poll.c bsd-poll.h
 endif
 
+if !HAVE_B64
+libopenbsd_compat_a_SOURCES += base64.c
+LDADD += $(libresolv_LIBS)
+endif
+
 if !HAVE_CLOSEFROM
 libopenbsd_compat_a_SOURCES += closefrom.c
 endif
@@ -68,9 +75,6 @@ libopenbsd_compat_a_SOURCES += sha2.c sha2.h
 endif
 endif
 
-LDADD = $(libbsd_LIBS)
-AM_CPPFLAGS = $(libbsd_CFLAGS)
-
 EXTRA_DIST = \
 	$(top_srcdir)/include/got_compat.h \
 	imsg.h \
blob - 4d5435146b078dba61a63b7037b38b5338634cb7
blob + 4bfc141b94ab3b2406e8c52721c2b2973397b0b3
--- configure.ac
+++ configure.ac
@@ -274,6 +274,67 @@ AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_c
 # implementations.
 AC_LIBOBJ(getopt)
 
+# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
+AC_MSG_CHECKING(for b64_ntop)
+	AC_LINK_IFELSE([AC_LANG_PROGRAM(
+	[
+		#include <sys/types.h>
+		#include <netinet/in.h>
+		#include <resolv.h>
+	],
+	[
+		b64_ntop(NULL, 0, NULL, 0);
+	])],
+	found_b64_ntop=yes,
+	found_b64_ntop=no
+)
+AC_MSG_RESULT($found_b64_ntop)
+libresolv_LIBS=""
+if test "x$found_b64_ntop" = xno; then
+	AC_MSG_CHECKING(for b64_ntop with -lresolv)
+	LIBS="-lresolv"
+	AC_LINK_IFELSE([AC_LANG_PROGRAM(
+		[
+			#include <sys/types.h>
+			#include <netinet/in.h>
+			#include <resolv.h>
+		],
+		[
+			b64_ntop(NULL, 0, NULL, 0);
+		])],
+		found_b64_ntop=yes,
+		found_b64_ntop=no
+	)
+	AC_MSG_RESULT($found_b64_ntop)
+	libresolv_LIBS="$LIBS"
+fi
+if test "x$found_b64_ntop" = xno; then
+	AC_MSG_CHECKING(for b64_ntop with -lnetwork)
+	LIBS="-lresolv -lnetwork"
+	AC_LINK_IFELSE([AC_LANG_PROGRAM(
+		[
+			#include <sys/types.h>
+			#include <netinet/in.h>
+			#include <resolv.h>
+		],
+		[
+			b64_ntop(NULL, 0, NULL, 0);
+		])],
+		found_b64_ntop=yes,
+		found_b64_ntop=no
+	)
+	AC_MSG_RESULT($found_b64_ntop)
+	libresolv_LIBS="$LIBS"
+fi
+
+AM_CONDITIONAL([HAVE_B64], [test "x$found_b64_ntop" = xyes])
+if test "x$found_b64_ntop" = xyes; then
+	AC_DEFINE([HAVE_B64_NTOP], [1], [define if b64_ntop is present])
+	AC_SUBST(libresolv_LIBS)
+else
+	AC_LIBOBJ(base64)
+fi
+
 # Check the platform we're compiling on.
 AC_MSG_CHECKING(platform)
 case "$host_os" in
blob - 00dcf879b5bf73d17a7cb2b944f71ea6763a4ad2
blob + 35d01d7cb84fec0d25eff3ca2fd087969ee5fa32
--- include/got_compat2.h
+++ include/got_compat2.h
@@ -111,6 +111,13 @@
 #define cap_enter() (0)
 #endif
 
+#ifndef HAVE_B64_NTOP
+#undef b64_ntop
+#undef b64_pton
+int              b64_ntop(u_char const *, size_t, char *, size_t);
+int              b64_pton(char const *, u_char *, size_t);
+#endif
+
 #ifndef HAVE_SETRESGID
 #define setresgid(a, b, c) (0)
 #endif