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.

431 lines
11 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1992 - 1999
  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. #include <nsi.h>
  12. #include <memory.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15. RPC_STATUS RPC_ENTRY
  16. RpcNsBindingExportW(
  17. IN unsigned long EntryNameSyntax,
  18. IN unsigned short * EntryName,
  19. IN RPC_IF_HANDLE RpcIfHandle, OPTIONAL
  20. IN RPC_BINDING_VECTOR * BindingVector, OPTIONAL
  21. IN UUID_VECTOR * ObjectVector OPTIONAL
  22. )
  23. /*++
  24. Routine Description:
  25. Place a server interface and objects in the name service data base.
  26. Arguments:
  27. EntryNameSyntax - This value describes the type/format of the EntryName.
  28. EntryName - Name that this export will be stored in. This is just a
  29. token that is passed on the the Name Server.
  30. RpcIfHandle - The interface that is being exported.
  31. BindingVector - A list of StringBindings to export that are associated
  32. with this interface.
  33. ObjectVector - A list of objects that are associated with this
  34. interface and Entry Name
  35. Returns:
  36. Bind(), RpcBindingToStringBinding(), nsi_binding_export()
  37. --*/
  38. {
  39. RPC_STATUS status;
  40. UNSIGNED16 NsiStatus;
  41. NSI_SERVER_BINDING_VECTOR_T *NsiVector = 0;
  42. WIDE_STRING *StringBindingW;
  43. RT_CHAR * StringBinding = 0;
  44. RT_CHAR * DynamicEndpoint = 0;
  45. unsigned int Index;
  46. unsigned int VectorSize = 0;
  47. NSI_INTERFACE_ID_T NilIfOnWire, __RPC_FAR *IfPtr;
  48. if (RpcIfHandle == NULL)
  49. {
  50. IfPtr = &NilIfOnWire;
  51. memset(IfPtr, 0, sizeof(NSI_INTERFACE_ID_T));
  52. }
  53. else
  54. {
  55. IfPtr = (NSI_INTERFACE_ID_T __RPC_FAR *)
  56. &((PRPC_CLIENT_INTERFACE)RpcIfHandle)->InterfaceId;
  57. }
  58. if (status = I_NsServerBindSearch())
  59. return(status);
  60. if (! EntryNameSyntax)
  61. EntryNameSyntax = DefaultSyntax;
  62. if (BindingVector && BindingVector->Count && RpcIfHandle)
  63. {
  64. VectorSize = (unsigned int) BindingVector->Count;
  65. NsiVector = (NSI_SERVER_BINDING_VECTOR_T *) I_RpcAllocate((unsigned int) (
  66. sizeof(NSI_SERVER_BINDING_VECTOR_T) +
  67. sizeof(unsigned short *) * VectorSize));
  68. if (!NsiVector)
  69. return(RPC_S_OUT_OF_MEMORY);
  70. NsiVector->count = 0;
  71. }
  72. // Copy the vector of binding handles into a vector of string bindinds
  73. // that are wide character.
  74. for (Index = 0; Index < VectorSize; Index++)
  75. {
  76. if (!BindingVector->BindingH[Index])
  77. continue;
  78. // Turn the private runtime data structure into a StringBinding.
  79. #ifdef NTENV
  80. status = I_RpcBindingToStaticStringBindingW(BindingVector->BindingH[Index],
  81. &StringBinding);
  82. // call to remove the dynamic part from the binding
  83. // and give the string binding.
  84. #else
  85. status = RpcBindingToStringBinding(BindingVector->BindingH[Index],
  86. &StringBinding);
  87. #endif
  88. if (status)
  89. goto ErrorExit;
  90. StringBindingW = new WIDE_STRING (StringBinding);
  91. if (!StringBindingW || StringBindingW->OutOfMemory())
  92. {
  93. status = RPC_S_OUT_OF_MEMORY;
  94. goto ErrorExit;
  95. }
  96. NsiVector->string[NsiVector->count++] = &(*StringBindingW);
  97. I_RpcFree(StringBindingW); // Free memory without destuctor
  98. #ifndef NTENV
  99. I_RpcFree(StringBinding); // Free the non unicode string
  100. #endif
  101. }
  102. RpcTryExcept
  103. {
  104. nsi_binding_export(
  105. NsiSvrBinding,
  106. EntryNameSyntax,
  107. EntryName,
  108. IfPtr,
  109. NsiVector,
  110. (NSI_UUID_VECTOR_P_T) ObjectVector,
  111. &NsiStatus
  112. );
  113. }
  114. RpcExcept(1)
  115. {
  116. NsiStatus = MapException(RpcExceptionCode());
  117. }
  118. RpcEndExcept
  119. status = NsiMapStatus(NsiStatus);
  120. ErrorExit:
  121. // Return memory allocated for nsi vector.
  122. if (NsiVector)
  123. for (Index = 0; Index < NsiVector->count; Index++)
  124. I_RpcFree(NsiVector->string[Index]);
  125. if (NsiVector)
  126. I_RpcFree(NsiVector);
  127. return(NsiMapStatus(NsiStatus));
  128. }
  129. RPC_STATUS RPC_ENTRY
  130. RpcNsBindingUnexportW(
  131. IN unsigned long EntryNameSyntax OPTIONAL,
  132. IN unsigned short * EntryName,
  133. IN RPC_IF_HANDLE RpcIfHandle OPTIONAL,
  134. IN UUID_VECTOR * ObjectVector OPTIONAL
  135. )
  136. /*++
  137. Routine Description:
  138. Remove a server interface and objects in the name service data base.
  139. Arguments:
  140. EntryNameSyntax - This value describes the type/format of the EntryName.
  141. EntryName - Name that this export will be stored in. This is just a
  142. token that is passed on the the Name Server.
  143. RpcIfHandle - The interface that is being unexported.
  144. ObjectVector - A list of objects that are associated with this
  145. interface and Entry Name
  146. Returns:
  147. Bind(), nsi_binding_unexport()
  148. --*/
  149. {
  150. RPC_STATUS status;
  151. UNSIGNED16 NsiStatus;
  152. NSI_INTERFACE_ID_T NilIfOnWire, __RPC_FAR *IfPtr;
  153. if (RpcIfHandle == NULL)
  154. {
  155. IfPtr = &NilIfOnWire;
  156. memset(IfPtr, 0, sizeof(NSI_INTERFACE_ID_T));
  157. }
  158. else
  159. {
  160. IfPtr = (NSI_INTERFACE_ID_T __RPC_FAR *)
  161. &((PRPC_CLIENT_INTERFACE)RpcIfHandle)->InterfaceId;
  162. }
  163. if (status = I_NsServerBindSearch())
  164. return(status);
  165. if (! EntryNameSyntax)
  166. EntryNameSyntax = DefaultSyntax;
  167. RpcTryExcept
  168. {
  169. nsi_binding_unexport(NsiSvrBinding, EntryNameSyntax, EntryName,
  170. IfPtr, (NSI_UUID_VECTOR_P_T) ObjectVector,
  171. &NsiStatus);
  172. }
  173. RpcExcept(1)
  174. {
  175. NsiStatus = MapException(RpcExceptionCode());
  176. }
  177. RpcEndExcept
  178. return(NsiMapStatus(NsiStatus));
  179. }
  180. RPC_STATUS RPC_ENTRY
  181. RpcNsBindingExportA(
  182. IN unsigned long EntryNameSyntax,
  183. IN unsigned char * EntryName,
  184. IN RPC_IF_HANDLE RpcIfHandle,
  185. IN RPC_BINDING_VECTOR * BindingVector, OPTIONAL
  186. IN UUID_VECTOR * ObjectVector OPTIONAL
  187. )
  188. /*++
  189. Routine Description:
  190. This is an ASCII wrapper to the UNICODE version of the API. It
  191. converts all char * -> short * strings and calls the UNICODE version.
  192. --*/
  193. {
  194. WIDE_STRING EntryNameW(EntryName);
  195. if (EntryNameW.OutOfMemory())
  196. return(RPC_S_OUT_OF_MEMORY);
  197. return(RpcNsBindingExportW(EntryNameSyntax, &EntryNameW,
  198. RpcIfHandle, BindingVector, ObjectVector));
  199. }
  200. RPC_STATUS RPC_ENTRY
  201. RpcNsBindingUnexportA(
  202. IN unsigned long EntryNameSyntax,
  203. IN unsigned char * EntryName,
  204. IN RPC_IF_HANDLE RpcIfHandle,
  205. IN UUID_VECTOR * ObjectVector OPTIONAL
  206. )
  207. /*++
  208. Routine Description:
  209. This is an ASCII wrapper to the UNICODE version of the API. It
  210. converts all char * -> short * strings and calls the UNICODE version.
  211. --*/
  212. {
  213. WIDE_STRING EntryNameW(EntryName);
  214. if (EntryNameW.OutOfMemory())
  215. return(RPC_S_OUT_OF_MEMORY);
  216. return(RpcNsBindingUnexportW(EntryNameSyntax, &EntryNameW,
  217. RpcIfHandle, ObjectVector));
  218. }
  219. #ifdef NTENV
  220. /*
  221. Function:
  222. The Binding Vector corresponding to this Server is discovered
  223. using InqBindings, And is cached along with the EntryName and RpcIfHandle
  224. in the same Process.
  225. When a PnP event occurs resulting in addition/deletion of the bindings
  226. Corresponding changes are made to the Name Service database. (added or deleted)
  227. Notice that this can not be called from a process that is not a server. The
  228. Exports have to be done from the server itself if it has to be PnP aware
  229. */
  230. RPC_STATUS RPC_ENTRY
  231. RpcNsBindingExportPnPW(
  232. IN unsigned long EntryNameSyntax,
  233. IN unsigned short * EntryName,
  234. IN RPC_IF_HANDLE RpcIfHandle, OPTIONAL
  235. IN UUID_VECTOR * ObjectVector OPTIONAL
  236. )
  237. {
  238. RPC_STATUS status = RPC_S_OK;
  239. RPC_BINDING_VECTOR *BindingVec = NULL;
  240. status = RpcServerInqBindings(&BindingVec);
  241. // InqBindings to get the binding vector
  242. if (status != RPC_S_OK)
  243. return status;
  244. status = RpcNsBindingExportW(EntryNameSyntax, EntryName,
  245. RpcIfHandle, BindingVec,
  246. ObjectVector
  247. );
  248. if (status != RPC_S_OK)
  249. return status;
  250. // only if this is valid, other invalid cases will all be caught before
  251. if (RpcIfHandle)
  252. status = I_RpcNsInterfaceExported(EntryNameSyntax, EntryName,
  253. (RPC_SERVER_INTERFACE *)RpcIfHandle);
  254. return status;
  255. // going to cache for bindings exported to the locator
  256. // (only if the prev. export succeeded)
  257. }
  258. /*
  259. Removes all the bindings corresponding to this particular server
  260. from the Name Service database. It also removes it from the cache that
  261. is maintained for the EntryName/InterfaceId combination.
  262. Notice that this can not be called from a process that is not a server. The
  263. Unexports have to be done from the server itself if it has to be PnP aware
  264. */
  265. RPC_STATUS RPC_ENTRY
  266. RpcNsBindingUnexportPnPW(
  267. IN unsigned long EntryNameSyntax OPTIONAL,
  268. IN unsigned short * EntryName,
  269. IN RPC_IF_HANDLE RpcIfHandle OPTIONAL,
  270. IN UUID_VECTOR * ObjectVector OPTIONAL
  271. )
  272. {
  273. RPC_STATUS status = RPC_S_OK;
  274. status = RpcNsBindingUnexportW(EntryNameSyntax, EntryName,
  275. RpcIfHandle, ObjectVector);
  276. if (status != RPC_S_OK)
  277. return status;
  278. if (RpcIfHandle)
  279. status = I_RpcNsInterfaceUnexported(EntryNameSyntax, EntryName,
  280. (RPC_SERVER_INTERFACE *)RpcIfHandle);
  281. // once it has got removed, remove it from the cache as well.
  282. return status;
  283. }
  284. RPC_STATUS RPC_ENTRY
  285. RpcNsBindingExportPnPA(
  286. IN unsigned long EntryNameSyntax,
  287. IN unsigned char * EntryName,
  288. IN RPC_IF_HANDLE RpcIfHandle, OPTIONAL
  289. IN UUID_VECTOR * ObjectVector OPTIONAL
  290. )
  291. {
  292. WIDE_STRING EntryNameW(EntryName);
  293. if (EntryNameW.OutOfMemory())
  294. return(RPC_S_OUT_OF_MEMORY);
  295. return(RpcNsBindingExportPnPW(EntryNameSyntax, &EntryNameW,
  296. RpcIfHandle, ObjectVector));
  297. }
  298. RPC_STATUS RPC_ENTRY
  299. RpcNsBindingUnexportPnPA(
  300. IN unsigned long EntryNameSyntax OPTIONAL,
  301. IN unsigned char * EntryName,
  302. IN RPC_IF_HANDLE RpcIfHandle OPTIONAL,
  303. IN UUID_VECTOR * ObjectVector OPTIONAL
  304. )
  305. {
  306. WIDE_STRING EntryNameW(EntryName);
  307. if (EntryNameW.OutOfMemory())
  308. return(RPC_S_OUT_OF_MEMORY);
  309. return(RpcNsBindingUnexportPnPW(EntryNameSyntax, &EntryNameW,
  310. RpcIfHandle, ObjectVector));
  311. }
  312. #endif