/lsass/client/rpc/netlogon/netr_serverauthenticate3.c

https://github.com/BeyondTrust/pbis-open · C · 144 lines · 79 code · 23 blank · 42 comment · 6 complexity · f38f6d44d74a2567905a821593fc94fa MD5 · raw file

  1. /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*-
  2. * ex: set softtabstop=4 tabstop=8 expandtab shiftwidth=4: *
  3. * Editor Settings: expandtabs and use 4 spaces for indentation */
  4. /*
  5. * Copyright © BeyondTrust Software 2004 - 2019
  6. * All rights reserved.
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * BEYONDTRUST MAKES THIS SOFTWARE AVAILABLE UNDER OTHER LICENSING TERMS AS
  21. * WELL. IF YOU HAVE ENTERED INTO A SEPARATE LICENSE AGREEMENT WITH
  22. * BEYONDTRUST, THEN YOU MAY ELECT TO USE THE SOFTWARE UNDER THE TERMS OF THAT
  23. * SOFTWARE LICENSE AGREEMENT INSTEAD OF THE TERMS OF THE APACHE LICENSE,
  24. * NOTWITHSTANDING THE ABOVE NOTICE. IF YOU HAVE QUESTIONS, OR WISH TO REQUEST
  25. * A COPY OF THE ALTERNATE LICENSING TERMS OFFERED BY BEYONDTRUST, PLEASE CONTACT
  26. * BEYONDTRUST AT beyondtrust.com/contact
  27. */
  28. /*
  29. * Copyright (C) BeyondTrust Software. All rights reserved.
  30. *
  31. * Module Name:
  32. *
  33. * netr_serverauthenticate3.c
  34. *
  35. * Abstract:
  36. *
  37. * Remote Procedure Call (RPC) Client Interface
  38. *
  39. * NetrServerAuthenticate3 function.
  40. *
  41. * Authors: Rafal Szczesniak (rafal@likewise.com)
  42. */
  43. #include "includes.h"
  44. NTSTATUS
  45. NetrServerAuthenticate3(
  46. IN NETR_BINDING hBinding,
  47. IN PCWSTR pwszServer,
  48. IN PCWSTR pwszAccount,
  49. IN UINT16 SchannelType,
  50. IN PCWSTR pwszComputer,
  51. IN BYTE CliCreds[8],
  52. IN BYTE SrvCreds[8],
  53. IN OUT UINT32 *pNegFlags,
  54. IN OUT UINT32 *pRid
  55. )
  56. {
  57. NTSTATUS ntStatus = STATUS_SUCCESS;
  58. DWORD dwError = ERROR_SUCCESS;
  59. NetrCred Creds;
  60. PWSTR pwszServerName = NULL;
  61. PWSTR pwszAccountName = NULL;
  62. PWSTR pwszComputerName = NULL;
  63. UINT32 Flags = 0;
  64. UINT32 Rid = 0;
  65. memset(&Creds, 0, sizeof(Creds));
  66. BAIL_ON_INVALID_PTR(hBinding, ntStatus);
  67. BAIL_ON_INVALID_PTR(pwszServer, ntStatus);
  68. BAIL_ON_INVALID_PTR(pwszAccount, ntStatus);
  69. BAIL_ON_INVALID_PTR(pwszComputer, ntStatus);
  70. BAIL_ON_INVALID_PTR(CliCreds, ntStatus);
  71. BAIL_ON_INVALID_PTR(SrvCreds, ntStatus);
  72. BAIL_ON_INVALID_PTR(pNegFlags, ntStatus);
  73. BAIL_ON_INVALID_PTR(pRid, ntStatus);
  74. memcpy(Creds.data, CliCreds, sizeof(Creds.data));
  75. dwError = LwAllocateWc16String(&pwszServerName,
  76. pwszServer);
  77. BAIL_ON_WIN_ERROR(dwError);
  78. dwError = LwAllocateWc16String(&pwszAccountName,
  79. pwszAccount);
  80. BAIL_ON_WIN_ERROR(dwError);
  81. dwError = LwAllocateWc16String(&pwszComputerName,
  82. pwszComputer);
  83. BAIL_ON_WIN_ERROR(dwError);
  84. DCERPC_CALL(ntStatus, cli_NetrServerAuthenticate3(hBinding,
  85. pwszServerName,
  86. pwszAccountName,
  87. SchannelType,
  88. pwszComputerName,
  89. &Creds,
  90. &Flags,
  91. &Rid));
  92. BAIL_ON_NT_STATUS(ntStatus);
  93. memcpy(SrvCreds, Creds.data, sizeof(Creds.data));
  94. *pNegFlags = Flags;
  95. *pRid = Rid;
  96. cleanup:
  97. memset(&Creds, 0, sizeof(Creds));
  98. LW_SAFE_FREE_MEMORY(pwszServerName);
  99. LW_SAFE_FREE_MEMORY(pwszAccountName);
  100. LW_SAFE_FREE_MEMORY(pwszComputerName);
  101. if (ntStatus == STATUS_SUCCESS &&
  102. dwError != ERROR_SUCCESS)
  103. {
  104. ntStatus = LwWin32ErrorToNtStatus(dwError);
  105. }
  106. return ntStatus;
  107. error:
  108. if (SrvCreds)
  109. {
  110. memset(SrvCreds, 0, sizeof(Creds.data));
  111. }
  112. if (pNegFlags)
  113. {
  114. *pNegFlags = 0;
  115. }
  116. if (pRid)
  117. {
  118. *pRid = 0;
  119. }
  120. goto cleanup;
  121. }