char *secrets_fetch_machine_password(const char *domain, time_t *pass_last_set_time, enum netr_SchannelType *channel) { char *ret; ret = (char *)secrets_fetch(machine_password_keystr(domain), NULL); if (pass_last_set_time) { size_t size; uint32 *last_set_time; last_set_time = (unsigned int *)secrets_fetch(machine_last_change_time_keystr(domain), &size); if (last_set_time) { *pass_last_set_time = IVAL(last_set_time,0); SAFE_FREE(last_set_time); } else { *pass_last_set_time = 0; } } if (channel) { size_t size; uint32 *channel_type; channel_type = (unsigned int *)secrets_fetch(machine_sec_channel_type_keystr(domain), &size); if (channel_type) { *channel = IVAL(channel_type,0); SAFE_FREE(channel_type); } else { *channel = get_default_sec_channel(); } } return ret; }
enum netr_SchannelType get_sec_channel_type(const char *param) { if (!(param && *param)) { return get_default_sec_channel(); } else { if (strequal(param, "PDC")) { return SEC_CHAN_BDC; } else if (strequal(param, "BDC")) { return SEC_CHAN_BDC; } else if (strequal(param, "MEMBER")) { return SEC_CHAN_WKSTA; #if 0 } else if (strequal(param, "DOMAIN")) { return SEC_CHAN_DOMAIN; #endif } else { return get_default_sec_channel(); } } }
/************************************************************************ 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 *key = NULL; char *ret; asprintf(&key, "%s/%s", SECRETS_MACHINE_PASSWORD, domain); strupper_m(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_m(key); last_set_time = secrets_fetch(key, &size); if (last_set_time) { *pass_last_set_time = IVAL(last_set_time,0); SAFE_FREE(last_set_time); } 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_m(key); channel_type = secrets_fetch(key, &size); if (channel_type) { *channel = IVAL(channel_type,0); SAFE_FREE(channel_type); } else { *channel = get_default_sec_channel(); } SAFE_FREE(key); } return ret; }
bool secrets_fetch_trust_account_password_legacy(const char *domain, uint8 ret_pwd[16], time_t *pass_last_set_time, enum netr_SchannelType *channel) { struct machine_acct_pass *pass; size_t size = 0; if (!(pass = (struct machine_acct_pass *)secrets_fetch( trust_keystr(domain), &size))) { DEBUG(5, ("secrets_fetch failed!\n")); return False; } if (size != sizeof(*pass)) { DEBUG(0, ("secrets were of incorrect size!\n")); SAFE_FREE(pass); return False; } if (pass_last_set_time) { *pass_last_set_time = pass->mod_time; } memcpy(ret_pwd, pass->hash, 16); if (channel) { *channel = get_default_sec_channel(); } /* Test if machine password has expired and needs to be changed */ if (lp_machine_password_timeout()) { if (pass->mod_time > 0 && time(NULL) > (pass->mod_time + (time_t)lp_machine_password_timeout())) { global_machine_password_needs_changing = True; } } SAFE_FREE(pass); return True; }
BOOL secrets_fetch_trust_account_password(const char *domain, uint8 ret_pwd[16], time_t *pass_last_set_time, uint32 *channel) { struct machine_acct_pass *pass; char *plaintext; size_t size; plaintext = secrets_fetch_machine_password(domain, pass_last_set_time, channel); if (plaintext) { DEBUG(4,("Using cleartext machine password\n")); E_md4hash(plaintext, ret_pwd); SAFE_FREE(plaintext); return True; } if (!(pass = secrets_fetch(trust_keystr(domain), &size))) { DEBUG(5, ("secrets_fetch failed!\n")); return False; } if (size != sizeof(*pass)) { DEBUG(0, ("secrets were of incorrect size!\n")); return False; } 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; }