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.

193 lines
4.5 KiB

  1. // Copyright (c) 1998-1999 Microsoft Corporation
  2. /******************************************************************************
  3. *
  4. * CHGLOGON.C
  5. *
  6. * This module contains code for the CHGLOGON utility.
  7. *
  8. *
  9. *******************************************************************************/
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <winstaw.h>
  15. #include <assert.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <utilsub.h>
  19. #include <string.h>
  20. #include <locale.h>
  21. #include <printfoa.h>
  22. #include "chglogon.h"
  23. /*
  24. * Global Data
  25. */
  26. USHORT help_flag = FALSE; // User wants help
  27. USHORT fQuery = FALSE; // query winstations
  28. USHORT fEnable = FALSE; // enable winstations
  29. USHORT fDisable = FALSE; // disable winstations
  30. TOKMAP ptm[] = {
  31. {L"/q", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fQuery},
  32. {L"/query", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fQuery},
  33. {L"/enable", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fEnable},
  34. {L"/disable", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fDisable},
  35. {L"/?", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &help_flag},
  36. {0, 0, 0, 0, 0}
  37. };
  38. /*
  39. * Local function prototypes.
  40. */
  41. void Usage(BOOLEAN bError);
  42. /*******************************************************************************
  43. *
  44. * main
  45. *
  46. ******************************************************************************/
  47. int __cdecl
  48. main(INT argc, CHAR **argv)
  49. {
  50. WCHAR **argvW;
  51. ULONG rc;
  52. INT i;
  53. PPOLICY_TS_MACHINE Ppolicy;
  54. setlocale(LC_ALL, ".OCP");
  55. /*
  56. * Massage the command line.
  57. */
  58. argvW = MassageCommandLine((DWORD)argc);
  59. if (argvW == NULL) {
  60. ErrorPrintf(IDS_ERROR_MALLOC);
  61. return(FAILURE);
  62. }
  63. /*
  64. * parse the cmd line without parsing the program name (argc-1, argv+1)
  65. */
  66. rc = ParseCommandLine(argc-1, argvW+1, ptm, 0);
  67. /*
  68. * Check for error from ParseCommandLine
  69. */
  70. if ( help_flag || rc ) {
  71. if ( !help_flag && !(rc & PARSE_FLAG_NO_PARMS) ) {
  72. Usage(TRUE);
  73. return(FAILURE);
  74. } else {
  75. Usage(FALSE);
  76. return(SUCCESS);
  77. }
  78. }
  79. //Check if we are running under Terminal Server
  80. if(!AreWeRunningTerminalServices())
  81. {
  82. ErrorPrintf(IDS_ERROR_NOT_TS);
  83. return(FAILURE);
  84. }
  85. /*
  86. * Check if Group policy has thrown the big switch, if so, inform and refuse any changes
  87. */
  88. Ppolicy = LocalAlloc( LPTR, sizeof(POLICY_TS_MACHINE) );
  89. if (Ppolicy == NULL) {
  90. ErrorPrintf(IDS_ERROR_MALLOC);
  91. return(FAILURE);
  92. }
  93. RegGetMachinePolicy( Ppolicy );
  94. if ( Ppolicy->fPolicyDenyTSConnections )
  95. {
  96. if (Ppolicy->fDenyTSConnections)
  97. {
  98. ErrorPrintf(IDS_ERROR_WINSTATIONS_GP_DENY_CONNECTIONS_1 );
  99. }
  100. else
  101. {
  102. ErrorPrintf(IDS_ERROR_WINSTATIONS_GP_DENY_CONNECTIONS_0 );
  103. }
  104. LocalFree( Ppolicy );
  105. Ppolicy = NULL;
  106. return( FAILURE );
  107. }
  108. if (Ppolicy != NULL) {
  109. LocalFree( Ppolicy );
  110. Ppolicy = NULL;
  111. }
  112. /*
  113. * Enable or disable
  114. */
  115. if ( fDisable ) {
  116. rc = WriteProfileString( APPLICATION_NAME, WINSTATIONS_DISABLED, TEXT("1") );
  117. }
  118. else if ( fEnable ) {
  119. rc = WriteProfileString( APPLICATION_NAME, WINSTATIONS_DISABLED, TEXT("0") );
  120. }
  121. /*
  122. * Query or error ?
  123. */
  124. if ( !fQuery && (rc != 1) ) {
  125. ErrorPrintf(IDS_ACCESS_DENIED);
  126. }
  127. else if ( GetProfileInt( APPLICATION_NAME, WINSTATIONS_DISABLED, 0 ) == 0 ) {
  128. ErrorPrintf(IDS_WINSTATIONS_ENABLED);
  129. }
  130. else {
  131. ErrorPrintf(IDS_WINSTATIONS_DISABLED);
  132. }
  133. return(SUCCESS);
  134. }
  135. /*******************************************************************************
  136. *
  137. * Usage
  138. *
  139. * Output the usage message for this utility.
  140. *
  141. * ENTRY:
  142. * bError (input)
  143. * TRUE if the 'invalid parameter(s)' message should preceed the usage
  144. * message and the output go to stderr; FALSE for no such error
  145. * string and output goes to stdout.
  146. *
  147. * EXIT:
  148. *
  149. *
  150. ******************************************************************************/
  151. void
  152. Usage( BOOLEAN bError )
  153. {
  154. if ( bError ) {
  155. ErrorPrintf(IDS_ERROR_INVALID_PARAMETERS);
  156. }
  157. ErrorPrintf(IDS_HELP_USAGE1);
  158. ErrorPrintf(IDS_HELP_USAGE2);
  159. ErrorPrintf(IDS_HELP_USAGE3);
  160. ErrorPrintf(IDS_HELP_USAGE4);
  161. ErrorPrintf(IDS_HELP_USAGE5);
  162. } /* Usage() */