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.

201 lines
6.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999.
  5. //
  6. // File: ACLDiag.cpp
  7. //
  8. // Contents: Defines the entry point for the console application.
  9. //
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. #include "adutils.h"
  14. #include "SecDesc.h"
  15. #include "schema.h"
  16. #include "ChkDeleg.h"
  17. #include "EffRight.h"
  18. CACLDiagComModule _Module;
  19. // Function prototypes
  20. void DisplayHelp ();
  21. // Command-line options string constants
  22. const wstring strSchemaFlag = L"/schema";
  23. const wstring strCheckDelegationFlag = L"/chkdeleg";
  24. const wstring strGetEffectiveFlag = L"/geteffective:";
  25. const wstring strFixDelegationFlag = L"/fixdeleg";
  26. const wstring strTabDelimitedOutputFlag = L"/tdo";
  27. const wstring strLogFlag = L"/log:";
  28. const wstring strHelpFlag = L"/?";
  29. const wstring strSkipDescriptionFlag = L"/skip";
  30. int _cdecl main(int argc, char* argv[])
  31. {
  32. UNREFERENCED_PARAMETER (argv);
  33. // If no arguments provided, display the help
  34. if ( 1 == argc )
  35. {
  36. DisplayHelp ();
  37. return 0;
  38. }
  39. #if DBG
  40. CheckDebugOutputLevel ();
  41. #endif
  42. LPCWSTR * lpServiceArgVectors = 0; // Array of pointers to string
  43. int cArgs = 0; // Count of arguments
  44. size_t lenFlag = strGetEffectiveFlag.length ();
  45. lpServiceArgVectors = (LPCWSTR *)CommandLineToArgvW(GetCommandLineW(), OUT &cArgs);
  46. if (lpServiceArgVectors == NULL)
  47. return NULL;
  48. for (int nToken = 1; nToken < cArgs; nToken++)
  49. {
  50. ASSERT(lpServiceArgVectors[nToken] != NULL);
  51. if ( !lpServiceArgVectors[nToken] )
  52. break;
  53. wstring strToken = lpServiceArgVectors[nToken]; // Copy the string
  54. switch (nToken)
  55. {
  56. case 0: // appName: skip
  57. continue;
  58. case 1: // object name or a help flag
  59. if ( !_wcsnicmp (strHelpFlag.c_str (), strToken.c_str (),
  60. strToken.length ()) )
  61. {
  62. DisplayHelp ();
  63. return 0;
  64. }
  65. else
  66. _Module.SetObjectDN (strToken);
  67. break;
  68. default:
  69. {
  70. size_t lenToken = strToken.length ();
  71. if ( !_wcsnicmp (strSchemaFlag.c_str (), strToken.c_str (),
  72. lenToken))
  73. {
  74. _Module.SetDoSchema ();
  75. }
  76. else if ( !_wcsnicmp (strCheckDelegationFlag.c_str (),
  77. strToken.c_str (), lenToken) )
  78. {
  79. _Module.SetCheckDelegation ();
  80. }
  81. else if ( !_wcsnicmp (strGetEffectiveFlag.c_str (),
  82. strToken.c_str (), lenFlag) )
  83. {
  84. wstring strUserGroup = strToken.substr(lenFlag,
  85. lenToken);
  86. _Module.SetDoGetEffective (strUserGroup);
  87. }
  88. else if ( !_wcsnicmp (strFixDelegationFlag.c_str (),
  89. strToken.c_str (), lenToken) )
  90. {
  91. _Module.SetFixDelegation ();
  92. }
  93. else if ( !_wcsnicmp (strTabDelimitedOutputFlag.c_str (),
  94. strToken.c_str (), lenToken) )
  95. {
  96. _Module.SetTabDelimitedOutput ();
  97. }
  98. else if ( !_wcsnicmp (strLogFlag.c_str (), strToken.c_str (),
  99. lenFlag) )
  100. {
  101. wstring strPath = strToken.substr(lenFlag, lenToken);
  102. _Module.SetDoLog (strPath);
  103. }
  104. else if ( !_wcsnicmp (strSkipDescriptionFlag.c_str (),
  105. strToken.c_str (), lenToken) )
  106. {
  107. _Module.SetSkipDescription ();;
  108. }
  109. else if ( !_wcsnicmp (strHelpFlag.c_str (), strToken.c_str (),
  110. lenToken) )
  111. {
  112. DisplayHelp ();
  113. return 0;
  114. }
  115. else
  116. {
  117. wstring str;
  118. FormatMessage (str, IDS_INVALID_OPTION, strToken.c_str ());
  119. MyWprintf (str.c_str ());
  120. DisplayHelp ();
  121. return 0;
  122. }
  123. }
  124. break;
  125. }
  126. }
  127. LocalFree (lpServiceArgVectors);
  128. HRESULT hr = CoInitialize(NULL);
  129. if ( SUCCEEDED (hr) )
  130. {
  131. hr = _Module.Init ();
  132. if ( SUCCEEDED (hr) )
  133. {
  134. hr = DoSecurityDescription ();
  135. if ( SUCCEEDED (hr) && _Module.DoSchema () )
  136. hr = DoSchemaDiagnosis ();
  137. if ( SUCCEEDED (hr) && _Module.CheckDelegation () )
  138. hr = CheckDelegation ();
  139. if ( SUCCEEDED (hr) && _Module.DoGetEffective () )
  140. hr = EffectiveRightsDiagnosis ();
  141. }
  142. else
  143. DisplayHelp ();
  144. }
  145. else
  146. {
  147. _TRACE (0, L"CoInitialize Failed with %x\n",hr);
  148. return 0;
  149. }
  150. return 0;
  151. }
  152. ///////////////////////////////////////////////////////////////////////////////
  153. //
  154. // Method: DisplayHelp
  155. //
  156. // Print the purpose of the tool and each of the command-line options.
  157. //
  158. ///////////////////////////////////////////////////////////////////////////////
  159. void DisplayHelp ()
  160. {
  161. CWString str;
  162. int helpIDs[] = {IDS_HELP_MAIN,
  163. IDS_HELP_SCHEMA,
  164. IDS_HELP_CHKDELEG,
  165. IDS_HELP_GETEFFECTIVE,
  166. IDS_HELP_CDO,
  167. // IDS_HELP_LOG,
  168. IDS_HELP_SKIP_DESCRIPTION,
  169. 0};
  170. for (int nIndex = 0; helpIDs[nIndex]; nIndex++)
  171. {
  172. str.LoadFromResource (helpIDs[nIndex]);
  173. MyWprintf (str.c_str ());
  174. }
  175. }