summaryrefslogtreecommitdiffstats
path: root/private/nw/ndsutils/userfrag.c
blob: 7b8d7efefda7e988e40cf1b492113a43eb357b79 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/***

Copyright (c) 1995  Microsoft Corporation

Module Name:

    UserFrag.c

Abstract:

    User mode fragment exchange test.

Author:

    Cory West       [corywest]  05-Jan-1996

***/

#include "ndsapi32.h"
#include <nds.h>

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

    NTSTATUS Status;
    HANDLE hNdsTree;
    OEM_STRING OemArg;

    UNICODE_STRING NdsTree;
    WCHAR TreeBuffer[48];     // Max nds tree name length.

    UNICODE_STRING Object;
    WCHAR ObjectBuffer[256];  // Max nds name length.

    DWORD dwResolverFlags;
    DWORD dwOid;
    DWORD dwReplyLength;
    BYTE NdsReply[NDS_BUFFER_SIZE];

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

    if ( argc != 3 ) {
        printf( "Usage: userfrag [server name] [nds object]\n" );
        return -1;
    }

    //
    // Get the server.
    //

    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 the object information.
    //

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

    Object.Length = 0;
    Object.MaximumLength = sizeof( ObjectBuffer );
    Object.Buffer = ObjectBuffer;

    RtlOemStringToUnicodeString( &Object, &OemArg, FALSE );

    dwResolverFlags = RSLV_DEREF_ALIASES | RSLV_WALK_TREE | RSLV_WRITABLE;

    Status = FragExWithWait( hNdsTree,
                             NDSV_RESOLVE_NAME,
                             NdsReply,
                             NDS_BUFFER_SIZE,
                             &dwReplyLength,
                             "DDDSDDDD",
                             0,                     // version
                             dwResolverFlags,       // flags
                             0,                     // scope
                             &Object,               // distinguished name
                             1,0,                   // transport type
                             1,0 );                 // treeWalker type


    if ( !NT_SUCCESS( Status ) ) {
       printf( "The resolve name failed.\n" );
       goto ExitWithClose;
    }

    Status = ParseResponse( NdsReply,
                            dwReplyLength,
                            "G_D",
                            2 * sizeof( DWORD ), // Skip the first two DWORDs
                            &dwOid );

    if ( !NT_SUCCESS( Status ) ) {
        printf( "The resolve name response was undecipherable.\n" );
        goto ExitWithClose;
    }

    Status = FragExWithWait( hNdsTree,
                             NDSV_READ_ENTRY_INFO,
                             NdsReply,
                             NDS_BUFFER_SIZE,
                             &dwReplyLength,
                             "DD",
                             0,
                             dwOid );

    if ( !NT_SUCCESS( Status ) ) {
       printf( "The get object info failed.\n" );
       goto ExitWithClose;
    }

ExitWithClose:

    CloseHandle( hNdsTree );

    if ( NT_SUCCESS( Status ) ) {
        return 0;
    }

    printf( "Unable to complete the requested operation: 0x%08lx\n", Status );
    return -1;

}