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