Skip to content

Commit

Permalink
AD: Construct UPN from the sAMAccountName
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejv2 committed Jul 15, 2024
1 parent d9d7a0d commit 9d04d38
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/providers/ldap/sdap_async_users.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ int sdap_save_user(TALLOC_CTX *memctx,
int ret;
const char *user_name = NULL;
const char *fullname = NULL;
const char *samaccountname = NULL;
const char *realm;
const char *pwd;
const char *gecos;
const char *homedir;
Expand All @@ -203,6 +205,7 @@ int sdap_save_user(TALLOC_CTX *memctx,
size_t c;
char *p1;
char *p2;
char *new_upn;
bool is_posix = true;

DEBUG(SSSDBG_TRACE_FUNC, "Save user\n");
Expand Down Expand Up @@ -269,7 +272,24 @@ int sdap_save_user(TALLOC_CTX *memctx,
DEBUG(SSSDBG_TRACE_FUNC, "Processing user %s\n", user_name);

if (opts->schema_type == SDAP_SCHEMA_AD) {
/* construct canonical UPN from sAMAccountName to help Samba and also to allow us to lookup user via UPN */
ret = sysdb_attrs_get_string(attrs,
opts->user_map[SDAP_AT_USER_SAMACCOUNTNAME].sys_name, &samaccountname);
if (ret == EOK) {
ret = ENOENT;
realm = dp_opt_get_cstring(opts->basic, SDAP_KRB5_REALM);
if (realm != NULL) {
new_upn = talloc_asprintf(memctx, "%s@%s", samaccountname, realm);
if (new_upn != NULL){
ret = sysdb_attrs_add_string(user_attrs, SYSDB_CANONICAL_UPN, new_upn);
DEBUG(SSSDBG_TRACE_FUNC, "Storing Canonical UPN %s for user %s\n", new_upn, user_name);
}
}
}
if (ret != EOK) {
DEBUG(SSSDBG_MINOR_FAILURE,"Unable to obtain Canonical UPN for %s\n", user_name);
}
ret = sysdb_attrs_get_string(attrs,
opts->user_map[SDAP_AT_USER_FULLNAME].sys_name, &fullname);
if (ret == EOK) {
ret = sysdb_attrs_add_string(user_attrs, SYSDB_FULLNAME, fullname);
Expand Down

0 comments on commit 9d04d38

Please sign in to comment.