Changeset 745 for trunk/server/nsswitch/nsstest.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/nsswitch/nsstest.c
r414 r745 3 3 nss tester for winbindd 4 4 Copyright (C) Andrew Tridgell 2001 5 Copyright (C) Tim Potter 2003 5 6 6 7 This program is free software; you can redistribute it and/or modify … … 18 19 */ 19 20 20 #include "includes.h" 21 21 #include "replace.h" 22 22 #include "nsswitch/nsstest.h" 23 23 … … 30 30 static void *find_fn(const char *name) 31 31 { 32 char s[1024];32 char *s; 33 33 static void *h; 34 34 void *res; 35 35 36 snprintf(s,sizeof(s), "_nss_%s_%s", nss_name, name); 36 if (asprintf(&s, "_nss_%s_%s", nss_name, name) < 0) { 37 exit(1); 38 } 37 39 38 40 if (!h) { … … 46 48 if (!res) { 47 49 printf("Can't find function %s\n", s); 48 return NULL; 49 } 50 total_errors++; 51 free(s); 52 return NULL; 53 } 54 free(s); 50 55 return res; 51 56 } … … 62 67 { 63 68 NSS_STATUS (*_nss_getpwent_r)(struct passwd *, char *, 64 size_t , int *) = find_fn("getpwent_r"); 69 size_t , int *) = 70 (NSS_STATUS (*)(struct passwd *, char *, 71 size_t, int *))find_fn("getpwent_r"); 65 72 static struct passwd pwd; 66 73 static char buf[1000]; 67 74 NSS_STATUS status; 68 75 76 if (!_nss_getpwent_r) 77 return NULL; 78 69 79 status = _nss_getpwent_r(&pwd, buf, sizeof(buf), &nss_errno); 70 80 if (status == NSS_STATUS_NOTFOUND) { … … 81 91 { 82 92 NSS_STATUS (*_nss_getpwnam_r)(const char *, struct passwd *, char *, 83 size_t , int *) = find_fn("getpwnam_r"); 93 size_t , int *) = 94 (NSS_STATUS (*)(const char *, struct passwd *, char *, 95 size_t, int *))find_fn("getpwnam_r"); 84 96 static struct passwd pwd; 85 97 static char buf[1000]; 86 98 NSS_STATUS status; 87 99 100 if (!_nss_getpwnam_r) 101 return NULL; 102 88 103 status = _nss_getpwnam_r(name, &pwd, buf, sizeof(buf), &nss_errno); 89 104 if (status == NSS_STATUS_NOTFOUND) { … … 100 115 { 101 116 NSS_STATUS (*_nss_getpwuid_r)(uid_t , struct passwd *, char *, 102 size_t , int *) = find_fn("getpwuid_r"); 117 size_t , int *) = 118 (NSS_STATUS (*)(uid_t, struct passwd *, char *, 119 size_t, int *))find_fn("getpwuid_r"); 103 120 static struct passwd pwd; 104 121 static char buf[1000]; 105 122 NSS_STATUS status; 106 123 124 if (!_nss_getpwuid_r) 125 return NULL; 126 107 127 status = _nss_getpwuid_r(uid, &pwd, buf, sizeof(buf), &nss_errno); 108 128 if (status == NSS_STATUS_NOTFOUND) { … … 118 138 static void nss_setpwent(void) 119 139 { 120 NSS_STATUS (*_nss_setpwent)(void) = find_fn("setpwent"); 121 NSS_STATUS status; 140 NSS_STATUS (*_nss_setpwent)(void) = 141 (NSS_STATUS(*)(void))find_fn("setpwent"); 142 NSS_STATUS status; 143 144 if (!_nss_setpwent) 145 return; 146 122 147 status = _nss_setpwent(); 123 148 if (status != NSS_STATUS_SUCCESS) { … … 128 153 static void nss_endpwent(void) 129 154 { 130 NSS_STATUS (*_nss_endpwent)(void) = find_fn("endpwent"); 131 NSS_STATUS status; 155 NSS_STATUS (*_nss_endpwent)(void) = 156 (NSS_STATUS (*)(void))find_fn("endpwent"); 157 NSS_STATUS status; 158 159 if (!_nss_endpwent) 160 return; 161 132 162 status = _nss_endpwent(); 133 163 if (status != NSS_STATUS_SUCCESS) { … … 140 170 { 141 171 NSS_STATUS (*_nss_getgrent_r)(struct group *, char *, 142 size_t , int *) = find_fn("getgrent_r"); 172 size_t , int *) = 173 (NSS_STATUS (*)(struct group *, char *, 174 size_t, int *))find_fn("getgrent_r"); 143 175 static struct group grp; 144 176 static char *buf; … … 146 178 NSS_STATUS status; 147 179 148 if (!buf) buf = malloc_array_p(char, buflen); 180 if (!_nss_getgrent_r) 181 return NULL; 182 183 if (!buf) 184 buf = (char *)malloc(buflen); 149 185 150 186 again: … … 152 188 if (status == NSS_STATUS_TRYAGAIN) { 153 189 buflen *= 2; 154 buf = realloc_p(buf, char, buflen); 190 buf = (char *)realloc(buf, buflen); 191 if (!buf) { 192 return NULL; 193 } 155 194 goto again; 156 195 } 157 196 if (status == NSS_STATUS_NOTFOUND) { 197 free(buf); 158 198 return NULL; 159 199 } 160 200 if (status != NSS_STATUS_SUCCESS) { 161 201 report_nss_error("getgrent", status); 202 free(buf); 162 203 return NULL; 163 204 } … … 168 209 { 169 210 NSS_STATUS (*_nss_getgrnam_r)(const char *, struct group *, char *, 170 size_t , int *) = find_fn("getgrnam_r"); 211 size_t , int *) = 212 (NSS_STATUS (*)(const char *, struct group *, char *, 213 size_t, int *))find_fn("getgrnam_r"); 171 214 static struct group grp; 172 215 static char *buf; … … 174 217 NSS_STATUS status; 175 218 176 if (!buf) buf = malloc_array_p(char, buflen); 219 if (!_nss_getgrnam_r) 220 return NULL; 221 222 if (!buf) 223 buf = (char *)malloc(buflen); 177 224 again: 178 225 status = _nss_getgrnam_r(name, &grp, buf, buflen, &nss_errno); 179 226 if (status == NSS_STATUS_TRYAGAIN) { 180 227 buflen *= 2; 181 buf = realloc_p(buf, char, buflen); 228 buf = (char *)realloc(buf, buflen); 229 if (!buf) { 230 return NULL; 231 } 182 232 goto again; 183 233 } 184 234 if (status == NSS_STATUS_NOTFOUND) { 235 free(buf); 185 236 return NULL; 186 237 } 187 238 if (status != NSS_STATUS_SUCCESS) { 188 239 report_nss_error("getgrnam", status); 240 free(buf); 189 241 return NULL; 190 242 } … … 195 247 { 196 248 NSS_STATUS (*_nss_getgrgid_r)(gid_t , struct group *, char *, 197 size_t , int *) = find_fn("getgrgid_r"); 249 size_t , int *) = 250 (NSS_STATUS (*)(gid_t, struct group *, char *, 251 size_t, int *))find_fn("getgrgid_r"); 198 252 static struct group grp; 199 253 static char *buf; … … 201 255 NSS_STATUS status; 202 256 203 if (!buf) buf = malloc_array_p(char, buflen); 257 if (!_nss_getgrgid_r) 258 return NULL; 259 260 if (!buf) 261 buf = (char *)malloc(buflen); 262 204 263 again: 205 264 status = _nss_getgrgid_r(gid, &grp, buf, buflen, &nss_errno); 206 265 if (status == NSS_STATUS_TRYAGAIN) { 207 266 buflen *= 2; 208 buf = realloc_p(buf, char, buflen); 267 buf = (char *)realloc(buf, buflen); 268 if (!buf) { 269 return NULL; 270 } 209 271 goto again; 210 272 } 211 273 if (status == NSS_STATUS_NOTFOUND) { 274 free(buf); 212 275 return NULL; 213 276 } 214 277 if (status != NSS_STATUS_SUCCESS) { 215 278 report_nss_error("getgrgid", status); 279 free(buf); 216 280 return NULL; 217 281 } … … 221 285 static void nss_setgrent(void) 222 286 { 223 NSS_STATUS (*_nss_setgrent)(void) = find_fn("setgrent"); 224 NSS_STATUS status; 287 NSS_STATUS (*_nss_setgrent)(void) = 288 (NSS_STATUS (*)(void))find_fn("setgrent"); 289 NSS_STATUS status; 290 291 if (!_nss_setgrent) 292 return; 293 225 294 status = _nss_setgrent(); 226 295 if (status != NSS_STATUS_SUCCESS) { … … 231 300 static void nss_endgrent(void) 232 301 { 233 NSS_STATUS (*_nss_endgrent)(void) = find_fn("endgrent"); 234 NSS_STATUS status; 302 NSS_STATUS (*_nss_endgrent)(void) = 303 (NSS_STATUS (*)(void))find_fn("endgrent"); 304 NSS_STATUS status; 305 306 if (!_nss_endgrent) 307 return; 308 235 309 status = _nss_endgrent(); 236 310 if (status != NSS_STATUS_SUCCESS) { … … 243 317 NSS_STATUS (*_nss_initgroups)(char *, gid_t , long int *, 244 318 long int *, gid_t **, long int , int *) = 245 find_fn("initgroups_dyn"); 246 NSS_STATUS status; 247 248 if (!_nss_initgroups) return NSS_STATUS_UNAVAIL; 319 (NSS_STATUS (*)(char *, gid_t, long int *, 320 long int *, gid_t **, 321 long int, int *))find_fn("initgroups_dyn"); 322 NSS_STATUS status; 323 324 if (!_nss_initgroups) 325 return NSS_STATUS_UNAVAIL; 249 326 250 327 status = _nss_initgroups(user, group, start, size, groups, 0, &nss_errno); … … 257 334 static void print_passwd(struct passwd *pwd) 258 335 { 259 printf("%s:%s:% d:%d:%s:%s:%s\n",336 printf("%s:%s:%lu:%lu:%s:%s:%s\n", 260 337 pwd->pw_name, 261 338 pwd->pw_passwd, 262 pwd->pw_uid,263 pwd->pw_gid,339 (unsigned long)pwd->pw_uid, 340 (unsigned long)pwd->pw_gid, 264 341 pwd->pw_gecos, 265 342 pwd->pw_dir, … … 270 347 { 271 348 int i; 272 printf("%s:%s:% d:",349 printf("%s:%s:%lu:", 273 350 grp->gr_name, 274 351 grp->gr_passwd, 275 grp->gr_gid);352 (unsigned long)grp->gr_gid); 276 353 277 354 if (!grp->gr_mem[0]) { … … 281 358 282 359 for (i=0; grp->gr_mem[i+1]; i++) { 283 printf("%s, 360 printf("%s,", grp->gr_mem[i]); 284 361 } 285 362 printf("%s\n", grp->gr_mem[i]); … … 294 371 NSS_STATUS status; 295 372 296 groups = (gid_t *)malloc _array_p(gid_t,size);373 groups = (gid_t *)malloc(size); 297 374 groups[0] = gid; 298 375 … … 304 381 305 382 for (i=0; i<start-1; i++) { 306 printf("% d, ",groups[i]);307 } 308 printf("% d\n",groups[i]);383 printf("%lu, ", (unsigned long)groups[i]); 384 } 385 printf("%lu\n", (unsigned long)groups[i]); 309 386 } 310 387
Note:
See TracChangeset
for help on using the changeset viewer.