From c9222ab838844bca698a64b2125a19244ee6f008 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 18 Mar 2021 09:59:08 +0100 Subject: s3:netapi: Implement public libnetapi_get_(username|password) functions Signed-off-by: Andreas Schneider Reviewed-by: Guenther Deschner --- source3/lib/netapi/netapi.c | 46 +++++++++++++++++++++++++++++++++++++ source3/lib/netapi/netapi.h | 6 +++++ source3/lib/netapi/netapi_private.h | 2 -- 3 files changed, 52 insertions(+), 2 deletions(-) (limited to 'source3/lib/netapi') diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index fb8b4bc6113..820dd8ac6e0 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -227,6 +227,52 @@ NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx, /**************************************************************** ****************************************************************/ +/** + * @brief Get the username of the libnet context + * + * @param[in] ctx The netapi context + * + * @param[in] username A pointer to hold the username. + * + * @return 0 on success, an werror code otherwise. + */ +NET_API_STATUS libnetapi_get_username(struct libnetapi_ctx *ctx, + const char **username) +{ + if (ctx == NULL) { + return W_ERROR_V(WERR_INVALID_PARAMETER); + } + + if (username != NULL) { + *username = ctx->username; + } + + return NET_API_STATUS_SUCCESS; +} + +/** + * @brief Get the password of the libnet context + * + * @param[in] ctx The netapi context + * + * @param[in] password A pointer to hold the password. + * + * @return 0 on success, an werror code otherwise. + */ +NET_API_STATUS libnetapi_get_password(struct libnetapi_ctx *ctx, + const char **password) +{ + if (ctx == NULL) { + return W_ERROR_V(WERR_INVALID_PARAMETER); + } + + if (password != NULL) { + *password = ctx->password; + } + + return NET_API_STATUS_SUCCESS; +} + NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx, const char *username) { diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 6fc539c8f6f..b7fdb752a79 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1391,6 +1391,12 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx); NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx); +NET_API_STATUS libnetapi_get_username(struct libnetapi_ctx *ctx, + const char **username); + +NET_API_STATUS libnetapi_get_password(struct libnetapi_ctx *ctx, + const char **password); + /**************************************************************** ****************************************************************/ diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 4d028251c43..998d2b2b634 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -53,8 +53,6 @@ struct libnetapi_private_ctx { struct messaging_context *msg_ctx; }; -NET_API_STATUS libnetapi_get_password(struct libnetapi_ctx *ctx, char **password); -NET_API_STATUS libnetapi_get_username(struct libnetapi_ctx *ctx, char **username); NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, const char *format, ...) PRINTF_ATTRIBUTE(2,3); -- cgit v1.2.1