testprogs: print secdesc->Control in spoolss test.
[ira/wip.git] / testprogs / win32 / spoolss / printlib.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for spoolss rpc operations
4
5    Copyright (C) Gerald (Jerry) Carter 2007
6    Copyright (C) Guenther Deschner 2009-2010
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <windows.h>
23 #include <stdio.h>
24 #include <assert.h>
25 #include <sddl.h>
26
27 void print_devmode(DEVMODE *pDevModeIn)
28 {
29         if (pDevModeIn == NULL) {
30                 printf("\tDevice Mode\t= (null)\n");
31                 return;
32         }
33
34         printf("\tDEVMODE:----------\n");
35         printf("\tDeviceName:      [%s]\n", pDevModeIn->dmDeviceName);
36         printf("\tSpecVersion:     %d\n",   pDevModeIn->dmSpecVersion);
37         printf("\tDriverVersion:   %d\n",   pDevModeIn->dmDriverVersion);
38         printf("\tSize:            %d\n",   pDevModeIn->dmSize);
39         printf("\tDriverExtra:     %d\n",   pDevModeIn->dmDriverExtra);
40         printf("\tFields:          0x%x\n", pDevModeIn->dmFields);
41
42         if (pDevModeIn->dmFields & DM_ORIENTATION)
43                 printf("\tOrientation:     %d\n", pDevModeIn->dmOrientation);
44         if (pDevModeIn->dmFields & DM_PAPERSIZE)
45                 printf("\tPaperSize:       %d\n", pDevModeIn->dmPaperSize);
46         if (pDevModeIn->dmFields & DM_PAPERLENGTH)
47                 printf("\tPaperLength:     %d\n", pDevModeIn->dmPaperLength);
48         if (pDevModeIn->dmFields & DM_PAPERWIDTH)
49                 printf("\tPaperWidth:      %d\n", pDevModeIn->dmPaperWidth);
50 //      if (pDevModeIn->dmFields & DM_POSITION)
51 //              printf("\tPosition:        %d\n", pDevModeIn->dmPosition);
52         if (pDevModeIn->dmFields & DM_SCALE)
53                 printf("\tScale:           %d\n", pDevModeIn->dmScale);
54         if (pDevModeIn->dmFields & DM_COPIES)
55                 printf("\tCopies:          %d\n", pDevModeIn->dmCopies );
56         if (pDevModeIn->dmFields & DM_DEFAULTSOURCE)
57                 printf("\tDefaultSource:   %d\n", pDevModeIn->dmDefaultSource);
58         if (pDevModeIn->dmFields & DM_PRINTQUALITY)
59                 printf("\tPrintQuality:    %d\n", pDevModeIn->dmPrintQuality);
60         if (pDevModeIn->dmFields & DM_COLOR)
61                 printf("\tColor:           %d\n", pDevModeIn->dmColor);
62         if (pDevModeIn->dmFields & DM_DUPLEX)
63                 printf("\tDuplex:          %d\n", pDevModeIn->dmDuplex);
64         if (pDevModeIn->dmFields & DM_YRESOLUTION)
65                 printf("\tYResolution:     %d\n", pDevModeIn->dmYResolution);
66         if (pDevModeIn->dmFields & DM_TTOPTION)
67                 printf("\tTTOption:        %d\n", pDevModeIn->dmTTOption);
68         if (pDevModeIn->dmFields & DM_COLLATE)
69                 printf("\tCollate:         %d\n", pDevModeIn->dmCollate);
70         if (pDevModeIn->dmFields & DM_FORMNAME)
71                 printf("\tForm:            [%s]\n", pDevModeIn->dmFormName);
72         if (pDevModeIn->dmFields & DM_LOGPIXELS)
73                 printf("\tLogPixels:       %d\n", pDevModeIn->dmLogPixels);
74         if (pDevModeIn->dmFields & DM_BITSPERPEL)
75                 printf("\tBitsPerPel:      %d\n", pDevModeIn->dmBitsPerPel);
76         if (pDevModeIn->dmFields & DM_PELSWIDTH)
77                 printf("\tPelsWidth:       %d\n", pDevModeIn->dmPelsWidth);
78         if (pDevModeIn->dmFields & DM_PELSHEIGHT)
79                 printf("\tPelsHeight:      %d\n", pDevModeIn->dmPelsHeight);
80         if (pDevModeIn->dmFields & DM_DISPLAYFLAGS)
81                 printf("\tDisplayFlags:    %d\n", pDevModeIn->dmDisplayFlags);
82 //      if (pDevModeIn->dmFields & DM_NUP)
83 //              printf("\tNup:             %d\n", pDevModeIn->dmNup);
84         if (pDevModeIn->dmFields & DM_DISPLAYFREQUENCY)
85                 printf("\tDisplayFrequency:%d\n", pDevModeIn->dmDisplayFrequency);
86         if (pDevModeIn->dmFields & DM_ICMMETHOD)
87                 printf("\tICMMethod:       %d\n", pDevModeIn->dmICMMethod);
88         if (pDevModeIn->dmFields & DM_ICMINTENT)
89                 printf("\tICMIntent:       %d\n", pDevModeIn->dmICMIntent);
90         if (pDevModeIn->dmFields & DM_MEDIATYPE)
91                 printf("\tMediaType:       %d\n", pDevModeIn->dmMediaType);
92         if (pDevModeIn->dmFields & DM_DITHERTYPE)
93                 printf("\tDitherType:      %d\n", pDevModeIn->dmDitherType);
94 //      if (pDevModeIn->dmFields & DM_PANNINGWIDTH)
95 //              printf("\tPanningWidth:    %d\n", pDevModeIn->dmPanningWidth);
96 //      if (pDevModeIn->dmFields & DM_PANNINGHEIGHT)
97 //              printf("\tPanningHeight:   %d\n", pDevModeIn->dmPanningHeight);
98
99 #if 0
100         if (bForceIn) {
101                 printf("DEVMODE\n");
102                 Dump((BYTE*)pDevModeIn, sizeof(DEVMODE), LEADER);
103
104                 if (pDevModeIn->dmDriverExtra) {
105                         printf("DriverExtra\n");
106                         Dump((BYTE*)pDevModeIn + sizeof(DEVMODE), pDevModeIn->dmDriverExtra, LEADER);
107                 }
108         }
109 #endif
110
111         return;
112 }
113
114 void print_acl(const char* str, ACL *acl)
115 {
116         printf("%s\n", str);
117         if (acl == NULL)
118                 return;
119
120         printf("\t\tACL Revision \t\t 0x%x\n", acl->AclRevision);
121         printf("\t\tSbz1\t\t 0x%x\n", acl->Sbz1);
122         printf("\t\tSbz2\t\t 0x%x\n", acl->Sbz2);
123         printf("\t\tACL Size\t\t 0x%x\n", acl->AclSize);
124         printf("\t\tACL Count\t\t 0x%x\n", acl->AceCount);
125
126         return;
127 }
128
129 void PrintLastError();
130
131 void print_sid(LPSTR str, PSID sid)
132 {
133         LPSTR sid_string;
134
135         printf("%s\n", str);
136
137         if (sid == NULL) {
138                 printf("(null sid)\n");
139                 return;
140         }
141
142         if (!ConvertSidToStringSid(sid, &sid_string)) {
143                 PrintLastError();
144                 return;
145         }
146
147         printf("%s\n", sid_string);
148         LocalFree(sid_string);
149
150         return;
151 }
152
153 void print_secdesc(SECURITY_DESCRIPTOR *secdesc)
154 {
155         if (secdesc == NULL) {
156                 printf("\tSecurity Descriptor\t= (null)\n");
157                 return;
158         }
159
160         printf("\tRevision\t= 0x%x\n", secdesc->Revision);
161         printf("\tSbz1\t\t= 0x%x\n", secdesc->Sbz1);
162         printf("\tControl\t\t= 0x%x\n", secdesc->Control);
163 #if 0
164         print_sid("\tOwner\t\t= ", secdesc->Owner);
165         print_sid("\tGroup\t\t= ",secdesc->Group);
166         print_acl("\tSacl\t\t= ", secdesc->Sacl);
167         print_acl("\tDacl\t\t= ", secdesc->Dacl);
168 #endif
169         return;
170 }
171
172 void PrintLastError()
173 {
174         LPVOID lpMsgBuf;
175         DWORD status;
176
177         status = GetLastError();
178
179         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
180                       NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
181                       (LPTSTR)&lpMsgBuf, 0, NULL);
182         printf("ERROR  [0x%x] : %s\n", status, (char*)lpMsgBuf);
183         LocalFree(lpMsgBuf);
184
185         return;
186 }
187
188
189 void print_job_info_1(PJOB_INFO_1 info)
190 {
191         printf("\tJob ID\t\t= %d\n",            info->JobId);
192         printf("\tPrinter Name\t= %s\n",        info->pPrinterName);
193         printf("\tMachine Name\t= %s\n",        info->pMachineName);
194         printf("\tUser Name\t= %s\n",           info->pUserName);
195         printf("\tDocument\t= %s\n",            info->pDocument);
196         printf("\tDatatype\t= %s\n",            info->pDatatype);
197         printf("\tStatus\t\t= %s\n",            info->pStatus);
198         printf("\tStatus\t= %d\n",              info->Status);
199         printf("\tPriority\t= %d\n",            info->Priority);
200         printf("\tPosition\t= %d\n",            info->Position);
201         printf("\tTotal Pages\t= %d\n", info->TotalPages);
202         printf("\tPages Printed\t= %d\n",       info->PagesPrinted);
203         printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
204                 info->Submitted.wDay, info->Submitted.wMonth,
205                 info->Submitted.wYear, info->Submitted.wHour,
206                 info->Submitted.wMinute, info->Submitted.wSecond);
207
208         return;
209 }
210
211 void print_job_info_2(PJOB_INFO_2 info)
212 {
213         printf("\tJob ID\t\t= %d\n",            info->JobId);
214         printf("\tPrinter Name\t= %s\n",        info->pPrinterName);
215         printf("\tMachine Name\t= %s\n",        info->pMachineName);
216         printf("\tUser Name\t= %s\n",           info->pUserName);
217         printf("\tDocument\t= %s\n",            info->pDocument);
218         printf("\tDatatype\t= %s\n",            info->pDatatype);
219         printf("\tNotify Name\t= %s\n",         info->pNotifyName);
220         printf("\tPrint Processor\t= %s\n",     info->pPrintProcessor);
221         printf("\tParameters\t= %s\n",          info->pParameters);
222         printf("\tDriver Name\t= %s\n",         info->pDriverName);
223         printf("\tStatus\t\t= %s\n",            info->pStatus);
224         printf("\tStatus\t\t= %d\n",            info->Status);
225         printf("\tPriority\t= %d\n",            info->Priority);
226         printf("\tPosition\t= %d\n",            info->Position);
227         printf("\tTotal Pages\t= %d\n",         info->TotalPages);
228         printf("\tPages Printed\t= %d\n",       info->PagesPrinted);
229         printf("\tStart Time\t= %d\n",          info->StartTime);
230         printf("\tUntil Time\t= %d\n",          info->UntilTime);
231         printf("\tTime\t\t= %d\n",              info->Time);
232         printf("\tSize\t\t= %d\n",              info->Size);
233         printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
234                 info->Submitted.wDay, info->Submitted.wMonth,
235                 info->Submitted.wYear, info->Submitted.wHour,
236                 info->Submitted.wMinute, info->Submitted.wSecond);
237         printf("\tDevice Mode Information\n");
238         printf("\t-----------------------\n");
239         print_devmode(info->pDevMode);
240         printf("\tSecurity Descriptor Information\n");
241         printf("\t-------------------------------\n");
242         print_secdesc(info->pSecurityDescriptor);
243
244         return;
245 }
246
247 void print_job_info_3(PJOB_INFO_3 info)
248 {
249         printf("\tJob ID\t\t= %d\n",            info->JobId);
250         printf("\tJob ID Next Job\t= %d\n",     info->NextJobId);
251         printf("\tReserved (must be 0)\t= %d\n",info->Reserved);
252
253         return;
254 }
255
256 void print_job_info_4(PJOB_INFO_4 info)
257 {
258         printf("\tJob ID\t\t= %d\n",            info->JobId);
259         printf("\tPrinter Name\t= %s\n",        info->pPrinterName);
260         printf("\tMachine Name\t= %s\n",        info->pMachineName);
261         printf("\tUser Name\t= %s\n",           info->pUserName);
262         printf("\tDocument\t= %s\n",            info->pDocument);
263         printf("\tDatatype\t= %s\n",            info->pDatatype);
264         printf("\tNotify Name\t= %s\n",         info->pNotifyName);
265         printf("\tPrint Processor\t= %s\n",     info->pPrintProcessor);
266         printf("\tDriver Name\t= %s\n",         info->pDriverName);
267         printf("\tStatus\t\t= %s\n",            info->pStatus);
268         printf("\tStatus\t\t= %d\n",            info->Status);
269         printf("\tPriority\t= %d\n",            info->Priority);
270         printf("\tPosition\t= %d\n",            info->Position);
271         printf("\tTotal Pages\t= %d\n",         info->TotalPages);
272         printf("\tPages Printed\t= %d\n",       info->PagesPrinted);
273         printf("\tStart Time\t= %d\n",          info->StartTime);
274         printf("\tUntil Time\t= %d\n",          info->UntilTime);
275         printf("\tTime\t\t= %d\n",              info->Time);
276         printf("\tSize\t\t= %d\n",              info->Size);
277         printf("\tSize High\t\t= 0x%016x\n",    info->SizeHigh);
278         printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
279                 info->Submitted.wDay, info->Submitted.wMonth,
280                 info->Submitted.wYear, info->Submitted.wHour,
281                 info->Submitted.wMinute, info->Submitted.wSecond);
282         printf("\tDevice Mode Information\n");
283         printf("\t-----------------------\n");
284         print_devmode(info->pDevMode);
285         printf("\tSecurity Descriptor Information\n");
286         printf("\t-------------------------------\n");
287         print_secdesc(info->pSecurityDescriptor);
288
289         return;
290 }
291
292 void print_job_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
293 {
294         DWORD i;
295         PJOB_INFO_1     buffer1 = NULL;
296         PJOB_INFO_2     buffer2 = NULL;
297         PJOB_INFO_3     buffer3 = NULL;
298         PJOB_INFO_4     buffer4 = NULL;
299
300         if (!buffer) {
301                 return;
302         }
303
304         switch (level) {
305         case 1:
306                 buffer1 = (PJOB_INFO_1)buffer;
307                 break;
308         case 2:
309                 buffer2 = (PJOB_INFO_2)buffer;
310                 break;
311         case 3:
312                 buffer3 = (PJOB_INFO_3)buffer;
313                 break;
314         case 4:
315                 buffer4 = (PJOB_INFO_4)buffer;
316                 break;
317         default:
318                 break;
319         }
320
321         printf("Job Info Level %d:\n", level);
322
323         switch (level) {
324         case 1:
325                 for (i=0; i<count; i++) {
326                         print_job_info_1(&buffer1[i]);
327                         printf("\n");
328                 }
329                 break;
330         case 2:
331                 for (i=0; i<count; i++) {
332                         print_job_info_2(&buffer2[i]);
333                         printf("\n");
334                 }
335                 break;
336         case 3:
337                 for (i=0; i<count; i++) {
338                         print_job_info_3(&buffer3[i]);
339                         printf("\n");
340                 }
341                 break;
342         case 4:
343                 for (i=0; i<count; i++) {
344                         print_job_info_4(&buffer4[i]);
345                         printf("\n");
346                 }
347                 break;
348         default:
349                 break;
350         }
351 }
352
353 void print_monitor_info_1(PMONITOR_INFO_1 info)
354 {
355         printf("\tMonitor Name\t= %s\n",        info->pName);
356
357         return;
358 }
359
360 void print_monitor_info_2(PMONITOR_INFO_2 info)
361 {
362         printf("\tMonitor Name\t= %s\n",        info->pName);
363         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
364         printf("\tDLL Name\t= %s\n",            info->pDLLName);
365
366         return;
367 }
368
369 void print_monitor_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
370 {
371         DWORD i;
372         PMONITOR_INFO_1 buffer1 = NULL;
373         PMONITOR_INFO_2 buffer2 = NULL;
374
375         if (!buffer) {
376                 return;
377         }
378
379         switch (level) {
380         case 1:
381                 buffer1 = (PMONITOR_INFO_1)buffer;
382                 break;
383         case 2:
384                 buffer2 = (PMONITOR_INFO_2)buffer;
385                 break;
386         default:
387                 break;
388         }
389
390         printf("Monitor Info Level %d:\n", level);
391
392         switch (level) {
393         case 1:
394                 for (i=0; i<count; i++) {
395                         print_monitor_info_1(&buffer1[i]);
396                         printf("\n");
397                 }
398                 break;
399         case 2:
400                 for (i=0; i<count; i++) {
401                         print_monitor_info_2(&buffer2[i]);
402                         printf("\n");
403                 }
404                 break;
405         default:
406                 break;
407         }
408 }
409
410 void print_port_info_1(PPORT_INFO_1 info)
411 {
412         printf("\tPort Name\t= %s\n",   info->pName);
413         return;
414 }
415
416 void print_port_info_2(PPORT_INFO_2 info)
417 {
418         printf("\tPort Name\t= %s\n",   info->pPortName);
419         printf("\tMonitor Name\t= %s\n",info->pMonitorName);
420         printf("\tDescription\t= %s\n", info->pDescription);
421         printf("\tPort Type\t= 0x%08x\n", info->fPortType);
422         printf("\tReserved\t= 0x%08x\n", info->Reserved);
423         return;
424 }
425
426 void print_port_info_3(PPORT_INFO_3 info)
427 {
428         printf("\tStatus\t= 0x%08x\n", info->dwStatus);
429         printf("\tStatus String\t= %s\n", info->pszStatus);
430         printf("\tSeverity\t= 0x%08x\n", info->dwSeverity);
431         return;
432 }
433
434 void print_port_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
435 {
436         DWORD i;
437         PPORT_INFO_1 buffer1 = NULL;
438         PPORT_INFO_2 buffer2 = NULL;
439         PPORT_INFO_3 buffer3 = NULL;
440
441         if (!buffer) {
442                 return;
443         }
444
445         switch (level) {
446         case 1:
447                 buffer1 = (PPORT_INFO_1)buffer;
448                 break;
449         case 2:
450                 buffer2 = (PPORT_INFO_2)buffer;
451                 break;
452         case 3:
453                 buffer3 = (PPORT_INFO_3)buffer;
454                 break;
455         default:
456                 break;
457         }
458
459         printf("Port Info Level %d:\n", level);
460
461         switch (level) {
462         case 1:
463                 for (i=0; i<count; i++) {
464                         print_port_info_1(&buffer1[i]);
465                         printf("\n");
466                 }
467                 break;
468         case 2:
469                 for (i=0; i<count; i++) {
470                         print_port_info_2(&buffer2[i]);
471                         printf("\n");
472                 }
473                 break;
474         case 3:
475                 for (i=0; i<count; i++) {
476                         print_port_info_3(&buffer3[i]);
477                         printf("\n");
478                 }
479                 break;
480         default:
481                 break;
482         }
483 }
484
485 void print_form_info_1(PFORM_INFO_1 info)
486 {
487         printf("\tForm Name\t= %s\n",   info->pName);
488         printf("\tFlags\t\t= 0x%x\n",   info->Flags);
489         printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
490         printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
491                         info->ImageableArea.left, info->ImageableArea.right,
492                         info->ImageableArea.top, info->ImageableArea.bottom);
493
494         return;
495 }
496
497 void print_form_info_2(PFORM_INFO_2 info)
498 {
499         printf("\tForm Name\t= %s\n",   info->pName);
500         printf("\tFlags\t\t= 0x%x\n",   info->Flags);
501         printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
502         printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
503                         info->ImageableArea.left, info->ImageableArea.right,
504                         info->ImageableArea.top, info->ImageableArea.bottom);
505         printf("\tKeyword\t= %s\n",     info->pKeyword);
506         printf("\tString Type\t= 0x%08x\n", info->StringType);
507         printf("\tMui DLL\t= %s\n",     info->pMuiDll);
508         printf("\tResource Id\t= 0x%08x\n", info->dwResourceId);
509         printf("\tDisplay Name\t= %s\n",info->pDisplayName);
510         printf("\tLang Id\t= 0x%04x\n", info->wLangId);
511
512         return;
513 }
514
515 void print_form_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
516 {
517         DWORD i;
518         PFORM_INFO_1 buffer1 = NULL;
519         PFORM_INFO_2 buffer2 = NULL;
520
521         if (!buffer) {
522                 return;
523         }
524
525         switch (level) {
526         case 1:
527                 buffer1 = (PFORM_INFO_1)buffer;
528                 break;
529         case 2:
530                 buffer2 = (PFORM_INFO_2)buffer;
531                 break;
532         default:
533                 break;
534         }
535
536         printf("Form Info Level %d:\n", level);
537
538         switch (level) {
539         case 1:
540                 for (i=0; i<count; i++) {
541                         print_form_info_1(&buffer1[i]);
542                         printf("\n");
543                 }
544                 break;
545         case 2:
546                 for (i=0; i<count; i++) {
547                         print_form_info_2(&buffer2[i]);
548                         printf("\n");
549                 }
550                 break;
551         default:
552                 break;
553         }
554 }
555
556 void print_printer_info_1(PPRINTER_INFO_1 info)
557 {
558         printf("\tPrinter Name\t= %s\n",        info->pName);
559         printf("\tDescription\t= %s\n",         info->pDescription);
560         printf("\tComment\t\t= %s\n",           info->pComment);
561         printf("\tFlags\t\t= 0x%x\n",           info->Flags);
562
563         return;
564 }
565
566 void print_printer_info_2(PPRINTER_INFO_2 info)
567 {
568         printf("\tServer Name\t\t= %s\n",       info->pServerName);
569         printf("\tPrinter Name\t\t= %s\n",      info->pPrinterName);
570         printf("\tPort Name\t\t= %s\n",         info->pPortName);
571         printf("\tShare Name\t\t= %s\n",        info->pShareName);
572         printf("\tDriver Name\t\t= %s\n",       info->pDriverName);
573         printf("\tComment\t\t\t= %s\n",         info->pComment);
574         printf("\tLocation\t\t= %s\n",          info->pLocation);
575         printf("\tSeparator File\t\t= %s\n",    info->pSepFile);
576         printf("\tDefault Data Type\t= %s\n",   info->pDatatype);
577         printf("\tPrint Processor\t\t= %s\n",   info->pPrintProcessor);
578         printf("\tParameters\t\t= %s\n",        info->pParameters);
579         printf("\tAttributes\t\t= 0x%x\n",      info->Attributes);
580         printf("\tPriority\t\t= 0x%x\n",        info->Priority);
581         printf("\tDefault Priority\t= 0x%x\n",  info->DefaultPriority);
582         printf("\tStart Time\t\t= 0x%x\n",      info->StartTime);
583         printf("\tUntil Time\t\t= 0x%x\n",      info->UntilTime);
584         printf("\tStatus\t\t\t= 0x%x\n",        info->Status);
585         printf("\tcJobs\t\t\t= 0x%x\n",         info->cJobs);
586         printf("\tAverage PPM\t\t= 0x%x\n",     info->AveragePPM);
587
588         printf("\tDevice Mode Information\n");
589         printf("\t-----------------------\n");
590         print_devmode(info->pDevMode);
591         printf("\tSecurity Descriptor Information\n");
592         printf("\t-------------------------------\n");
593         print_secdesc(info->pSecurityDescriptor);
594         return;
595 }
596
597 void print_printer_info_5(PPRINTER_INFO_5 info)
598 {
599         printf("\tPrinter Name\t\t\t= %s\n",            info->pPrinterName);
600         printf("\tPort Name\t\t\t= %s\n",               info->pPortName);
601         printf("\tAttributes\t\t\t= 0x%x\n",            info->Attributes);
602         printf("\tDev NotSelect Timeout\t= 0x%x\n",     info->DeviceNotSelectedTimeout);
603         printf("\tTX RetryTimeout\t\t= 0x%x\n",         info->TransmissionRetryTimeout);
604         return;
605 }
606
607 void print_printer_info_6(PPRINTER_INFO_6 info)
608 {
609         printf("\tStatus\t\t\t= 0x%x\n",                info->dwStatus);
610         return;
611 }
612
613 void print_printer_info_7(PPRINTER_INFO_7 info)
614 {
615         printf("\tObject GUID\t\t\t= %s\n",             info->pszObjectGUID);
616         printf("\tAction\t\t\t= 0x%x\n",                info->dwAction);
617         return;
618 }
619
620 void print_printer_info_8(PPRINTER_INFO_8 info)
621 {
622         print_devmode(info->pDevMode);
623 }
624
625 void print_printer_info_9(PPRINTER_INFO_9 info)
626 {
627         print_devmode(info->pDevMode);
628 }
629
630 void print_printer_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
631 {
632         DWORD i;
633         PPRINTER_INFO_1 buffer1 = NULL;
634         PPRINTER_INFO_2 buffer2 = NULL;
635         PPRINTER_INFO_3 buffer3 = NULL;
636         PPRINTER_INFO_4 buffer4 = NULL;
637         PPRINTER_INFO_5 buffer5 = NULL;
638         PPRINTER_INFO_6 buffer6 = NULL;
639         PPRINTER_INFO_7 buffer7 = NULL;
640         PPRINTER_INFO_8 buffer8 = NULL;
641
642         if (!buffer) {
643                 return;
644         }
645
646         switch (level) {
647         case 1:
648                 buffer1 = (PPRINTER_INFO_1)buffer;
649                 break;
650         case 2:
651                 buffer2 = (PPRINTER_INFO_2)buffer;
652                 break;
653         case 3:
654                 buffer3 = (PPRINTER_INFO_3)buffer;
655                 break;
656         case 4:
657                 buffer4 = (PPRINTER_INFO_4)buffer;
658                 break;
659         case 5:
660                 buffer5 = (PPRINTER_INFO_5)buffer;
661                 break;
662         case 6:
663                 buffer6 = (PPRINTER_INFO_6)buffer;
664                 break;
665         case 7:
666                 buffer7 = (PPRINTER_INFO_7)buffer;
667                 break;
668         case 8:
669                 buffer8 = (PPRINTER_INFO_8)buffer;
670                 break;
671         default:
672                 break;
673         }
674
675         printf("Printer Info Level %d:\n", level);
676
677         switch (level) {
678         case 1:
679                 for (i=0; i<count; i++) {
680                         print_printer_info_1(&buffer1[i]);
681                         printf("\n");
682                 }
683                 break;
684         case 2:
685                 for (i=0; i<count; i++) {
686                         print_printer_info_2(&buffer2[i]);
687                         printf("\n");
688                 }
689                 break;
690 #if 0
691         case 3:
692                 for (i=0; i<count; i++) {
693                         print_printer_info_3(&buffer3[i]);
694                         printf("\n");
695                 }
696                 break;
697         case 4:
698                 for (i=0; i<count; i++) {
699                         print_printer_info_4(&buffer4[i]);
700                         printf("\n");
701                 }
702                 break;
703 #endif
704         case 5:
705                 for (i=0; i<count; i++) {
706                         print_printer_info_5(&buffer5[i]);
707                         printf("\n");
708                 }
709                 break;
710         case 6:
711                 for (i=0; i<count; i++) {
712                         print_printer_info_6(&buffer6[i]);
713                         printf("\n");
714                 }
715                 break;
716         case 7:
717                 for (i=0; i<count; i++) {
718                         print_printer_info_7(&buffer7[i]);
719                         printf("\n");
720                 }
721                 break;
722         case 8:
723                 for (i=0; i<count; i++) {
724                         print_printer_info_8(&buffer8[i]);
725                         printf("\n");
726                 }
727                 break;
728         default:
729                 break;
730         }
731 }
732
733 void print_printprocessor_info_1(PPRINTPROCESSOR_INFO_1 info)
734 {
735         printf("\tPrint Processor Name\t= %s\n", info->pName);
736
737         return;
738 }
739
740 void print_printprocessor_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
741 {
742         DWORD i;
743         PPRINTPROCESSOR_INFO_1 buffer1 = NULL;
744
745         if (!buffer) {
746                 return;
747         }
748
749         switch (level) {
750         case 1:
751                 buffer1 = (PPRINTPROCESSOR_INFO_1)buffer;
752                 break;
753         default:
754                 break;
755         }
756
757         printf("Print Processor Info Level %d:\n", level);
758
759         switch (level) {
760         case 1:
761                 for (i=0; i<count; i++) {
762                         print_printprocessor_info_1(&buffer1[i]);
763                         printf("\n");
764                 }
765                 break;
766         default:
767                 break;
768         }
769 }
770
771 void print_datatypes_info_1(PDATATYPES_INFO_1 info)
772 {
773         printf("\tDataTypes Name\t= %s\n", info->pName);
774
775         return;
776 }
777
778 void print_datatypes_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
779 {
780         DWORD i;
781         PDATATYPES_INFO_1 buffer1 = NULL;
782
783         if (!buffer) {
784                 return;
785         }
786
787         switch (level) {
788         case 1:
789                 buffer1 = (PDATATYPES_INFO_1)buffer;
790                 break;
791         default:
792                 break;
793         }
794
795         printf("DataTypes Info Level %d:\n", level);
796
797         switch (level) {
798         case 1:
799                 for (i=0; i<count; i++) {
800                         print_datatypes_info_1(&buffer1[i]);
801                         printf("\n");
802                 }
803                 break;
804         default:
805                 break;
806         }
807 }
808
809 void print_driver_info_1(PDRIVER_INFO_1 info)
810 {
811         printf("\tDriver Name\t= %s\n\n",       info->pName);
812
813         return;
814 }
815
816 void print_driver_info_2(PDRIVER_INFO_2 info)
817 {
818         printf("\tDriver Name\t= %s\n",         info->pName);
819         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
820         printf("\tVersion\t\t= %d\n",           info->cVersion);
821         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
822         printf("\tData File\t= %s\n",           info->pDataFile);
823         printf("\tConfig File\t= %s\n\n",       info->pConfigFile);
824
825         return;
826 }
827
828 void print_driver_info_3(PDRIVER_INFO_3 info)
829 {
830         char *ptr = NULL;
831
832         printf("\tDriver Name\t= %s\n",         info->pName);
833         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
834         printf("\tVersion\t\t= %d\n",           info->cVersion);
835         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
836         printf("\tData File\t= %s\n",           info->pDataFile);
837         printf("\tConfig File\t= %s\n",         info->pConfigFile);
838         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
839         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
840         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
841         ptr = (char*)info->pDependentFiles;
842         while ((ptr != NULL) && (*ptr != '\0')) {
843                 printf("\tDependent Files\t= %s\n", ptr);
844                 for (;*ptr != '\0'; ptr++)
845                         /* printf("%s\n", ptr); */
846                         ;
847                 ptr++;
848         }
849
850         return;
851 }
852
853 void print_driver_info_4(PDRIVER_INFO_4 info)
854 {
855         char *ptr = NULL;
856
857         printf("\tDriver Name\t= %s\n",         info->pName);
858         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
859         printf("\tVersion\t\t= %d\n",           info->cVersion);
860         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
861         printf("\tData File\t= %s\n",           info->pDataFile);
862         printf("\tConfig File\t= %s\n",         info->pConfigFile);
863         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
864         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
865         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
866         printf("\tPrevious Names\t= %s\n",      info->pszzPreviousNames);
867         ptr = (char*)info->pDependentFiles;
868         while ((ptr != NULL) && (*ptr != '\0')) {
869                 printf("\tDependent Files\t= %s\n", ptr);
870                 for (;*ptr != '\0'; ptr++)
871                         /* printf("%s\n", ptr); */
872                         ;
873                 ptr++;
874         }
875
876         return;
877 }
878
879 void print_driver_info_5(PDRIVER_INFO_5 info)
880 {
881         printf("\tDriver Name\t= %s\n",         info->pName);
882         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
883         printf("\tVersion\t\t= %d\n",           info->cVersion);
884         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
885         printf("\tData File\t= %s\n",           info->pDataFile);
886         printf("\tConfig File\t= %s\n",         info->pConfigFile);
887         printf("\tDriver Attributes\t= %d\n",   info->dwDriverAttributes);
888         printf("\tConfig Version\t= %d\n",      info->dwConfigVersion);
889         printf("\tDriver Version\t= %d\n",      info->dwDriverVersion);
890
891         return;
892 }
893
894 void print_driver_info_6(PDRIVER_INFO_6 info)
895 {
896         char *ptr = NULL;
897
898         printf("\tDriver Name\t= %s\n",         info->pName);
899         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
900         printf("\tVersion\t\t= %d\n",           info->cVersion);
901         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
902         printf("\tData File\t= %s\n",           info->pDataFile);
903         printf("\tConfig File\t= %s\n",         info->pConfigFile);
904         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
905         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
906         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
907         printf("\tPrevious Names\t= %s\n",      info->pszzPreviousNames);
908         ptr = (char*)info->pDependentFiles;
909         if (ptr != NULL) {
910                 while (*ptr != '\0') {
911                         printf("\tDependent Files\t= %s\n", ptr);
912                         for (;*ptr != '\0'; ptr++)
913                                 /* printf("%s\n", ptr); */
914                                 ;
915                         ptr++;
916                 }
917         } else {
918                 printf("\tPrevious Names\t= (null)\n");
919         }
920
921         ptr = (char*)info->pszzPreviousNames;
922         if (ptr != NULL) {
923                 while (*ptr != '\0') {
924                         printf("\tPrevious Names\t= %s\n", ptr);
925                         for (;*ptr != '\0'; ptr++)
926                                 /* printf("%s\n", ptr); */
927                                 ;
928                         ptr++;
929                 }
930         } else {
931                 printf("\tPrevious Names\t= (null)\n");
932         }
933
934         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
935         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
936         printf("\tManufacture Name = %s\n",     info->pszMfgName);
937         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
938         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
939         printf("\tProvider\t= %s\n",            info->pszProvider);
940         return;
941 }
942
943 static void print_multi_sz(LPSTR multisz)
944 {
945         char *ptr = NULL;
946
947         ptr = (char *)multisz;
948
949         if (!ptr) {
950                 printf("(null)\n");
951                 return;
952         }
953
954         while (*ptr != '\0') {
955                 printf("%s\n", ptr);
956                 for (; *ptr != '\0'; ptr++) {
957                         /* printf("%s\n", ptr); */
958                         ;
959                 }
960                 ptr++;
961         }
962 }
963
964 void print_driver_info_8(PDRIVER_INFO_8 info)
965 {
966         printf("\tDriver Name\t= %s\n",         info->pName);
967         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
968         printf("\tVersion\t\t= %d\n",           info->cVersion);
969         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
970         printf("\tData File\t= %s\n",           info->pDataFile);
971         printf("\tConfig File\t= %s\n",         info->pConfigFile);
972         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
973         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
974         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
975         printf("\tPrevious Names\t=\n");
976         print_multi_sz(info->pszzPreviousNames);
977         printf("\tDependent Files\t=\n");
978         print_multi_sz(info->pDependentFiles);
979         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
980         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
981         printf("\tManufacture Name = %s\n",     info->pszMfgName);
982         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
983         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
984         printf("\tProvider\t= %s\n",            info->pszProvider);
985         printf("\tPrint Processor\t= %s\n",     info->pszPrintProcessor);
986         printf("\tVendor Setup\t= %s\n",        info->pszVendorSetup);
987         printf("\tColor Profiles\t=\n");
988         print_multi_sz(info->pszzColorProfiles);
989         printf("\tInf Path\t= %s\n",            info->pszInfPath);
990         printf("\tPrinter Driver Attributes = %d\n", info->dwPrinterDriverAttributes);
991         printf("\tCore Driver Dependencies\t=\n");
992         print_multi_sz(info->pszzCoreDriverDependencies);
993         printf("\tMin Inbox Driver VerDate\t= %d\n", info->ftMinInboxDriverVerDate);
994         printf("\tMin Inbox Driver VerVersion\t= %d\n", info->dwlMinInboxDriverVerVersion);
995         return;
996 }
997
998 void print_driver_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
999 {
1000         DWORD i;
1001         PDRIVER_INFO_1  buffer1 = NULL;
1002         PDRIVER_INFO_2  buffer2 = NULL;
1003         PDRIVER_INFO_3  buffer3 = NULL;
1004         PDRIVER_INFO_4  buffer4 = NULL;
1005         PDRIVER_INFO_5  buffer5 = NULL;
1006         PDRIVER_INFO_6  buffer6 = NULL;
1007         PDRIVER_INFO_8  buffer8 = NULL;
1008
1009         if (!buffer) {
1010                 return;
1011         }
1012
1013         switch (level) {
1014         case 1:
1015                 buffer1 = (PDRIVER_INFO_1)buffer;
1016                 break;
1017         case 2:
1018                 buffer2 = (PDRIVER_INFO_2)buffer;
1019                 break;
1020         case 3:
1021                 buffer3 = (PDRIVER_INFO_3)buffer;
1022                 break;
1023         case 4:
1024                 buffer4 = (PDRIVER_INFO_4)buffer;
1025                 break;
1026         case 5:
1027                 buffer5 = (PDRIVER_INFO_5)buffer;
1028                 break;
1029         case 6:
1030                 buffer6 = (PDRIVER_INFO_6)buffer;
1031                 break;
1032         case 8:
1033                 buffer8 = (PDRIVER_INFO_8)buffer;
1034                 break;
1035         default:
1036                 break;
1037         }
1038
1039         printf("Driver Info Level %d:\n", level);
1040
1041         switch (level) {
1042         case 1:
1043                 for (i=0; i<count; i++) {
1044                         print_driver_info_1(&buffer1[i]);
1045                         printf("\n");
1046                 }
1047                 break;
1048         case 2:
1049                 for (i=0; i<count; i++) {
1050                         print_driver_info_2(&buffer2[i]);
1051                         printf("\n");
1052                 }
1053                 break;
1054         case 3:
1055                 for (i=0; i<count; i++) {
1056                         print_driver_info_3(&buffer3[i]);
1057                         printf("\n");
1058                 }
1059                 break;
1060         case 4:
1061                 for (i=0; i<count; i++) {
1062                         print_driver_info_4(&buffer4[i]);
1063                         printf("\n");
1064                 }
1065                 break;
1066         case 5:
1067                 for (i=0; i<count; i++) {
1068                         print_driver_info_5(&buffer5[i]);
1069                         printf("\n");
1070                 }
1071                 break;
1072         case 6:
1073                 for (i=0; i<count; i++) {
1074                         print_driver_info_6(&buffer6[i]);
1075                         printf("\n");
1076                 }
1077                 break;
1078         case 8:
1079                 for (i=0; i<count; i++) {
1080                         print_driver_info_8(&buffer8[i]);
1081                         printf("\n");
1082                 }
1083                 break;
1084         default:
1085                 break;
1086         }
1087 }
1088
1089 void print_doc_info_1(PDOC_INFO_1 info)
1090 {
1091         printf("\tDocument Name\t= %s\n",       info->pDocName);
1092         printf("\tOutput Filename\t= %s\n",     info->pOutputFile);
1093         printf("\tDatatype\t= %s\n",            info->pDatatype);
1094         return;
1095 }
1096
1097 void print_printer_keys(LPSTR buffer)
1098 {
1099         LPSTR p = NULL;
1100
1101         p = buffer;
1102
1103         while (p && *p) {
1104                 printf("%s\n", p);
1105                 for (; *p; p = CharNext(p)) {
1106                         p = CharNext(p);
1107                 }
1108         }
1109 }
1110
1111 static LPSTR reg_type_str(DWORD type)
1112 {
1113         switch (type) {
1114         case REG_DWORD:
1115                 return "REG_DWORD";
1116         case REG_SZ:
1117                 return "REG_SZ";
1118         case REG_MULTI_SZ:
1119                 return "REG_MULTI_SZ";
1120         case REG_BINARY:
1121                 return "REG_BINARY";
1122         default:
1123                 return NULL;
1124         }
1125 }
1126
1127 void print_printer_data(LPSTR keyname, LPSTR valuename, DWORD size, LPBYTE buffer, DWORD type)
1128 {
1129         DWORD i = 0;
1130         LPSTR p = NULL;
1131
1132         if (keyname) {
1133                 printf("\tKey Name:\t%s\n", keyname);
1134         }
1135
1136         printf("\tValue Name:\t%s\n", valuename);
1137         printf("\tSize: 0x%x (%d)\n", size, size);
1138         printf("\tType:\t\t%s\n", reg_type_str(type));
1139
1140         switch (type) {
1141         case REG_SZ:
1142                 printf("\t\t%s\n", (LPSTR)buffer);
1143                 break;
1144         case REG_MULTI_SZ:
1145                 p = (LPSTR)buffer;
1146                 while (p && *p) {
1147                         printf("%s\n", p);
1148                         for (; *p; p = CharNext(p)) {
1149                                 p = CharNext(p);
1150                         }
1151                 }
1152                 break;
1153         case REG_DWORD:
1154                 assert(size == 4);
1155                 printf("\t\t0x%08x\n", (DWORD)*buffer);
1156                 break;
1157         case REG_BINARY:
1158                 for (i=0; i < size; i++) {
1159                         printf("\t0x%x", buffer[i]);
1160                         if (i%4 == 3) {
1161                                 printf("\n");
1162                         }
1163                 }
1164                 break;
1165         default:
1166                 break;
1167         }
1168 }
1169
1170 void print_printer_enum_values(PRINTER_ENUM_VALUES *info)
1171 {
1172         print_printer_data(NULL, info->pValueName, info->cbData, info->pData, info->dwType);
1173 }
1174