add SetPrinterDataExW.exe.
[gd/win32-spoolss/.git] / SetPrinter.c
1 /******************************************************************
2  * SPOOLSS regression testing code for Samba print servers
3  *
4  *****************************************************************/
5
6 #include <windows.h>
7 #include <stdio.h>
8 #include "printlib.h"
9
10 /* we will excercise info level 2 (cange the drivername)
11    and info level 3 (security descriptor) */
12 int main (int argc, char* argv[])
13 {
14         DWORD   needed;
15         HANDLE  printer;
16         PPRINTER_INFO_2 buffer2 = NULL;
17         PRINTER_INFO_3  buffer3;
18
19         if (argc < 3)
20         {
21                 fprintf (stderr, "useage: %s <printername> <drivername>\n", argv[0]);
22                 exit (-1);
23         }
24
25         /* open the printer */
26         if (!OpenPrinter (argv[1], &printer, NULL))
27         {
28                 fprintf (stderr, "Unable to open %s!\n", argv[1]);
29                 exit (-1);
30         }
31         else
32         {
33                 printf ("Printer [%s] opened successfully.\n\n", argv[1]);
34         }
35
36         /* INFO LEVEL 2 */
37         GetPrinter(printer, 2, (LPBYTE)buffer2, 0, &needed);
38         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
39         {
40                 if (needed != 0)
41                         fprintf (stderr, "Error GetPrinter Info Level 2 for [%s] using NULL buffer.\n", argv[1]);
42                 else
43                         printf ("Info level 2 returned no information\n");
44         }
45         else
46         {
47                 if ((buffer2 = (PPRINTER_INFO_2)malloc(needed)) == NULL)
48                 {
49                         fprintf (stderr, "Unable to malloc memory for buffer!\n");
50                         exit (-1);
51                 }
52                 if (!GetPrinter(printer, 2, (LPBYTE)buffer2, needed, &needed))
53                 {
54                         fprintf (stderr, "Error getting printers Info Level 2 for [%s].\nSize of buffer = %d\n",
55                                         argv[1], needed);
56                 }
57
58                 printf ("Printer Info Level 2:\n");
59                 print_printer_info_2(buffer2);
60                 printf ("\n");
61         }
62
63         /* set the new drivername */
64         buffer2->pDriverName = _strdup (argv[2]);
65         if (SetPrinter(printer, 2, (LPBYTE)buffer2, 0))
66         {
67                 printf ("Printer driver successfully changed to [%s]\n", argv[2]);
68                 printf ("Printer Info 2 :\n");
69                 print_printer_info_2 (buffer2);
70                 printf ("\n");
71         }
72         else
73                 PrintLastError();
74
75         /* exercise the various command options */
76         printf ("command = PRINTER_CONTROL_PAUSE\n");
77         if (SetPrinter (printer, 2, (LPBYTE)buffer2, PRINTER_CONTROL_PAUSE))
78                 printf ("Printer successfully paused.\n");
79         else
80                 PrintLastError();
81         printf ("\n");
82
83         printf ("command = PRINTER_CONTROL_RESUME\n");
84         if (SetPrinter (printer, 2, (LPBYTE)buffer2, PRINTER_CONTROL_RESUME))
85                 printf ("Printer successfully paused.\n");
86         else
87                 PrintLastError();
88         printf ("\n");
89
90         printf ("command = PRINTER_CONTROL_PURGE\n");
91         if (SetPrinter (printer, 2, (LPBYTE)buffer2, PRINTER_CONTROL_PURGE))
92                 printf ("Printer successfully paused.\n");
93         else
94                 PrintLastError();
95         printf ("\n");
96
97
98         /* we'll just use the security descriptor from the buffer2 */
99         printf ("Testing setting of security descriptor using PRINTER_INFO_3...\n");
100         buffer3.pSecurityDescriptor = buffer2->pSecurityDescriptor;
101
102         printf ("Current security descriptor settings for [%s]:\n", argv[1]);
103         /* print_secdesc (buffer3.pSecurityDescriptor); */
104         printf ("\n");
105
106         printf ("no changes to security descriptor...\n\n");
107
108
109         if (SetPrinter (printer, 3, (LPBYTE)&buffer3, 0))
110         {
111                 printf ("Printer descriptor information updated successfully.\n");
112                 printf ("New security descriptor settings for [%s]:\n", argv[1]);
113                 /* print_secdesc (buffer3.pSecurityDescriptor); */
114                 printf ("\n");
115         }
116         else
117                 PrintLastError();
118         printf ("\n");
119
120         /* close the printer */
121         if (!ClosePrinter(printer))
122         {
123                 fprintf (stderr, "Error closing printer!\n");
124                 exit (-1);
125         }
126         else
127         {
128                 printf ("Printer [%s] closed successfully.\n", argv[1]);
129         }
130
131         return 0;
132
133 }