s3: Lift the smbd_messaging_context from nt_printer_publish
[amitay/samba.git] / source3 / include / nt_printing.h
1 /*
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    SMB parameters and setup
5    Copyright (C) Andrew Tridgell              1992-2000,
6    Copyright (C) Jean Francois Micouleau      1998-2000.
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 3 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 #ifndef NT_PRINTING_H_
23 #define NT_PRINTING_H_
24
25 #include "client.h"
26 #include "../librpc/gen_ndr/srv_spoolss.h"
27
28 /* container for a single registry key */
29
30 typedef struct {
31         char                    *name;
32         struct regval_ctr       *values;
33 } NT_PRINTER_KEY;
34
35 /* container for all printer data */
36
37 typedef struct {
38         int             num_keys;
39         NT_PRINTER_KEY  *keys;
40 } NT_PRINTER_DATA;
41
42 typedef struct nt_printer_info_level_2
43 {
44         uint32 attributes;
45         uint32 priority;
46         uint32 default_priority;
47         uint32 starttime;
48         uint32 untiltime;
49         uint32 status;
50         uint32 cjobs;
51         uint32 averageppm;
52         fstring servername;
53         fstring printername;
54         fstring sharename;
55         fstring portname;
56         fstring drivername;
57         char comment[1024];
58         fstring location;
59         struct spoolss_DeviceMode *devmode;
60         fstring sepfile;
61         fstring printprocessor;
62         fstring datatype;
63         fstring parameters;
64         NT_PRINTER_DATA *data;
65         struct sec_desc_buf *secdesc_buf;
66         uint32 changeid;
67         uint32 c_setprinter;
68         uint32 setuptime;       
69 } NT_PRINTER_INFO_LEVEL_2;
70
71 typedef struct nt_printer_info_level
72 {
73         NT_PRINTER_INFO_LEVEL_2 *info_2;
74 } NT_PRINTER_INFO_LEVEL;
75
76 typedef struct
77 {
78         fstring name;
79         uint32 flag;
80         uint32 width;
81         uint32 length;
82         uint32 left;
83         uint32 top;
84         uint32 right;
85         uint32 bottom;
86 } nt_forms_struct;
87
88 #ifndef SAMBA_PRINTER_PORT_NAME
89 #define SAMBA_PRINTER_PORT_NAME "Samba Printer Port"
90 #endif
91
92 /* DOS header format */
93 #define DOS_HEADER_SIZE                 64
94 #define DOS_HEADER_MAGIC_OFFSET         0
95 #define DOS_HEADER_MAGIC                0x5A4D
96 #define DOS_HEADER_LFANEW_OFFSET        60
97
98 /* New Executable format (Win or OS/2 1.x segmented) */
99 #define NE_HEADER_SIZE                  64
100 #define NE_HEADER_SIGNATURE_OFFSET      0
101 #define NE_HEADER_SIGNATURE             0x454E
102 #define NE_HEADER_TARGET_OS_OFFSET      54
103 #define NE_HEADER_TARGOS_WIN            0x02
104 #define NE_HEADER_MINOR_VER_OFFSET      62
105 #define NE_HEADER_MAJOR_VER_OFFSET      63
106
107 /* Portable Executable format */
108 #define PE_HEADER_SIZE                  24
109 #define PE_HEADER_SIGNATURE_OFFSET      0
110 #define PE_HEADER_SIGNATURE             0x00004550
111 #define PE_HEADER_MACHINE_OFFSET        4
112 #define PE_HEADER_MACHINE_I386          0x14c
113 #define PE_HEADER_NUMBER_OF_SECTIONS    6
114 #define PE_HEADER_OPTIONAL_HEADER_SIZE  20
115 #define PE_HEADER_SECT_HEADER_SIZE      40
116 #define PE_HEADER_SECT_NAME_OFFSET      0
117 #define PE_HEADER_SECT_SIZE_DATA_OFFSET 16
118 #define PE_HEADER_SECT_PTR_DATA_OFFSET  20
119
120 /* Microsoft file version format */
121 #define VS_SIGNATURE                    "VS_VERSION_INFO"
122 #define VS_MAGIC_VALUE                  0xfeef04bd
123 #define VS_MAJOR_OFFSET                                 8
124 #define VS_MINOR_OFFSET                                 12
125 #define VS_VERSION_INFO_UNICODE_SIZE    (sizeof(VS_SIGNATURE)*2+4+VS_MINOR_OFFSET+4) /* not true size! */
126 #define VS_VERSION_INFO_SIZE            (sizeof(VS_SIGNATURE)+4+VS_MINOR_OFFSET+4)   /* not true size! */
127 #define VS_NE_BUF_SIZE                  4096  /* Must be > 2*VS_VERSION_INFO_SIZE */
128
129 /* Notify spoolss clients that something has changed.  The
130    notification data is either stored in two uint32 values or a
131    variable length array. */
132
133 #define SPOOLSS_NOTIFY_MSG_UNIX_JOBID 0x0001    /* Job id is unix  */
134
135 typedef struct spoolss_notify_msg {
136         fstring printer;        /* Name of printer notified */
137         uint32 type;            /* Printer or job notify */
138         uint32 field;           /* Notify field changed */
139         uint32 id;              /* Job id */
140         uint32 len;             /* Length of data, 0 for two uint32 value */
141         uint32 flags;
142         union {
143                 uint32 value[2];
144                 char *data;
145         } notify;
146 } SPOOLSS_NOTIFY_MSG;
147
148 typedef struct {
149         fstring                 printername;
150         uint32                  num_msgs;
151         SPOOLSS_NOTIFY_MSG      *msgs;
152 } SPOOLSS_NOTIFY_MSG_GROUP;
153
154 typedef struct {
155         TALLOC_CTX                      *ctx;
156         uint32                          num_groups;
157         SPOOLSS_NOTIFY_MSG_GROUP        *msg_groups;
158 } SPOOLSS_NOTIFY_MSG_CTR;
159
160 #define SPLHND_PRINTER          1
161 #define SPLHND_SERVER           2
162 #define SPLHND_PORTMON_TCP      3
163 #define SPLHND_PORTMON_LOCAL    4
164
165 /* structure to store the printer handles */
166 /* and a reference to what it's pointing to */
167 /* and the notify info asked about */
168 /* that's the central struct */
169 typedef struct _Printer{
170         struct _Printer *prev, *next;
171         bool document_started;
172         bool page_started;
173         uint32 jobid; /* jobid in printing backend */
174         int printer_type;
175         fstring servername;
176         fstring sharename;
177         uint32 type;
178         uint32 access_granted;
179         struct {
180                 uint32 flags;
181                 uint32 options;
182                 fstring localmachine;
183                 uint32 printerlocal;
184                 struct spoolss_NotifyOption *option;
185                 struct policy_handle client_hnd;
186                 bool client_connected;
187                 uint32 change;
188                 /* are we in a FindNextPrinterChangeNotify() call? */
189                 bool fnpcn;
190                 struct messaging_context *msg_ctx;
191         } notify;
192         struct {
193                 fstring machine;
194                 fstring user;
195         } client;
196
197         /* devmode sent in the OpenPrinter() call */
198         struct spoolss_DeviceMode *devmode;
199
200         /* TODO cache the printer info2 structure */
201         struct spoolss_PrinterInfo2 *info2;
202         
203 } Printer_entry;
204
205 /*
206  * The printer attributes.
207  * I #defined all of them (grabbed form MSDN)
208  * I'm only using:
209  * ( SHARED | NETWORK | RAW_ONLY )
210  * RAW_ONLY _MUST_ be present otherwise NT will send an EMF file
211  */
212
213 #define PRINTER_ATTRIBUTE_SAMBA                 (PRINTER_ATTRIBUTE_RAW_ONLY|\
214                                                  PRINTER_ATTRIBUTE_SHARED|\
215                                                  PRINTER_ATTRIBUTE_LOCAL)
216 #define PRINTER_ATTRIBUTE_NOT_SAMBA             (PRINTER_ATTRIBUTE_NETWORK)
217
218 #define DRIVER_ANY_VERSION              0xffffffff
219 #define DRIVER_MAX_VERSION              4
220
221 struct print_architecture_table_node {
222         const char      *long_archi;
223         const char      *short_archi;
224         int     version;
225 };
226
227 bool nt_printing_init(struct messaging_context *msg_ctx);
228
229 WERROR spoolss_create_default_devmode(TALLOC_CTX *mem_ctx,
230                                       const char *devicename,
231                                       struct spoolss_DeviceMode **devmode);
232
233 WERROR spoolss_create_default_secdesc(TALLOC_CTX *mem_ctx,
234                                       struct spoolss_security_descriptor **secdesc);
235
236 WERROR spoolss_map_to_os2_driver(TALLOC_CTX *mem_ctx, const char **pdrivername);
237
238 const char *get_short_archi(const char *long_archi);
239
240 bool print_access_check(struct auth_serversupplied_info *server_info,
241                         struct messaging_context *msg_ctx, int snum,
242                         int access_type);
243
244 WERROR nt_printer_publish(TALLOC_CTX *mem_ctx,
245                           struct auth_serversupplied_info *server_info,
246                           struct messaging_context *msg_ctx,
247                           struct spoolss_PrinterInfo2 *pinfo2,
248                           int action);
249
250 bool is_printer_published(TALLOC_CTX *mem_ctx,
251                           struct auth_serversupplied_info *server_info,
252                           char *servername, char *printer, struct GUID *guid,
253                           struct spoolss_PrinterInfo2 **info2);
254
255 WERROR check_published_printers(void);
256
257 bool driver_info_ctr_to_info8(struct spoolss_AddDriverInfoCtr *r,
258                               struct spoolss_DriverInfo8 *_info8);
259
260 bool printer_driver_in_use(TALLOC_CTX *mem_ctx,
261                            struct auth_serversupplied_info *server_info,
262                            struct messaging_context *msg_ctx,
263                            const struct spoolss_DriverInfo8 *r);
264 bool printer_driver_files_in_use(TALLOC_CTX *mem_ctx,
265                                  struct auth_serversupplied_info *server_info,
266                                  struct messaging_context *msg_ctx,
267                                  struct spoolss_DriverInfo8 *r);
268 bool delete_driver_files(struct auth_serversupplied_info *server_info,
269                          const struct spoolss_DriverInfo8 *r);
270
271 WERROR move_driver_to_download_area(struct pipes_struct *p,
272                                     struct spoolss_AddDriverInfoCtr *r,
273                                     WERROR *perr);
274
275 WERROR clean_up_driver_struct(TALLOC_CTX *mem_ctx,
276                               struct pipes_struct *rpc_pipe,
277                               struct spoolss_AddDriverInfoCtr *r);
278
279 void map_printer_permissions(struct security_descriptor *sd);
280
281 void map_job_permissions(struct security_descriptor *sd);
282
283 bool print_time_access_check(struct auth_serversupplied_info *server_info,
284                              struct messaging_context *msg_ctx,
285                              const char *servicename);
286
287 void nt_printer_remove(TALLOC_CTX *mem_ctx,
288                         struct auth_serversupplied_info *server_info,
289                         struct messaging_context *msg_ctx,
290                         const char *printer);
291
292 #endif /* NT_PRINTING_H_ */