Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/kdc/wdc-samba4.c

    r740 r988  
    3535        krb5_error_code ret;
    3636        NTSTATUS nt_status;
     37        struct samba_kdc_entry *skdc_entry =
     38                talloc_get_type_abort(client->ctx,
     39                struct samba_kdc_entry);
    3740
    3841        mem_ctx = talloc_named(client->ctx, 0, "samba_get_pac context");
     
    4144        }
    4245
    43         nt_status = samba_kdc_get_pac_blob(mem_ctx, client, &pac_blob);
     46        nt_status = samba_kdc_get_pac_blob(mem_ctx, skdc_entry, &pac_blob);
    4447        if (!NT_STATUS_IS_OK(nt_status)) {
    4548                talloc_free(mem_ctx);
     
    4750        }
    4851
    49         ret = samba_make_krb5_pac(context, pac_blob, pac);
     52        ret = samba_make_krb5_pac(context, pac_blob, NULL, pac);
    5053
    5154        talloc_free(mem_ctx);
     
    5760static krb5_error_code samba_wdc_reget_pac(void *priv, krb5_context context,
    5861                                           const krb5_principal client_principal,
     62                                           const krb5_principal delegated_proxy_principal,
    5963                                           struct hdb_entry_ex *client,
    6064                                           struct hdb_entry_ex *server,
     
    6266                                           krb5_pac *pac)
    6367{
    64         struct samba_kdc_entry *p = talloc_get_type(server->ctx, struct samba_kdc_entry);
     68        struct samba_kdc_entry *p =
     69                talloc_get_type_abort(server->ctx,
     70                struct samba_kdc_entry);
     71        struct samba_kdc_entry *krbtgt_skdc_entry =
     72                talloc_get_type_abort(krbtgt->ctx,
     73                struct samba_kdc_entry);
    6574        TALLOC_CTX *mem_ctx = talloc_named(p, 0, "samba_kdc_reget_pac context");
    6675        DATA_BLOB *pac_blob;
     76        DATA_BLOB *deleg_blob = NULL;
    6777        krb5_error_code ret;
    6878        NTSTATUS nt_status;
     79        struct PAC_SIGNATURE_DATA *pac_srv_sig;
     80        struct PAC_SIGNATURE_DATA *pac_kdc_sig;
     81        bool is_in_db, is_untrusted;
    6982
    7083        if (!mem_ctx) {
     
    7386
    7487        /* The user account may be set not to want the PAC */
    75         if (!samba_princ_needs_pac(server)) {
     88        if (!samba_princ_needs_pac(p)) {
    7689                talloc_free(mem_ctx);
    7790                return EINVAL;
     
    8194         * RODC, then we need to regenerate the PAC - we can't trust
    8295         * it */
    83         if (samba_krbtgt_was_untrusted_rodc(krbtgt)) {
     96        ret = samba_krbtgt_is_in_db(krbtgt_skdc_entry, &is_in_db, &is_untrusted);
     97        if (ret != 0) {
     98                talloc_free(mem_ctx);
     99                return ret;
     100        }
     101
     102        if (is_untrusted) {
     103                struct samba_kdc_entry *client_skdc_entry = NULL;
     104
    84105                if (client == NULL) {
    85106                        return KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN;
    86107                }
    87                 nt_status = samba_kdc_get_pac_blob(mem_ctx, client, &pac_blob);
     108
     109                client_skdc_entry = talloc_get_type_abort(client->ctx,
     110                                                          struct samba_kdc_entry);
     111
     112                nt_status = samba_kdc_get_pac_blob(mem_ctx, client_skdc_entry, &pac_blob);
    88113                if (!NT_STATUS_IS_OK(nt_status)) {
    89114                        talloc_free(mem_ctx);
     
    97122                }
    98123
     124                pac_srv_sig = talloc_zero(mem_ctx, struct PAC_SIGNATURE_DATA);
     125                if (!pac_srv_sig) {
     126                        talloc_free(mem_ctx);
     127                        return ENOMEM;
     128                }
     129
     130                pac_kdc_sig = talloc_zero(mem_ctx, struct PAC_SIGNATURE_DATA);
     131                if (!pac_kdc_sig) {
     132                        talloc_free(mem_ctx);
     133                        return ENOMEM;
     134                }
     135
    99136                nt_status = samba_kdc_update_pac_blob(mem_ctx, context,
    100                                                       pac, pac_blob);
     137                                                      *pac, pac_blob,
     138                                                      pac_srv_sig, pac_kdc_sig);
    101139                if (!NT_STATUS_IS_OK(nt_status)) {
    102140                        DEBUG(0, ("Building PAC failed: %s\n",
     
    105143                        return EINVAL;
    106144                }
    107         }
     145               
     146                if (is_in_db) {
     147                        /* Now check the KDC signature, fetching the correct key based on the enc type */
     148                        ret = kdc_check_pac(context, pac_srv_sig->signature, pac_kdc_sig, krbtgt);
     149                        if (ret != 0) {
     150                                DEBUG(1, ("PAC KDC signature failed to verify\n"));
     151                                talloc_free(mem_ctx);
     152                                return ret;
     153                        }
     154                }
     155        }
     156
     157        if (delegated_proxy_principal) {
     158                deleg_blob = talloc_zero(mem_ctx, DATA_BLOB);
     159                if (!deleg_blob) {
     160                        talloc_free(mem_ctx);
     161                        return ENOMEM;
     162                }
     163
     164                nt_status = samba_kdc_update_delegation_info_blob(mem_ctx,
     165                                        context, *pac,
     166                                        server->entry.principal,
     167                                        delegated_proxy_principal,
     168                                        deleg_blob);
     169                if (!NT_STATUS_IS_OK(nt_status)) {
     170                        DEBUG(0, ("Building PAC failed: %s\n",
     171                                  nt_errstr(nt_status)));
     172                        talloc_free(mem_ctx);
     173                        return EINVAL;
     174                }
     175        }
     176
    108177        /* We now completely regenerate this pac */
    109178        krb5_pac_free(context, *pac);
    110179
    111         ret = samba_make_krb5_pac(context, pac_blob, pac);
     180        ret = samba_make_krb5_pac(context, pac_blob, deleg_blob, pac);
    112181
    113182        talloc_free(mem_ctx);
     
    133202        }
    134203
    135         if (nb_name == NULL) {
     204        if ((nb_name == NULL) || (nb_name[0] == '\0')) {
    136205                return NULL;
    137206        }
    138207
    139208        /* Strip space padding */
    140         i = strlen(nb_name) - 1;
    141         while (i > 0 && nb_name[i] == ' ') {
    142                 nb_name[i] = '\0';
     209        for (len = strlen(nb_name) - 1;
     210             (len > 0) && (nb_name[len] == ' ');
     211             --len) {
     212                nb_name[len] = '\0';
    143213        }
    144214
     
    155225        return kdata;
    156226}
     227
     228/* this function allocates 'data' using malloc.
     229 * The caller is responsible for freeing it */
     230static void samba_kdc_build_edata_reply(NTSTATUS nt_status, DATA_BLOB *e_data)
     231{
     232        krb5_error_code ret = 0;
     233        PA_DATA pa;
     234        unsigned char *buf;
     235        size_t len;
     236
     237        if (!e_data)
     238                return;
     239
     240        e_data->data   = NULL;
     241        e_data->length = 0;
     242
     243        pa.padata_type          = KRB5_PADATA_PW_SALT;
     244        pa.padata_value.length  = 12;
     245        pa.padata_value.data    = malloc(pa.padata_value.length);
     246        if (!pa.padata_value.data) {
     247                e_data->length = 0;
     248                e_data->data = NULL;
     249                return;
     250        }
     251
     252        SIVAL(pa.padata_value.data, 0, NT_STATUS_V(nt_status));
     253        SIVAL(pa.padata_value.data, 4, 0);
     254        SIVAL(pa.padata_value.data, 8, 1);
     255
     256        ASN1_MALLOC_ENCODE(PA_DATA, buf, len, &pa, &len, ret);
     257        free(pa.padata_value.data);
     258        if (ret) {
     259                return;
     260        }
     261
     262        e_data->data   = buf;
     263        e_data->length = len;
     264
     265        return;
     266}
     267
    157268
    158269static krb5_error_code samba_wdc_check_client_access(void *priv,
     
    213324
    214325struct krb5plugin_windc_ftable windc_plugin_table = {
    215         .minor_version = KRB5_WINDC_PLUGING_MINOR,
     326        .minor_version = KRB5_WINDC_PLUGIN_MINOR,
    216327        .init = samba_wdc_plugin_init,
    217328        .fini = samba_wdc_plugin_fini,
Note: See TracChangeset for help on using the changeset viewer.