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/libwbclient/wbc_pam.c

    r599 r745  
    2626#include "replace.h"
    2727#include "libwbclient.h"
     28#include "../winbind_client.h"
    2829
    2930/* Authenticate a username/password pair */
     
    4748}
    4849
    49 static wbcErr wbc_create_auth_info(TALLOC_CTX *mem_ctx,
    50                                    const struct winbindd_response *resp,
     50static bool sid_attr_compose(struct wbcSidWithAttr *s,
     51                             const struct wbcDomainSid *d,
     52                             uint32_t rid, uint32_t attr)
     53{
     54        if (d->num_auths >= WBC_MAXSUBAUTHS) {
     55                return false;
     56        }
     57        s->sid = *d;
     58        s->sid.sub_auths[s->sid.num_auths++] = rid;
     59        s->attributes = attr;
     60        return true;
     61}
     62
     63static void wbcAuthUserInfoDestructor(void *ptr)
     64{
     65        struct wbcAuthUserInfo *i = (struct wbcAuthUserInfo *)ptr;
     66        free(i->account_name);
     67        free(i->user_principal);
     68        free(i->full_name);
     69        free(i->domain_name);
     70        free(i->dns_domain_name);
     71        free(i->logon_server);
     72        free(i->logon_script);
     73        free(i->profile_path);
     74        free(i->home_directory);
     75        free(i->home_drive);
     76        free(i->sids);
     77}
     78
     79static wbcErr wbc_create_auth_info(const struct winbindd_response *resp,
    5180                                   struct wbcAuthUserInfo **_i)
    5281{
     
    5887        uint32_t j;
    5988
    60         i = talloc(mem_ctx, struct wbcAuthUserInfo);
     89        i = (struct wbcAuthUserInfo *)wbcAllocateMemory(
     90                1, sizeof(struct wbcAuthUserInfo),
     91                wbcAuthUserInfoDestructor);
    6192        BAIL_ON_PTR_ERROR(i, wbc_status);
    6293
    6394        i->user_flags   = resp->data.auth.info3.user_flgs;
    6495
    65         i->account_name = talloc_strdup(i, resp->data.auth.info3.user_name);
     96        i->account_name = strdup(resp->data.auth.info3.user_name);
    6697        BAIL_ON_PTR_ERROR(i->account_name, wbc_status);
    6798        i->user_principal= NULL;
    68         i->full_name    = talloc_strdup(i, resp->data.auth.info3.full_name);
     99        i->full_name    = strdup(resp->data.auth.info3.full_name);
    69100        BAIL_ON_PTR_ERROR(i->full_name, wbc_status);
    70         i->domain_name  = talloc_strdup(i, resp->data.auth.info3.logon_dom);
     101        i->domain_name  = strdup(resp->data.auth.info3.logon_dom);
    71102        BAIL_ON_PTR_ERROR(i->domain_name, wbc_status);
    72103        i->dns_domain_name= NULL;
     
    90121        i->pass_must_change_time= resp->data.auth.info3.pass_must_change_time;
    91122
    92         i->logon_server = talloc_strdup(i, resp->data.auth.info3.logon_srv);
     123        i->logon_server = strdup(resp->data.auth.info3.logon_srv);
    93124        BAIL_ON_PTR_ERROR(i->logon_server, wbc_status);
    94         i->logon_script = talloc_strdup(i, resp->data.auth.info3.logon_script);
     125        i->logon_script = strdup(resp->data.auth.info3.logon_script);
    95126        BAIL_ON_PTR_ERROR(i->logon_script, wbc_status);
    96         i->profile_path = talloc_strdup(i, resp->data.auth.info3.profile_path);
     127        i->profile_path = strdup(resp->data.auth.info3.profile_path);
    97128        BAIL_ON_PTR_ERROR(i->profile_path, wbc_status);
    98         i->home_directory= talloc_strdup(i, resp->data.auth.info3.home_dir);
     129        i->home_directory= strdup(resp->data.auth.info3.home_dir);
    99130        BAIL_ON_PTR_ERROR(i->home_directory, wbc_status);
    100         i->home_drive   = talloc_strdup(i, resp->data.auth.info3.dir_drive);
     131        i->home_drive   = strdup(resp->data.auth.info3.dir_drive);
    101132        BAIL_ON_PTR_ERROR(i->home_drive, wbc_status);
    102133
     
    105136        i->num_sids     += resp->data.auth.info3.num_other_sids;
    106137
    107         i->sids = talloc_array(i, struct wbcSidWithAttr, i->num_sids);
     138        i->sids = (struct wbcSidWithAttr *)calloc(
     139                sizeof(struct wbcSidWithAttr), i->num_sids);
    108140        BAIL_ON_PTR_ERROR(i->sids, wbc_status);
    109141
     
    112144        BAIL_ON_WBC_ERROR(wbc_status);
    113145
    114 #define _SID_COMPOSE(s, d, r, a) { \
    115         (s).sid = d; \
    116         if ((s).sid.num_auths < WBC_MAXSUBAUTHS) { \
    117                 (s).sid.sub_auths[(s).sid.num_auths++] = r; \
    118         } else { \
    119                 wbc_status = WBC_ERR_INVALID_SID; \
    120                 BAIL_ON_WBC_ERROR(wbc_status); \
    121         } \
    122         (s).attributes = a; \
    123 } while (0)
    124 
    125146        sn = 0;
    126         _SID_COMPOSE(i->sids[sn], domain_sid,
    127                      resp->data.auth.info3.user_rid,
    128                      0);
     147        if (!sid_attr_compose(&i->sids[sn], &domain_sid,
     148                              resp->data.auth.info3.user_rid, 0)) {
     149                wbc_status = WBC_ERR_INVALID_SID;
     150                goto done;
     151        }
    129152        sn++;
    130         _SID_COMPOSE(i->sids[sn], domain_sid,
    131                      resp->data.auth.info3.group_rid,
    132                      0);
     153        if (!sid_attr_compose(&i->sids[sn], &domain_sid,
     154                              resp->data.auth.info3.group_rid, 0)) {
     155                wbc_status = WBC_ERR_INVALID_SID;
     156                goto done;
     157        }
    133158        sn++;
    134159
     
    158183                }
    159184
    160                 _SID_COMPOSE(i->sids[sn], domain_sid,
    161                              rid, attrs);
     185                if (!sid_attr_compose(&i->sids[sn], &domain_sid,
     186                                      rid, attrs)) {
     187                        wbc_status = WBC_ERR_INVALID_SID;
     188                        goto done;
     189                }
    162190                sn++;
    163191        }
     
    203231        i = NULL;
    204232done:
    205         talloc_free(i);
    206         return wbc_status;
    207 }
    208 
    209 static wbcErr wbc_create_error_info(TALLOC_CTX *mem_ctx,
    210                                   const struct winbindd_response *resp,
    211                                   struct wbcAuthErrorInfo **_e)
     233        wbcFreeMemory(i);
     234        return wbc_status;
     235}
     236
     237static void wbcAuthErrorInfoDestructor(void *ptr)
     238{
     239        struct wbcAuthErrorInfo *e = (struct wbcAuthErrorInfo *)ptr;
     240        free(e->nt_string);
     241        free(e->display_string);
     242}
     243
     244static wbcErr wbc_create_error_info(const struct winbindd_response *resp,
     245                                    struct wbcAuthErrorInfo **_e)
    212246{
    213247        wbcErr wbc_status = WBC_ERR_SUCCESS;
    214248        struct wbcAuthErrorInfo *e;
    215249
    216         e = talloc(mem_ctx, struct wbcAuthErrorInfo);
     250        e = (struct wbcAuthErrorInfo *)wbcAllocateMemory(
     251                1, sizeof(struct wbcAuthErrorInfo),
     252                wbcAuthErrorInfoDestructor);
    217253        BAIL_ON_PTR_ERROR(e, wbc_status);
    218254
    219255        e->nt_status = resp->data.auth.nt_status;
    220256        e->pam_error = resp->data.auth.pam_error;
    221         e->nt_string = talloc_strdup(e, resp->data.auth.nt_status_string);
     257        e->nt_string = strdup(resp->data.auth.nt_status_string);
    222258        BAIL_ON_PTR_ERROR(e->nt_string, wbc_status);
    223259
    224         e->display_string = talloc_strdup(e, resp->data.auth.error_string);
     260        e->display_string = strdup(resp->data.auth.error_string);
    225261        BAIL_ON_PTR_ERROR(e->display_string, wbc_status);
    226262
     
    229265
    230266done:
    231         talloc_free(e);
    232         return wbc_status;
    233 }
    234 
    235 static wbcErr wbc_create_password_policy_info(TALLOC_CTX *mem_ctx,
    236                                               const struct winbindd_response *resp,
     267        wbcFreeMemory(e);
     268        return wbc_status;
     269}
     270
     271static wbcErr wbc_create_password_policy_info(const struct winbindd_response *resp,
    237272                                              struct wbcUserPasswordPolicyInfo **_i)
    238273{
     
    240275        struct wbcUserPasswordPolicyInfo *i;
    241276
    242         i = talloc(mem_ctx, struct wbcUserPasswordPolicyInfo);
     277        i = (struct wbcUserPasswordPolicyInfo *)wbcAllocateMemory(
     278                1, sizeof(struct wbcUserPasswordPolicyInfo), NULL);
    243279        BAIL_ON_PTR_ERROR(i, wbc_status);
    244280
     
    253289
    254290done:
    255         talloc_free(i);
    256         return wbc_status;
    257 }
    258 
    259 static wbcErr wbc_create_logon_info(TALLOC_CTX *mem_ctx,
    260                                     struct winbindd_response *resp,
     291        wbcFreeMemory(i);
     292        return wbc_status;
     293}
     294
     295static void wbcLogonUserInfoDestructor(void *ptr)
     296{
     297        struct wbcLogonUserInfo *i = (struct wbcLogonUserInfo *)ptr;
     298        wbcFreeMemory(i->info);
     299        wbcFreeMemory(i->blobs);
     300}
     301
     302static wbcErr wbc_create_logon_info(struct winbindd_response *resp,
    261303                                    struct wbcLogonUserInfo **_i)
    262304{
     
    264306        struct wbcLogonUserInfo *i;
    265307
    266         i = talloc_zero(mem_ctx, struct wbcLogonUserInfo);
     308        i = (struct wbcLogonUserInfo *)wbcAllocateMemory(
     309                1, sizeof(struct wbcLogonUserInfo),
     310                wbcLogonUserInfoDestructor);
    267311        BAIL_ON_PTR_ERROR(i, wbc_status);
    268312
    269         wbc_status = wbc_create_auth_info(i, resp, &i->info);
     313        wbc_status = wbc_create_auth_info(resp, &i->info);
    270314        BAIL_ON_WBC_ERROR(wbc_status);
    271315
    272         if (resp->data.auth.krb5ccname &&
    273             strlen(resp->data.auth.krb5ccname)) {
     316        if (resp->data.auth.krb5ccname[0] != '\0') {
    274317                wbc_status = wbcAddNamedBlob(&i->num_blobs,
    275318                                             &i->blobs,
     
    281324        }
    282325
    283         if (resp->data.auth.unix_username &&
    284             strlen(resp->data.auth.unix_username)) {
     326        if (resp->data.auth.unix_username[0] != '\0') {
    285327                wbc_status = wbcAddNamedBlob(&i->num_blobs,
    286328                                             &i->blobs,
     
    295337        i = NULL;
    296338done:
    297         if (!WBC_ERROR_IS_OK(wbc_status) && i) {
    298                 wbcFreeMemory(i->blobs);
    299         }
    300 
    301         talloc_free(i);
    302         return wbc_status;
    303 }
     339        wbcFreeMemory(i);
     340        return wbc_status;
     341}
     342
    304343
    305344/* Authenticate with more detailed information */
     
    437476                        request.flags |= WBFLAG_BIG_NTLMV2_BLOB;
    438477                        request.extra_len = params->password.response.nt_length;
    439                         request.extra_data.data = talloc_zero_array(NULL, char, request.extra_len);
     478                        request.extra_data.data = (char *)malloc(
     479                                request.extra_len);
    440480                        if (request.extra_data.data == NULL) {
    441481                                wbc_status = WBC_ERR_NO_MEMORY;
     
    471511        if (response.data.auth.nt_status != 0) {
    472512                if (error) {
    473                         wbc_status = wbc_create_error_info(NULL,
    474                                                            &response,
     513                        wbc_status = wbc_create_error_info(&response,
    475514                                                           error);
    476515                        BAIL_ON_WBC_ERROR(wbc_status);
     
    483522
    484523        if (info) {
    485                 wbc_status = wbc_create_auth_info(NULL,
    486                                                   &response,
    487                                                   info);
     524                wbc_status = wbc_create_auth_info(&response, info);
    488525                BAIL_ON_WBC_ERROR(wbc_status);
    489526        }
    490527
    491528done:
    492         if (response.extra_data.data)
    493                 free(response.extra_data.data);
    494 
    495         talloc_free(request.extra_data.data);
     529        winbindd_free_response(&response);
     530
     531        free(request.extra_data.data);
    496532
    497533        return wbc_status;
     
    520556        if (response.data.auth.nt_status != 0) {
    521557                if (error) {
    522                         wbc_status = wbc_create_error_info(NULL,
    523                                                            &response,
     558                        wbc_status = wbc_create_error_info(&response,
    524559                                                           error);
    525560                        BAIL_ON_WBC_ERROR(wbc_status);
     
    557592        if (response.data.auth.nt_status != 0) {
    558593                if (error) {
    559                         wbc_status = wbc_create_error_info(NULL,
    560                                                            &response,
     594                        wbc_status = wbc_create_error_info(&response,
    561595                                                           error);
    562596                        BAIL_ON_WBC_ERROR(wbc_status);
     
    601635        if (response.data.auth.nt_status != 0) {
    602636                if (error) {
    603                         wbc_status = wbc_create_error_info(NULL,
    604                                                            &response,
     637                        wbc_status = wbc_create_error_info(&response,
    605638                                                           error);
    606639                        BAIL_ON_WBC_ERROR(wbc_status);
     
    688721        if (response.data.auth.nt_status != 0) {
    689722                if (error) {
    690                         wbc_status = wbc_create_error_info(NULL,
    691                                                            &response,
     723                        wbc_status = wbc_create_error_info(&response,
    692724                                                           error);
    693725                        BAIL_ON_WBC_ERROR(wbc_status);
     
    758790        if (!params->account_name) {
    759791                wbc_status = WBC_ERR_INVALID_PARAM;
    760                 BAIL_ON_WBC_ERROR(wbc_status);
     792                goto done;
    761793        }
    762794
     
    782814                if (!params->account_name) {
    783815                        wbc_status = WBC_ERR_INVALID_PARAM;
    784                         BAIL_ON_WBC_ERROR(wbc_status);
     816                        goto done;
    785817                }
    786818
     
    806838                if (!params->account_name || !params->domain_name) {
    807839                        wbc_status = WBC_ERR_INVALID_PARAM;
    808                         BAIL_ON_WBC_ERROR(wbc_status);
     840                        goto done;
    809841                }
    810842
     
    812844                    !params->old_password.response.old_lm_hash_enc_data) {
    813845                        wbc_status = WBC_ERR_INVALID_PARAM;
    814                         BAIL_ON_WBC_ERROR(wbc_status);
     846                        goto done;
    815847                }
    816848
     
    818850                    params->old_password.response.old_lm_hash_enc_data) {
    819851                        wbc_status = WBC_ERR_INVALID_PARAM;
    820                         BAIL_ON_WBC_ERROR(wbc_status);
     852                        goto done;
    821853                }
    822854
     
    824856                    !params->old_password.response.old_nt_hash_enc_data) {
    825857                        wbc_status = WBC_ERR_INVALID_PARAM;
    826                         BAIL_ON_WBC_ERROR(wbc_status);
     858                        goto done;
    827859                }
    828860
     
    830862                    params->old_password.response.old_nt_hash_enc_data) {
    831863                        wbc_status = WBC_ERR_INVALID_PARAM;
    832                         BAIL_ON_WBC_ERROR(wbc_status);
     864                        goto done;
    833865                }
    834866
     
    836868                    !params->new_password.response.lm_data) {
    837869                        wbc_status = WBC_ERR_INVALID_PARAM;
    838                         BAIL_ON_WBC_ERROR(wbc_status);
     870                        goto done;
    839871                }
    840872
     
    842874                    params->new_password.response.lm_data) {
    843875                        wbc_status = WBC_ERR_INVALID_PARAM;
    844                         BAIL_ON_WBC_ERROR(wbc_status);
     876                        goto done;
    845877                }
    846878
     
    848880                    !params->new_password.response.nt_data) {
    849881                        wbc_status = WBC_ERR_INVALID_PARAM;
    850                         BAIL_ON_WBC_ERROR(wbc_status);
     882                        goto done;
    851883                }
    852884
     
    854886                    params->new_password.response.nt_data) {
    855887                        wbc_status = WBC_ERR_INVALID_PARAM;
    856                         BAIL_ON_WBC_ERROR(wbc_status);
     888                        goto done;
    857889                }
    858890
     
    900932        default:
    901933                wbc_status = WBC_ERR_INVALID_PARAM;
    902                 BAIL_ON_WBC_ERROR(wbc_status);
     934                goto done;
    903935                break;
    904936        }
     
    917949        if (response.data.auth.nt_status != 0) {
    918950                if (error) {
    919                         wbc_status = wbc_create_error_info(NULL,
    920                                                            &response,
     951                        wbc_status = wbc_create_error_info(&response,
    921952                                                           error);
    922953                        BAIL_ON_WBC_ERROR(wbc_status);
     
    926957
    927958        if (policy) {
    928                 wbc_status = wbc_create_password_policy_info(NULL,
    929                                                              &response,
     959                wbc_status = wbc_create_password_policy_info(&response,
    930960                                                             policy);
    931961                BAIL_ON_WBC_ERROR(wbc_status);
     
    9751005{
    9761006        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    977         int cmd = 0;
    9781007        struct winbindd_request request;
    9791008        struct winbindd_response response;
     
    10141043        /* Initialize request */
    10151044
    1016         cmd = WINBINDD_PAM_AUTH;
    10171045        request.flags = WBFLAG_PAM_INFO3_TEXT |
    10181046                        WBFLAG_PAM_USER_SESSION_KEY |
     
    10761104        }
    10771105
    1078         wbc_status = wbcRequestResponse(cmd,
     1106        wbc_status = wbcRequestResponse(WINBINDD_PAM_AUTH,
    10791107                                        &request,
    10801108                                        &response);
     
    10821110        if (response.data.auth.nt_status != 0) {
    10831111                if (error) {
    1084                         wbc_status = wbc_create_error_info(NULL,
    1085                                                            &response,
     1112                        wbc_status = wbc_create_error_info(&response,
    10861113                                                           error);
    10871114                        BAIL_ON_WBC_ERROR(wbc_status);
     
    10941121
    10951122        if (info) {
    1096                 wbc_status = wbc_create_logon_info(NULL,
    1097                                                    &response,
     1123                wbc_status = wbc_create_logon_info(&response,
    10981124                                                   info);
    10991125                BAIL_ON_WBC_ERROR(wbc_status);
     
    11011127
    11021128        if (policy) {
    1103                 wbc_status = wbc_create_password_policy_info(NULL,
    1104                                                              &response,
     1129                wbc_status = wbc_create_password_policy_info(&response,
    11051130                                                             policy);
    11061131                BAIL_ON_WBC_ERROR(wbc_status);
     
    11081133
    11091134done:
    1110         if (response.extra_data.data)
    1111                 free(response.extra_data.data);
    1112 
    1113         return wbc_status;
     1135        winbindd_free_response(&response);
     1136
     1137        return wbc_status;
     1138}
     1139
     1140static void wbcCredentialCacheInfoDestructor(void *ptr)
     1141{
     1142        struct wbcCredentialCacheInfo *i =
     1143                (struct wbcCredentialCacheInfo *)ptr;
     1144        wbcFreeMemory(i->blobs);
    11141145}
    11151146
     
    11871218
    11881219        if (request.extra_len != 0) {
    1189                 request.extra_data.data = talloc_array(
    1190                         NULL, char, request.extra_len);
     1220                request.extra_data.data = (char *)malloc(request.extra_len);
    11911221                if (request.extra_data.data == NULL) {
    11921222                        status = WBC_ERR_NO_MEMORY;
     
    12111241        }
    12121242
    1213         result = talloc(NULL, struct wbcCredentialCacheInfo);
     1243        result = (struct wbcCredentialCacheInfo *)wbcAllocateMemory(
     1244                1, sizeof(struct wbcCredentialCacheInfo),
     1245                wbcCredentialCacheInfoDestructor);
    12141246        if (result == NULL) {
    12151247                status = WBC_ERR_NO_MEMORY;
     
    12171249        }
    12181250        result->num_blobs = 0;
    1219         result->blobs = talloc(result, struct wbcNamedBlob);
    1220         if (result->blobs == NULL) {
    1221                 status = WBC_ERR_NO_MEMORY;
    1222                 goto fail;
    1223         }
     1251        result->blobs = NULL;
    12241252        status = wbcAddNamedBlob(&result->num_blobs, &result->blobs,
    12251253                                 "auth_blob", 0,
     
    12371265        }
    12381266
    1239         if (response.extra_data.data)
    1240                 free(response.extra_data.data);
    12411267        *info = result;
    1242         return WBC_ERR_SUCCESS;
    1243 
     1268        result = NULL;
     1269        status = WBC_ERR_SUCCESS;
    12441270fail:
    1245         TALLOC_FREE(request.extra_data.data);
    1246         if (response.extra_data.data)
    1247                 free(response.extra_data.data);
    1248         talloc_free(result);
     1271        free(request.extra_data.data);
     1272        winbindd_free_response(&response);
     1273        wbcFreeMemory(result);
    12491274        return status;
    12501275}
Note: See TracChangeset for help on using the changeset viewer.