s3: Lift the smbd_messaging_context from winreg_printer_deleteform1
[amitay/samba.git] / source3 / rpc_server / srv_spoolss_util.h
1 /*
2  *  Unix SMB/CIFS implementation.
3  *
4  *  SPOOLSS RPC Pipe server / winreg client routines
5  *
6  *  Copyright (c) 2010      Andreas Schneider <asn@samba.org>
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 _SRV_SPOOLSS_UITL_H
23 #define _SRV_SPOOLSS_UITL_H
24
25
26 enum spoolss_PrinterInfo2Mask {
27         SPOOLSS_PRINTER_INFO_ATTRIBUTES      = (int)(0x00000001),
28         SPOOLSS_PRINTER_INFO_AVERAGEPPM      = (int)(0x00000002),
29         SPOOLSS_PRINTER_INFO_CJOBS           = (int)(0x00000004),
30         SPOOLSS_PRINTER_INFO_COMMENT         = (int)(0x00000008),
31         SPOOLSS_PRINTER_INFO_DATATYPE        = (int)(0x00000010),
32         SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY = (int)(0x00000020),
33         SPOOLSS_PRINTER_INFO_DEVMODE         = (int)(0x00000040),
34         SPOOLSS_PRINTER_INFO_DRIVERNAME      = (int)(0x00000080),
35         SPOOLSS_PRINTER_INFO_LOCATION        = (int)(0x00000100),
36         SPOOLSS_PRINTER_INFO_NAME            = (int)(0x00000200),
37         SPOOLSS_PRINTER_INFO_PARAMETERS      = (int)(0x00000400),
38         SPOOLSS_PRINTER_INFO_PORTNAME        = (int)(0x00000800),
39         SPOOLSS_PRINTER_INFO_PRINTERNAME     = (int)(0x00001000),
40         SPOOLSS_PRINTER_INFO_PRINTPROCESSOR  = (int)(0x00002000),
41         SPOOLSS_PRINTER_INFO_PRIORITY        = (int)(0x00004000),
42         SPOOLSS_PRINTER_INFO_SECDESC         = (int)(0x00008000),
43         SPOOLSS_PRINTER_INFO_SEPFILE         = (int)(0x00010000),
44         SPOOLSS_PRINTER_INFO_SERVERNAME      = (int)(0x00020000),
45         SPOOLSS_PRINTER_INFO_SHARENAME       = (int)(0x00040000),
46         SPOOLSS_PRINTER_INFO_STARTTIME       = (int)(0x00080000),
47         SPOOLSS_PRINTER_INFO_STATUS          = (int)(0x00100000),
48         SPOOLSS_PRINTER_INFO_UNTILTIME       = (int)(0x00200000)
49 };
50
51 #define SPOOLSS_PRINTER_INFO_ALL SPOOLSS_PRINTER_INFO_ATTRIBUTES      | \
52                                  SPOOLSS_PRINTER_INFO_AVERAGEPPM      | \
53                                  SPOOLSS_PRINTER_INFO_CJOBS           | \
54                                  SPOOLSS_PRINTER_INFO_COMMENT         | \
55                                  SPOOLSS_PRINTER_INFO_DATATYPE        | \
56                                  SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY | \
57                                  SPOOLSS_PRINTER_INFO_DEVMODE         | \
58                                  SPOOLSS_PRINTER_INFO_DRIVERNAME      | \
59                                  SPOOLSS_PRINTER_INFO_LOCATION        | \
60                                  SPOOLSS_PRINTER_INFO_NAME            | \
61                                  SPOOLSS_PRINTER_INFO_PARAMETERS      | \
62                                  SPOOLSS_PRINTER_INFO_PORTNAME        | \
63                                  SPOOLSS_PRINTER_INFO_PRINTERNAME     | \
64                                  SPOOLSS_PRINTER_INFO_PRINTPROCESSOR  | \
65                                  SPOOLSS_PRINTER_INFO_PRIORITY        | \
66                                  SPOOLSS_PRINTER_INFO_SECDESC         | \
67                                  SPOOLSS_PRINTER_INFO_SEPFILE         | \
68                                  SPOOLSS_PRINTER_INFO_SERVERNAME      | \
69                                  SPOOLSS_PRINTER_INFO_SHARENAME       | \
70                                  SPOOLSS_PRINTER_INFO_STARTTIME       | \
71                                  SPOOLSS_PRINTER_INFO_STATUS          | \
72                                  SPOOLSS_PRINTER_INFO_UNTILTIME
73
74 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
75                              struct auth_serversupplied_info *server_info,
76                              struct messaging_context *msg_ctx,
77                              const char *servername,
78                              const char *sharename);
79
80 /**
81  * @internal
82  *
83  * @brief Update the information of a printer in the registry.
84  *
85  * @param[in]  mem_ctx  The talloc memory context to use.
86  *
87  * @param[in]  server_info The server supplied session info.
88  *
89  * @param[in]  sharename  The share name.
90  *
91  * @param[in]  info2_mask A bitmask which defines which values should be set.
92  *
93  * @param[in]  info2    A SetPrinterInfo2 structure with the data to set.
94  *
95  * @param[in]  devmode  A device mode structure with the data to set.
96  *
97  * @param[in]  secdesc  A security descriptor structure with the data to set.
98  *
99  * @return              On success WERR_OK, a corresponding DOS error is
100  *                      something went wrong.
101  */
102 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
103                              struct auth_serversupplied_info *server_info,
104                              struct messaging_context *msg_ctx,
105                              const char *sharename,
106                              uint32_t info2_mask,
107                              struct spoolss_SetPrinterInfo2 *info2,
108                              struct spoolss_DeviceMode *devmode,
109                              struct security_descriptor *secdesc);
110
111
112 /**
113  * @brief Get the inforamtion of a printer stored in the registry.
114  *
115  * @param[in]  mem_ctx  The talloc memory context to use.
116  *
117  * @param[in]  server_info The server supplied session info.
118  *
119  * @param[in]  printer  The servername to use.
120  *
121  * @param[in]  printer  The name of the printer to get.
122  *
123  * @param[out] pinfo2   A pointer to store a PRINTER_INFO_2 structure.
124  *
125  * @return              On success WERR_OK, a corresponding DOS error is
126  *                      something went wrong.
127  */
128 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
129                           struct auth_serversupplied_info *server_info,
130                           struct messaging_context *msg_ctx,
131                           const char *servername,
132                           const char *printer,
133                           struct spoolss_PrinterInfo2 **pinfo2);
134
135 /**
136  * @brief Get the security descriptor for a printer.
137  *
138  * @param[in]  mem_ctx  The talloc memory context to use.
139  *
140  * @param[in]  server_info The server supplied session info.
141  *
142  * @param[in]  sharename  The share name.
143  *
144  * @param[out] psecdesc   A pointer to store the security descriptor.
145  *
146  * @return              On success WERR_OK, a corresponding DOS error is
147  *                      something went wrong.
148  */
149 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
150                                   struct auth_serversupplied_info *server_info,
151                                   struct messaging_context *msg_ctx,
152                                   const char *sharename,
153                                   struct spoolss_security_descriptor **psecdesc);
154
155 /**
156  * @brief Set the security descriptor for a printer.
157  *
158  * @param[in]  mem_ctx  The talloc memory context to use.
159  *
160  * @param[in]  server_info The server supplied session info.
161  *
162  * @param[in]  sharename  The share name.
163  *
164  * @param[in]  secdesc  The security descriptor to save.
165  *
166  * @return              On success WERR_OK, a corresponding DOS error is
167  *                      something went wrong.
168  */
169 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
170                                   struct auth_serversupplied_info *server_info,
171                                   struct messaging_context *msg_ctx,
172                                   const char *sharename,
173                                   const struct spoolss_security_descriptor *secdesc);
174
175 /**
176  * @internal
177  *
178  * @brief Set printer data over the winreg pipe.
179  *
180  * @param[in]  mem_ctx  The talloc memory context to use.
181  *
182  * @param[in]  server_info The server supplied session info.
183  *
184  * @param[in]  printer  The printer name.
185  *
186  * @param[in]  key      The key of the printer data to store the value.
187  *
188  * @param[in]  value    The value name to save.
189  *
190  * @param[in]  type     The type of the value to use.
191  *
192  * @param[in]  data     The data which sould be saved under the given value.
193  *
194  * @param[in]  data_size The size of the data.
195  *
196  * @return              On success WERR_OK, a corresponding DOS error is
197  *                      something went wrong.
198  */
199 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
200                                  struct auth_serversupplied_info *server_info,
201                                  struct messaging_context *msg_ctx,
202                                  const char *printer,
203                                  const char *key,
204                                  const char *value,
205                                  enum winreg_Type type,
206                                  uint8_t *data,
207                                  uint32_t data_size);
208
209 /**
210  * @internal
211  *
212  * @brief Get printer data over a winreg pipe.
213  *
214  * @param[in]  mem_ctx  The talloc memory context to use.
215  *
216  * @param[in]  server_info The server supplied session info.
217  *
218  * @param[in]  printer  The printer name.
219  *
220  * @param[in]  key      The key of the printer data to get the value.
221  *
222  * @param[in]  value    The name of the value to query.
223  *
224  * @param[in]  type     The type of the value to query.
225  *
226  * @param[out] data     A pointer to store the data.
227  *
228  * @param[out] data_size A pointer to store the size of the data.
229  *
230  * @return              On success WERR_OK, a corresponding DOS error is
231  *                      something went wrong.
232  */
233 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
234                                  struct auth_serversupplied_info *server_info,
235                                  struct messaging_context *msg_ctx,
236                                  const char *printer,
237                                  const char *key,
238                                  const char *value,
239                                  enum winreg_Type *type,
240                                  uint8_t **data,
241                                  uint32_t *data_size);
242
243 /**
244  * @internal
245  *
246  * @brief Enumerate on the values of a given key and provide the data.
247  *
248  * @param[in]  mem_ctx  The talloc memory context to use.
249  *
250  * @param[in]  server_info The server supplied session info.
251  *
252  * @param[in]  printer  The printer name.
253  *
254  * @param[in]  key      The key of the printer data to get the value.
255  *
256  * @param[out] pnum_values A pointer to store the number of values we found.
257  *
258  * @param[out] penum_values A pointer to store the values and its data.
259  *
260  * @return                   WERR_OK on success, the corresponding DOS error
261  *                           code if something gone wrong.
262  */
263 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
264                                   struct auth_serversupplied_info *server_info,
265                                   struct messaging_context *msg_ctx,
266                                   const char *printer,
267                                   const char *key,
268                                   uint32_t *pnum_values,
269                                   struct spoolss_PrinterEnumValues **penum_values);
270
271 /**
272  * @internal
273  *
274  * @brief Delete printer data over a winreg pipe.
275  *
276  * @param[in]  mem_ctx  The talloc memory context to use.
277  *
278  * @param[in]  server_info The server supplied session info.
279  *
280  * @param[in]  printer  The printer name.
281  *
282  * @param[in]  key      The key of the printer data to delete.
283  *
284  * @param[in]  value    The name of the value to delete.
285  *
286  * @return              On success WERR_OK, a corresponding DOS error is
287  *                      something went wrong.
288  */
289 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
290                                     struct auth_serversupplied_info *server_info,
291                                     struct messaging_context *msg_ctx,
292                                     const char *printer,
293                                     const char *key,
294                                     const char *value);
295
296 /**
297  * @internal
298  *
299  * @brief Enumerate on the subkeys of a given key and provide the data.
300  *
301  * @param[in]  mem_ctx  The talloc memory context to use.
302  *
303  * @param[in]  server_info The server supplied session info.
304  *
305  * @param[in]  printer  The printer name.
306  *
307  * @param[in]  key      The key of the printer data to get the value.
308  *
309  * @param[out] pnum_subkeys A pointer to store the number of subkeys found.
310  *
311  * @param[in]  psubkeys A pointer to an array to store the names of the subkeys
312  *                      found.
313  *
314  * @return              WERR_OK on success, the corresponding DOS error
315  *                      code if something gone wrong.
316  */
317 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
318                                struct auth_serversupplied_info *server_info,
319                                struct messaging_context *msg_ctx,
320                                const char *printer,
321                                const char *key,
322                                uint32_t *pnum_subkeys,
323                                const char ***psubkeys);
324
325 /**
326  * @internal
327  *
328  * @brief Delete a key with subkeys of a given printer.
329  *
330  * @param[in]  mem_ctx  The talloc memory context to use.
331  *
332  * @param[in]  server_info The server supplied session info.
333  *
334  * @param[in]  printer  The printer name.
335  *
336  * @param[in]  key      The key of the printer to delete.
337  *
338  * @return              On success WERR_OK, a corresponding DOS error is
339  *                      something went wrong.
340  */
341 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
342                                  struct auth_serversupplied_info *server_info,
343                                  struct messaging_context *msg_ctx,
344                                  const char *printer,
345                                  const char *key);
346
347 /**
348  * @brief Update the ChangeID of a printer.
349  *
350  * The ChangeID **must** be increasing over the lifetime of client's spoolss
351  * service in order for the client's cache to show updates.
352  *
353  * If a form is updated of a printer, the we need to update the ChangeID of the
354  * pritner.
355  *
356  * @param[in]  mem_ctx  The talloc memory context to use.
357  *
358  * @param[in]  server_info The server supplied session info.
359  *
360  * @param[in]  printer  The printer name.
361  *
362  * @return              On success WERR_OK, a corresponding DOS error is
363  *                      something went wrong.
364  */
365 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
366                                       struct auth_serversupplied_info *server_info,
367                                       struct messaging_context *msg_ctx,
368                                       const char *printer);
369
370 /**
371  * @brief Get the ChangeID of the given printer.
372  *
373  * @param[in]  mem_ctx  The talloc memory context to use.
374  *
375  * @param[in]  server_info The server supplied session info.
376  *
377  * @param[in]  printer  The printer name.
378  *
379  * @param[in]  changeid A pointer to store the changeid.
380  *
381  * @return              On success WERR_OK, a corresponding DOS error is
382  *                      something went wrong.
383  */
384 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
385                                    struct auth_serversupplied_info *server_info,
386                                    struct messaging_context *msg_ctx,
387                                    const char *printer,
388                                    uint32_t *pchangeid);
389
390 /**
391  * @internal
392  *
393  * @brief This function adds a form to the list of available forms that can be
394  * selected for the specified printer.
395  *
396  * @param[in]  mem_ctx  The talloc memory context to use.
397  *
398  * @param[in]  server_info The server supplied session info.
399  *
400  * @param[in]  form     The form to add.
401  *
402  * @return              WERR_OK on success.
403  *                      WERR_ALREADY_EXISTS if the form already exists or is a
404  *                                          builtin form.
405  *                      A corresponding DOS error is something went wrong.
406  */
407 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
408                                struct auth_serversupplied_info *server_info,
409                                struct messaging_context *msg_ctx,
410                                struct spoolss_AddFormInfo1 *form);
411
412 /*
413  * @brief This function enumerates the forms supported by the specified printer.
414  *
415  * @param[in]  mem_ctx  The talloc memory context to use.
416  *
417  * @param[in]  server_info The server supplied session info.
418  *
419  * @param[out] pnum_info A pointer to store the FormInfo count.
420  *
421  * @param[out] pinfo     A pointer to store an array with FormInfo.
422  *
423  * @return              On success WERR_OK, a corresponding DOS error is
424  *                      something went wrong.
425  */
426 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
427                                  struct auth_serversupplied_info *server_info,
428                                  struct messaging_context *msg_ctx,
429                                  uint32_t *pnum_info,
430                                  union spoolss_FormInfo **pinfo);
431
432 /**
433  * @brief This function removes a form name from the list of supported forms.
434  *
435  * @param[in]  mem_ctx  The talloc memory context to use.
436  *
437  * @param[in]  server_info The server supplied session info.
438  *
439  * @param[in]  form_name The name of the form to delete.
440  *
441  * @return              WERR_OK on success.
442  *                      WERR_INVALID_PARAM if the form is a builtin form.
443  *                      WERR_INVALID_FORM_NAME if the form or key doesn't exist.
444  *                      A corresponding DOS error is something went wrong.
445  */
446 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
447                                   struct auth_serversupplied_info *server_info,
448                                   struct messaging_context *msg_ctx,
449                                   const char *form_name);
450
451 /**
452  * @brief This function sets the form information for the specified printer.
453  *
454  * If one provides both the name in the API call and inside the FormInfo
455  * structure, then the form gets renamed.
456  *
457  * @param[in]  mem_ctx  The talloc memory context to use.
458  *
459  * @param[in]  server_info The server supplied session info.
460  *
461  * @param[in]  form_name The name of the form to set or rename.
462  *
463  * @param[in]  form     The FormInfo structure to save.
464  *
465  * @return              WERR_OK on success.
466  *                      WERR_INVALID_PARAM if the form is a builtin form.
467  *                      A corresponding DOS error is something went wrong.
468  */
469 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
470                                struct auth_serversupplied_info *server_info,
471                                const char *form_name,
472                                struct spoolss_AddFormInfo1 *form);
473
474 /**
475  * @brief This function retrieves information about a specified form.
476  *
477  * @param[in]  mem_ctx  The talloc memory context to use.
478  *
479  * @param[in]  server_info The server supplied session info.
480  *
481  * @param[in]  form_name The name of the form to query.
482  *
483  * @param[out] form     A pointer to a form structure to fill out.
484  *
485  * @return              On success WERR_OK, a corresponding DOS error is
486  *                      something went wrong.
487  */
488 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
489                                struct auth_serversupplied_info *server_info,
490                                const char *form_name,
491                                struct spoolss_FormInfo1 *form);
492
493 /**
494  * @brief This function adds a new spool driver
495  *
496  * @param[in]  mem_ctx         A talloc memory context.
497  *
498  * @param[in]  server_info     Auth info to open the pipe.
499  *
500  * @param[in]  r               The structure containing the new driver data.
501  *
502  * @param[out] driver_name     Returns the driver name.
503  *
504  * @param[out] driver_version  Returns the driver version.
505  *
506  * @return              On success WERR_OK, a corresponding DOS error is
507  *                      something went wrong.
508  */
509 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
510                          struct auth_serversupplied_info *server_info,
511                          struct spoolss_AddDriverInfoCtr *r,
512                          const char **driver_name,
513                          uint32_t *driver_version);
514
515 /**
516  * @brief This function gets printer driver information
517  *
518  * @param[in]  mem_ctx         A talloc memory context.
519  *
520  * @param[in]  server_info     Auth info to open the pipe.
521  *
522  * @param[in]  architecture    The architecture type.
523  *
524  * @param[in]  driver_name     The driver name.
525  *
526  * @param[in]  driver_version  The driver version.
527  *
528  * @param[out] _info8   The structure that holds the full driver information.
529  *
530  * @return              On success WERR_OK, a corresponding DOS error is
531  *                      something went wrong.
532  */
533
534 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
535                          struct auth_serversupplied_info *server_info,
536                          const char *architecture,
537                          const char *driver_name,
538                          uint32_t driver_version,
539                          struct spoolss_DriverInfo8 **_info8);
540
541 /**
542  * @brief This function deletes a printer driver information
543  *
544  * @param[in]  mem_ctx         A talloc memory context.
545  *
546  * @param[in]  server_info     Auth info to open the pipe.
547  *
548  * @param[out] info8    The structure that holds the full driver information.
549  *
550  * @param[in]  version  The driver type version.
551  *
552  * @return              On success WERR_OK, a corresponding DOS error is
553  *                      something went wrong.
554  */
555
556 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
557                          struct auth_serversupplied_info *server_info,
558                          struct spoolss_DriverInfo8 *info8,
559                          uint32_t version);
560
561 /**
562  * @brief This function gets printer drivers list for the specified
563  *        architecture and type version
564  *
565  * @param[in]  mem_ctx         A talloc memory context.
566  *
567  * @param[in]  server_info     Auth info to open the pipe.
568  *
569  * @param[in]  architecture    The architecture type.
570  *
571  * @param[in]  version         The driver version.
572  *
573  * @param[out] num_drivers     The number of drivers.
574  *
575  * @param[out] version         The drivers names.
576  *
577  * @return              On success WERR_OK, a corresponding DOS error is
578  *                      something went wrong.
579  */
580
581 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
582                               struct auth_serversupplied_info *server_info,
583                               const char *architecture,
584                               uint32_t version,
585                               uint32_t *num_drivers,
586                               const char ***drivers);
587
588 #endif /* _SRV_SPOOLSS_UITL_H */