From da17eb6c8619c0f781cd4601c0da1258043aa475 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 14 Feb 2012 12:01:38 -0500 Subject: [PATCH] Windows: avoid GetComputerNameW call for all ioctl Cache the value of GetComputerNameW() to avoid repeated calls for each and every redirector ioctl request. Change-Id: I4476db982897a631510eba7d859385268b16ce34 Reviewed-on: http://gerrit.openafs.org/6708 Tested-by: BuildBot Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- src/WINNT/afsrdr/user/RDRFunction.c | 21 ++++++++++++--------- src/WINNT/afsrdr/user/RDRIoctl.c | 10 ++++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/WINNT/afsrdr/user/RDRFunction.c b/src/WINNT/afsrdr/user/RDRFunction.c index 9ae6d0a5d6..b9e27c5c68 100644 --- a/src/WINNT/afsrdr/user/RDRFunction.c +++ b/src/WINNT/afsrdr/user/RDRFunction.c @@ -178,17 +178,19 @@ RDR_SetInitParams( OUT AFSRedirectorInitInfo **ppRedirInitInfo, OUT DWORD * pRed return 0; } +static wchar_t cname[MAX_COMPUTERNAME_LENGTH+1] = L""; + cm_user_t * RDR_GetLocalSystemUser( void) { smb_username_t *unp; cm_user_t *userp = NULL; - wchar_t cname[MAX_COMPUTERNAME_LENGTH+1]; - int cnamelen = MAX_COMPUTERNAME_LENGTH+1; - - GetComputerNameW(cname, &cnamelen); - _wcsupr(cname); + if ( cname[0] == '\0') { + int len = MAX_COMPUTERNAME_LENGTH+1; + GetComputerNameW(cname, &len); + _wcsupr(cname); + } unp = smb_FindUserByName(NTSID_LOCAL_SYSTEM, cname, SMB_FLAG_CREATE); lock_ObtainMutex(&unp->mx); if (!unp->userp) @@ -220,14 +222,15 @@ RDR_UserFromAuthGroup( IN GUID *pGuid) smb_username_t *unp; cm_user_t * userp = NULL; RPC_WSTR UuidString = NULL; - wchar_t cname[MAX_COMPUTERNAME_LENGTH+1]; - int cnamelen = MAX_COMPUTERNAME_LENGTH+1; if (UuidToStringW((UUID *)pGuid, &UuidString) != RPC_S_OK) goto done; - GetComputerNameW(cname, &cnamelen); - _wcsupr(cname); + if ( cname[0] == '\0') { + int len = MAX_COMPUTERNAME_LENGTH+1; + GetComputerNameW(cname, &len); + _wcsupr(cname); + } unp = smb_FindUserByName(UuidString, cname, SMB_FLAG_CREATE); lock_ObtainMutex(&unp->mx); diff --git a/src/WINNT/afsrdr/user/RDRIoctl.c b/src/WINNT/afsrdr/user/RDRIoctl.c index 89c3e67a57..37d7275940 100644 --- a/src/WINNT/afsrdr/user/RDRIoctl.c +++ b/src/WINNT/afsrdr/user/RDRIoctl.c @@ -924,17 +924,19 @@ RDR_IoctlSetToken(struct RDR_ioctl *ioctlp, struct cm_user *userp, afs_uint32 pf #if defined(NO_AUTH_GROUPS) if ((pflags & AFSCALL_FLAG_LOCAL_SYSTEM) && (flags & PIOCTL_LOGON)) { - wchar_t cname[MAX_COMPUTERNAME_LENGTH+1]; - int cnamelen = MAX_COMPUTERNAME_LENGTH+1; PSID pSid = NULL; DWORD dwSize1, dwSize2; wchar_t *pszRefDomain = NULL; SID_NAME_USE snu = SidTypeGroup; clientchar_t * secSidString = NULL; DWORD gle; + static wchar_t cname[MAX_COMPUTERNAME_LENGTH+1] = L""; - GetComputerNameW(cname, &cnamelen); - wcsupr(cname); + if ( cname[0] == '\0') { + int len = MAX_COMPUTERNAME_LENGTH+1; + GetComputerNameW(cname, &len); + _wcsupr(cname); + } /* * The input name is probably not a SID for the user which is how