summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/debug.c10
-rw-r--r--source3/lib/display_dsdcinfo.c72
-rw-r--r--source3/lib/gencache.c12
-rw-r--r--source3/lib/interfaces.c402
-rw-r--r--source3/lib/netapi/examples/Makefile.in34
-rw-r--r--source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c2
-rw-r--r--source3/lib/netapi/joindomain.c12
-rw-r--r--source3/lib/netapi/netapi.c4
-rw-r--r--source3/lib/netapi/serverinfo.c5
-rw-r--r--source3/lib/privileges_basic.c4
-rw-r--r--source3/lib/repdir.c217
-rw-r--r--source3/lib/replace/Makefile.in6
-rw-r--r--source3/lib/replace/README2
-rw-r--r--source3/lib/replace/configure.ac2
-rw-r--r--source3/lib/replace/dlfcn.c2
-rw-r--r--source3/lib/replace/getifaddrs.c361
-rw-r--r--source3/lib/replace/getifaddrs.m4127
-rw-r--r--source3/lib/replace/getpass.c5
-rw-r--r--source3/lib/replace/getpass.m412
-rw-r--r--source3/lib/replace/libreplace.m474
-rw-r--r--source3/lib/replace/libreplace_ld.m44
-rw-r--r--source3/lib/replace/replace.h20
-rw-r--r--source3/lib/replace/socket.c35
-rw-r--r--source3/lib/replace/socket.m440
-rw-r--r--source3/lib/replace/system/config.m416
-rw-r--r--source3/lib/replace/system/network.h48
-rw-r--r--source3/lib/replace/test/getifaddrs.c100
-rw-r--r--source3/lib/replace/test/testsuite.c17
-rw-r--r--source3/lib/select.c3
-rw-r--r--source3/lib/sock_exec.c8
-rw-r--r--source3/lib/util_nttoken.c50
-rw-r--r--source3/lib/util_reg.c6
-rw-r--r--source3/lib/util_sid.c30
-rw-r--r--source3/lib/util_sock.c8
-rw-r--r--source3/lib/util_str.c30
-rw-r--r--source3/lib/util_tdb.c16
36 files changed, 962 insertions, 834 deletions
diff --git a/source3/lib/debug.c b/source3/lib/debug.c
index 9ff267b607..c4a0d1b47b 100644
--- a/source3/lib/debug.c
+++ b/source3/lib/debug.c
@@ -827,6 +827,7 @@ void check_log_size( void )
};
int priority;
char *msgbuf = NULL;
+ int ret;
if( syslog_level >= ( sizeof(priority_map) / sizeof(priority_map[0]) ) || syslog_level < 0)
priority = LOG_DEBUG;
@@ -834,10 +835,10 @@ void check_log_size( void )
priority = priority_map[syslog_level];
va_start(ap, format_str);
- vasprintf(&msgbuf, format_str, ap);
+ ret = vasprintf(&msgbuf, format_str, ap);
va_end(ap);
- if (msgbuf) {
+ if (ret == -1) {
syslog(priority, "%s", msgbuf);
}
SAFE_FREE(msgbuf);
@@ -1059,12 +1060,13 @@ bool dbghdr(int level, int cls, const char *file, const char *func, int line)
va_list ap;
char *msgbuf = NULL;
bool ret = true;
+ int res;
va_start(ap, format_str);
- vasprintf(&msgbuf, format_str, ap);
+ res = vasprintf(&msgbuf, format_str, ap);
va_end(ap);
- if (msgbuf) {
+ if (res != -1) {
format_debug_text(msgbuf);
} else {
ret = false;
diff --git a/source3/lib/display_dsdcinfo.c b/source3/lib/display_dsdcinfo.c
deleted file mode 100644
index dcb05297a1..0000000000
--- a/source3/lib/display_dsdcinfo.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- Copyright (C) Guenther Deschner 2007
-
- 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 <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-
-/****************************************************************
-****************************************************************/
-
-void display_ds_domain_controller_info(TALLOC_CTX *mem_ctx,
- const struct DS_DOMAIN_CONTROLLER_INFO *info)
-{
- d_printf("domain_controller_name: %s\n",
- info->domain_controller_name);
- d_printf("domain_controller_address: %s\n",
- info->domain_controller_address);
- d_printf("domain_controller_address_type: %d\n",
- info->domain_controller_address_type);
- d_printf("domain_guid: %s\n",
- GUID_string(mem_ctx, info->domain_guid));
- d_printf("domain_name: %s\n",
- info->domain_name);
- d_printf("dns_forest_name: %s\n",
- info->dns_forest_name);
-
- d_printf("flags: 0x%08x\n"
- "\tIs a PDC: %s\n"
- "\tIs a GC of the forest: %s\n"
- "\tIs an LDAP server: %s\n"
- "\tSupports DS: %s\n"
- "\tIs running a KDC: %s\n"
- "\tIs running time services: %s\n"
- "\tIs the closest DC: %s\n"
- "\tIs writable: %s\n"
- "\tHas a hardware clock: %s\n"
- "\tIs a non-domain NC serviced by LDAP server: %s\n"
- "\tDomainControllerName is a DNS name: %s\n"
- "\tDomainName is a DNS name: %s\n"
- "\tDnsForestName is a DNS name: %s\n",
- info->flags,
- (info->flags & ADS_PDC) ? "yes" : "no",
- (info->flags & ADS_GC) ? "yes" : "no",
- (info->flags & ADS_LDAP) ? "yes" : "no",
- (info->flags & ADS_DS) ? "yes" : "no",
- (info->flags & ADS_KDC) ? "yes" : "no",
- (info->flags & ADS_TIMESERV) ? "yes" : "no",
- (info->flags & ADS_CLOSEST) ? "yes" : "no",
- (info->flags & ADS_WRITABLE) ? "yes" : "no",
- (info->flags & ADS_GOOD_TIMESERV) ? "yes" : "no",
- (info->flags & ADS_NDNC) ? "yes" : "no",
- (info->flags & ADS_DNS_CONTROLLER) ? "yes":"no",
- (info->flags & ADS_DNS_DOMAIN) ? "yes":"no",
- (info->flags & ADS_DNS_FOREST) ? "yes":"no");
-
- d_printf("dc_site_name: %s\n", info->dc_site_name);
- d_printf("client_site_name: %s\n", info->client_site_name);
-}
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 663385cfe3..6131269adb 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -120,9 +120,9 @@ bool gencache_set(const char *keystr, const char *value, time_t timeout)
if (!gencache_init()) return False;
- asprintf(&valstr, CACHE_DATA_FMT, (int)timeout, value);
- if (!valstr)
+ if (asprintf(&valstr, CACHE_DATA_FMT, (int)timeout, value) == -1) {
return False;
+ }
databuf = string_term_tdb_data(valstr);
DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout ="
@@ -340,8 +340,7 @@ bool gencache_set_data_blob(const char *keystr, DATA_BLOB *blob, time_t timeout)
return False;
}
- asprintf(&valstr, "%12u/%s", (int)timeout, BLOB_TYPE);
- if (!valstr) {
+ if (asprintf(&valstr, "%12u/%s", (int)timeout, BLOB_TYPE) == -1) {
return False;
}
@@ -452,8 +451,9 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time
break;
}
- asprintf(&fmt, READ_CACHE_DATA_FMT_TEMPLATE, (unsigned int)databuf.dsize - TIMEOUT_LEN);
- if (!fmt) {
+ if (asprintf(&fmt, READ_CACHE_DATA_FMT_TEMPLATE,
+ (unsigned int)databuf.dsize - TIMEOUT_LEN)
+ == -1) {
SAFE_FREE(valstr);
SAFE_FREE(entry);
SAFE_FREE(keystr);
diff --git a/source3/lib/interfaces.c b/source3/lib/interfaces.c
index 3797fc679d..dd857ae672 100644
--- a/source3/lib/interfaces.c
+++ b/source3/lib/interfaces.c
@@ -191,7 +191,6 @@ void make_net(struct sockaddr_storage *pss_out,
Also gets IPv6 interfaces.
****************************************************************************/
-#if HAVE_IFACE_GETIFADDRS
/****************************************************************************
Get the netmask address for a local interface.
****************************************************************************/
@@ -237,19 +236,9 @@ static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
memcpy(&ifaces[total].netmask, ifptr->ifa_netmask, copy_size);
if (ifaces[total].flags & (IFF_BROADCAST|IFF_LOOPBACK)) {
- if (ifptr->ifa_broadaddr) {
- memcpy(&ifaces[total].bcast,
- ifptr->ifa_broadaddr,
- copy_size);
- } else {
- /* For some reason ifptr->ifa_broadaddr
- * is null. Make one from ifa_addr and
- * ifa_netmask.
- */
- make_bcast(&ifaces[total].bcast,
- &ifaces[total].ip,
- &ifaces[total].netmask);
- }
+ make_bcast(&ifaces[total].bcast,
+ &ifaces[total].ip,
+ &ifaces[total].netmask);
} else if ((ifaces[total].flags & IFF_POINTOPOINT) &&
ifptr->ifa_dstaddr ) {
memcpy(&ifaces[total].bcast,
@@ -269,339 +258,6 @@ static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
return total;
}
-#define _FOUND_IFACE_ANY
-#endif /* HAVE_IFACE_GETIFADDRS */
-#if HAVE_IFACE_IFCONF
-
-/* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1
- V4.0, Ultrix 4.4, SCO Unix 3.2, IRIX 6.4 and FreeBSD 3.2.
-
- It probably also works on any BSD style system. */
-
-/****************************************************************************
- Get the netmask address for a local interface.
-****************************************************************************/
-
-static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- struct ifconf ifc;
- char buff[8192];
- int fd, i, n;
- struct ifreq *ifr=NULL;
- int total = 0;
-
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
- return -1;
- }
-
- ifc.ifc_len = sizeof(buff);
- ifc.ifc_buf = buff;
-
- if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
- close(fd);
- return -1;
- }
-
- ifr = ifc.ifc_req;
-
- n = ifc.ifc_len / sizeof(struct ifreq);
-
- /* Loop through interfaces, looking for given IP address */
- for (i=n-1;i>=0 && total < max_interfaces;i--) {
-
- memset(&ifaces[total], '\0', sizeof(ifaces[total]));
-
- /* Check the interface is up. */
- if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) != 0) {
- continue;
- }
-
- ifaces[total].flags = ifr[i].ifr_flags;
-
- if (!(ifaces[total].flags & IFF_UP)) {
- continue;
- }
-
- if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) {
- continue;
- }
-
- strlcpy(ifaces[total].name, ifr[i].ifr_name,
- sizeof(ifaces[total].name));
-
- memcpy(&ifaces[total].ip, &ifr[i].ifr_addr,
- sizeof(struct sockaddr_in));
-
- if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) {
- continue;
- }
-
- memcpy(&ifaces[total].netmask, &ifr[i].ifr_netmask,
- sizeof(struct sockaddr_in));
-
- if (ifaces[total].flags & IFF_BROADCAST) {
- if (ioctl(fd, SIOCGIFBRDADDR, &ifr[i]) != 0) {
- continue;
- }
- memcpy(&ifaces[total].bcast, &ifr[i].ifr_broadaddr,
- sizeof(struct sockaddr_in));
- } else if (ifaces[total].flags & IFF_POINTOPOINT) {
- if (ioctl(fd, SIOCGIFDSTADDR, &ifr[i]) != 0) {
- continue;
- }
- memcpy(&ifaces[total].bcast, &ifr[i].ifr_dstaddr,
- sizeof(struct sockaddr_in));
- } else {
- continue;
- }
-
- total++;
- }
-
- close(fd);
-
- return total;
-}
-
-#define _FOUND_IFACE_ANY
-#endif /* HAVE_IFACE_IFCONF */
-#ifdef HAVE_IFACE_IFREQ
-
-#ifndef I_STR
-#include <sys/stropts.h>
-#endif
-
-/****************************************************************************
- This should cover most of the streams based systems.
- Thanks to Andrej.Borsenkow@mow.siemens.ru for several ideas in this code.
-****************************************************************************/
-
-static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- struct ifreq ifreq;
- struct strioctl strioctl;
- char buff[8192];
- int fd, i, n;
- struct ifreq *ifr=NULL;
- int total = 0;
-
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
- return -1;
- }
-
- strioctl.ic_cmd = SIOCGIFCONF;
- strioctl.ic_dp = buff;
- strioctl.ic_len = sizeof(buff);
- if (ioctl(fd, I_STR, &strioctl) < 0) {
- close(fd);
- return -1;
- }
-
- /* we can ignore the possible sizeof(int) here as the resulting
- number of interface structures won't change */
- n = strioctl.ic_len / sizeof(struct ifreq);
-
- /* we will assume that the kernel returns the length as an int
- at the start of the buffer if the offered size is a
- multiple of the structure size plus an int */
- if (n*sizeof(struct ifreq) + sizeof(int) == strioctl.ic_len) {
- ifr = (struct ifreq *)(buff + sizeof(int));
- } else {
- ifr = (struct ifreq *)buff;
- }
-
- /* Loop through interfaces */
-
- for (i = 0; i<n && total < max_interfaces; i++) {
-
- memset(&ifaces[total], '\0', sizeof(ifaces[total]));
-
- ifreq = ifr[i];
-
- strioctl.ic_cmd = SIOCGIFFLAGS;
- strioctl.ic_dp = (char *)&ifreq;
- strioctl.ic_len = sizeof(struct ifreq);
- if (ioctl(fd, I_STR, &strioctl) != 0) {
- continue;
- }
-
- ifaces[total].flags = ifreq.ifr_flags;
-
- if (!(ifaces[total].flags & IFF_UP)) {
- continue;
- }
-
- strioctl.ic_cmd = SIOCGIFADDR;
- strioctl.ic_dp = (char *)&ifreq;
- strioctl.ic_len = sizeof(struct ifreq);
- if (ioctl(fd, I_STR, &strioctl) != 0) {
- continue;
- }
-
- strlcpy(ifaces[total].name,
- ifreq.ifr_name,
- sizeof(ifaces[total].name));
-
- memcpy(&ifaces[total].ip, &ifreq.ifr_addr,
- sizeof(struct sockaddr_in));
-
- strioctl.ic_cmd = SIOCGIFNETMASK;
- strioctl.ic_dp = (char *)&ifreq;
- strioctl.ic_len = sizeof(struct ifreq);
- if (ioctl(fd, I_STR, &strioctl) != 0) {
- continue;
- }
-
- memcpy(&ifaces[total].netmask, &ifreq.ifr_addr,
- sizeof(struct sockaddr_in));
-
- if (ifaces[total].flags & IFF_BROADCAST) {
- strioctl.ic_cmd = SIOCGIFBRDADDR;
- strioctl.ic_dp = (char *)&ifreq;
- strioctl.ic_len = sizeof(struct ifreq);
- if (ioctl(fd, I_STR, &strioctl) != 0) {
- continue;
- }
- memcpy(&ifaces[total].bcast, &ifreq.ifr_broadaddr,
- sizeof(struct sockaddr_in));
- } else if (ifaces[total].flags & IFF_POINTOPOINT) {
- strioctl.ic_cmd = SIOCGIFDSTADDR;
- strioctl.ic_dp = (char *)&ifreq;
- strioctl.ic_len = sizeof(struct ifreq);
- if (ioctl(fd, I_STR, &strioctl) != 0) {
- continue;
- }
- memcpy(&ifaces[total].bcast, &ifreq.ifr_dstaddr,
- sizeof(struct sockaddr_in));
- } else {
- continue;
- }
-
- total++;
- }
-
- close(fd);
-
- return total;
-}
-
-#define _FOUND_IFACE_ANY
-#endif /* HAVE_IFACE_IFREQ */
-#ifdef HAVE_IFACE_AIX
-
-/****************************************************************************
- This one is for AIX (tested on 4.2).
-****************************************************************************/
-
-static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- char buff[8192];
- int fd, i;
- struct ifconf ifc;
- struct ifreq *ifr=NULL;
- int total = 0;
-
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
- return -1;
- }
-
-
- ifc.ifc_len = sizeof(buff);
- ifc.ifc_buf = buff;
-
- if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
- close(fd);
- return -1;
- }
-
- ifr = ifc.ifc_req;
-
- /* Loop through interfaces */
- i = ifc.ifc_len;
-
- while (i > 0 && total < max_interfaces) {
- uint_t inc;
-
- memset(&ifaces[total], '\0', sizeof(ifaces[total]));
-
- inc = ifr->ifr_addr.sa_len;
-
- if (ioctl(fd, SIOCGIFFLAGS, ifr) != 0) {
- goto next;
- }
-
- ifaces[total].flags = ifr->ifr_flags;
-
- if (!(ifaces[total].flags & IFF_UP)) {
- goto next;
- }
-
- if (ioctl(fd, SIOCGIFADDR, ifr) != 0) {
- goto next;
- }
-
- memcpy(&ifaces[total].ip, &ifr->ifr_addr,
- sizeof(struct sockaddr_in));
-
- strlcpy(ifaces[total].name, ifr->ifr_name,
- sizeof(ifaces[total].name));
-
- if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) {
- goto next;
- }
-
- memcpy(&ifaces[total].netmask, &ifr->ifr_addr,
- sizeof(struct sockaddr_in));
-
- if (ifaces[total].flags & IFF_BROADCAST) {
- if (ioctl(fd, SIOCGIFBRDADDR, ifr) != 0) {
- goto next;
- }
- memcpy(&ifaces[total].bcast, &ifr->ifr_broadaddr,
- sizeof(struct sockaddr_in));
- } else if (ifaces[total].flags & IFF_POINTOPOINT) {
- if (ioctl(fd, SIOCGIFDSTADDR, ifr) != 0) {
- goto next;
- }
- memcpy(&ifaces[total].bcast, &ifr->ifr_dstaddr,
- sizeof(struct sockaddr_in));
- } else {
- goto next;
- }
-
-
- total++;
-
- next:
- /*
- * Patch from Archie Cobbs (archie@whistle.com). The
- * addresses in the SIOCGIFCONF interface list have a
- * minimum size. Usually this doesn't matter, but if
- * your machine has tunnel interfaces, etc. that have
- * a zero length "link address", this does matter. */
-
- if (inc < sizeof(ifr->ifr_addr))
- inc = sizeof(ifr->ifr_addr);
- inc += IFNAMSIZ;
-
- ifr = (struct ifreq*) (((char*) ifr) + inc);
- i -= inc;
- }
-
- close(fd);
- return total;
-}
-
-#define _FOUND_IFACE_ANY
-#endif /* HAVE_IFACE_AIX */
-#ifndef _FOUND_IFACE_ANY
-static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- return -1;
-}
-#endif
-
-
static int iface_comp(struct iface_struct *i1, struct iface_struct *i2)
{
int r;
@@ -693,55 +349,3 @@ int get_interfaces(struct iface_struct *ifaces, int max_interfaces)
return total;
}
-
-#ifdef AUTOCONF_TEST
-/* this is the autoconf driver to test get_interfaces() */
-
-static socklen_t calc_sa_size(struct sockaddr *psa)
-{
- socklen_t sl = sizeof(struct sockaddr_in);
-#if defined(HAVE_IPV6)
- if (psa->sa_family == AF_INET6) {
- sl = sizeof(struct sockaddr_in6);
- }
-#endif
- return sl;
-}
-
- int main()
-{
- struct iface_struct ifaces[MAX_INTERFACES];
- int total = get_interfaces(ifaces, MAX_INTERFACES);
- int i;
-
- printf("got %d interfaces:\n", total);
- if (total <= 0) {
- exit(1);
- }
-
- for (i=0;i<total;i++) {
- char addr[INET6_ADDRSTRLEN];
- int ret;
- printf("%-10s ", ifaces[i].name);
- addr[0] = '\0';
- ret = getnameinfo((struct sockaddr *)&ifaces[i].ip,
- calc_sa_size(&ifaces[i].ip),
- addr, sizeof(addr),
- NULL, 0, NI_NUMERICHOST);
- printf("IP=%s ", addr);
- addr[0] = '\0';
- ret = getnameinfo((struct sockaddr *)&ifaces[i].netmask,
- calc_sa_size(&ifaces[i].netmask),
- addr, sizeof(addr),
- NULL, 0, NI_NUMERICHOST);
- printf("NETMASK=%s ", addr);
- addr[0] = '\0';
- ret = getnameinfo((struct sockaddr *)&ifaces[i].bcast,
- calc_sa_size(&ifaces[i].bcast),
- addr, sizeof(addr),
- NULL, 0, NI_NUMERICHOST);
- printf("BCAST=%s\n", addr);
- }
- return 0;
-}
-#endif
diff --git a/source3/lib/netapi/examples/Makefile.in b/source3/lib/netapi/examples/Makefile.in
index 86e1b1bc2f..000eef118b 100644
--- a/source3/lib/netapi/examples/Makefile.in
+++ b/source3/lib/netapi/examples/Makefile.in
@@ -3,10 +3,11 @@ GTK_LIBS=`pkg-config gtk+-2.0 --libs`
KRB5LIBS=@KRB5_LIBS@
LDAP_LIBS=@LDAP_LIBS@
-LIBS=@LIBS@ -lnetapi
+LIBS=@LIBS@ -lnetapi -ltdb -ltalloc
DEVELOPER_CFLAGS=@DEVELOPER_CFLAGS@
FLAGS=-I../ -L../../../bin @CFLAGS@ $(GTK_FLAGS)
CC=@CC@
+PICFLAG=@PICFLAG@
LDFLAGS=@PIE_LDFLAGS@ @LDFLAGS@
DYNEXP=@DYNEXP@
@@ -14,7 +15,12 @@ DYNEXP=@DYNEXP@
COMPILE_CC = $(CC) -I. $(FLAGS) $(PICFLAG) -c $< -o $@
COMPILE = $(COMPILE_CC)
-BINARY_PREREQS = proto_exists bin/.dummy
+PROGS = bin/getdc@EXEEXT@ \
+ bin/netdomjoin@EXEEXT@ \
+ bin/netdomjoin-gui@EXEEXT@ \
+ bin/getjoinableous@EXEEXT@
+
+all: $(PROGS)
MAKEDIR = || exec false; \
if test -d "$$dir"; then :; else \
@@ -24,6 +30,13 @@ MAKEDIR = || exec false; \
mkdir "$$dir" || \
exec false; fi || exec false
+BINARY_PREREQS = bin/.dummy
+
+bin/.dummy:
+ @if (: >> $@ || : > $@) >/dev/null 2>&1; then :; else \
+ dir=bin $(MAKEDIR); fi
+ @: >> $@ || : > $@ # what a fancy emoticon!
+
.c.o:
@if (: >> $@ || : > $@) >/dev/null 2>&1; then rm -f $@; else \
dir=`echo $@ | sed 's,/[^/]*$$,,;s,^$$,.,'` $(MAKEDIR); fi
@@ -38,30 +51,23 @@ NETDOMJOIN_OBJ = netdomjoin/netdomjoin.o
NETDOMJOIN_GUI_OBJ = netdomjoin-gui/netdomjoin-gui.o
GETJOINABLEOUS_OBJ = getjoinableous/getjoinableous.o
-PROGS = bin/getdc@EXEEXT@ \
- bin/netdomjoin@EXEEXT@ \
- bin/netdomjoin-gui@EXEEXT@ \
- bin/getjoinableous@EXEEXT@
-
-all: $(PROGS)
-
-bin/getdc@EXEEXT@: $(GETDC_OBJ)
+bin/getdc@EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ)
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(GETDC_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
-bin/getjoinableous@EXEEXT@: $(GETJOINABLEOUS_OBJ)
+bin/getjoinableous@EXEEXT@: $(BINARY_PREREQS) $(GETJOINABLEOUS_OBJ)
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(GETJOINABLEOUS_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
-bin/netdomjoin@EXEEXT@: $(NETDOMJOIN_OBJ)
+bin/netdomjoin@EXEEXT@: $(BINARY_PREREQS) $(NETDOMJOIN_OBJ)
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(NETDOMJOIN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS)
-bin/netdomjoin-gui@EXEEXT@: $(NETDOMJOIN_GUI_OBJ)
+bin/netdomjoin-gui@EXEEXT@: $(BINARY_PREREQS) $(NETDOMJOIN_GUI_OBJ)
@echo Linking $@
@$(CC) $(FLAGS) $(GTK_FLAGS) -o $@ $(NETDOMJOIN_GUI_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $(GTK_LIBS)
clean:
-rm -f $(PROGS)
-rm -f core */*~ *~ \
- */*.o */*/*.o */*/*/*.o \
+ */*.o */*/*.o */*/*/*.o
diff --git a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c
index 73b14d4d87..a3719c7442 100644
--- a/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c
+++ b/source3/lib/netapi/examples/netdomjoin-gui/netdomjoin-gui.c
@@ -154,7 +154,7 @@ static void callback_apply_description_change(GtkWidget *widget,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"Failed to change computer description: %s.",
- libnetapi_errstr(status));
+ libnetapi_get_error_string(state->ctx, status));
g_signal_connect_swapped(dialog, "response",
G_CALLBACK(gtk_widget_destroy),
dialog);
diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c
index 55f334b5e1..405f96a87e 100644
--- a/source3/lib/netapi/joindomain.c
+++ b/source3/lib/netapi/joindomain.c
@@ -48,7 +48,7 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx,
if (join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) {
NTSTATUS status;
- struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+ struct netr_DsRGetDCNameInfo *info = NULL;
uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
DS_WRITABLE_REQUIRED |
DS_RETURN_DNS_NAME;
@@ -60,7 +60,7 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx,
return ntstatus_to_werror(status);
}
r->in.dc_name = talloc_strdup(mem_ctx,
- info->domain_controller_name);
+ info->dc_unc);
W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
}
@@ -252,7 +252,7 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx,
} else {
NTSTATUS status;
const char *domain = NULL;
- struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+ struct netr_DsRGetDCNameInfo *info = NULL;
uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
DS_WRITABLE_REQUIRED |
DS_RETURN_DNS_NAME;
@@ -269,7 +269,7 @@ static WERROR NetUnjoinDomainLocal(struct libnetapi_ctx *mem_ctx,
return ntstatus_to_werror(status);
}
r->in.dc_name = talloc_strdup(mem_ctx,
- info->domain_controller_name);
+ info->dc_unc);
W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
}
@@ -562,7 +562,7 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx,
NTSTATUS status;
ADS_STATUS ads_status;
ADS_STRUCT *ads = NULL;
- struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+ struct netr_DsRGetDCNameInfo *info = NULL;
uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
DS_RETURN_DNS_NAME;
@@ -574,7 +574,7 @@ static WERROR NetGetJoinableOUsLocal(struct libnetapi_ctx *ctx,
return ntstatus_to_werror(status);
}
- ads = ads_init(domain, domain, info->domain_controller_name);
+ ads = ads_init(domain, domain, info->dc_unc);
if (!ads) {
return WERR_GENERAL_FAILURE;
}
diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c
index 47b3ba93cf..fb091f6e0b 100644
--- a/source3/lib/netapi/netapi.c
+++ b/source3/lib/netapi/netapi.c
@@ -50,7 +50,9 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
return W_ERROR_V(WERR_NOMEM);
}
- DEBUGLEVEL = 0;
+ if (!DEBUGLEVEL) {
+ DEBUGLEVEL = 0;
+ }
setup_logging("libnetapi", true);
dbf = x_stderr;
diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c
index 7fa166e411..d30e7d97f7 100644
--- a/source3/lib/netapi/serverinfo.c
+++ b/source3/lib/netapi/serverinfo.c
@@ -185,6 +185,9 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx,
}
if (!lp_config_backend_is_registry()) {
+ libnetapi_set_error_string(ctx,
+ "Configuration manipulation requested but not "
+ "supported by backend");
return WERR_NOT_SUPPORTED;
}
@@ -268,7 +271,7 @@ static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
server_name,
level,
- info,
+ &info,
parm_error,
&werr);
if (!NT_STATUS_IS_OK(status)) {
diff --git a/source3/lib/privileges_basic.c b/source3/lib/privileges_basic.c
index 753f7265a1..865c1f655c 100644
--- a/source3/lib/privileges_basic.c
+++ b/source3/lib/privileges_basic.c
@@ -473,7 +473,7 @@ bool se_priv_to_privilege_set( PRIVILEGE_SET *set, SE_PRIV *mask )
/*******************************************************************
*******************************************************************/
-static bool luid_to_se_priv( LUID *luid, SE_PRIV *mask )
+static bool luid_to_se_priv( struct lsa_LUID *luid, SE_PRIV *mask )
{
int i;
uint32 num_privs = count_all_privileges();
@@ -491,7 +491,7 @@ static bool luid_to_se_priv( LUID *luid, SE_PRIV *mask )
/*******************************************************************
*******************************************************************/
-bool privilege_set_to_se_priv( SE_PRIV *mask, PRIVILEGE_SET *privset )
+bool privilege_set_to_se_priv( SE_PRIV *mask, struct lsa_PrivilegeSet *privset )
{
int i;
diff --git a/source3/lib/repdir.c b/source3/lib/repdir.c
deleted file mode 100644
index 08f7d16a81..0000000000
--- a/source3/lib/repdir.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- Copyright (C) Andrew Tridgell 2005
- Updated for Samba3 64-bit cleanliness (C) Jeremy Allison 2006
-
- 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 <http://www.gnu.org/licenses/>.
-*/
-/*
- a replacement for opendir/readdir/telldir/seekdir/closedir for BSD systems
-
- This is needed because the existing directory handling in FreeBSD
- and OpenBSD (and possibly NetBSD) doesn't correctly handle unlink()
- on files in a directory where telldir() has been used. On a block
- boundary it will occasionally miss a file when seekdir() is used to
- return to a position previously recorded with telldir().
-
- This also fixes a severe performance and memory usage problem with
- telldir() on BSD systems. Each call to telldir() in BSD adds an
- entry to a linked list, and those entries are cleaned up on
- closedir(). This means with a large directory closedir() can take an
- arbitrary amount of time, causing network timeouts as millions of
- telldir() entries are freed
-
- Note! This replacement code is not portable. It relies on getdents()
- always leaving the file descriptor at a seek offset that is a
- multiple of DIR_BUF_SIZE. If the code detects that this doesn't
- happen then it will abort(). It also does not handle directories
- with offsets larger than can be stored in a long,
-
- This code is available under other free software licenses as
- well. Contact the author.
-*/
-
-#include <include/includes.h>
-
- void replace_readdir_dummy(void);
- void replace_readdir_dummy(void) {}
-
-#if defined(REPLACE_READDIR)
-
-#if defined(PARANOID_MALLOC_CHECKER)
-#ifdef malloc
-#undef malloc
-#endif
-#endif
-
-#define DIR_BUF_BITS 9
-#define DIR_BUF_SIZE (1<<DIR_BUF_BITS)
-
-struct dir_buf {
- int fd;
- int nbytes, ofs;
- SMB_OFF_T seekpos;
- char buf[DIR_BUF_SIZE];
-};
-
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPENDIR64)
- SMB_STRUCT_DIR *opendir64(const char *dname)
-#else
- SMB_STRUCT_DIR *opendir(const char *dname)
-#endif
-{
- struct dir_buf *d;
- d = malloc(sizeof(*d));
- if (d == NULL) {
- errno = ENOMEM;
- return NULL;
- }
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPEN64)
- d->fd = open64(dname, O_RDONLY);
-#else
- d->fd = open(dname, O_RDONLY);
-#endif
-
- if (d->fd == -1) {
- free(d);
- return NULL;
- }
- d->ofs = 0;
- d->seekpos = 0;
- d->nbytes = 0;
- return (SMB_STRUCT_DIR *)d;
-}
-
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_READDIR64)
- SMB_STRUCT_DIRENT *readdir64(SMB_STRUCT_DIR *dir)
-#else
- SMB_STRUCT_DIRENT *readdir(SMB_STRUCT_DIR *dir)
-#endif
-{
- struct dir_buf *d = (struct dir_buf *)dir;
- SMB_STRUCT_DIRENT *de;
-
- if (d->ofs >= d->nbytes) {
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_LSEEK64)
- d->seekpos = lseek64(d->fd, 0, SEEK_CUR);
-#else
- d->seekpos = lseek(d->fd, 0, SEEK_CUR);
-#endif
-
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_GETDENTS64)
- d->nbytes = getdents64(d->fd, d->buf, DIR_BUF_SIZE);
-#else
- d->nbytes = getdents(d->fd, d->buf, DIR_BUF_SIZE);
-#endif
- d->ofs = 0;
- }
- if (d->ofs >= d->nbytes) {
- return NULL;
- }
- de = (SMB_STRUCT_DIRENT *)&d->buf[d->ofs];
- d->ofs += de->d_reclen;
- return de;
-}
-
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_TELLDIR64)
- long telldir64(SMB_STRUCT_DIR *dir)
-#else
- long telldir(SMB_STRUCT_DIR *dir)
-#endif
-{
- struct dir_buf *d = (struct dir_buf *)dir;
- if (d->ofs >= d->nbytes) {
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_LSEEK64)
- d->seekpos = lseek64(d->fd, 0, SEEK_CUR);
-#else
- d->seekpos = lseek(d->fd, 0, SEEK_CUR);
-#endif
- d->ofs = 0;
- d->nbytes = 0;
- }
- /* this relies on seekpos always being a multiple of
- DIR_BUF_SIZE. Is that always true on BSD systems? */
- if (d->seekpos & (DIR_BUF_SIZE-1)) {
- abort();
- }
- return d->seekpos + d->ofs;
-}
-
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_SEEKDIR64)
- void seekdir64(SMB_STRUCT_DIR *dir, long ofs)
-#else
- void seekdir(SMB_STRUCT_DIR *dir, long ofs)
-#endif
-{
- struct dir_buf *d = (struct dir_buf *)dir;
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_LSEEK64)
- d->seekpos = lseek64(d->fd, ofs & ~(DIR_BUF_SIZE-1), SEEK_SET);
-#else
- d->seekpos = lseek(d->fd, ofs & ~(DIR_BUF_SIZE-1), SEEK_SET);
-#endif
-
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_GETDENTS64)
- d->nbytes = getdents64(d->fd, d->buf, DIR_BUF_SIZE);
-#else
- d->nbytes = getdents(d->fd, d->buf, DIR_BUF_SIZE);
-#endif
-
- d->ofs = 0;
- while (d->ofs < (ofs & (DIR_BUF_SIZE-1))) {
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_READDIR64)
- if (readdir64(dir) == NULL) break;
-#else
- if (readdir(dir) == NULL) break;
-#endif
- }
-}
-
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_REWINDDIR64)
- void rewinddir64(SMB_STRUCT_DIR *dir)
-#else
- void rewinddir(SMB_STRUCT_DIR *dir)
-#endif
-{
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_SEEKDIR64)
- seekdir64(dir, 0);
-#else
- seekdir(dir, 0);
-#endif
-}
-
-#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CLOSEDIR64)
- int closedir64(SMB_STRUCT_DIR *dir)
-#else
- int closedir(SMB_STRUCT_DIR *dir)
-#endif
-{
- struct dir_buf *d = (struct dir_buf *)dir;
- int r = close(d->fd);
- if (r != 0) {
- return r;
- }
- free(d);
- return 0;
-}
-
-#ifndef dirfd
-/* darn, this is a macro on some systems. */
- int dirfd(SMB_STRUCT_DIR *dir)
-{
- struct dir_buf *d = (struct dir_buf *)dir;
- return d->fd;
-}
-#endif
-#endif /* REPLACE_READDIR */
diff --git a/source3/lib/replace/Makefile.in b/source3/lib/replace/Makefile.in
index 30f39ac6cb..c989835a8d 100644
--- a/source3/lib/replace/Makefile.in
+++ b/source3/lib/replace/Makefile.in
@@ -10,6 +10,7 @@ VPATH = @libreplacedir@
srcdir = @srcdir@
builddir = @builddir@
INSTALL = @INSTALL@
+LIBS = @LIBS@
.PHONY: test all showflags install installcheck clean distclean realdistclean
@@ -25,6 +26,7 @@ showflags:
@echo ' CC = $(CC)'
@echo ' CFLAGS = $(CFLAGS)'
@echo ' LDFLAGS= $(LDFLAGS)'
+ @echo ' LIBS = $(LIBS)'
install: all
mkdir -p $(libdir)
@@ -38,10 +40,10 @@ test: all
installcheck: install test
-TEST_OBJS = test/testsuite.o test/os2_delete.o test/strptime.o
+TEST_OBJS = test/testsuite.o test/os2_delete.o test/strptime.o test/getifaddrs.o
testsuite: libreplace.a $(TEST_OBJS)
- $(CC) -o testsuite $(TEST_OBJS) -L. -lreplace $(LDFLAGS)
+ $(CC) -o testsuite $(TEST_OBJS) -L. -lreplace $(LDFLAGS) $(LIBS)
.c.o:
@echo Compiling $*.c
diff --git a/source3/lib/replace/README b/source3/lib/replace/README
index c61f78a951..268a1b15cf 100644
--- a/source3/lib/replace/README
+++ b/source3/lib/replace/README
@@ -60,6 +60,8 @@ getaddrinfo
freeaddrinfo
getnameinfo
gai_strerror
+getifaddrs
+freeifaddrs
Types:
bool
diff --git a/source3/lib/replace/configure.ac b/source3/lib/replace/configure.ac
index beeb77e152..f5e054f476 100644
--- a/source3/lib/replace/configure.ac
+++ b/source3/lib/replace/configure.ac
@@ -3,6 +3,8 @@ AC_INIT(replace.c)
AC_CONFIG_SRCDIR([replace.c])
AC_CONFIG_HEADER(config.h)
+CFLAGS="$CFLAGS -I$srcdir"
+
AC_LIBREPLACE_ALL_CHECKS
if test "$ac_cv_prog_gcc" = yes; then
diff --git a/source3/lib/replace/dlfcn.c b/source3/lib/replace/dlfcn.c
index 42848848e8..3b109d7e40 100644
--- a/source3/lib/replace/dlfcn.c
+++ b/source3/lib/replace/dlfcn.c
@@ -35,6 +35,8 @@ void *rep_dlopen(const char *name, int flags)
#endif
{
#ifdef HAVE_SHL_LOAD
+ if (name == NULL)
+ return PROG_HANDLE;
return (void *)shl_load(name, flags, 0);
#else
return NULL;
diff --git a/source3/lib/replace/getifaddrs.c b/source3/lib/replace/getifaddrs.c
new file mode 100644
index 0000000000..f6f0ec080c
--- /dev/null
+++ b/source3/lib/replace/getifaddrs.c
@@ -0,0 +1,361 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Andrew Tridgell 1998
+ Copyright (C) Jeremy Allison 2007
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#define SOCKET_WRAPPER_NOT_REPLACE
+
+#include "replace.h"
+#include "system/network.h"
+
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#ifndef SIOCGIFCONF
+#ifdef HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
+#endif
+
+#ifdef HAVE_IFACE_GETIFADDRS
+#define _FOUND_IFACE_ANY
+#else
+
+void rep_freeifaddrs(struct ifaddrs *ifp)
+{
+ if (ifp != NULL) {
+ free(ifp->ifa_name);
+ free(ifp->ifa_addr);
+ free(ifp->ifa_netmask);
+ free(ifp->ifa_dstaddr);
+ freeifaddrs(ifp->ifa_next);
+ free(ifp);
+ }
+}
+
+static struct sockaddr *sockaddr_dup(struct sockaddr *sa)
+{
+ struct sockaddr *ret;
+ socklen_t socklen;
+#ifdef HAVE_SOCKADDR_SA_LEN
+ socklen = sa->sa_len;
+#else
+ socklen = sizeof(struct sockaddr_storage);
+#endif
+ ret = calloc(1, socklen);
+ if (ret == NULL)
+ return NULL;
+ memcpy(ret, sa, socklen);
+ return ret;
+}
+#endif
+
+#if HAVE_IFACE_IFCONF
+
+/* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1
+ V4.0, Ultrix 4.4, SCO Unix 3.2, IRIX 6.4 and FreeBSD 3.2.
+
+ It probably also works on any BSD style system. */
+
+int rep_getifaddrs(struct ifaddrs **ifap)
+{
+ struct ifconf ifc;
+ char buff[8192];
+ int fd, i, n;
+ struct ifreq *ifr=NULL;
+ struct in_addr ipaddr;
+ struct in_addr nmask;
+ char *iname;
+ struct ifaddrs *curif;
+ struct ifaddrs *lastif = NULL;
+
+ *ifap = NULL;
+
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
+ return -1;
+ }
+
+ ifc.ifc_len = sizeof(buff);
+ ifc.ifc_buf = buff;
+
+ if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
+ close(fd);
+ return -1;
+ }
+
+ ifr = ifc.ifc_req;
+
+ n = ifc.ifc_len / sizeof(struct ifreq);
+
+ /* Loop through interfaces, looking for given IP address */
+ for (i=n-1; i>=0; i--) {
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) == -1) {
+ freeifaddrs(*ifap);
+ return -1;
+ }
+
+ curif = calloc(1, sizeof(struct ifaddrs));
+ curif->ifa_name = strdup(ifr[i].ifr_name);
+ curif->ifa_flags = ifr[i].ifr_flags;
+ curif->ifa_dstaddr = NULL;
+ curif->ifa_data = NULL;
+ curif->ifa_next = NULL;
+
+ curif->ifa_addr = NULL;
+ if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != -1) {
+ curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr);
+ }
+
+ curif->ifa_netmask = NULL;
+ if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != -1) {
+ curif->ifa_netmask = sockaddr_dup(&ifr[i].ifr_addr);
+ }
+
+ if (lastif == NULL) {
+ *ifap = curif;
+ } else {
+ lastif->ifa_next = curif;
+ }
+ lastif = curif;
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+#define _FOUND_IFACE_ANY
+#endif /* HAVE_IFACE_IFCONF */
+#ifdef HAVE_IFACE_IFREQ
+
+#ifndef I_STR
+#include <sys/stropts.h>
+#endif
+
+/****************************************************************************
+this should cover most of the streams based systems
+Thanks to Andrej.Borsenkow@mow.siemens.ru for several ideas in this code
+****************************************************************************/
+int rep_getifaddrs(struct ifaddrs **ifap)
+{
+ struct ifreq ifreq;
+ struct strioctl strioctl;
+ char buff[8192];
+ int fd, i, n;
+ struct ifreq *ifr=NULL;
+ struct in_addr ipaddr;
+ struct in_addr nmask;
+ char *iname;
+ struct ifaddrs *curif;
+ struct ifaddrs *lastif = NULL;
+
+ *ifap = NULL;
+
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
+ return -1;
+ }
+
+ strioctl.ic_cmd = SIOCGIFCONF;
+ strioctl.ic_dp = buff;
+ strioctl.ic_len = sizeof(buff);
+ if (ioctl(fd, I_STR, &strioctl) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ /* we can ignore the possible sizeof(int) here as the resulting
+ number of interface structures won't change */
+ n = strioctl.ic_len / sizeof(struct ifreq);
+
+ /* we will assume that the kernel returns the length as an int
+ at the start of the buffer if the offered size is a
+ multiple of the structure size plus an int */
+ if (n*sizeof(struct ifreq) + sizeof(int) == strioctl.ic_len) {
+ ifr = (struct ifreq *)(buff + sizeof(int));
+ } else {
+ ifr = (struct ifreq *)buff;
+ }
+
+ /* Loop through interfaces */
+
+ for (i = 0; i<n; i++) {
+ ifreq = ifr[i];
+
+ curif = calloc(1, sizeof(struct ifaddrs));
+ if (lastif == NULL) {
+ *ifap = curif;
+ } else {
+ lastif->ifa_next = curif;
+ }
+
+ strioctl.ic_cmd = SIOCGIFFLAGS;
+ strioctl.ic_dp = (char *)&ifreq;
+ strioctl.ic_len = sizeof(struct ifreq);
+ if (ioctl(fd, I_STR, &strioctl) != 0) {
+ freeifaddrs(*ifap);
+ return -1;
+ }
+
+ curif->ifa_flags = ifreq.ifr_flags;
+
+ strioctl.ic_cmd = SIOCGIFADDR;
+ strioctl.ic_dp = (char *)&ifreq;
+ strioctl.ic_len = sizeof(struct ifreq);
+ if (ioctl(fd, I_STR, &strioctl) != 0) {
+ freeifaddrs(*ifap);
+ return -1;
+ }
+
+ curif->ifa_name = strdup(ifreq.ifr_name);
+ curif->ifa_addr = sockaddr_dup(&ifreq.ifr_addr);
+ curif->ifa_dstaddr = NULL;
+ curif->ifa_data = NULL;
+ curif->ifa_next = NULL;
+ curif->ifa_netmask = NULL;
+
+ strioctl.ic_cmd = SIOCGIFNETMASK;
+ strioctl.ic_dp = (char *)&ifreq;
+ strioctl.ic_len = sizeof(struct ifreq);
+ if (ioctl(fd, I_STR, &strioctl) != 0) {
+ freeifaddrs(*ifap);
+ return -1;
+ }
+
+ curif->ifa_netmask = sockaddr_dup(&ifreq.ifr_addr);
+
+ lastif = curif;
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+#define _FOUND_IFACE_ANY
+#endif /* HAVE_IFACE_IFREQ */
+#ifdef HAVE_IFACE_AIX
+
+/****************************************************************************
+this one is for AIX (tested on 4.2)
+****************************************************************************/
+int rep_getifaddrs(struct ifaddrs **ifap)
+{
+ char buff[8192];
+ int fd, i;
+ struct ifconf ifc;
+ struct ifreq *ifr=NULL;
+ struct in_addr ipaddr;
+ struct in_addr nmask;
+ char *iname;
+ struct ifaddrs *curif;
+ struct ifaddrs *lastif = NULL;
+
+ *ifap = NULL;
+
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
+ return -1;
+ }
+
+ ifc.ifc_len = sizeof(buff);
+ ifc.ifc_buf = buff;
+
+ if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
+ close(fd);
+ return -1;
+ }
+
+ ifr = ifc.ifc_req;
+
+ /* Loop through interfaces */
+ i = ifc.ifc_len;
+
+ while (i > 0) {
+ uint_t inc;
+
+ inc = ifr->ifr_addr.sa_len;
+
+ if (ioctl(fd, SIOCGIFADDR, ifr) != 0) {
+ freeaddrinfo(*ifap);
+ return -1;
+ }
+
+ curif = calloc(1, sizeof(struct ifaddrs));
+ if (lastif == NULL) {
+ *ifap = curif;
+ } else {
+ lastif->ifa_next = curif;
+ }
+
+ curif->ifa_name = strdup(ifr->ifr_name);
+ curif->ifa_addr = sockaddr_dup(&ifr->ifr_addr);
+ curif->ifa_dstaddr = NULL;
+ curif->ifa_data = NULL;
+ curif->ifa_netmask = NULL;
+ curif->ifa_next = NULL;
+
+ if (ioctl(fd, SIOCGIFFLAGS, ifr) != 0) {
+ freeaddrinfo(*ifap);
+ return -1;
+ }
+
+ curif->ifa_flags = ifr->ifr_flags;
+
+ if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) {
+ freeaddrinfo(*ifap);
+ return -1;
+ }
+
+ curif->ifa_netmask = sockaddr_dup(&ifr->ifr_addr);
+
+ lastif = curif;
+
+ next:
+ /*
+ * Patch from Archie Cobbs (archie@whistle.com). The
+ * addresses in the SIOCGIFCONF interface list have a
+ * minimum size. Usually this doesn't matter, but if
+ * your machine has tunnel interfaces, etc. that have
+ * a zero length "link address", this does matter. */
+
+ if (inc < sizeof(ifr->ifr_addr))
+ inc = sizeof(ifr->ifr_addr);
+ inc += IFNAMSIZ;
+
+ ifr = (struct ifreq*) (((char*) ifr) + inc);
+ i -= inc;
+ }
+
+ close(fd);
+ return 0;
+}
+
+#define _FOUND_IFACE_ANY
+#endif /* HAVE_IFACE_AIX */
+#ifndef _FOUND_IFACE_ANY
+int rep_getifaddrs(struct ifaddrs **ifap)
+{
+ errno = ENOSYS;
+ return -1;
+}
+#endif
diff --git a/source3/lib/replace/getifaddrs.m4 b/source3/lib/replace/getifaddrs.m4
new file mode 100644
index 0000000000..6cca155de3
--- /dev/null
+++ b/source3/lib/replace/getifaddrs.m4
@@ -0,0 +1,127 @@
+AC_CHECK_HEADERS([ifaddrs.h])
+
+dnl Used when getifaddrs is not available
+AC_CHECK_MEMBERS([struct sockaddr.sa_len],
+ [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])],
+ [],
+ [#include <sys/socket.h>])
+
+dnl test for getifaddrs and freeifaddrs
+AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[
+AC_TRY_COMPILE([
+#include <sys/types.h>
+#if STDC_HEADERS
+#include <stdlib.h>
+#include <stddef.h>
+#endif
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <ifaddrs.h>
+#include <netdb.h>],
+[
+struct ifaddrs *ifp = NULL;
+int ret = getifaddrs (&ifp);
+freeifaddrs(ifp);
+],
+libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)])
+if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then
+ AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs])
+ AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs])
+ AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available])
+fi
+
+##################
+# look for a method of finding the list of network interfaces
+#
+# This tests need LIBS="$NSL_LIBS $SOCKET_LIBS"
+#
+old_LIBS=$LIBS
+LIBS="$NSL_LIBS $SOCKET_LIBS"
+iface=no;
+##################
+# look for a method of finding the list of network interfaces
+iface=no;
+AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[
+AC_TRY_RUN([
+#define HAVE_IFACE_GETIFADDRS 1
+#define NO_CONFIG_H 1
+#define AUTOCONF_TEST 1
+#define SOCKET_WRAPPER_NOT_REPLACE
+#include "$libreplacedir/replace.c"
+#include "$libreplacedir/inet_ntop.c"
+#include "$libreplacedir/snprintf.c"
+#include "$libreplacedir/getifaddrs.c"
+#define getifaddrs_test main
+#include "$libreplacedir/test/getifaddrs.c"],
+ libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)])
+if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then
+ iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available])
+else
+ LIBREPLACEOBJ="${LIBREPLACEOBJ} getifaddrs.o"
+fi
+
+
+if test $iface = no; then
+AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[
+AC_TRY_RUN([
+#define HAVE_IFACE_AIX 1
+#define NO_CONFIG_H 1
+#define AUTOCONF_TEST 1
+#undef _XOPEN_SOURCE_EXTENDED
+#define SOCKET_WRAPPER_NOT_REPLACE
+#include "$libreplacedir/replace.c"
+#include "$libreplacedir/inet_ntop.c"
+#include "$libreplacedir/snprintf.c"
+#include "$libreplacedir/getifaddrs.c"
+#define getifaddrs_test main
+#include "$libreplacedir/test/getifaddrs.c"],
+ libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)])
+if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then
+ iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available])
+ old_LIBS="$old_LIBS $LIBS"
+fi
+fi
+
+
+if test $iface = no; then
+AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[
+AC_TRY_RUN([
+#define HAVE_IFACE_IFCONF 1
+#define NO_CONFIG_H 1
+#define AUTOCONF_TEST 1
+#define SOCKET_WRAPPER_NOT_REPLACE
+#include "$libreplacedir/replace.c"
+#include "$libreplacedir/inet_ntop.c"
+#include "$libreplacedir/snprintf.c"
+#include "$libreplacedir/getifaddrs.c"
+#define getifaddrs_test main
+#include "$libreplacedir/test/getifaddrs.c"],
+ libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)])
+if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then
+ iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available])
+ old_LIBS="$old_LIBS $LIBS"
+fi
+fi
+
+if test $iface = no; then
+AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[
+AC_TRY_RUN([
+#define HAVE_IFACE_IFREQ 1
+#define NO_CONFIG_H 1
+#define AUTOCONF_TEST 1
+#define SOCKET_WRAPPER_NOT_REPLACE
+#include "$libreplacedir/replace.c"
+#include "$libreplacedir/inet_ntop.c"
+#include "$libreplacedir/snprintf.c"
+#include "$libreplacedir/getifaddrs.c"
+#define getifaddrs_test main
+#include "$libreplacedir/test/getifaddrs.c"],
+ libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)])
+if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then
+ iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available])
+ old_LIBS="$old_LIBS $LIBS"
+fi
+fi
+
+LIBS=$old_LIBS
diff --git a/source3/lib/replace/getpass.c b/source3/lib/replace/getpass.c
index d91d029f6a..57e28eb981 100644
--- a/source3/lib/replace/getpass.c
+++ b/source3/lib/replace/getpass.c
@@ -185,7 +185,10 @@ char *rep_getpass(const char *prompt)
buf[0] = 0;
if (!gotintr) {
in_fd = fileno(in);
- fgets(buf, bufsize, in);
+ if (fgets(buf, bufsize, in) == NULL) {
+ buf[0] = 0;
+ return buf;
+ }
}
nread = strlen(buf);
if (nread) {
diff --git a/source3/lib/replace/getpass.m4 b/source3/lib/replace/getpass.m4
index c4da9aae59..b93817f9d3 100644
--- a/source3/lib/replace/getpass.m4
+++ b/source3/lib/replace/getpass.m4
@@ -1,22 +1,22 @@
-AC_CHECK_FUNC(getpass, samba_cv_HAVE_GETPASS=yes)
-AC_CHECK_FUNC(getpassphrase, samba_cv_HAVE_GETPASSPHRASE=yes)
-if test x"$samba_cv_HAVE_GETPASS" = x"yes" -a x"$samba_cv_HAVE_GETPASSPHRASE" = x"yes"; then
+AC_CHECK_FUNC(getpass, libreplace_cv_HAVE_GETPASS=yes)
+AC_CHECK_FUNC(getpassphrase, libreplace_cv_HAVE_GETPASSPHRASE=yes)
+if test x"$libreplace_cv_HAVE_GETPASS" = x"yes" -a x"$libreplace_cv_HAVE_GETPASSPHRASE" = x"yes"; then
AC_DEFINE(REPLACE_GETPASS_BY_GETPASSPHRASE, 1, [getpass returns <9 chars where getpassphrase returns <265 chars])
AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
LIBREPLACEOBJ="${LIBREPLACEOBJ} getpass.o"
else
-AC_CACHE_CHECK([whether getpass should be replaced],samba_cv_REPLACE_GETPASS,[
+AC_CACHE_CHECK([whether getpass should be replaced],libreplace_cv_REPLACE_GETPASS,[
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -I$libreplacedir/"
AC_TRY_COMPILE([
#include "confdefs.h"
#define NO_CONFIG_H
#include "$libreplacedir/getpass.c"
-],[],samba_cv_REPLACE_GETPASS=yes,samba_cv_REPLACE_GETPASS=no)
+],[],libreplace_cv_REPLACE_GETPASS=yes,libreplace_cv_REPLACE_GETPASS=no)
CPPFLAGS="$SAVE_CPPFLAGS"
])
-if test x"$samba_cv_REPLACE_GETPASS" = x"yes"; then
+if test x"$libreplace_cv_REPLACE_GETPASS" = x"yes"; then
AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
LIBREPLACEOBJ="${LIBREPLACEOBJ} getpass.o"
fi
diff --git a/source3/lib/replace/libreplace.m4 b/source3/lib/replace/libreplace.m4
index f866b3648f..e0cc57f4c8 100644
--- a/source3/lib/replace/libreplace.m4
+++ b/source3/lib/replace/libreplace.m4
@@ -85,10 +85,10 @@ AC_INCLUDES_DEFAULT
#endif]
)
-AC_CACHE_CHECK([for working mmap],samba_cv_HAVE_MMAP,[
+AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[
AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
- samba_cv_HAVE_MMAP=yes,samba_cv_HAVE_MMAP=no,samba_cv_HAVE_MMAP=cross)])
-if test x"$samba_cv_HAVE_MMAP" = x"yes"; then
+ libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)])
+if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then
AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
fi
@@ -120,7 +120,7 @@ if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
fi
-AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
+AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[
AC_TRY_RUN([
#include <stdio.h>
#include <unistd.h>
@@ -133,8 +133,8 @@ main() { struct in_addr ip; ip.s_addr = 0x12345678;
if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
exit(1);}],
- samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
-if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
+ libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)])
+if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then
AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
fi
@@ -182,7 +182,7 @@ AC_HAVE_DECL(setresuid, [#include <unistd.h>])
AC_HAVE_DECL(setresgid, [#include <unistd.h>])
AC_HAVE_DECL(errno, [#include <errno.h>])
-AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
+AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[
AC_TRY_RUN([#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -197,10 +197,10 @@ main() {
if ((st.st_mode & 0777) != 0600) exit(1);
exit(0);
}],
-samba_cv_HAVE_SECURE_MKSTEMP=yes,
-samba_cv_HAVE_SECURE_MKSTEMP=no,
-samba_cv_HAVE_SECURE_MKSTEMP=cross)])
-if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
+libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
+libreplace_cv_HAVE_SECURE_MKSTEMP=no,
+libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
+if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
fi
@@ -209,7 +209,7 @@ AC_CHECK_HEADERS(stdio.h strings.h)
AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
-AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
+AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
AC_TRY_RUN([
#include <sys/types.h>
#include <stdio.h>
@@ -243,43 +243,43 @@ void foo(const char *format, ...) {
}
main() { foo("hello"); }
],
-samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
-if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
+libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
+if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
fi
dnl VA_COPY
-AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
+AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
AC_TRY_LINK([#include <stdarg.h>
va_list ap1,ap2;], [va_copy(ap1,ap2);],
-samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
-if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
+libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
+if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
fi
-if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
-AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
+if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
+AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
AC_TRY_LINK([#include <stdarg.h>
va_list ap1,ap2;], [__va_copy(ap1,ap2);],
-samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
-if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
+libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
+if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
fi
fi
dnl __FUNCTION__ macro
-AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
+AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
-samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
-if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
+libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
+if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
else
dnl __func__ macro
- AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
+ AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
- samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
- if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
+ libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
+ if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
fi
fi
@@ -302,7 +302,7 @@ eprintf("bla", "bar");
], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
-AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
+AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
AC_TRY_COMPILE([
#include <sys/types.h>
#if STDC_HEADERS
@@ -310,30 +310,30 @@ AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
#include <stddef.h>
#endif
#include <signal.h>],[sig_atomic_t i = 0],
- samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
-if test x"$samba_cv_sig_atomic_t" = x"yes"; then
+ libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
+if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
fi
-AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[
+AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
AC_TRY_COMPILE([
#include <unistd.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif],
[int fd = open("/dev/null", O_DIRECT);],
-samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)])
-if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
+libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
+if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
fi
dnl Check if the C compiler understands volatile (it should, being ANSI).
-AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
+AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
- samba_cv_volatile=yes,samba_cv_volatile=no)])
-if test x"$samba_cv_volatile" = x"yes"; then
+ libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
+if test x"$libreplace_cv_volatile" = x"yes"; then
AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
fi
@@ -344,10 +344,12 @@ m4_include(getpass.m4)
m4_include(strptime.m4)
m4_include(win32.m4)
m4_include(timegm.m4)
+m4_include(socket.m4)
m4_include(inet_ntop.m4)
m4_include(inet_pton.m4)
m4_include(getaddrinfo.m4)
m4_include(repdir.m4)
+m4_include(getifaddrs.m4)
AC_CHECK_FUNCS([syslog printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
diff --git a/source3/lib/replace/libreplace_ld.m4 b/source3/lib/replace/libreplace_ld.m4
index 08defb091f..f0d10c1e3e 100644
--- a/source3/lib/replace/libreplace_ld.m4
+++ b/source3/lib/replace/libreplace_ld.m4
@@ -246,10 +246,6 @@ AC_DEFUN([AC_LD_SONAMEFLAG],
# Not supported
SONAMEFLAG="#"
;;
- *aix*)
- # Not supported
- SONAMEFLAG="#"
- ;;
esac
])
diff --git a/source3/lib/replace/replace.h b/source3/lib/replace/replace.h
index 1d1cbc2cd2..0d16f4ffd0 100644
--- a/source3/lib/replace/replace.h
+++ b/source3/lib/replace/replace.h
@@ -340,6 +340,26 @@ ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)
/* prototype is in "system/network.h" */
#endif
+#ifndef HAVE_CONNECT
+#define connect rep_connect
+/* prototype is in "system/network.h" */
+#endif
+
+#ifndef HAVE_GETHOSTBYNAME
+#define gethostbyname rep_gethostbyname
+/* prototype is in "system/network.h" */
+#endif
+
+#ifndef HAVE_GETIFADDRS
+#define getifaddrs rep_getifaddrs
+/* prototype is in "system/network.h" */
+#endif
+
+#ifndef HAVE_FREEIFADDRS
+#define freeifaddrs rep_freeifaddrs
+/* prototype is in "system/network.h" */
+#endif
+
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
diff --git a/source3/lib/replace/socket.c b/source3/lib/replace/socket.c
new file mode 100644
index 0000000000..35e975fce7
--- /dev/null
+++ b/source3/lib/replace/socket.c
@@ -0,0 +1,35 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * Dummy replacements for socket functions.
+ *
+ * Copyright (C) Michael Adam <obnox@samba.org> 2008
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "system/network.h"
+
+int rep_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
+struct hostent *rep_gethostbyname(const char *name)
+{
+ errno = ENOSYS;
+ return NULL;
+}
diff --git a/source3/lib/replace/socket.m4 b/source3/lib/replace/socket.m4
new file mode 100644
index 0000000000..c0c8f93e81
--- /dev/null
+++ b/source3/lib/replace/socket.m4
@@ -0,0 +1,40 @@
+dnl The following test is roughl taken from the cvs sources.
+dnl
+dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
+dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
+dnl libsocket.so which has a bad implementation of gethostbyname (it
+dnl only looks in /etc/hosts), so we only look for -lsocket if we need
+dnl it.
+AC_CHECK_FUNCS(connect)
+if test x"$ac_cv_func_connect" = x"no"; then
+ AC_CHECK_LIB_EXT(nsl_s, SOCKET_LIBS, connect)
+ AC_CHECK_LIB_EXT(nsl, SOCKET_LIBS, connect)
+ AC_CHECK_LIB_EXT(socket, SOCKET_LIBS, connect)
+ AC_CHECK_LIB_EXT(inet, SOCKET_LIBS, connect)
+ dnl We can't just call AC_CHECK_FUNCS(connect) here,
+ dnl because the value has been cached.
+ if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" ||
+ test x"$ac_cv_lib_ext_nsl_connect" = x"yes" ||
+ test x"$ac_cv_lib_ext_socket_connect" = x"yes" ||
+ test x"$ac_cv_lib_ext_inet_connect" = x"yes"
+ then
+ AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()])
+ fi
+fi
+
+AC_CHECK_FUNCS(gethostbyname)
+if test x"$ac_cv_func_gethostbyname" = x"no"; then
+ AC_CHECK_LIB_EXT(nsl_s, NSL_LIBS, gethostbyname)
+ AC_CHECK_LIB_EXT(nsl, NSL_LIBS, gethostbyname)
+ AC_CHECK_LIB_EXT(socket, NSL_LIBS, gethostbyname)
+ dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here,
+ dnl because the value has been cached.
+ if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" ||
+ test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" ||
+ test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes"
+ then
+ AC_DEFINE(HAVE_GETHOSTBYNAME,1,
+ [Whether the system has gethostbyname()])
+ fi
+fi
+
diff --git a/source3/lib/replace/system/config.m4 b/source3/lib/replace/system/config.m4
index 1c05733126..66c2bd652a 100644
--- a/source3/lib/replace/system/config.m4
+++ b/source3/lib/replace/system/config.m4
@@ -18,7 +18,7 @@ AC_CHECK_HEADERS(sys/capability.h)
case "$host_os" in
*linux*)
-AC_CACHE_CHECK([for broken RedHat 7.2 system header files],samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS,[
+AC_CACHE_CHECK([for broken RedHat 7.2 system header files],libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS,[
AC_TRY_COMPILE([
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
@@ -29,14 +29,14 @@ AC_TRY_COMPILE([
],[
int i;
],
- samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=no,
- samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=yes
+ libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=no,
+ libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=yes
)])
-if test x"$samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" = x"yes"; then
+if test x"$libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" = x"yes"; then
AC_DEFINE(BROKEN_REDHAT_7_SYSTEM_HEADERS,1,[Broken RedHat 7.2 system header files])
fi
-AC_CACHE_CHECK([for broken RHEL5 sys/capability.h],samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER,[
+AC_CACHE_CHECK([for broken RHEL5 sys/capability.h],libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER,[
AC_TRY_COMPILE([
#ifdef HAVE_SYS_CAPABILITY_H
#include <sys/capability.h>
@@ -45,10 +45,10 @@ AC_TRY_COMPILE([
],[
__s8 i;
],
- samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER=no,
- samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER=yes
+ libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=no,
+ libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=yes
)])
-if test x"$samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER" = x"yes"; then
+if test x"$libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER" = x"yes"; then
AC_DEFINE(BROKEN_RHEL5_SYS_CAP_HEADER,1,[Broken RHEL5 sys/capability.h])
fi
;;
diff --git a/source3/lib/replace/system/network.h b/source3/lib/replace/system/network.h
index aff8a841da..796df2d1da 100644
--- a/source3/lib/replace/system/network.h
+++ b/source3/lib/replace/system/network.h
@@ -6,6 +6,7 @@
networking system include wrappers
Copyright (C) Andrew Tridgell 2004
+ Copyright (C) Jelmer Vernooij 2007
** NOTE! The following LGPL license applies to the replace
** library. This does NOT imply that all of Samba is released
@@ -82,6 +83,11 @@
#include <stropts.h>
#endif
+#ifndef HAVE_SOCKLEN_T
+#define HAVE_SOCKLEN_T
+typedef int socklen_t;
+#endif
+
#ifdef REPLACE_INET_NTOA
/* define is in "replace.h" */
char *rep_inet_ntoa(struct in_addr ip);
@@ -97,6 +103,41 @@ int rep_inet_pton(int af, const char *src, void *dst);
const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size);
#endif
+#ifndef HAVE_CONNECT
+/* define is in "replace.h" */
+int rep_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+#endif
+
+#ifndef HAVE_GETHOSTBYNAME
+/* define is in "replace.h" */
+struct hostent *rep_gethostbyname(const char *name);
+#endif
+
+#ifdef HAVE_IFADDRS_H
+#include <ifaddrs.h>
+#endif
+
+#ifndef HAVE_STRUCT_IFADDRS
+struct ifaddrs {
+ struct ifaddrs *ifa_next; /* Pointer to next struct */
+ char *ifa_name; /* Interface name */
+ unsigned int ifa_flags; /* Interface flags */
+ struct sockaddr *ifa_addr; /* Interface address */
+ struct sockaddr *ifa_netmask; /* Interface netmask */
+#undef ifa_dstaddr
+ struct sockaddr *ifa_dstaddr; /* P2P interface destination */
+ void *ifa_data; /* Address specific data */
+};
+#endif
+
+#ifndef HAVE_GETIFADDRS
+int rep_getifaddrs(struct ifaddrs **);
+#endif
+
+#ifndef HAVE_FREEIFADDRS
+void rep_freeifaddrs(struct ifaddrs *);
+#endif
+
/*
* Some systems have getaddrinfo but not the
* defines needed to use it.
@@ -219,11 +260,6 @@ const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size);
#define HOST_NAME_MAX 256
#endif
-#ifndef HAVE_SOCKLEN_T
-#define HAVE_SOCKLEN_T
-typedef int socklen_t;
-#endif
-
#ifndef HAVE_SA_FAMILY_T
#define HAVE_SA_FAMILY_T
typedef unsigned short int sa_family_t;
@@ -269,7 +305,7 @@ struct addrinfo {
/* Needed for some systems that don't define it (Solaris). */
#ifndef ifr_netmask
-#define ifr_netmask ifr_addrs
+#define ifr_netmask ifr_addr
#endif
#ifdef SOCKET_WRAPPER
diff --git a/source3/lib/replace/test/getifaddrs.c b/source3/lib/replace/test/getifaddrs.c
new file mode 100644
index 0000000000..8b00ac2f40
--- /dev/null
+++ b/source3/lib/replace/test/getifaddrs.c
@@ -0,0 +1,100 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * libreplace getifaddrs test
+ *
+ * Copyright (C) Michael Adam <obnox@samba.org> 2008
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef AUTOCONF_TEST
+#include "replace.h"
+#include "system/network.h"
+#endif
+
+#ifdef HAVE_INET_NTOP
+#define rep_inet_ntop inet_ntop
+#endif
+
+static const char *format_sockaddr(struct sockaddr *addr,
+ char *addrstring,
+ socklen_t addrlen)
+{
+ const char *result = NULL;
+
+ if (addr->sa_family == AF_INET) {
+ result = rep_inet_ntop(AF_INET,
+ &((struct sockaddr_in *)addr)->sin_addr,
+ addrstring,
+ addrlen);
+#ifdef HAVE_STRUCT_SOCKADDR_IN6
+ } else if (addr->sa_family == AF_INET6) {
+ result = rep_inet_ntop(AF_INET6,
+ &((struct sockaddr_in6 *)addr)->sin6_addr,
+ addrstring,
+ addrlen);
+#endif
+ }
+ return result;
+}
+
+int getifaddrs_test(void)
+{
+ struct ifaddrs *ifs = NULL;
+ struct ifaddrs *ifs_head = NULL;
+ int ret;
+
+ ret = getifaddrs(&ifs);
+ ifs_head = ifs;
+ if (ret != 0) {
+ fprintf(stderr, "getifaddrs() failed: %s\n", strerror(errno));
+ return 1;
+ }
+
+ while (ifs) {
+ printf("%-10s ", ifs->ifa_name);
+ if (ifs->ifa_addr != NULL) {
+ char addrstring[INET6_ADDRSTRLEN];
+ const char *result;
+
+ result = format_sockaddr(ifs->ifa_addr,
+ addrstring,
+ sizeof(addrstring));
+ if (result != NULL) {
+ printf("IP=%s ", addrstring);
+ }
+
+ if (ifs->ifa_netmask != NULL) {
+ result = format_sockaddr(ifs->ifa_netmask,
+ addrstring,
+ sizeof(addrstring));
+ if (result != NULL) {
+ printf("NETMASK=%s", addrstring);
+ }
+ } else {
+ printf("AF=%d ", ifs->ifa_addr->sa_family);
+ }
+ } else {
+ printf("<no address>");
+ }
+
+ printf("\n");
+ ifs = ifs->ifa_next;
+ }
+
+ freeifaddrs(ifs_head);
+
+ return 0;
+}
diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c
index 5b95ae395c..b538360365 100644
--- a/source3/lib/replace/test/testsuite.c
+++ b/source3/lib/replace/test/testsuite.c
@@ -856,6 +856,22 @@ static int test_strptime(void)
return libreplace_test_strptime();
}
+extern int getifaddrs_test(void);
+
+static int test_getifaddrs(void)
+{
+
+ printf("test: getifaddrs\n");
+
+ if (getifaddrs_test() != 0) {
+ printf("failure: getifaddrs\n");
+ return false;
+ }
+
+ printf("success: getifaddrs\n");
+ return true;
+}
+
struct torture_context;
bool torture_local_replace(struct torture_context *ctx)
{
@@ -903,6 +919,7 @@ bool torture_local_replace(struct torture_context *ctx)
ret &= test_MAX();
ret &= test_socketpair();
ret &= test_strptime();
+ ret &= test_getifaddrs();
return ret;
}
diff --git a/source3/lib/select.c b/source3/lib/select.c
index d5e4ba68f2..c3da6a9bba 100644
--- a/source3/lib/select.c
+++ b/source3/lib/select.c
@@ -58,7 +58,8 @@ int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, s
fd_set *readfds2, readfds_buf;
if (initialised != sys_getpid()) {
- pipe(select_pipe);
+ if (pipe(select_pipe) == -1)
+ smb_panic("Could not create select pipe");
/*
* These next two lines seem to fix a bug with the Linux
diff --git a/source3/lib/sock_exec.c b/source3/lib/sock_exec.c
index 203d7e93b3..278a174663 100644
--- a/source3/lib/sock_exec.c
+++ b/source3/lib/sock_exec.c
@@ -105,8 +105,12 @@ int sock_exec(const char *prog)
close(fd[0]);
close(0);
close(1);
- dup(fd[1]);
- dup(fd[1]);
+ if (dup(fd[1]) == -1) {
+ exit(1);
+ }
+ if (dup(fd[1]) == -1) {
+ exit(1);
+ }
exit(system(prog));
}
close(fd[1]);
diff --git a/source3/lib/util_nttoken.c b/source3/lib/util_nttoken.c
index 13c66a5f45..f81191af58 100644
--- a/source3/lib/util_nttoken.c
+++ b/source3/lib/util_nttoken.c
@@ -7,6 +7,7 @@
* Copyright (C) Rafal Szczesniak 2002
* Copyright (C) Volker Lendecke 2006
* Copyright (C) Michael Adam 2007
+ * Copyright (C) Guenther Deschner 2007
*
* 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
@@ -67,3 +68,52 @@ NT_USER_TOKEN *dup_nt_token(TALLOC_CTX *mem_ctx, const NT_USER_TOKEN *ptoken)
return token;
}
+/****************************************************************************
+ merge NT tokens
+****************************************************************************/
+
+NTSTATUS merge_nt_token(TALLOC_CTX *mem_ctx,
+ const struct nt_user_token *token_1,
+ const struct nt_user_token *token_2,
+ struct nt_user_token **token_out)
+{
+ struct nt_user_token *token = NULL;
+ NTSTATUS status;
+ int i;
+
+ if (!token_1 || !token_2 || !token_out) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ token = TALLOC_ZERO_P(mem_ctx, struct nt_user_token);
+ NT_STATUS_HAVE_NO_MEMORY(token);
+
+ for (i=0; i < token_1->num_sids; i++) {
+ status = add_sid_to_array_unique(mem_ctx,
+ &token_1->user_sids[i],
+ &token->user_sids,
+ &token->num_sids);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(token);
+ return status;
+ }
+ }
+
+ for (i=0; i < token_2->num_sids; i++) {
+ status = add_sid_to_array_unique(mem_ctx,
+ &token_2->user_sids[i],
+ &token->user_sids,
+ &token->num_sids);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(token);
+ return status;
+ }
+ }
+
+ se_priv_add(&token->privileges, &token_1->privileges);
+ se_priv_add(&token->privileges, &token_2->privileges);
+
+ *token_out = token;
+
+ return NT_STATUS_OK;
+}
diff --git a/source3/lib/util_reg.c b/source3/lib/util_reg.c
index 2d7d70c63f..2475dca040 100644
--- a/source3/lib/util_reg.c
+++ b/source3/lib/util_reg.c
@@ -95,7 +95,7 @@ WERROR reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len,
thislen = strnlen_w(p, len) + 1;
dstlen = convert_string_allocate(*values, CH_UTF16LE, CH_UNIX,
p, thislen*2, (void *)&val,
- True);
+ true);
if (dstlen == (size_t)-1) {
TALLOC_FREE(*values);
return WERR_NOMEM;
@@ -137,8 +137,8 @@ bool registry_smbconf_valname_forbidden(const char *valname)
for (forbidden = forbidden_valnames; *forbidden != NULL; forbidden++) {
if (strwicmp(valname, *forbidden) == 0) {
- return True;
+ return true;
}
}
- return False;
+ return false;
}
diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c
index 37865238a5..fd2e93a697 100644
--- a/source3/lib/util_sid.c
+++ b/source3/lib/util_sid.c
@@ -665,7 +665,7 @@ bool is_null_sid(const DOM_SID *sid)
}
NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx,
- const NET_USER_INFO_3 *info3,
+ const struct netr_SamInfo3 *info3,
DOM_SID **user_sids,
size_t *num_user_sids,
bool include_user_group_rid)
@@ -678,45 +678,45 @@ NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx,
if (include_user_group_rid) {
- if (!sid_compose(&sid, &(info3->dom_sid.sid), info3->user_rid))
+ if (!sid_compose(&sid, info3->base.domain_sid, info3->base.rid))
{
DEBUG(3, ("could not compose user SID from rid 0x%x\n",
- info3->user_rid));
+ info3->base.rid));
return NT_STATUS_INVALID_PARAMETER;
}
status = add_sid_to_array(mem_ctx, &sid, &sid_array, &num_sids);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("could not append user SID from rid 0x%x\n",
- info3->user_rid));
+ info3->base.rid));
return status;
}
- if (!sid_compose(&sid, &(info3->dom_sid.sid), info3->group_rid))
+ if (!sid_compose(&sid, info3->base.domain_sid, info3->base.primary_gid))
{
DEBUG(3, ("could not compose group SID from rid 0x%x\n",
- info3->group_rid));
+ info3->base.primary_gid));
return NT_STATUS_INVALID_PARAMETER;
}
status = add_sid_to_array(mem_ctx, &sid, &sid_array, &num_sids);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("could not append group SID from rid 0x%x\n",
- info3->group_rid));
+ info3->base.rid));
return status;
}
}
- for (i = 0; i < info3->num_groups2; i++) {
- if (!sid_compose(&sid, &(info3->dom_sid.sid),
- info3->gids[i].g_rid))
+ for (i = 0; i < info3->base.groups.count; i++) {
+ if (!sid_compose(&sid, info3->base.domain_sid,
+ info3->base.groups.rids[i].rid))
{
DEBUG(3, ("could not compose SID from additional group "
- "rid 0x%x\n", info3->gids[i].g_rid));
+ "rid 0x%x\n", info3->base.groups.rids[i].rid));
return NT_STATUS_INVALID_PARAMETER;
}
status = add_sid_to_array(mem_ctx, &sid, &sid_array, &num_sids);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("could not append SID from additional group "
- "rid 0x%x\n", info3->gids[i].g_rid));
+ "rid 0x%x\n", info3->base.groups.rids[i].rid));
return status;
}
}
@@ -727,12 +727,12 @@ NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx,
http://www.microsoft.com/windows2000/techinfo/administration/security/sidfilter.asp
*/
- for (i = 0; i < info3->num_other_sids; i++) {
- status = add_sid_to_array(mem_ctx, &info3->other_sids[i].sid,
+ for (i = 0; i < info3->sidcount; i++) {
+ status = add_sid_to_array(mem_ctx, info3->sids[i].sid,
&sid_array, &num_sids);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("could not add SID to array: %s\n",
- sid_string_dbg(&info3->other_sids[i].sid)));
+ sid_string_dbg(info3->sids[i].sid)));
return status;
}
}
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 71d48d6053..2a65943872 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -370,7 +370,7 @@ void in_addr_to_sockaddr_storage(struct sockaddr_storage *ss,
Convert an IPv6 struct in_addr to a struct sockaddr_storage.
********************************************************************/
-void in6_addr_to_sockaddr_storage(struct sockaddr_storage *ss,
+ void in6_addr_to_sockaddr_storage(struct sockaddr_storage *ss,
struct in6_addr ip)
{
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)ss;
@@ -1904,8 +1904,7 @@ int create_pipe_sock(const char *socket_dir,
goto out_close;
}
- asprintf(&path, "%s/%s", socket_dir, socket_name);
- if (!path) {
+ if (asprintf(&path, "%s/%s", socket_dir, socket_name) == -1) {
goto out_close;
}
@@ -1933,7 +1932,8 @@ int create_pipe_sock(const char *socket_dir,
out_close:
SAFE_FREE(path);
- close(sock);
+ if (sock != -1)
+ close(sock);
out_umask:
umask(old_umask);
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index f631dfffee..cb8a100fa7 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -2086,6 +2086,7 @@ static char *ipstr_list_add(char **ipstr_list, const struct ip_service *service)
{
char *new_ipstr = NULL;
char addr_buf[INET6_ADDRSTRLEN];
+ int ret;
/* arguments checking */
if (!ipstr_list || !service) {
@@ -2100,33 +2101,30 @@ static char *ipstr_list_add(char **ipstr_list, const struct ip_service *service)
if (*ipstr_list) {
if (service->ss.ss_family == AF_INET) {
/* IPv4 */
- asprintf(&new_ipstr, "%s%s%s:%d",
- *ipstr_list,
- IPSTR_LIST_SEP,
- addr_buf,
- service->port);
+ ret = asprintf(&new_ipstr, "%s%s%s:%d", *ipstr_list,
+ IPSTR_LIST_SEP, addr_buf,
+ service->port);
} else {
/* IPv6 */
- asprintf(&new_ipstr, "%s%s[%s]:%d",
- *ipstr_list,
- IPSTR_LIST_SEP,
- addr_buf,
- service->port);
+ ret = asprintf(&new_ipstr, "%s%s[%s]:%d", *ipstr_list,
+ IPSTR_LIST_SEP, addr_buf,
+ service->port);
}
SAFE_FREE(*ipstr_list);
} else {
if (service->ss.ss_family == AF_INET) {
/* IPv4 */
- asprintf(&new_ipstr, "%s:%d",
- addr_buf,
- service->port);
+ ret = asprintf(&new_ipstr, "%s:%d", addr_buf,
+ service->port);
} else {
/* IPv6 */
- asprintf(&new_ipstr, "[%s]:%d",
- addr_buf,
- service->port);
+ ret = asprintf(&new_ipstr, "[%s]:%d", addr_buf,
+ service->port);
}
}
+ if (ret == -1) {
+ return NULL;
+ }
*ipstr_list = new_ipstr;
return *ipstr_list;
}
diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c
index dd5ebcd7ab..724832ea5b 100644
--- a/source3/lib/util_tdb.c
+++ b/source3/lib/util_tdb.c
@@ -669,12 +669,13 @@ static void tdb_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, const char *fo
{
va_list ap;
char *ptr = NULL;
+ int ret;
va_start(ap, format);
- vasprintf(&ptr, format, ap);
+ ret = vasprintf(&ptr, format, ap);
va_end(ap);
- if (!ptr || !*ptr)
+ if ((ret == -1) || !*ptr)
return;
DEBUG((int)level, ("tdb(%s): %s", tdb_name(tdb) ? tdb_name(tdb) : "unnamed", ptr));
@@ -867,11 +868,8 @@ static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
va_list ap;
char *ptr = NULL;
int debuglevel = 0;
+ int ret;
- va_start(ap, format);
- vasprintf(&ptr, format, ap);
- va_end(ap);
-
switch (level) {
case TDB_DEBUG_FATAL:
debug_level = 0;
@@ -889,7 +887,11 @@ static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
debuglevel = 0;
}
- if (ptr != NULL) {
+ va_start(ap, format);
+ ret = vasprintf(&ptr, format, ap);
+ va_end(ap);
+
+ if (ret != -1) {
const char *name = tdb_name(tdb);
DEBUG(debuglevel, ("tdb(%s): %s", name ? name : "unnamed", ptr));
free(ptr);