Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Implicit User Principal Name If Explicit Does Not Exist #332

Merged
merged 2 commits into from
Jul 20, 2018

Conversation

NoMoreFood
Copy link

  • Modified user principal name lookup to default to the implicit form (SamAccountName@DnsDomainName) if no explicit user principal name attribute is found on the account.

- Modified user principal name lookup to default to the implicit form (SamAccountName@DnsDomainName) if no explicit user principal name attribute is found on the account.
wcscat_s(user_principal_name, MAX_UPN_LEN + 1, L"@");
wcsncat_s(user_principal_name, MAX_UPN_LEN + 1, domain_upn, wcschr(domain_upn, L'/') - domain_upn);
debug3("%s: Successfully discovered implicit principal name: '%ls'=>'%ls'",
__FUNCTION__, sam_account_name, user_principal_name);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help me understand. How would the NameCanonical name be different from NameSamCompatible name ? As per msdn NameCanonical can have multiple '/'s.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're only using the fully qualified domain name part of NameCanonical (i.e. domain.local/other/path/stuff).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Missed it earlier.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some additional explanation to the code as well.

lookup_error = GetLastError();
domain_upn_len = ARRAYSIZE(domain_upn);
if (pTranslateNameW(sam_account_name, NameSamCompatible, NameCanonical, domain_upn, &domain_upn_len) != 0) {
wcscpy_s(user_principal_name, MAX_UPN_LEN + 1, wcschr(sam_account_name, L'\\') + 1);
Copy link

@manojampalam manojampalam Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize user_principal_name to "\0".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the intent here. String copy functions do not need an initialized string since they start copying immediately into the passed pointer without looking at what data might be there.

/* report error and copy the sam account name into the buffer */
error("%s: User principal name lookup failed for user '%ls' (explicit: %d, implicit: %d)",
__FUNCTION__, sam_account_name, lookup_error, GetLastError());
wcscpy_s(user_principal_name, MAX_UPN_LEN + 1, sam_account_name);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this.. it will be clean to assume that nothing gets set on the failure path

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

else
debug3("%s: Successfully discovered principal name: '%ls'=>'%ls'", __FUNCTION__, user_cpn, domain_upn);

lookup_principal_name(user_cpn, domain_upn);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle failure (copy user_cpn to domain_upn on failure)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -715,4 +706,37 @@ get_custom_lsa_package()
return s_lsa_auth_pkg;
}

int lookup_principal_name(const wchar_t * sam_account_name, wchar_t * user_principal_name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a brief summary on what this routine does.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

…ns 1

- Moved lookup_principal_name() fallback behavior out of the function and into the caller.
- Added additional comments.
@manojampalam manojampalam merged commit 3669643 into PowerShell:latestw_all Jul 20, 2018
@NoMoreFood NoMoreFood deleted the kerberos_fix branch July 20, 2018 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants