Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/lib/replace/replace.c

    r860 r988  
    2828#include "system/filesys.h"
    2929#include "system/time.h"
     30#include "system/network.h"
    3031#include "system/passwd.h"
    3132#include "system/syslog.h"
     
    6465
    6566#ifndef HAVE_STRLCPY
    66 /* like strncpy but does not 0 fill the buffer and always null
    67    terminates. bufsize is the size of the destination buffer */
     67/*
     68 * Like strncpy but does not 0 fill the buffer and always null
     69 * terminates. bufsize is the size of the destination buffer.
     70 * Returns the length of s.
     71 */
    6872size_t rep_strlcpy(char *d, const char *s, size_t bufsize)
    6973{
    7074        size_t len = strlen(s);
    7175        size_t ret = len;
    72         if (bufsize <= 0) return 0;
    73         if (len >= bufsize) len = bufsize-1;
     76
     77        if (bufsize <= 0) {
     78                return 0;
     79        }
     80        if (len >= bufsize) {
     81                len = bufsize - 1;
     82        }
    7483        memcpy(d, s, len);
    7584        d[len] = 0;
     
    8493size_t rep_strlcat(char *d, const char *s, size_t bufsize)
    8594{
    86         size_t len1 = strlen(d);
     95        size_t len1 = strnlen(d, bufsize);
    8796        size_t len2 = strlen(s);
    8897        size_t ret = len1 + len2;
     
    212221}
    213222#endif /* HAVE_INITGROUPS */
    214 
    215 
    216 #if (defined(SecureWare) && defined(SCO))
    217 /* This is needed due to needing the nap() function but we don't want
    218    to include the Xenix libraries since that will break other things...
    219    BTW: system call # 0x0c28 is the same as calling nap() */
    220 long nap(long milliseconds) {
    221          return syscall(0x0c28, milliseconds);
    222  }
    223 #endif
    224223
    225224
     
    412411        /* have a reasonable go at emulating it. Hope that
    413412           the system mktemp() isn't completely hopeless */
    414         char *p = mktemp(template);
    415         if (!p)
     413        mktemp(template);
     414        if (template[0] == 0)
    416415                return -1;
    417         return open(p, O_CREAT|O_EXCL|O_RDWR, 0600);
     416        return open(template, O_CREAT|O_EXCL|O_RDWR, 0600);
    418417}
    419418#endif
     
    477476#endif
    478477
     478#ifndef HAVE_STRSEP
     479char *rep_strsep(char **pps, const char *delim)
     480{
     481        char *ret = *pps;
     482        char *p = *pps;
     483
     484        if (p == NULL) {
     485                return NULL;
     486        }
     487        p += strcspn(p, delim);
     488        if (*p == '\0') {
     489                *pps = NULL;
     490        } else {
     491                *p = '\0';
     492                *pps = p + 1;
     493        }
     494        return ret;
     495}
     496#endif
     497
    479498#ifndef HAVE_STRTOK_R
    480499/* based on GLIBC version, copyright Free Software Foundation */
     
    520539#else
    521540#ifdef HAVE_BSD_STRTOLL
    522 #ifdef HAVE_STRTOQ
     541#undef strtoll
    523542long long int rep_strtoll(const char *str, char **endptr, int base)
    524543{
    525         long long int nb = strtoq(str, endptr, base);
    526         /* In linux EINVAL is only returned if base is not ok */
     544        int saved_errno = errno;
     545        long long int nb = strtoll(str, endptr, base);
     546        /* With glibc EINVAL is only returned if base is not ok */
    527547        if (errno == EINVAL) {
    528548                if (base == 0 || (base >1 && base <37)) {
     
    531551                         * Let's reset errno.
    532552                         */
    533                         errno = 0;
     553                        errno = saved_errno;
    534554                }
    535555        }
    536556        return nb;
    537557}
    538 #else
    539 #error "You need the strtoq function"
    540 #endif /* HAVE_STRTOQ */
    541558#endif /* HAVE_BSD_STRTOLL */
    542559#endif /* HAVE_STRTOLL */
     
    558575#else
    559576#ifdef HAVE_BSD_STRTOLL
    560 #ifdef HAVE_STRTOUQ
     577#undef strtoull
    561578unsigned long long int rep_strtoull(const char *str, char **endptr, int base)
    562579{
    563         unsigned long long int nb = strtouq(str, endptr, base);
    564         /* In linux EINVAL is only returned if base is not ok */
     580        int saved_errno = errno;
     581        unsigned long long int nb = strtoull(str, endptr, base);
     582        /* With glibc EINVAL is only returned if base is not ok */
    565583        if (errno == EINVAL) {
    566584                if (base == 0 || (base >1 && base <37)) {
     
    569587                         * Let's reset errno.
    570588                         */
    571                         errno = 0;
     589                        errno = saved_errno;
    572590                }
    573591        }
    574592        return nb;
    575593}
    576 #else
    577 #error "You need the strtouq function"
    578 #endif /* HAVE_STRTOUQ */
    579594#endif /* HAVE_BSD_STRTOLL */
    580595#endif /* HAVE_STRTOULL */
     
    795810#endif
    796811
    797 #if !defined(HAVE_STRERROR_R) || !defined(STRERROR_R_PROTO_COMPATIBLE)
     812#ifndef HAVE_STRERROR_R
    798813int rep_strerror_r(int errnum, char *buf, size_t buflen)
    799814{
     
    814829        switch (clk_id) {
    815830                case 0: /* CLOCK_REALTIME :*/
    816 #ifdef HAVE_GETTIMEOFDAY_TZ
     831#if defined(HAVE_GETTIMEOFDAY_TZ) || defined(HAVE_GETTIMEOFDAY_TZ_VOID)
    817832                        gettimeofday(&tval,NULL);
    818833#else
     
    829844}
    830845#endif
     846
     847#ifndef HAVE_MEMALIGN
     848void *rep_memalign( size_t align, size_t size )
     849{
     850#if defined(HAVE_POSIX_MEMALIGN)
     851        void *p = NULL;
     852        int ret = posix_memalign( &p, align, size );
     853        if ( ret == 0 )
     854                return p;
     855
     856        return NULL;
     857#else
     858        /* On *BSD systems memaligns doesn't exist, but memory will
     859         * be aligned on allocations of > pagesize. */
     860#if defined(SYSCONF_SC_PAGESIZE)
     861        size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
     862#elif defined(HAVE_GETPAGESIZE)
     863        size_t pagesize = (size_t)getpagesize();
     864#else
     865        size_t pagesize = (size_t)-1;
     866#endif
     867        if (pagesize == (size_t)-1) {
     868                errno = ENOSYS;
     869                return NULL;
     870        }
     871        if (size < pagesize) {
     872                size = pagesize;
     873        }
     874        return malloc(size);
     875#endif
     876}
     877#endif
     878
     879#ifndef HAVE_GETPEEREID
     880int rep_getpeereid(int s, uid_t *uid, gid_t *gid)
     881{
     882#if defined(HAVE_PEERCRED)
     883        struct ucred cred;
     884        socklen_t cred_len = sizeof(struct ucred);
     885        int ret;
     886
     887#undef getsockopt
     888        ret = getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void *)&cred, &cred_len);
     889        if (ret != 0) {
     890                return -1;
     891        }
     892
     893        if (cred_len != sizeof(struct ucred)) {
     894                errno = EINVAL;
     895                return -1;
     896        }
     897
     898        *uid = cred.uid;
     899        *gid = cred.gid;
     900        return 0;
     901#else
     902        errno = ENOSYS;
     903        return -1;
     904#endif
     905}
     906#endif
     907
     908#ifndef HAVE_USLEEP
     909int rep_usleep(useconds_t sec)
     910{
     911        struct timeval tval;
     912        /*
     913         * Fake it with select...
     914         */
     915        tval.tv_sec = 0;
     916        tval.tv_usec = usecs/1000;
     917        select(0,NULL,NULL,NULL,&tval);
     918        return 0;
     919}
     920#endif /* HAVE_USLEEP */
     921
     922#ifndef HAVE_SETPROCTITLE
     923void rep_setproctitle(const char *fmt, ...)
     924{
     925}
     926#endif
Note: See TracChangeset for help on using the changeset viewer.