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.

215 lines
4.3 KiB

  1. #define NL_MAX_DNS_LABEL_LENGTH 63
  2. #include <nt.h>
  3. #include <ntrtl.h>
  4. #include <nturtl.h>
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <shellapi.h>
  9. // #include <winsock2.h>
  10. // #include <dnsapi.h>
  11. #include <lmcons.h>
  12. #include <lmerr.h>
  13. #include <ismapi.h>
  14. #include <rpc.h>
  15. #include <ntdsapi.h>
  16. #include <ntdsa.h>
  17. // #include <dnssubr.h>
  18. #include <nldebug.h>
  19. // #include <tstring.h>
  20. //
  21. // Grab random stuff needed from Netlogon's environment.
  22. //
  23. LPWSTR NlGlobalUnicodeSiteName;
  24. BOOLEAN NlGlobalMemberWorkstation = FALSE;
  25. CRITICAL_SECTION NlGlobalLogFileCritSect;
  26. #define MAX_PRINTF_LEN 1024 // Arbitrary.
  27. VOID
  28. NlPrintRoutine(
  29. IN DWORD DebugFlag,
  30. IN LPSTR Format,
  31. ...
  32. )
  33. {
  34. va_list arglist;
  35. char OutputBuffer[MAX_PRINTF_LEN];
  36. //
  37. // Put a the information requested by the caller onto the line
  38. //
  39. va_start(arglist, Format);
  40. (VOID) vsprintf(OutputBuffer, Format, arglist);
  41. va_end(arglist);
  42. printf( "%s", OutputBuffer );
  43. return;
  44. UNREFERENCED_PARAMETER( DebugFlag );
  45. }
  46. VOID
  47. NlAssertFailed(
  48. IN PVOID FailedAssertion,
  49. IN PVOID FileName,
  50. IN ULONG LineNumber,
  51. IN PCHAR Message OPTIONAL
  52. )
  53. {
  54. printf( "\n*** Assertion failed: %s%s\n*** Source File: %s, line %ld\n\n",
  55. Message ? Message : "",
  56. FailedAssertion,
  57. FileName,
  58. LineNumber
  59. );
  60. }
  61. BOOL
  62. NlCaptureSiteName(
  63. WCHAR CapturedSiteName[NL_MAX_DNS_LABEL_LENGTH+1]
  64. )
  65. /*++
  66. Routine Description:
  67. Capture the current sitename of the site this machine is in.
  68. Arguments:
  69. CapturedSiteName - Returns the name of the site this machine is in.
  70. Return Value:
  71. TRUE - if there is a site name.
  72. FALSE - if there is no site name.
  73. --*/
  74. {
  75. BOOL RetVal;
  76. if ( NlGlobalUnicodeSiteName == NULL ) {
  77. CapturedSiteName[0] = L'\0';
  78. RetVal = FALSE;
  79. } else {
  80. wcscpy( CapturedSiteName, NlGlobalUnicodeSiteName );
  81. RetVal = TRUE;
  82. }
  83. return RetVal;
  84. }
  85. NTSTATUS
  86. GetConfigurationName(
  87. DWORD which,
  88. DWORD *pcbName,
  89. DSNAME *pName)
  90. /*++
  91. Description:
  92. Routine for in-process clients like LSA to learn about various names
  93. we have cached in gAnchor.
  94. This routine intentionally does not require a THSTATE or DBPOS.
  95. Arguments:
  96. which - Identifies a DSCONFIGNAME value.
  97. pcbName - On input holds the byte count of the pName buffer. On
  98. STATUS_BUFFER_TOO_SMALL error returns the count of bytes required.
  99. pName - Pointer to user provided output buffer.
  100. Return Values:
  101. STATUS_SUCCESS on success.
  102. STATUS_INVALID_PARAMETER on bad parameter.
  103. STATUS_BUFFER_TOO_SMALL if buffer is too small.
  104. STATUS_NOT_FOUND if we don't have the name. Note that this can
  105. happen if caller is too early in the boot cycle.
  106. --*/
  107. {
  108. ULONG Length;
  109. #define MAGIC L"CN=Configuration,DC=cliffvdom,DC=nttest,DC=microsoft,DC=com"
  110. Length = sizeof(DSNAME) + sizeof(MAGIC);
  111. if ( *pcbName < Length ) {
  112. *pcbName = Length;
  113. return(STATUS_BUFFER_TOO_SMALL);
  114. }
  115. if ( pName != NULL ) {
  116. pName->NameLen = sizeof(MAGIC) - sizeof(WCHAR);
  117. wcscpy( pName->StringName, MAGIC );
  118. } else {
  119. return( STATUS_INVALID_PARAMETER );
  120. }
  121. return(STATUS_SUCCESS);
  122. }
  123. _cdecl
  124. main(int argc, char **argv)
  125. {
  126. NET_API_STATUS NetStatus;
  127. LPWSTR CommandLine;
  128. LPWSTR *argvw;
  129. int argcw;
  130. //
  131. // Get the command line in Unicode
  132. //
  133. CommandLine = GetCommandLine();
  134. argvw = CommandLineToArgvW( CommandLine, &argcw );
  135. if ( argvw == NULL ) {
  136. fprintf( stderr, "Can't convert command line to Unicode: %ld\n", GetLastError() );
  137. return 1;
  138. }
  139. //
  140. // Set the site name.
  141. //
  142. if ( argcw != 2 ) {
  143. // Usage:
  144. printf( "Usage: %ws <SiteDcIsIn>\n", argv[0]);
  145. return -1;
  146. }
  147. NlGlobalUnicodeSiteName = argvw[1];
  148. //
  149. // Misc environment initialization
  150. //
  151. RtlInitializeCriticalSection( &NlGlobalLogFileCritSect );
  152. //
  153. // Compute the site coverage.
  154. //
  155. NlSitesUpdateSiteCoverage( L"cliffvdom.nttest.microsoft.com", TRUE );
  156. return 0;
  157. }