summaryrefslogtreecommitdiffstats
path: root/private/nw/nwscript/ncp.c
blob: 72b4533503a9c5fa096b4874d2253b28d4f3a7d2 (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356

/*************************************************************************
*
*  NCP.C
*
*  All routines doing direct NCPs or filecontrol operations
*
*  Copyright (c) 1995 Microsoft Corporation
*
*  $Log:   N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\NCP.C  $
*  
*     Rev 1.2   10 Apr 1996 14:22:50   terryt
*  Hotfix for 21181hq
*  
*     Rev 1.2   12 Mar 1996 19:54:06   terryt
*  Relative NDS names and merge
*  
*     Rev 1.1   22 Dec 1995 14:24:56   terryt
*  Add Microsoft headers
*  
*     Rev 1.0   15 Nov 1995 18:07:10   terryt
*  Initial revision.
*  
*************************************************************************/
#include <stdio.h>
#include <direct.h>
#include <time.h>
#include <stdlib.h>

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>

#include <nwapi32.h>
#include <ntddnwfs.h>

#include "nwscript.h"
#include "ntnw.h"
#include "inc/nwlibs.h"


/********************************************************************

        NTGetUserID

Routine Description:

        Given a connection handle, return the user ID

Arguments:

        ConnectionHandle - Connection Handle
        UserID           - returned User ID

Return Value:
        0 = success
        else NT error

 *******************************************************************/
unsigned int
NTGetUserID(
    unsigned int       ConnectionHandle,
    unsigned long      *pUserID
    )
{
    NTSTATUS NtStatus ;
    unsigned int ObjectType;
    unsigned char LoginTime[7];
    unsigned char UserName[48];
    VERSION_INFO VerInfo;
    unsigned int Version;
    unsigned int ConnectionNum;
    PNWC_SERVER_INFO   pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ; 

    NtStatus = GetConnectionNumber( ConnectionHandle, &ConnectionNum );

    if (!NT_SUCCESS(NtStatus)) 
       return NtStatus;

    NtStatus = NWGetFileServerVersionInfo( (NWCONN_HANDLE)ConnectionHandle,
                                            &VerInfo );

    if (!NT_SUCCESS(NtStatus)) 
       return NtStatus;

    Version = VerInfo.Version * 1000 + VerInfo.SubVersion * 10;

    if ( ( Version >= 3110 ) || ( Version < 2000 ) ) {
        NtStatus = NwlibMakeNcp(
                    pServerInfo->hConn,     // Connection Handle
                    FSCTL_NWR_NCP_E3H,      // Bindery function
                    8,                      // Max request packet size
                    63,                     // Max response packet size
                    "br|rrrr",              // Format string
                    // === REQUEST ================================
                    0x1c,                   // b Get Connection Information
                    &ConnectionNum, 4,      // r Connection Number
                    // === REPLY ==================================
                    pUserID, 4,             // r Object ID
                    &ObjectType, 2,         // r Object Type
                    UserName, 48,           // r UserName
                    LoginTime, 7            // r Login Time
                    );
    }
    else {
        NtStatus = NwlibMakeNcp(
                    pServerInfo->hConn,     // Connection Handle
                    FSCTL_NWR_NCP_E3H,      // Bindery function
                    4,                      // Max request packet size
                    63,                     // Max response packet size
                    "bb|rrrr",              // Format string
                    // === REQUEST ================================
                    0x16,                   // b Get Connection Information
                    ConnectionNum,          // b Connection Number
                    // === REPLY ==================================
                    pUserID, 4,             // r Object ID
                    &ObjectType, 2,         // r Object Type
                    UserName, 48,           // r UserName
                    LoginTime, 7            // r Login Time
                    );
    }

    return NtStatus;
}

/********************************************************************

        GetConnectionNumber

Routine Description:

        Given a ConnectionHandle, return the NetWare Connection number

Arguments:

        ConnectionHandle  - Connection Handle
        pConnectionNumber - pointer to returned connection number

Return Value:
        0 = success
        else NT error

 *******************************************************************/
unsigned int
GetConnectionNumber(
    unsigned int       ConnectionHandle,
    unsigned int *     pConnectionNumber )
{
    NTSTATUS            Status;
    IO_STATUS_BLOCK     IoStatusBlock;
    NWR_GET_CONNECTION_DETAILS Details;
    PNWC_SERVER_INFO   pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ; 

    Status = NtFsControlFile(
                 pServerInfo->hConn,     // Connection Handle
                 NULL,
                 NULL,
                 NULL,
                 &IoStatusBlock,
                 FSCTL_NWR_GET_CONN_DETAILS,
                 NULL,
                 0,
                 (PVOID) &Details,
                 sizeof(Details));

    if (Status == STATUS_SUCCESS) {
        Status = IoStatusBlock.Status;
    }

    if (NT_SUCCESS(Status)) {
        *pConnectionNumber = 256 * Details.ConnectionNumberHi +
                             Details.ConnectionNumberLo;
    }

    return Status;
}

/********************************************************************

        GetInternetAddress

Routine Description:

        Return the address of the current system

Arguments:

        ConnectionHandle - Connection Handle
        ConnectionNum    - Connection Number
        pAddress         - returned address

Return Value:
        0 = success
        else NT error

 *******************************************************************/
unsigned int
GetInternetAddress(
    unsigned int       ConnectionHandle,
    unsigned int       ConnectionNum,
    unsigned char      *pAddress
    )
{
    NTSTATUS NtStatus ;
    VERSION_INFO VerInfo;
    unsigned int Version;
    unsigned char Address[12];
    PNWC_SERVER_INFO   pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ; 

    NtStatus = NWGetFileServerVersionInfo( (NWCONN_HANDLE)ConnectionHandle,
                                            &VerInfo );

    if (!NT_SUCCESS(NtStatus)) 
       return NtStatus;

    Version = VerInfo.Version * 1000 + VerInfo.SubVersion * 10;

    if ( ( Version >= 3110 ) || ( Version < 2000 ) ) {
        NtStatus = NwlibMakeNcp(
                    pServerInfo->hConn,     // Connection Handle
                    FSCTL_NWR_NCP_E3H,      // Bindery function
                    7,                      // Max request packet size
                    14,                     // Max response packet size
                    "br|r",                 // Format string
                    // === REQUEST ================================
                    0x1a,                   // b Get Connection Information
                    &ConnectionNum, 4,      // r Connection Number
                    // === REPLY ==================================
                    Address, 12             // r Login Time
                    );
    }
    else {
        NtStatus = NwlibMakeNcp(
                    pServerInfo->hConn,     // Connection Handle
                    FSCTL_NWR_NCP_E3H,      // Bindery function
                    4,                      // Max request packet size
                    14,                     // Max response packet size
                    "bb|r",                 // Format string
                    // === REQUEST ================================
                    0x13,                   // b Get Connection Information
                    (unsigned char)ConnectionNum, // b Connection Number
                    // === REPLY ==================================
                    Address, 12             // r Login Time
                    );
    }
    memcpy( pAddress, Address, 10 );

    return NtStatus;
}


/********************************************************************

        GetBinderyObjectID

Routine Description:

        Get the object ID of a named object in the bindery

Arguments:

        ConnectionHandle - Server connection handle
        pObjectName      - Name of object
        ObjectType       - Object type
        pObjectId        - returned object ID


Return Value:
        0 = success
        else NT error

 *******************************************************************/
unsigned int
GetBinderyObjectID( 
    unsigned int       ConnectionHandle,
    char              *pObjectName,
    unsigned short     ObjectType,
    unsigned long     *pObjectId )
{
    PNWC_SERVER_INFO   pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ; 
    unsigned int reply;

    reply = NwlibMakeNcp(
                    pServerInfo->hConn,     // Connection Handle
                    FSCTL_NWR_NCP_E3H,      // Directory function
                    54,                     // Max request packet size
                    56,                     // Max response packet size
                    "brp|r",                // Format string
                    // === REQUEST ================================
                    0x35,                   // b Get object ID
                    &ObjectType, W_SIZE,    // r Object type HI-LO
                    pObjectName,            // p UserName
                    // === REPLY ==================================
                    pObjectId, 4            // 4 bytes of raw data
                    );
    return reply;
}

/********************************************************************

        GetDefaultPrinterQueue

Routine Description:

    Get the default printer queue.

Arguments:
    ConnectionHandle - IN
       Handle to server
    pServerName - IN
       File server name
    pQueueName - OUT
       Default printer queue name
        

Return Value:

 *******************************************************************/
unsigned int
GetDefaultPrinterQueue (
    unsigned int  ConnectionHandle,
    unsigned char *pServerName,
    unsigned char *pQueueName
    )
{
    unsigned long      ObjectID;
    NTSTATUS           NtStatus ;
    PNWC_SERVER_INFO   pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ; 
    NWOBJ_TYPE         ObjectType;
    NWCCODE            Nwcode;

    NtStatus = NwlibMakeNcp(
                    pServerInfo->hConn,     // Connection Handle
                    NWR_ANY_F2_NCP(0x11),   // F2 Function function
                    4,                      // Max request packet size
                    4,                      // Max response packet size
                    "wbb|d",                // Format string
                    // === REQUEST ================================
                    0x2,                    // w Length
                    0xA,                    // b Subfunction
                    0,                      // b printer number
                    // === REPLY ==================================
                    &ObjectID               // d Object ID of Queue
                    );

    if ( !NT_SUCCESS( NtStatus ) )
        return ( NtStatus & 0xFF );

    Nwcode = NWGetObjectName( (NWCONN_HANDLE) ConnectionHandle,
                              ObjectID,
                              pQueueName,
                              &ObjectType ); 

    return Nwcode;
}