diff --git a/extra/exports b/extra/exports index 98fc8f1b92918d00a7266b81f39c2e82fcfd081d..2ab863f58f86953909376969ec02e964ccfa0941 100644 --- a/extra/exports +++ b/extra/exports @@ -646,3 +646,4 @@ coio_write_timeout fiber_set_name_n authenticate +user_auth_method_name diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fbf86da62d8bbf44197e1707a24d001018f1a5d1..cf1d0f5e2b9c165bf7d444a8cba58bccb04c91c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -273,6 +273,7 @@ set(api_headers ${PROJECT_SOURCE_DIR}/src/box/iterator_type.h ${PROJECT_SOURCE_DIR}/src/box/error.h ${PROJECT_SOURCE_DIR}/src/box/lua/tuple.h + ${PROJECT_SOURCE_DIR}/src/box/user.h ${PROJECT_SOURCE_DIR}/src/lib/core/latch.h ${PROJECT_SOURCE_DIR}/src/lib/core/clock.h ${PROJECT_SOURCE_DIR}/src/box/decimal.h diff --git a/src/box/user.cc b/src/box/user.cc index 27af33e5598a9ad11874535413ee1427658a0522..ad24a69792ed817d1ab243d1110abb5b36014858 100644 --- a/src/box/user.cc +++ b/src/box/user.cc @@ -40,6 +40,7 @@ #include "sequence.h" #include "tt_static.h" #include "txn.h" +#include "authentication.h" struct universe universe; static struct user users[BOX_USER_MAX]; @@ -436,6 +437,14 @@ user_reload_privs(struct user *user, struct txn_stmt *rolled_back_stmt) return 0; } +const char * +user_auth_method_name(const char *user_name, uint32_t user_name_len) +{ + struct user *user = user_find_by_name(user_name, user_name_len); + struct authenticator *auth = user != NULL ? user->def->auth : NULL; + return auth != NULL ? auth->method->name : NULL; +} + /** }}} */ /* {{{ authentication tokens */ diff --git a/src/box/user.h b/src/box/user.h index e49073a8e0ff49e0abf4656d1f432b0116e72e27..654a5ecdaac58463d446c25295dd63a1b13aa487 100644 --- a/src/box/user.h +++ b/src/box/user.h @@ -144,6 +144,24 @@ credentials_reset(struct credentials *cr, struct user *new_user) credentials_create(cr, new_user); } +/** \cond public */ + +/** + * Get an auth method name used by a user. + * Returns method name on success and NULL on error. + * + * This function is used to determine the authentication method when + * authenticating a postgres client. There is an another way to determine auth + * method name: export user_find_by_name and extract the name from the name + * field of the authenticator contained in the user, but this approach seems to + * be more complicated, since we still need to export something, as well as + * add definition of user and its internal fields in module.h. + */ +const char * +user_auth_method_name(const char *name, uint32_t name_len); + +/** \endcond public */ + /** * For best performance, all users are maintained in this array. * Position in the array is store in user->auth_token and also