Windows NT 4.0 source code leak
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.

308 lines
6.9 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. nsisvr.cxx
  5. Abstract:
  6. This is the server side NSI service support layer. These are wrappers
  7. which call the name service provider.
  8. Author:
  9. Steven Zeck (stevez) 03/04/92
  10. --*/
  11. #ifdef NTENV
  12. extern "C" {
  13. #include <nt.h>
  14. #include <excpt.h>
  15. }
  16. #endif // NTENV
  17. #include <nsi.h>
  18. #include <memory.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21. RPC_STATUS RPC_ENTRY
  22. RpcNsBindingExportW(
  23. IN unsigned long EntryNameSyntax,
  24. IN unsigned short * EntryName,
  25. IN RPC_IF_HANDLE RpcIfHandle, OPTIONAL
  26. IN RPC_BINDING_VECTOR * BindingVector, OPTIONAL
  27. IN UUID_VECTOR * ObjectVector OPTIONAL
  28. )
  29. /*++
  30. Routine Description:
  31. Place a server interface and objects in the name service data base.
  32. Arguments:
  33. EntryNameSyntax - This value describes the type/format of the EntryName.
  34. EntryName - Name that this export will be stored in. This is just a
  35. token that is passed on the the Name Server.
  36. RpcIfHandle - The interface that is being exported.
  37. BindingVector - A list of StringBindings to export that are associated
  38. with this interface.
  39. ObjectVector - A list of objects that are associated with this
  40. interface and Entry Name
  41. Returns:
  42. Bind(), RpcBindingToStringBinding(), nsi_binding_export()
  43. --*/
  44. {
  45. RPC_STATUS status;
  46. UNSIGNED16 NsiStatus;
  47. NSI_SERVER_BINDING_VECTOR_T *NsiVector = 0;
  48. WIDE_STRING *StringBindingW;
  49. RT_CHAR * StringBinding = 0;
  50. RT_CHAR * DynamicEndpoint = 0;
  51. unsigned int Index;
  52. unsigned int VectorSize = 0;
  53. NSI_INTERFACE_ID_T NilIfOnWire, __RPC_FAR *IfPtr;
  54. if (RpcIfHandle == NULL)
  55. {
  56. IfPtr = &NilIfOnWire;
  57. memset(IfPtr, 0, sizeof(NSI_INTERFACE_ID_T));
  58. }
  59. else
  60. {
  61. IfPtr = (NSI_INTERFACE_ID_T __RPC_FAR *)
  62. &((PRPC_CLIENT_INTERFACE)RpcIfHandle)->InterfaceId;
  63. }
  64. if (status = I_NsServerBindSearch())
  65. return(status);
  66. if (! EntryNameSyntax)
  67. EntryNameSyntax = DefaultSyntax;
  68. if (BindingVector && BindingVector->Count && RpcIfHandle)
  69. {
  70. VectorSize = (unsigned int) BindingVector->Count;
  71. NsiVector = (NSI_SERVER_BINDING_VECTOR_T *) I_RpcAllocate((unsigned int) (
  72. sizeof(NSI_SERVER_BINDING_VECTOR_T) +
  73. sizeof(unsigned short *) * VectorSize));
  74. if (!NsiVector)
  75. return(RPC_S_OUT_OF_MEMORY);
  76. NsiVector->count = 0;
  77. }
  78. // Copy the vector of binding handles into a vector of string bindinds
  79. // that are wide character.
  80. for (Index = 0; Index < VectorSize; Index++)
  81. {
  82. if (!BindingVector->BindingH[Index])
  83. continue;
  84. // Turn the private runtime data structure into a StringBinding.
  85. status = RpcBindingToStringBinding(BindingVector->BindingH[Index],
  86. &StringBinding);
  87. if (status)
  88. goto ErrorExit;
  89. StringBindingW = new WIDE_STRING (StringBinding);
  90. if (!StringBindingW || StringBindingW->OutOfMemory())
  91. {
  92. status = RPC_S_OUT_OF_MEMORY;
  93. goto ErrorExit;
  94. }
  95. NsiVector->string[NsiVector->count++] = &(*StringBindingW);
  96. I_RpcFree(StringBindingW); // Free memory without destuctor
  97. #ifndef NTENV
  98. I_RpcFree(StringBinding); // Free the non unicode string
  99. #endif
  100. }
  101. RpcTryExcept
  102. {
  103. nsi_binding_export(
  104. EntryNameSyntax,
  105. EntryName,
  106. IfPtr,
  107. NsiVector,
  108. (NSI_UUID_VECTOR_P_T) ObjectVector,
  109. &NsiStatus
  110. );
  111. }
  112. RpcExcept(1)
  113. {
  114. NsiStatus = MapException(RpcExceptionCode());
  115. }
  116. RpcEndExcept
  117. status = NsiMapStatus(NsiStatus);
  118. ErrorExit:
  119. // Return memory allocated for nsi vector.
  120. if (NsiVector)
  121. for (Index = 0; Index < NsiVector->count; Index++)
  122. I_RpcFree(NsiVector->string[Index]);
  123. if (NsiVector)
  124. I_RpcFree(NsiVector);
  125. return(NsiMapStatus(NsiStatus));
  126. }
  127. RPC_STATUS RPC_ENTRY
  128. RpcNsBindingUnexportW(
  129. IN unsigned long EntryNameSyntax OPTIONAL,
  130. IN unsigned short * EntryName,
  131. IN RPC_IF_HANDLE RpcIfHandle OPTIONAL,
  132. IN UUID_VECTOR * ObjectVector OPTIONAL
  133. )
  134. /*++
  135. Routine Description:
  136. Remove a server interface and objects in the name service data base.
  137. Arguments:
  138. EntryNameSyntax - This value describes the type/format of the EntryName.
  139. EntryName - Name that this export will be stored in. This is just a
  140. token that is passed on the the Name Server.
  141. RpcIfHandle - The interface that is being unexported.
  142. ObjectVector - A list of objects that are associated with this
  143. interface and Entry Name
  144. Returns:
  145. Bind(), nsi_binding_unexport()
  146. --*/
  147. {
  148. RPC_STATUS status;
  149. UNSIGNED16 NsiStatus;
  150. NSI_INTERFACE_ID_T NilIfOnWire, __RPC_FAR *IfPtr;
  151. if (RpcIfHandle == NULL)
  152. {
  153. IfPtr = &NilIfOnWire;
  154. memset(IfPtr, 0, sizeof(NSI_INTERFACE_ID_T));
  155. }
  156. else
  157. {
  158. IfPtr = (NSI_INTERFACE_ID_T __RPC_FAR *)
  159. &((PRPC_CLIENT_INTERFACE)RpcIfHandle)->InterfaceId;
  160. }
  161. if (status = I_NsServerBindSearch())
  162. return(status);
  163. if (! EntryNameSyntax)
  164. EntryNameSyntax = DefaultSyntax;
  165. RpcTryExcept
  166. {
  167. nsi_binding_unexport(EntryNameSyntax, EntryName,
  168. IfPtr,
  169. (NSI_UUID_VECTOR_P_T) ObjectVector,
  170. &NsiStatus);
  171. }
  172. RpcExcept(1)
  173. {
  174. NsiStatus = MapException(RpcExceptionCode());
  175. }
  176. RpcEndExcept
  177. return(NsiMapStatus(NsiStatus));
  178. }
  179. RPC_STATUS RPC_ENTRY
  180. RpcNsBindingExportA(
  181. IN unsigned long EntryNameSyntax,
  182. IN unsigned char * EntryName,
  183. IN RPC_IF_HANDLE RpcIfHandle,
  184. IN RPC_BINDING_VECTOR * BindingVector, OPTIONAL
  185. IN UUID_VECTOR * ObjectVector OPTIONAL
  186. )
  187. /*++
  188. Routine Description:
  189. This is an ASCII wrapper to the UNICODE version of the API. It
  190. converts all char * -> short * strings and calls the UNICODE version.
  191. --*/
  192. {
  193. WIDE_STRING EntryNameW(EntryName);
  194. if (EntryNameW.OutOfMemory())
  195. return(RPC_S_OUT_OF_MEMORY);
  196. return(RpcNsBindingExportW(EntryNameSyntax, &EntryNameW,
  197. RpcIfHandle, BindingVector, ObjectVector));
  198. }
  199. RPC_STATUS RPC_ENTRY
  200. RpcNsBindingUnexportA(
  201. IN unsigned long EntryNameSyntax,
  202. IN unsigned char * EntryName,
  203. IN RPC_IF_HANDLE RpcIfHandle,
  204. IN UUID_VECTOR * ObjectVector OPTIONAL
  205. )
  206. /*++
  207. Routine Description:
  208. This is an ASCII wrapper to the UNICODE version of the API. It
  209. converts all char * -> short * strings and calls the UNICODE version.
  210. --*/
  211. {
  212. WIDE_STRING EntryNameW(EntryName);
  213. if (EntryNameW.OutOfMemory())
  214. return(RPC_S_OUT_OF_MEMORY);
  215. return(RpcNsBindingUnexportW(EntryNameSyntax, &EntryNameW,
  216. RpcIfHandle, ObjectVector));
  217. }