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.

348 lines
6.9 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1992 - 1999
  3. Module Name:
  4. util.cxx
  5. Abstract:
  6. This module contains utility functions used by the NSI client wrappers.
  7. Author:
  8. Steven Zeck (stevez) 03/27/92
  9. --*/
  10. #include <nsi.h>
  11. #include <memory.h>
  12. #include <string.h>
  13. #include <stdio.h>
  14. #ifndef WIN32
  15. extern "C"
  16. {
  17. int atoi(char *);
  18. void far pascal OutputDebugString(void far *);
  19. void __RPC_FAR * __RPC_API
  20. MIDL_user_allocate(
  21. size_t cb
  22. );
  23. void __RPC_API
  24. MIDL_user_free(
  25. void __RPC_FAR * p
  26. );
  27. }
  28. #else
  29. #include <stdlib.h>
  30. #endif
  31. RPC_STATUS NsiToRpcStatus[] =
  32. {
  33. RPC_S_OK, // NSI_S_OK
  34. RPC_S_NO_MORE_BINDINGS, // NSI_S_NO_MORE_BINDINGS
  35. RPC_S_INTERFACE_NOT_FOUND, // NSI_S_INTERFACE_NOT_FOUND
  36. RPC_S_ENTRY_NOT_FOUND, // NSI_S_ENTRY_NOT_FOUND
  37. RPC_S_NAME_SERVICE_UNAVAILABLE,// NSI_S_NAME_SERVICE_UNAVAILABLE
  38. RPC_S_ACCESS_DENIED, // NSI_S_NO_NS_PRIVILEGE
  39. RPC_S_UNSUPPORTED_NAME_SYNTAX, // NSI_S_UNSUPPORTED_NAME_SYNTAX
  40. RPC_S_NOT_ALL_OBJS_UNEXPORTED, // NSI_S_NOTHING_TO_UNEXPORT
  41. RPC_S_INVALID_NAME_SYNTAX, // NSI_S_INVALID_NAME_SYNTAX
  42. RPC_S_NO_CONTEXT_AVAILABLE, // NSI_S_INVALID_NS_HANDLE
  43. RPC_S_OUT_OF_RESOURCES, // NSI_S_INVALID_OBJECT
  44. RPC_S_NOT_ALL_OBJS_UNEXPORTED, // NSI_S_NOT_ALL_OBJS_UNEXPORTED
  45. RPC_S_INVALID_STRING_BINDING, // NSI_S_INVALID_STRING_BINDING
  46. RPC_S_INTERNAL_ERROR, // NSI_S_SOME_OTHER_ERROR
  47. RPC_S_NOTHING_TO_EXPORT, // NSI_S_NOTHING_TO_EXPORT
  48. RPC_S_CANNOT_SUPPORT, // NSI_S_UNIMPLEMENTED_API
  49. RPC_S_NOTHING_TO_EXPORT, // NSI_S_NO_INTERFACES_EXPORTED
  50. RPC_S_INCOMPLETE_NAME, // NSI_S_INCOMPLETE_NAME
  51. RPC_S_INVALID_VERS_OPTION, // NSI_S_INVALID_VERS_OPTION
  52. RPC_S_NO_MORE_MEMBERS, // NSI_S_NO_MORE_MEMBERS
  53. RPC_S_ENTRY_ALREADY_EXISTS, // NSI_S_ENTRY_ALREADY_EXISTS
  54. RPC_S_OUT_OF_MEMORY, // NSI_S_OUT_OF_MEMORY
  55. RPC_S_GROUP_MEMBER_NOT_FOUND, // NSI_S_GROUP_MEMBER_NOT_FOUND
  56. RPC_S_SERVER_UNAVAILABLE, // NSI_S_NO_MASTER_LOCATOR
  57. RPC_S_ENTRY_TYPE_MISMATCH, // NSI_S_ENTRY_TYPE_MISMATCH
  58. RPC_S_NOT_ALL_OBJS_EXPORTED, // NSI_S_NOT_ALL_OBJS_EXPORTED
  59. RPC_S_INTERFACE_NOT_EXPORTED, // NSI_S_INTERFACE_NOT_EXPORTED
  60. RPC_S_PROFILE_NOT_ADDED, // NSI_S_PROFILE_NOT_ADDED
  61. RPC_S_PRF_ELT_NOT_ADDED, // NSI_S_PRF_ELT_NOT_ADDED
  62. RPC_S_PRF_ELT_NOT_REMOVED, // NSI_S_PRF_ELT_NOT_REMOVED
  63. RPC_S_GRP_ELT_NOT_ADDED, // NSI_S_GRP_ELT_NOT_ADDED
  64. RPC_S_GRP_ELT_NOT_REMOVED // NSI_S_GRP_ELT_NOT_REMOVED
  65. };
  66. UNSIGNED16
  67. MapException(
  68. IN RPC_STATUS Exception
  69. )
  70. /*++
  71. Routine Description:
  72. Map a RPC exception to a NSI status code.
  73. Arguments:
  74. Exception - Stub generated exception code.
  75. Returns:
  76. NSI status code
  77. --*/
  78. {
  79. #ifdef NTENV
  80. // If an NT access fault was raised, re-raise it.
  81. if (Exception == 0xc0000005)
  82. RpcRaiseException(Exception);
  83. #endif
  84. switch(Exception)
  85. {
  86. case RPC_X_SS_CONTEXT_MISMATCH:
  87. case RPC_X_SS_IN_NULL_CONTEXT:
  88. case RPC_S_INVALID_BINDING:
  89. return(NSI_S_INVALID_NS_HANDLE);
  90. case RPC_S_OUT_OF_MEMORY:
  91. return(NSI_S_OUT_OF_MEMORY);
  92. case RPC_X_ENUM_VALUE_OUT_OF_RANGE:
  93. return (NSI_S_UNIMPLEMENTED_API);
  94. }
  95. return(NSI_S_NAME_SERVICE_UNAVAILABLE);
  96. }
  97. WIDE_STRING::WIDE_STRING(
  98. IN unsigned char * AsciiString OPTIONAL
  99. )
  100. /*++
  101. Routine Description:
  102. Make a UNICODE string from an ASCII string.
  103. Arguments:
  104. AsciiString - 8 bit string to widen to 16 bits.
  105. Returns:
  106. String is set to new value. If there was an allocation error, then
  107. the value is set to AllocError.
  108. --*/
  109. {
  110. if (!AsciiString)
  111. {
  112. String = 0;
  113. AllocMode = AllocReference;
  114. return;
  115. }
  116. int Size = (strlen((CONST_CHAR *) AsciiString) + 1) * sizeof(unsigned short);
  117. if (! (String = (unsigned short *)I_RpcAllocate(Size)))
  118. {
  119. AllocMode = AllocError;
  120. return;
  121. }
  122. AllocMode = AllocMemory;
  123. #ifdef NTENV
  124. AsciiToUnicodeNT(String, AsciiString);
  125. #else
  126. for (unsigned short *pT = String; *pT++ = *AsciiString++;) ;
  127. #endif
  128. }
  129. #ifndef NTENV
  130. int
  131. UnicodeToAscii(
  132. unsigned short *UnicodeString
  133. )
  134. /*++
  135. Routine Description:
  136. Make a ASCII string from an UNICODE string. This is done in
  137. place so the string becomes ASCII.
  138. Arguments:
  139. UnicodeString - unicode string to convert
  140. Returns:
  141. 1 if conversion was OK, 0 if there was an error.
  142. --*/
  143. {
  144. unsigned char * AsciiString;
  145. for (AsciiString = (unsigned char *) UnicodeString;
  146. *UnicodeString <= 0xff && *UnicodeString; )
  147. *AsciiString++ = *UnicodeString++;
  148. *AsciiString = 0;
  149. return((*UnicodeString == 0)? RPC_S_OK: RPC_S_OK);
  150. }
  151. #endif
  152. void *
  153. #if defined(WIN32)
  154. __cdecl
  155. #endif
  156. operator new(
  157. size_t size
  158. )
  159. {
  160. return(I_RpcAllocate(size));
  161. }
  162. void
  163. #if defined(WIN32)
  164. __cdecl
  165. #endif
  166. operator delete(
  167. void * p
  168. )
  169. {
  170. I_RpcFree(p);
  171. }
  172. void CallExportInit() {}
  173. unsigned char *
  174. CopyString(
  175. IN char * String
  176. )
  177. /*++
  178. Routine Description:
  179. Copy a string.
  180. Arguments:
  181. String - to copy
  182. Returns:
  183. pointer to a copy, Nil if out of memory.
  184. --*/
  185. {
  186. unsigned char * pReturn;
  187. if (!String || !( pReturn = new unsigned char [strlen(String)+1]))
  188. return(0);
  189. return ((unsigned char *) strcpy((char *) pReturn, (CONST_CHAR *) String));
  190. }
  191. void
  192. GetDefaultEntrys(
  193. IN void * Key
  194. )
  195. /*++
  196. Routine Description:
  197. Get the default Entry name and syntax type form the registry.
  198. Arguments:
  199. Key - open registry handle
  200. --*/
  201. {
  202. // While we have the registry open, get the default syntax entrys.
  203. if (! fSyntaxDefaultsLoaded)
  204. {
  205. unsigned char *SyntaxValue;
  206. if (SyntaxValue = RegGetString(Key, "DefaultSyntax"))
  207. {
  208. DefaultSyntax = atoi((char *)SyntaxValue);
  209. delete SyntaxValue;
  210. }
  211. if (SyntaxValue = RegGetString(Key, "DefaultEntry"))
  212. {
  213. DefaultName = new WIDE_STRING(SyntaxValue);
  214. delete SyntaxValue;
  215. }
  216. fSyntaxDefaultsLoaded = 1;
  217. }
  218. }
  219. #if !defined(NTENV) && DBG
  220. void
  221. RtlAssert(
  222. void * FailedAssertion,
  223. void * FileName,
  224. unsigned long LineNumber,
  225. char * Message
  226. )
  227. {
  228. UNUSED(Message);
  229. #if defined(OS212)
  230. printf("Assert failed %s in %s line %ld\n",
  231. FailedAssertion, FileName, LineNumber);
  232. #elif defined(WIN)
  233. char Buffer[300];
  234. sprintf(Buffer, "Assert failed %s in %s line %ld\n",
  235. FailedAssertion, FileName, LineNumber);
  236. OutputDebugString(Buffer);
  237. #endif
  238. }
  239. #endif