Changeset 740 for vendor/current/nsswitch/libwbclient/wbclient.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/nsswitch/libwbclient/wbclient.c
r478 r740 24 24 25 25 #include "replace.h" 26 #include "talloc.h"27 #include "tevent.h"28 26 #include "libwbclient.h" 29 27 … … 37 35 struct winbindd_response *response); 38 36 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 /* 49 38 result == NSS_STATUS_UNAVAIL: winbind not around 50 39 result == NSS_STATUS_NOTFOUND: winbind around, but domain missing … … 57 46 58 47 --Volker 59 * *********************************************************************/48 */ 60 49 61 50 static wbcErr wbcRequestResponseInt( … … 92 81 } 93 82 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 */ 94 92 wbcErr wbcRequestResponse(int cmd, 95 93 struct winbindd_request *request, … … 150 148 } 151 149 150 #define WBC_MAGIC (0x7a2b0e1e) 151 #define WBC_MAGIC_FREE (0x875634fe) 152 153 struct wbcMemPrefix { 154 uint32_t magic; 155 void (*destructor)(void *ptr); 156 }; 157 158 static size_t wbcPrefixLen(void) 159 { 160 size_t result = sizeof(struct wbcMemPrefix); 161 return (result + 15) & ~15; 162 } 163 164 static struct wbcMemPrefix *wbcMemToPrefix(void *ptr) 165 { 166 return (struct wbcMemPrefix *)(((char *)ptr) - wbcPrefixLen()); 167 } 168 169 void *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 152 189 /* Free library allocated memory */ 153 190 void wbcFreeMemory(void *p) 154 191 { 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); 158 209 return; 159 210 } 160 211 212 char *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 226 static void wbcStringArrayDestructor(void *ptr) 227 { 228 char **p = (char **)ptr; 229 while (*p != NULL) { 230 free(*p); 231 p += 1; 232 } 233 } 234 235 const char **wbcAllocateStringArray(int num_strings) 236 { 237 return (const char **)wbcAllocateMemory( 238 num_strings + 1, sizeof(const char *), 239 wbcStringArrayDestructor); 240 } 241 161 242 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details) 162 243 { 163 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;164 244 struct wbcLibraryDetails *info; 165 245 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 } 168 252 169 253 info->major_version = WBCLIENT_MAJOR_VERSION; 170 254 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; 174 256 175 257 *_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.