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/source4/auth/kerberos/kerberos.c

    r414 r745  
    3434  This version is built to use a keyblock, rather than needing the
    3535  original password.
     36
     37  The impersonate_principal is the principal if NULL, or the principal to impersonate
     38
     39  The target_service defaults to the krbtgt if NULL, but could be kpasswd/realm or the local service (if we are doing s4u2self)
    3640*/
    3741 krb5_error_code kerberos_kinit_keyblock_cc(krb5_context ctx, krb5_ccache cc,
    38                                 krb5_principal principal, krb5_keyblock *keyblock,
    39                                 time_t *expire_time, time_t *kdc_time)
     42                                            krb5_principal principal, krb5_keyblock *keyblock,
     43                                            const char *target_service,
     44                                            krb5_get_init_creds_opt *krb_options,
     45                                            time_t *expire_time, time_t *kdc_time)
    4046{
    4147        krb5_error_code code = 0;
    4248        krb5_creds my_creds;
    43         krb5_get_init_creds_opt *options;
    44 
    45         if ((code = krb5_get_init_creds_opt_alloc(ctx, &options))) {
    46                 return code;
    47         }
    48 
    49         krb5_get_init_creds_opt_set_default_flags(ctx, NULL, NULL, options);
    5049
    5150        if ((code = krb5_get_init_creds_keyblock(ctx, &my_creds, principal, keyblock,
    52                                                  0, NULL, options))) {
     51                                                 0, target_service, krb_options))) {
    5352                return code;
    5453        }
    5554       
    5655        if ((code = krb5_cc_initialize(ctx, cc, principal))) {
    57                 krb5_get_init_creds_opt_free(ctx, options);
    5856                krb5_free_cred_contents(ctx, &my_creds);
    5957                return code;
     
    6159       
    6260        if ((code = krb5_cc_store_cred(ctx, cc, &my_creds))) {
    63                 krb5_get_init_creds_opt_free(ctx, options);
    6461                krb5_free_cred_contents(ctx, &my_creds);
    6562                return code;
     
    7471        }
    7572
    76         krb5_get_init_creds_opt_free(ctx, options);
    7773        krb5_free_cred_contents(ctx, &my_creds);
    7874       
     
    8379  simulate a kinit, putting the tgt in the given credentials cache.
    8480  Orignally by remus@snapserver.com
     81
     82  The impersonate_principal is the principal if NULL, or the principal to impersonate
     83
     84  The target_service defaults to the krbtgt if NULL, but could be kpasswd/realm or the local service (if we are doing s4u2self)
     85
    8586*/
    8687 krb5_error_code kerberos_kinit_password_cc(krb5_context ctx, krb5_ccache cc,
    87                                 krb5_principal principal, const char *password,
    88                                 time_t *expire_time, time_t *kdc_time)
     88                                            krb5_principal principal, const char *password,
     89                                            krb5_principal impersonate_principal, const char *target_service,
     90                                            krb5_get_init_creds_opt *krb_options,
     91                                            time_t *expire_time, time_t *kdc_time)
    8992{
    9093        krb5_error_code code = 0;
    9194        krb5_creds my_creds;
    92         krb5_get_init_creds_opt *options;
     95        krb5_creds *impersonate_creds;
     96        krb5_get_creds_opt options;
    9397
    94         if ((code = krb5_get_init_creds_opt_alloc(ctx, &options))) {
     98        /* If we are not impersonating, then get this ticket for the
     99         * target service, otherwise a krbtgt, and get the next ticket
     100         * for the target */
     101        if ((code = krb5_get_init_creds_password(ctx, &my_creds, principal, password,
     102                                                 NULL, NULL,
     103                                                 0,
     104                                                 impersonate_principal ? NULL : target_service,
     105                                                 krb_options))) {
    95106                return code;
    96107        }
    97108
    98         krb5_get_init_creds_opt_set_default_flags(ctx, NULL, NULL, options);
    99 
    100         if ((code = krb5_get_init_creds_password(ctx, &my_creds, principal, password,
    101                                                  NULL,
    102                                                  NULL, 0, NULL, options))) {
    103                 return code;
    104         }
    105        
    106109        if ((code = krb5_cc_initialize(ctx, cc, principal))) {
    107                 krb5_get_init_creds_opt_free(ctx, options);
    108110                krb5_free_cred_contents(ctx, &my_creds);
    109111                return code;
     
    111113       
    112114        if ((code = krb5_cc_store_cred(ctx, cc, &my_creds))) {
    113                 krb5_get_init_creds_opt_free(ctx, options);
    114115                krb5_free_cred_contents(ctx, &my_creds);
    115116                return code;
     
    124125        }
    125126
    126         krb5_get_init_creds_opt_free(ctx, options);
    127127        krb5_free_cred_contents(ctx, &my_creds);
    128128       
     129        if (code == 0 && impersonate_principal) {
     130                krb5_principal target_princ;
     131                if ((code = krb5_get_creds_opt_alloc(ctx, &options))) {
     132                        return code;
     133                }
     134
     135                if ((code = krb5_get_creds_opt_set_impersonate(ctx, options, impersonate_principal))) {
     136                        krb5_get_creds_opt_free(ctx, options);
     137                        return code;
     138                }
     139
     140                if ((code = krb5_parse_name(ctx, target_service, &target_princ))) {
     141                        krb5_get_creds_opt_free(ctx, options);
     142                        return code;
     143                }
     144
     145                if ((code = krb5_principal_set_realm(ctx, target_princ, krb5_principal_get_realm(ctx, principal)))) {
     146                        krb5_get_creds_opt_free(ctx, options);
     147                        krb5_free_principal(ctx, target_princ);
     148                        return code;
     149                }
     150
     151                if ((code = krb5_get_creds(ctx, options, cc, target_princ, &impersonate_creds))) {
     152                        krb5_free_principal(ctx, target_princ);
     153                        krb5_get_creds_opt_free(ctx, options);
     154                        return code;
     155                }
     156
     157                krb5_free_principal(ctx, target_princ);
     158
     159                code = krb5_cc_store_cred(ctx, cc, impersonate_creds);
     160                krb5_get_creds_opt_free(ctx, options);
     161                krb5_free_creds(ctx, impersonate_creds);
     162        }
     163
    129164        return 0;
    130165}
Note: See TracChangeset for help on using the changeset viewer.