diff --git a/client.c b/client.c index 502fa7dc..90dd9f1d 100644 --- a/client.c +++ b/client.c @@ -52,8 +52,8 @@ int packetSendFollowup(struct in_addr destination, fprintf(stderr,"Could not create UDP socket.\n"); exit(-3); } - int TRUE=1; - setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &TRUE, sizeof(TRUE)); + r=1; + setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &r, sizeof(r)); } r=sendto(sock,packet,packet_len,0,(struct sockaddr *)&peer_addr,sizeof(peer_addr)); @@ -86,8 +86,8 @@ int packetSendRequest(int method,unsigned char *packet,int packet_len,int batchP fprintf(stderr,"Could not create UDP socket.\n"); exit(-3); } - int TRUE=1; - setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &TRUE, sizeof(TRUE)); + i=1; + setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i)); } /* Deal with special case */ diff --git a/commandline.c b/commandline.c index 6500c449..eb0a860f 100644 --- a/commandline.c +++ b/commandline.c @@ -17,7 +17,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#define _GNU_SOURCE // For asprintf() #include #include #include diff --git a/configure.in b/configure.in index f3e3916f..5dd3328d 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,8 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(dna.c) +CPPFLAGS=-D_GNU_SOURCE + dnl Set $host_os, which is needed by javac detection. AC_CANONICAL_SYSTEM @@ -37,11 +39,16 @@ dnl Math library functions for spandsp AC_CHECK_HEADERS([math.h], [INSERT_MATH_HEADER="#include "]) AC_CHECK_HEADERS([float.h]) -dnl Math library functions for spandsp +dnl Check for Linux version of struct ucred AC_CHECK_MEMBER(struct ucred.uid, - [AC_DEFINE([HAVE_STRUCT_UCRED], 1)],, + [AC_DEFINE([HAVE_LINUX_STRUCT_UCRED], 1)],, [#include ]) +dnl Check for BSD version of struct ucred +AC_CHECK_MEMBER(struct xucred.cr_uid, + [AC_DEFINE([HAVE_BSD_STRUCT_UCRED], 1)],, + [#include ]) + dnl Check for a working Java compiler, keep going if unsuccessful. dnl *** Kludge: override AC_MSG_ERROR because AC_PROG_JAVAC does not have dnl *** [if-found] and [if-not-found] action parameters. @@ -75,9 +82,11 @@ AC_CHECK_HEADERS( sys/socket.h \ sys/mman.h \ sys/time.h \ + sys/ucred.h \ poll.h \ netdb.h \ linux/if.h \ + linux/ioctl.h \ linux/netlink.h \ linux/rtnetlink.h \ net/if.h \ diff --git a/monitor.c b/monitor.c index cda8fc4a..617e6368 100644 --- a/monitor.c +++ b/monitor.c @@ -27,13 +27,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "rhizome.h" #include -#ifndef HAVE_STRUCT_UCRED -struct ucred { - pid_t pid; - uid_t uid; - gid_t gid; -}; -#endif // HAVE_STRUCT_UCRED +#if defined(LOCAL_PEERCRED) && !defined(SO_PEERCRED) +#define SO_PEERCRED LOCAL_PEERCRED +#endif /* really shouldn't need more than 2: 1 for rhizome @@ -202,7 +198,14 @@ int monitor_poll() WHYF("ignored_length=%d",ignored_length); int res = fcntl(s,F_SETFL, O_NONBLOCK); if (res) { close(s); continue; } +#if defined(HAVE_LINUX_STRUCT_UCRED) struct ucred ucred; +#elif defined(HAVE_BSD_STRUCT_UCRED) + struct xucred ucred; +#else +#error "Unknown ucred struct" +#endif + uid_t otheruid; socklen_t len=sizeof(ucred); res = getsockopt(s,SOL_SOCKET,SO_PEERCRED,&ucred,&len); if (len>sizeof(ucred)) { @@ -211,9 +214,14 @@ int monitor_poll() if (res) { WHY("Failed to read credentials of monitor.socket client"); close(s); continue; } - if (ucred.uid&&(ucred.uid!=getuid())) { +#if defined(HAVE_LINUX_STRUCT_UCRED) + otheruid = ucred.uid; +#elif defined(HAVE_BSD_STRUCT_UCRED) + otheruid = ucred.cr_uid; +#endif + if (otheruid&&(otheruid!=getuid())) { WHYF("monitor.socket client has wrong uid (%d versus %d)", - ucred.uid,getuid()); + otheruid,getuid()); write(s,"\nCLOSE:Incorrect UID\n",strlen("\nCLOSE:Incorrect UID\n")); close(s); continue; } diff --git a/pa_phone.c b/pa_phone.c index 8508fb8e..0c840988 100644 --- a/pa_phone.c +++ b/pa_phone.c @@ -11,8 +11,6 @@ #define NUM_BUFS (8) #define ECHO_LEN (128) #define ADAPT_MODE (ECHO_CAN_USE_ADAPTION | ECHO_CAN_USE_NLP | ECHO_CAN_USE_CNG) -#define MIN(x, y) ((x) > (y) ? y : x) -#define MAX(x, y) ((x) < (y) ? y : x) #define CODEC2_BYTES_PER_FRAME ((CODEC2_BITS_PER_FRAME + 7) / 8) diff --git a/serval.h b/serval.h index 8306f4dd..aec16d87 100755 --- a/serval.h +++ b/serval.h @@ -59,6 +59,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifdef HAVE_IFADDRS_H #include #endif + +#ifdef HAVE_SYS_UCRED_H +#include +#endif #endif #if !defined(FORASTERISK) && !defined(s_addr) diff --git a/server.c b/server.c index 54c98294..2461ab77 100644 --- a/server.c +++ b/server.c @@ -791,11 +791,11 @@ int createServerSocket() fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, NULL)|O_CLOEXEC); - int TRUE=1; - setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &TRUE, sizeof(TRUE)); + int i=1; + setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i)); errno=0; - if(setsockopt(sock, IPPROTO_IP, IP_RECVTTL, &TRUE,sizeof(TRUE))<0) + if(setsockopt(sock, IPPROTO_IP, IP_RECVTTL, &i,sizeof(i))<0) WHY_perror("setsockopt(IP_RECVTTL)"); bind_addr.sin_family = AF_INET;