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.

116 lines
3.7 KiB

  1. // winpop.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include "WinPop3.h"
  5. #include <atlbase.h>
  6. #include <checkuser.h> //IsUserInGroup
  7. #include <locale.h>
  8. #include <stdio.h>
  9. int _cdecl wmain(int argc, wchar_t* argv[])
  10. {
  11. HRESULT hr = S_OK;
  12. CWinPop3 wp3;
  13. CHAR szConsoleCP[8];
  14. setlocale( LC_ALL, "" );
  15. if ( 0 < _snprintf( szConsoleCP, 7, ".%d", GetConsoleOutputCP() ))
  16. setlocale( LC_CTYPE, szConsoleCP );
  17. // Command check
  18. if ( S_OK != IsUserInGroup(DOMAIN_ALIAS_RID_ADMINS)) // Admin check
  19. hr = E_ACCESSDENIED;
  20. else if ( 2 > argc )
  21. hr = -1;
  22. else if ( 2 < argc )
  23. {
  24. for ( int i = 1; i < argc; i++ )
  25. {
  26. if (( 0 == _wcsicmp( L"/?", argv[i] )) || ( 0 == _wcsicmp( L"-?", argv[i] )))
  27. {
  28. if (( 0 == _wcsicmp( L"GET", argv[1] )) || ( 0 == _wcsicmp( L"SET", argv[1] )))
  29. hr = -2;
  30. else
  31. hr = -1;
  32. }
  33. }
  34. }
  35. if ( S_OK == hr )
  36. {
  37. hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
  38. if ( S_OK == hr )
  39. {
  40. if ( 0 == _wcsicmp( L"ADD", argv[1] ))
  41. { // ADD <domainname | username@domainname>
  42. hr = wp3.Add( argc, argv );
  43. }
  44. else if (( 0 == _wcsicmp( L"DEL", argv[1] )) || ( 0 == _wcsicmp( L"DELETE", argv[1] )))
  45. { // DEL <domainname | username@domainname>
  46. hr = wp3.Del( argc, argv );
  47. }
  48. else if ( 0 == _wcsicmp( L"INIT", argv[1] ))
  49. { // INIT [0|1]
  50. hr = wp3.Init( argc, argv );
  51. }
  52. else if ( 0 == _wcsicmp( L"LIST", argv[1] ))
  53. { // LIST [domainname]
  54. hr = wp3.List( argc, argv );
  55. }
  56. else if ( 0 == _wcsicmp( L"LOCK", argv[1] ))
  57. { // ADD <domainname | username@domainname>
  58. hr = wp3.Lock( argc, argv, TRUE );
  59. }
  60. else if ( 0 == _wcsicmp( L"UNLOCK", argv[1] ))
  61. { // ADD <domainname | username@domainname>
  62. hr = wp3.Lock( argc, argv, FALSE );
  63. }
  64. else if ( 0 == _wcsicmp( L"STAT", argv[1] ))
  65. { // LIST [domainname]
  66. hr = wp3.Stat( argc, argv );
  67. }
  68. else if ( 0 == _wcsicmp( L"GET", argv[1] ))
  69. { // GET [setting]
  70. hr = wp3.Get( argc, argv );
  71. }
  72. else if ( 0 == _wcsicmp( L"SET", argv[1] ))
  73. { // SET [setting] [value]
  74. hr = wp3.Set( argc, argv );
  75. }
  76. else if ( 0 == _wcsicmp( L"CHANGEPWD", argv[1] ))
  77. { // SET [setting] [value]
  78. hr = wp3.SetPassword( argc, argv );
  79. }
  80. else if ( 0 == _wcsicmp( L"CREATEQUOTAFILE", argv[1] ))
  81. { // CREATEQUOTAFILE username@domainname [/MACHINE:machinename] [/USER:username]
  82. hr = wp3.CreateQuotaFile( argc, argv );
  83. }
  84. else if ( 0 == _wcsicmp( L"MIGRATETOAD", argv[1] ))
  85. { // MIGRATETOAD username@domainname
  86. hr = wp3.AddUserToAD( argc, argv );
  87. }
  88. else if ( 0 == _wcsicmp( L"NET", argv[1] ))
  89. { // SET [setting] [value]
  90. hr = wp3.Net( argc, argv );
  91. }
  92. else
  93. hr = -1;
  94. CoUninitialize();
  95. }
  96. }
  97. if ( -1 == hr )
  98. {
  99. wp3.PrintUsage();
  100. }
  101. else if ( -2 == hr )
  102. {
  103. wp3.PrintUsageGetSet();
  104. }
  105. else if ( 0 != hr )
  106. {
  107. wp3.PrintError( hr );
  108. }
  109. return hr;
  110. }