Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/nsswitch/nsstest.c

    r414 r745  
    33   nss tester for winbindd
    44   Copyright (C) Andrew Tridgell 2001
     5   Copyright (C) Tim Potter 2003
    56
    67   This program is free software; you can redistribute it and/or modify
     
    1819*/
    1920
    20 #include "includes.h"
    21 
     21#include "replace.h"
    2222#include "nsswitch/nsstest.h"
    2323
     
    3030static void *find_fn(const char *name)
    3131{
    32         char s[1024];
     32        char *s;
    3333        static void *h;
    3434        void *res;
    3535
    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        }
    3739
    3840        if (!h) {
     
    4648        if (!res) {
    4749                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);
    5055        return res;
    5156}
     
    6267{
    6368        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");
    6572        static struct passwd pwd;
    6673        static char buf[1000];
    6774        NSS_STATUS status;
    6875
     76        if (!_nss_getpwent_r)
     77                return NULL;
     78
    6979        status = _nss_getpwent_r(&pwd, buf, sizeof(buf), &nss_errno);
    7080        if (status == NSS_STATUS_NOTFOUND) {
     
    8191{
    8292        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");
    8496        static struct passwd pwd;
    8597        static char buf[1000];
    8698        NSS_STATUS status;
    8799
     100        if (!_nss_getpwnam_r)
     101                return NULL;
     102
    88103        status = _nss_getpwnam_r(name, &pwd, buf, sizeof(buf), &nss_errno);
    89104        if (status == NSS_STATUS_NOTFOUND) {
     
    100115{
    101116        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");
    103120        static struct passwd pwd;
    104121        static char buf[1000];
    105122        NSS_STATUS status;
    106123
     124        if (!_nss_getpwuid_r)
     125                return NULL;
     126
    107127        status = _nss_getpwuid_r(uid, &pwd, buf, sizeof(buf), &nss_errno);
    108128        if (status == NSS_STATUS_NOTFOUND) {
     
    118138static void nss_setpwent(void)
    119139{
    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
    122147        status = _nss_setpwent();
    123148        if (status != NSS_STATUS_SUCCESS) {
     
    128153static void nss_endpwent(void)
    129154{
    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
    132162        status = _nss_endpwent();
    133163        if (status != NSS_STATUS_SUCCESS) {
     
    140170{
    141171        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");
    143175        static struct group grp;
    144176        static char *buf;
     
    146178        NSS_STATUS status;
    147179
    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);
    149185
    150186again:
     
    152188        if (status == NSS_STATUS_TRYAGAIN) {
    153189                buflen *= 2;
    154                 buf = realloc_p(buf, char, buflen);
     190                buf = (char *)realloc(buf, buflen);
     191                if (!buf) {
     192                        return NULL;
     193                }
    155194                goto again;
    156195        }
    157196        if (status == NSS_STATUS_NOTFOUND) {
     197                free(buf);
    158198                return NULL;
    159199        }
    160200        if (status != NSS_STATUS_SUCCESS) {
    161201                report_nss_error("getgrent", status);
     202                free(buf);
    162203                return NULL;
    163204        }
     
    168209{
    169210        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");
    171214        static struct group grp;
    172215        static char *buf;
     
    174217        NSS_STATUS status;
    175218
    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);
    177224again:
    178225        status = _nss_getgrnam_r(name, &grp, buf, buflen, &nss_errno);
    179226        if (status == NSS_STATUS_TRYAGAIN) {
    180227                buflen *= 2;
    181                 buf = realloc_p(buf, char, buflen);
     228                buf = (char *)realloc(buf, buflen);
     229                if (!buf) {
     230                        return NULL;
     231                }
    182232                goto again;
    183233        }
    184234        if (status == NSS_STATUS_NOTFOUND) {
     235                free(buf);
    185236                return NULL;
    186237        }
    187238        if (status != NSS_STATUS_SUCCESS) {
    188239                report_nss_error("getgrnam", status);
     240                free(buf);
    189241                return NULL;
    190242        }
     
    195247{
    196248        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");
    198252        static struct group grp;
    199253        static char *buf;
     
    201255        NSS_STATUS status;
    202256
    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
    204263again:
    205264        status = _nss_getgrgid_r(gid, &grp, buf, buflen, &nss_errno);
    206265        if (status == NSS_STATUS_TRYAGAIN) {
    207266                buflen *= 2;
    208                 buf = realloc_p(buf, char, buflen);
     267                buf = (char *)realloc(buf, buflen);
     268                if (!buf) {
     269                        return NULL;
     270                }
    209271                goto again;
    210272        }
    211273        if (status == NSS_STATUS_NOTFOUND) {
     274                free(buf);
    212275                return NULL;
    213276        }
    214277        if (status != NSS_STATUS_SUCCESS) {
    215278                report_nss_error("getgrgid", status);
     279                free(buf);
    216280                return NULL;
    217281        }
     
    221285static void nss_setgrent(void)
    222286{
    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
    225294        status = _nss_setgrent();
    226295        if (status != NSS_STATUS_SUCCESS) {
     
    231300static void nss_endgrent(void)
    232301{
    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
    235309        status = _nss_endgrent();
    236310        if (status != NSS_STATUS_SUCCESS) {
     
    243317        NSS_STATUS (*_nss_initgroups)(char *, gid_t , long int *,
    244318                                      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;
    249326
    250327        status = _nss_initgroups(user, group, start, size, groups, 0, &nss_errno);
     
    257334static void print_passwd(struct passwd *pwd)
    258335{
    259         printf("%s:%s:%d:%d:%s:%s:%s\n",
     336        printf("%s:%s:%lu:%lu:%s:%s:%s\n",
    260337               pwd->pw_name,
    261338               pwd->pw_passwd,
    262                pwd->pw_uid,
    263                pwd->pw_gid,
     339               (unsigned long)pwd->pw_uid,
     340               (unsigned long)pwd->pw_gid,
    264341               pwd->pw_gecos,
    265342               pwd->pw_dir,
     
    270347{
    271348        int i;
    272         printf("%s:%s:%d: ",
     349        printf("%s:%s:%lu:",
    273350               grp->gr_name,
    274351               grp->gr_passwd,
    275                grp->gr_gid);
     352               (unsigned long)grp->gr_gid);
    276353
    277354        if (!grp->gr_mem[0]) {
     
    281358
    282359        for (i=0; grp->gr_mem[i+1]; i++) {
    283                 printf("%s, ", grp->gr_mem[i]);
     360                printf("%s,", grp->gr_mem[i]);
    284361        }
    285362        printf("%s\n", grp->gr_mem[i]);
     
    294371        NSS_STATUS status;
    295372
    296         groups = (gid_t *)malloc_array_p(gid_t, size);
     373        groups = (gid_t *)malloc(size);
    297374        groups[0] = gid;
    298375
     
    304381
    305382        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]);
    309386}
    310387
Note: See TracChangeset for help on using the changeset viewer.