Changeset 745 for trunk/server/source4/auth/kerberos/kerberos.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/auth/kerberos/kerberos.c
r414 r745 34 34 This version is built to use a keyblock, rather than needing the 35 35 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) 36 40 */ 37 41 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) 40 46 { 41 47 krb5_error_code code = 0; 42 48 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);50 49 51 50 if ((code = krb5_get_init_creds_keyblock(ctx, &my_creds, principal, keyblock, 52 0, NULL,options))) {51 0, target_service, krb_options))) { 53 52 return code; 54 53 } 55 54 56 55 if ((code = krb5_cc_initialize(ctx, cc, principal))) { 57 krb5_get_init_creds_opt_free(ctx, options);58 56 krb5_free_cred_contents(ctx, &my_creds); 59 57 return code; … … 61 59 62 60 if ((code = krb5_cc_store_cred(ctx, cc, &my_creds))) { 63 krb5_get_init_creds_opt_free(ctx, options);64 61 krb5_free_cred_contents(ctx, &my_creds); 65 62 return code; … … 74 71 } 75 72 76 krb5_get_init_creds_opt_free(ctx, options);77 73 krb5_free_cred_contents(ctx, &my_creds); 78 74 … … 83 79 simulate a kinit, putting the tgt in the given credentials cache. 84 80 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 85 86 */ 86 87 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) 89 92 { 90 93 krb5_error_code code = 0; 91 94 krb5_creds my_creds; 92 krb5_get_init_creds_opt *options; 95 krb5_creds *impersonate_creds; 96 krb5_get_creds_opt options; 93 97 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))) { 95 106 return code; 96 107 } 97 108 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 106 109 if ((code = krb5_cc_initialize(ctx, cc, principal))) { 107 krb5_get_init_creds_opt_free(ctx, options);108 110 krb5_free_cred_contents(ctx, &my_creds); 109 111 return code; … … 111 113 112 114 if ((code = krb5_cc_store_cred(ctx, cc, &my_creds))) { 113 krb5_get_init_creds_opt_free(ctx, options);114 115 krb5_free_cred_contents(ctx, &my_creds); 115 116 return code; … … 124 125 } 125 126 126 krb5_get_init_creds_opt_free(ctx, options);127 127 krb5_free_cred_contents(ctx, &my_creds); 128 128 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 129 164 return 0; 130 165 }
Note:
See TracChangeset
for help on using the changeset viewer.