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.

204 lines
6.6 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 lenEffectiveFlag = strGetEffectiveFlag.length ();
  45. size_t lenLogFlag = strLogFlag.length ();
  46. lpServiceArgVectors = (LPCWSTR *)CommandLineToArgvW(GetCommandLineW(), OUT &cArgs);
  47. if (lpServiceArgVectors == NULL)
  48. return NULL;
  49. for (int nToken = 1; nToken < cArgs; nToken++)
  50. {
  51. ASSERT(lpServiceArgVectors[nToken] != NULL);
  52. if ( !lpServiceArgVectors[nToken] )
  53. break;
  54. wstring strToken = lpServiceArgVectors[nToken]; // Copy the string
  55. switch (nToken)
  56. {
  57. case 0: // appName: skip
  58. continue;
  59. case 1: // object name or a help flag
  60. if ( !_wcsnicmp (strHelpFlag.c_str (), strToken.c_str (),
  61. strToken.length ()) )
  62. {
  63. DisplayHelp ();
  64. return 0;
  65. }
  66. else
  67. _Module.SetObjectDN (strToken);
  68. break;
  69. default:
  70. {
  71. size_t lenToken = strToken.length ();
  72. if ( !_wcsnicmp (strSchemaFlag.c_str (), strToken.c_str (),
  73. lenToken))
  74. {
  75. _Module.SetDoSchema ();
  76. }
  77. else if ( !_wcsnicmp (strCheckDelegationFlag.c_str (),
  78. strToken.c_str (), lenToken) )
  79. {
  80. _Module.SetCheckDelegation ();
  81. }
  82. else if ( !_wcsnicmp (strGetEffectiveFlag.c_str (),
  83. strToken.c_str (), lenEffectiveFlag) )
  84. {
  85. wstring strUserGroup = strToken.substr(lenEffectiveFlag,
  86. lenToken - lenEffectiveFlag);
  87. _Module.SetDoGetEffective (strUserGroup);
  88. }
  89. else if ( !_wcsnicmp (strFixDelegationFlag.c_str (),
  90. strToken.c_str (), lenToken) )
  91. {
  92. _Module.SetFixDelegation ();
  93. }
  94. else if ( !_wcsnicmp (strTabDelimitedOutputFlag.c_str (),
  95. strToken.c_str (), lenToken) )
  96. {
  97. _Module.SetTabDelimitedOutput ();
  98. }
  99. else if ( !_wcsnicmp (strLogFlag.c_str (), strToken.c_str (),
  100. lenLogFlag) )
  101. {
  102. wstring strPath = strToken.substr(lenLogFlag, lenToken - lenLogFlag);
  103. _Module.SetDoLog (strPath);
  104. }
  105. else if ( !_wcsnicmp (strSkipDescriptionFlag.c_str (),
  106. strToken.c_str (), lenToken) )
  107. {
  108. _Module.SetSkipDescription ();;
  109. }
  110. else if ( !_wcsnicmp (strHelpFlag.c_str (), strToken.c_str (),
  111. lenToken) )
  112. {
  113. DisplayHelp ();
  114. return 0;
  115. }
  116. else
  117. {
  118. wstring str;
  119. FormatMessage (str, IDS_INVALID_OPTION, strToken.c_str ());
  120. MyWprintf (str.c_str ());
  121. DisplayHelp ();
  122. return 0;
  123. }
  124. }
  125. break;
  126. }
  127. }
  128. LocalFree (lpServiceArgVectors);
  129. HRESULT hr = CoInitialize(NULL);
  130. if ( SUCCEEDED (hr) )
  131. {
  132. hr = _Module.Init ();
  133. if ( SUCCEEDED (hr) )
  134. {
  135. hr = DoSecurityDescription ();
  136. if ( SUCCEEDED (hr) && _Module.DoSchema () )
  137. hr = DoSchemaDiagnosis ();
  138. if ( SUCCEEDED (hr) && _Module.CheckDelegation () )
  139. hr = CheckDelegation ();
  140. if ( SUCCEEDED (hr) && _Module.DoGetEffective () )
  141. hr = EffectiveRightsDiagnosis ();
  142. }
  143. else
  144. DisplayHelp ();
  145. }
  146. else
  147. {
  148. _TRACE (0, L"CoInitialize Failed with %x\n",hr);
  149. return 0;
  150. }
  151. return 0;
  152. }
  153. ///////////////////////////////////////////////////////////////////////////////
  154. //
  155. // Method: DisplayHelp
  156. //
  157. // Print the purpose of the tool and each of the command-line options.
  158. //
  159. ///////////////////////////////////////////////////////////////////////////////
  160. void DisplayHelp ()
  161. {
  162. CWString str;
  163. int helpIDs[] = {IDS_HELP_MAIN,
  164. IDS_HELP_SCHEMA,
  165. IDS_HELP_CHKDELEG,
  166. IDS_HELP_GETEFFECTIVE,
  167. IDS_HELP_FIXDELEG,
  168. // IDS_HELP_LOG,
  169. IDS_HELP_SKIP_DESCRIPTION,
  170. IDS_HELP_CDO,
  171. IDS_HELP_EXAMPLE,
  172. 0};
  173. for (int nIndex = 0; helpIDs[nIndex]; nIndex++)
  174. {
  175. str.LoadFromResource (helpIDs[nIndex]);
  176. MyWprintf (str.c_str ());
  177. }
  178. }