Changeset 988 for vendor/current/source4/kdc/wdc-samba4.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/kdc/wdc-samba4.c
r740 r988 35 35 krb5_error_code ret; 36 36 NTSTATUS nt_status; 37 struct samba_kdc_entry *skdc_entry = 38 talloc_get_type_abort(client->ctx, 39 struct samba_kdc_entry); 37 40 38 41 mem_ctx = talloc_named(client->ctx, 0, "samba_get_pac context"); … … 41 44 } 42 45 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); 44 47 if (!NT_STATUS_IS_OK(nt_status)) { 45 48 talloc_free(mem_ctx); … … 47 50 } 48 51 49 ret = samba_make_krb5_pac(context, pac_blob, pac);52 ret = samba_make_krb5_pac(context, pac_blob, NULL, pac); 50 53 51 54 talloc_free(mem_ctx); … … 57 60 static krb5_error_code samba_wdc_reget_pac(void *priv, krb5_context context, 58 61 const krb5_principal client_principal, 62 const krb5_principal delegated_proxy_principal, 59 63 struct hdb_entry_ex *client, 60 64 struct hdb_entry_ex *server, … … 62 66 krb5_pac *pac) 63 67 { 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); 65 74 TALLOC_CTX *mem_ctx = talloc_named(p, 0, "samba_kdc_reget_pac context"); 66 75 DATA_BLOB *pac_blob; 76 DATA_BLOB *deleg_blob = NULL; 67 77 krb5_error_code ret; 68 78 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; 69 82 70 83 if (!mem_ctx) { … … 73 86 74 87 /* 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)) { 76 89 talloc_free(mem_ctx); 77 90 return EINVAL; … … 81 94 * RODC, then we need to regenerate the PAC - we can't trust 82 95 * 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 84 105 if (client == NULL) { 85 106 return KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN; 86 107 } 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); 88 113 if (!NT_STATUS_IS_OK(nt_status)) { 89 114 talloc_free(mem_ctx); … … 97 122 } 98 123 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 99 136 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); 101 139 if (!NT_STATUS_IS_OK(nt_status)) { 102 140 DEBUG(0, ("Building PAC failed: %s\n", … … 105 143 return EINVAL; 106 144 } 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 108 177 /* We now completely regenerate this pac */ 109 178 krb5_pac_free(context, *pac); 110 179 111 ret = samba_make_krb5_pac(context, pac_blob, pac);180 ret = samba_make_krb5_pac(context, pac_blob, deleg_blob, pac); 112 181 113 182 talloc_free(mem_ctx); … … 133 202 } 134 203 135 if ( nb_name == NULL) {204 if ((nb_name == NULL) || (nb_name[0] == '\0')) { 136 205 return NULL; 137 206 } 138 207 139 208 /* 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'; 143 213 } 144 214 … … 155 225 return kdata; 156 226 } 227 228 /* this function allocates 'data' using malloc. 229 * The caller is responsible for freeing it */ 230 static 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 157 268 158 269 static krb5_error_code samba_wdc_check_client_access(void *priv, … … 213 324 214 325 struct krb5plugin_windc_ftable windc_plugin_table = { 215 .minor_version = KRB5_WINDC_PLUGIN G_MINOR,326 .minor_version = KRB5_WINDC_PLUGIN_MINOR, 216 327 .init = samba_wdc_plugin_init, 217 328 .fini = samba_wdc_plugin_fini,
Note:
See TracChangeset
for help on using the changeset viewer.