Source code of Windows XP (NT5)
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.

207 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. modify.c
  5. Abstract:
  6. This is for modifying boot.ini and DS entries
  7. Author:
  8. Sean Selitrennikoff - 5/4/98
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #if 0
  14. WCHAR BootPath[TMP_BUFFER_SIZE];
  15. WCHAR ComputerName[TMP_BUFFER_SIZE];
  16. WCHAR DsPath[TMP_BUFFER_SIZE];
  17. NTSTATUS
  18. ModifyDSEntries(
  19. IN PVOID pBuffer,
  20. IN ULONG Length
  21. )
  22. /*++
  23. Routine Description:
  24. This routine does all the munging of DS entries to make this machine look
  25. like a remote boot client.
  26. Arguments:
  27. pBuffer - Pointer to any arguments passed in the to do item.
  28. Length - Length, in bytes of the arguments.
  29. Return Value:
  30. STATUS_SUCCESS if it completes the to do item properly.
  31. --*/
  32. {
  33. NTSTATUS Status;
  34. PLDAP LdapHandle;
  35. ULONG TmpUlong;
  36. ULONG LdapError;
  37. LDAPMod FilePathMod;
  38. WCHAR *AttrValues1[2];
  39. PLDAPMod Modifiers[2];
  40. PIMIRROR_MODIFY_DS_INFO pModifyInfo;
  41. DWORD Error;
  42. HKEY hkey;
  43. PWCHAR pTmp;
  44. HANDLE Handle;
  45. IO_STATUS_BLOCK IoStatus;
  46. UNICODE_STRING UnicodeString;
  47. OBJECT_ATTRIBUTES ObjectAttributes;
  48. PUCHAR pch;
  49. DWORD NameLength;
  50. DWORD SidLength;
  51. DWORD DomainLength;
  52. DWORD RequestSize;
  53. SID_NAME_USE snu;
  54. PDOMAIN_CONTROLLER_INFO DCInfo;
  55. IMirrorNowDoing(PatchDSEntries, NULL);
  56. if (Length != sizeof(IMIRROR_MODIFY_DS_INFO)) {
  57. IMirrorHandleError(ERROR_DS_SERVER_DOWN, PatchDSEntries);
  58. return ERROR_DS_SERVER_DOWN;
  59. }
  60. pModifyInfo = (PIMIRROR_MODIFY_DS_INFO)pBuffer;
  61. //
  62. // Verify that server exists.
  63. //
  64. Status = VerifyServerExists(pModifyInfo->ServerName,
  65. (wcslen(pModifyInfo->ServerName) + 1) * sizeof(WCHAR)
  66. );
  67. if (!NT_SUCCESS(Status)) {
  68. IMirrorHandleError(Status, PatchDSEntries);
  69. return Status;
  70. }
  71. //
  72. // Get the computer name
  73. //
  74. NameLength = TMP_BUFFER_SIZE;
  75. if (!GetComputerName(ComputerName, &NameLength)) {
  76. IMirrorHandleError(STATUS_NO_MEMORY, PatchDSEntries);
  77. return STATUS_NO_MEMORY;
  78. }
  79. ComputerName[NameLength] = UNICODE_NULL;
  80. NameLength++;
  81. //
  82. //
  83. // Before doing anything else, setup the values we are going to use later.
  84. //
  85. //
  86. //
  87. // Setup BootPath
  88. //
  89. swprintf(BootPath, L"%ws\\Clients\\%ws\\startrom.com", pModifyInfo->ServerName, ComputerName);
  90. //
  91. // Get the path to this machine object
  92. //
  93. TmpUlong = sizeof(DsPath);
  94. if (!GetComputerObjectName(NameFullyQualifiedDN, DsPath, &TmpUlong)) {
  95. Error = GetLastError();
  96. IMirrorHandleError(Error, PatchDSEntries);
  97. return STATUS_UNSUCCESSFUL;
  98. }
  99. //
  100. // Connect to the DS
  101. //
  102. LdapHandle = ldap_init(NULL, LDAP_PORT);
  103. if (LdapHandle == NULL) {
  104. Error = GetLastError();
  105. IMirrorHandleError(Error, PatchDSEntries);
  106. return STATUS_UNSUCCESSFUL;
  107. }
  108. TmpUlong = DS_DIRECTORY_SERVICE_REQUIRED | DS_IP_REQUIRED;
  109. ldap_set_option(LdapHandle, LDAP_OPT_GETDSNAME_FLAGS, &TmpUlong);
  110. TmpUlong = (ULONG) LDAP_OPT_ON;
  111. ldap_set_option(LdapHandle, LDAP_OPT_REFERRALS, (void *)&TmpUlong);
  112. TmpUlong = LDAP_VERSION3;
  113. ldap_set_option(LdapHandle, LDAP_OPT_VERSION, &TmpUlong);
  114. LdapError = ldap_connect(LdapHandle,0);
  115. if (LdapError != LDAP_SUCCESS) {
  116. ldap_unbind(LdapHandle);
  117. IMirrorHandleError(LdapError, PatchDSEntries);
  118. return STATUS_UNSUCCESSFUL;
  119. }
  120. //
  121. // Make the binding
  122. //
  123. LdapError = ldap_bind_s(LdapHandle, NULL, NULL, LDAP_AUTH_NEGOTIATE);
  124. if (LdapError != LDAP_SUCCESS) {
  125. ldap_unbind(LdapHandle);
  126. IMirrorHandleError(LdapError, PatchDSEntries);
  127. return STATUS_UNSUCCESSFUL;
  128. }
  129. //
  130. // Setup the attribute changes
  131. //
  132. FilePathMod.mod_op = LDAP_MOD_REPLACE;
  133. FilePathMod.mod_type = L"netbootMachineFilePath";
  134. FilePathMod.mod_values = AttrValues1;
  135. AttrValues1[0] = BootPath;
  136. AttrValues1[1] = NULL;
  137. Modifiers[0] = &FilePathMod;
  138. Modifiers[1] = NULL;
  139. //
  140. // Submit the changes to the DS
  141. //
  142. LdapError = ldap_modify_s(LdapHandle, DsPath, Modifiers);
  143. ldap_unbind(LdapHandle);
  144. if (LdapError != LDAP_SUCCESS) {
  145. IMirrorHandleError(LdapError, PatchDSEntries);
  146. return STATUS_UNSUCCESSFUL;
  147. }
  148. return STATUS_SUCCESS;
  149. }
  150. #endif