Ignore:
Timestamp:
Aug 2, 2010, 8:16:45 PM (15 years ago)
Author:
Silvan Scherrer
Message:

Samba Server 3.5: trunk update to 3.5.4

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/libads/kerberos_verify.c

    r414 r480  
    308308        krb5_error_code ret = 0;
    309309        bool auth_ok = False;
     310        bool cont = true;
    310311        char *password_s = NULL;
    311         krb5_data password;
     312        /* Let's make some room for 2 password (old and new)*/
     313        krb5_data passwords[2];
    312314        krb5_enctype enctypes[] = {
    313315#if defined(ENCTYPE_ARCFOUR_HMAC)
     
    319321        };
    320322        krb5_data packet;
    321         int i;
     323        int i, j;
    322324
    323325        *pp_tkt = NULL;
     
    325327        *perr = 0;
    326328
     329        ZERO_STRUCT(passwords);
    327330
    328331        if (!secrets_init()) {
     
    339342        }
    340343
    341         password.data = password_s;
    342         password.length = strlen(password_s);
     344        passwords[0].data = password_s;
     345        passwords[0].length = strlen(password_s);
     346
     347        password_s = secrets_fetch_prev_machine_password(lp_workgroup());
     348        if (password_s) {
     349                DEBUG(10,("ads_secrets_verify_ticket: found previous password\n"));
     350                passwords[1].data = password_s;
     351                passwords[1].length = strlen(password_s);
     352        }
    343353
    344354        /* CIFS doesn't use addresses in tickets. This would break NAT. JRA */
     
    348358
    349359        /* We need to setup a auth context with each possible encoding type in turn. */
    350         for (i=0;enctypes[i];i++) {
    351                 krb5_keyblock *key = NULL;
    352 
    353                 if (!(key = SMB_MALLOC_P(krb5_keyblock))) {
    354                         ret = ENOMEM;
    355                         goto out;
    356                 }
    357        
    358                 if (create_kerberos_key_from_string(context, host_princ, &password, key, enctypes[i], false)) {
    359                         SAFE_FREE(key);
    360                         continue;
    361                 }
    362 
    363                 krb5_auth_con_setuseruserkey(context, auth_context, key);
    364 
    365                 if (!(ret = krb5_rd_req(context, &auth_context, &packet,
    366                                         NULL,
    367                                         NULL, NULL, pp_tkt))) {
    368                         DEBUG(10,("ads_secrets_verify_ticket: enc type [%u] decrypted message !\n",
    369                                 (unsigned int)enctypes[i] ));
    370                         auth_ok = True;
    371                         krb5_copy_keyblock(context, key, keyblock);
     360        for (j=0; j<2 && passwords[j].length; j++) {
     361
     362                for (i=0;enctypes[i];i++) {
     363                        krb5_keyblock *key = NULL;
     364
     365                        if (!(key = SMB_MALLOC_P(krb5_keyblock))) {
     366                                ret = ENOMEM;
     367                                goto out;
     368                        }
     369
     370                        if (create_kerberos_key_from_string(context, host_princ, &passwords[j], key, enctypes[i], false)) {
     371                                SAFE_FREE(key);
     372                                continue;
     373                        }
     374
     375                        krb5_auth_con_setuseruserkey(context, auth_context, key);
     376
     377                        if (!(ret = krb5_rd_req(context, &auth_context, &packet,
     378                                                NULL,
     379                                                NULL, NULL, pp_tkt))) {
     380                                DEBUG(10,("ads_secrets_verify_ticket: enc type [%u] decrypted message !\n",
     381                                        (unsigned int)enctypes[i] ));
     382                                auth_ok = True;
     383                                cont = false;
     384                                krb5_copy_keyblock(context, key, keyblock);
     385                                krb5_free_keyblock(context, key);
     386                                break;
     387                        }
     388
     389                        DEBUG((ret != KRB5_BAD_ENCTYPE) ? 3 : 10,
     390                                        ("ads_secrets_verify_ticket: enc type [%u] failed to decrypt with error %s\n",
     391                                        (unsigned int)enctypes[i], error_message(ret)));
     392
     393                        /* successfully decrypted but ticket is just not valid at the moment */
     394                        if (ret == KRB5KRB_AP_ERR_TKT_NYV ||
     395                            ret == KRB5KRB_AP_ERR_TKT_EXPIRED ||
     396                            ret == KRB5KRB_AP_ERR_SKEW) {
     397                                krb5_free_keyblock(context, key);
     398                                cont = false;
     399                                break;
     400                        }
     401
    372402                        krb5_free_keyblock(context, key);
     403                }
     404                if (!cont) {
     405                        /* If we found a valid pass then no need to try
     406                         * the next one or we have invalid ticket so no need
     407                         * to try next password*/
    373408                        break;
    374409                }
    375 
    376                 DEBUG((ret != KRB5_BAD_ENCTYPE) ? 3 : 10,
    377                                 ("ads_secrets_verify_ticket: enc type [%u] failed to decrypt with error %s\n",
    378                                 (unsigned int)enctypes[i], error_message(ret)));
    379 
    380                 /* successfully decrypted but ticket is just not valid at the moment */
    381                 if (ret == KRB5KRB_AP_ERR_TKT_NYV ||
    382                     ret == KRB5KRB_AP_ERR_TKT_EXPIRED ||
    383                     ret == KRB5KRB_AP_ERR_SKEW) {
    384                         krb5_free_keyblock(context, key);
    385                         break;
    386                 }
    387 
    388                 krb5_free_keyblock(context, key);
    389 
    390410        }
    391411
    392412 out:
    393         SAFE_FREE(password_s);
     413        SAFE_FREE(passwords[0].data);
     414        SAFE_FREE(passwords[1].data);
    394415        *perr = ret;
    395416        return auth_ok;
Note: See TracChangeset for help on using the changeset viewer.