Leaked source code of windows server 2003
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.

184 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Copyright (c) 1993 Micro Computer Systems, Inc.
  4. Module Name:
  5. net\svcdlls\nwsap\client\advapi.c
  6. Abstract:
  7. This routine handles the Advertise API for the SAP Agent
  8. Author:
  9. Brian Walker (MCS) 06-15-1993
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. /*++
  15. *******************************************************************
  16. S a p A d d A d v e r t i s e
  17. Routine Description:
  18. This routine adds an entry to the list of servers
  19. that we advertise.
  20. Arguments:
  21. ServerName = Ptr to AsciiZ server name
  22. ServerType = USHORT of object type to add
  23. ServerAddr = Ptr to 12 byte aerver address
  24. RespondNearest = TRUE = Use me for respond nearest call
  25. FALSE = Don't use me for respond nearest call
  26. Return Value:
  27. SAPRETURN_SUCCESS - Added OK
  28. SAPRETURN_NOMEMORY - Error allocating memory
  29. SAPRETURN_EXISTS - Already exists in list
  30. SAPRETURN_NOTINIT - SAP Agent is not running
  31. *******************************************************************
  32. --*/
  33. INT
  34. SapAddAdvertise(
  35. IN PUCHAR ServerName,
  36. IN USHORT ServerType,
  37. IN PUCHAR ServerAddr,
  38. IN BOOL RespondNearest)
  39. {
  40. NTSTATUS status;
  41. NWSAP_REQUEST_MESSAGE request;
  42. NWSAP_REPLY_MESSAGE reply;
  43. /** If not running - return error **/
  44. if (!SapLibInitialized)
  45. return SAPRETURN_NOTINIT;
  46. /** Make sure name is not too long **/
  47. if (strlen(ServerName) > NWSAP_MAXNAME_LENGTH) {
  48. return SAPRETURN_INVALIDNAME;
  49. }
  50. /** Build the Add Advertise message **/
  51. request.MessageType = NWSAP_LPCMSG_ADDADVERTISE;
  52. request.PortMessage.u1.s1.DataLength = (USHORT)(sizeof(request) - sizeof(PORT_MESSAGE));
  53. request.PortMessage.u1.s1.TotalLength = sizeof(request);
  54. request.PortMessage.u2.ZeroInit = 0;
  55. memset(request.Message.AdvApi.ServerName, 0, NWSAP_MAXNAME_LENGTH+1);
  56. strcpy(request.Message.AdvApi.ServerName, ServerName);
  57. memcpy(request.Message.AdvApi.ServerAddr, ServerAddr, 12);
  58. request.Message.AdvApi.ServerType = ServerType;
  59. request.Message.AdvApi.RespondNearest = RespondNearest;
  60. /** Send it and get a response **/
  61. status = NtRequestWaitReplyPort(
  62. SapXsPortHandle,
  63. (PPORT_MESSAGE)&request,
  64. (PPORT_MESSAGE)&reply);
  65. if (!NT_SUCCESS(status)) {
  66. return status;
  67. }
  68. /** If we got a SAP error - return it **/
  69. if (reply.Error)
  70. return reply.Error;
  71. /** Return the entry **/
  72. memcpy(ServerAddr, reply.Message.AdvApi.ServerAddr, 12);
  73. /** All Done OK **/
  74. return SAPRETURN_SUCCESS;
  75. }
  76. /*++
  77. *******************************************************************
  78. S a p R e m o v e A d v e r t i s e
  79. Routine Description:
  80. This routine removes an entry to the list of servers
  81. that we advertise.
  82. Arguments:
  83. ServerName = Ptr to AsciiZ server name
  84. ServerType = USHORT of object type to remove
  85. Return Value:
  86. SAPRETURN_SUCCESS - Added OK
  87. SAPRETURN_NOTEXIST - Entry does not exist in list
  88. SAPRETURN_NOTINIT - SAP Agent is not running
  89. *******************************************************************
  90. --*/
  91. INT
  92. SapRemoveAdvertise(
  93. IN PUCHAR ServerName,
  94. IN USHORT ServerType)
  95. {
  96. NTSTATUS status;
  97. NWSAP_REQUEST_MESSAGE request;
  98. NWSAP_REPLY_MESSAGE reply;
  99. /** If not running - return error **/
  100. if (!SapLibInitialized)
  101. return SAPRETURN_NOTINIT;
  102. /** Make sure name is not too long **/
  103. if (strlen(ServerName) > NWSAP_MAXNAME_LENGTH) {
  104. return SAPRETURN_INVALIDNAME;
  105. }
  106. /** Build the Add Advertise message **/
  107. request.MessageType = NWSAP_LPCMSG_REMOVEADVERTISE;
  108. request.PortMessage.u1.s1.DataLength = (USHORT)(sizeof(request) - sizeof(PORT_MESSAGE));
  109. request.PortMessage.u1.s1.TotalLength = sizeof(request);
  110. request.PortMessage.u2.ZeroInit = 0;
  111. memset(request.Message.AdvApi.ServerName, 0, NWSAP_MAXNAME_LENGTH+1);
  112. strcpy(request.Message.AdvApi.ServerName, ServerName);
  113. request.Message.AdvApi.ServerType = ServerType;
  114. /** Send it and get a response **/
  115. status = NtRequestWaitReplyPort(
  116. SapXsPortHandle,
  117. (PPORT_MESSAGE)&request,
  118. (PPORT_MESSAGE)&reply);
  119. if (!NT_SUCCESS(status)) {
  120. return status;
  121. }
  122. /** If we got a SAP error - return it **/
  123. if (reply.Error)
  124. return reply.Error;
  125. /** All Done OK **/
  126. return SAPRETURN_SUCCESS;
  127. }
  128.