From e583dd6278fedf9ad45b551dccf94fbe6c785119 Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Fri, 14 Mar 2003 17:12:40 +0000 Subject: Fresh meat in trusted domains code: - packing/unpacking utility functions for trusted domain password struct; can be used to prepare buffer to store in secrets.tdb or (soon) passdb backend - similiar functions for DOM_SID - respectively modified secrets_(fetch|store) routines - new auth mapping code utilising introduced is_trusted_domain function - added tdb (un)packing of single bytes Rafal (This used to be commit 5281ee7e84421b9be746aed2f1718ceaf2a2fe3d) --- source3/passdb/secrets.c | 77 +++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 30 deletions(-) (limited to 'source3/passdb') diff --git a/source3/passdb/secrets.c b/source3/passdb/secrets.c index 2b944a9941..4b0913a624 100644 --- a/source3/passdb/secrets.c +++ b/source3/passdb/secrets.c @@ -265,38 +265,44 @@ BOOL secrets_fetch_trust_account_password(const char *domain, uint8 ret_pwd[16], ************************************************************************/ BOOL secrets_fetch_trusted_domain_password(const char *domain, char** pwd, - DOM_SID *sid, time_t *pass_last_set_time) + DOM_SID *sid, time_t *pass_last_set_time) { - struct trusted_dom_pass *pass; + struct trusted_dom_pass pass; size_t size; + + /* unpacking structures */ + char* pass_buf; + int pass_len = 0; + + ZERO_STRUCT(pass); /* fetching trusted domain password structure */ - if (!(pass = secrets_fetch(trustdom_keystr(domain), &size))) { + if (!(pass_buf = secrets_fetch(trustdom_keystr(domain), &size))) { DEBUG(5, ("secrets_fetch failed!\n")); return False; } - if (size != sizeof(*pass)) { - DEBUG(0, ("secrets were of incorrect size!\n")); + /* unpack trusted domain password */ + pass_len = tdb_trusted_dom_pass_unpack(pass_buf, size, &pass); + if (pass_len != size) { + DEBUG(5, ("Invalid secrets size. Unpacked data doesn't match trusted_dom_pass structure.\n")); return False; } - + /* the trust's password */ if (pwd) { - *pwd = strdup(pass->pass); + *pwd = strdup(pass.pass); if (!*pwd) { return False; } } /* last change time */ - if (pass_last_set_time) *pass_last_set_time = pass->mod_time; + if (pass_last_set_time) *pass_last_set_time = pass.mod_time; /* domain sid */ - memcpy(&sid, &(pass->domain_sid), sizeof(sid)); - - SAFE_FREE(pass); - + sid_copy(sid, &pass.domain_sid); + return True; } @@ -315,7 +321,7 @@ BOOL secrets_store_trust_account_password(const char *domain, uint8 new_pwd[16]) } /** - * Routine to set the password for trusted domain + * Routine to store the password for trusted domain * * @param domain remote domain name * @param pwd plain text password of trust relationship @@ -325,12 +331,17 @@ BOOL secrets_store_trust_account_password(const char *domain, uint8 new_pwd[16]) **/ BOOL secrets_store_trusted_domain_password(const char* domain, smb_ucs2_t *uni_dom_name, - size_t uni_name_len, const char* pwd, - DOM_SID sid) -{ + size_t uni_name_len, const char* pwd, + DOM_SID sid) +{ + /* packing structures */ + pstring pass_buf; + int pass_len = 0; + int pass_buf_len = sizeof(pass_buf); + struct trusted_dom_pass pass; ZERO_STRUCT(pass); - + /* unicode domain name and its length */ if (!uni_dom_name) return False; @@ -346,9 +357,11 @@ BOOL secrets_store_trusted_domain_password(const char* domain, smb_ucs2_t *uni_d fstrcpy(pass.pass, pwd); /* domain sid */ - memcpy(&(pass.domain_sid), &sid, sizeof(sid)); + sid_copy(&pass.domain_sid, &sid); + + pass_len = tdb_trusted_dom_pass_pack(pass_buf, pass_buf_len, &pass); - return secrets_store(trustdom_keystr(domain), (void *)&pass, sizeof(pass)); + return secrets_store(trustdom_keystr(domain), (void *)&pass_buf, pass_len); } /************************************************************************ @@ -475,9 +488,10 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in char *pattern; unsigned int start_idx; uint32 idx = 0; - size_t size; + size_t size, packed_size = 0; fstring dom_name; - struct trusted_dom_pass *pass; + char *packed_pass; + struct trusted_dom_pass *pass = talloc_zero(ctx, sizeof(struct trusted_dom_pass)); NTSTATUS status; if (!secrets_init()) return NT_STATUS_ACCESS_DENIED; @@ -505,7 +519,7 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in */ status = NT_STATUS_NO_MORE_ENTRIES; - /* searching for keys in sectrets db -- way to go ... */ + /* searching for keys in secrets db -- way to go ... */ for (k = keys; k; k = k->next) { char *secrets_key; @@ -516,14 +530,20 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in return NT_STATUS_NO_MEMORY; } - pass = secrets_fetch(secrets_key, &size); - - if (size != sizeof(*pass)) { + packed_pass = secrets_fetch(secrets_key, &size); + packed_size = tdb_trusted_dom_pass_unpack(packed_pass, size, pass); + + if (size != packed_size) { DEBUG(2, ("Secrets record %s is invalid!\n", secrets_key)); SAFE_FREE(pass); - continue; + if (size) SAFE_FREE(packed_pass); + + return NT_STATUS_UNSUCCESSFUL; } + /* packed representation isn't needed anymore */ + SAFE_FREE(packed_pass); + pull_ucs2_fstring(dom_name, pass->uni_name); DEBUG(18, ("Fetched secret record num %d.\nDomain name: %s, SID: %s\n", idx, dom_name, sid_string_static(&pass->domain_sid))); @@ -569,10 +589,7 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in start_idx, max_num_domains)); } - idx++; - - /* free returned tdb record */ - SAFE_FREE(pass); + idx++; } DEBUG(5, ("secrets_get_trusted_domains: got %d domains\n", *num_domains)); -- cgit