summaryrefslogtreecommitdiffstats
path: root/private/nw/test/getmsg.c
blob: 35c3146d23f823bef14918fc878a826227c9555f (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*++

Copyright (c) 1993  Microsoft Corporation

Module Name:

    fileio.c

Abstract:

    User mode test program for the Microsoft Netware redir file system.

    This test program can be built from the command line using the
    command 'nmake UMTEST=fileio'.

Author:

    Manny Weiser (mannyw)   17-May-1993

Revision History:

--*/

#include <stdio.h>
#include <string.h>
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <ntddnwfs.h>

//
// Local definitions
//

VOID
DisplayUsage(
    PSZ ProgramName
    );


BOOLEAN
OpenRedir(
    PHANDLE Handle
    );

GetMessage(
    IN HANDLE Handle
    );

#define BUFFER_SIZE 200


_cdecl
main(
    int argc,
    char *argv[],
    )
{
    HANDLE handle;
    BOOLEAN success;

    success = OpenRedir( &handle );
    if ( !success) {
        return 1;
    }

    printf("Opened redirector\n" );

    success = GetMessage( handle );
    if ( !success) {
        return 1;
    }

    printf( "%s exiting\n", argv[0]);
    NtClose( handle );
    return 0;


}


BOOLEAN
OpenRedir(
    PHANDLE Handle
    )
{
    NTSTATUS status;
    OBJECT_ATTRIBUTES objectAttributes;
    IO_STATUS_BLOCK ioStatusBlock;
    UNICODE_STRING FileName;

    FileName.Buffer = DD_NWFS_DEVICE_NAME_U;
    FileName.Length = sizeof( DD_NWFS_DEVICE_NAME_U ) - sizeof( WCHAR );
    FileName.MaximumLength = sizeof( DD_NWFS_DEVICE_NAME_U );

    //
    //  Open the file
    //

    InitializeObjectAttributes(
        &objectAttributes,
        &FileName,
        OBJ_CASE_INSENSITIVE,
        NULL,
        NULL
        );

    status = NtOpenFile (
                Handle,
                FILE_GENERIC_READ | SYNCHRONIZE,
                &objectAttributes,
                &ioStatusBlock,
                FILE_SHARE_WRITE | FILE_SHARE_READ,
                0L
                );

    if (!NT_SUCCESS(status) ) {
        printf( "Open status = %x for file %Z\n", status, &FileName );
    }

    return ( (BOOLEAN) NT_SUCCESS( status ) );
}



GetMessage(
    IN HANDLE Handle
    )
{
    NTSTATUS status;
    IO_STATUS_BLOCK IoStatusBlock;
    char OutputBuffer[200];
    PWCHAR ServerName;
    PWCHAR Message;
    PNWR_SERVER_MESSAGE ServerMessage;

    printf("Waiting for message\n" );

    status = NtFsControlFile(
                Handle,
                NULL,
                NULL,
                NULL,
                &IoStatusBlock,
                FSCTL_NWR_GET_MESSAGE,
                NULL,
                0,
                OutputBuffer,
                sizeof(OutputBuffer)
                );

#if 0
    if ( NT_SUCCESS( status ) ) {

        status = NtWaitForSingleObject( Handle, FALSE, NULL );
        if ( NT_SUCCESS( status )) {
            status = IoStatusBlock.Status;
        }
    }

    if ( !NT_SUCCESS( status ) ) {
        printf("NtFsControlFile returns %08lx\n", status );
        return( status );
    } else {
        printf("Message received\n" );
    }

    ServerMessage = (PNWR_SERVER_MESSAGE)OutputBuffer;
    ServerName = ServerMessage->Server;
    Message = (PWCHAR)((PCHAR)ServerMessage + ServerMessage->MessageOffset);

    printf("From %S, Message = %S\n", ServerName, Message );
#endif

    return( status );
}