Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/nsswitch/libwbclient/wbclient.c

    r478 r740  
    2424
    2525#include "replace.h"
    26 #include "talloc.h"
    27 #include "tevent.h"
    2826#include "libwbclient.h"
    2927
     
    3735                                          struct winbindd_response *response);
    3836
    39 /** @brief Wrapper around Winbind's send/receive API call
    40  *
    41  * @param cmd       Winbind command operation to perform
    42  * @param request   Send structure
    43  * @param response  Receive structure
    44  *
    45  * @return #wbcErr
    46  **/
    47 
    48 /**********************************************************************
     37/*
    4938 result == NSS_STATUS_UNAVAIL: winbind not around
    5039 result == NSS_STATUS_NOTFOUND: winbind around, but domain missing
     
    5746
    5847 --Volker
    59 **********************************************************************/
     48*/
    6049
    6150static wbcErr wbcRequestResponseInt(
     
    9281}
    9382
     83/**
     84 * @brief Wrapper around Winbind's send/receive API call
     85 *
     86 * @param cmd       Winbind command operation to perform
     87 * @param request   Send structure
     88 * @param response  Receive structure
     89 *
     90 * @return #wbcErr
     91 */
    9492wbcErr wbcRequestResponse(int cmd,
    9593                          struct winbindd_request *request,
     
    150148}
    151149
     150#define WBC_MAGIC (0x7a2b0e1e)
     151#define WBC_MAGIC_FREE (0x875634fe)
     152
     153struct wbcMemPrefix {
     154        uint32_t magic;
     155        void (*destructor)(void *ptr);
     156};
     157
     158static size_t wbcPrefixLen(void)
     159{
     160        size_t result = sizeof(struct wbcMemPrefix);
     161        return (result + 15) & ~15;
     162}
     163
     164static struct wbcMemPrefix *wbcMemToPrefix(void *ptr)
     165{
     166        return (struct wbcMemPrefix *)(((char *)ptr) - wbcPrefixLen());
     167}
     168
     169void *wbcAllocateMemory(size_t nelem, size_t elsize,
     170                        void (*destructor)(void *ptr))
     171{
     172        struct wbcMemPrefix *result;
     173
     174        if (nelem >= (2<<24)/elsize) {
     175                /* basic protection against integer wrap */
     176                return NULL;
     177        }
     178
     179        result = (struct wbcMemPrefix *)calloc(
     180                1, nelem*elsize + wbcPrefixLen());
     181        if (result == NULL) {
     182                return NULL;
     183        }
     184        result->magic = WBC_MAGIC;
     185        result->destructor = destructor;
     186        return ((char *)result) + wbcPrefixLen();
     187}
     188
    152189/* Free library allocated memory */
    153190void wbcFreeMemory(void *p)
    154191{
    155         if (p)
    156                 talloc_free(p);
    157 
     192        struct wbcMemPrefix *wbcMem;
     193
     194        if (p == NULL) {
     195                return;
     196        }
     197        wbcMem = wbcMemToPrefix(p);
     198        if (wbcMem->magic != WBC_MAGIC) {
     199                return;
     200        }
     201
     202        /* paranoid check to ensure we don't double free */
     203        wbcMem->magic = WBC_MAGIC_FREE;
     204
     205        if (wbcMem->destructor != NULL) {
     206                wbcMem->destructor(p);
     207        }
     208        free(wbcMem);
    158209        return;
    159210}
    160211
     212char *wbcStrDup(const char *str)
     213{
     214        char *result;
     215        size_t len;
     216
     217        len = strlen(str);
     218        result = (char *)wbcAllocateMemory(len+1, sizeof(char), NULL);
     219        if (result == NULL) {
     220                return NULL;
     221        }
     222        memcpy(result, str, len+1);
     223        return result;
     224}
     225
     226static void wbcStringArrayDestructor(void *ptr)
     227{
     228        char **p = (char **)ptr;
     229        while (*p != NULL) {
     230                free(*p);
     231                p += 1;
     232        }
     233}
     234
     235const char **wbcAllocateStringArray(int num_strings)
     236{
     237        return (const char **)wbcAllocateMemory(
     238                num_strings + 1, sizeof(const char *),
     239                wbcStringArrayDestructor);
     240}
     241
    161242wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details)
    162243{
    163         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    164244        struct wbcLibraryDetails *info;
    165245
    166         info = talloc(NULL, struct wbcLibraryDetails);
    167         BAIL_ON_PTR_ERROR(info, wbc_status);
     246        info = (struct wbcLibraryDetails *)wbcAllocateMemory(
     247                1, sizeof(struct wbcLibraryDetails), NULL);
     248
     249        if (info == NULL) {
     250                return WBC_ERR_NO_MEMORY;
     251        }
    168252
    169253        info->major_version = WBCLIENT_MAJOR_VERSION;
    170254        info->minor_version = WBCLIENT_MINOR_VERSION;
    171         info->vendor_version = talloc_strdup(info,
    172                                              WBCLIENT_VENDOR_VERSION);
    173         BAIL_ON_PTR_ERROR(info->vendor_version, wbc_status);
     255        info->vendor_version = WBCLIENT_VENDOR_VERSION;
    174256
    175257        *_details = info;
    176         info = NULL;
    177 
    178         wbc_status = WBC_ERR_SUCCESS;
    179 
    180 done:
    181         talloc_free(info);
    182         return wbc_status;
    183 }
     258        return WBC_ERR_SUCCESS;
     259}
Note: See TracChangeset for help on using the changeset viewer.