summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2007-12-11 16:32:38 +0100
committerMichael Adam <obnox@samba.org>2007-12-13 10:15:20 +0100
commit13e0e4bdf25d00bdf021851d4f5a9e906212c357 (patch)
tree4ad2d59e0753e2b3f09274d3c920da0e6e6424c3 /source3
parenta493c7baac311e9ac0a560e4412d07df150f4407 (diff)
downloadsamba-13e0e4bdf25d00bdf021851d4f5a9e906212c357.tar.gz
samba-13e0e4bdf25d00bdf021851d4f5a9e906212c357.tar.bz2
samba-13e0e4bdf25d00bdf021851d4f5a9e906212c357.zip
Refactor out assembling of trust creds (pw, account name, principal).
Michael (This used to be commit 481f18b20d6d5ee12c62120a3559bb16cc98e465)
Diffstat (limited to 'source3')
-rw-r--r--source3/winbindd/winbindd_cm.c55
1 files changed, 38 insertions, 17 deletions
diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c
index 00d9092dc3..cc7a0cc671 100644
--- a/source3/winbindd/winbindd_cm.c
+++ b/source3/winbindd/winbindd_cm.c
@@ -635,6 +635,40 @@ static bool get_dc_name_via_netlogon(const struct winbindd_domain *domain,
return True;
}
+/**
+ * Helper function to assemble trust password and account name
+ */
+static NTSTATUS get_trust_creds(const struct winbindd_domain *domain,
+ char **machine_password,
+ char **machine_account,
+ char **machine_krb5_principal)
+{
+ const char *account_name;
+
+ if (!get_trust_pw_clear(domain->name, machine_password,
+ &account_name, NULL))
+ {
+ return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
+ }
+
+ if ((machine_account != NULL) &&
+ (asprintf(machine_account, "%s$", account_name) == -1))
+ {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ /* this is at least correct when domain is our domain,
+ * which is the only case, when this is currently used: */
+ if ((machine_krb5_principal != NULL) &&
+ (asprintf(machine_krb5_principal, "%s$@%s", account_name,
+ domain->alt_name) == -1))
+ {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ return NT_STATUS_OK;
+}
+
/************************************************************************
Given a fd with a just-connected TCP connection to a DC, open a connection
to the pipe.
@@ -649,7 +683,6 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
char *machine_password = NULL;
char *machine_krb5_principal = NULL;
char *machine_account = NULL;
- const char *account_name = NULL;
char *ipc_username = NULL;
char *ipc_domain = NULL;
char *ipc_password = NULL;
@@ -729,22 +762,10 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
{
ADS_STATUS ads_status;
- if (!get_trust_pw_clear(domain->name, &machine_password,
- &account_name, NULL))
- {
- result = NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
- goto done;
- }
-
- if (asprintf(&machine_account, "%s$", account_name) == -1) {
- result = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- if (asprintf(&machine_krb5_principal, "%s$@%s", account_name,
- lp_realm()) == -1)
- {
- result = NT_STATUS_NO_MEMORY;
+ result = get_trust_creds(domain, &machine_password,
+ &machine_account,
+ &machine_krb5_principal);
+ if (!NT_STATUS_IS_OK(result)) {
goto done;
}