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.

214 lines
5.7 KiB

  1. #include <pch.cxx>
  2. #pragma hdrstop
  3. #include <ole2.h>
  4. #include "trkwks.hxx"
  5. #include "dltadmin.hxx"
  6. HRESULT
  7. SendParameterValueToService( BOOL fTrkWks, DWORD dwParameter, DWORD dwValue )
  8. {
  9. HRESULT hr = E_FAIL;
  10. RPC_STATUS rpcstatus;
  11. RPC_TCHAR * ptszStringBinding;
  12. RPC_BINDING_HANDLE hBinding = NULL;
  13. BOOL fBound = FALSE;
  14. TRKSVR_MESSAGE_UNION Msg;
  15. if( !fTrkWks )
  16. return( HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED ));
  17. rpcstatus = RpcStringBindingCompose( NULL, TEXT("ncalrpc"), NULL, TEXT("trkwks"),
  18. NULL, &ptszStringBinding);
  19. if( rpcstatus )
  20. {
  21. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcStringBindingCompose %lu"), rpcstatus ));
  22. hr = HRESULT_FROM_WIN32(rpcstatus);
  23. goto Exit;
  24. }
  25. rpcstatus = RpcBindingFromStringBinding( ptszStringBinding, &hBinding );
  26. RpcStringFree( &ptszStringBinding );
  27. if( rpcstatus )
  28. {
  29. TrkLog(( TRKDBG_ERROR, TEXT("Failed RpcBindingFromStringBinding") ));
  30. hr = HRESULT_FROM_WIN32(rpcstatus);
  31. goto Exit;
  32. }
  33. fBound = TRUE;
  34. memset( &Msg, 0, sizeof(Msg) );
  35. Msg.MessageType = WKS_CONFIG;
  36. Msg.Priority = PRI_0;
  37. Msg.WksConfig.dwParameter = dwParameter;
  38. Msg.WksConfig.dwNewValue = dwValue;
  39. __try
  40. {
  41. hr = LnkCallSvrMessage( hBinding, &Msg);
  42. }
  43. __except( EXCEPTION_EXECUTE_HANDLER )
  44. {
  45. hr = HRESULT_FROM_WIN32( GetExceptionCode() );
  46. }
  47. if( FAILED(hr) )
  48. {
  49. _tprintf( TEXT("Failed call to service (%08x)\n"), hr );
  50. goto Exit;
  51. }
  52. Exit:
  53. if( fBound )
  54. RpcBindingFree( &hBinding );
  55. return( hr );
  56. }
  57. BOOL
  58. DltAdminConfig( ULONG cArgs, TCHAR * const rgptszArgs[], ULONG *pcEaten )
  59. {
  60. BOOL fTrkWks = FALSE;
  61. LONG iArg = 0;
  62. BOOL fDynamic = FALSE;
  63. if( 1 <= cArgs && IsHelpArgument( rgptszArgs[0] ))
  64. {
  65. printf("\nOption Config\n"
  66. " Purpose: Set tracking service configuration\n"
  67. " Usage: -config <trkwks|trksvr> [options] [<parameter> <value>]\n"
  68. " If the parm/value is ommitted, a list\n"
  69. " of parameters is displayed\n"
  70. " Options: -d Attempt to dynamically change the parameter\n"
  71. " on the running service\n"
  72. " E.g.: -config trkwks VolInitInitialDelay 0\n"
  73. " -config trkwks\n"
  74. " -config trkwks -d MoveNotifyTimeout 5\n" );
  75. return( TRUE );
  76. }
  77. if( !_tcsicmp( rgptszArgs[iArg], TEXT("trkwks") ))
  78. fTrkWks = TRUE;
  79. else if( !_tcsicmp( rgptszArgs[iArg], TEXT("trksvr") ))
  80. fTrkWks = FALSE;
  81. else
  82. {
  83. _tprintf( TEXT("Invalid service name (%s). Use -? for help\n"), rgptszArgs[0] );
  84. return( FALSE );
  85. }
  86. iArg++;
  87. while( iArg < cArgs
  88. &&
  89. ( rgptszArgs[ iArg ][0] == TEXT('/')
  90. ||
  91. rgptszArgs[ iArg ][0] == TEXT('-') ) )
  92. {
  93. _tcsupr( rgptszArgs[ iArg ] );
  94. switch( rgptszArgs[ iArg ][ 1 ] )
  95. {
  96. case TEXT('D'):
  97. fDynamic = TRUE;
  98. break;
  99. default:
  100. _tprintf( TEXT("Unknown option (%s). Use -? for help\n"), rgptszArgs[iArg] );
  101. return( FALSE );
  102. }
  103. iArg++;
  104. (*pcEaten)++;
  105. }
  106. if( iArg + 2 != cArgs
  107. &&
  108. iArg != cArgs )
  109. {
  110. printf( "Invalid parameters. Use -? for help\n" );
  111. return( FALSE );
  112. }
  113. (*pcEaten) += 2;
  114. if( fTrkWks )
  115. {
  116. CTrkWksConfiguration configWks;
  117. configWks.Initialize( TRUE ); // => Persistable
  118. if( iArg == cArgs )
  119. printf( "Configurable parameters:\n\n" );
  120. for( int i = 0; i < configWks.GetParameterCount(); i++ )
  121. {
  122. if( iArg == cArgs )
  123. {
  124. _tprintf( TEXT(" %s\n"), configWks.GetParameterName( i ) );
  125. }
  126. else if( !_tcsicmp( configWks.GetParameterName(i), rgptszArgs[iArg] ))
  127. {
  128. DWORD dwValue;
  129. if( 1 == _stscanf( rgptszArgs[iArg+1], TEXT("0x%x"), &dwValue )
  130. ||
  131. 1 == _stscanf( rgptszArgs[iArg+1], TEXT("%lu"), &dwValue) )
  132. {
  133. if( fDynamic )
  134. {
  135. HRESULT hr = SendParameterValueToService( fTrkWks, i, dwValue );
  136. if( FAILED(hr) )
  137. {
  138. _tprintf( TEXT("Couldn't set %s in service (%08x)"),
  139. rgptszArgs[iArg], hr );
  140. return( FALSE );
  141. }
  142. else
  143. {
  144. }
  145. }
  146. HRESULT hr = configWks.PersistParameter( i, dwValue );
  147. if( FAILED(hr) )
  148. {
  149. printf( "Couldn't write parameter to registry (%08x)", hr );
  150. return( FALSE );
  151. }
  152. else
  153. {
  154. _tprintf( TEXT("Set %s to 0x%x\n"), configWks.GetParameterName(i), dwValue );
  155. }
  156. }
  157. else
  158. {
  159. _tprintf( TEXT("Couldn't interpret parameter value (%s)\n"), rgptszArgs[iArg+1] );
  160. return( FALSE );
  161. }
  162. break;
  163. }
  164. }
  165. }
  166. return( TRUE );
  167. } // main()