diff options
author | Andrew Tridgell <tridge@samba.org> | 1998-07-29 03:08:05 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1998-07-29 03:08:05 +0000 |
commit | 64578c0589a3a741f81fb55c16eeb882128da00b (patch) | |
tree | 8b650156e44e4d39af8625185d857a88789b8074 /source3/lib | |
parent | c48b3fce6be6d5d952cbcda0ddae223dda5a576f (diff) | |
download | samba-64578c0589a3a741f81fb55c16eeb882128da00b.tar.gz samba-64578c0589a3a741f81fb55c16eeb882128da00b.tar.bz2 samba-64578c0589a3a741f81fb55c16eeb882128da00b.zip |
merge from the autoconf2 branch to the main branch
(This used to be commit 3bda7ac417107a7b01d91805ca71c4330657ed21)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/access.c | 2 | ||||
-rw-r--r-- | source3/lib/fault.c | 8 | ||||
-rw-r--r-- | source3/lib/getsmbpass.c | 25 | ||||
-rw-r--r-- | source3/lib/interface.c | 227 | ||||
-rw-r--r-- | source3/lib/netmask.c | 351 | ||||
-rw-r--r-- | source3/lib/replace.c | 236 | ||||
-rw-r--r-- | source3/lib/signal.c | 102 | ||||
-rw-r--r-- | source3/lib/slprintf.c | 4 | ||||
-rw-r--r-- | source3/lib/system.c | 34 | ||||
-rw-r--r-- | source3/lib/time.c | 47 | ||||
-rw-r--r-- | source3/lib/ufc.c | 5 | ||||
-rw-r--r-- | source3/lib/username.c | 7 | ||||
-rw-r--r-- | source3/lib/util.c | 273 |
13 files changed, 757 insertions, 564 deletions
diff --git a/source3/lib/access.c b/source3/lib/access.c index fe78700edd..d5e81eb50f 100644 --- a/source3/lib/access.c +++ b/source3/lib/access.c @@ -203,7 +203,7 @@ static int string_match(char *tok,char *s) && strcasecmp(tok, s + str_len - tok_len) == 0) return (YES); } else if (tok[0] == '@') { /* netgroup: look it up */ -#ifdef NETGROUP +#ifdef HAVE_NETGROUP static char *mydomain = NULL; char *hostname = NULL; BOOL netgroup_ok = False; diff --git a/source3/lib/fault.c b/source3/lib/fault.c index f46ccbb185..e1b3c6cd9f 100644 --- a/source3/lib/fault.c +++ b/source3/lib/fault.c @@ -45,10 +45,10 @@ static void fault_report(int sig) fault_setup(cont_fn); cont_fn(NULL); #ifdef SIGSEGV - signal(SIGSEGV,SIGNAL_CAST SIG_DFL); + CatchSignal(SIGSEGV,SIGNAL_CAST SIG_DFL); #endif #ifdef SIGBUS - signal(SIGBUS,SIGNAL_CAST SIG_DFL); + CatchSignal(SIGBUS,SIGNAL_CAST SIG_DFL); #endif return; /* this should cause a core dump */ } @@ -71,10 +71,10 @@ void fault_setup(void (*fn)(void *)) cont_fn = fn; #ifdef SIGSEGV - signal(SIGSEGV,SIGNAL_CAST sig_fault); + CatchSignal(SIGSEGV,SIGNAL_CAST sig_fault); #endif #ifdef SIGBUS - signal(SIGBUS,SIGNAL_CAST sig_fault); + CatchSignal(SIGBUS,SIGNAL_CAST sig_fault); #endif } diff --git a/source3/lib/getsmbpass.c b/source3/lib/getsmbpass.c index 68754f0848..7e544fa8d0 100644 --- a/source3/lib/getsmbpass.c +++ b/source3/lib/getsmbpass.c @@ -40,20 +40,19 @@ static struct termio t; #define TCSANOW 0 #endif - int tcgetattr(int fd, struct termio *t) +static int tcgetattr(int fd, struct termio *t) { return ioctl(fd, TCGETA, t); } - int tcsetattr(int fd, int flags, struct termio *t) +static int tcsetattr(int fd, int flags, struct termio *t) { if(flags & TCSAFLUSH) ioctl(fd, TCFLSH, TCIOFLUSH); return ioctl(fd, TCSETS, t); } -#else /* SYSV_TERMIO */ -#ifdef BSD_TERMIO +#elif !defined(TCSAFLUSH) /* BSD TERMIO HANDLING */ @@ -63,33 +62,25 @@ static struct sgttyb t; #define TURN_ECHO_OFF(t) ((t).sg_flags &= ~ECHO) #define TURN_ECHO_ON(t) ((t).sg_flags |= ECHO) -#ifndef TCSAFLUSH #define TCSAFLUSH 1 -#endif - -#ifndef TCSANOW #define TCSANOW 0 -#endif - int tcgetattr(int fd, struct sgttyb *t) +static int tcgetattr(int fd, struct sgttyb *t) { return ioctl(fd, TIOCGETP, (char *)t); } - int tcsetattr(int fd, int flags, struct sgttyb *t) +static int tcsetattr(int fd, int flags, struct sgttyb *t) { return ioctl(fd, TIOCSETP, (char *)t); } -#else /* BSD_TERMIO */ - -/* POSIX TERMIO HANDLING */ +#else /* POSIX TERMIO HANDLING */ #define ECHO_IS_ON(t) ((t).c_lflag & ECHO) #define TURN_ECHO_OFF(t) ((t).c_lflag &= ~ECHO) #define TURN_ECHO_ON(t) ((t).c_lflag |= ECHO) static struct termios t; -#endif /* BSD_TERMIO */ #endif /* SYSV_TERMIO */ char *getsmbpass(char *prompt) @@ -101,7 +92,7 @@ char *getsmbpass(char *prompt) size_t nread; /* Catch problematic signals */ - signal(SIGINT, SIGNAL_CAST SIG_IGN); + CatchSignal(SIGINT, SIGNAL_CAST SIG_IGN); /* Try to write to and read from the terminal if we can. If we can't open the terminal, use stderr and stdin. */ @@ -153,7 +144,7 @@ char *getsmbpass(char *prompt) fclose (in); /* Catch problematic signals */ - signal(SIGINT, SIGNAL_CAST SIG_DFL); + CatchSignal(SIGINT, SIGNAL_CAST SIG_DFL); printf("\n"); return buf; diff --git a/source3/lib/interface.c b/source3/lib/interface.c index 8c1610e9cb..7aae803abf 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -78,200 +78,45 @@ static void get_broadcast(struct in_addr *if_ipaddr, struct in_addr *if_bcast, struct in_addr *if_nmask) { - BOOL found = False; -#ifndef NO_GET_BROADCAST - int sock = -1; /* AF_INET raw socket desc */ - char buff[1024]; - struct ifreq *ifr=NULL; - int i; - -#if defined(EVEREST) - int n_interfaces; - struct ifconf ifc; - struct ifreq *ifreqs; -#elif defined(USE_IFREQ) - struct ifreq ifreq; - struct strioctl strioctl; - struct ifconf *ifc; -#else - struct ifconf ifc; -#endif -#endif - - /* get a default netmask and broadcast */ - default_netmask(if_nmask, if_ipaddr); - -#ifndef NO_GET_BROADCAST - /* Create a socket to the INET kernel. */ -#if USE_SOCKRAW - if ((sock = socket(AF_INET, SOCK_RAW, PF_INET )) < 0) -#else - if ((sock = socket(AF_INET, SOCK_DGRAM, 0 )) < 0) -#endif - { - DEBUG(0,( "Unable to open socket to get broadcast address\n")); - return; - } - - /* Get a list of the configured interfaces */ -#ifdef EVEREST - /* This is part of SCO Openserver 5: The ioctls are no longer part - if the lower level STREAMS interface glue. They are now real - ioctl calls */ - - if (ioctl(sock, SIOCGIFANUM, &n_interfaces) < 0) { - DEBUG(0,( "SIOCGIFANUM: %s\n", strerror(errno))); - } else { - DEBUG(0,( "number of interfaces returned is: %d\n", n_interfaces)); - - ifc.ifc_len = sizeof(struct ifreq) * n_interfaces; - ifc.ifc_buf = (caddr_t) alloca(ifc.ifc_len); - - if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) - DEBUG(0, ( "SIOCGIFCONF: %s\n", strerror(errno))); - else { - ifr = ifc.ifc_req; - - for (i = 0; i < n_interfaces; ++i) { - if (if_ipaddr->s_addr == - ((struct sockaddr_in *) &ifr[i].ifr_addr)->sin_addr.s_addr) { - found = True; - break; + uint32 nm; + short onbc; + short offbc; + + /* get a default netmask and broadcast */ + default_netmask(if_nmask, if_ipaddr); + + get_netmask(if_ipaddr, if_nmask); + + /* sanity check on the netmask */ + nm = ntohl(if_nmask->s_addr); + onbc = 0; + offbc = 0; + while((onbc + offbc) < 32) { + if(nm & 0x80000000) { + onbc++; + if(offbc) { + /* already found an off bit, so mask + is wrong */ + onbc = 34; + } + } else { + offbc++; + } + nm <<= 1; + } + if ((onbc < 8)||(onbc == 34)) { + DEBUG(0,("Impossible netmask %s - using defaults\n", + inet_ntoa(*if_nmask))); + default_netmask(if_nmask, if_ipaddr); } - } - } - } -#elif defined(USE_IFREQ) - ifc = (struct ifconf *)buff; - ifc->ifc_len = BUFSIZ - sizeof(struct ifconf); - strioctl.ic_cmd = SIOCGIFCONF; - strioctl.ic_dp = (char *)ifc; - strioctl.ic_len = sizeof(buff); - if (ioctl(sock, I_STR, &strioctl) < 0) { - DEBUG(0,( "I_STR/SIOCGIFCONF: %s\n", strerror(errno))); - } else { - ifr = (struct ifreq *)ifc->ifc_req; - - /* Loop through interfaces, looking for given IP address */ - for (i = ifc->ifc_len / sizeof(struct ifreq); --i >= 0; ifr++) { - if (if_ipaddr->s_addr == - (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) { - found = True; - break; - } - } - } -#elif defined(__FreeBSD__) || defined(NETBSD) || defined(AMIGA) || defined(_AIX41) || defined(__OpenBSD__) - ifc.ifc_len = sizeof(buff); - ifc.ifc_buf = buff; - if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) { - DEBUG(0,("SIOCGIFCONF: %s\n", strerror(errno))); - } else { - ifr = ifc.ifc_req; - /* Loop through interfaces, looking for given IP address */ - i = ifc.ifc_len; - while (i > 0) { - if (if_ipaddr->s_addr == - (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) { - found = True; - break; - } - i -= ifr->ifr_addr.sa_len + IFNAMSIZ; - ifr = (struct ifreq*) ((char*) ifr + ifr->ifr_addr.sa_len + IFNAMSIZ); - } - } -#else - ifc.ifc_len = sizeof(buff); - ifc.ifc_buf = buff; - if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) { - DEBUG(0,("SIOCGIFCONF: %s\n", strerror(errno))); - } else { - ifr = ifc.ifc_req; - - /* Loop through interfaces, looking for given IP address */ - for (i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++) { -#ifdef BSDI - if (ioctl(sock, SIOCGIFADDR, ifr) < 0) break; -#endif - if (if_ipaddr->s_addr == - (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) { - found = True; - break; - } - } - } -#endif - - if (!found) { - DEBUG(0,("No interface found for address %s\n", inet_ntoa(*if_ipaddr))); - } else { - /* Get the netmask address from the kernel */ -#ifdef USE_IFREQ - ifreq = *ifr; - - strioctl.ic_cmd = SIOCGIFNETMASK; - strioctl.ic_dp = (char *)&ifreq; - strioctl.ic_len = sizeof(struct ifreq); - if (ioctl(sock, I_STR, &strioctl) < 0) - DEBUG(0,("Failed I_STR/SIOCGIFNETMASK: %s\n", strerror(errno))); - else - *if_nmask = ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr; -#else - if (ioctl(sock, SIOCGIFNETMASK, ifr) < 0) - DEBUG(0,("SIOCGIFNETMASK failed\n")); - else - *if_nmask = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr; -#endif - - DEBUG(4,("Netmask for %s = %s\n", ifr->ifr_name, - inet_ntoa(*if_nmask))); - } - - /* Close up shop */ - (void) close(sock); - -#endif - - /* sanity check on the netmask */ - { - uint32 nm; - short onbc; - short offbc; - - nm = ntohl(if_nmask->s_addr); - onbc = 0; - offbc = 0; - while( (onbc + offbc) < 32 ) - { - if( nm & 0x80000000 ) - { - onbc++; - if( offbc ) /* already found an off bit, so mask is wrong */ - { - onbc = 34; - } - } - else - { - offbc++; - } - nm <<= 1; - } - if ((onbc < 8)||(onbc == 34)) { - DEBUG(0,("Impossible netmask %s - using defaults\n",inet_ntoa(*if_nmask))); - default_netmask(if_nmask, if_ipaddr); - } - } - /* derive the broadcast assuming a 1's broadcast, as this is what - all MS operating systems do, we have to comply even if the unix - box is setup differently */ - { - if_bcast->s_addr = MKBCADDR(if_ipaddr->s_addr, if_nmask->s_addr); - } + /* derive the broadcast assuming a 1's broadcast, as this is what + all MS operating systems do, we have to comply even if the unix + box is setup differently */ + if_bcast->s_addr = MKBCADDR(if_ipaddr->s_addr, if_nmask->s_addr); - DEBUG(4,("Derived broadcast address %s\n", inet_ntoa(*if_bcast))); -} /* get_broadcast */ + DEBUG(4,("Derived broadcast address %s\n", inet_ntoa(*if_bcast))); +} diff --git a/source3/lib/netmask.c b/source3/lib/netmask.c new file mode 100644 index 0000000000..138a4413f1 --- /dev/null +++ b/source3/lib/netmask.c @@ -0,0 +1,351 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + code to query kernel netmask + Copyright (C) Andrew Tridgell 1998 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +/* working out the netmask for an interface is an incredibly non-portable + thing. We have several possible implementations below, and autoconf + tries each of them to see what works + + Note that this file does _not_ include includes.h. That is so this code + can be called directly from the autoconf tests. That also means + this code cannot use any of the normal Samba debug stuff or defines. + This is standalone code. + +*/ + +#ifndef AUTOCONF +#include "config.h" +#endif + +#ifdef HAVE_NETMASK_IFCONF + +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <sys/ioctl.h> +#include <net/if.h> + +#ifndef SIOCGIFCONF +#include <sys/sockio.h> +#endif + + +/**************************************************************************** + get the netmask address for a local interface +****************************************************************************/ +int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask) +{ + struct ifconf ifc; + char buff[2048]; + int fd, i, n; + struct ifreq *ifr=NULL; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { +#ifdef DEBUG + fprintf(stderr,"socket failed\n"); +#endif + return -1; + } + + ifc.ifc_len = sizeof(buff); + ifc.ifc_buf = buff; + if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { +#ifdef DEBUG + fprintf(stderr,"SIOCGIFCONF failed\n"); +#endif + close(fd); + return -1; + } + + ifr = ifc.ifc_req; + + n = ifc.ifc_len / sizeof(struct ifreq); + +#ifdef DEBUG + fprintf(stderr,"%d interfaces - looking for %s\n", + n, inet_ntoa(*ipaddr)); +#endif + + /* Loop through interfaces, looking for given IP address */ + for (i=n-1;i>=0;i--) { + if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) { +#ifdef DEBUG + fprintf(stderr,"SIOCGIFADDR failed\n"); +#endif + continue; + } + +#ifdef DEBUG + fprintf(stderr,"interface %s\n", + inet_ntoa((*(struct sockaddr_in *)&ifr[i].ifr_addr).sin_addr)); +#endif + if (ipaddr->s_addr != + (*(struct sockaddr_in *)&ifr[i].ifr_addr).sin_addr.s_addr) { + continue; + } + + if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) { +#ifdef DEBUG + fprintf(stderr,"SIOCGIFNETMASK failed\n"); +#endif + close(fd); + return -1; + } + close(fd); + (*nmask) = ((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr; +#ifdef DEBUG + fprintf(stderr,"netmask %s\n", inet_ntoa(*nmask)); +#endif + return 0; + } + +#ifdef DEBUG + fprintf(stderr,"interface not found\n"); +#endif + + close(fd); + return -1; +} + +#elif defined(HAVE_NETMASK_IFREQ) + +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <sys/ioctl.h> +#include <net/if.h> + +#ifndef SIOCGIFCONF +#include <sys/sockio.h> +#endif + +#ifndef I_STR +#include <sys/stropts.h> +#endif + + +/**************************************************************************** +this should cover most of the rest of systems +****************************************************************************/ + int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask) +{ + struct ifreq ifreq; + struct strioctl strioctl; + struct ifconf *ifc; + char buff[2048]; + int fd, i, n; + struct ifreq *ifr=NULL; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { +#ifdef DEBUG + fprintf(stderr,"socket failed\n"); +#endif + return -1; + } + + ifc = (struct ifconf *)buff; + ifc->ifc_len = BUFSIZ - sizeof(struct ifconf); + strioctl.ic_cmd = SIOCGIFCONF; + strioctl.ic_dp = (char *)ifc; + strioctl.ic_len = sizeof(buff); + if (ioctl(fd, I_STR, &strioctl) < 0) { +#ifdef DEBUG + fprintf(stderr,"SIOCGIFCONF failed\n"); +#endif + close(fd); + return -1; + } + + ifr = (struct ifreq *)ifc->ifc_req; + + /* Loop through interfaces, looking for given IP address */ + n = ifc->ifc_len / sizeof(struct ifreq); + + for (i = 0; i<n; i++, ifr++) { +#ifdef DEBUG + fprintf(stderr,"interface %s\n", + inet_ntoa((*(struct sockaddr_in *)&ifr->ifr_addr).sin_addr.s_addr)); +#endif + if (ipaddr->s_addr == + (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) { + break; + } + } + +#ifdef DEBUG + if (i == n) { + fprintf(stderr,"interface not found\n"); + close(fd); + return -1; + } +#endif + + ifreq = *ifr; + + strioctl.ic_cmd = SIOCGIFNETMASK; + strioctl.ic_dp = (char *)&ifreq; + strioctl.ic_len = sizeof(struct ifreq); + if (ioctl(fd, I_STR, &strioctl) != 0) { +#ifdef DEBUG + fprintf(stderr,"Failed SIOCGIFNETMASK\n"); +#endif + close(fd); + return -1; + } + + close(fd); + *nmask = ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr; +#ifdef DEBUG + fprintf(stderr,"netmask %s\n", inet_ntoa(*nmask)); +#endif + return 0; +} + +#elif defined(HAVE_NETMASK_AIX) + +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <sys/ioctl.h> +#include <net/if.h> + +#ifndef SIOCGIFCONF +#include <sys/sockio.h> +#endif + +/**************************************************************************** +this one is for AIX +****************************************************************************/ + int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask) +{ + char buff[2048]; + int fd, i, n; + struct ifconf ifc; + struct ifreq *ifr=NULL; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { +#ifdef DEBUG + fprintf(stderr,"socket failed\n"); +#endif + return -1; + } + + + ifc.ifc_len = sizeof(buff); + ifc.ifc_buf = buff; + + if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { +#ifdef DEBUG + fprintf(stderr,"SIOCGIFCONF failed\n"); +#endif + close(fd); + return -1; + } + + ifr = ifc.ifc_req; + /* Loop through interfaces, looking for given IP address */ + i = ifc.ifc_len; + while (i > 0) { +#ifdef DEBUG + fprintf(stderr,"interface %s\n", + inet_ntoa((*(struct sockaddr_in *)&ifr->ifr_addr).sin_addr)); +#endif + if (ipaddr->s_addr == + (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) { + break; + } + i -= ifr->ifr_addr.sa_len + IFNAMSIZ; + ifr = (struct ifreq*) ((char*) ifr + ifr->ifr_addr.sa_len + + IFNAMSIZ); + } + + +#ifdef DEBUG + if (i <= 0) { + fprintf(stderr,"interface not found\n"); + close(fd); + return -1; + } +#endif + + if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { +#ifdef DEBUG + fprintf(stderr,"SIOCGIFNETMASK failed\n"); +#endif + close(fd); + return -1; + } + + close(fd); + + (*nmask) = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr; +#ifdef DEBUG + fprintf(stderr,"netmask %s\n", inet_ntoa(*nmask)); +#endif + return 0; +} + +#else /* a dummy version */ + int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask) +{ + return -1; +} +#endif + + +#ifdef AUTOCONF +/* this is the autoconf driver to test get_netmask() */ + + main() +{ + char buf[1024]; + struct hostent *hp; + struct in_addr ip, nmask; + + if (gethostname(buf, sizeof(buf)-1) != 0) { + fprintf(stderr,"gethostname failed\n"); + exit(1); + } + + hp = gethostbyname(buf); + + if (!hp) { + fprintf(stderr,"gethostbyname failed\n"); + exit(1); + } + + memcpy((char *)&ip, (char *)hp->h_addr, hp->h_length); + + if (get_netmask(&ip, &nmask) == 0) exit(0); + + fprintf(stderr,"get_netmask failed\n"); + exit(1); +} +#endif diff --git a/source3/lib/replace.c b/source3/lib/replace.c index a08d3d240e..50eac37c83 100644 --- a/source3/lib/replace.c +++ b/source3/lib/replace.c @@ -27,20 +27,8 @@ extern int DEBUGLEVEL; void replace_dummy(void) {} -#ifdef REPLACE_STRLEN -/**************************************************************************** -a replacement strlen() that returns int for solaris -****************************************************************************/ - int Strlen(char *s) -{ - int ret=0; - if (!s) return(0); - while (*s++) ret++; - return(ret); -} -#endif -#ifdef NO_FTRUNCATE +#ifndef HAVE_FTRUNCATE /******************************************************************* ftruncate for operating systems that don't have it ********************************************************************/ @@ -57,27 +45,7 @@ ftruncate for operating systems that don't have it #endif -#ifdef REPLACE_STRSTR -/**************************************************************************** -Mips version of strstr doesn't seem to work correctly. -There is a #define in includes.h to redirect calls to this function. -****************************************************************************/ -char *Strstr(char *s, char *p) -{ - int len = strlen(p); - - while ( *s != '\0' ) { - if ( strncmp(s, p, len) == 0 ) - return s; - s++; - } - - return NULL; -} -#endif /* REPLACE_STRSTR */ - - -#ifdef REPLACE_MKTIME +#ifndef HAVE_MKTIME /******************************************************************* a mktime() replacement for those who don't have it - contributed by C.A. Lademann <cal@zls.com> @@ -86,7 +54,7 @@ C.A. Lademann <cal@zls.com> #define HOUR 60*MINUTE #define DAY 24*HOUR #define YEAR 365*DAY -time_t Mktime(struct tm *t) + time_t mktime(struct tm *t) { struct tm *u; time_t epoch = 0; @@ -126,22 +94,17 @@ time_t Mktime(struct tm *t) t->tm_wday = u->tm_wday; t->tm_yday = u->tm_yday; t->tm_isdst = u->tm_isdst; -#ifndef NO_TM_NAME - memcpy(t->tm_name, u->tm_name, LTZNMAX); -#endif } return(epoch); } -#endif /* REPLACE_MKTIME */ +#endif /* !HAVE_MKTIME */ -#ifdef REPLACE_RENAME +#ifndef HAVE_RENAME /* Rename a file. (from libiberty in GNU binutils) */ - int rename (zfrom, zto) - const char *zfrom; - const char *zto; + int rename(const char *zfrom, const char *zto) { if (link (zfrom, zto) < 0) { @@ -156,73 +119,70 @@ time_t Mktime(struct tm *t) #endif -#ifdef REPLACE_INNETGR +#ifndef HAVE_INNETGR /* * Search for a match in a netgroup. This replaces it on broken systems. */ -int InNetGr(char *group,char *host,char *user,char *dom) + int innetgr(char *group,char *host,char *user,char *dom) { - char *hst, *usr, *dm; + char *hst, *usr, *dm; - setnetgrent(group); - while (getnetgrent(&hst, &usr, &dm)) - if (((host == 0) || (hst == 0) || !strcmp(host, hst)) && - ((user == 0) || (usr == 0) || !strcmp(user, usr)) && - ((dom == 0) || (dm == 0) || !strcmp(dom, dm))) { - endnetgrent(); - return (1); - } - endnetgrent(); - return (0); + setnetgrent(group); + while (getnetgrent(&hst, &usr, &dm)) { + if (((host == 0) || (hst == 0) || !strcmp(host, hst)) && + ((user == 0) || (usr == 0) || !strcmp(user, usr)) && + ((dom == 0) || (dm == 0) || !strcmp(dom, dm))) { + endnetgrent(); + return (1); + } + } + endnetgrent(); + return (0); } #endif -#ifdef NO_INITGROUPS -#include <sys/types.h> -#include <limits.h> -#include <grp.h> - -#ifndef NULL -#define NULL (void *)0 -#endif - +#ifndef HAVE_INITGROUPS /**************************************************************************** some systems don't have an initgroups call ****************************************************************************/ int initgroups(char *name,gid_t id) { -#ifdef NO_SETGROUPS - /* yikes! no SETGROUPS or INITGROUPS? how can this work? */ - return(0); +#ifndef HAVE_SETGROUPS + static int done; + if (!done) { + DEBUG(1,("WARNING: running without setgroups\n")); + done=1; + } + /* yikes! no SETGROUPS or INITGROUPS? how can this work? */ + return(0); #else - gid_t grouplst[NGROUPS_MAX]; - int i,j; - struct group *g; - char *gr; - - grouplst[0] = id; - i = 1; - while (i < NGROUPS_MAX && - ((g = (struct group *)getgrent()) != (struct group *)NULL)) - { - if (g->gr_gid == id) - continue; - j = 0; - gr = g->gr_mem[0]; - while (gr && (*gr != (char)NULL)) { - if (strcmp(name,gr) == 0) { - grouplst[i] = g->gr_gid; - i++; - gr = (char *)NULL; - break; + gid_t grouplst[NGROUPS_MAX]; + int i,j; + struct group *g; + char *gr; + + grouplst[0] = id; + i = 1; + while (i < NGROUPS_MAX && + ((g = (struct group *)getgrent()) != (struct group *)NULL)) { + if (g->gr_gid == id) + continue; + j = 0; + gr = g->gr_mem[0]; + while (gr && (*gr != (char)NULL)) { + if (strcmp(name,gr) == 0) { + grouplst[i] = g->gr_gid; + i++; + gr = (char *)NULL; + break; + } + gr = g->gr_mem[++j]; + } } - gr = g->gr_mem[++j]; - } - } - endgrent(); - return(setgroups(i,grouplst)); + endgrent(); + return(setgroups(i,grouplst)); #endif } #endif @@ -232,27 +192,89 @@ int InNetGr(char *group,char *host,char *user,char *dom) /* This is needed due to needing the nap() function but we don't want to include the Xenix libraries since that will break other things... BTW: system call # 0x0c28 is the same as calling nap() */ -long nap(long milliseconds) { - return syscall(0x0c28, milliseconds); -} + long nap(long milliseconds) { + return syscall(0x0c28, milliseconds); + } #endif -#if WRAP_MEMCPY -#undef memcpy +#ifndef HAVE_MEMMOVE /******************************************************************* -a wrapper around memcpy for diagnostic purposes +safely copies memory, ensuring no overlap problems. +this is only used if the machine does not have it's own memmove(). +this is not the fastest algorithm in town, but it will do for our +needs. ********************************************************************/ -void *memcpy_wrapped(void *d,void *s,int l,char *fname,int line) + void *memmove(void *dest,const void *src,int size) { - if (l>64 && (((int)d)%4) != (((int)s)%4)) - DEBUG(4,("Misaligned memcpy(0x%X,0x%X,%d) at %s(%d)\n",d,s,l,fname,line)); -#ifdef xx_old_memcpy - return(xx_old_memcpy(d,s,l)); -#else - return(memcpy(d,s,l)); + unsigned long d,s; + int i; + if (dest==src || !size) return(dest); + + d = (unsigned long)dest; + s = (unsigned long)src; + + if ((d >= (s+size)) || (s >= (d+size))) { + /* no overlap */ + memcpy(dest,src,size); + return(dest); + } + + if (d < s) { + /* we can forward copy */ + if (s-d >= sizeof(int) && + !(s%sizeof(int)) && + !(d%sizeof(int)) && + !(size%sizeof(int))) { + /* do it all as words */ + int *idest = (int *)dest; + int *isrc = (int *)src; + size /= sizeof(int); + for (i=0;i<size;i++) idest[i] = isrc[i]; + } else { + /* simplest */ + char *cdest = (char *)dest; + char *csrc = (char *)src; + for (i=0;i<size;i++) cdest[i] = csrc[i]; + } + } else { + /* must backward copy */ + if (d-s >= sizeof(int) && + !(s%sizeof(int)) && + !(d%sizeof(int)) && + !(size%sizeof(int))) { + /* do it all as words */ + int *idest = (int *)dest; + int *isrc = (int *)src; + size /= sizeof(int); + for (i=size-1;i>=0;i--) idest[i] = isrc[i]; + } else { + /* simplest */ + char *cdest = (char *)dest; + char *csrc = (char *)src; + for (i=size-1;i>=0;i--) cdest[i] = csrc[i]; + } + } + return(dest); +} #endif + +#ifndef HAVE_STRDUP +/**************************************************************************** +duplicate a string +****************************************************************************/ + char *strdup(const char *s) +{ + int len; + char *ret; + + if (!s) return(NULL); + + len = strlen(s)+1; + ret = (char *)malloc(len); + if (!ret) return(NULL); + memcpy(ret,s,len); + return(ret); } -#define memcpy(d,s,l) memcpy_wrapped(d,s,l,__FILE__,__LINE__) #endif diff --git a/source3/lib/signal.c b/source3/lib/signal.c new file mode 100644 index 0000000000..8f6f5a9cd4 --- /dev/null +++ b/source3/lib/signal.c @@ -0,0 +1,102 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + signal handling functions + + Copyright (C) Andrew Tridgell 1998 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +/**************************************************************************** +catch child exits +****************************************************************************/ +static void sig_cld(int signum) +{ + while (sys_waitpid((pid_t)-1,(int *)NULL, WNOHANG) > 0) ; + + CatchSignal(SIGCLD, SIG_IGN); +} + + + +/******************************************************************* +block sigs +********************************************************************/ +void BlockSignals(BOOL block,int signum) +{ +#ifdef HAVE_SIGPROCMASK + sigset_t set; + sigemptyset(&set); + sigaddset(&set,signum); + sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL); +#elif defined(HAVE_SIGBLOCK) + int block_mask = sigmask(signum); + static int oldmask = 0; + if (block) { + oldmask = sigblock(block_mask); + } else { + sigsetmask(oldmask); + } +#else + /* yikes! This platform can't block signals? */ + static int done; + if (!done) { + DEBUG(0,("WARNING: No signal blocking available\n")); + done=1; + } +#endif +} + + + +/******************************************************************* +catch a signal. This should implement the following semantics: + +1) the handler remains installed after being called +2) the signal should be blocked during handler execution +********************************************************************/ +void CatchSignal(int signum,void (*handler)(int )) +{ +#ifdef HAVE_SIGACTION + struct sigaction act; + + memset(&act, 0, sizeof(act)); + + act.sa_handler = handler; +#ifdef SA_RESTART + act.sa_flags = SA_RESTART; +#endif + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask,signum); + sigaction(signum,&act,NULL); +#else + /* FIXME: need to handle sigvec and systems with broken signal() */ + signal(signum, handler); +#endif +} + + + +/******************************************************************* +ignore SIGCLD via whatever means is necessary for this OS +********************************************************************/ +void CatchChild(void) +{ + CatchSignal(SIGCLD, sig_cld); +} diff --git a/source3/lib/slprintf.c b/source3/lib/slprintf.c index 4de7b10f4f..acdcfee38f 100644 --- a/source3/lib/slprintf.c +++ b/source3/lib/slprintf.c @@ -83,7 +83,7 @@ int vslprintf(char *str, int n, char *format, va_list ap) #endif } -#ifdef __STDC__ +#ifdef HAVE_STDARG_H int slprintf(char *str, int n, char *format, ...) { #else @@ -96,7 +96,7 @@ va_dcl va_list ap; int ret; -#ifdef __STDC__ +#ifdef HAVE_STDARG_H va_start(ap, format); #else va_start(ap); diff --git a/source3/lib/system.c b/source3/lib/system.c index f453741fdd..ab65339f6e 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -44,7 +44,7 @@ this replaces the normal select() system call return if some data has arrived on one of the file descriptors return -1 means error ********************************************************************/ -#ifdef NO_SELECT +#ifndef HAVE_SELECT static int pollfd(int fd) { int r=0; @@ -146,11 +146,11 @@ The wait() calls vary between systems ********************************************************************/ int sys_waitpid(pid_t pid,int *status,int options) { -#ifdef USE_WAITPID +#ifdef HAVE_WAITPID return waitpid(pid,status,options); -#else /* USE_WAITPID */ +#else /* HAVE_WAITPID */ return wait4(pid, status, options, NULL); -#endif /* USE_WAITPID */ +#endif /* HAVE_WAITPID */ } /******************************************************************* @@ -343,10 +343,10 @@ for getwd char *sys_getwd(char *s) { char *wd; -#ifdef USE_GETCWD - wd = (char *) getcwd (s, sizeof (pstring)); +#ifdef HAVE_GETCWD + wd = (char *)getcwd(s, sizeof (pstring)); #else - wd = (char *) getwd (s); + wd = (char *)getwd(s); #endif if (wd) unix_to_dos (wd, True); @@ -358,10 +358,14 @@ chown isn't used much but OS/2 doesn't have it ********************************************************************/ int sys_chown(char *fname,int uid,int gid) { -#ifdef NO_CHOWN - DEBUG(1,("Warning - chown(%s,%d,%d) not done\n",fname,uid,gid)); +#ifndef HAVE_CHOWN + static int done; + if (!done) { + DEBUG(1,("WARNING: no chown!\n")); + done=1; + } #else - return(chown(fname,uid,gid)); + return(chown(fname,uid,gid)); #endif } @@ -370,10 +374,14 @@ os/2 also doesn't have chroot ********************************************************************/ int sys_chroot(char *dname) { -#ifdef NO_CHROOT - DEBUG(1,("Warning - chroot(%s) not done\n",dname)); +#ifndef HAVE_CHROOT + static int done; + if (!done) { + DEBUG(1,("WARNING: no chroot!\n")); + done=1; + } #else - return(chroot(dname)); + return(chroot(dname)); #endif } diff --git a/source3/lib/time.c b/source3/lib/time.c index c73d219120..6eacf2a5ed 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -51,10 +51,10 @@ a gettimeofday wrapper ********************************************************************/ void GetTimeOfDay(struct timeval *tval) { -#ifdef GETTIMEOFDAY1 - gettimeofday(tval); +#ifdef HAVE_GETTIMEOFDAY_TZ + gettimeofday(tval,NULL); #else - gettimeofday(tval,NULL); + gettimeofday(tval); #endif } @@ -477,11 +477,11 @@ char *http_timestring(time_t t) if (!tm) slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); else -#ifdef NO_STRFTIME +#ifndef HAVE_STRFTIME fstrcpy(buf, asctime(tm)); -#else /* NO_STRFTIME */ +#else /* !HAVE_STRFTIME */ strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); -#endif /* NO_STRFTIME */ +#endif /* !HAVE_STRFTIME */ return buf; } @@ -492,31 +492,20 @@ char *http_timestring(time_t t) ****************************************************************************/ char *timestring(void ) { - static fstring TimeBuf; - time_t t = time(NULL); - struct tm *tm = LocalTime(&t); - - if (!tm) - slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t); - else -#ifdef NO_STRFTIME - fstrcpy(TimeBuf, asctime(tm)); -#elif defined(CLIX) || defined(CONVEX) - strftime(TimeBuf,100,"%Y/%m/%d %I:%M:%S %p",tm); -#elif defined(AMPM) - strftime(TimeBuf,100,"%Y/%m/%d %r",tm); -#elif defined(TZ_TIME) - { - int zone = TimeDiff(t); - int absZoneMinutes = (zone<0 ? -zone : zone) / 60; - size_t len = strftime(TimeBuf,sizeof(TimeBuf)-6,"%Y/%m/%d %T",tm); - slprintf(TimeBuf+len, sizeof(fstring) - len - 1, " %c%02d%02d", - zone<0?'+':'-',absZoneMinutes/60,absZoneMinutes%60); - } + static fstring TimeBuf; + time_t t = time(NULL); + struct tm *tm = LocalTime(&t); + + if (!tm) { + slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t); + } else { +#ifdef HAVE_STRFTIME + strftime(TimeBuf,100,"%Y/%m/%d %T",tm); #else - strftime(TimeBuf,100,"%Y/%m/%d %T",tm); + fstrcpy(TimeBuf, asctime(tm)); #endif - return(TimeBuf); + } + return(TimeBuf); } /**************************************************************************** diff --git a/source3/lib/ufc.c b/source3/lib/ufc.c index 17fd970c5b..f464953498 100644 --- a/source3/lib/ufc.c +++ b/source3/lib/ufc.c @@ -16,7 +16,9 @@ */ -#ifdef UFC_CRYPT +#include "includes.h" + +#ifndef HAVE_CRYPT /* * UFC-crypt: ultra fast crypt(3) implementation @@ -42,7 +44,6 @@ * Support routines * */ -#include "includes.h" #ifndef long32 diff --git a/source3/lib/username.c b/source3/lib/username.c index b79e6aefc3..8fb81e22b0 100644 --- a/source3/lib/username.c +++ b/source3/lib/username.c @@ -212,7 +212,6 @@ struct passwd *Get_Pwnam(char *user,BOOL allow_change) strlower(user); last_char = strlen(user)-1; user[last_char] = toupper(user[last_char]); - DEBUG(3, ("Trying username %s\n", user)); ret = _Get_Pwnam(user); if (ret) return(ret); @@ -232,7 +231,7 @@ check if a user is in a netgroup user list ****************************************************************************/ static BOOL user_in_netgroup_list(char *user,char *ngname) { -#ifdef NETGROUP +#ifdef HAVE_NETGROUP static char *mydomain = NULL; if (mydomain == NULL) yp_get_default_domain(&mydomain); @@ -252,7 +251,7 @@ static BOOL user_in_netgroup_list(char *user,char *ngname) if (innetgr(ngname, NULL, user, mydomain)) return (True); } -#endif /* NETGROUP */ +#endif /* HAVE_NETGROUP */ return False; } @@ -261,7 +260,7 @@ check if a user is in a UNIX user list ****************************************************************************/ static BOOL user_in_group_list(char *user,char *gname) { -#if HAVE_GETGRNAM +#ifdef HAVE_GETGRNAM struct group *gptr; char **member; struct passwd *pass = Get_Pwnam(user,False); diff --git a/source3/lib/util.c b/source3/lib/util.c index 22db8d4ab6..8d1f619318 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -21,7 +21,7 @@ #include "includes.h" -#if (defined(NETGROUP) && defined (AUTOMOUNT)) +#if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT)) #ifdef NISPLUS_HOME #include <rpcsvc/nis.h> #else @@ -29,12 +29,12 @@ #endif #endif -#ifdef USE_SSL +#ifdef WITH_SSL #include <ssl.h> #undef Realloc /* SSLeay defines this and samba has a function of this name */ extern SSL *ssl; extern int sslFd; -#endif /* USE_SSL */ +#endif /* WITH_SSL */ pstring scope = ""; @@ -70,7 +70,7 @@ int trans_num = 0; int case_default = CASE_LOWER; pstring debugf = ""; -int syslog_level; +int syslog_level = 0; /* the following control case operations - they are put here so the client can link easily */ @@ -119,17 +119,16 @@ int sig_usr2(void) DEBUG( 0, ( "Got SIGUSR2 set debug level to %d.\n", DEBUGLEVEL ) ); BlockSignals( False, SIGUSR2); -#ifndef DONT_REINSTALL_SIG - signal(SIGUSR2, SIGNAL_CAST sig_usr2); -#endif + CatchSignal(SIGUSR2, SIGNAL_CAST sig_usr2); + return(0); } #endif /* SIGUSR1 */ #if defined(SIGUSR1) -/**************************************************************************** ** +/****************************************************************************** catch a sigusr1 - increase the debug log level. - **************************************************************************** */ + *****************************************************************************/ int sig_usr1(void) { BlockSignals( True, SIGUSR1); @@ -142,9 +141,7 @@ int sig_usr1(void) DEBUG( 0, ( "Got SIGUSR1 set debug level to %d.\n", DEBUGLEVEL ) ); BlockSignals( False, SIGUSR1); -#ifndef DONT_REINSTALL_SIG - signal(SIGUSR1, SIGNAL_CAST sig_usr1); -#endif + CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1); return(0); } #endif /* SIGUSR1 */ @@ -155,7 +152,7 @@ int sig_usr1(void) ******************************************************************/ void setup_logging(char *pname,BOOL interactive) { -#ifdef SYSLOG +#ifdef WITH_SYSLOG if (!interactive) { char *p = strrchr(pname,'/'); if (p) pname = p+1; @@ -273,7 +270,7 @@ static void check_log_size(void) write an debug message on the debugfile. This is called by the DEBUG macro ********************************************************************/ -#ifdef __STDC__ +#ifdef HAVE_STDARG_H int Debug1(char *format_str, ...) { #else @@ -286,7 +283,7 @@ va_dcl int old_errno = errno; if (stdout_logging) { -#ifdef __STDC__ +#ifdef HAVE_STDARG_H va_start(ap, format_str); #else va_start(ap); @@ -298,7 +295,7 @@ va_dcl return(0); } -#ifdef SYSLOG +#ifdef WITH_SYSLOG if (!lp_syslog_only()) #endif { @@ -318,7 +315,7 @@ va_dcl } } -#ifdef SYSLOG +#ifdef WITH_SYSLOG if (syslog_level < lp_syslog()) { /* @@ -341,7 +338,7 @@ va_dcl else priority = priority_map[syslog_level]; -#ifdef __STDC__ +#ifdef HAVE_STDARG_H va_start(ap, format_str); #else va_start(ap); @@ -355,11 +352,11 @@ va_dcl } #endif -#ifdef SYSLOG +#ifdef WITH_SYSLOG if (!lp_syslog_only()) #endif { -#ifdef __STDC__ +#ifdef HAVE_STDARG_H va_start(ap, format_str); #else va_start(ap); @@ -483,65 +480,6 @@ char **toktocliplist(int *ctok, char *sep) return ret; } -#ifndef HAVE_MEMMOVE -/******************************************************************* -safely copies memory, ensuring no overlap problems. -this is only used if the machine does not have it's own memmove(). -this is not the fastest algorithm in town, but it will do for our -needs. -********************************************************************/ -void *MemMove(void *dest,void *src,int size) -{ - unsigned long d,s; - int i; - if (dest==src || !size) return(dest); - - d = (unsigned long)dest; - s = (unsigned long)src; - - if ((d >= (s+size)) || (s >= (d+size))) { - /* no overlap */ - memcpy(dest,src,size); - return(dest); - } - - if (d < s) - { - /* we can forward copy */ - if (s-d >= sizeof(int) && - !(s%sizeof(int)) && !(d%sizeof(int)) && !(size%sizeof(int))) { - /* do it all as words */ - int *idest = (int *)dest; - int *isrc = (int *)src; - size /= sizeof(int); - for (i=0;i<size;i++) idest[i] = isrc[i]; - } else { - /* simplest */ - char *cdest = (char *)dest; - char *csrc = (char *)src; - for (i=0;i<size;i++) cdest[i] = csrc[i]; - } - } - else - { - /* must backward copy */ - if (d-s >= sizeof(int) && - !(s%sizeof(int)) && !(d%sizeof(int)) && !(size%sizeof(int))) { - /* do it all as words */ - int *idest = (int *)dest; - int *isrc = (int *)src; - size /= sizeof(int); - for (i=size-1;i>=0;i--) idest[i] = isrc[i]; - } else { - /* simplest */ - char *cdest = (char *)dest; - char *csrc = (char *)src; - for (i=size-1;i>=0;i--) cdest[i] = csrc[i]; - } - } - return(dest); -} -#endif /* ************************************************************************* ** * Duplicate a block of memory. @@ -686,9 +624,9 @@ void set_socket_options(int fd, char *options) ****************************************************************************/ void close_sockets(void ) { -#ifdef USE_SSL +#ifdef WITH_SSL sslutil_disconnect(Client); -#endif /* USE_SSL */ +#endif /* WITH_SSL */ close(Client); Client = 0; @@ -2188,15 +2126,15 @@ int read_with_timeout(int fd,char *buf,int mincnt,int maxcnt,long time_out) if (mincnt == 0) mincnt = maxcnt; while (nread < mincnt) { -#ifdef USE_SSL +#ifdef WITH_SSL if(fd == sslFd){ readret = SSL_read(ssl, buf + nread, maxcnt - nread); }else{ readret = read(fd, buf + nread, maxcnt - nread); } -#else /* USE_SSL */ +#else /* WITH_SSL */ readret = read(fd, buf + nread, maxcnt - nread); -#endif /* USE_SSL */ +#endif /* WITH_SSL */ if (readret == 0) { smb_read_error = READ_EOF; @@ -2242,15 +2180,15 @@ int read_with_timeout(int fd,char *buf,int mincnt,int maxcnt,long time_out) return -1; } -#ifdef USE_SSL +#ifdef WITH_SSL if(fd == sslFd){ readret = SSL_read(ssl, buf + nread, maxcnt - nread); }else{ readret = read(fd, buf + nread, maxcnt - nread); } -#else /* USE_SSL */ +#else /* WITH_SSL */ readret = read(fd, buf+nread, maxcnt-nread); -#endif /* USE_SSL */ +#endif /* WITH_SSL */ if (readret == 0) { /* we got EOF on the file descriptor */ @@ -2335,15 +2273,15 @@ int read_data(int fd,char *buffer,int N) while (total < N) { -#ifdef USE_SSL +#ifdef WITH_SSL if(fd == sslFd){ ret = SSL_read(ssl, buffer + total, N - total); }else{ ret = read(fd,buffer + total,N - total); } -#else /* USE_SSL */ +#else /* WITH_SSL */ ret = read(fd,buffer + total,N - total); -#endif /* USE_SSL */ +#endif /* WITH_SSL */ if (ret == 0) { @@ -2371,15 +2309,15 @@ int write_data(int fd,char *buffer,int N) while (total < N) { -#ifdef USE_SSL +#ifdef WITH_SSL if(fd == sslFd){ ret = SSL_write(ssl,buffer + total,N - total); }else{ ret = write(fd,buffer + total,N - total); } -#else /* USE_SSL */ +#else /* WITH_SSL */ ret = write(fd,buffer + total,N - total); -#endif /* USE_SSL */ +#endif /* WITH_SSL */ if (ret == -1) return -1; if (ret == 0) return total; @@ -3364,28 +3302,25 @@ become a daemon, discarding the controlling terminal ****************************************************************************/ void become_daemon(void) { -#ifndef NO_FORK_DEBUG - if (fork()) - _exit(0); + if (fork()) { + _exit(0); + } /* detach from the terminal */ -#ifdef USE_SETSID - setsid(); -#else /* USE_SETSID */ -#ifdef TIOCNOTTY - { - int i = open("/dev/tty", O_RDWR); - if (i >= 0) - { - ioctl(i, (int) TIOCNOTTY, (char *)0); - close(i); - } - } -#endif /* TIOCNOTTY */ -#endif /* USE_SETSID */ - /* Close fd's 0,1,2. Needed if started by rsh */ - close_low_fds(); -#endif /* NO_FORK_DEBUG */ +#ifdef HAVE_SETSID + setsid(); +#elif defined(TIOCNOTTY) + { + int i = open("/dev/tty", O_RDWR); + if (i != -1) { + ioctl(i, (int) TIOCNOTTY, (char *)0); + close(i); + } + } +#endif /* HAVE_SETSID */ + + /* Close fd's 0,1,2. Needed if started by rsh */ + close_low_fds(); } @@ -3484,7 +3419,7 @@ int set_filelen(int fd, long len) extend a file with ftruncate. Provide alternate implementation for this */ -#if FTRUNCATE_CAN_EXTEND +#ifdef HAVE_FTRUNCATE_EXTEND return ftruncate(fd, len); #else struct stat st; @@ -3606,22 +3541,6 @@ void *Realloc(void *p,int size) return(ret); } -#ifdef NOSTRDUP -/**************************************************************************** -duplicate a string -****************************************************************************/ - char *strdup(char *s) -{ - char *ret = NULL; - int len; - if (!s) return(NULL); - ret = (char *)malloc((len = strlen(s))+1); - if (!ret) return(NULL); - safe_strcpy(ret,s,len); - return(ret); -} -#endif - /**************************************************************************** Signal handler for SIGPIPE (write on a disconnected socket) @@ -3707,7 +3626,8 @@ int open_socket_in(int type, int port, int dlevel,uint32 socket_addr) bzero((char *)&sock,sizeof(sock)); memcpy((char *)&sock.sin_addr,(char *)hp->h_addr, hp->h_length); -#if defined(__FreeBSD__) || defined(NETBSD) || defined(__OpenBSD__) /* XXX not the right ifdef */ + +#ifdef HAVE_SOCK_SIN_LEN sock.sin_len = sizeof(sock); #endif sock.sin_port = htons( port ); @@ -4065,7 +3985,7 @@ char *client_addr(int fd) return addr_buf; } -#if (defined(NETGROUP) && defined(AUTOMOUNT)) +#if (defined(HAVE_NETGROUP) && defined(WITH_AUTOMOUNT)) /****************************************************************** Remove any mount options such as -rsize=2048,wsize=2048 etc. Based on a fix from <Thomas.Hepper@icem.de>. @@ -4213,10 +4133,10 @@ char *automount_server(char *user_name) static pstring server_name; /* use the local machine name as the default */ - /* this will be the default if AUTOMOUNT is not used or fails */ + /* this will be the default if WITH_AUTOMOUNT is not used or fails */ pstrcpy(server_name, local_machine); -#if (defined(NETGROUP) && defined (AUTOMOUNT)) +#if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT)) if (lp_nis_home_map()) { @@ -4248,11 +4168,11 @@ char *automount_path(char *user_name) static pstring server_path; /* use the passwd entry as the default */ - /* this will be the default if AUTOMOUNT is not used or fails */ + /* this will be the default if WITH_AUTOMOUNT is not used or fails */ /* pstrcpy() copes with get_home_dir() returning NULL */ pstrcpy(server_path, get_home_dir(user_name)); -#if (defined(NETGROUP) && defined (AUTOMOUNT)) +#if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT)) if (lp_nis_home_map()) { @@ -4484,31 +4404,11 @@ turn a gid into a group name ********************************************************************/ char *gidtoname(int gid) { - static char name[40]; - struct group *grp = getgrgid(gid); - if (grp) return(grp->gr_name); - slprintf(name,sizeof(name) - 1, "%d",gid); - return(name); -} - -/******************************************************************* -block sigs -********************************************************************/ -void BlockSignals(BOOL block,int signum) -{ -#ifdef USE_SIGBLOCK - int block_mask = sigmask(signum); - static int oldmask = 0; - if (block) - oldmask = sigblock(block_mask); - else - sigsetmask(oldmask); -#elif defined(USE_SIGPROCMASK) - sigset_t set; - sigemptyset(&set); - sigaddset(&set,signum); - sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL); -#endif + static char name[40]; + struct group *grp = getgrgid(gid); + if (grp) return(grp->gr_name); + slprintf(name,sizeof(name) - 1, "%d",gid); + return(name); } #if AJT @@ -4517,15 +4417,10 @@ my own panic function - not suitable for general use ********************************************************************/ void ajt_panic(void) { - system("/usr/bin/X11/xedit -display solen:0 /tmp/ERROR_FAULT"); + system("/usr/bin/X11/xedit -display :0 /tmp/ERROR_FAULT"); } #endif -#ifdef USE_DIRECT -#define DIRECT direct -#else -#define DIRECT dirent -#endif /******************************************************************* a readdir wrapper which just returns the file name @@ -4533,43 +4428,33 @@ also return the inode number if requested ********************************************************************/ char *readdirname(void *p) { - struct DIRECT *ptr; - char *dname; + struct dirent *ptr; + char *dname; - if (!p) return(NULL); + if (!p) return(NULL); - ptr = (struct DIRECT *)readdir(p); - if (!ptr) return(NULL); + ptr = (struct dirent *)readdir(p); + if (!ptr) return(NULL); - dname = ptr->d_name; + dname = ptr->d_name; #ifdef NEXT2 - if (telldir(p) < 0) return(NULL); + if (telldir(p) < 0) return(NULL); #endif -#ifdef SUNOS5 - /* this handles a broken compiler setup, causing a mixture - of BSD and SYSV headers and libraries */ - { - static BOOL broken_readdir = False; - if (!broken_readdir && !(*(dname)) && strequal("..",dname-2)) - { - DEBUG(0,("Your readdir() is broken. You have somehow mixed SYSV and BSD headers and libraries\n")); - broken_readdir = True; - } - if (broken_readdir) - dname = dname - 2; - } +#ifdef HAVE_BROKEN_READDIR + /* using /usr/ucb/cc is BAD */ + dname = dname - 2; #endif - { - static pstring buf; - pstrcpy(buf, dname); - unix_to_dos(buf, True); - dname = buf; - } + { + static pstring buf; + memcpy(buf, dname, NAMLEN(ptr)+1); + unix_to_dos(buf, True); + dname = buf; + } - return(dname); + return(dname); } /******************************************************************* |