diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c index b9da77c6b84..20ab858e67b 100644 --- a/auth/credentials/credentials.c +++ b/auth/credentials/credentials.c @@ -738,6 +738,28 @@ _PUBLIC_ const char *cli_credentials_get_domain(struct cli_credentials *cred) return cred->domain; } +/** + * @brief Obtain the domain for this credential context. + * + * @param[in] cred The credential context. + * + * @param[out] obtained A pointer to store the obtained information. + * + * @return The domain name or NULL if an error occurred. + */ +_PUBLIC_ const char *cli_credentials_get_domain_and_obtained( + struct cli_credentials *cred, + enum credentials_obtained *obtained) +{ + const char *domain = cli_credentials_get_domain(cred); + + if (obtained != NULL) { + *obtained = cred->domain_obtained; + } + + return domain; +} + _PUBLIC_ bool cli_credentials_set_domain(struct cli_credentials *cred, const char *val, diff --git a/auth/credentials/credentials.h b/auth/credentials/credentials.h index 3ad40267e2e..341c984f60c 100644 --- a/auth/credentials/credentials.h +++ b/auth/credentials/credentials.h @@ -127,6 +127,9 @@ int cli_credentials_get_keytab(struct cli_credentials *cred, struct loadparm_context *lp_ctx, struct keytab_container **_ktc); const char *cli_credentials_get_domain(struct cli_credentials *cred); +const char *cli_credentials_get_domain_and_obtained( + struct cli_credentials *cred, + enum credentials_obtained *obtained); struct netlogon_creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred); void cli_credentials_set_machine_account_pending(struct cli_credentials *cred, struct loadparm_context *lp_ctx); diff --git a/auth/credentials/tests/test_creds.c b/auth/credentials/tests/test_creds.c index 414dd46a6b0..2cb2e6d0e34 100644 --- a/auth/credentials/tests/test_creds.c +++ b/auth/credentials/tests/test_creds.c @@ -48,6 +48,7 @@ static void torture_creds_init(void **state) const char *username = NULL; const char *domain = NULL; const char *password = NULL; + enum credentials_obtained dom_obtained = CRED_UNINITIALISED; enum credentials_obtained usr_obtained = CRED_UNINITIALISED; enum credentials_obtained pwd_obtained = CRED_UNINITIALISED; bool ok; @@ -65,6 +66,11 @@ static void torture_creds_init(void **state) domain = cli_credentials_get_domain(creds); assert_string_equal(domain, "WURST"); + domain = cli_credentials_get_domain_and_obtained(creds, + &dom_obtained); + assert_int_equal(dom_obtained, CRED_SPECIFIED); + assert_string_equal(domain, "WURST"); + username = cli_credentials_get_username(creds); assert_null(username); ok = cli_credentials_set_username(creds, "brot", CRED_SPECIFIED);