Jacek Caban : rpcrt4: Moved AcquireCredentialHandle call to RPCRT4_ServerGetRegisteredAuthInfo.

Alexandre Julliard julliard at winehq.org
Sun Jul 3 12:18:29 CDT 2016


Module: wine
Branch: master
Commit: f3e5e76da97dac32f3d7d7678649239bc1508502
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f3e5e76da97dac32f3d7d7678649239bc1508502

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Jun 27 17:08:40 2016 +0200

rpcrt4: Moved AcquireCredentialHandle call to RPCRT4_ServerGetRegisteredAuthInfo.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/rpcrt4/rpc_server.c | 47 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/dlls/rpcrt4/rpc_server.c b/dlls/rpcrt4/rpc_server.c
index bb77237..d77354d 100644
--- a/dlls/rpcrt4/rpc_server.c
+++ b/dlls/rpcrt4/rpc_server.c
@@ -1310,9 +1310,11 @@ struct rpc_server_registered_auth_info
 {
     struct list entry;
     TimeStamp exp;
+    BOOL cred_acquired;
     CredHandle cred;
     ULONG max_token;
     USHORT auth_type;
+    WCHAR *principal;
 };
 
 static RPC_STATUS find_security_package(ULONG auth_type, SecPkgInfoW **packages_buf, SecPkgInfoW **ret)
@@ -1357,6 +1359,28 @@ RPC_STATUS RPCRT4_ServerGetRegisteredAuthInfo(
     {
         if (auth_info->auth_type == auth_type)
         {
+            if (!auth_info->cred_acquired)
+            {
+                SecPkgInfoW *packages, *package;
+                SECURITY_STATUS sec_status;
+
+                status = find_security_package(auth_info->auth_type, &packages, &package);
+                if (status != RPC_S_OK)
+                    break;
+
+                sec_status = AcquireCredentialsHandleW((SEC_WCHAR *)auth_info->principal, package->Name,
+                                                       SECPKG_CRED_INBOUND, NULL, NULL, NULL, NULL,
+                                                       &auth_info->cred, &auth_info->exp);
+                FreeContextBuffer(packages);
+                if (sec_status != SEC_E_OK)
+                {
+                    status = RPC_S_SEC_PKG_ERROR;
+                    break;
+                }
+
+                auth_info->cred_acquired = TRUE;
+            }
+
             *cred = auth_info->cred;
             *exp = auth_info->exp;
             *max_token = auth_info->max_token;
@@ -1376,7 +1400,9 @@ void RPCRT4_ServerFreeAllRegisteredAuthInfo(void)
     EnterCriticalSection(&server_auth_info_cs);
     LIST_FOR_EACH_ENTRY_SAFE(auth_info, cursor2, &server_registered_auth_info, struct rpc_server_registered_auth_info, entry)
     {
-        FreeCredentialsHandle(&auth_info->cred);
+        if (auth_info->cred_acquired)
+            FreeCredentialsHandle(&auth_info->cred);
+        HeapFree(GetProcessHeap(), 0, auth_info->principal);
         HeapFree(GetProcessHeap(), 0, auth_info);
     }
     LeaveCriticalSection(&server_auth_info_cs);
@@ -1409,9 +1435,6 @@ RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( RPC_CSTR ServerPrincName, ULONG Au
 RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
                             LPVOID Arg )
 {
-    SECURITY_STATUS sec_status;
-    CredHandle cred;
-    TimeStamp exp;
     struct rpc_server_registered_auth_info *auth_info;
     SecPkgInfoW *packages, *package;
     ULONG max_token;
@@ -1423,24 +1446,20 @@ RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( RPC_WSTR ServerPrincName, ULONG Au
     if (status != RPC_S_OK)
         return status;
 
-    sec_status = AcquireCredentialsHandleW((SEC_WCHAR *)ServerPrincName,
-                                           package->Name,
-                                           SECPKG_CRED_INBOUND, NULL, NULL,
-                                           NULL, NULL, &cred, &exp);
     max_token = package->cbMaxToken;
     FreeContextBuffer(packages);
-    if (sec_status != SEC_E_OK)
-        return RPC_S_SEC_PKG_ERROR;
 
     auth_info = HeapAlloc(GetProcessHeap(), 0, sizeof(*auth_info));
     if (!auth_info)
-    {
-        FreeCredentialsHandle(&cred);
+        return RPC_S_OUT_OF_RESOURCES;
+
+    if (!ServerPrincName) {
+        auth_info->principal = NULL;
+    }else if (!(auth_info->principal = RPCRT4_strdupW(ServerPrincName))) {
+        HeapFree(GetProcessHeap(), 0, auth_info);
         return RPC_S_OUT_OF_RESOURCES;
     }
 
-    auth_info->exp = exp;
-    auth_info->cred = cred;
     auth_info->max_token = max_token;
     auth_info->auth_type = AuthnSvc;
 




More information about the wine-cvs mailing list