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.

267 lines
6.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\bindlib.c
  6. Abstract:
  7. This routine handles the BindLib 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 G e t O b j e c t N a m e
  17. Routine Description:
  18. This routine converts an Object ID into an Object Name
  19. and Type.
  20. Arguments:
  21. ObjectID = Object ID to convert
  22. ObjectName = Ptr to where to store 48 byte object name
  23. ObjectType = Ptr to where to store the object type
  24. ObjectAddr = Ptr to where to store NET_ADDRESS (12 bytes)
  25. ObjectName, ObjectType, ObjectAddr can be NULL.
  26. Return Value:
  27. SAPRETURN_SUCCESS = OK - name and type are filled in
  28. SAPRETURN_NOTEXIST = Invalid object id.
  29. *******************************************************************
  30. --*/
  31. INT
  32. SapGetObjectName(
  33. IN ULONG ObjectID,
  34. IN PUCHAR ObjectName,
  35. IN PUSHORT ObjectType,
  36. IN PUCHAR ObjectAddr)
  37. {
  38. NTSTATUS status;
  39. NWSAP_REQUEST_MESSAGE request;
  40. NWSAP_REPLY_MESSAGE reply;
  41. /** If not initialized - return error **/
  42. if (!SapLibInitialized)
  43. return SAPRETURN_NOTINIT;
  44. /** Build the Get Object Name message **/
  45. request.MessageType = NWSAP_LPCMSG_GETOBJECTNAME;
  46. request.PortMessage.u1.s1.DataLength = (USHORT)(sizeof(request) - sizeof(PORT_MESSAGE));
  47. request.PortMessage.u1.s1.TotalLength = sizeof(request);
  48. request.PortMessage.u2.ZeroInit = 0;
  49. request.PortMessage.MessageId = 0;
  50. request.Message.BindLibApi.ObjectID = ObjectID;
  51. /** Send it and get a response **/
  52. status = NtRequestWaitReplyPort(
  53. SapXsPortHandle,
  54. (PPORT_MESSAGE)&request,
  55. (PPORT_MESSAGE)&reply);
  56. if (!NT_SUCCESS(status)) {
  57. return status;
  58. }
  59. /** If we got a SAP error - return it **/
  60. if (reply.Error)
  61. return reply.Error;
  62. /** Return the entry **/
  63. if (ObjectType)
  64. *ObjectType = reply.Message.BindLibApi.ObjectType;
  65. if (ObjectName)
  66. memcpy(ObjectName, reply.Message.BindLibApi.ObjectName, NWSAP_MAXNAME_LENGTH+1);
  67. if (ObjectAddr)
  68. memcpy(ObjectAddr, reply.Message.BindLibApi.ObjectAddr, 12);
  69. /** All Done OK **/
  70. return SAPRETURN_SUCCESS;
  71. }
  72. /*++
  73. *******************************************************************
  74. S a p G e t O b j e c t I D
  75. Routine Description:
  76. This routine converts a name and type into an object ID.
  77. Arguments:
  78. ObjectName = Ptr to AsciiZ object name (Must be uppercase)
  79. ObjectType = Object type to look for
  80. ObjectID = Ptr to where to store the object ID.
  81. Return Value:
  82. SAPRETURN_SUCCESS = OK - Object ID is filled in
  83. SAPRETURN_NOTEXIST = Name/Type not found
  84. *******************************************************************
  85. --*/
  86. INT
  87. SapGetObjectID(
  88. IN PUCHAR ObjectName,
  89. IN USHORT ObjectType,
  90. IN PULONG ObjectID)
  91. {
  92. NTSTATUS status;
  93. NWSAP_REQUEST_MESSAGE request;
  94. NWSAP_REPLY_MESSAGE reply;
  95. /** If not initialized - return error **/
  96. if (!SapLibInitialized)
  97. return SAPRETURN_NOTINIT;
  98. /** If the name is too long - error **/
  99. if (strlen(ObjectName) > NWSAP_MAXNAME_LENGTH)
  100. return SAPRETURN_INVALIDNAME;
  101. /** Build the Get Object Name message **/
  102. request.MessageType = NWSAP_LPCMSG_GETOBJECTID;
  103. request.PortMessage.u1.s1.DataLength = (USHORT)(sizeof(request) - sizeof(PORT_MESSAGE));
  104. request.PortMessage.u1.s1.TotalLength = sizeof(request);
  105. request.PortMessage.u2.ZeroInit = 0;
  106. memset(request.Message.BindLibApi.ObjectName, 0, NWSAP_MAXNAME_LENGTH+1);
  107. strcpy(request.Message.BindLibApi.ObjectName, ObjectName);
  108. request.Message.BindLibApi.ObjectType = ObjectType;
  109. /** Send it and get a response **/
  110. status = NtRequestWaitReplyPort(
  111. SapXsPortHandle,
  112. (PPORT_MESSAGE)&request,
  113. (PPORT_MESSAGE)&reply);
  114. if (!NT_SUCCESS(status)) {
  115. return status;
  116. }
  117. /** If we got a SAP error - return it **/
  118. if (reply.Error)
  119. return reply.Error;
  120. /** Return the entry **/
  121. *ObjectID = reply.Message.BindLibApi.ObjectID;
  122. /** All Done OK **/
  123. return SAPRETURN_SUCCESS;
  124. }
  125. /*++
  126. *******************************************************************
  127. S a p S c a n O b j e c t
  128. Routine Description:
  129. This routine is used to scan thru the database list.
  130. Arguments:
  131. ObjectID = Ptr to last Object ID we saw. On first call
  132. this should point to a 0xFFFFFFFF.
  133. ObjectName = Ptr to where to store 48 byte object name
  134. ObjectType = Ptr to where to store the object type
  135. ScanType = Object Type that we are scanning for
  136. (0xFFFF = All)
  137. ObjectName, ObjectType can be NULL.
  138. Return Value:
  139. SAPRETURN_SUCCESS = OK - name and type are filled in
  140. ObjectID has the object ID of this entry.
  141. SAPRETURN_NOTEXIST = Invalid object id.
  142. *******************************************************************
  143. --*/
  144. INT
  145. SapScanObject(
  146. IN PULONG ObjectID,
  147. IN PUCHAR ObjectName,
  148. IN PUSHORT ObjectType,
  149. IN USHORT ScanType)
  150. {
  151. NTSTATUS status;
  152. NWSAP_REQUEST_MESSAGE request;
  153. NWSAP_REPLY_MESSAGE reply;
  154. /** If not initialized - return error **/
  155. if (!SapLibInitialized)
  156. return SAPRETURN_NOTINIT;
  157. /** Build the Get Object Name message **/
  158. request.MessageType = NWSAP_LPCMSG_SEARCH;
  159. request.PortMessage.u1.s1.DataLength = (USHORT)(sizeof(request) - sizeof(PORT_MESSAGE));
  160. request.PortMessage.u1.s1.TotalLength = sizeof(request);
  161. request.PortMessage.u2.ZeroInit = 0;
  162. request.Message.BindLibApi.ObjectID = *ObjectID;
  163. request.Message.BindLibApi.ScanType = ScanType;
  164. /** Send it and get a response **/
  165. status = NtRequestWaitReplyPort(
  166. SapXsPortHandle,
  167. (PPORT_MESSAGE)&request,
  168. (PPORT_MESSAGE)&reply);
  169. if (!NT_SUCCESS(status)) {
  170. return status;
  171. }
  172. /** If we got a SAP error - return it **/
  173. if (reply.Error)
  174. return reply.Error;
  175. /** Return the entry **/
  176. if (ObjectType)
  177. *ObjectType = reply.Message.BindLibApi.ObjectType;
  178. if (ObjectName)
  179. memcpy(ObjectName, reply.Message.BindLibApi.ObjectName, NWSAP_MAXNAME_LENGTH+1);
  180. *ObjectID = reply.Message.BindLibApi.ObjectID;
  181. /** All Done OK **/
  182. return SAPRETURN_SUCCESS;
  183. }
  184.