param: Rename variable used for lp_addprinter_cmd szAddPrinterCommand
[Samba.git] / testprogs / win32 / spoolss / printlib.c
blob1dd1277c3138384c4cb66ba03d3a04e247a44c08
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for spoolss rpc operations
5 Copyright (C) Gerald (Jerry) Carter 2007
6 Copyright (C) Guenther Deschner 2009-2010
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.
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.
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/>.
22 #include <windows.h>
23 #include <stdio.h>
24 #include <assert.h>
25 #include <sddl.h>
27 #ifndef MIN
28 #define MIN(a,b) ((a)<(b)?(a):(b))
29 #endif
31 void print_devmode(DEVMODE *pDevModeIn)
33 if (pDevModeIn == NULL) {
34 printf("\tDevice Mode\t= (null)\n");
35 return;
38 printf("\tDEVMODE:----------\n");
39 printf("\tDeviceName: [%s]\n", pDevModeIn->dmDeviceName);
40 printf("\tSpecVersion: %d\n", pDevModeIn->dmSpecVersion);
41 printf("\tDriverVersion: %d\n", pDevModeIn->dmDriverVersion);
42 printf("\tSize: %d\n", pDevModeIn->dmSize);
43 printf("\tDriverExtra: %d\n", pDevModeIn->dmDriverExtra);
44 printf("\tFields: 0x%x\n", pDevModeIn->dmFields);
46 if (pDevModeIn->dmFields & DM_ORIENTATION)
47 printf("\tOrientation: %d\n", pDevModeIn->dmOrientation);
48 if (pDevModeIn->dmFields & DM_PAPERSIZE)
49 printf("\tPaperSize: %d\n", pDevModeIn->dmPaperSize);
50 if (pDevModeIn->dmFields & DM_PAPERLENGTH)
51 printf("\tPaperLength: %d\n", pDevModeIn->dmPaperLength);
52 if (pDevModeIn->dmFields & DM_PAPERWIDTH)
53 printf("\tPaperWidth: %d\n", pDevModeIn->dmPaperWidth);
54 // if (pDevModeIn->dmFields & DM_POSITION)
55 // printf("\tPosition: %d\n", pDevModeIn->dmPosition);
56 if (pDevModeIn->dmFields & DM_SCALE)
57 printf("\tScale: %d\n", pDevModeIn->dmScale);
58 if (pDevModeIn->dmFields & DM_COPIES)
59 printf("\tCopies: %d\n", pDevModeIn->dmCopies );
60 if (pDevModeIn->dmFields & DM_DEFAULTSOURCE)
61 printf("\tDefaultSource: %d\n", pDevModeIn->dmDefaultSource);
62 if (pDevModeIn->dmFields & DM_PRINTQUALITY)
63 printf("\tPrintQuality: %d\n", pDevModeIn->dmPrintQuality);
64 if (pDevModeIn->dmFields & DM_COLOR)
65 printf("\tColor: %d\n", pDevModeIn->dmColor);
66 if (pDevModeIn->dmFields & DM_DUPLEX)
67 printf("\tDuplex: %d\n", pDevModeIn->dmDuplex);
68 if (pDevModeIn->dmFields & DM_YRESOLUTION)
69 printf("\tYResolution: %d\n", pDevModeIn->dmYResolution);
70 if (pDevModeIn->dmFields & DM_TTOPTION)
71 printf("\tTTOption: %d\n", pDevModeIn->dmTTOption);
72 if (pDevModeIn->dmFields & DM_COLLATE)
73 printf("\tCollate: %d\n", pDevModeIn->dmCollate);
74 if (pDevModeIn->dmFields & DM_FORMNAME)
75 printf("\tForm: [%s]\n", pDevModeIn->dmFormName);
76 if (pDevModeIn->dmFields & DM_LOGPIXELS)
77 printf("\tLogPixels: %d\n", pDevModeIn->dmLogPixels);
78 if (pDevModeIn->dmFields & DM_BITSPERPEL)
79 printf("\tBitsPerPel: %d\n", pDevModeIn->dmBitsPerPel);
80 if (pDevModeIn->dmFields & DM_PELSWIDTH)
81 printf("\tPelsWidth: %d\n", pDevModeIn->dmPelsWidth);
82 if (pDevModeIn->dmFields & DM_PELSHEIGHT)
83 printf("\tPelsHeight: %d\n", pDevModeIn->dmPelsHeight);
84 if (pDevModeIn->dmFields & DM_DISPLAYFLAGS)
85 printf("\tDisplayFlags: %d\n", pDevModeIn->dmDisplayFlags);
86 // if (pDevModeIn->dmFields & DM_NUP)
87 // printf("\tNup: %d\n", pDevModeIn->dmNup);
88 if (pDevModeIn->dmFields & DM_DISPLAYFREQUENCY)
89 printf("\tDisplayFrequency:%d\n", pDevModeIn->dmDisplayFrequency);
90 if (pDevModeIn->dmFields & DM_ICMMETHOD)
91 printf("\tICMMethod: %d\n", pDevModeIn->dmICMMethod);
92 if (pDevModeIn->dmFields & DM_ICMINTENT)
93 printf("\tICMIntent: %d\n", pDevModeIn->dmICMIntent);
94 if (pDevModeIn->dmFields & DM_MEDIATYPE)
95 printf("\tMediaType: %d\n", pDevModeIn->dmMediaType);
96 if (pDevModeIn->dmFields & DM_DITHERTYPE)
97 printf("\tDitherType: %d\n", pDevModeIn->dmDitherType);
98 // if (pDevModeIn->dmFields & DM_PANNINGWIDTH)
99 // printf("\tPanningWidth: %d\n", pDevModeIn->dmPanningWidth);
100 // if (pDevModeIn->dmFields & DM_PANNINGHEIGHT)
101 // printf("\tPanningHeight: %d\n", pDevModeIn->dmPanningHeight);
103 #if 0
104 if (bForceIn) {
105 printf("DEVMODE\n");
106 Dump((BYTE*)pDevModeIn, sizeof(DEVMODE), LEADER);
108 if (pDevModeIn->dmDriverExtra) {
109 printf("DriverExtra\n");
110 Dump((BYTE*)pDevModeIn + sizeof(DEVMODE), pDevModeIn->dmDriverExtra, LEADER);
113 #endif
115 return;
118 void print_acl(const char* str, ACL *acl)
120 printf("%s\n", str);
121 if (acl == NULL)
122 return;
124 printf("\t\tACL Revision \t\t 0x%x\n", acl->AclRevision);
125 printf("\t\tSbz1\t\t 0x%x\n", acl->Sbz1);
126 printf("\t\tSbz2\t\t 0x%x\n", acl->Sbz2);
127 printf("\t\tACL Size\t\t 0x%x\n", acl->AclSize);
128 printf("\t\tACL Count\t\t 0x%x\n", acl->AceCount);
130 return;
133 void PrintLastError();
135 void print_sid(LPSTR str, PSID sid)
137 LPSTR sid_string;
139 printf("%s\n", str);
141 if (sid == NULL) {
142 printf("(null sid)\n");
143 return;
146 if (!ConvertSidToStringSid(sid, &sid_string)) {
147 PrintLastError();
148 return;
151 printf("%s\n", sid_string);
152 LocalFree(sid_string);
154 return;
157 void print_secdesc(SECURITY_DESCRIPTOR *secdesc)
159 LPSTR sd_string;
161 if (secdesc == NULL) {
162 printf("\tSecurity Descriptor\t= (null)\n");
163 return;
166 if (!ConvertSecurityDescriptorToStringSecurityDescriptor(secdesc, 1, 7, &sd_string, NULL)) {
167 PrintLastError();
168 return;
171 printf("%s\n", sd_string);
172 LocalFree(sd_string);
174 #if 0
175 printf("\tRevision\t= 0x%x\n", secdesc->Revision);
176 printf("\tSbz1\t\t= 0x%x\n", secdesc->Sbz1);
177 printf("\tControl\t\t= 0x%x\n", secdesc->Control);
178 print_sid("\tOwner\t\t= ", secdesc->Owner);
179 print_sid("\tGroup\t\t= ",secdesc->Group);
180 print_acl("\tSacl\t\t= ", secdesc->Sacl);
181 print_acl("\tDacl\t\t= ", secdesc->Dacl);
182 #endif
183 return;
186 void PrintLastError()
188 LPVOID lpMsgBuf;
189 DWORD status;
191 status = GetLastError();
193 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
194 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
195 (LPTSTR)&lpMsgBuf, 0, NULL);
196 printf("ERROR [0x%x] : %s\n", status, (char*)lpMsgBuf);
197 LocalFree(lpMsgBuf);
199 return;
203 void print_job_info_1(PJOB_INFO_1 info)
205 printf("\tJob ID\t\t= %d\n", info->JobId);
206 printf("\tPrinter Name\t= %s\n", info->pPrinterName);
207 printf("\tMachine Name\t= %s\n", info->pMachineName);
208 printf("\tUser Name\t= %s\n", info->pUserName);
209 printf("\tDocument\t= %s\n", info->pDocument);
210 printf("\tDatatype\t= %s\n", info->pDatatype);
211 printf("\tStatus\t\t= %s\n", info->pStatus);
212 printf("\tStatus\t= %d\n", info->Status);
213 printf("\tPriority\t= %d\n", info->Priority);
214 printf("\tPosition\t= %d\n", info->Position);
215 printf("\tTotal Pages\t= %d\n", info->TotalPages);
216 printf("\tPages Printed\t= %d\n", info->PagesPrinted);
217 printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
218 info->Submitted.wDay, info->Submitted.wMonth,
219 info->Submitted.wYear, info->Submitted.wHour,
220 info->Submitted.wMinute, info->Submitted.wSecond);
222 return;
225 void print_job_info_2(PJOB_INFO_2 info)
227 printf("\tJob ID\t\t= %d\n", info->JobId);
228 printf("\tPrinter Name\t= %s\n", info->pPrinterName);
229 printf("\tMachine Name\t= %s\n", info->pMachineName);
230 printf("\tUser Name\t= %s\n", info->pUserName);
231 printf("\tDocument\t= %s\n", info->pDocument);
232 printf("\tDatatype\t= %s\n", info->pDatatype);
233 printf("\tNotify Name\t= %s\n", info->pNotifyName);
234 printf("\tPrint Processor\t= %s\n", info->pPrintProcessor);
235 printf("\tParameters\t= %s\n", info->pParameters);
236 printf("\tDriver Name\t= %s\n", info->pDriverName);
237 printf("\tStatus\t\t= %s\n", info->pStatus);
238 printf("\tStatus\t\t= %d\n", info->Status);
239 printf("\tPriority\t= %d\n", info->Priority);
240 printf("\tPosition\t= %d\n", info->Position);
241 printf("\tTotal Pages\t= %d\n", info->TotalPages);
242 printf("\tPages Printed\t= %d\n", info->PagesPrinted);
243 printf("\tStart Time\t= %d\n", info->StartTime);
244 printf("\tUntil Time\t= %d\n", info->UntilTime);
245 printf("\tTime\t\t= %d\n", info->Time);
246 printf("\tSize\t\t= %d\n", info->Size);
247 printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
248 info->Submitted.wDay, info->Submitted.wMonth,
249 info->Submitted.wYear, info->Submitted.wHour,
250 info->Submitted.wMinute, info->Submitted.wSecond);
251 printf("\tDevice Mode Information\n");
252 printf("\t-----------------------\n");
253 print_devmode(info->pDevMode);
254 printf("\tSecurity Descriptor Information\n");
255 printf("\t-------------------------------\n");
256 print_secdesc(info->pSecurityDescriptor);
258 return;
261 void print_job_info_3(PJOB_INFO_3 info)
263 printf("\tJob ID\t\t= %d\n", info->JobId);
264 printf("\tJob ID Next Job\t= %d\n", info->NextJobId);
265 printf("\tReserved (must be 0)\t= %d\n",info->Reserved);
267 return;
270 void print_job_info_4(PJOB_INFO_4 info)
272 printf("\tJob ID\t\t= %d\n", info->JobId);
273 printf("\tPrinter Name\t= %s\n", info->pPrinterName);
274 printf("\tMachine Name\t= %s\n", info->pMachineName);
275 printf("\tUser Name\t= %s\n", info->pUserName);
276 printf("\tDocument\t= %s\n", info->pDocument);
277 printf("\tDatatype\t= %s\n", info->pDatatype);
278 printf("\tNotify Name\t= %s\n", info->pNotifyName);
279 printf("\tPrint Processor\t= %s\n", info->pPrintProcessor);
280 printf("\tDriver Name\t= %s\n", info->pDriverName);
281 printf("\tStatus\t\t= %s\n", info->pStatus);
282 printf("\tStatus\t\t= %d\n", info->Status);
283 printf("\tPriority\t= %d\n", info->Priority);
284 printf("\tPosition\t= %d\n", info->Position);
285 printf("\tTotal Pages\t= %d\n", info->TotalPages);
286 printf("\tPages Printed\t= %d\n", info->PagesPrinted);
287 printf("\tStart Time\t= %d\n", info->StartTime);
288 printf("\tUntil Time\t= %d\n", info->UntilTime);
289 printf("\tTime\t\t= %d\n", info->Time);
290 printf("\tSize\t\t= %d\n", info->Size);
291 printf("\tSize High\t\t= 0x%016x\n", info->SizeHigh);
292 printf("\tSubmitted (DD:MM:YY HH:MM:SS)\t= %d:%d:%d %d:%d:%d UTC\n",
293 info->Submitted.wDay, info->Submitted.wMonth,
294 info->Submitted.wYear, info->Submitted.wHour,
295 info->Submitted.wMinute, info->Submitted.wSecond);
296 printf("\tDevice Mode Information\n");
297 printf("\t-----------------------\n");
298 print_devmode(info->pDevMode);
299 printf("\tSecurity Descriptor Information\n");
300 printf("\t-------------------------------\n");
301 print_secdesc(info->pSecurityDescriptor);
303 return;
306 void print_job_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
308 DWORD i;
309 PJOB_INFO_1 buffer1 = NULL;
310 PJOB_INFO_2 buffer2 = NULL;
311 PJOB_INFO_3 buffer3 = NULL;
312 PJOB_INFO_4 buffer4 = NULL;
314 if (!buffer) {
315 return;
318 switch (level) {
319 case 1:
320 buffer1 = (PJOB_INFO_1)buffer;
321 break;
322 case 2:
323 buffer2 = (PJOB_INFO_2)buffer;
324 break;
325 case 3:
326 buffer3 = (PJOB_INFO_3)buffer;
327 break;
328 case 4:
329 buffer4 = (PJOB_INFO_4)buffer;
330 break;
331 default:
332 break;
335 printf("Job Info Level %d:\n", level);
337 switch (level) {
338 case 1:
339 for (i=0; i<count; i++) {
340 print_job_info_1(&buffer1[i]);
341 printf("\n");
343 break;
344 case 2:
345 for (i=0; i<count; i++) {
346 print_job_info_2(&buffer2[i]);
347 printf("\n");
349 break;
350 case 3:
351 for (i=0; i<count; i++) {
352 print_job_info_3(&buffer3[i]);
353 printf("\n");
355 break;
356 case 4:
357 for (i=0; i<count; i++) {
358 print_job_info_4(&buffer4[i]);
359 printf("\n");
361 break;
362 default:
363 break;
367 void print_monitor_info_1(PMONITOR_INFO_1 info)
369 printf("\tMonitor Name\t= %s\n", info->pName);
371 return;
374 void print_monitor_info_2(PMONITOR_INFO_2 info)
376 printf("\tMonitor Name\t= %s\n", info->pName);
377 printf("\tEnvironment\t= %s\n", info->pEnvironment);
378 printf("\tDLL Name\t= %s\n", info->pDLLName);
380 return;
383 void print_monitor_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
385 DWORD i;
386 PMONITOR_INFO_1 buffer1 = NULL;
387 PMONITOR_INFO_2 buffer2 = NULL;
389 if (!buffer) {
390 return;
393 switch (level) {
394 case 1:
395 buffer1 = (PMONITOR_INFO_1)buffer;
396 break;
397 case 2:
398 buffer2 = (PMONITOR_INFO_2)buffer;
399 break;
400 default:
401 break;
404 printf("Monitor Info Level %d:\n", level);
406 switch (level) {
407 case 1:
408 for (i=0; i<count; i++) {
409 print_monitor_info_1(&buffer1[i]);
410 printf("\n");
412 break;
413 case 2:
414 for (i=0; i<count; i++) {
415 print_monitor_info_2(&buffer2[i]);
416 printf("\n");
418 break;
419 default:
420 break;
424 void print_port_info_1(PPORT_INFO_1 info)
426 printf("\tPort Name\t= %s\n", info->pName);
427 return;
430 void print_port_info_2(PPORT_INFO_2 info)
432 printf("\tPort Name\t= %s\n", info->pPortName);
433 printf("\tMonitor Name\t= %s\n",info->pMonitorName);
434 printf("\tDescription\t= %s\n", info->pDescription);
435 printf("\tPort Type\t= 0x%08x\n", info->fPortType);
436 printf("\tReserved\t= 0x%08x\n", info->Reserved);
437 return;
440 void print_port_info_3(PPORT_INFO_3 info)
442 printf("\tStatus\t= 0x%08x\n", info->dwStatus);
443 printf("\tStatus String\t= %s\n", info->pszStatus);
444 printf("\tSeverity\t= 0x%08x\n", info->dwSeverity);
445 return;
448 void print_port_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
450 DWORD i;
451 PPORT_INFO_1 buffer1 = NULL;
452 PPORT_INFO_2 buffer2 = NULL;
453 PPORT_INFO_3 buffer3 = NULL;
455 if (!buffer) {
456 return;
459 switch (level) {
460 case 1:
461 buffer1 = (PPORT_INFO_1)buffer;
462 break;
463 case 2:
464 buffer2 = (PPORT_INFO_2)buffer;
465 break;
466 case 3:
467 buffer3 = (PPORT_INFO_3)buffer;
468 break;
469 default:
470 break;
473 printf("Port Info Level %d:\n", level);
475 switch (level) {
476 case 1:
477 for (i=0; i<count; i++) {
478 print_port_info_1(&buffer1[i]);
479 printf("\n");
481 break;
482 case 2:
483 for (i=0; i<count; i++) {
484 print_port_info_2(&buffer2[i]);
485 printf("\n");
487 break;
488 case 3:
489 for (i=0; i<count; i++) {
490 print_port_info_3(&buffer3[i]);
491 printf("\n");
493 break;
494 default:
495 break;
499 void print_form_info_1(PFORM_INFO_1 info)
501 printf("\tForm Name\t= %s\n", info->pName);
502 printf("\tFlags\t\t= 0x%x\n", info->Flags);
503 printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
504 printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
505 info->ImageableArea.left, info->ImageableArea.right,
506 info->ImageableArea.top, info->ImageableArea.bottom);
508 return;
511 void print_form_info_2(PFORM_INFO_2 info)
513 printf("\tForm Name\t= %s\n", info->pName);
514 printf("\tFlags\t\t= 0x%x\n", info->Flags);
515 printf("\tSize\t\t= %d x %d\n", info->Size.cx, info->Size.cy);
516 printf("\tRectangle\t= [left]%d [right]%d [top]%d [bottom]%d\n",
517 info->ImageableArea.left, info->ImageableArea.right,
518 info->ImageableArea.top, info->ImageableArea.bottom);
519 printf("\tKeyword\t= %s\n", info->pKeyword);
520 printf("\tString Type\t= 0x%08x\n", info->StringType);
521 printf("\tMui DLL\t= %s\n", info->pMuiDll);
522 printf("\tResource Id\t= 0x%08x\n", info->dwResourceId);
523 printf("\tDisplay Name\t= %s\n",info->pDisplayName);
524 printf("\tLang Id\t= 0x%04x\n", info->wLangId);
526 return;
529 void print_form_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
531 DWORD i;
532 PFORM_INFO_1 buffer1 = NULL;
533 PFORM_INFO_2 buffer2 = NULL;
535 if (!buffer) {
536 return;
539 switch (level) {
540 case 1:
541 buffer1 = (PFORM_INFO_1)buffer;
542 break;
543 case 2:
544 buffer2 = (PFORM_INFO_2)buffer;
545 break;
546 default:
547 break;
550 printf("Form Info Level %d:\n", level);
552 switch (level) {
553 case 1:
554 for (i=0; i<count; i++) {
555 print_form_info_1(&buffer1[i]);
556 printf("\n");
558 break;
559 case 2:
560 for (i=0; i<count; i++) {
561 print_form_info_2(&buffer2[i]);
562 printf("\n");
564 break;
565 default:
566 break;
570 void print_printer_info_1(PPRINTER_INFO_1 info)
572 printf("\tPrinter Name\t= %s\n", info->pName);
573 printf("\tDescription\t= %s\n", info->pDescription);
574 printf("\tComment\t\t= %s\n", info->pComment);
575 printf("\tFlags\t\t= 0x%x\n", info->Flags);
577 return;
580 void print_printer_info_2(PPRINTER_INFO_2 info)
582 printf("\tServer Name\t\t= %s\n", info->pServerName);
583 printf("\tPrinter Name\t\t= %s\n", info->pPrinterName);
584 printf("\tPort Name\t\t= %s\n", info->pPortName);
585 printf("\tShare Name\t\t= %s\n", info->pShareName);
586 printf("\tDriver Name\t\t= %s\n", info->pDriverName);
587 printf("\tComment\t\t\t= %s\n", info->pComment);
588 printf("\tLocation\t\t= %s\n", info->pLocation);
589 printf("\tSeparator File\t\t= %s\n", info->pSepFile);
590 printf("\tDefault Data Type\t= %s\n", info->pDatatype);
591 printf("\tPrint Processor\t\t= %s\n", info->pPrintProcessor);
592 printf("\tParameters\t\t= %s\n", info->pParameters);
593 printf("\tAttributes\t\t= 0x%x\n", info->Attributes);
594 printf("\tPriority\t\t= 0x%x\n", info->Priority);
595 printf("\tDefault Priority\t= 0x%x\n", info->DefaultPriority);
596 printf("\tStart Time\t\t= 0x%x\n", info->StartTime);
597 printf("\tUntil Time\t\t= 0x%x\n", info->UntilTime);
598 printf("\tStatus\t\t\t= 0x%x\n", info->Status);
599 printf("\tcJobs\t\t\t= 0x%x\n", info->cJobs);
600 printf("\tAverage PPM\t\t= 0x%x\n", info->AveragePPM);
602 printf("\tDevice Mode Information\n");
603 printf("\t-----------------------\n");
604 print_devmode(info->pDevMode);
605 printf("\tSecurity Descriptor Information\n");
606 printf("\t-------------------------------\n");
607 print_secdesc(info->pSecurityDescriptor);
608 return;
611 void print_printer_info_3(PPRINTER_INFO_3 info)
613 printf("\tSecurity Descriptor Information\n");
614 printf("\t-------------------------------\n");
615 print_secdesc(info->pSecurityDescriptor);
616 return;
619 void print_printer_info_4(PPRINTER_INFO_4 info)
621 printf("\tServer Name\t\t= %s\n", info->pServerName);
622 printf("\tPrinter Name\t\t= %s\n", info->pPrinterName);
623 printf("\tAttributes\t\t= 0x%x\n", info->Attributes);
624 return;
627 void print_printer_info_5(PPRINTER_INFO_5 info)
629 printf("\tPrinter Name\t\t\t= %s\n", info->pPrinterName);
630 printf("\tPort Name\t\t\t= %s\n", info->pPortName);
631 printf("\tAttributes\t\t\t= 0x%x\n", info->Attributes);
632 printf("\tDev NotSelect Timeout\t= 0x%x\n", info->DeviceNotSelectedTimeout);
633 printf("\tTX RetryTimeout\t\t= 0x%x\n", info->TransmissionRetryTimeout);
634 return;
637 void print_printer_info_6(PPRINTER_INFO_6 info)
639 printf("\tStatus\t\t\t= 0x%x\n", info->dwStatus);
640 return;
643 void print_printer_info_7(PPRINTER_INFO_7 info)
645 printf("\tObject GUID\t\t\t= %s\n", info->pszObjectGUID);
646 printf("\tAction\t\t\t= 0x%x\n", info->dwAction);
647 return;
650 void print_printer_info_8(PPRINTER_INFO_8 info)
652 print_devmode(info->pDevMode);
655 void print_printer_info_9(PPRINTER_INFO_9 info)
657 print_devmode(info->pDevMode);
660 void print_printer_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
662 DWORD i;
663 PPRINTER_INFO_1 buffer1 = NULL;
664 PPRINTER_INFO_2 buffer2 = NULL;
665 PPRINTER_INFO_3 buffer3 = NULL;
666 PPRINTER_INFO_4 buffer4 = NULL;
667 PPRINTER_INFO_5 buffer5 = NULL;
668 PPRINTER_INFO_6 buffer6 = NULL;
669 PPRINTER_INFO_7 buffer7 = NULL;
670 PPRINTER_INFO_8 buffer8 = NULL;
671 PPRINTER_INFO_9 buffer9 = NULL;
673 if (!buffer) {
674 return;
677 switch (level) {
678 case 1:
679 buffer1 = (PPRINTER_INFO_1)buffer;
680 break;
681 case 2:
682 buffer2 = (PPRINTER_INFO_2)buffer;
683 break;
684 case 3:
685 buffer3 = (PPRINTER_INFO_3)buffer;
686 break;
687 case 4:
688 buffer4 = (PPRINTER_INFO_4)buffer;
689 break;
690 case 5:
691 buffer5 = (PPRINTER_INFO_5)buffer;
692 break;
693 case 6:
694 buffer6 = (PPRINTER_INFO_6)buffer;
695 break;
696 case 7:
697 buffer7 = (PPRINTER_INFO_7)buffer;
698 break;
699 case 8:
700 buffer8 = (PPRINTER_INFO_8)buffer;
701 break;
702 case 9:
703 buffer9 = (PPRINTER_INFO_9)buffer;
704 break;
705 default:
706 break;
709 printf("Printer Info Level %d:\n", level);
711 switch (level) {
712 case 1:
713 for (i=0; i<count; i++) {
714 print_printer_info_1(&buffer1[i]);
715 printf("\n");
717 break;
718 case 2:
719 for (i=0; i<count; i++) {
720 print_printer_info_2(&buffer2[i]);
721 printf("\n");
723 break;
724 case 3:
725 for (i=0; i<count; i++) {
726 print_printer_info_3(&buffer3[i]);
727 printf("\n");
729 break;
730 case 4:
731 for (i=0; i<count; i++) {
732 print_printer_info_4(&buffer4[i]);
733 printf("\n");
735 break;
736 case 5:
737 for (i=0; i<count; i++) {
738 print_printer_info_5(&buffer5[i]);
739 printf("\n");
741 break;
742 case 6:
743 for (i=0; i<count; i++) {
744 print_printer_info_6(&buffer6[i]);
745 printf("\n");
747 break;
748 case 7:
749 for (i=0; i<count; i++) {
750 print_printer_info_7(&buffer7[i]);
751 printf("\n");
753 break;
754 case 8:
755 for (i=0; i<count; i++) {
756 print_printer_info_8(&buffer8[i]);
757 printf("\n");
759 break;
760 case 9:
761 for (i=0; i<count; i++) {
762 print_printer_info_9(&buffer9[i]);
763 printf("\n");
765 break;
766 default:
767 break;
771 void print_printprocessor_info_1(PPRINTPROCESSOR_INFO_1 info)
773 printf("\tPrint Processor Name\t= %s\n", info->pName);
775 return;
778 void print_printprocessor_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
780 DWORD i;
781 PPRINTPROCESSOR_INFO_1 buffer1 = NULL;
783 if (!buffer) {
784 return;
787 switch (level) {
788 case 1:
789 buffer1 = (PPRINTPROCESSOR_INFO_1)buffer;
790 break;
791 default:
792 break;
795 printf("Print Processor Info Level %d:\n", level);
797 switch (level) {
798 case 1:
799 for (i=0; i<count; i++) {
800 print_printprocessor_info_1(&buffer1[i]);
801 printf("\n");
803 break;
804 default:
805 break;
809 void print_datatypes_info_1(PDATATYPES_INFO_1 info)
811 printf("\tDataTypes Name\t= %s\n", info->pName);
813 return;
816 void print_datatypes_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
818 DWORD i;
819 PDATATYPES_INFO_1 buffer1 = NULL;
821 if (!buffer) {
822 return;
825 switch (level) {
826 case 1:
827 buffer1 = (PDATATYPES_INFO_1)buffer;
828 break;
829 default:
830 break;
833 printf("DataTypes Info Level %d:\n", level);
835 switch (level) {
836 case 1:
837 for (i=0; i<count; i++) {
838 print_datatypes_info_1(&buffer1[i]);
839 printf("\n");
841 break;
842 default:
843 break;
847 void print_driver_info_1(PDRIVER_INFO_1 info)
849 printf("\tDriver Name\t= %s\n\n", info->pName);
851 return;
854 void print_driver_info_2(PDRIVER_INFO_2 info)
856 printf("\tDriver Name\t= %s\n", info->pName);
857 printf("\tEnvironment\t= %s\n", info->pEnvironment);
858 printf("\tVersion\t\t= %d\n", info->cVersion);
859 printf("\tDriver Path\t= %s\n", info->pDriverPath);
860 printf("\tData File\t= %s\n", info->pDataFile);
861 printf("\tConfig File\t= %s\n\n", info->pConfigFile);
863 return;
866 void print_driver_info_3(PDRIVER_INFO_3 info)
868 char *ptr = NULL;
870 printf("\tDriver Name\t= %s\n", info->pName);
871 printf("\tEnvironment\t= %s\n", info->pEnvironment);
872 printf("\tVersion\t\t= %d\n", info->cVersion);
873 printf("\tDriver Path\t= %s\n", info->pDriverPath);
874 printf("\tData File\t= %s\n", info->pDataFile);
875 printf("\tConfig File\t= %s\n", info->pConfigFile);
876 printf("\tHelp Path\t= %s\n", info->pHelpFile);
877 printf("\tMonitor Name\t= %s\n", info->pMonitorName);
878 printf("\tData Type\t= %s\n", info->pDefaultDataType);
879 ptr = (char*)info->pDependentFiles;
880 while ((ptr != NULL) && (*ptr != '\0')) {
881 printf("\tDependent Files\t= %s\n", ptr);
882 for (;*ptr != '\0'; ptr++)
883 /* printf("%s\n", ptr); */
885 ptr++;
888 return;
891 void print_driver_info_4(PDRIVER_INFO_4 info)
893 char *ptr = NULL;
895 printf("\tDriver Name\t= %s\n", info->pName);
896 printf("\tEnvironment\t= %s\n", info->pEnvironment);
897 printf("\tVersion\t\t= %d\n", info->cVersion);
898 printf("\tDriver Path\t= %s\n", info->pDriverPath);
899 printf("\tData File\t= %s\n", info->pDataFile);
900 printf("\tConfig File\t= %s\n", info->pConfigFile);
901 printf("\tHelp Path\t= %s\n", info->pHelpFile);
902 printf("\tMonitor Name\t= %s\n", info->pMonitorName);
903 printf("\tData Type\t= %s\n", info->pDefaultDataType);
904 printf("\tPrevious Names\t= %s\n", info->pszzPreviousNames);
905 ptr = (char*)info->pDependentFiles;
906 while ((ptr != NULL) && (*ptr != '\0')) {
907 printf("\tDependent Files\t= %s\n", ptr);
908 for (;*ptr != '\0'; ptr++)
909 /* printf("%s\n", ptr); */
911 ptr++;
914 return;
917 void print_driver_info_5(PDRIVER_INFO_5 info)
919 printf("\tDriver Name\t= %s\n", info->pName);
920 printf("\tEnvironment\t= %s\n", info->pEnvironment);
921 printf("\tVersion\t\t= %d\n", info->cVersion);
922 printf("\tDriver Path\t= %s\n", info->pDriverPath);
923 printf("\tData File\t= %s\n", info->pDataFile);
924 printf("\tConfig File\t= %s\n", info->pConfigFile);
925 printf("\tDriver Attributes\t= %d\n", info->dwDriverAttributes);
926 printf("\tConfig Version\t= %d\n", info->dwConfigVersion);
927 printf("\tDriver Version\t= %d\n", info->dwDriverVersion);
929 return;
932 void print_driver_info_6(PDRIVER_INFO_6 info)
934 char *ptr = NULL;
936 printf("\tDriver Name\t= %s\n", info->pName);
937 printf("\tEnvironment\t= %s\n", info->pEnvironment);
938 printf("\tVersion\t\t= %d\n", info->cVersion);
939 printf("\tDriver Path\t= %s\n", info->pDriverPath);
940 printf("\tData File\t= %s\n", info->pDataFile);
941 printf("\tConfig File\t= %s\n", info->pConfigFile);
942 printf("\tHelp Path\t= %s\n", info->pHelpFile);
943 printf("\tMonitor Name\t= %s\n", info->pMonitorName);
944 printf("\tData Type\t= %s\n", info->pDefaultDataType);
945 printf("\tPrevious Names\t= %s\n", info->pszzPreviousNames);
946 ptr = (char*)info->pDependentFiles;
947 if (ptr != NULL) {
948 while (*ptr != '\0') {
949 printf("\tDependent Files\t= %s\n", ptr);
950 for (;*ptr != '\0'; ptr++)
951 /* printf("%s\n", ptr); */
953 ptr++;
955 } else {
956 printf("\tPrevious Names\t= (null)\n");
959 ptr = (char*)info->pszzPreviousNames;
960 if (ptr != NULL) {
961 while (*ptr != '\0') {
962 printf("\tPrevious Names\t= %s\n", ptr);
963 for (;*ptr != '\0'; ptr++)
964 /* printf("%s\n", ptr); */
966 ptr++;
968 } else {
969 printf("\tPrevious Names\t= (null)\n");
972 printf("\tDriver Date\t= %d (%08x:%08x)\n",
973 info->ftDriverDate,
974 info->ftDriverDate.dwLowDateTime,
975 info->ftDriverDate.dwHighDateTime);
976 printf("\t\t");
977 print_file_time(&info->ftDriverDate);
978 printf("\tDriver Version\t= %d\n", info->dwlDriverVersion);
979 printf("\tManufacture Name = %s\n", info->pszMfgName);
980 printf("\tOEM URL\t\t= %s\n", info->pszOEMUrl);
981 printf("\tHardware ID\t= %s\n", info->pszHardwareID);
982 printf("\tProvider\t= %s\n", info->pszProvider);
983 return;
986 static void print_multi_sz(LPSTR multisz)
988 char *ptr = NULL;
990 ptr = (char *)multisz;
992 if (!ptr) {
993 printf("(null)\n");
994 return;
997 while (*ptr != '\0') {
998 printf("%s\n", ptr);
999 for (; *ptr != '\0'; ptr++) {
1000 /* printf("%s\n", ptr); */
1003 ptr++;
1007 void print_driver_info_8(PDRIVER_INFO_8 info)
1009 printf("\tDriver Name\t= %s\n", info->pName);
1010 printf("\tEnvironment\t= %s\n", info->pEnvironment);
1011 printf("\tVersion\t\t= %d\n", info->cVersion);
1012 printf("\tDriver Path\t= %s\n", info->pDriverPath);
1013 printf("\tData File\t= %s\n", info->pDataFile);
1014 printf("\tConfig File\t= %s\n", info->pConfigFile);
1015 printf("\tHelp Path\t= %s\n", info->pHelpFile);
1016 printf("\tMonitor Name\t= %s\n", info->pMonitorName);
1017 printf("\tData Type\t= %s\n", info->pDefaultDataType);
1018 printf("\tPrevious Names\t=\n");
1019 print_multi_sz(info->pszzPreviousNames);
1020 printf("\tDependent Files\t=\n");
1021 print_multi_sz(info->pDependentFiles);
1022 printf("\tDriver Date\t= %d (%08x:%08x)\n",
1023 info->ftDriverDate,
1024 info->ftDriverDate.dwLowDateTime,
1025 info->ftDriverDate.dwHighDateTime);
1026 printf("\t\t");
1027 print_file_time(&info->ftDriverDate);
1028 printf("\tDriver Version\t= %d\n", info->dwlDriverVersion);
1029 printf("\tManufacture Name = %s\n", info->pszMfgName);
1030 printf("\tOEM URL\t\t= %s\n", info->pszOEMUrl);
1031 printf("\tHardware ID\t= %s\n", info->pszHardwareID);
1032 printf("\tProvider\t= %s\n", info->pszProvider);
1033 printf("\tPrint Processor\t= %s\n", info->pszPrintProcessor);
1034 printf("\tVendor Setup\t= %s\n", info->pszVendorSetup);
1035 printf("\tColor Profiles\t=\n");
1036 print_multi_sz(info->pszzColorProfiles);
1037 printf("\tInf Path\t= %s\n", info->pszInfPath);
1038 printf("\tPrinter Driver Attributes = %d\n", info->dwPrinterDriverAttributes);
1039 printf("\tCore Driver Dependencies\t=\n");
1040 print_multi_sz(info->pszzCoreDriverDependencies);
1041 printf("\tMin Inbox Driver VerDate\t= %d (%08x:%08x)\n",
1042 info->ftMinInboxDriverVerDate,
1043 info->ftMinInboxDriverVerDate.dwLowDateTime,
1044 info->ftMinInboxDriverVerDate.dwHighDateTime);
1045 printf("\t\t");
1046 print_file_time(&info->ftMinInboxDriverVerDate);
1047 printf("\tMin Inbox Driver VerVersion\t= %d\n", info->dwlMinInboxDriverVerVersion);
1048 return;
1051 void print_driver_info_bylevel(DWORD level, LPBYTE buffer, DWORD count)
1053 DWORD i;
1054 PDRIVER_INFO_1 buffer1 = NULL;
1055 PDRIVER_INFO_2 buffer2 = NULL;
1056 PDRIVER_INFO_3 buffer3 = NULL;
1057 PDRIVER_INFO_4 buffer4 = NULL;
1058 PDRIVER_INFO_5 buffer5 = NULL;
1059 PDRIVER_INFO_6 buffer6 = NULL;
1060 PDRIVER_INFO_8 buffer8 = NULL;
1062 if (!buffer) {
1063 return;
1066 switch (level) {
1067 case 1:
1068 buffer1 = (PDRIVER_INFO_1)buffer;
1069 break;
1070 case 2:
1071 buffer2 = (PDRIVER_INFO_2)buffer;
1072 break;
1073 case 3:
1074 buffer3 = (PDRIVER_INFO_3)buffer;
1075 break;
1076 case 4:
1077 buffer4 = (PDRIVER_INFO_4)buffer;
1078 break;
1079 case 5:
1080 buffer5 = (PDRIVER_INFO_5)buffer;
1081 break;
1082 case 6:
1083 buffer6 = (PDRIVER_INFO_6)buffer;
1084 break;
1085 case 8:
1086 buffer8 = (PDRIVER_INFO_8)buffer;
1087 break;
1088 default:
1089 break;
1092 printf("Driver Info Level %d:\n", level);
1094 switch (level) {
1095 case 1:
1096 for (i=0; i<count; i++) {
1097 print_driver_info_1(&buffer1[i]);
1098 printf("\n");
1100 break;
1101 case 2:
1102 for (i=0; i<count; i++) {
1103 print_driver_info_2(&buffer2[i]);
1104 printf("\n");
1106 break;
1107 case 3:
1108 for (i=0; i<count; i++) {
1109 print_driver_info_3(&buffer3[i]);
1110 printf("\n");
1112 break;
1113 case 4:
1114 for (i=0; i<count; i++) {
1115 print_driver_info_4(&buffer4[i]);
1116 printf("\n");
1118 break;
1119 case 5:
1120 for (i=0; i<count; i++) {
1121 print_driver_info_5(&buffer5[i]);
1122 printf("\n");
1124 break;
1125 case 6:
1126 for (i=0; i<count; i++) {
1127 print_driver_info_6(&buffer6[i]);
1128 printf("\n");
1130 break;
1131 case 8:
1132 for (i=0; i<count; i++) {
1133 print_driver_info_8(&buffer8[i]);
1134 printf("\n");
1136 break;
1137 default:
1138 break;
1142 void print_doc_info_1(PDOC_INFO_1 info)
1144 printf("\tDocument Name\t= %s\n", info->pDocName);
1145 printf("\tOutput Filename\t= %s\n", info->pOutputFile);
1146 printf("\tDatatype\t= %s\n", info->pDatatype);
1147 return;
1150 void print_printer_keys(LPSTR buffer)
1152 LPSTR p = NULL;
1154 p = buffer;
1156 while (p && *p) {
1157 printf("%s\n", p);
1158 for (; *p; p = CharNext(p)) {
1159 p = CharNext(p);
1164 LPSTR reg_type_str(DWORD type)
1166 switch (type) {
1167 case REG_DWORD:
1168 return "REG_DWORD";
1169 case REG_SZ:
1170 return "REG_SZ";
1171 case REG_MULTI_SZ:
1172 return "REG_MULTI_SZ";
1173 case REG_BINARY:
1174 return "REG_BINARY";
1175 default:
1176 return NULL;
1180 void print_asc(const BYTE *buf, DWORD len)
1182 int i;
1183 for (i=0; i<len; i++) {
1184 printf("%c", isprint(buf[i])?buf[i]:'.');
1188 static void dump_data(const BYTE *buf, int len)
1190 int i=0;
1191 static const BYTE empty[16] = { 0, };
1193 if (len<=0) return;
1195 for (i=0; i<len;) {
1197 if (i%16 == 0) {
1198 if ((i > 0) &&
1199 (len > i+16) &&
1200 (memcmp(&buf[i], &empty, 16) == 0))
1202 i +=16;
1203 continue;
1206 if (i<len) {
1207 printf("[%04X] ",i);
1211 printf("%02x ", buf[i]);
1212 i++;
1214 if (i%8 == 0) printf(" ");
1215 if (i%16 == 0) {
1216 print_asc(&buf[i-16],8); printf(" ");
1217 print_asc(&buf[i-8],8); printf("\n");
1221 if (i%16) {
1222 int n;
1223 n = 16 - (i%16);
1224 printf(" ");
1225 if (n>8) printf(" ");
1226 while (n--) printf(" ");
1227 n = MIN(8,i%16);
1228 print_asc(&buf[i-(i%16)],n); printf( " " );
1229 n = (i%16) - n;
1230 if (n>0) print_asc(&buf[i-n],n);
1231 printf("\n");
1235 static void dump_printer_data(DWORD size, LPBYTE buffer, DWORD type)
1237 DWORD i = 0;
1238 LPSTR p = NULL;
1240 switch (type) {
1241 case REG_SZ:
1242 dump_data(buffer, size);
1243 break;
1244 case REG_MULTI_SZ:
1245 dump_data(buffer, size);
1246 p = (LPSTR)buffer;
1247 while (p && *p) {
1248 printf("\t\t%s\n", p);
1249 for (; *p; p = CharNext(p)) {
1250 p = CharNext(p);
1253 break;
1254 case REG_DWORD:
1255 assert(size == 4);
1256 printf("\t\t0x%08x\n", (DWORD)*buffer);
1257 break;
1258 case REG_BINARY:
1259 dump_data(buffer, size);
1260 break;
1261 default:
1262 break;
1266 void print_printer_data(LPSTR keyname, LPSTR valuename, DWORD size, LPBYTE buffer, DWORD type)
1268 if (keyname) {
1269 printf("\tKey Name:\t%s\n", keyname);
1272 printf("\tValue Name:\t%s\n", valuename);
1273 printf("\tSize:\t\t0x%x (%d)\n", size, size);
1274 printf("\tType:\t\t%s\n", reg_type_str(type));
1276 if (buffer == NULL || size == 0) {
1277 return;
1280 dump_printer_data(size, buffer, type);
1283 void print_printer_dataw(LPCWSTR keyname, LPCWSTR valuename, DWORD size, LPBYTE buffer, DWORD type)
1285 if (keyname) {
1286 printf("\tKey Name:\t%ls\n", keyname);
1289 printf("\tValue Name:\t%ls\n", valuename);
1290 printf("\tSize:\t\t0x%x (%d)\n", size, size);
1291 printf("\tType:\t\t%s\n", reg_type_str(type));
1293 if (buffer == NULL || size == 0) {
1294 return;
1297 dump_printer_data(size, buffer, type);
1301 void print_printer_enum_values(PRINTER_ENUM_VALUES *info)
1303 print_printer_data(NULL, info->pValueName, info->cbData, info->pData, info->dwType);
1306 void print_file_time(const FILETIME *t)
1308 SYSTEMTIME s;
1309 LPSTR dayofweek = NULL;
1310 LPSTR month = NULL;
1312 if (!FileTimeToSystemTime(t, &s)) {
1313 printf("Failed to convert FILETIME to SYSTEMTIME\n");
1314 return;
1316 switch (s.wDayOfWeek) {
1317 case 0:
1318 dayofweek = "Sun";
1319 break;
1320 case 1:
1321 dayofweek = "Mon";
1322 break;
1323 case 2:
1324 dayofweek = "Tue";
1325 break;
1326 case 3:
1327 dayofweek = "Wed";
1328 break;
1329 case 4:
1330 dayofweek = "Thu";
1331 break;
1332 case 5:
1333 dayofweek = "Fri";
1334 break;
1335 case 6:
1336 dayofweek = "Sat";
1337 break;
1338 default:
1339 break;
1342 switch (s.wMonth) {
1343 case 1:
1344 month = "Jan";
1345 break;
1346 case 2:
1347 month = "Feb";
1348 break;
1349 case 3:
1350 month = "Mar";
1351 break;
1352 case 4:
1353 month = "Apr";
1354 break;
1355 case 5:
1356 month = "May";
1357 break;
1358 case 6:
1359 month = "Jun";
1360 break;
1361 case 7:
1362 month = "Jul";
1363 break;
1364 case 8:
1365 month = "Aug";
1366 break;
1367 case 9:
1368 month = "Sep";
1369 break;
1370 case 10:
1371 month = "Oct";
1372 break;
1373 case 11:
1374 month = "Nov";
1375 break;
1376 case 12:
1377 month = "Dec";
1378 break;
1379 default:
1380 break;
1383 printf("%s %s %02d %02d:%02d:%02d %04d\n",
1384 dayofweek, month, s.wDay,
1385 s.wHour, s.wMinute, s.wSecond, s.wYear);