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.

343 lines
6.1 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  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. };
  58. UNSIGNED16
  59. MapException(
  60. IN RPC_STATUS Exception
  61. )
  62. /*++
  63. Routine Description:
  64. Map a RPC exception to a NSI status code.
  65. Arguments:
  66. Exception - Stub generated exception code.
  67. Returns:
  68. NSI status code
  69. --*/
  70. {
  71. #ifdef NTENV
  72. // If an NT access fault was raised, re-raise it.
  73. if (Exception == 0xc0000005)
  74. RpcRaiseException(Exception);
  75. #endif
  76. switch(Exception)
  77. {
  78. case RPC_X_SS_CONTEXT_MISMATCH:
  79. case RPC_X_SS_IN_NULL_CONTEXT:
  80. return(NSI_S_INVALID_NS_HANDLE);
  81. case RPC_S_OUT_OF_MEMORY:
  82. return(NSI_S_OUT_OF_MEMORY);
  83. case RPC_X_ENUM_VALUE_OUT_OF_RANGE:
  84. return (NSI_S_UNIMPLEMENTED_API);
  85. }
  86. return(NSI_S_NAME_SERVICE_UNAVAILABLE);
  87. }
  88. WIDE_STRING::WIDE_STRING(
  89. IN unsigned char * AsciiString OPTIONAL
  90. )
  91. /*++
  92. Routine Description:
  93. Make a UNICODE string from an ASCII string.
  94. Arguments:
  95. AsciiString - 8 bit string to widen to 16 bits.
  96. Returns:
  97. String is set to new value. If there was an allocation error, then
  98. the value is set to AllocError.
  99. --*/
  100. {
  101. if (!AsciiString)
  102. {
  103. String = 0;
  104. AllocMode = AllocReference;
  105. return;
  106. }
  107. int Size = (strlen((CONST_CHAR *) AsciiString) + 1) * sizeof(unsigned short);
  108. if (! (String = (unsigned short *)I_RpcAllocate(Size)))
  109. {
  110. AllocMode = AllocError;
  111. return;
  112. }
  113. AllocMode = AllocMemory;
  114. #ifdef NTENV
  115. AsciiToUnicodeNT(String, AsciiString);
  116. #else
  117. for (unsigned short *pT = String; *pT++ = *AsciiString++;) ;
  118. #endif
  119. }
  120. #ifndef NTENV
  121. int
  122. UnicodeToAscii(
  123. unsigned short *UnicodeString
  124. )
  125. /*++
  126. Routine Description:
  127. Make a ASCII string from an UNICODE string. This is done in
  128. place so the string becomes ASCII.
  129. Arguments:
  130. UnicodeString - unicode string to convert
  131. Returns:
  132. 1 if conversion was OK, 0 if there was an error.
  133. --*/
  134. {
  135. unsigned char * AsciiString;
  136. for (AsciiString = (unsigned char *) UnicodeString;
  137. *UnicodeString <= 0xff && *UnicodeString; )
  138. *AsciiString++ = *UnicodeString++;
  139. *AsciiString = 0;
  140. return((*UnicodeString == 0)? RPC_S_OK: RPC_S_OK);
  141. }
  142. #endif
  143. void *
  144. #if defined(WIN32)
  145. _CRTAPI1
  146. #endif
  147. operator new(
  148. size_t size
  149. )
  150. {
  151. return(I_RpcAllocate(size));
  152. }
  153. void
  154. #if defined(WIN32)
  155. _CRTAPI1
  156. #endif
  157. operator delete(
  158. void * p
  159. )
  160. {
  161. I_RpcFree(p);
  162. }
  163. extern "C" {
  164. void CallExportInit() {}
  165. unsigned char *
  166. CopyString(
  167. IN char * String
  168. )
  169. /*++
  170. Routine Description:
  171. Copy a string.
  172. Arguments:
  173. String - to copy
  174. Returns:
  175. pointer to a copy, Nil if out of memory.
  176. --*/
  177. {
  178. unsigned char * pReturn;
  179. if (!String || !( pReturn = new unsigned char [strlen(String)+1]))
  180. return(0);
  181. return ((unsigned char *) strcpy((char *) pReturn, (CONST_CHAR *) String));
  182. }
  183. } // extern "C"
  184. void
  185. GetDefaultEntrys(
  186. IN void * Key
  187. )
  188. /*++
  189. Routine Description:
  190. Get the default Entry name and syntax type form the registry.
  191. Arguments:
  192. Key - open registry handle
  193. --*/
  194. {
  195. // While we have the registry open, get the default syntax entrys.
  196. if (! fSyntaxDefaultsLoaded)
  197. {
  198. unsigned char *SyntaxValue;
  199. if (SyntaxValue = RegGetString(Key, "DefaultSyntax"))
  200. {
  201. DefaultSyntax = atoi((char *)SyntaxValue);
  202. delete SyntaxValue;
  203. }
  204. if (SyntaxValue = RegGetString(Key, "DefaultEntry"))
  205. {
  206. DefaultName = new WIDE_STRING(SyntaxValue);
  207. delete SyntaxValue;
  208. }
  209. fSyntaxDefaultsLoaded = 1;
  210. }
  211. }
  212. #if !defined(NTENV) && DBG
  213. void
  214. RtlAssert(
  215. void * FailedAssertion,
  216. void * FileName,
  217. unsigned long LineNumber,
  218. char * Message
  219. )
  220. {
  221. UNUSED(Message);
  222. #if defined(OS212)
  223. printf("Assert failed %s in %s line %ld\n",
  224. FailedAssertion, FileName, LineNumber);
  225. #elif defined(WIN)
  226. char Buffer[300];
  227. sprintf(Buffer, "Assert failed %s in %s line %ld\n",
  228. FailedAssertion, FileName, LineNumber);
  229. OutputDebugString(Buffer);
  230. #endif
  231. }
  232. #endif