testprogs: use ConvertSidToStringSid in order to print sids 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 #if 0
163         print_sid("\tOwner\t\t= ", secdesc->Owner);
164         print_sid("\tGroup\t\t= ",secdesc->Group);
165         print_acl("\tSacl\t\t= ", secdesc->Sacl);
166         print_acl("\tDacl\t\t= ", secdesc->Dacl);
167 #endif
168         return;
169 }
170
171 void PrintLastError()
172 {
173         LPVOID lpMsgBuf;
174         DWORD status;
175
176         status = GetLastError();
177
178         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
179                       NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
180                       (LPTSTR)&lpMsgBuf, 0, NULL);
181         printf("ERROR  [0x%x] : %s\n", status, (char*)lpMsgBuf);
182         LocalFree(lpMsgBuf);
183
184         return;
185 }
186
187
188 void print_job_info_1(PJOB_INFO_1 info)
189 {
190         printf("\tJob ID\t\t= %d\n",            info->JobId);
191         printf("\tPrinter Name\t= %s\n",        info->pPrinterName);
192         printf("\tMachine Name\t= %s\n",        info->pMachineName);
193         printf("\tUser Name\t= %s\n",           info->pUserName);
194         printf("\tDocument\t= %s\n",            info->pDocument);
195         printf("\tDatatype\t= %s\n",            info->pDatatype);
196         printf("\tStatus\t\t= %s\n",            info->pStatus);
197         printf("\tStatus\t= %d\n",              info->Status);
198         printf("\tPriority\t= %d\n",            info->Priority);
199         printf("\tPosition\t= %d\n",            info->Position);
200         printf("\tTotal Pages\t= %d\n", info->TotalPages);
201         printf("\tPages Printed\t= %d\n",       info->PagesPrinted);
202         printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
203                 info->Submitted.wDay, info->Submitted.wMonth,
204                 info->Submitted.wYear, info->Submitted.wHour,
205                 info->Submitted.wMinute, info->Submitted.wSecond);
206
207         return;
208 }
209
210 void print_job_info_2(PJOB_INFO_2 info)
211 {
212         printf("\tJob ID\t\t= %d\n",            info->JobId);
213         printf("\tPrinter Name\t= %s\n",        info->pPrinterName);
214         printf("\tMachine Name\t= %s\n",        info->pMachineName);
215         printf("\tUser Name\t= %s\n",           info->pUserName);
216         printf("\tDocument\t= %s\n",            info->pDocument);
217         printf("\tDatatype\t= %s\n",            info->pDatatype);
218         printf("\tNotify Name\t= %s\n",         info->pNotifyName);
219         printf("\tPrint Processor\t= %s\n",     info->pPrintProcessor);
220         printf("\tParameters\t= %s\n",          info->pParameters);
221         printf("\tDriver Name\t= %s\n",         info->pDriverName);
222         printf("\tStatus\t\t= %s\n",            info->pStatus);
223         printf("\tStatus\t\t= %d\n",            info->Status);
224         printf("\tPriority\t= %d\n",            info->Priority);
225         printf("\tPosition\t= %d\n",            info->Position);
226         printf("\tTotal Pages\t= %d\n",         info->TotalPages);
227         printf("\tPages Printed\t= %d\n",       info->PagesPrinted);
228         printf("\tStart Time\t= %d\n",          info->StartTime);
229         printf("\tUntil Time\t= %d\n",          info->UntilTime);
230         printf("\tTime\t\t= %d\n",              info->Time);
231         printf("\tSize\t\t= %d\n",              info->Size);
232         printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
233                 info->Submitted.wDay, info->Submitted.wMonth,
234                 info->Submitted.wYear, info->Submitted.wHour,
235                 info->Submitted.wMinute, info->Submitted.wSecond);
236         printf("\tDevice Mode Information\n");
237         printf("\t-----------------------\n");
238         print_devmode(info->pDevMode);
239         printf("\tSecurity Descriptor Information\n");
240         printf("\t-------------------------------\n");
241         print_secdesc(info->pSecurityDescriptor);
242
243         return;
244 }
245
246 void print_job_info_3(PJOB_INFO_3 info)
247 {
248         printf("\tJob ID\t\t= %d\n",            info->JobId);
249         printf("\tJob ID Next Job\t= %d\n",     info->NextJobId);
250         printf("\tReserved (must be 0)\t= %d\n",info->Reserved);
251
252         return;
253 }
254
255 void print_job_info_4(PJOB_INFO_4 info)
256 {
257         printf("\tJob ID\t\t= %d\n",            info->JobId);
258         printf("\tPrinter Name\t= %s\n",        info->pPrinterName);
259         printf("\tMachine Name\t= %s\n",        info->pMachineName);
260         printf("\tUser Name\t= %s\n",           info->pUserName);
261         printf("\tDocument\t= %s\n",            info->pDocument);
262         printf("\tDatatype\t= %s\n",            info->pDatatype);
263         printf("\tNotify Name\t= %s\n",         info->pNotifyName);
264         printf("\tPrint Processor\t= %s\n",     info->pPrintProcessor);
265         printf("\tDriver Name\t= %s\n",         info->pDriverName);
266         printf("\tStatus\t\t= %s\n",            info->pStatus);
267         printf("\tStatus\t\t= %d\n",            info->Status);
268         printf("\tPriority\t= %d\n",            info->Priority);
269         printf("\tPosition\t= %d\n",            info->Position);
270         printf("\tTotal Pages\t= %d\n",         info->TotalPages);
271         printf("\tPages Printed\t= %d\n",       info->PagesPrinted);
272         printf("\tStart Time\t= %d\n",          info->StartTime);
273         printf("\tUntil Time\t= %d\n",          info->UntilTime);
274         printf("\tTime\t\t= %d\n",              info->Time);
275         printf("\tSize\t\t= %d\n",              info->Size);
276         printf("\tSize High\t\t= 0x%016x\n",    info->SizeHigh);
277         printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
278                 info->Submitted.wDay, info->Submitted.wMonth,
279                 info->Submitted.wYear, info->Submitted.wHour,
280                 info->Submitted.wMinute, info->Submitted.wSecond);
281         printf("\tDevice Mode Information\n");
282         printf("\t-----------------------\n");
283         print_devmode(info->pDevMode);
284         printf("\tSecurity Descriptor Information\n");
285         printf("\t-------------------------------\n");
286         print_secdesc(info->pSecurityDescriptor);
287
288         return;
289 }
290
291 void print_job_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
292 {
293         DWORD i;
294         PJOB_INFO_1     buffer1 = NULL;
295         PJOB_INFO_2     buffer2 = NULL;
296         PJOB_INFO_3     buffer3 = NULL;
297         PJOB_INFO_4     buffer4 = NULL;
298
299         if (!buffer) {
300                 return;
301         }
302
303         switch (level) {
304         case 1:
305                 buffer1 = (PJOB_INFO_1)buffer;
306                 break;
307         case 2:
308                 buffer2 = (PJOB_INFO_2)buffer;
309                 break;
310         case 3:
311                 buffer3 = (PJOB_INFO_3)buffer;
312                 break;
313         case 4:
314                 buffer4 = (PJOB_INFO_4)buffer;
315                 break;
316         default:
317                 break;
318         }
319
320         printf("Job Info Level %d:\n", level);
321
322         switch (level) {
323         case 1:
324                 for (i=0; i<count; i++) {
325                         print_job_info_1(&buffer1[i]);
326                         printf("\n");
327                 }
328                 break;
329         case 2:
330                 for (i=0; i<count; i++) {
331                         print_job_info_2(&buffer2[i]);
332                         printf("\n");
333                 }
334                 break;
335         case 3:
336                 for (i=0; i<count; i++) {
337                         print_job_info_3(&buffer3[i]);
338                         printf("\n");
339                 }
340                 break;
341         case 4:
342                 for (i=0; i<count; i++) {
343                         print_job_info_4(&buffer4[i]);
344                         printf("\n");
345                 }
346                 break;
347         default:
348                 break;
349         }
350 }
351
352 void print_monitor_info_1(PMONITOR_INFO_1 info)
353 {
354         printf("\tMonitor Name\t= %s\n",        info->pName);
355
356         return;
357 }
358
359 void print_monitor_info_2(PMONITOR_INFO_2 info)
360 {
361         printf("\tMonitor Name\t= %s\n",        info->pName);
362         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
363         printf("\tDLL Name\t= %s\n",            info->pDLLName);
364
365         return;
366 }
367
368 void print_monitor_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
369 {
370         DWORD i;
371         PMONITOR_INFO_1 buffer1 = NULL;
372         PMONITOR_INFO_2 buffer2 = NULL;
373
374         if (!buffer) {
375                 return;
376         }
377
378         switch (level) {
379         case 1:
380                 buffer1 = (PMONITOR_INFO_1)buffer;
381                 break;
382         case 2:
383                 buffer2 = (PMONITOR_INFO_2)buffer;
384                 break;
385         default:
386                 break;
387         }
388
389         printf("Monitor Info Level %d:\n", level);
390
391         switch (level) {
392         case 1:
393                 for (i=0; i<count; i++) {
394                         print_monitor_info_1(&buffer1[i]);
395                         printf("\n");
396                 }
397                 break;
398         case 2:
399                 for (i=0; i<count; i++) {
400                         print_monitor_info_2(&buffer2[i]);
401                         printf("\n");
402                 }
403                 break;
404         default:
405                 break;
406         }
407 }
408
409 void print_port_info_1(PPORT_INFO_1 info)
410 {
411         printf("\tPort Name\t= %s\n",   info->pName);
412         return;
413 }
414
415 void print_port_info_2(PPORT_INFO_2 info)
416 {
417         printf("\tPort Name\t= %s\n",   info->pPortName);
418         printf("\tMonitor Name\t= %s\n",info->pMonitorName);
419         printf("\tDescription\t= %s\n", info->pDescription);
420         printf("\tPort Type\t= 0x%08x\n", info->fPortType);
421         printf("\tReserved\t= 0x%08x\n", info->Reserved);
422         return;
423 }
424
425 void print_port_info_3(PPORT_INFO_3 info)
426 {
427         printf("\tStatus\t= 0x%08x\n", info->dwStatus);
428         printf("\tStatus String\t= %s\n", info->pszStatus);
429         printf("\tSeverity\t= 0x%08x\n", info->dwSeverity);
430         return;
431 }
432
433 void print_port_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
434 {
435         DWORD i;
436         PPORT_INFO_1 buffer1 = NULL;
437         PPORT_INFO_2 buffer2 = NULL;
438         PPORT_INFO_3 buffer3 = NULL;
439
440         if (!buffer) {
441                 return;
442         }
443
444         switch (level) {
445         case 1:
446                 buffer1 = (PPORT_INFO_1)buffer;
447                 break;
448         case 2:
449                 buffer2 = (PPORT_INFO_2)buffer;
450                 break;
451         case 3:
452                 buffer3 = (PPORT_INFO_3)buffer;
453                 break;
454         default:
455                 break;
456         }
457
458         printf("Port Info Level %d:\n", level);
459
460         switch (level) {
461         case 1:
462                 for (i=0; i<count; i++) {
463                         print_port_info_1(&buffer1[i]);
464                         printf("\n");
465                 }
466                 break;
467         case 2:
468                 for (i=0; i<count; i++) {
469                         print_port_info_2(&buffer2[i]);
470                         printf("\n");
471                 }
472                 break;
473         case 3:
474                 for (i=0; i<count; i++) {
475                         print_port_info_3(&buffer3[i]);
476                         printf("\n");
477                 }
478                 break;
479         default:
480                 break;
481         }
482 }
483
484 void print_form_info_1(PFORM_INFO_1 info)
485 {
486         printf("\tForm Name\t= %s\n",   info->pName);
487         printf("\tFlags\t\t= 0x%x\n",   info->Flags);
488         printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
489         printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
490                         info->ImageableArea.left, info->ImageableArea.right,
491                         info->ImageableArea.top, info->ImageableArea.bottom);
492
493         return;
494 }
495
496 void print_form_info_2(PFORM_INFO_2 info)
497 {
498         printf("\tForm Name\t= %s\n",   info->pName);
499         printf("\tFlags\t\t= 0x%x\n",   info->Flags);
500         printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
501         printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
502                         info->ImageableArea.left, info->ImageableArea.right,
503                         info->ImageableArea.top, info->ImageableArea.bottom);
504         printf("\tKeyword\t= %s\n",     info->pKeyword);
505         printf("\tString Type\t= 0x%08x\n", info->StringType);
506         printf("\tMui DLL\t= %s\n",     info->pMuiDll);
507         printf("\tResource Id\t= 0x%08x\n", info->dwResourceId);
508         printf("\tDisplay Name\t= %s\n",info->pDisplayName);
509         printf("\tLang Id\t= 0x%04x\n", info->wLangId);
510
511         return;
512 }
513
514 void print_form_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
515 {
516         DWORD i;
517         PFORM_INFO_1 buffer1 = NULL;
518         PFORM_INFO_2 buffer2 = NULL;
519
520         if (!buffer) {
521                 return;
522         }
523
524         switch (level) {
525         case 1:
526                 buffer1 = (PFORM_INFO_1)buffer;
527                 break;
528         case 2:
529                 buffer2 = (PFORM_INFO_2)buffer;
530                 break;
531         default:
532                 break;
533         }
534
535         printf("Form Info Level %d:\n", level);
536
537         switch (level) {
538         case 1:
539                 for (i=0; i<count; i++) {
540                         print_form_info_1(&buffer1[i]);
541                         printf("\n");
542                 }
543                 break;
544         case 2:
545                 for (i=0; i<count; i++) {
546                         print_form_info_2(&buffer2[i]);
547                         printf("\n");
548                 }
549                 break;
550         default:
551                 break;
552         }
553 }
554
555 void print_printer_info_1(PPRINTER_INFO_1 info)
556 {
557         printf("\tPrinter Name\t= %s\n",        info->pName);
558         printf("\tDescription\t= %s\n",         info->pDescription);
559         printf("\tComment\t\t= %s\n",           info->pComment);
560         printf("\tFlags\t\t= 0x%x\n",           info->Flags);
561
562         return;
563 }
564
565 void print_printer_info_2(PPRINTER_INFO_2 info)
566 {
567         printf("\tServer Name\t\t= %s\n",       info->pServerName);
568         printf("\tPrinter Name\t\t= %s\n",      info->pPrinterName);
569         printf("\tPort Name\t\t= %s\n",         info->pPortName);
570         printf("\tShare Name\t\t= %s\n",        info->pShareName);
571         printf("\tDriver Name\t\t= %s\n",       info->pDriverName);
572         printf("\tComment\t\t\t= %s\n",         info->pComment);
573         printf("\tLocation\t\t= %s\n",          info->pLocation);
574         printf("\tSeparator File\t\t= %s\n",    info->pSepFile);
575         printf("\tDefault Data Type\t= %s\n",   info->pDatatype);
576         printf("\tPrint Processor\t\t= %s\n",   info->pPrintProcessor);
577         printf("\tParameters\t\t= %s\n",        info->pParameters);
578         printf("\tAttributes\t\t= 0x%x\n",      info->Attributes);
579         printf("\tPriority\t\t= 0x%x\n",        info->Priority);
580         printf("\tDefault Priority\t= 0x%x\n",  info->DefaultPriority);
581         printf("\tStart Time\t\t= 0x%x\n",      info->StartTime);
582         printf("\tUntil Time\t\t= 0x%x\n",      info->UntilTime);
583         printf("\tStatus\t\t\t= 0x%x\n",        info->Status);
584         printf("\tcJobs\t\t\t= 0x%x\n",         info->cJobs);
585         printf("\tAverage PPM\t\t= 0x%x\n",     info->AveragePPM);
586
587         printf("\tDevice Mode Information\n");
588         printf("\t-----------------------\n");
589         print_devmode(info->pDevMode);
590 #if 0
591         printf("\tSecurity Descriptor Information\n");
592         printf("\t-------------------------------\n");
593         print_secdesc(info->pSecurityDescriptor);
594 #endif
595         return;
596 }
597
598 void print_printer_info_5(PPRINTER_INFO_5 info)
599 {
600         printf("\tPrinter Name\t\t\t= %s\n",            info->pPrinterName);
601         printf("\tPort Name\t\t\t= %s\n",               info->pPortName);
602         printf("\tAttributes\t\t\t= 0x%x\n",            info->Attributes);
603         printf("\tDev NotSelect Timeout\t= 0x%x\n",     info->DeviceNotSelectedTimeout);
604         printf("\tTX RetryTimeout\t\t= 0x%x\n",         info->TransmissionRetryTimeout);
605         return;
606 }
607
608 void print_printer_info_6(PPRINTER_INFO_6 info)
609 {
610         printf("\tStatus\t\t\t= 0x%x\n",                info->dwStatus);
611         return;
612 }
613
614 void print_printer_info_7(PPRINTER_INFO_7 info)
615 {
616         printf("\tObject GUID\t\t\t= %s\n",             info->pszObjectGUID);
617         printf("\tAction\t\t\t= 0x%x\n",                info->dwAction);
618         return;
619 }
620
621 void print_printer_info_8(PPRINTER_INFO_8 info)
622 {
623         print_devmode(info->pDevMode);
624 }
625
626 void print_printer_info_9(PPRINTER_INFO_9 info)
627 {
628         print_devmode(info->pDevMode);
629 }
630
631 void print_printer_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
632 {
633         DWORD i;
634         PPRINTER_INFO_1 buffer1 = NULL;
635         PPRINTER_INFO_2 buffer2 = NULL;
636         PPRINTER_INFO_3 buffer3 = NULL;
637         PPRINTER_INFO_4 buffer4 = NULL;
638         PPRINTER_INFO_5 buffer5 = NULL;
639         PPRINTER_INFO_6 buffer6 = NULL;
640         PPRINTER_INFO_7 buffer7 = NULL;
641         PPRINTER_INFO_8 buffer8 = NULL;
642
643         if (!buffer) {
644                 return;
645         }
646
647         switch (level) {
648         case 1:
649                 buffer1 = (PPRINTER_INFO_1)buffer;
650                 break;
651         case 2:
652                 buffer2 = (PPRINTER_INFO_2)buffer;
653                 break;
654         case 3:
655                 buffer3 = (PPRINTER_INFO_3)buffer;
656                 break;
657         case 4:
658                 buffer4 = (PPRINTER_INFO_4)buffer;
659                 break;
660         case 5:
661                 buffer5 = (PPRINTER_INFO_5)buffer;
662                 break;
663         case 6:
664                 buffer6 = (PPRINTER_INFO_6)buffer;
665                 break;
666         case 7:
667                 buffer7 = (PPRINTER_INFO_7)buffer;
668                 break;
669         case 8:
670                 buffer8 = (PPRINTER_INFO_8)buffer;
671                 break;
672         default:
673                 break;
674         }
675
676         printf("Printer Info Level %d:\n", level);
677
678         switch (level) {
679         case 1:
680                 for (i=0; i<count; i++) {
681                         print_printer_info_1(&buffer1[i]);
682                         printf("\n");
683                 }
684                 break;
685         case 2:
686                 for (i=0; i<count; i++) {
687                         print_printer_info_2(&buffer2[i]);
688                         printf("\n");
689                 }
690                 break;
691 #if 0
692         case 3:
693                 for (i=0; i<count; i++) {
694                         print_printer_info_3(&buffer3[i]);
695                         printf("\n");
696                 }
697                 break;
698         case 4:
699                 for (i=0; i<count; i++) {
700                         print_printer_info_4(&buffer4[i]);
701                         printf("\n");
702                 }
703                 break;
704 #endif
705         case 5:
706                 for (i=0; i<count; i++) {
707                         print_printer_info_5(&buffer5[i]);
708                         printf("\n");
709                 }
710                 break;
711         case 6:
712                 for (i=0; i<count; i++) {
713                         print_printer_info_6(&buffer6[i]);
714                         printf("\n");
715                 }
716                 break;
717         case 7:
718                 for (i=0; i<count; i++) {
719                         print_printer_info_7(&buffer7[i]);
720                         printf("\n");
721                 }
722                 break;
723         case 8:
724                 for (i=0; i<count; i++) {
725                         print_printer_info_8(&buffer8[i]);
726                         printf("\n");
727                 }
728                 break;
729         default:
730                 break;
731         }
732 }
733
734 void print_printprocessor_info_1(PPRINTPROCESSOR_INFO_1 info)
735 {
736         printf("\tPrint Processor Name\t= %s\n", info->pName);
737
738         return;
739 }
740
741 void print_printprocessor_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
742 {
743         DWORD i;
744         PPRINTPROCESSOR_INFO_1 buffer1 = NULL;
745
746         if (!buffer) {
747                 return;
748         }
749
750         switch (level) {
751         case 1:
752                 buffer1 = (PPRINTPROCESSOR_INFO_1)buffer;
753                 break;
754         default:
755                 break;
756         }
757
758         printf("Print Processor Info Level %d:\n", level);
759
760         switch (level) {
761         case 1:
762                 for (i=0; i<count; i++) {
763                         print_printprocessor_info_1(&buffer1[i]);
764                         printf("\n");
765                 }
766                 break;
767         default:
768                 break;
769         }
770 }
771
772 void print_datatypes_info_1(PDATATYPES_INFO_1 info)
773 {
774         printf("\tDataTypes Name\t= %s\n", info->pName);
775
776         return;
777 }
778
779 void print_datatypes_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
780 {
781         DWORD i;
782         PDATATYPES_INFO_1 buffer1 = NULL;
783
784         if (!buffer) {
785                 return;
786         }
787
788         switch (level) {
789         case 1:
790                 buffer1 = (PDATATYPES_INFO_1)buffer;
791                 break;
792         default:
793                 break;
794         }
795
796         printf("DataTypes Info Level %d:\n", level);
797
798         switch (level) {
799         case 1:
800                 for (i=0; i<count; i++) {
801                         print_datatypes_info_1(&buffer1[i]);
802                         printf("\n");
803                 }
804                 break;
805         default:
806                 break;
807         }
808 }
809
810 void print_driver_info_1(PDRIVER_INFO_1 info)
811 {
812         printf("\tDriver Name\t= %s\n\n",       info->pName);
813
814         return;
815 }
816
817 void print_driver_info_2(PDRIVER_INFO_2 info)
818 {
819         printf("\tDriver Name\t= %s\n",         info->pName);
820         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
821         printf("\tVersion\t\t= %d\n",           info->cVersion);
822         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
823         printf("\tData File\t= %s\n",           info->pDataFile);
824         printf("\tConfig File\t= %s\n\n",       info->pConfigFile);
825
826         return;
827 }
828
829 void print_driver_info_3(PDRIVER_INFO_3 info)
830 {
831         char *ptr = NULL;
832
833         printf("\tDriver Name\t= %s\n",         info->pName);
834         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
835         printf("\tVersion\t\t= %d\n",           info->cVersion);
836         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
837         printf("\tData File\t= %s\n",           info->pDataFile);
838         printf("\tConfig File\t= %s\n",         info->pConfigFile);
839         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
840         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
841         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
842         ptr = (char*)info->pDependentFiles;
843         while ((ptr != NULL) && (*ptr != '\0')) {
844                 printf("\tDependent Files\t= %s\n", ptr);
845                 for (;*ptr != '\0'; ptr++)
846                         /* printf("%s\n", ptr); */
847                         ;
848                 ptr++;
849         }
850
851         return;
852 }
853
854 void print_driver_info_4(PDRIVER_INFO_4 info)
855 {
856         char *ptr = NULL;
857
858         printf("\tDriver Name\t= %s\n",         info->pName);
859         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
860         printf("\tVersion\t\t= %d\n",           info->cVersion);
861         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
862         printf("\tData File\t= %s\n",           info->pDataFile);
863         printf("\tConfig File\t= %s\n",         info->pConfigFile);
864         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
865         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
866         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
867         printf("\tPrevious Names\t= %s\n",      info->pszzPreviousNames);
868         ptr = (char*)info->pDependentFiles;
869         while ((ptr != NULL) && (*ptr != '\0')) {
870                 printf("\tDependent Files\t= %s\n", ptr);
871                 for (;*ptr != '\0'; ptr++)
872                         /* printf("%s\n", ptr); */
873                         ;
874                 ptr++;
875         }
876
877         return;
878 }
879
880 void print_driver_info_5(PDRIVER_INFO_5 info)
881 {
882         printf("\tDriver Name\t= %s\n",         info->pName);
883         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
884         printf("\tVersion\t\t= %d\n",           info->cVersion);
885         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
886         printf("\tData File\t= %s\n",           info->pDataFile);
887         printf("\tConfig File\t= %s\n",         info->pConfigFile);
888         printf("\tDriver Attributes\t= %d\n",   info->dwDriverAttributes);
889         printf("\tConfig Version\t= %d\n",      info->dwConfigVersion);
890         printf("\tDriver Version\t= %d\n",      info->dwDriverVersion);
891
892         return;
893 }
894
895 void print_driver_info_6(PDRIVER_INFO_6 info)
896 {
897         char *ptr = NULL;
898
899         printf("\tDriver Name\t= %s\n",         info->pName);
900         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
901         printf("\tVersion\t\t= %d\n",           info->cVersion);
902         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
903         printf("\tData File\t= %s\n",           info->pDataFile);
904         printf("\tConfig File\t= %s\n",         info->pConfigFile);
905         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
906         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
907         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
908         printf("\tPrevious Names\t= %s\n",      info->pszzPreviousNames);
909         ptr = (char*)info->pDependentFiles;
910         if (ptr != NULL) {
911                 while (*ptr != '\0') {
912                         printf("\tDependent Files\t= %s\n", ptr);
913                         for (;*ptr != '\0'; ptr++)
914                                 /* printf("%s\n", ptr); */
915                                 ;
916                         ptr++;
917                 }
918         } else {
919                 printf("\tPrevious Names\t= (null)\n");
920         }
921
922         ptr = (char*)info->pszzPreviousNames;
923         if (ptr != NULL) {
924                 while (*ptr != '\0') {
925                         printf("\tPrevious Names\t= %s\n", ptr);
926                         for (;*ptr != '\0'; ptr++)
927                                 /* printf("%s\n", ptr); */
928                                 ;
929                         ptr++;
930                 }
931         } else {
932                 printf("\tPrevious Names\t= (null)\n");
933         }
934
935         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
936         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
937         printf("\tManufacture Name = %s\n",     info->pszMfgName);
938         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
939         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
940         printf("\tProvider\t= %s\n",            info->pszProvider);
941         return;
942 }
943
944 static void print_multi_sz(LPSTR multisz)
945 {
946         char *ptr = NULL;
947
948         ptr = (char *)multisz;
949
950         if (!ptr) {
951                 printf("(null)\n");
952                 return;
953         }
954
955         while (*ptr != '\0') {
956                 printf("%s\n", ptr);
957                 for (; *ptr != '\0'; ptr++) {
958                         /* printf("%s\n", ptr); */
959                         ;
960                 }
961                 ptr++;
962         }
963 }
964
965 void print_driver_info_8(PDRIVER_INFO_8 info)
966 {
967         printf("\tDriver Name\t= %s\n",         info->pName);
968         printf("\tEnvironment\t= %s\n",         info->pEnvironment);
969         printf("\tVersion\t\t= %d\n",           info->cVersion);
970         printf("\tDriver Path\t= %s\n",         info->pDriverPath);
971         printf("\tData File\t= %s\n",           info->pDataFile);
972         printf("\tConfig File\t= %s\n",         info->pConfigFile);
973         printf("\tHelp Path\t= %s\n",           info->pHelpFile);
974         printf("\tMonitor Name\t= %s\n",        info->pMonitorName);
975         printf("\tData Type\t= %s\n",           info->pDefaultDataType);
976         printf("\tPrevious Names\t=\n");
977         print_multi_sz(info->pszzPreviousNames);
978         printf("\tDependent Files\t=\n");
979         print_multi_sz(info->pDependentFiles);
980         printf("\tDriver Date\t= %d\n",         info->ftDriverDate);
981         printf("\tDriver Version\t= %d\n",      info->dwlDriverVersion);
982         printf("\tManufacture Name = %s\n",     info->pszMfgName);
983         printf("\tOEM URL\t\t= %s\n",           info->pszOEMUrl);
984         printf("\tHardware ID\t= %s\n",         info->pszHardwareID);
985         printf("\tProvider\t= %s\n",            info->pszProvider);
986         printf("\tPrint Processor\t= %s\n",     info->pszPrintProcessor);
987         printf("\tVendor Setup\t= %s\n",        info->pszVendorSetup);
988         printf("\tColor Profiles\t=\n");
989         print_multi_sz(info->pszzColorProfiles);
990         printf("\tInf Path\t= %s\n",            info->pszInfPath);
991         printf("\tPrinter Driver Attributes = %d\n", info->dwPrinterDriverAttributes);
992         printf("\tCore Driver Dependencies\t=\n");
993         print_multi_sz(info->pszzCoreDriverDependencies);
994         printf("\tMin Inbox Driver VerDate\t= %d\n", info->ftMinInboxDriverVerDate);
995         printf("\tMin Inbox Driver VerVersion\t= %d\n", info->dwlMinInboxDriverVerVersion);
996         return;
997 }
998
999 void print_driver_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
1000 {
1001         DWORD i;
1002         PDRIVER_INFO_1  buffer1 = NULL;
1003         PDRIVER_INFO_2  buffer2 = NULL;
1004         PDRIVER_INFO_3  buffer3 = NULL;
1005         PDRIVER_INFO_4  buffer4 = NULL;
1006         PDRIVER_INFO_5  buffer5 = NULL;
1007         PDRIVER_INFO_6  buffer6 = NULL;
1008         PDRIVER_INFO_8  buffer8 = NULL;
1009
1010         if (!buffer) {
1011                 return;
1012         }
1013
1014         switch (level) {
1015         case 1:
1016                 buffer1 = (PDRIVER_INFO_1)buffer;
1017                 break;
1018         case 2:
1019                 buffer2 = (PDRIVER_INFO_2)buffer;
1020                 break;
1021         case 3:
1022                 buffer3 = (PDRIVER_INFO_3)buffer;
1023                 break;
1024         case 4:
1025                 buffer4 = (PDRIVER_INFO_4)buffer;
1026                 break;
1027         case 5:
1028                 buffer5 = (PDRIVER_INFO_5)buffer;
1029                 break;
1030         case 6:
1031                 buffer6 = (PDRIVER_INFO_6)buffer;
1032                 break;
1033         case 8:
1034                 buffer8 = (PDRIVER_INFO_8)buffer;
1035                 break;
1036         default:
1037                 break;
1038         }
1039
1040         printf("Driver Info Level %d:\n", level);
1041
1042         switch (level) {
1043         case 1:
1044                 for (i=0; i<count; i++) {
1045                         print_driver_info_1(&buffer1[i]);
1046                         printf("\n");
1047                 }
1048                 break;
1049         case 2:
1050                 for (i=0; i<count; i++) {
1051                         print_driver_info_2(&buffer2[i]);
1052                         printf("\n");
1053                 }
1054                 break;
1055         case 3:
1056                 for (i=0; i<count; i++) {
1057                         print_driver_info_3(&buffer3[i]);
1058                         printf("\n");
1059                 }
1060                 break;
1061         case 4:
1062                 for (i=0; i<count; i++) {
1063                         print_driver_info_4(&buffer4[i]);
1064                         printf("\n");
1065                 }
1066                 break;
1067         case 5:
1068                 for (i=0; i<count; i++) {
1069                         print_driver_info_5(&buffer5[i]);
1070                         printf("\n");
1071                 }
1072                 break;
1073         case 6:
1074                 for (i=0; i<count; i++) {
1075                         print_driver_info_6(&buffer6[i]);
1076                         printf("\n");
1077                 }
1078                 break;
1079         case 8:
1080                 for (i=0; i<count; i++) {
1081                         print_driver_info_8(&buffer8[i]);
1082                         printf("\n");
1083                 }
1084                 break;
1085         default:
1086                 break;
1087         }
1088 }
1089
1090 void print_doc_info_1(PDOC_INFO_1 info)
1091 {
1092         printf("\tDocument Name\t= %s\n",       info->pDocName);
1093         printf("\tOutput Filename\t= %s\n",     info->pOutputFile);
1094         printf("\tDatatype\t= %s\n",            info->pDatatype);
1095         return;
1096 }
1097
1098 void print_printer_keys(LPSTR buffer)
1099 {
1100         LPSTR p = NULL;
1101
1102         p = buffer;
1103
1104         while (p && *p) {
1105                 printf("%s\n", p);
1106                 for (; *p; p = CharNext(p)) {
1107                         p = CharNext(p);
1108                 }
1109         }
1110 }
1111
1112 static LPSTR reg_type_str(DWORD type)
1113 {
1114         switch (type) {
1115         case REG_DWORD:
1116                 return "REG_DWORD";
1117         case REG_SZ:
1118                 return "REG_SZ";
1119         case REG_MULTI_SZ:
1120                 return "REG_MULTI_SZ";
1121         case REG_BINARY:
1122                 return "REG_BINARY";
1123         default:
1124                 return NULL;
1125         }
1126 }
1127
1128 void print_printer_data(LPSTR keyname, LPSTR valuename, DWORD size, LPBYTE buffer, DWORD type)
1129 {
1130         DWORD i = 0;
1131         LPSTR p = NULL;
1132
1133         if (keyname) {
1134                 printf("\tKey Name:\t%s\n", keyname);
1135         }
1136
1137         printf("\tValue Name:\t%s\n", valuename);
1138         printf("\tSize: 0x%x (%d)\n", size, size);
1139         printf("\tType:\t\t%s\n", reg_type_str(type));
1140
1141         switch (type) {
1142         case REG_SZ:
1143                 printf("\t\t%s\n", (LPSTR)buffer);
1144                 break;
1145         case REG_MULTI_SZ:
1146                 p = (LPSTR)buffer;
1147                 while (p && *p) {
1148                         printf("%s\n", p);
1149                         for (; *p; p = CharNext(p)) {
1150                                 p = CharNext(p);
1151                         }
1152                 }
1153                 break;
1154         case REG_DWORD:
1155                 assert(size == 4);
1156                 printf("\t\t0x%08x\n", (DWORD)*buffer);
1157                 break;
1158         case REG_BINARY:
1159                 for (i=0; i < size; i++) {
1160                         printf("\t0x%x", buffer[i]);
1161                         if (i%4 == 3) {
1162                                 printf("\n");
1163                         }
1164                 }
1165                 break;
1166         default:
1167                 break;
1168         }
1169 }
1170
1171 void print_printer_enum_values(PRINTER_ENUM_VALUES *info)
1172 {
1173         print_printer_data(NULL, info->pValueName, info->cbData, info->pData, info->dwType);
1174 }
1175