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/util/system.c

    r740 r988  
    2323#include "system/filesys.h"
    2424
     25#undef malloc
     26
    2527/*
    2628   The idea is that this file will eventually have wrappers around all
     
    3840*/
    3941
    40 /**************************************************************************
    41 A wrapper for gethostbyname() that tries avoids looking up hostnames
    42 in the root domain, which can cause dial-on-demand links to come up for no
    43 apparent reason.
    44 ****************************************************************************/
    45 
    46 _PUBLIC_ struct hostent *sys_gethostbyname(const char *name)
    47 {
    48 #ifdef REDUCE_ROOT_DNS_LOOKUPS
    49         char query[256], hostname[256];
    50         char *domain;
    51 
    52         /* Does this name have any dots in it? If so, make no change */
    53 
    54         if (strchr(name, '.'))
    55                 return(gethostbyname(name));
    56 
    57         /* Get my hostname, which should have domain name
    58                 attached. If not, just do the gethostname on the
    59                 original string.
    60         */
    61 
    62         gethostname(hostname, sizeof(hostname) - 1);
    63         hostname[sizeof(hostname) - 1] = 0;
    64         if ((domain = strchr(hostname, '.')) == NULL)
    65                 return(gethostbyname(name));
    66 
    67         /* Attach domain name to query and do modified query.
    68                 If names too large, just do gethostname on the
    69                 original string.
    70         */
    71 
    72         if((strlen(name) + strlen(domain)) >= sizeof(query))
    73                 return(gethostbyname(name));
    74 
    75         slprintf(query, sizeof(query)-1, "%s%s", name, domain);
    76         return(gethostbyname(query));
    77 #else /* REDUCE_ROOT_DNS_LOOKUPS */
    78         return(gethostbyname(name));
    79 #endif /* REDUCE_ROOT_DNS_LOOKUPS */
    80 }
    81 
    82 _PUBLIC_ struct in_addr sys_inet_makeaddr(int net, int host)
    83 {
    84         struct in_addr in;
    85         struct in_addr in2;
    86         in = inet_makeaddr(net, host);
    87         in2.s_addr = in.s_addr;
    88         return in2;
    89 }
    90 
    91 /**************************************************************************
    92  Wrapper for fork. Ensures we clear our pid cache.
    93 ****************************************************************************/
    94 
    95 static pid_t mypid = (pid_t)-1;
    96 
    97 _PUBLIC_ pid_t sys_fork(void)
    98 {
    99         pid_t forkret = fork();
    100 
    101         if (forkret == (pid_t)0) {
    102                 /* Child - reset mypid so sys_getpid does a system call. */
    103                 mypid = (pid_t) -1;
    104         }
    105 
    106         return forkret;
    107 }
    108 
    109 /**************************************************************************
    110  Wrapper for getpid. Ensures we only do a system call *once*.
    111 ****************************************************************************/
    112 
    113 _PUBLIC_ pid_t sys_getpid(void)
    114 {
    115         if (mypid == (pid_t)-1)
    116                 mypid = getpid();
    117 
    118         return mypid;
    119 }
    120 
    121 
    122 _PUBLIC_ int sys_getpeereid( int s, uid_t *uid)
    123 {
    124 #if defined(HAVE_PEERCRED)
    125         struct ucred cred;
    126         socklen_t cred_len = sizeof(struct ucred);
    127         int ret;
    128 
    129         ret = getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void *)&cred, &cred_len);
    130         if (ret != 0) {
    131                 return -1;
    132         }
    133 
    134         if (cred_len != sizeof(struct ucred)) {
    135                 errno = EINVAL;
    136                 return -1;
    137         }
    138 
    139         *uid = cred.uid;
    140         return 0;
    141 #else
    142 #if defined(HAVE_GETPEEREID)
    143         gid_t gid;
    144         return getpeereid(s, uid, &gid);
    145 #endif
    146         errno = ENOSYS;
    147         return -1;
    148 #endif
    149 }
    15042
    15143_PUBLIC_ int sys_getnameinfo(const struct sockaddr *psa,
     
    17264        return getnameinfo(psa, salen, host, hostlen, service, servlen, flags);
    17365}
    174 
    175 _PUBLIC_ int sys_connect(int fd, const struct sockaddr * addr)
    176 {
    177         socklen_t salen = (socklen_t)-1;
    178 
    179         if (addr->sa_family == AF_INET) {
    180             salen = sizeof(struct sockaddr_in);
    181         } else if (addr->sa_family == AF_UNIX) {
    182             salen = sizeof(struct sockaddr_un);
    183         }
    184 #if defined(HAVE_IPV6)
    185         else if (addr->sa_family == AF_INET6) {
    186             salen = sizeof(struct sockaddr_in6);
    187         }
    188 #endif
    189 
    190         return connect(fd, addr, salen);
    191 }
Note: See TracChangeset for help on using the changeset viewer.