@@ -57,8 +57,6 @@ typedef struct {
5757typedef struct {
5858 fr_value_box_t password ;
5959 tmpl_t const * password_tmpl ;
60- fr_value_box_t user_base ;
61- fr_value_box_t user_filter ;
6260 fr_value_box_t user_sasl_mech ;
6361 fr_value_box_t user_sasl_authname ;
6462 fr_value_box_t user_sasl_proxy ;
@@ -192,7 +190,6 @@ static const call_env_method_t authenticate_method_env = {
192190 .env = (call_env_parser_t []) {
193191 { FR_CALL_ENV_SUBSECTION ("user" , NULL , CALL_ENV_FLAG_REQUIRED ,
194192 ((call_env_parser_t []) {
195- USER_CALL_ENV_COMMON (ldap_auth_call_env_t ),
196193 { FR_CALL_ENV_PARSE_OFFSET ("password_attribute" , FR_TYPE_STRING ,
197194 CALL_ENV_FLAG_ATTRIBUTE | CALL_ENV_FLAG_REQUIRED | CALL_ENV_FLAG_NULLABLE | CALL_ENV_FLAG_CONCAT | CALL_ENV_FLAG_BARE_WORD_ATTRIBUTE ,
198195 ldap_auth_call_env_t , password , password_tmpl ),
@@ -1424,70 +1421,6 @@ static unlang_action_t mod_map_proc(rlm_rcode_t *p_result, void const *mod_inst,
14241421 map_ctx -> serverctrls , NULL );
14251422}
14261423
1427- /** Perform async lookup of user DN if required for authentication
1428- *
1429- */
1430- static unlang_action_t mod_authenticate_start (rlm_rcode_t * p_result , UNUSED int * priority ,
1431- request_t * request , void * uctx )
1432- {
1433- ldap_auth_ctx_t * auth_ctx = talloc_get_type_abort (uctx , ldap_auth_ctx_t );
1434- fr_ldap_thread_trunk_t * ttrunk ;
1435- rlm_ldap_t const * inst = auth_ctx -> inst ;
1436-
1437- ttrunk = fr_thread_ldap_trunk_get (auth_ctx -> thread , inst -> handle_config .server , inst -> handle_config .admin_identity ,
1438- inst -> handle_config .admin_password , request , & inst -> handle_config );
1439- if (!ttrunk ) RETURN_MODULE_FAIL ;
1440-
1441- return rlm_ldap_find_user_async (auth_ctx , auth_ctx -> inst , request , & auth_ctx -> call_env -> user_base ,
1442- & auth_ctx -> call_env -> user_filter , ttrunk , NULL , NULL );
1443- }
1444-
1445- /** Initiate async LDAP bind to authenticate user
1446- *
1447- */
1448- static unlang_action_t mod_authenticate_resume (rlm_rcode_t * p_result , UNUSED int * priority ,
1449- request_t * request , void * uctx )
1450- {
1451- ldap_auth_ctx_t * auth_ctx = talloc_get_type_abort (uctx , ldap_auth_ctx_t );
1452-
1453- /*
1454- * SASL bind auth will have the mech set.
1455- */
1456- if (auth_ctx -> call_env -> user_sasl_mech .type == FR_TYPE_STRING ) {
1457- #ifdef WITH_SASL
1458- ldap_auth_call_env_t * call_env = auth_ctx -> call_env ;
1459-
1460- RDEBUG2 ("Login attempt using identity \"%pV\"" , & call_env -> user_sasl_authname );
1461-
1462- return fr_ldap_sasl_bind_auth_async (request , auth_ctx -> thread , call_env -> user_sasl_mech .vb_strvalue ,
1463- call_env -> user_sasl_authname .vb_strvalue ,
1464- auth_ctx -> password , call_env -> user_sasl_proxy .vb_strvalue ,
1465- call_env -> user_sasl_realm .vb_strvalue );
1466- #else
1467- RDEBUG ("Configuration item 'sasl.mech' is not supported. "
1468- "The linked version of libldap does not provide ldap_sasl_bind( function" );
1469- RETURN_MODULE_FAIL ;
1470- #endif
1471- }
1472-
1473- /*
1474- * Arriving here from an LDAP search will mean the dn in auth_ctx is NULL.
1475- */
1476- if (!auth_ctx -> dn ) auth_ctx -> dn = rlm_find_user_dn_cached (request );
1477-
1478- /*
1479- * No DN found - can't authenticate the user with a simple bind.
1480- */
1481- if (!auth_ctx -> dn ) {
1482- talloc_free (auth_ctx );
1483- RETURN_MODULE_FAIL ;
1484- }
1485-
1486- RDEBUG2 ("Login attempt as \"%s\"" , auth_ctx -> dn );
1487-
1488- return fr_ldap_bind_auth_async (request , auth_ctx -> thread , auth_ctx -> dn , auth_ctx -> password );
1489- }
1490-
14911424static unlang_action_t CC_HINT (nonnull ) mod_authenticate (rlm_rcode_t * p_result , module_ctx_t const * mctx , request_t * request )
14921425{
14931426 rlm_ldap_t const * inst = talloc_get_type_abort_const (mctx -> mi -> data , rlm_ldap_t );
@@ -1507,15 +1440,6 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result,
15071440 RETURN_MODULE_INVALID ;
15081441 }
15091442
1510- /*
1511- * Log the password
1512- */
1513- if (RDEBUG_ENABLED3 ) {
1514- RDEBUG ("Login attempt with password \"%pV\"" , & call_env -> password );
1515- } else {
1516- RDEBUG2 ("Login attempt with password" );
1517- }
1518-
15191443 auth_ctx = talloc (unlang_interpret_frame_talloc_ctx (request ), ldap_auth_ctx_t );
15201444 * auth_ctx = (ldap_auth_ctx_t ){
15211445 .password = call_env -> password .vb_strvalue ,
@@ -1525,15 +1449,51 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result,
15251449 };
15261450
15271451 /*
1528- * Check for a cached copy of the DN
1452+ * Find the user's DN
15291453 */
15301454 auth_ctx -> dn = rlm_find_user_dn_cached (request );
15311455
1532- if (unlang_function_push (request , auth_ctx -> dn || (call_env -> user_sasl_mech .type == FR_TYPE_STRING ) ?
1533- NULL : mod_authenticate_start , mod_authenticate_resume ,
1534- NULL , 0 , UNLANG_SUB_FRAME , auth_ctx ) < 0 ) RETURN_MODULE_FAIL ;
1456+ /*
1457+ * The DN is required for non-SASL auth
1458+ */
1459+ if (!auth_ctx -> dn && (call_env -> user_sasl_mech .type != FR_TYPE_STRING )) {
1460+ REDEBUG ("No DN found for authentication. Populate control.%s with the DN to use in authentication." ,
1461+ attr_ldap_userdn -> name );
1462+ REDEBUG ("You should call %s in the recv section and check its return." , inst -> mi -> name );
1463+ talloc_free (auth_ctx );
1464+ RETURN_MODULE_FAIL ;
1465+ }
15351466
1536- return UNLANG_ACTION_PUSHED_CHILD ;
1467+ /*
1468+ * Log the password
1469+ */
1470+ if (RDEBUG_ENABLED3 ) {
1471+ RDEBUG ("Login attempt with password \"%pV\"" , & call_env -> password );
1472+ } else {
1473+ RDEBUG2 ("Login attempt with password" );
1474+ }
1475+
1476+ /*
1477+ * SASL bind auth will have the mech set.
1478+ */
1479+ if (auth_ctx -> call_env -> user_sasl_mech .type == FR_TYPE_STRING ) {
1480+ #ifdef WITH_SASL
1481+ RDEBUG2 ("Login attempt using identity \"%pV\"" , & call_env -> user_sasl_authname );
1482+
1483+ return fr_ldap_sasl_bind_auth_async (request , auth_ctx -> thread , call_env -> user_sasl_mech .vb_strvalue ,
1484+ call_env -> user_sasl_authname .vb_strvalue ,
1485+ auth_ctx -> password , call_env -> user_sasl_proxy .vb_strvalue ,
1486+ call_env -> user_sasl_realm .vb_strvalue );
1487+ #else
1488+ RDEBUG ("Configuration item 'sasl.mech' is not supported. "
1489+ "The linked version of libldap does not provide ldap_sasl_bind( function" );
1490+ RETURN_MODULE_FAIL ;
1491+ #endif
1492+ }
1493+
1494+ RDEBUG2 ("Login attempt as \"%s\"" , auth_ctx -> dn );
1495+
1496+ return fr_ldap_bind_auth_async (request , auth_ctx -> thread , auth_ctx -> dn , auth_ctx -> password );
15371497}
15381498
15391499/** Start LDAP authorization with async lookup of user DN
0 commit comments