Eric,

Try this patch.
It doesn't use syshacks, it really detect the getservbyname_r variant.

Jean-Louis

On 02/08/17 05:57 PM, Eric Lovelace wrote:
I worked your patch in with some changes I made and got it to compile (The changes to Makefile.am <http://Makefile.am> were a separate problem that came up after). Currently I am working with inetd to try and actually get it running to confirm that it works, but it definitely compiles now! Changes are below.

--- config/amanda/syshacks.m4 Wed Aug 2 11:06:49 2017
+++ config/amanda/syshacks.m4.bak Wed Aug 2 11:05:12 2017
@@ -23,7 +23,6 @@
*-freebsd*)
;;
*-openbsd*)
- AC_DEFINE(GETSERVBYNAME_R4,1,[Define on openbsd])
;;
*-hp-*)
case "$CC" in

--- /root/amanda-3.4.5/common-src/security-util.c Wed Aug  2 17:39:04 2017
+++ /root/amanda-3.4.5/common-src/security-util.c.bak Wed Aug 2 08:56:01 2017
@@ -3305,7 +3305,7 @@
         struct servent sp;
         char buf[2048];

-#if defined GETSERVBYNAME_R5
+#ifdef GETSERVBYNAME_R5
        result = getservbyname_r(service, proto, &sp, buf, 2048);
        if (result == 0) {
            assert(errno != ERANGE);
@@ -3313,16 +3313,6 @@
        } else {
            port = (in_port_t)(ntohs((in_port_t)sp.s_port));
        }
-#elif defined GETSERVBYNAME_R4
-       struct servent_data servent_data;
-        int r;
-       memset(&servent_data, 0, sizeof(struct servent_data));
-        r = getservbyname_r(service, proto, &result, &servent_data);
-        if (r !=0) {
-            port = 0;
-        } else {
-            port = (in_port_t)(ntohs((in_port_t)result->s_port));
-        }
 #else
        int r;
        r = getservbyname_r(service, proto, &sp, buf, 2048, &result);

--- Makefile.am <http://Makefile.am> Wed Aug 2 14:12:14 2017
+++ Makefile.am.bak Wed Aug 2 13:30:41 2017
@@ -4,7 +4,7 @@
include $(top_srcdir)/config/automake/vars.am
include $(top_srcdir)/config/automake/installperms.am

-ACLOCAL_AMFLAGS = --force -I config -I . -I config/gettext-macros -I config/gnulib -I config/amanda -I config/macro-archive +ACLOCAL_AMFLAGS = --force -I config -I . -I config/gettext-macros -I config/gnulib -I config/amanda -I config/macro-archive -I /usr/share/aclocal

if WANT_CLIENT
CLIENT_SUBDIRS = client-src application-src

From: <[email protected] <mailto:[email protected]>> on behalf of Jean-Louis Martineau <[email protected] <mailto:[email protected]>>
Date: Wednesday, August 2, 2017 at 1:02 PM
To: Eric Lovelace <[email protected] <mailto:[email protected]>>, "[email protected] <mailto:[email protected]>" <[email protected] <mailto:[email protected]>>
Subject: Re: Compiling 3.4.5 on OpenBSD 6.1

Another variant of getservbyname_r.

Try the attached patch.
I can't compile it, I do not have an openbsd host.

If the patch works, we will have to fix the configure script to detect that variant and define GETSERVBYNAME_R4

Jean-Louis


On 01/08/17 06:17 PM, Eric Lovelace wrote:
This seems to be the relevant part from the doc (located here: https://man.openbsd.org/getservent.3 <https://man.openbsd.org/getservent.3>):

int getservbyname_r(const char *name, const char *proto, struct servent *servent, struct servent_data *servent_data);

I checked out the line from the source (security-util.c line 3318)
r = getservbyname_r(service, proto, &sp, buf, 2048, &result);

So there definitely is a mismatch in parameters. It also looks like that area of code already has some logic for switching between a 5 parameter call and a 6 parameter call; I guess when I sit back down in front of the system in question I will see if I can get enough of a handle on the code to write the 4 parameter call.
________________________________________
From: Jean-Louis Martineau [[email protected]]
Sent: Tuesday, August 01, 2017 5:11 PM
To: Eric Lovelace; [email protected]
Subject: Re: Compiling 3.4.5 on OpenBSD 6.1

How getservbyname_r is defined on OpenBSD 6.1

Jean-Louis

On 01/08/17 04:28 PM, Eric Lovelace wrote:
> Hello,
>
> I would like to run Amanda on OpenBSD (Ideally with current versions of
> each). From what I have found online, this was possible in previous
> versions of both softwares but I can¹t find any examples with more recent
> versions; is this setup still supported? I ran into an issue with the
> default make command (that apparently the Makefile used some GNU make
> exclusive features), but using gmake seemed to advance the progress a
> little further. Has anyone encountered anything similar and been able to
> get it working? Thanks in advance!
>
> The error from running gmake
> ============================
> libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../config -I../gnulib
> -I../common-src -fno-strict-aliasing -D_GNU_SOURCE -I/usr/include -pthread
> -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include
> -I/usr/local/include -Wall -Wextra -Wparentheses
> -Wdeclaration-after-statement -Wmissing-prototypes -Wstrict-prototypes
> -Wmissing-declarations -Wformat -Wformat-security -Wsign-compare
> -Wfloat-equal -Wold-style-definition -Wno-strict-aliasing
> -Wno-unknown-pragmas -Wno-deprecated-declarations
> -DAMANDA_FILE=\"security-util.c\" -g -O2 -fno-strict-aliasing -MT
> security-util.lo -MD -MP -MF .deps/security-util.Tpo -c security-util.c
> -fPIC -DPIC -o .libs/security-util.o
> security-util.c: In function 'find_port_for_service':
> security-util.c:3318: warning: passing argument 4 of 'getservbyname_r'
> from incompatible pointer type
> security-util.c:3318: error: too many arguments to function
> 'getservbyname_r'
> gmake[3]: *** [Makefile:2479: security-util.lo] Error 1
> gmake[3]: Leaving directory '/root/amanda-3.4.5/common-src'
> gmake[2]: *** [Makefile:2123: all] Error 2
> gmake[2]: Leaving directory '/root/amanda-3.4.5/common-src'
> gmake[1]: *** [Makefile:1717: all-recursive] Error 1
> gmake[1]: Leaving directory '/root/amanda-3.4.5'
> gmake: *** [Makefile:1641: all] Error 2
>
>
>
>
> The results from ./configure
> ============================
> Directories:
> Application: /usr/local/libexec/amanda/application
> Configuration: /usr/local/etc/amanda
> GNU Tar lists: /usr/local/var/amanda/gnutar-lists
> Perl modules (amperldir): /usr/local/libdata/perl5/site_perl
> Template and example data files (amdatadir): /usr/local/share/amanda
> Temporary: /tmp/amanda
> WARNINGS:
> no user specified (--with-user) -- using 'amanda'
> no group specified (--with-group) -- using 'backup'
> /bin/tar is not GNU tar, so it will not be used.
> /usr/local/bin/smbclient does not seem to be smbclient.
>
>
This message is the property of CARBONITE, INC. and may contain confidential or 
privileged information.
If this message has been delivered to you by mistake, then do not copy or 
deliver this message to anyone.  Instead, destroy it and notify me by reply 
e-mail
diff --git a/common-src/amutil.c b/common-src/amutil.c
index 5e84b6d..8ea9cd1 100644
--- a/common-src/amutil.c
+++ b/common-src/amutil.c
@@ -333,23 +333,28 @@ connect_port(
 {
     int			save_errno;
     struct servent *	result;
-    int			r;
     socklen_t_equiv	len;
     socklen_t_equiv	socklen;
     int			s;
 
-#ifdef HAVE_GETSERVBYPORT_R
+#ifdef HAVE_FUNC_GETSERVBYNAME_R_6
+    struct servent	servPort;
+    char		buf[2048];
+    int			r;
+    r = getservbyport_r((int)htons(port), proto, &servPort, buf, 2048, &result);
+    assert(r != ERANGE);
+#elif HAVE_FUNC_GETSERVBYNAME_R_5
     struct servent	servPort;
     char		buf[2048];
-# ifdef GETSERVBYPORT_R5
     result = getservbyport_r((int)htons(port), proto, &servPort, buf, 2048);
     if (result == 0) {
 	assert(errno != ERANGE);
     }
-# else
-    r = getservbyport_r((int)htons(port), proto, &servPort, buf, 2048, &result);
-    assert(r != ERANGE);
-# endif
+#elif HAVE_FUNC_GETSERVBYNAME_R_4
+    struct servent_data servent_data;
+    int			r;
+    memset(&servent_data, 0, sizeof(struct servent_data));
+    r = getservbyport_r((int)htons(port), proto, &result, &servent_data);
 #else
     result = getservbyport((int)htons(port), proto);
 #endif
@@ -490,7 +495,6 @@ bind_portrange(
     in_port_t cnt;
     socklen_t_equiv socklen;
     struct servent *result;
-    int             r;
     const in_port_t num_ports = (in_port_t)(last_port - first_port + 1);
     int save_errno = EAGAIN;
     int new_s;
@@ -509,22 +513,28 @@ bind_portrange(
      * if we don't happen to start at the beginning.
      */
     for (cnt = 0; cnt < num_ports; cnt++) {
-#ifdef HAVE_GETSERVBYPORT_R
-	struct servent  servPort;
-	char            buf[2048];
-
-# ifdef GETSERVBYPORT_R5
+#ifdef HAVE_FUNC_GETSERVBYNAME_R_6
+	struct servent	servPort;
+	char		buf[2048];
+	int			r;
+	r = getservbyport_r((int)htons(port), proto, &servPort, buf, 2048, &result);
+	assert(r != ERANGE);
+#elif HAVE_FUNC_GETSERVBYNAME_R_5
+	struct servent	servPort;
+	char		buf[2048];
 	result = getservbyport_r((int)htons(port), proto, &servPort, buf, 2048);
 	if (result == 0) {
 	    assert(errno != ERANGE);
 	}
-# else
-	r = getservbyport_r((int)htons(port), proto, &servPort, buf, 2048, &result);
-	assert(r != ERANGE);
-# endif
+#elif HAVE_FUNC_GETSERVBYNAME_R_4
+	struct servent_data servent_data;
+	int			r;
+	memset(&servent_data, 0, sizeof(struct servent_data));
+	r = getservbyport_r((int)htons(port), proto, &result, &servent_data);
 #else
 	result = getservbyport((int)htons(port), proto);
 #endif
+
 	amfree(*bind_msg);
 g_debug("bind_portrange2: Try  port %d", port);
 	if ((result == NULL) || strstr(result->s_name, AMANDA_SERVICE_NAME)) {
diff --git a/common-src/krb5-security.c b/common-src/krb5-security.c
index 9b6967a..fb7adfb 100644
--- a/common-src/krb5-security.c
+++ b/common-src/krb5-security.c
@@ -410,23 +410,13 @@ static int
 runkrb5(
     struct sec_handle *	rh)
 {
-    struct servent	sp;
-    struct servent *	result;
-    char                buf[2048];
-    int                 r;
     int			server_socket;
     in_port_t		my_port, port;
     struct tcp_conn *	rc = rh->rc;
     const char *err;
     char *stream_msg = NULL;
 
-    r = getservbyname_r(AMANDA_KRB5_SERVICE_NAME, "tcp", &sp, buf,2048, &result);
-    assert(r != ERANGE);
-    if (r != 0) {
-	port = htons(AMANDA_KRB5_DEFAULT_PORT);
-    } else {
-	port = sp.s_port;
-    }
+    port = find_port_for_service(AMANDA_KRB5_SERVICE_NAME, "tcp");
 
     if ((err = get_tgt(keytab_name, principal_name)) != NULL) {
         security_seterror(&rh->sech, "%s: could not get TGT: %s",
@@ -435,7 +425,7 @@ runkrb5(
     }
 
     server_socket = stream_client_privileged(NULL, rc->hostname,
-				     (in_port_t)(ntohs(port)),
+				     port,
 				     STREAM_BUFSIZE,
 				     STREAM_BUFSIZE,
 				     &my_port,
diff --git a/common-src/security-util.c b/common-src/security-util.c
index 1f3fd02..6069445 100644
--- a/common-src/security-util.c
+++ b/common-src/security-util.c
@@ -3357,11 +3357,21 @@ find_port_for_service(
 	port = atoi(service);
     } else {
         struct servent *result;
-#ifdef HAVE_GETSERVBYNAME_R
+#ifdef HAVE_FUNC_GETSERVBYNAME_R_6
         struct servent sp;
         char buf[2048];
+	int r;
+	r = getservbyname_r(service, proto, &sp, buf, 2048, &result);
+	assert(r != ERANGE);
+	if (r != 0) {
+	    port = 0;
+	} else {
+	    port = (in_port_t)(ntohs((in_port_t)sp.s_port));
+	}
 
-#ifdef GETSERVBYNAME_R5
+#elif HAVE_FUNC_GETSERVBYNAME_R_5
+        struct servent sp;
+        char buf[2048];
 	result = getservbyname_r(service, proto, &sp, buf, 2048);
 	if (result == 0) {
 	    assert(errno != ERANGE);
@@ -3369,16 +3379,16 @@ find_port_for_service(
 	} else {
 	    port = (in_port_t)(ntohs((in_port_t)sp.s_port));
 	}
-#else
+#elif HAVE_FUNC_GETSERVBYNAME_R_4
+	struct servent_data servent_data;
 	int r;
-	r = getservbyname_r(service, proto, &sp, buf, 2048, &result);
-	assert(r != ERANGE);
+	memset(&servent_data, 0, sizeof(struct servent_data));
+	r = getservbyname_r(service, proto, &result, &servent_data);
 	if (r != 0) {
 	    port = 0;
 	} else {
-	    port = (in_port_t)(ntohs((in_port_t)sp.s_port));
+	    port = (in_port_t)(ntohs((in_port_t)result->s_port));
 	}
-#endif
 #else
 	if ((result = getservbyname(service, proto)) == NULL) {
 	    port = 0;
diff --git a/config/amanda/amanda_configure.m4 b/config/amanda/amanda_configure.m4
index 4e0811c..5b427ae 100644
--- a/config/amanda/amanda_configure.m4
+++ b/config/amanda/amanda_configure.m4
@@ -365,8 +365,7 @@ ICE_CHECK_DECL(strcasecmp,string.h strings.h)
 ICE_CHECK_DECL(euidaccess,unistd.h)
 ICE_CHECK_DECL(eaccess,unistd.h)
 ICE_CHECK_DECL(clock_gettime,time.h)
-AC_CHECK_FUNCS(getservbyname_r)
-AC_CHECK_FUNCS(getservbyport_r)
+AX_FUNC_WHICH_GETSERVBYNAME_R
 AC_CHECK_FUNCS(sem_timedwait)
 
 #
diff --git a/config/amanda/syshacks.m4 b/config/amanda/syshacks.m4
index 5dd8aa6..d6ccf04 100644
--- a/config/amanda/syshacks.m4
+++ b/config/amanda/syshacks.m4
@@ -74,8 +74,6 @@ AC_DEFUN([AMANDA_SYSHACKS], [
 		    ;;
         *-solaris2*)
 		    AMANDA_ADD_CFLAGS([-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1])
-		    AC_DEFINE(GETSERVBYNAME_R5,1,[Define on solaris])
-		    AC_DEFINE(GETSERVBYPORT_R5,1,[Define on solaris])
 		    ;;
         *-sun-sunos4.1*)
 		    ;;
diff --git a/config/macro-archive/ax_func_which_getservbyname_r.m4 b/config/macro-archive/ax_func_which_getservbyname_r.m4
new file mode 100644
index 0000000..60d0381
--- /dev/null
+++ b/config/macro-archive/ax_func_which_getservbyname_r.m4
@@ -0,0 +1,109 @@
+# ==================================================================================
+#  https://www.gnu.org/software/autoconf-archive/ax_func_which_getservbyname_r.html
+# ==================================================================================
+#
+# SYNOPSIS
+#
+#   AX_FUNC_WHICH_GETSERVBYNAME_R
+#
+# DESCRIPTION
+#
+#   Provides a test to determine the correct way to call getservbyname_r:
+#
+#    - defines HAVE_FUNC_GETSERVBYNAME_R_6 if it needs 6 arguments (e.g linux)
+#    - defines HAVE_FUNC_GETSERVBYNAME_R_5 if it needs 5 arguments (e.g. solaris)
+#    - defines HAVE_FUNC_GETSERVBYNAME_R_4 if it needs 4 arguments (e.g. osf/1)
+#
+#   An example use can be found at
+#   http://raf.org/autoconf/net_getservbyname.c
+#
+#   Based on Caolan McNamara's gethostbyname_r macro. Based on David
+#   Arnold's autoconf suggestion in the threads faq.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 raf <[email protected]>
+#
+#   This program is free software: you can redistribute it and/or modify it
+#   under the terms of the GNU General Public License as published by the
+#   Free Software Foundation, either version 3 of the License, or (at your
+#   option) any later version.
+#
+#   This program is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+#   Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License along
+#   with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+#   As a special exception, the respective Autoconf Macro's copyright owner
+#   gives unlimited permission to copy, distribute and modify the configure
+#   scripts that are the output of Autoconf when processing the Macro. You
+#   need not follow the terms of the GNU General Public License when using
+#   or distributing such scripts, even though portions of the text of the
+#   Macro appear in them. The GNU General Public License (GPL) does govern
+#   all other use of the material that constitutes the Autoconf Macro.
+#
+#   This special exception to the GPL applies to versions of the Autoconf
+#   Macro released by the Autoconf Archive. When you make and distribute a
+#   modified version of the Autoconf Macro, you may extend this special
+#   exception to the GPL to apply to your modified version as well.
+
+#serial 6
+
+AU_ALIAS([AC_RAF_FUNC_WHICH_GETSERVBYNAME_R], [AX_FUNC_WHICH_GETSERVBYNAME_R])
+AC_DEFUN([AX_FUNC_WHICH_GETSERVBYNAME_R],
+[AC_CACHE_CHECK(for getservbyname_r, ax_cv_func_which_getservbyname_r, [
+AC_CHECK_FUNC(getservbyname_r, [
+        AC_TRY_COMPILE([
+#               include <netdb.h>
+        ],      [
+
+        char *name;
+        char *proto;
+        struct servent *se;
+        struct servent_data data;
+        (void) getservbyname_r(name, proto, se, &data);
+
+                ],ax_cv_func_which_getservbyname_r=four,
+                        [
+  AC_TRY_COMPILE([
+#   include <netdb.h>
+  ], [
+        char *name;
+        char *proto;
+        struct servent *se, *res;
+        char buffer[2048];
+        int buflen = 2048;
+        (void) getservbyname_r(name, proto, se, buffer, buflen, &res)
+  ],ax_cv_func_which_getservbyname_r=six,
+
+  [
+  AC_TRY_COMPILE([
+#   include <netdb.h>
+  ], [
+        char *name;
+        char *proto;
+        struct servent *se;
+        char buffer[2048];
+        int buflen = 2048;
+        (void) getservbyname_r(name, proto, se, buffer, buflen)
+  ],ax_cv_func_which_getservbyname_r=five,ax_cv_func_which_getservbyname_r=no)
+
+  ]
+
+  )
+                        ]
+                )]
+        ,ax_cv_func_which_getservbyname_r=no)])
+
+if test $ax_cv_func_which_getservbyname_r = six; then
+  AC_DEFINE([HAVE_FUNC_GETSERVBYNAME_R_6], [1], [Defined if getservbyname_r have 6 argument])
+elif test $ax_cv_func_which_getservbyname_r = five; then
+  AC_DEFINE([HAVE_FUNC_GETSERVBYNAME_R_5], [1], [Defined if getservbyname_r have 5 argument])
+elif test $ax_cv_func_which_getservbyname_r = four; then
+  AC_DEFINE([HAVE_FUNC_GETSERVBYNAME_R_4], [1], [Defined if getservbyname_r have 4 argument])
+fi
+
+])

Reply via email to