summaryrefslogtreecommitdiff
path: root/source3/passdb/secrets.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/passdb/secrets.c')
-rw-r--r--source3/passdb/secrets.c88
1 files changed, 37 insertions, 51 deletions
diff --git a/source3/passdb/secrets.c b/source3/passdb/secrets.c
index 64fedc7284..db08d02714 100644
--- a/source3/passdb/secrets.c
+++ b/source3/passdb/secrets.c
@@ -265,44 +265,38 @@ 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_buf = secrets_fetch(trustdom_keystr(domain), &size))) {
+ if (!(pass = secrets_fetch(trustdom_keystr(domain), &size))) {
DEBUG(5, ("secrets_fetch failed!\n"));
return False;
}
- /* 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"));
+ if (size != sizeof(*pass)) {
+ DEBUG(0, ("secrets were of incorrect size!\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 */
- sid_copy(sid, &pass.domain_sid);
-
+ memcpy(&sid, &(pass->domain_sid), sizeof(sid));
+
+ SAFE_FREE(pass);
+
return True;
}
@@ -321,7 +315,7 @@ BOOL secrets_store_trust_account_password(const char *domain, uint8 new_pwd[16])
}
/**
- * Routine to store the password for trusted domain
+ * Routine to set the password for trusted domain
*
* @param domain remote domain name
* @param pwd plain text password of trust relationship
@@ -331,17 +325,12 @@ 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)
-{
- /* packing structures */
- pstring pass_buf;
- int pass_len = 0;
- int pass_buf_len = sizeof(pass_buf);
-
+ size_t uni_name_len, const char* pwd,
+ DOM_SID sid)
+{
struct trusted_dom_pass pass;
ZERO_STRUCT(pass);
-
+
/* unicode domain name and its length */
if (!uni_dom_name)
return False;
@@ -357,11 +346,9 @@ BOOL secrets_store_trusted_domain_password(const char* domain, smb_ucs2_t *uni_d
fstrcpy(pass.pass, pwd);
/* domain sid */
- sid_copy(&pass.domain_sid, &sid);
-
- pass_len = tdb_trusted_dom_pass_pack(pass_buf, pass_buf_len, &pass);
+ memcpy(&(pass.domain_sid), &sid, sizeof(sid));
- return secrets_store(trustdom_keystr(domain), (void *)&pass_buf, pass_len);
+ return secrets_store(trustdom_keystr(domain), (void *)&pass, sizeof(pass));
}
/************************************************************************
@@ -488,10 +475,9 @@ 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, packed_size = 0;
+ size_t size;
fstring dom_name;
- char *packed_pass;
- struct trusted_dom_pass *pass = talloc_zero(ctx, sizeof(struct trusted_dom_pass));
+ struct trusted_dom_pass *pass;
NTSTATUS status;
if (!secrets_init()) return NT_STATUS_ACCESS_DENIED;
@@ -519,7 +505,7 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in
*/
status = NT_STATUS_NO_MORE_ENTRIES;
- /* searching for keys in secrets db -- way to go ... */
+ /* searching for keys in sectrets db -- way to go ... */
for (k = keys; k; k = k->next) {
char *secrets_key;
@@ -530,19 +516,14 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in
return NT_STATUS_NO_MEMORY;
}
- packed_pass = secrets_fetch(secrets_key, &size);
- packed_size = tdb_trusted_dom_pass_unpack(packed_pass, size, pass);
-
- if (size != packed_size) {
+ pass = secrets_fetch(secrets_key, &size);
+
+ if (size != sizeof(*pass)) {
DEBUG(2, ("Secrets record %s is invalid!\n", secrets_key));
- if (size) SAFE_FREE(packed_pass);
-
+ SAFE_FREE(pass);
continue;
}
- /* 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)));
@@ -553,6 +534,8 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in
dom = talloc_zero(ctx, sizeof(*dom));
if (!dom) {
/* free returned tdb record */
+ SAFE_FREE(pass);
+
return NT_STATUS_NO_MEMORY;
}
@@ -586,7 +569,10 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in
start_idx, max_num_domains));
}
- idx++;
+ idx++;
+
+ /* free returned tdb record */
+ SAFE_FREE(pass);
}
DEBUG(5, ("secrets_get_trusted_domains: got %d domains\n", *num_domains));
@@ -609,9 +595,9 @@ BOOL secrets_named_mutex(const char *name, unsigned int timeout)
if (!message_init())
return False;
- ret = tdb_lock_bystring(tdb, name, timeout);
- if (ret == 0)
- DEBUG(10,("secrets_named_mutex: got mutex for %s\n", name ));
+ ret = tdb_lock_bystring(tdb, name, timeout);
+ if (ret == 0)
+ DEBUG(10,("secrets_named_mutex: got mutex for %s\n", name ));
return (ret == 0);
}
@@ -622,8 +608,8 @@ BOOL secrets_named_mutex(const char *name, unsigned int timeout)
void secrets_named_mutex_release(const char *name)
{
- tdb_unlock_bystring(tdb, name);
- DEBUG(10,("secrets_named_mutex: released mutex for %s\n", name ));
+ tdb_unlock_bystring(tdb, name);
+ DEBUG(10,("secrets_named_mutex: released mutex for %s\n", name ));
}
/*********************************************************