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.

289 lines
7.5 KiB

  1. /*++
  2. MISCCMDS.CXX
  3. Copyright (C) 1999 Microsoft Corporation, all rights reserved.
  4. DESCRIPTION: miscellaneous command callbacks and the command vector
  5. Created, May 21, 1999 by DavidCHR.
  6. --*/
  7. #include "Everything.hxx"
  8. /* these are the callback functions invoked by the option parser.
  9. We declare them here so that they can be called from the array
  10. below */
  11. TestFunc
  12. SetDnsDomain, // domain.cxx
  13. AddKdcName, // servers.cxx
  14. AddKpasswdName, // servers.cxx
  15. MapUser, // mapuser.cxx
  16. SetMachinePassword, // below in this file
  17. DumpState, // dmpstate.cxx
  18. ChooseDomain , // domain.cxx
  19. DeleteKdcName, // servers.cxx
  20. DelKpasswdName, // servers.cxx
  21. ChangeViaKpasswd, // support.cxx
  22. SetRealmFlags, // realmflags.cxx
  23. AddRealmFlags, // realmflags.cxx
  24. DelRealmFlags, // realmflags.cxx
  25. ListRealmFlags, // realmflags.cxx
  26. RemoveDomainName, // servers.cxx
  27. PrintHelp; // below in this file
  28. NTSTATUS
  29. SetMachinePassword( LPWSTR * Parameter)
  30. {
  31. NTSTATUS Status = STATUS_SUCCESS;
  32. UNICODE_STRING MachinePassword;
  33. UNICODE_STRING KeyName;
  34. LPWSTR Password;
  35. if ( !ReadOptionallyStarredPassword( Parameter[ 0 ],
  36. PROMPT_FOR_PASSWORD_TWICE,
  37. L"new computer",
  38. &Password ) ) {
  39. return STATUS_UNSUCCESSFUL;
  40. }
  41. printf("Setting computer password\n");
  42. RtlInitUnicodeString(
  43. &MachinePassword,
  44. Password
  45. );
  46. RtlInitUnicodeString(
  47. &KeyName,
  48. L"$MACHINE.ACC"
  49. );
  50. Status = LsaStorePrivateData(
  51. LsaHandle,
  52. &KeyName,
  53. &MachinePassword
  54. );
  55. if (!NT_SUCCESS(Status))
  56. {
  57. printf("Failed to set machine password: 0x%x\n",Status);
  58. }
  59. free( Password );
  60. return(Status);
  61. }
  62. NTSTATUS
  63. SetServer(LPWSTR * Parameter)
  64. {
  65. printf("Targeting server %ws\n",Parameter[0]);
  66. wcscpy(ServerBuffer,Parameter[0]);
  67. ServerName = ServerBuffer;
  68. return(STATUS_SUCCESS);
  69. }
  70. #if DBG /* This function and its corresponding variable
  71. are only useful on debug builds. */
  72. ULONG GlobalDebugFlags = ~DEBUG_OPTIONS;
  73. NTSTATUS
  74. SetDebugFlags( LPWSTR *Params ) {
  75. ASSERT( *Params != NULL );
  76. GlobalDebugFlags = wcstoul( *Params,
  77. 0,
  78. NULL );
  79. printf( "Debug Print Flags set to 0x%x.\n",
  80. GlobalDebugFlags );
  81. return STATUS_SUCCESS;
  82. }
  83. #endif
  84. /*------------------------------------------------------------
  85. Here's the array of callbacks. It's read by the command
  86. line interpreter in main()
  87. ------------------------------------------------------------*/
  88. CommandPair Commands[] = {
  89. // argument argc doNow? argFunction description
  90. {L"/SetDomain", 1, SetDnsDomain, NULL, // renamed -- hidden from help
  91. 0,
  92. NULL, // no arguments
  93. "requires a reboot to take effect" },
  94. {L"/SetRealm", 1, SetDnsDomain, "<DnsDomainName>",
  95. CAN_HAVE_FEWER_ARGUMENTS,
  96. "Makes this computer a member of an RFC1510 Kerberos Realm",
  97. "requires a reboot to take effect" },
  98. {L"/MapUser", 2, MapUser, "<Principal> <Account>",
  99. CAN_HAVE_FEWER_ARGUMENTS,
  100. "Maps a Kerberos Principal ('*' = any principal)\n"
  101. "\tto an account ('*' = an account by same name)"
  102. },
  103. {L"/AddKdc", 1, AddKdcName, "<RealmName> [KdcName]",
  104. CAN_HAVE_MORE_ARGUMENTS,
  105. "Defines a KDC entry for the given realm.\n"
  106. "\tIf KdcName omitted, DNS may be used to locate KDCs.",
  107. "requires a reboot to take effect on pre-SP1 Win2000 computers" },
  108. {L"/DelKdc", 1, DeleteKdcName, "<RealmName> [KdcName]",
  109. CAN_HAVE_MORE_ARGUMENTS,
  110. "deletes a KDC entry for the realm.\n"
  111. "\tIf KdcName omitted, the realm entry itself is deleted.",
  112. "requires a reboot to take effect on pre-SP1 Win2000 computers" },
  113. {L"/AddKpasswd", 2, AddKpasswdName, "<Realmname> <KpasswdName>",
  114. 0, // no flags
  115. "Add Kpasswd server address for a realm",
  116. "requires a reboot to take effect on pre-SP1 Win2000 computers" },
  117. {L"/DelKpasswd", 2, DelKpasswdName, "<Realmname> <KpasswdName>",
  118. 0, // no flags
  119. "Delete Kpasswd server address for a realm",
  120. "requires a reboot to take effect on pre-SP1 Win2000 computers" },
  121. {L"/Server", 1, SetServer, "<Servername>",
  122. DO_COMMAND_IMMEDIATELY,
  123. "specify name of a Windows machine to target the changes."
  124. },
  125. {L"/SetMachPassword", 1, SetMachinePassword, NULL, // renamed; hidden from help
  126. 0, // no flags
  127. NULL, // no description -- this option is depricated.
  128. "requires a reboot to take effect." },
  129. {L"/SetComputerPassword", 1, SetMachinePassword, "<Password>",
  130. 0, // no flags
  131. "Sets the password for the computer's domain account\n"
  132. "\t(or \"host\" principal)",
  133. "requires a reboot to take effect." },
  134. { L"/RemoveRealm", 1, RemoveDomainName, "<RealmName>",
  135. 0, // no flags
  136. "delete all information for this realm from the registry.",
  137. "requires a reboot to take effect on pre-SP1 Win2000 computers" },
  138. {L"/Domain", 1, ChooseDomain, "[DomainName]",
  139. DO_COMMAND_IMMEDIATELY |
  140. CAN_HAVE_FEWER_ARGUMENTS,
  141. "use this domain (if DomainName is unspecified, detect it)" },
  142. {L"/ChangePassword", 2, ChangeViaKpasswd, "<OldPasswd> <NewPasswd>",
  143. DO_COMMAND_IMMEDIATELY,
  144. "Use Kpasswd to change the logged-on user's password.\n"
  145. "\tUse '*' to be prompted for passwords." },
  146. // realm flag stuff:
  147. { L"/ListRealmFlags", 0, ListRealmFlags,
  148. "(no args)",
  149. DO_COMMAND_IMMEDIATELY,
  150. "Lists the available Realm flags that ksetup knows"
  151. },
  152. { L"/SetRealmFlags", 2, SetRealmFlags,
  153. "<realm> <flag> [flag] [flag] [...]",
  154. CAN_HAVE_MORE_ARGUMENTS,
  155. "Sets RealmFlags for a specific realm" },
  156. { L"/AddRealmFlags", 2, AddRealmFlags,
  157. "<realm> <flag> [flag] [flag] [...]",
  158. CAN_HAVE_MORE_ARGUMENTS,
  159. "Adds additional RealmFlags to a realm"
  160. },
  161. { L"/DelRealmFlags", 2, DelRealmFlags,
  162. "<realm> <flag> [flag] [flag] [...]",
  163. CAN_HAVE_MORE_ARGUMENTS,
  164. "Deletes RealmFlags from a realm." },
  165. {L"/DumpState", 0, DumpState,
  166. "(no args)",
  167. 0,
  168. "Analyze the kerberos configuration on the given machine." },
  169. {L"/?", 0, PrintHelp, NULL }, // hidden from help
  170. {L"/help", 0, PrintHelp, NULL }, // hidden from help
  171. #if DBG
  172. {L"/debugflag", 1, SetDebugFlags, "<flags>",
  173. DO_COMMAND_IMMEDIATELY,
  174. "Set debugging flags" },
  175. #endif
  176. };
  177. ULONG cCommands = sizeof( Commands ) / sizeof( Commands[ 0 ] );
  178. NTSTATUS
  179. PrintHelp(LPWSTR * Parameter)
  180. {
  181. ULONG i;
  182. LPSTR pDesc;
  183. printf( "\n"
  184. "USAGE:\n" );
  185. for ( i = 0 ;
  186. i < cCommands ;
  187. i ++ ) {
  188. if ( Commands[ i ].Arguments ) {
  189. printf( "%ws %hs\n",
  190. Commands[ i ].Name,
  191. Commands[ i ].Arguments );
  192. #if 1
  193. if ( Commands[ i ].ExtendedDescription ) {
  194. printf( "\t%hs\n",
  195. Commands[ i ].ExtendedDescription );
  196. }
  197. #else
  198. for ( pDesc = Commands[ i ].ExtendedDescription;
  199. pDesc && *pDesc ;
  200. /* No increment */
  201. ) {
  202. printf( "%-20hs %hs\n",
  203. "",
  204. pDesc );
  205. pDesc = strchr( pDesc, '\0' );
  206. if ( pDesc ) pDesc++;
  207. }
  208. #endif
  209. }
  210. }
  211. return(STATUS_SUCCESS);
  212. }