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.

133 lines
2.4 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Cx.c
  5. Abstract:
  6. This is the command line NDS utility for setting contexts.
  7. Author:
  8. Cory West [corywest] 25-Oct-95
  9. ***/
  10. #include "ndsapi32.h"
  11. int
  12. _cdecl main(
  13. int argc,
  14. char **argv
  15. ) {
  16. NTSTATUS Status;
  17. HANDLE hNdsTree;
  18. OEM_STRING OemArg;
  19. UNICODE_STRING NdsTree;
  20. WCHAR TreeBuffer[1024];
  21. UNICODE_STRING Context;
  22. WCHAR ContextBuffer[1024];
  23. //
  24. // Who do we want to monkey with?
  25. //
  26. if ( argc < 2 ) {
  27. printf( "Usage: cx [tree name] [optional context]\n" );
  28. return -1;
  29. }
  30. //
  31. // Get the tree.
  32. //
  33. OemArg.Length = strlen( argv[1] );
  34. OemArg.MaximumLength = OemArg.Length;
  35. OemArg.Buffer = argv[1];
  36. NdsTree.Length = 0;
  37. NdsTree.MaximumLength = sizeof( TreeBuffer );
  38. NdsTree.Buffer = TreeBuffer;
  39. RtlOemStringToUnicodeString( &NdsTree, &OemArg, FALSE );
  40. //
  41. // Open up a handle to the tree.
  42. //
  43. Status = NwNdsOpenTreeHandle( &NdsTree,
  44. &hNdsTree );
  45. if ( !NT_SUCCESS( Status ) ) {
  46. printf( "The supplied tree name is invalid or the tree is unavailable.\n" );
  47. return -1;
  48. }
  49. //
  50. // Get or set the context, depending.
  51. //
  52. Context.Length = 0;
  53. Context.MaximumLength = sizeof( ContextBuffer );
  54. Context.Buffer = ContextBuffer;
  55. Status = STATUS_UNSUCCESSFUL;
  56. if ( argc == 2 ) {
  57. //
  58. // Get the context.
  59. //
  60. Status = NwNdsGetTreeContext ( hNdsTree,
  61. &NdsTree,
  62. &Context );
  63. if ( !NT_SUCCESS( Status ) ) {
  64. printf( "You are not logged into the specified tree.\n" );
  65. goto Exit;
  66. }
  67. ContextBuffer[Context.Length/sizeof(WCHAR)] = L'\0';
  68. printf( "%S", ContextBuffer );
  69. } else {
  70. //
  71. // Set the context.
  72. //
  73. OemArg.Length = strlen( argv[2] );
  74. OemArg.MaximumLength = OemArg.Length;
  75. OemArg.Buffer = argv[2];
  76. RtlOemStringToUnicodeString( &Context, &OemArg, FALSE );
  77. Status = NwNdsSetTreeContext ( hNdsTree,
  78. &NdsTree,
  79. &Context );
  80. if ( !NT_SUCCESS( Status ) ) {
  81. printf( "*** Set context: Status = %08lx\n", Status );
  82. }
  83. }
  84. Exit:
  85. CloseHandle( hNdsTree );
  86. if ( !NT_SUCCESS( Status )) {
  87. return -1;
  88. }
  89. return 0;
  90. }