Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.1 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1998
  5. //
  6. // File: lsclient.cpp
  7. //
  8. // Contents: Client's RPC binding routine and Hydra License Server Lookup
  9. // routine.
  10. //
  11. // History: 01-09-98 HueiWang Created
  12. //
  13. //---------------------------------------------------------------------------
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <tchar.h>
  18. #include <rpc.h>
  19. #include "lsclient.h"
  20. #include "lscommon.h"
  21. //+------------------------------------------------------------------------
  22. // Function: ConnectToLsServer()
  23. //
  24. // Description:
  25. //
  26. // Binding to sepecific hydra license server
  27. //
  28. // Arguments:
  29. //
  30. // szLsServer - Hydra License Server name
  31. //
  32. // Return Value:
  33. //
  34. // RPC binding handle or NULL if error, use GetLastError() to retrieve
  35. // error.
  36. //-------------------------------------------------------------------------
  37. PCONTEXT_HANDLE
  38. ConnectLsServer( LPTSTR szLsServer, LPTSTR szProtocol, LPTSTR szEndPoint, DWORD dwAuthLevel )
  39. {
  40. LPTSTR szBindingString;
  41. RPC_BINDING_HANDLE hBinding=NULL;
  42. RPC_STATUS status;
  43. PCONTEXT_HANDLE pContext=NULL;
  44. status = RpcStringBindingCompose(0,
  45. szProtocol,
  46. szLsServer,
  47. szEndPoint,
  48. 0,
  49. &szBindingString);
  50. if(status!=RPC_S_OK)
  51. return NULL;
  52. status=RpcBindingFromStringBinding( szBindingString, &hBinding);
  53. RpcStringFree( &szBindingString );
  54. if(status != RPC_S_OK)
  55. return NULL;
  56. status=RpcBindingSetAuthInfo(hBinding,
  57. 0,
  58. dwAuthLevel,
  59. RPC_C_AUTHN_WINNT,
  60. 0,
  61. 0);
  62. if(status == RPC_S_OK)
  63. {
  64. // Obtain context handle from server
  65. status = LSConnect( hBinding, &pContext );
  66. }
  67. SetLastError((status == RPC_S_OK) ? ERROR_SUCCESS : status);
  68. return pContext;
  69. }
  70. //-------------------------------------------------------------------------
  71. PCONTEXT_HANDLE
  72. ConnectToLsServer( LPTSTR szLsServer )
  73. {
  74. TCHAR szMachineName[MAX_COMPUTERNAME_LENGTH + 1] ;
  75. PCONTEXT_HANDLE pContext=NULL;
  76. DWORD cbMachineName=MAX_COMPUTERNAME_LENGTH;
  77. GetComputerName(szMachineName, &cbMachineName);
  78. if(_tcsicmp(szMachineName, szLsServer) == 0)
  79. {
  80. pContext=ConnectLsServer(szLsServer, _TEXT(RPC_PROTOSEQLPC), NULL, RPC_C_AUTHN_LEVEL_DEFAULT);
  81. if(GetLastError() >= LSERVER_ERROR_BASE)
  82. {
  83. return NULL;
  84. }
  85. // try to connect with TCP protocol, if local procedure failed
  86. }
  87. if(pContext == NULL)
  88. {
  89. pContext=ConnectLsServer(szLsServer, _TEXT(RPC_PROTOSEQNP), _TEXT(LSNAMEPIPE), RPC_C_AUTHN_LEVEL_NONE);
  90. }
  91. return pContext;
  92. }
  93. //-------------------------------------------------------------------------
  94. void
  95. DisconnectFromServer( PCONTEXT_HANDLE pContext )
  96. {
  97. LSDisconnect( &pContext );
  98. }