Windows: avoid GetComputerNameW call for all ioctl
authorJeffrey Altman <jaltman@your-file-system.com>
Tue, 14 Feb 2012 17:01:38 +0000 (12:01 -0500)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Wed, 15 Feb 2012 06:31:34 +0000 (22:31 -0800)
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 <buildbot@rampaginggeek.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>

src/WINNT/afsrdr/user/RDRFunction.c
src/WINNT/afsrdr/user/RDRIoctl.c

index 9ae6d0a..b9e27c5 100644 (file)
@@ -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);
index 89c3e67..37d7275 100644 (file)
@@ -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