From df5e459299d1eb61879a4bdaf6f600acaab90b6a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 25 May 2018 13:40:12 +0200 Subject: [PATCH] s3:lib: add caching to set_current_user_info() Currently we do that in the caller, but we use global cache anyway, so we can simplify the callers. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- source3/lib/substitute.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 9fdc5ca1edc..ea227c5ab68 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -247,6 +247,17 @@ static const char *get_smb_user_name(void) void set_current_user_info(const char *smb_name, const char *unix_name, const char *domain) { + static const void *last_smb_name; + static const void *last_unix_name; + static const void *last_domain; + + if (likely(last_smb_name == smb_name && + last_unix_name == unix_name && + last_domain == domain)) + { + return; + } + fstrcpy(current_user_info.smb_name, smb_name); fstrcpy(current_user_info.unix_name, unix_name); fstrcpy(current_user_info.domain, domain); @@ -255,6 +266,10 @@ void set_current_user_info(const char *smb_name, const char *unix_name, * has already been sanitised in register_existing_vuid. */ sub_set_smb_name(current_user_info.smb_name); + + last_smb_name = smb_name; + last_unix_name = unix_name; + last_domain = domain; } /*******************************************************************