Skip to content

Commit

Permalink
Simplify fr_ldap_edir_get_password
Browse files Browse the repository at this point in the history
  • Loading branch information
ndptech committed Sep 8, 2023
1 parent ea8401f commit 4a8a701
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/lib/ldap/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ int fr_ldap_conn_directory_alloc_async(fr_ldap_connection_t *ldap_conn);
/*
* edir.c - Edirectory integrations
*/
int fr_ldap_edir_get_password(rlm_rcode_t *p_result, request_t *request, char const *dn,
unlang_action_t fr_ldap_edir_get_password(request_t *request, char const *dn,
fr_ldap_thread_trunk_t *ttrunk, fr_dict_attr_t const *password_da);

char const *fr_ldap_edir_errstr(int code);
Expand Down
22 changes: 9 additions & 13 deletions src/lib/ldap/edir.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,24 +284,23 @@ static void ldap_edir_get_password_cancel(UNUSED request_t *request, UNUSED fr_s

/** Initiate retrieval of the universal password from Novell eDirectory
*
* @param[in,out] p_result Current result code.
* @param[in] request Current request.
* @param[in] dn of the user whose password is to be retrieved.
* @param[in] ttrunk on which to send the LDAP request.
* @param[in] password_da DA to use when creating password attribute.
* @return
* - 0 on success.
* - < 0 on failure.
* - UNLANG_ACTION_PUSHED_CHILD on success.
* - UNLANG_ACTION_FAIL on failure.
*/
int fr_ldap_edir_get_password(rlm_rcode_t *p_result, request_t *request, char const *dn,
fr_ldap_thread_trunk_t *ttrunk, fr_dict_attr_t const *password_da)
unlang_action_t fr_ldap_edir_get_password(request_t *request, char const *dn, fr_ldap_thread_trunk_t *ttrunk,
fr_dict_attr_t const *password_da)
{
ldap_edir_ctx_t *edir_ctx;
int err = 0;

if (!dn || !*dn) {
REDEBUG("Missing DN");
RETURN_MODULE_FAIL;
return UNLANG_ACTION_FAIL;
}

MEM(edir_ctx = talloc(unlang_interpret_frame_talloc_ctx(request), ldap_edir_ctx_t));
Expand All @@ -315,16 +314,13 @@ int fr_ldap_edir_get_password(rlm_rcode_t *p_result, request_t *request, char co
err = ber_encode_request_data(dn, &edir_ctx->dn);
if (err) {
REDEBUG("Failed to encode user DN: %s", fr_ldap_edir_errstr(err));
fail:
talloc_free(edir_ctx);
RETURN_MODULE_FAIL;
return UNLANG_ACTION_FAIL;
}

if (unlang_function_push(request, ldap_edir_get_password_start, ldap_edir_get_password_resume,
ldap_edir_get_password_cancel, ~FR_SIGNAL_CANCEL,
UNLANG_SUB_FRAME, edir_ctx) < 0) goto fail;

return UNLANG_ACTION_PUSHED_CHILD;
return unlang_function_push(request, ldap_edir_get_password_start, ldap_edir_get_password_resume,
ldap_edir_get_password_cancel, ~FR_SIGNAL_CANCEL,
UNLANG_SUB_FRAME, edir_ctx);
}

char const *fr_ldap_edir_errstr(int code)
Expand Down
8 changes: 2 additions & 6 deletions src/modules/rlm_ldap/rlm_ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,13 +1510,9 @@ static unlang_action_t mod_authorize_resume(rlm_rcode_t *p_result, UNUSED int *p
* Retrive universal password
*/
REPEAT_MOD_AUTHORIZE_RESUME;
if (fr_ldap_edir_get_password(p_result, request, autz_ctx->dn, autz_ctx->ttrunk,
attr_cleartext_password) < 0) {
rcode = RLM_MODULE_FAIL;
goto finish;
}
autz_ctx->status = LDAP_AUTZ_EDIR_BIND;
return UNLANG_ACTION_PUSHED_CHILD;
return fr_ldap_edir_get_password(request, autz_ctx->dn, autz_ctx->ttrunk,
attr_cleartext_password);
}
FALL_THROUGH;

Expand Down

0 comments on commit 4a8a701

Please sign in to comment.