summaryrefslogtreecommitdiffstats
path: root/private/nw/ndsutils/cx.c
blob: b1147b2cc61d65074c3f5d88ec00bdad60c6634e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/***

Copyright (c) 1995  Microsoft Corporation

Module Name:

    Cx.c

Abstract:

    This is the command line NDS utility for setting contexts.

Author:

    Cory West       [corywest]  25-Oct-95

***/

#include "ndsapi32.h"

int
_cdecl main(
    int argc,
    char **argv
) {

    NTSTATUS Status;
    HANDLE hNdsTree;
    OEM_STRING OemArg;

    UNICODE_STRING NdsTree;
    WCHAR TreeBuffer[1024];

    UNICODE_STRING Context;
    WCHAR ContextBuffer[1024];

    //
    // Who do we want to monkey with?
    //

    if ( argc < 2 ) {
        printf( "Usage: cx [tree name] [optional context]\n" );
	return -1;
    }

    //
    // Get the tree.
    //

    OemArg.Length = strlen( argv[1] );
    OemArg.MaximumLength = OemArg.Length;
    OemArg.Buffer = argv[1];

    NdsTree.Length = 0;
    NdsTree.MaximumLength = sizeof( TreeBuffer );
    NdsTree.Buffer = TreeBuffer;

    RtlOemStringToUnicodeString( &NdsTree, &OemArg, FALSE );

    //
    // Open up a handle to the tree.
    //

    Status = NwNdsOpenTreeHandle( &NdsTree,
                                  &hNdsTree );

    if ( !NT_SUCCESS( Status ) ) {
       printf( "The supplied tree name is invalid or the tree is unavailable.\n" );
       return -1;
    }

    //
    // Get or set the context, depending.
    //

    Context.Length = 0;
    Context.MaximumLength = sizeof( ContextBuffer );
    Context.Buffer = ContextBuffer;

    Status = STATUS_UNSUCCESSFUL;

    if ( argc == 2 ) {

       //
       // Get the context.
       //

       Status = NwNdsGetTreeContext ( hNdsTree,
                                      &NdsTree,
				      &Context );

       if ( !NT_SUCCESS( Status ) ) {
	   printf( "You are not logged into the specified tree.\n" );
	   goto Exit;
       }

       ContextBuffer[Context.Length/sizeof(WCHAR)] = L'\0';
       printf( "%S", ContextBuffer );

    } else {

       //
       // Set the context.
       //

       OemArg.Length = strlen( argv[2] );
       OemArg.MaximumLength = OemArg.Length;
       OemArg.Buffer = argv[2];

       RtlOemStringToUnicodeString( &Context, &OemArg, FALSE );

       Status = NwNdsSetTreeContext ( hNdsTree,
                                      &NdsTree,
				      &Context );

       if ( !NT_SUCCESS( Status ) ) {
	   printf( "*** Set context: Status = %08lx\n", Status );
       }

   }


Exit:

    CloseHandle( hNdsTree );

    if ( !NT_SUCCESS( Status )) {
        return -1;
    }

    return 0;

}