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
|
/*++
Copyright (c) 1993 Microsoft Corporation
Module Name:
splutil.c
Abstract:
This module provides all the utility functions for the netware print
provider.
Author:
Yi-Hsin Sung (yihsins) 15-Apr-1993
Revision History:
--*/
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>
#include <winspool.h>
#include <splutil.h>
DWORD PrinterInfo1Offsets[]={offsetof(LPPRINTER_INFO_1W, pDescription),
offsetof(LPPRINTER_INFO_1W, pName),
offsetof(LPPRINTER_INFO_1W, pComment),
0xFFFFFFFF};
DWORD PrinterInfo2Offsets[]={offsetof(LPPRINTER_INFO_2W, pServerName),
offsetof(LPPRINTER_INFO_2W, pPrinterName),
offsetof(LPPRINTER_INFO_2W, pShareName),
offsetof(LPPRINTER_INFO_2W, pPortName),
offsetof(LPPRINTER_INFO_2W, pDriverName),
offsetof(LPPRINTER_INFO_2W, pComment),
offsetof(LPPRINTER_INFO_2W, pLocation),
offsetof(LPPRINTER_INFO_2W, pDevMode),
offsetof(LPPRINTER_INFO_2W, pSepFile),
offsetof(LPPRINTER_INFO_2W, pPrintProcessor),
offsetof(LPPRINTER_INFO_2W, pDatatype),
offsetof(LPPRINTER_INFO_2W, pParameters),
offsetof(LPPRINTER_INFO_2W, pSecurityDescriptor),
0xFFFFFFFF};
DWORD PrinterInfo3Offsets[]={offsetof(LPPRINTER_INFO_3, pSecurityDescriptor),
0xFFFFFFFF};
DWORD JobInfo1Offsets[]={offsetof(LPJOB_INFO_1W, pPrinterName),
offsetof(LPJOB_INFO_1W, pMachineName),
offsetof(LPJOB_INFO_1W, pUserName),
offsetof(LPJOB_INFO_1W, pDocument),
offsetof(LPJOB_INFO_1W, pDatatype),
offsetof(LPJOB_INFO_1W, pStatus),
0xFFFFFFFF};
DWORD JobInfo2Offsets[]={offsetof(LPJOB_INFO_2W, pPrinterName),
offsetof(LPJOB_INFO_2W, pMachineName),
offsetof(LPJOB_INFO_2W, pUserName),
offsetof(LPJOB_INFO_2W, pDocument),
offsetof(LPJOB_INFO_2W, pNotifyName),
offsetof(LPJOB_INFO_2W, pDatatype),
offsetof(LPJOB_INFO_2W, pPrintProcessor),
offsetof(LPJOB_INFO_2W, pParameters),
offsetof(LPJOB_INFO_2W, pDriverName),
offsetof(LPJOB_INFO_2W, pDevMode),
offsetof(LPJOB_INFO_2W, pStatus),
offsetof(LPJOB_INFO_2W, pSecurityDescriptor),
0xFFFFFFFF};
DWORD AddJobInfo1Offsets[]={offsetof(LPADDJOB_INFO_1W, Path),
0xFFFFFFFF};
VOID
MarshallUpStructure(
LPBYTE lpStructure,
LPDWORD lpOffsets,
LPBYTE lpBufferStart
)
{
register DWORD i=0;
while (lpOffsets[i] != -1) {
if ((*(LPBYTE *)(lpStructure+lpOffsets[i]))) {
(*(LPBYTE *)(lpStructure+lpOffsets[i]))+=(DWORD)lpBufferStart;
}
i++;
}
}
VOID
MarshallDownStructure(
LPBYTE lpStructure,
LPDWORD lpOffsets,
LPBYTE lpBufferStart
)
{
register DWORD i=0;
if (!lpStructure)
return;
while (lpOffsets[i] != -1) {
if ((*(LPBYTE*)(lpStructure+lpOffsets[i]))) {
(*(LPBYTE*)(lpStructure+lpOffsets[i]))-=(DWORD)lpBufferStart;
}
i++;
}
}
LPVOID
AllocNwSplMem(
DWORD flags,
DWORD cb
)
/*++
Routine Description:
This function will allocate local memory. It will possibly allocate extra
memory and fill this with debugging information for the debugging version.
Arguments:
flags - Flags to be passed to LocalAlloc
cb - The amount of memory to allocate in bytes
Return Value:
NON-NULL - A pointer to the allocated memory
--*/
{
LPDWORD pMem;
DWORD cbNew;
#if DBG
cbNew = cb + 2*sizeof(DWORD);
if (cbNew & 3)
cbNew += sizeof(DWORD) - (cbNew & 3);
#else
cbNew = cb;
#endif
pMem = (LPDWORD) LocalAlloc( flags, cbNew );
if ( !pMem )
{
KdPrint(("Memory Allocation in AllocNwSplMem failed for %d bytes\n", cbNew));
return NULL;
}
#if DBG
*pMem = cb;
*(LPDWORD)((LPBYTE)pMem+cbNew-sizeof(DWORD)) = 0xdeadbeef;
return (LPVOID) (pMem + 1);
#else
return (LPVOID) pMem;
#endif
}
VOID
FreeNwSplMem(
LPVOID pMem,
DWORD cb
)
/*++
Routine Description:
This function will frees the local memory allocated by AllocSplMem.
Extra checking will be performed in the debug version to ensure that
the size to be freed is indeed the size we allocated through AllocSplMem.
Arguments:
pMem - A pointer to the allocated memory
cb - The amount of memory to free
Return Value:
--*/
{
DWORD cbNew;
LPDWORD pNewMem;
if ( !pMem )
return;
pNewMem = pMem;
#if DBG
pNewMem--;
cbNew = cb + 2*sizeof(DWORD);
if ( cbNew & 3 )
cbNew += sizeof(DWORD) - (cbNew & 3);
if ( ( *pNewMem != cb )
|| (*(LPDWORD)((LPBYTE)pNewMem + cbNew - sizeof(DWORD)) != 0xdeadbeef)
)
{
KdPrint(("Corrupt Memory in FreeNwSplMem : %0lx\n", pNewMem ));
return;
}
#else
cbNew = cb;
#endif
LocalFree( (LPVOID) pNewMem );
}
LPWSTR
AllocNwSplStr(
LPWSTR pStr
)
/*++
Routine Description:
This function will allocate enough local memory to store the specified
string, and copy that string to the allocated memory
Arguments:
pStr - Pointer to the string that needs to be allocated and stored
Return Value:
NON-NULL - A pointer to the allocated memory containing the string
--*/
{
LPWSTR pMem;
if ( !pStr )
return NULL;
if ( pMem = AllocNwSplMem(0, (wcslen(pStr) + 1) * sizeof(WCHAR)))
wcscpy(pMem, pStr);
return pMem;
}
VOID
FreeNwSplStr(
LPWSTR pStr
)
/*++
Routine Description:
This function will frees the string allocated by AllocSplStr.
Extra checking will be performed in the debug version to ensure that
the size to be freed is indeed the size we allocated through AllocSplStr.
Arguments:
pStr - A pointer to the allocated string
Return Value:
--*/
{
if ( pStr )
FreeNwSplMem(pStr, (wcslen(pStr) + 1) * sizeof(WCHAR));
}
BOOL
ValidateUNCName(
LPWSTR pName
)
/*++
Routine Description:
This function will checks whether the given name is a valid UNC
name ( in the form \\server\name) or not.
Arguments:
pName - The supplied name
Return Value:
TRUE - The name given is a valid UNC name
FALSE - Otherwise
--*/
{
if ( pName
&& (*pName++ == L'\\')
&& (*pName++ == L'\\')
&& (wcschr(pName, L'\\'))
)
{
return TRUE;
}
return FALSE;
}
#ifndef NOT_USED
LPWSTR
GetNextElement(LPWSTR *pPtr, WCHAR token)
{
LPWSTR pszRestOfString = *pPtr;
LPWSTR pszRetval = NULL;
LPWSTR pszStr = NULL;
if ( *pszRestOfString == L'\0')
return NULL;
if ((pszStr = wcschr (pszRestOfString, token))== NULL )
{
pszRetval = *pPtr;
*pPtr += wcslen(*pPtr);
return pszRetval;
}
else
{
*pszStr = L'\0';
pszRetval = *pPtr ;
*pPtr = ++pszStr ;
return pszRetval ;
}
}
#endif
|