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.c190
1 files changed, 49 insertions, 141 deletions
diff --git a/source3/passdb/secrets.c b/source3/passdb/secrets.c
index 138a9231fd..db08d02714 100644
--- a/source3/passdb/secrets.c
+++ b/source3/passdb/secrets.c
@@ -222,40 +222,25 @@ BOOL secrets_lock_trust_account_password(const char *domain, BOOL dolock)
}
/************************************************************************
- Routine to get the default secure channel type for trust accounts
-************************************************************************/
-
-uint32 get_default_sec_channel(void)
-{
- if (lp_server_role() == ROLE_DOMAIN_BDC ||
- lp_server_role() == ROLE_DOMAIN_PDC) {
- return SEC_CHAN_BDC;
- } else {
- return SEC_CHAN_WKSTA;
- }
-}
-
-/************************************************************************
Routine to get the trust account password for a domain.
The user of this function must have locked the trust password file using
the above call.
************************************************************************/
BOOL secrets_fetch_trust_account_password(const char *domain, uint8 ret_pwd[16],
- time_t *pass_last_set_time,
- uint32 *channel)
+ time_t *pass_last_set_time)
{
struct machine_acct_pass *pass;
char *plaintext;
size_t size;
- plaintext = secrets_fetch_machine_password(domain, pass_last_set_time,
- channel);
+ plaintext = secrets_fetch_machine_password();
if (plaintext) {
/* we have an ADS password - use that */
DEBUG(4,("Using ADS machine password\n"));
E_md4hash(plaintext, ret_pwd);
SAFE_FREE(plaintext);
+ pass_last_set_time = 0;
return True;
}
@@ -272,10 +257,6 @@ BOOL secrets_fetch_trust_account_password(const char *domain, uint8 ret_pwd[16],
if (pass_last_set_time) *pass_last_set_time = pass->mod_time;
memcpy(ret_pwd, pass->hash, 16);
SAFE_FREE(pass);
-
- if (channel)
- *channel = get_default_sec_channel();
-
return True;
}
@@ -284,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;
}
@@ -340,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
@@ -350,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;
@@ -376,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));
}
/************************************************************************
@@ -388,42 +356,14 @@ BOOL secrets_store_trusted_domain_password(const char* domain, smb_ucs2_t *uni_d
the password is assumed to be a null terminated ascii string
************************************************************************/
-BOOL secrets_store_machine_password(const char *pass, const char *domain, uint32 sec_channel)
+BOOL secrets_store_machine_password(const char *pass)
{
- char *key = NULL;
+ char *key;
BOOL ret;
- uint32 last_change_time;
- uint32 sec_channel_type;
-
- asprintf(&key, "%s/%s", SECRETS_MACHINE_PASSWORD, domain);
- if (!key)
- return False;
+ asprintf(&key, "%s/%s", SECRETS_MACHINE_PASSWORD, lp_workgroup());
strupper(key);
-
ret = secrets_store(key, pass, strlen(pass)+1);
- SAFE_FREE(key);
-
- if (!ret)
- return ret;
-
- asprintf(&key, "%s/%s", SECRETS_MACHINE_LAST_CHANGE_TIME, domain);
- if (!key)
- return False;
- strupper(key);
-
- SIVAL(&last_change_time, 0, time(NULL));
- ret = secrets_store(key, &last_change_time, sizeof(last_change_time));
- SAFE_FREE(key);
-
- asprintf(&key, "%s/%s", SECRETS_MACHINE_SEC_CHANNEL_TYPE, domain);
- if (!key)
- return False;
- strupper(key);
-
- SIVAL(&sec_channel_type, 0, sec_channel);
- ret = secrets_store(key, &sec_channel_type, sizeof(sec_channel_type));
- SAFE_FREE(key);
-
+ free(key);
return ret;
}
@@ -432,45 +372,14 @@ BOOL secrets_store_machine_password(const char *pass, const char *domain, uint32
Routine to fetch the plaintext machine account password for a realm
the password is assumed to be a null terminated ascii string
************************************************************************/
-char *secrets_fetch_machine_password(const char *domain,
- time_t *pass_last_set_time,
- uint32 *channel)
+char *secrets_fetch_machine_password(void)
{
- char *key = NULL;
+ char *key;
char *ret;
- asprintf(&key, "%s/%s", SECRETS_MACHINE_PASSWORD, domain);
+ asprintf(&key, "%s/%s", SECRETS_MACHINE_PASSWORD, lp_workgroup());
strupper(key);
ret = (char *)secrets_fetch(key, NULL);
- SAFE_FREE(key);
-
- if (pass_last_set_time) {
- size_t size;
- uint32 *last_set_time;
- asprintf(&key, "%s/%s", SECRETS_MACHINE_LAST_CHANGE_TIME, domain);
- strupper(key);
- last_set_time = secrets_fetch(key, &size);
- if (last_set_time) {
- *pass_last_set_time = IVAL(last_set_time,0);
- } else {
- *pass_last_set_time = 0;
- }
- SAFE_FREE(key);
- }
-
- if (channel) {
- size_t size;
- uint32 *channel_type;
- asprintf(&key, "%s/%s", SECRETS_MACHINE_SEC_CHANNEL_TYPE, domain);
- strupper(key);
- channel_type = secrets_fetch(key, &size);
- if (channel_type) {
- *channel = IVAL(channel_type,0);
- } else {
- *channel = get_default_sec_channel();
- }
- SAFE_FREE(key);
- }
-
+ free(key);
return ret;
}
@@ -566,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;
@@ -597,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;
@@ -608,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)));
@@ -631,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;
}
@@ -664,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));
@@ -687,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);
}
@@ -700,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 ));
}
/*********************************************************
@@ -715,7 +623,7 @@ BOOL must_use_pdc( const char *domain )
time_t last_change_time;
unsigned char passwd[16];
- if ( !secrets_fetch_trust_account_password(domain, passwd, &last_change_time, NULL) )
+ if ( !secrets_fetch_trust_account_password(domain, passwd, &last_change_time) )
return False;
/*