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.

251 lines
4.6 KiB

  1. /*--
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. anydc.c
  5. Abstract:
  6. Test program for the Finding a DC in any domain
  7. Author:
  8. 04-Sep-1995 (cliffv)
  9. Environment:
  10. User mode only.
  11. Contains NT-specific code.
  12. Requires ANSI C extensions: slash-slash comments, long external names.
  13. Revision History:
  14. --*/
  15. //
  16. // Common include files.
  17. //
  18. #include <nt.h>
  19. #include <ntrtl.h>
  20. #include <nturtl.h>
  21. #undef DOMAIN_ALL_ACCESS // defined in both ntsam.h and ntwinapi.h
  22. #include <ntsam.h>
  23. #include <ntlsa.h>
  24. #include <windows.h>
  25. #include <lmcons.h>
  26. // #include <accessp.h>
  27. //#include <icanon.h>
  28. #include <lmerr.h>
  29. // #include <lmwksta.h>
  30. // #include <lmaccess.h>
  31. // #include <lmapibuf.h>
  32. // #include <lmremutl.h> // NetpRemoteComputerSupports(), SUPPORTS_ stuff
  33. // #include <lmsvc.h> // SERVICE_WORKSTATION.
  34. #include <lmuse.h> // NetUseDel()
  35. // #include <netlogon.h> // Needed by logonp.h
  36. // #include <logonp.h> // I_NetGetDCList()
  37. // #include <names.h>
  38. // #include <netdebug.h>
  39. #include <netlib.h>
  40. // #include <netlibnt.h>
  41. // #include <winnetwk.h>
  42. // #include <secobj.h>
  43. #include <stddef.h>
  44. #include <stdio.h>
  45. #include <uasp.h>
  46. // #include <rpc.h> // Needed by NetRpc.h
  47. // #include <netrpc.h> // My prototype, NET_REMOTE_FLAG_ equates.
  48. // #include <rpcutil.h> // NetpRpcStatusToApiStatus().
  49. #include <tstring.h> // NetAllocWStrFromStr
  50. #include <wtypes.h>
  51. VOID
  52. PrintStatus(
  53. NET_API_STATUS NetStatus
  54. )
  55. /*++
  56. Routine Description:
  57. Print a net status code.
  58. Arguments:
  59. NetStatus - The net status code to print.
  60. Return Value:
  61. None
  62. --*/
  63. {
  64. printf( "Status = %lu 0x%lx", NetStatus, NetStatus );
  65. switch (NetStatus) {
  66. case NERR_Success:
  67. printf( " NERR_Success" );
  68. break;
  69. case NERR_DCNotFound:
  70. printf( " NERR_DCNotFound" );
  71. break;
  72. case NERR_NetNotStarted:
  73. printf( " NERR_NetNotStarted" );
  74. break;
  75. case NERR_WkstaNotStarted:
  76. printf( " NERR_WkstaNotStarted" );
  77. break;
  78. case NERR_ServerNotStarted:
  79. printf( " NERR_ServerNotStarted" );
  80. break;
  81. case NERR_BrowserNotStarted:
  82. printf( " NERR_BrowserNotStarted" );
  83. break;
  84. case NERR_ServiceNotInstalled:
  85. printf( " NERR_ServiceNotInstalled" );
  86. break;
  87. case NERR_BadTransactConfig:
  88. printf( " NERR_BadTransactConfig" );
  89. break;
  90. default:
  91. printf( " %ld", NetStatus );
  92. break;
  93. }
  94. printf( "\n" );
  95. }
  96. VOID
  97. NlpDumpSid(
  98. IN PSID Sid OPTIONAL
  99. )
  100. /*++
  101. Routine Description:
  102. Dumps a SID
  103. Arguments:
  104. DebugFlag - Debug flag to pass on to NlPrintRoutine
  105. Sid - SID to output
  106. Return Value:
  107. none
  108. --*/
  109. {
  110. //
  111. // Output the SID
  112. //
  113. if ( Sid == NULL ) {
  114. printf( "(null)\n" );
  115. } else {
  116. UNICODE_STRING SidString;
  117. NTSTATUS Status;
  118. Status = RtlConvertSidToUnicodeString( &SidString, Sid, TRUE );
  119. if ( !NT_SUCCESS(Status) ) {
  120. printf( "Invalid 0x%lX\n", Status );
  121. } else {
  122. printf( "%wZ\n", &SidString );
  123. RtlFreeUnicodeString( &SidString );
  124. }
  125. }
  126. }
  127. int __cdecl
  128. main(
  129. IN int argc,
  130. IN char ** argv
  131. )
  132. /*++
  133. Routine Description:
  134. Call UaspOpenDomainWithDomainName with first arguement
  135. Arguments:
  136. argc - the number of command-line arguments.
  137. argv - an array of pointers to the arguments.
  138. Return Value:
  139. Exit status
  140. --*/
  141. {
  142. NET_API_STATUS NetStatus;
  143. LPWSTR DomainName;
  144. BOOL AccountDomain;
  145. SAM_HANDLE DomainHandle;
  146. PSID DomainId;
  147. //
  148. // Validate the argument count
  149. //
  150. if ( argc != 2 && argc != 3) {
  151. fprintf( stderr, "Usage: anydc <DomainName> [Builtin]\n");
  152. return 1;
  153. }
  154. //
  155. // Convert the args to unicode
  156. //
  157. DomainName = NetpAllocWStrFromStr( argv[1] );
  158. AccountDomain = argc < 3;
  159. //
  160. // Find a DC
  161. //
  162. NetStatus = UaspOpenDomainWithDomainName(
  163. DomainName,
  164. 0,
  165. AccountDomain,
  166. &DomainHandle,
  167. &DomainId );
  168. PrintStatus( NetStatus );
  169. if ( NetStatus == NERR_Success ) {
  170. printf( "Sid is: ");
  171. NlpDumpSid( DomainId );
  172. UaspCloseDomain( DomainHandle );
  173. }
  174. }