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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
/*++
Copyright (c) 1995 Microsoft Corporation
Module Name:
nwlibs\psdb.c
Abstract:
Read the Print Con database file APIs.
Author:
Shawn Walker (v-swalk) 12-12-1994
Revision History:
--*/
#include "common.h"
extern DWORD SwapLong(DWORD number);
unsigned int
PSGetJobName(
unsigned int ConnectionHandle,
unsigned short SearchFlag,
unsigned char *pOwner,
unsigned char *pJobName,
PPS_JOB_RECORD pJobRecord,
unsigned char GetDefault
);
#define MAX_JOB_NAME_ENTRY 37
#define O_RDONLY 0x0000 /* open for reading only */
#define O_WRONLY 0x0001 /* open for writing only */
#define O_RDWR 0x0002 /* open for reading and writing */
#define O_APPEND 0x0008 /* writes done at eof */
#define O_CREAT 0x0100 /* create and open file */
#define O_TRUNC 0x0200 /* open and truncate */
#define O_EXCL 0x0400 /* open only if file doesn't already exist */
#define O_TEXT 0x4000 /* file mode is text (translated) */
#define O_BINARY 0x8000 /* file mode is binary (untranslated) */
#define S_IEXEC 0000100 /* execute/search permission, owner */
#define S_IWRITE 0000200 /* write permission, owner */
#define S_IREAD 0000400 /* read permission, owner */
#define S_IFCHR 0020000 /* character special */
#define S_IFDIR 0040000 /* directory */
#define S_IFREG 0100000 /* regular */
#define S_IFMT 0170000 /* file type mask */
#include <pshpack1.h>
typedef struct _PRINTCON_HEADER {
unsigned char Text[115];
unsigned char MajorVersion;
unsigned char MinorVersion1;
unsigned char MinorVersion2;
unsigned char DefaultJobName[32];
} PRINTCON_HEADER, *PPRINTCON_HEADER;
#define PRINTCON_HEADER_SIZE sizeof(PRINTCON_HEADER)
typedef struct _JOB_NAME_AREA {
unsigned char JobName[32];
unsigned long JobRecordOffset;
} JOB_NAME_AREA, *PJOB_NAME_AREA;
#define JOB_NAME_AREA_SIZE sizeof(JOB_NAME_AREA)
typedef struct _JOB_RECORD_AREA {
unsigned char ServerName[NCP_BINDERY_OBJECT_NAME_LENGTH];
unsigned char QueueName[NCP_BINDERY_OBJECT_NAME_LENGTH];
unsigned char TabSize;
unsigned short NumberOfCopies;
unsigned char FormName[40];
unsigned char NotifyWhenDone; //0=No, 1=Yes
unsigned long PrintServerID;
unsigned char Name[13];
unsigned char BannerName[13];
unsigned char Device[33];
unsigned char Mode[33];
unsigned char BannerFlag; //0=No Banner, 1=Banner
unsigned char DataType; //1=Byte,0=Stream
unsigned char FormFeed; //0=Don't Suppress FF, 1=Suppress FF
unsigned short TimeoutCount;
unsigned char LocalPrinter; //1=LPT1, 2=LPT2, 3=LPT3
unsigned char AutoEndCap; //0=Don't Auto EndCap, 1=Do Auto EndCap
} JOB_RECORD_AREA, *PJOB_RECORD_AREA;
#include <poppack.h>
#define JOB_RECORD_AREA_SIZE sizeof(JOB_RECORD_AREA)
/*++
*******************************************************************
PSJobGetDefault
Routine Description:
Get the default print job configuration from the printcon.dat
file.
Arguments:
ConnectionHandle = The connection handle to use.
SearchFlag =
pOwner =
pJobName = A pointer to return the default job configuration name.
pJobRecord = A pointer to return the default job configuration.
Return Value:
SUCCESSFUL 0x0000
PS_ERR_BAD_VERSION 0x7770
PS_ERR_GETTING_DEFAULT 0x7773
PS_ERR_OPENING_DB 0x7774
PS_ERR_READING_DB 0x7775
PS_ERR_READING_RECORD 0x7776
PS_ERR_INTERNAL_ERROR 0x7779
PS_ERR_NO_DEFAULT_SPECIFIED 0x777B
INVALID_CONNECTION 0x8801
*******************************************************************
--*/
unsigned int
PSJobGetDefault(
unsigned int ConnectionHandle,
unsigned short SearchFlag,
unsigned char *pOwner,
unsigned char *pJobName,
PPS_JOB_RECORD pJobRecord
)
{
return PSGetJobName(
ConnectionHandle,
SearchFlag,
pOwner,
pJobName,
pJobRecord,
TRUE);
}
/*++
*******************************************************************
PSJobRead
Routine Description:
Get the print job configuration from the printcon.dat file.
Arguments:
ConnectionHandle = The connection handle to use.
pOwner =
pJobName = A pointer to return the default job configuration name.
pJobRecord = A pointer to return the default job configuration.
Return Value:
SUCCESSFUL 0x0000
PS_ERR_BAD_VERSION 0x7770
PS_ERR_GETTING_DEFAULT 0x7773
PS_ERR_OPENING_DB 0x7774
PS_ERR_READING_DB 0x7775
PS_ERR_READING_RECORD 0x7776
PS_ERR_INTERNAL_ERROR 0x7779
PS_ERR_NO_DEFAULT_SPECIFIED 0x777B
INVALID_CONNECTION 0x8801
*******************************************************************
--*/
unsigned int
PSJobRead(
unsigned int ConnectionHandle,
unsigned char *pOwner,
unsigned char *pJobName,
PPS_JOB_RECORD pJobRecord
)
{
return PSGetJobName(
ConnectionHandle,
0,
pOwner,
pJobName,
pJobRecord,
FALSE);
}
/*++
*******************************************************************
PSGetJobName
Routine Description:
Common routine to get the print job configuration from the
printcon.dat file.
Arguments:
ConnectionHandle = The connection handle to use.
SearchFlag =
pOwner =
pJobName = A pointer to return the default job configuration name.
pJobRecord = A pointer to return the default job configuration.
GetDefault = TRUE = get the default job name, FALSE = Don't get
the default job name.
Return Value:
SUCCESSFUL 0x0000
PS_ERR_BAD_VERSION 0x7770
PS_ERR_GETTING_DEFAULT 0x7773
PS_ERR_OPENING_DB 0x7774
PS_ERR_READING_DB 0x7775
PS_ERR_READING_RECORD 0x7776
PS_ERR_INTERNAL_ERROR 0x7779
PS_ERR_NO_DEFAULT_SPECIFIED 0x777B
INVALID_CONNECTION 0x8801
*******************************************************************
--*/
unsigned int
PSGetJobName(
unsigned int ConnectionHandle,
unsigned short SearchFlag,
unsigned char *pOwner,
unsigned char *pJobName,
PPS_JOB_RECORD pJobRecord,
unsigned char GetDefault
)
{
unsigned char *pSearchJobName;
unsigned long ObjectId;
FILE *stream = NULL;
unsigned int Count;
unsigned int Bytes;
unsigned int RetCode;
unsigned int ConnectionNumber;
JOB_NAME_AREA JobNameArea;
JOB_RECORD_AREA JobRecord;
PRINTCON_HEADER PrintConHeader;
unsigned char MailDirPath[NCP_MAX_PATH_LENGTH];
/** Get the connection number for this connection **/
RetCode = GetConnectionNumber(ConnectionHandle, &ConnectionNumber);
if (RetCode) {
goto CommonExit;
}
RetCode = GetBinderyObjectID (ConnectionHandle, LOGIN_NAME,
OT_USER, &ObjectId);
if (RetCode) {
goto CommonExit;
}
/** Build the path to open the file **/
sprintf(MailDirPath, "SYS:MAIL/%lX/PRINTCON.DAT", SwapLong(ObjectId));
stream = fopen(NTNWtoUNCFormat( MailDirPath), "rb");
if (stream == NULL) {
RetCode = PS_ERR_OPENING_DB;
goto CommonExit;
}
Bytes = fread( (unsigned char *) &PrintConHeader, sizeof( char), PRINTCON_HEADER_SIZE, stream);
if (Bytes < PRINTCON_HEADER_SIZE) {
RetCode = PS_ERR_INTERNAL_ERROR;
goto CommonExit;
}
/** Check the version number **/
if ((PrintConHeader.MajorVersion != 3 &&
PrintConHeader.MajorVersion != 1) ||
PrintConHeader.MinorVersion1 != 1 ||
PrintConHeader.MinorVersion2 != 1) {
RetCode = PS_ERR_BAD_VERSION;
goto CommonExit;
}
/** Get the name we are looking for **/
if (GetDefault) {
if (PrintConHeader.DefaultJobName[0] == 0) {
RetCode = PS_ERR_NO_DEFAULT_SPECIFIED;
goto CommonExit;
}
pSearchJobName = PrintConHeader.DefaultJobName;
}
else {
pSearchJobName = pJobName;
}
Count = 0;
/** Go through all of the job entry to look for the name **/
while (Count < MAX_JOB_NAME_ENTRY) {
Bytes = fread( (unsigned char *) &JobNameArea, sizeof(unsigned char), JOB_NAME_AREA_SIZE, stream);
if (Bytes < JOB_NAME_AREA_SIZE) {
RetCode = PS_ERR_INTERNAL_ERROR;
goto CommonExit;
}
Count++;
/** Skip the entry with a null job name **/
if (JobNameArea.JobName[0] == 0) {
continue;
}
/** Is this the job name we are looking for? **/
if (!_strcmpi(pSearchJobName, JobNameArea.JobName)) {
break;
}
}
/** See if we found the job name **/
if (Count > MAX_JOB_NAME_ENTRY) {
if (GetDefault) {
RetCode = PS_ERR_GETTING_DEFAULT;
}
else {
RetCode = PS_ERR_READING_RECORD;
}
goto CommonExit;
}
fseek(stream, JobNameArea.JobRecordOffset, SEEK_SET);
Bytes = fread( (unsigned char *) &JobRecord, sizeof(unsigned char), JOB_RECORD_AREA_SIZE, stream);
if (Bytes < JOB_RECORD_AREA_SIZE) {
RetCode = PS_ERR_READING_RECORD;
goto CommonExit;
}
memset(pJobRecord, 0, PS_JOB_RECORD_SIZE);
if (JobRecord.NotifyWhenDone) {
pJobRecord->PrintJobFlag |= PS_JOB_NOTIFY;
}
if (JobRecord.BannerFlag) {
pJobRecord->PrintJobFlag |= PS_JOB_PRINT_BANNER;
}
if (JobRecord.DataType) {
pJobRecord->PrintJobFlag |= PS_JOB_EXPAND_TABS;
}
if (JobRecord.FormFeed) {
pJobRecord->PrintJobFlag |= PS_JOB_NO_FORMFEED;
}
if (JobRecord.AutoEndCap) {
pJobRecord->PrintJobFlag |= PS_JOB_AUTO_END;
}
if (JobRecord.TimeoutCount) {
pJobRecord->PrintJobFlag |= PS_JOB_TIMEOUT;
}
pJobRecord->Copies = JobRecord.NumberOfCopies;
pJobRecord->TabSize = JobRecord.TabSize;
pJobRecord->TimeOutCount = JobRecord.TimeoutCount;
pJobRecord->LocalPrinter = JobRecord.LocalPrinter;
strcpy(pJobRecord->Mode, JobRecord.Mode);
strcpy(pJobRecord->Device, JobRecord.Device);
strcpy(pJobRecord->FormName, JobRecord.FormName);
strcpy(pJobRecord->BannerName, JobRecord.BannerName);
strcpy(pJobRecord->u.NonDS.PrintQueue, JobRecord.QueueName);
strcpy(pJobRecord->u.NonDS.FileServer, JobRecord.ServerName);
if (GetDefault && pJobName) {
strcpy(pJobName, JobNameArea.JobName);
}
if (pOwner) {
*pOwner = 0;
}
CommonExit:
if (stream != NULL) {
fclose( stream );
}
return RetCode;
}
|