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.

380 lines
12 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. NtStatus.c
  5. Abstract:
  6. This module contains code to convert status code types.
  7. Author:
  8. Rita Wong (ritaw) 01-Mar-1991
  9. Revision History:
  10. 03-Apr-1991 JohnRo
  11. Borrowed Rita's WsMapStatus routine to create NetpNtStatusToApiStatus.
  12. 16-Apr-1991 JohnRo
  13. Include other header files for <netlibnt.h>.
  14. 06-May-1991 JohnRo
  15. Avoid NET_API_FUNCTION for non-APIs.
  16. 26-Jul-1991 CliffV
  17. Add the SAM status codes.
  18. 06-Sep-1991 CliffV
  19. Added NetpApiStatusToNtStatus.
  20. 02-Oct-1991 JohnRo
  21. Avoid STATUS_INVALID_CONNECTION duplicate warnings.
  22. 05-Aug-1992 Madana
  23. Add new netlogon error codes.
  24. --*/
  25. //
  26. // These must be included first:
  27. //
  28. #include <nt.h> // IN, NTSTATUS, etc.
  29. #include <windef.h> // DWORD.
  30. #include <lmcons.h> // NET_API_STATUS.
  31. #include <netlibnt.h> // My prototype.
  32. //
  33. // These may be included in any order:
  34. //
  35. #include <debuglib.h> // IF_DEBUG().
  36. #include <lmerr.h> // NERR_ and ERROR_ equates.
  37. #include <netdebug.h> // FORMAT_NTSTATUS, NetpKdPrint(()).
  38. #include <ntstatus.h> // STATUS_ equates.
  39. #include <ntrtl.h>
  40. #ifdef WIN32_CHICAGO
  41. #include "ntcalls.h"
  42. #endif // WIN32_CHICAGO
  43. NET_API_STATUS
  44. NetpNtStatusToApiStatus (
  45. IN NTSTATUS NtStatus
  46. )
  47. /*++
  48. Routine Description:
  49. This function takes an NT status code and maps it to the appropriate
  50. LAN Man error code.
  51. Arguments:
  52. NtStatus - Supplies the NT status.
  53. Return Value:
  54. Returns the appropriate LAN Man error code for the NT status.
  55. --*/
  56. {
  57. NET_API_STATUS error;
  58. IF_DEBUG(NTSTATUS) {
  59. #ifndef WIN32_CHICAGO
  60. NetpKdPrint(( " NT status is " FORMAT_NTSTATUS "\n", NtStatus ));
  61. #else // WIN32_CHICAGO
  62. NlPrint(( NL_MISC, " NT status is " FORMAT_NTSTATUS "\n", NtStatus ));
  63. #endif // WIN32_CHICAGO
  64. }
  65. //
  66. // A small optimization for the most common case.
  67. //
  68. if ( NtStatus == STATUS_SUCCESS ) {
  69. return NERR_Success;
  70. }
  71. switch ( NtStatus ) {
  72. case STATUS_BUFFER_TOO_SMALL :
  73. return NERR_BufTooSmall;
  74. case STATUS_FILES_OPEN :
  75. return NERR_OpenFiles;
  76. case STATUS_CONNECTION_IN_USE :
  77. return NERR_DevInUse;
  78. case STATUS_INVALID_LOGON_HOURS :
  79. return NERR_InvalidLogonHours;
  80. case STATUS_INVALID_WORKSTATION :
  81. return NERR_InvalidWorkstation;
  82. case STATUS_PASSWORD_EXPIRED :
  83. return NERR_PasswordExpired;
  84. case STATUS_ACCOUNT_EXPIRED :
  85. return NERR_AccountExpired;
  86. case STATUS_REDIRECTOR_NOT_STARTED :
  87. return NERR_NetNotStarted;
  88. case STATUS_GROUP_EXISTS:
  89. return NERR_GroupExists;
  90. case STATUS_INTERNAL_DB_CORRUPTION:
  91. return NERR_InvalidDatabase;
  92. case STATUS_INVALID_ACCOUNT_NAME:
  93. return NERR_BadUsername;
  94. case STATUS_INVALID_DOMAIN_ROLE:
  95. case STATUS_INVALID_SERVER_STATE:
  96. case STATUS_BACKUP_CONTROLLER:
  97. return NERR_NotPrimary;
  98. case STATUS_INVALID_DOMAIN_STATE:
  99. return NERR_ACFNotLoaded;
  100. case STATUS_MEMBER_IN_GROUP:
  101. return NERR_UserInGroup;
  102. case STATUS_MEMBER_NOT_IN_GROUP:
  103. return NERR_UserNotInGroup;
  104. case STATUS_NONE_MAPPED:
  105. case STATUS_NO_SUCH_GROUP:
  106. return NERR_GroupNotFound;
  107. case STATUS_SPECIAL_GROUP:
  108. case STATUS_MEMBERS_PRIMARY_GROUP:
  109. return NERR_SpeGroupOp;
  110. case STATUS_USER_EXISTS:
  111. return NERR_UserExists;
  112. case STATUS_NO_SUCH_USER:
  113. return NERR_UserNotFound;
  114. case STATUS_PRIVILEGE_NOT_HELD:
  115. return ERROR_ACCESS_DENIED;
  116. case STATUS_LOGON_SERVER_CONFLICT:
  117. return NERR_LogonServerConflict;
  118. case STATUS_TIME_DIFFERENCE_AT_DC:
  119. return NERR_TimeDiffAtDC;
  120. case STATUS_SYNCHRONIZATION_REQUIRED:
  121. return NERR_SyncRequired;
  122. case STATUS_WRONG_PASSWORD_CORE:
  123. return NERR_BadPasswordCore;
  124. case STATUS_DOMAIN_CONTROLLER_NOT_FOUND:
  125. return NERR_DCNotFound;
  126. case STATUS_PASSWORD_RESTRICTION:
  127. return NERR_PasswordTooShort;
  128. case STATUS_ALREADY_DISCONNECTED:
  129. return NERR_Success;
  130. default:
  131. //
  132. // Use the system routine to do the mapping to ERROR_ codes.
  133. //
  134. #ifndef WIN32_CHICAGO
  135. error = RtlNtStatusToDosError( NtStatus );
  136. if ( error != (NET_API_STATUS)NtStatus ) {
  137. return error;
  138. }
  139. #endif // WIN32_CHICAGO
  140. //
  141. // Could not map the NT status to anything appropriate.
  142. //
  143. #if DBG
  144. DbgPrint( " Unmapped NT status is " FORMAT_NTSTATUS "\n", NtStatus);
  145. #endif
  146. return NERR_InternalError;
  147. }
  148. } // NetpNtStatusToApiStatus
  149. //
  150. // Map of Network (DOS) status codes to NT status codes
  151. //
  152. DBGSTATIC
  153. struct {
  154. NET_API_STATUS NetStatus;
  155. NTSTATUS NtStatus;
  156. } ErrorMap[] =
  157. {
  158. { NERR_Success, STATUS_SUCCESS },
  159. { ERROR_ACCESS_DENIED, STATUS_ACCESS_DENIED},
  160. { ERROR_ADAP_HDW_ERR, STATUS_ADAPTER_HARDWARE_ERROR},
  161. { ERROR_ALREADY_EXISTS, STATUS_OBJECT_NAME_COLLISION},
  162. { ERROR_ARITHMETIC_OVERFLOW, STATUS_INTEGER_OVERFLOW},
  163. { ERROR_BAD_DEV_TYPE, STATUS_BAD_DEVICE_TYPE},
  164. { ERROR_BAD_EXE_FORMAT, STATUS_INVALID_IMAGE_FORMAT},
  165. { ERROR_BAD_LENGTH, STATUS_DATA_ERROR},
  166. { ERROR_BAD_NETPATH, STATUS_BAD_NETWORK_PATH},
  167. { ERROR_BAD_NET_NAME, STATUS_BAD_NETWORK_NAME},
  168. { ERROR_BAD_NET_RESP, STATUS_INVALID_NETWORK_RESPONSE},
  169. { ERROR_BAD_PATHNAME, STATUS_OBJECT_PATH_SYNTAX_BAD},
  170. { ERROR_BAD_PIPE, STATUS_INVALID_PIPE_STATE},
  171. { ERROR_BAD_REM_ADAP, STATUS_BAD_REMOTE_ADAPTER},
  172. { ERROR_BUFFER_OVERFLOW, STATUS_BUFFER_OVERFLOW},
  173. { ERROR_BUSY, STATUS_DEVICE_BUSY},
  174. { ERROR_CRC, STATUS_CRC_ERROR},
  175. { ERROR_CURRENT_DIRECTORY, STATUS_DIRECTORY_NOT_EMPTY},
  176. { ERROR_DEV_NOT_EXIST, STATUS_DEVICE_DOES_NOT_EXIST},
  177. { ERROR_DIRECTORY, STATUS_NOT_A_DIRECTORY},
  178. { ERROR_DISK_FULL, STATUS_DISK_FULL},
  179. { ERROR_DUP_NAME, STATUS_DUPLICATE_NAME},
  180. { ERROR_EAS_DIDNT_FIT, STATUS_EA_TOO_LARGE},
  181. { ERROR_EAS_NOT_SUPPORTED, STATUS_EAS_NOT_SUPPORTED},
  182. { ERROR_FILE_NOT_FOUND, STATUS_NO_SUCH_FILE},
  183. { ERROR_GEN_FAILURE, STATUS_UNSUCCESSFUL},
  184. { ERROR_HANDLE_EOF, STATUS_END_OF_FILE},
  185. { ERROR_INVALID_ADDRESS, STATUS_MEMORY_NOT_ALLOCATED},
  186. { ERROR_INVALID_EA_NAME, STATUS_INVALID_EA_NAME},
  187. { ERROR_INVALID_FUNCTION, STATUS_NOT_IMPLEMENTED},
  188. { ERROR_INVALID_HANDLE, STATUS_INVALID_HANDLE},
  189. { ERROR_INVALID_NAME, STATUS_OBJECT_NAME_INVALID},
  190. { ERROR_INVALID_PARAMETER, STATUS_INVALID_PARAMETER},
  191. { ERROR_INVALID_PASSWORD, STATUS_WRONG_PASSWORD},
  192. { ERROR_IO_PENDING, STATUS_PENDING},
  193. { ERROR_LOCK_VIOLATION, STATUS_LOCK_NOT_GRANTED},
  194. { ERROR_LOGON_TYPE_NOT_GRANTED, STATUS_LOGON_TYPE_NOT_GRANTED},
  195. { ERROR_NETNAME_DELETED, STATUS_NETWORK_NAME_DELETED},
  196. { ERROR_NETWORK_ACCESS_DENIED, STATUS_NETWORK_ACCESS_DENIED},
  197. { ERROR_NETWORK_BUSY, STATUS_NETWORK_BUSY},
  198. { ERROR_NETWORK_UNREACHABLE, STATUS_NETWORK_UNREACHABLE},
  199. { ERROR_NET_WRITE_FAULT, STATUS_NET_WRITE_FAULT},
  200. { ERROR_NOACCESS, STATUS_ACCESS_VIOLATION},
  201. { ERROR_NOT_DOS_DISK, STATUS_DISK_CORRUPT_ERROR},
  202. { ERROR_NOT_ENOUGH_MEMORY, STATUS_NO_MEMORY},
  203. { ERROR_NOT_LOCKED, STATUS_RANGE_NOT_LOCKED},
  204. { ERROR_NOT_OWNER, STATUS_MUTANT_NOT_OWNED},
  205. { ERROR_NOT_READY, STATUS_DEVICE_OFF_LINE},
  206. { ERROR_NOT_SAME_DEVICE, STATUS_NOT_SAME_DEVICE},
  207. { ERROR_NOT_SUPPORTED, STATUS_NOT_SUPPORTED},
  208. { ERROR_NO_DATA, STATUS_PIPE_CLOSING},
  209. { ERROR_NO_MORE_FILES, STATUS_NO_MORE_FILES},
  210. { ERROR_NO_MORE_ITEMS, STATUS_NO_MORE_EAS},
  211. { ERROR_NO_SPOOL_SPACE, STATUS_NO_SPOOL_SPACE},
  212. { ERROR_OUT_OF_PAPER, STATUS_DEVICE_PAPER_EMPTY},
  213. { ERROR_PATH_NOT_FOUND, STATUS_OBJECT_PATH_NOT_FOUND},
  214. { ERROR_PIPE_BUSY, STATUS_PIPE_NOT_AVAILABLE},
  215. { ERROR_PIPE_NOT_CONNECTED, STATUS_PIPE_DISCONNECTED},
  216. { ERROR_PRINTQ_FULL, STATUS_PRINT_QUEUE_FULL},
  217. { ERROR_PRINT_CANCELLED, STATUS_PRINT_CANCELLED},
  218. { ERROR_PROC_NOT_FOUND, STATUS_PROCEDURE_NOT_FOUND},
  219. { ERROR_REDIR_PAUSED, STATUS_REDIRECTOR_PAUSED},
  220. { ERROR_REM_NOT_LIST, STATUS_REMOTE_NOT_LISTENING},
  221. { ERROR_REQ_NOT_ACCEP, STATUS_REQUEST_NOT_ACCEPTED},
  222. { ERROR_SECTOR_NOT_FOUND, STATUS_NONEXISTENT_SECTOR},
  223. { ERROR_SEM_TIMEOUT, STATUS_IO_TIMEOUT},
  224. { ERROR_SHARING_PAUSED, STATUS_SHARING_PAUSED},
  225. { ERROR_SHARING_VIOLATION, STATUS_SHARING_VIOLATION},
  226. { ERROR_SWAPERROR, STATUS_IN_PAGE_ERROR},
  227. { ERROR_TOO_MANY_CMDS, STATUS_TOO_MANY_COMMANDS},
  228. { ERROR_TOO_MANY_NAMES, STATUS_TOO_MANY_NAMES},
  229. { ERROR_TOO_MANY_OPEN_FILES, STATUS_TOO_MANY_OPENED_FILES},
  230. { ERROR_TOO_MANY_POSTS, STATUS_SEMAPHORE_LIMIT_EXCEEDED},
  231. { ERROR_TOO_MANY_SESS, STATUS_TOO_MANY_SESSIONS},
  232. { ERROR_UNEXP_NET_ERR, STATUS_UNEXPECTED_NETWORK_ERROR},
  233. { ERROR_VC_DISCONNECTED, STATUS_VIRTUAL_CIRCUIT_CLOSED},
  234. { ERROR_WRONG_DISK, STATUS_WRONG_VOLUME},
  235. { ERROR_NETLOGON_NOT_STARTED, STATUS_NETLOGON_NOT_STARTED},
  236. { ERROR_ACCOUNT_EXPIRED, STATUS_ACCOUNT_EXPIRED},
  237. { ERROR_ACCOUNT_LOCKED_OUT, STATUS_ACCOUNT_LOCKED_OUT},
  238. { ERROR_PASSWORD_MUST_CHANGE, STATUS_PASSWORD_MUST_CHANGE },
  239. { ERROR_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT, STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT},
  240. { ERROR_NOLOGON_WORKSTATION_TRUST_ACCOUNT, STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT},
  241. { ERROR_NOLOGON_SERVER_TRUST_ACCOUNT, STATUS_NOLOGON_SERVER_TRUST_ACCOUNT},
  242. { ERROR_DOMAIN_TRUST_INCONSISTENT, STATUS_DOMAIN_TRUST_INCONSISTENT},
  243. { ERROR_INVALID_DOMAIN_ROLE, STATUS_INVALID_DOMAIN_ROLE },
  244. { NERR_AccountExpired, STATUS_ACCOUNT_EXPIRED},
  245. { NERR_ACFNotLoaded, STATUS_INVALID_DOMAIN_STATE},
  246. { NERR_ACFNoRoom, STATUS_INTERNAL_DB_ERROR},
  247. { NERR_BadPassword, STATUS_WRONG_PASSWORD},
  248. { NERR_BadUsername, STATUS_INVALID_ACCOUNT_NAME},
  249. { NERR_BufTooSmall, STATUS_BUFFER_TOO_SMALL},
  250. { NERR_CanNotGrowUASFile, STATUS_INTERNAL_DB_ERROR},
  251. { NERR_DevInUse, STATUS_CONNECTION_IN_USE},
  252. { NERR_GroupExists, STATUS_GROUP_EXISTS},
  253. { NERR_GroupNotFound, STATUS_NONE_MAPPED},
  254. { NERR_InvalidDatabase, STATUS_INTERNAL_DB_CORRUPTION},
  255. { NERR_InvalidLogonHours, STATUS_INVALID_LOGON_HOURS},
  256. { NERR_InvalidWorkstation, STATUS_INVALID_WORKSTATION},
  257. { NERR_NetNotStarted, STATUS_REDIRECTOR_NOT_STARTED},
  258. { NERR_NotPrimary, STATUS_BACKUP_CONTROLLER},
  259. { NERR_OpenFiles, STATUS_FILES_OPEN},
  260. { NERR_PasswordExpired, STATUS_PASSWORD_EXPIRED},
  261. { NERR_SpeGroupOp, STATUS_SPECIAL_GROUP},
  262. { NERR_UserExists, STATUS_USER_EXISTS},
  263. { NERR_UserInGroup, STATUS_MEMBER_IN_GROUP},
  264. { NERR_UserNotInGroup, STATUS_MEMBER_NOT_IN_GROUP},
  265. { NERR_UserNotFound, STATUS_NO_SUCH_USER },
  266. { NERR_LogonServerConflict, STATUS_LOGON_SERVER_CONFLICT},
  267. { NERR_TimeDiffAtDC, STATUS_TIME_DIFFERENCE_AT_DC},
  268. { NERR_SyncRequired, STATUS_SYNCHRONIZATION_REQUIRED},
  269. { NERR_DCNotFound, STATUS_DOMAIN_CONTROLLER_NOT_FOUND},
  270. { NERR_WkstaNotStarted, RPC_NT_SERVER_UNAVAILABLE },
  271. { NERR_ServerNotStarted, RPC_NT_SERVER_UNAVAILABLE },
  272. { NERR_ServiceNotInstalled, RPC_NT_SERVER_UNAVAILABLE },
  273. { NERR_PasswordTooShort, STATUS_PASSWORD_RESTRICTION },
  274. { NERR_PasswordCantChange, STATUS_PASSWORD_RESTRICTION },
  275. { NERR_PasswordTooRecent, STATUS_PASSWORD_RESTRICTION },
  276. };
  277. NTSTATUS
  278. NetpApiStatusToNtStatus(
  279. NET_API_STATUS NetStatus
  280. )
  281. /*++
  282. Routine Description:
  283. Convert a Network (DOS) status code to the NT equivalent.
  284. Arguments:
  285. NetStatus - The Network status code to convert
  286. Return Value:
  287. The corresponding NT status code.
  288. --*/
  289. {
  290. DWORD i;
  291. //
  292. // Loop trying to find the matching status code.
  293. //
  294. for ( i=0; i<sizeof(ErrorMap) / sizeof(ErrorMap[0]); i++) {
  295. if (ErrorMap[i].NetStatus == NetStatus) {
  296. return ErrorMap[i].NtStatus;
  297. }
  298. }
  299. return STATUS_INTERNAL_ERROR;
  300. }