summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/providers/krb5/krb5_auth.c9
-rw-r--r--src/providers/krb5/krb5_common.c25
-rw-r--r--src/providers/krb5/krb5_common.h2
3 files changed, 30 insertions, 6 deletions
diff --git a/src/providers/krb5/krb5_auth.c b/src/providers/krb5/krb5_auth.c
index 626df2ff..08a97ef1 100644
--- a/src/providers/krb5/krb5_auth.c
+++ b/src/providers/krb5/krb5_auth.c
@@ -716,14 +716,11 @@ struct tevent_req *krb5_auth_send(TALLOC_CTX *mem_ctx,
case 1:
kr->upn = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_UPN, NULL);
if (kr->upn == NULL) {
- /* NOTE: this is a hack, works only in some environments */
- kr->upn = talloc_asprintf(kr, "%s@%s", pd->user, realm);
- if (kr->upn == NULL) {
- DEBUG(1, ("failed to build simple upn.\n"));
- ret = ENOMEM;
+ ret = krb5_get_simple_upn(state, krb5_ctx, pd->user, &kr->upn);
+ if (ret != EOK) {
+ DEBUG(1, ("krb5_get_simple_upn failed.\n"));
goto done;
}
- DEBUG(9, ("Using simple UPN [%s].\n", kr->upn));
}
kr->homedir = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_HOMEDIR,
diff --git a/src/providers/krb5/krb5_common.c b/src/providers/krb5/krb5_common.c
index 81ad4e9d..4d577257 100644
--- a/src/providers/krb5/krb5_common.c
+++ b/src/providers/krb5/krb5_common.c
@@ -653,3 +653,28 @@ errno_t krb5_install_sigterm_handler(struct tevent_context *ev,
return EOK;
}
+
+errno_t krb5_get_simple_upn(TALLOC_CTX *mem_ctx, struct krb5_ctx *krb5_ctx,
+ const char *username, const char **_upn)
+{
+ const char *realm;
+ char *upn;
+
+ realm = dp_opt_get_cstring(krb5_ctx->opts, KRB5_REALM);
+ if (realm == NULL) {
+ DEBUG(1, ("Missing Kerberos realm.\n"));
+ return ENOENT;
+ }
+
+ /* NOTE: this is a hack, works only in some environments */
+ upn = talloc_asprintf(mem_ctx, "%s@%s", username, realm);
+ if (upn == NULL) {
+ DEBUG(1, ("talloc_asprintf failed.\n"));
+ return ENOMEM;
+ }
+
+ DEBUG(9, ("Using simple UPN [%s].\n", upn));
+
+ *_upn = upn;
+ return EOK;
+}
diff --git a/src/providers/krb5/krb5_common.h b/src/providers/krb5/krb5_common.h
index a8ebcf5c..139ce400 100644
--- a/src/providers/krb5/krb5_common.h
+++ b/src/providers/krb5/krb5_common.h
@@ -145,4 +145,6 @@ errno_t write_krb5info_file(const char *realm, const char *kdc,
errno_t remove_krb5_info_files(TALLOC_CTX *mem_ctx, const char *realm);
+errno_t krb5_get_simple_upn(TALLOC_CTX *mem_ctx, struct krb5_ctx *krb5_ctx,
+ const char *username, const char **_upn);
#endif /* __KRB5_COMMON_H__ */