743ad5ca04d0ab15dbbef5843c68abfa1ab8799c
[metze/samba/wip.git] / source3 / rpc_server / spoolss / srv_spoolss_util.c
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 #include "includes.h"
23 #include "rpc_server/rpc_ncacn_np.h"
24 #include "../lib/tsocket/tsocket.h"
25 #include "../librpc/gen_ndr/ndr_spoolss.h"
26 #include "../librpc/gen_ndr/ndr_winreg.h"
27 #include "srv_spoolss_util.h"
28 #include "rpc_client/cli_winreg_spoolss.h"
29
30 WERROR winreg_printer_binding_handle(TALLOC_CTX *mem_ctx,
31                                      const struct auth_session_info *session_info,
32                                      struct messaging_context *msg_ctx,
33                                      struct dcerpc_binding_handle **winreg_binding_handle)
34 {
35         struct tsocket_address *local;
36         NTSTATUS status;
37         int rc;
38
39         rc = tsocket_address_inet_from_strings(mem_ctx,
40                                                "ip",
41                                                "127.0.0.1",
42                                                0,
43                                                &local);
44         if (rc < 0) {
45                 return WERR_NOT_ENOUGH_MEMORY;
46         }
47
48         status = rpcint_binding_handle(mem_ctx,
49                                        &ndr_table_winreg,
50                                        local,
51                                        NULL,
52                                        session_info,
53                                        msg_ctx,
54                                        winreg_binding_handle);
55         talloc_free(local);
56         if (!NT_STATUS_IS_OK(status)) {
57                 DEBUG(0, ("winreg_printer_binding_handle: Could not connect to winreg pipe: %s\n",
58                           nt_errstr(status)));
59                 return ntstatus_to_werror(status);
60         }
61
62         return WERR_OK;
63 }
64
65 WERROR winreg_delete_printer_key_internal(TALLOC_CTX *mem_ctx,
66                                           const struct auth_session_info *session_info,
67                                           struct messaging_context *msg_ctx,
68                                           const char *printer,
69                                           const char *key)
70 {
71         WERROR result;
72         struct dcerpc_binding_handle *b;
73         TALLOC_CTX *tmp_ctx;
74
75         tmp_ctx = talloc_stackframe();
76         if (tmp_ctx == NULL) {
77                 return WERR_NOT_ENOUGH_MEMORY;
78         }
79
80         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
81         if (!W_ERROR_IS_OK(result)) {
82                 talloc_free(tmp_ctx);
83                 return result;
84         }
85
86         result = winreg_delete_printer_key(tmp_ctx,
87                                            b,
88                                            printer,
89                                            key);
90
91         talloc_free(tmp_ctx);
92         return result;
93 }
94
95 WERROR winreg_printer_update_changeid_internal(TALLOC_CTX *mem_ctx,
96                                                const struct auth_session_info *session_info,
97                                                struct messaging_context *msg_ctx,
98                                                const char *printer)
99 {
100         WERROR result;
101         struct dcerpc_binding_handle *b;
102         TALLOC_CTX *tmp_ctx;
103
104         tmp_ctx = talloc_stackframe();
105         if (tmp_ctx == NULL) {
106                 return WERR_NOT_ENOUGH_MEMORY;
107         }
108
109         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
110         if (!W_ERROR_IS_OK(result)) {
111                 talloc_free(tmp_ctx);
112                 return result;
113         }
114
115         result = winreg_printer_update_changeid(mem_ctx,
116                                                 b,
117                                                 printer);
118
119         talloc_free(tmp_ctx);
120         return result;
121 }
122
123 WERROR winreg_printer_get_changeid_internal(TALLOC_CTX *mem_ctx,
124                                             const struct auth_session_info *session_info,
125                                             struct messaging_context *msg_ctx,
126                                             const char *printer,
127                                             uint32_t *pchangeid)
128 {
129         WERROR result;
130         struct dcerpc_binding_handle *b;
131         TALLOC_CTX *tmp_ctx;
132
133         tmp_ctx = talloc_stackframe();
134         if (tmp_ctx == NULL) {
135                 return WERR_NOT_ENOUGH_MEMORY;
136         }
137
138         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
139         if (!W_ERROR_IS_OK(result)) {
140                 talloc_free(tmp_ctx);
141                 return result;
142         }
143
144         result = winreg_printer_get_changeid(mem_ctx,
145                                              b,
146                                              printer,
147                                              pchangeid);
148
149         talloc_free(tmp_ctx);
150         return result;
151 }
152
153 WERROR winreg_get_printer_internal(TALLOC_CTX *mem_ctx,
154                                    const struct auth_session_info *session_info,
155                                    struct messaging_context *msg_ctx,
156                                    const char *printer,
157                                    struct spoolss_PrinterInfo2 **pinfo2)
158 {
159         WERROR result;
160         struct dcerpc_binding_handle *b;
161         TALLOC_CTX *tmp_ctx;
162
163         tmp_ctx = talloc_stackframe();
164         if (tmp_ctx == NULL) {
165                 return WERR_NOT_ENOUGH_MEMORY;
166         }
167
168         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
169         if (!W_ERROR_IS_OK(result)) {
170                 talloc_free(tmp_ctx);
171                 return result;
172         }
173
174         result = winreg_get_printer(mem_ctx,
175                                     b,
176                                     printer,
177                                     pinfo2);
178
179         talloc_free(tmp_ctx);
180         return result;
181 }
182
183 WERROR winreg_create_printer_internal(TALLOC_CTX *mem_ctx,
184                                       const struct auth_session_info *session_info,
185                                       struct messaging_context *msg_ctx,
186                                       const char *sharename)
187 {
188         WERROR result;
189         struct dcerpc_binding_handle *b;
190         TALLOC_CTX *tmp_ctx;
191
192         tmp_ctx = talloc_stackframe();
193         if (tmp_ctx == NULL) {
194                 return WERR_NOT_ENOUGH_MEMORY;
195         }
196
197         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
198         if (!W_ERROR_IS_OK(result)) {
199                 talloc_free(tmp_ctx);
200                 return result;
201         }
202
203         result = winreg_create_printer(mem_ctx,
204                                        b,
205                                        sharename);
206
207         talloc_free(tmp_ctx);
208         return result;
209 }
210
211 WERROR winreg_update_printer_internal(TALLOC_CTX *mem_ctx,
212                                       const struct auth_session_info *session_info,
213                                       struct messaging_context *msg_ctx,
214                                       const char *sharename,
215                                       uint32_t info2_mask,
216                                       struct spoolss_SetPrinterInfo2 *info2,
217                                       struct spoolss_DeviceMode *devmode,
218                                       struct security_descriptor *secdesc)
219 {
220         WERROR result;
221         struct dcerpc_binding_handle *b;
222         TALLOC_CTX *tmp_ctx;
223
224         tmp_ctx = talloc_stackframe();
225         if (tmp_ctx == NULL) {
226                 return WERR_NOT_ENOUGH_MEMORY;
227         }
228
229         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
230         if (!W_ERROR_IS_OK(result)) {
231                 talloc_free(tmp_ctx);
232                 return result;
233         }
234
235         result = winreg_update_printer(mem_ctx,
236                                        b,
237                                        sharename,
238                                        info2_mask,
239                                        info2,
240                                        devmode,
241                                        secdesc);
242
243         talloc_free(tmp_ctx);
244         return result;
245 }
246
247 WERROR winreg_set_printer_dataex_internal(TALLOC_CTX *mem_ctx,
248                                           const struct auth_session_info *session_info,
249                                           struct messaging_context *msg_ctx,
250                                           const char *printer,
251                                           const char *key,
252                                           const char *value,
253                                           enum winreg_Type type,
254                                           uint8_t *data,
255                                           uint32_t data_size)
256 {
257         WERROR result;
258         struct dcerpc_binding_handle *b;
259         TALLOC_CTX *tmp_ctx;
260
261         tmp_ctx = talloc_stackframe();
262         if (tmp_ctx == NULL) {
263                 return WERR_NOT_ENOUGH_MEMORY;
264         }
265
266         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
267         if (!W_ERROR_IS_OK(result)) {
268                 talloc_free(tmp_ctx);
269                 return result;
270         }
271
272         result = winreg_set_printer_dataex(mem_ctx,
273                                            b,
274                                            printer,
275                                            key,
276                                            value,
277                                            type,
278                                            data,
279                                            data_size);
280
281         talloc_free(tmp_ctx);
282         return result;
283 }
284
285 WERROR winreg_enum_printer_dataex_internal(TALLOC_CTX *mem_ctx,
286                                            const struct auth_session_info *session_info,
287                                            struct messaging_context *msg_ctx,
288                                            const char *printer,
289                                            const char *key,
290                                            uint32_t *pnum_values,
291                                            struct spoolss_PrinterEnumValues **penum_values)
292 {
293         WERROR result;
294         struct dcerpc_binding_handle *b;
295         TALLOC_CTX *tmp_ctx;
296
297         tmp_ctx = talloc_stackframe();
298         if (tmp_ctx == NULL) {
299                 return WERR_NOT_ENOUGH_MEMORY;
300         }
301
302         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
303         if (!W_ERROR_IS_OK(result)) {
304                 talloc_free(tmp_ctx);
305                 return result;
306         }
307
308         result = winreg_enum_printer_dataex(mem_ctx,
309                                             b,
310                                             printer,
311                                             key,
312                                             pnum_values,
313                                             penum_values);
314
315         talloc_free(tmp_ctx);
316         return result;
317 }
318
319 WERROR winreg_get_printer_dataex_internal(TALLOC_CTX *mem_ctx,
320                                           const struct auth_session_info *session_info,
321                                           struct messaging_context *msg_ctx,
322                                           const char *printer,
323                                           const char *key,
324                                           const char *value,
325                                           enum winreg_Type *type,
326                                           uint8_t **data,
327                                           uint32_t *data_size)
328 {
329         WERROR result;
330         struct dcerpc_binding_handle *b;
331         TALLOC_CTX *tmp_ctx;
332
333         tmp_ctx = talloc_stackframe();
334         if (tmp_ctx == NULL) {
335                 return WERR_NOT_ENOUGH_MEMORY;
336         }
337
338         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
339         if (!W_ERROR_IS_OK(result)) {
340                 talloc_free(tmp_ctx);
341                 return result;
342         }
343
344         result = winreg_get_printer_dataex(mem_ctx,
345                                            b,
346                                            printer,
347                                            key,
348                                            value,
349                                            type,
350                                            data,
351                                            data_size);
352
353         talloc_free(tmp_ctx);
354         return result;
355 }
356
357 WERROR winreg_delete_printer_dataex_internal(TALLOC_CTX *mem_ctx,
358                                              const struct auth_session_info *session_info,
359                                              struct messaging_context *msg_ctx,
360                                              const char *printer,
361                                              const char *key,
362                                              const char *value)
363 {
364         WERROR result;
365         struct dcerpc_binding_handle *b;
366         TALLOC_CTX *tmp_ctx;
367
368         tmp_ctx = talloc_stackframe();
369         if (tmp_ctx == NULL) {
370                 return WERR_NOT_ENOUGH_MEMORY;
371         }
372
373         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
374         if (!W_ERROR_IS_OK(result)) {
375                 talloc_free(tmp_ctx);
376                 return result;
377         }
378
379         result = winreg_delete_printer_dataex(mem_ctx,
380                                               b,
381                                               printer,
382                                               key,
383                                               value);
384
385         talloc_free(tmp_ctx);
386         return result;
387 }
388
389 WERROR winreg_get_driver_internal(TALLOC_CTX *mem_ctx,
390                                   const struct auth_session_info *session_info,
391                                   struct messaging_context *msg_ctx,
392                                   const char *architecture,
393                                   const char *driver_name,
394                                   uint32_t driver_version,
395                                   struct spoolss_DriverInfo8 **_info8)
396 {
397         WERROR result;
398         struct dcerpc_binding_handle *b;
399         TALLOC_CTX *tmp_ctx;
400
401         tmp_ctx = talloc_stackframe();
402         if (tmp_ctx == NULL) {
403                 return WERR_NOT_ENOUGH_MEMORY;
404         }
405
406         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
407         if (!W_ERROR_IS_OK(result)) {
408                 talloc_free(tmp_ctx);
409                 return result;
410         }
411
412         result = winreg_get_driver(mem_ctx,
413                                    b,
414                                    architecture,
415                                    driver_name,
416                                    driver_version,
417                                    _info8);
418
419         talloc_free(tmp_ctx);
420         return result;
421 }
422
423 WERROR winreg_get_driver_list_internal(TALLOC_CTX *mem_ctx,
424                                        const struct auth_session_info *session_info,
425                                        struct messaging_context *msg_ctx,
426                                        const char *architecture,
427                                        uint32_t version,
428                                        uint32_t *num_drivers,
429                                        const char ***drivers_p)
430 {
431         WERROR result;
432         struct dcerpc_binding_handle *b;
433         TALLOC_CTX *tmp_ctx;
434
435         tmp_ctx = talloc_stackframe();
436         if (tmp_ctx == NULL) {
437                 return WERR_NOT_ENOUGH_MEMORY;
438         }
439
440         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
441         if (!W_ERROR_IS_OK(result)) {
442                 talloc_free(tmp_ctx);
443                 return result;
444         }
445
446         result = winreg_get_driver_list(mem_ctx,
447                                         b,
448                                         architecture,
449                                         version,
450                                         num_drivers,
451                                         drivers_p);
452
453         talloc_free(tmp_ctx);
454         return result;
455 }
456
457 WERROR winreg_del_driver_internal(TALLOC_CTX *mem_ctx,
458                                   const struct auth_session_info *session_info,
459                                   struct messaging_context *msg_ctx,
460                                   struct spoolss_DriverInfo8 *info8,
461                                   uint32_t version)
462 {
463         WERROR result;
464         struct dcerpc_binding_handle *b;
465         TALLOC_CTX *tmp_ctx;
466
467         tmp_ctx = talloc_stackframe();
468         if (tmp_ctx == NULL) {
469                 return WERR_NOT_ENOUGH_MEMORY;
470         }
471
472         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
473         if (!W_ERROR_IS_OK(result)) {
474                 talloc_free(tmp_ctx);
475                 return result;
476         }
477
478         result = winreg_del_driver(mem_ctx,
479                                    b,
480                                    info8,
481                                    version);
482
483         talloc_free(tmp_ctx);
484         return result;
485 }
486
487 WERROR winreg_add_driver_internal(TALLOC_CTX *mem_ctx,
488                                   const struct auth_session_info *session_info,
489                                   struct messaging_context *msg_ctx,
490                                   struct spoolss_AddDriverInfoCtr *r,
491                                   const char **driver_name,
492                                   uint32_t *driver_version)
493 {
494         WERROR result;
495         struct dcerpc_binding_handle *b;
496         TALLOC_CTX *tmp_ctx;
497
498         tmp_ctx = talloc_stackframe();
499         if (tmp_ctx == NULL) {
500                 return WERR_NOT_ENOUGH_MEMORY;
501         }
502
503         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
504         if (!W_ERROR_IS_OK(result)) {
505                 talloc_free(tmp_ctx);
506                 return result;
507         }
508
509         result = winreg_add_driver(mem_ctx,
510                                    b,
511                                    r,
512                                    driver_name,
513                                    driver_version);
514
515         talloc_free(tmp_ctx);
516         return result;
517 }
518
519 WERROR winreg_get_core_driver_internal(TALLOC_CTX *mem_ctx,
520                                        const struct auth_session_info *session_info,
521                                        struct messaging_context *msg_ctx,
522                                        const char *architecture,
523                                        const struct GUID *core_driver_guid,
524                                        struct spoolss_CorePrinterDriver **core_printer_driver)
525 {
526         WERROR result;
527         struct dcerpc_binding_handle *b;
528         TALLOC_CTX *tmp_ctx;
529
530         tmp_ctx = talloc_stackframe();
531         if (tmp_ctx == NULL) {
532                 return WERR_NOT_ENOUGH_MEMORY;
533         }
534
535         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
536         if (!W_ERROR_IS_OK(result)) {
537                 talloc_free(tmp_ctx);
538                 return result;
539         }
540
541         result = winreg_get_core_driver(mem_ctx,
542                                         b,
543                                         architecture,
544                                         core_driver_guid,
545                                         core_printer_driver);
546
547         talloc_free(tmp_ctx);
548         return result;
549 }
550
551 WERROR winreg_add_core_driver_internal(TALLOC_CTX *mem_ctx,
552                                        const struct auth_session_info *session_info,
553                                        struct messaging_context *msg_ctx,
554                                        const char *architecture,
555                                        const struct spoolss_CorePrinterDriver *core_printer_driver)
556 {
557         WERROR result;
558         struct dcerpc_binding_handle *b;
559         TALLOC_CTX *tmp_ctx;
560
561         tmp_ctx = talloc_stackframe();
562         if (tmp_ctx == NULL) {
563                 return WERR_NOT_ENOUGH_MEMORY;
564         }
565
566         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
567         if (!W_ERROR_IS_OK(result)) {
568                 talloc_free(tmp_ctx);
569                 return result;
570         }
571
572         result = winreg_add_core_driver(mem_ctx,
573                                         b,
574                                         architecture,
575                                         core_printer_driver);
576
577         talloc_free(tmp_ctx);
578         return result;
579 }
580
581 WERROR winreg_get_printer_secdesc_internal(TALLOC_CTX *mem_ctx,
582                                            const struct auth_session_info *session_info,
583                                            struct messaging_context *msg_ctx,
584                                            const char *sharename,
585                                            struct spoolss_security_descriptor **psecdesc)
586 {
587         WERROR result;
588         struct dcerpc_binding_handle *b;
589         TALLOC_CTX *tmp_ctx;
590
591         tmp_ctx = talloc_stackframe();
592         if (tmp_ctx == NULL) {
593                 return WERR_NOT_ENOUGH_MEMORY;
594         }
595
596         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
597         if (!W_ERROR_IS_OK(result)) {
598                 talloc_free(tmp_ctx);
599                 return result;
600         }
601
602         result = winreg_get_printer_secdesc(mem_ctx,
603                                             b,
604                                             sharename,
605                                             psecdesc);
606
607         talloc_free(tmp_ctx);
608         return result;
609 }
610
611 WERROR winreg_set_printer_secdesc_internal(TALLOC_CTX *mem_ctx,
612                                            const struct auth_session_info *session_info,
613                                            struct messaging_context *msg_ctx,
614                                            const char *sharename,
615                                            const struct spoolss_security_descriptor *secdesc)
616 {
617         WERROR result;
618         struct dcerpc_binding_handle *b;
619         TALLOC_CTX *tmp_ctx;
620
621         tmp_ctx = talloc_stackframe();
622         if (tmp_ctx == NULL) {
623                 return WERR_NOT_ENOUGH_MEMORY;
624         }
625
626         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
627         if (!W_ERROR_IS_OK(result)) {
628                 talloc_free(tmp_ctx);
629                 return result;
630         }
631
632         result = winreg_set_printer_secdesc(mem_ctx,
633                                             b,
634                                             sharename,
635                                             secdesc);
636
637         talloc_free(tmp_ctx);
638         return result;
639 }
640
641 WERROR winreg_printer_enumforms1_internal(TALLOC_CTX *mem_ctx,
642                                           const struct auth_session_info *session_info,
643                                           struct messaging_context *msg_ctx,
644                                           uint32_t *pnum_info,
645                                           union spoolss_FormInfo **pinfo)
646 {
647         WERROR result;
648         struct dcerpc_binding_handle *b;
649         TALLOC_CTX *tmp_ctx;
650
651         tmp_ctx = talloc_stackframe();
652         if (tmp_ctx == NULL) {
653                 return WERR_NOT_ENOUGH_MEMORY;
654         }
655
656         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
657         if (!W_ERROR_IS_OK(result)) {
658                 talloc_free(tmp_ctx);
659                 return result;
660         }
661
662         result = winreg_printer_enumforms1(mem_ctx,
663                                            b,
664                                            pnum_info,
665                                            pinfo);
666
667         talloc_free(tmp_ctx);
668         return result;
669 }
670
671 WERROR winreg_printer_getform1_internal(TALLOC_CTX *mem_ctx,
672                                         const struct auth_session_info *session_info,
673                                         struct messaging_context *msg_ctx,
674                                         const char *form_name,
675                                         struct spoolss_FormInfo1 *r)
676 {
677         WERROR result;
678         struct dcerpc_binding_handle *b;
679         TALLOC_CTX *tmp_ctx;
680
681         tmp_ctx = talloc_stackframe();
682         if (tmp_ctx == NULL) {
683                 return WERR_NOT_ENOUGH_MEMORY;
684         }
685
686         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
687         if (!W_ERROR_IS_OK(result)) {
688                 talloc_free(tmp_ctx);
689                 return result;
690         }
691
692         result = winreg_printer_getform1(mem_ctx,
693                                          b,
694                                          form_name,
695                                          r);
696
697         talloc_free(tmp_ctx);
698         return result;
699 }
700
701 WERROR winreg_printer_addform1_internal(TALLOC_CTX *mem_ctx,
702                                         const struct auth_session_info *session_info,
703                                         struct messaging_context *msg_ctx,
704                                         struct spoolss_AddFormInfo1 *form)
705 {
706         WERROR result;
707         struct dcerpc_binding_handle *b;
708         TALLOC_CTX *tmp_ctx;
709
710         tmp_ctx = talloc_stackframe();
711         if (tmp_ctx == NULL) {
712                 return WERR_NOT_ENOUGH_MEMORY;
713         }
714
715         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
716         if (!W_ERROR_IS_OK(result)) {
717                 talloc_free(tmp_ctx);
718                 return result;
719         }
720
721         result = winreg_printer_addform1(mem_ctx,
722                                          b,
723                                          form);
724
725         talloc_free(tmp_ctx);
726         return result;
727 }
728
729 WERROR winreg_printer_setform1_internal(TALLOC_CTX *mem_ctx,
730                                         const struct auth_session_info *session_info,
731                                         struct messaging_context *msg_ctx,
732                                         const char *form_name,
733                                         struct spoolss_AddFormInfo1 *form)
734 {
735         WERROR result;
736         struct dcerpc_binding_handle *b;
737         TALLOC_CTX *tmp_ctx;
738
739         tmp_ctx = talloc_stackframe();
740         if (tmp_ctx == NULL) {
741                 return WERR_NOT_ENOUGH_MEMORY;
742         }
743
744         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
745         if (!W_ERROR_IS_OK(result)) {
746                 talloc_free(tmp_ctx);
747                 return result;
748         }
749
750         result = winreg_printer_setform1(mem_ctx,
751                                          b,
752                                          form_name,
753                                          form);
754
755         talloc_free(tmp_ctx);
756         return result;
757 }
758
759 WERROR winreg_printer_deleteform1_internal(TALLOC_CTX *mem_ctx,
760                                            const struct auth_session_info *session_info,
761                                            struct messaging_context *msg_ctx,
762                                            const char *form_name)
763 {
764         WERROR result;
765         struct dcerpc_binding_handle *b;
766         TALLOC_CTX *tmp_ctx;
767
768         tmp_ctx = talloc_stackframe();
769         if (tmp_ctx == NULL) {
770                 return WERR_NOT_ENOUGH_MEMORY;
771         }
772
773         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
774         if (!W_ERROR_IS_OK(result)) {
775                 talloc_free(tmp_ctx);
776                 return result;
777         }
778
779         result = winreg_printer_deleteform1(mem_ctx,
780                                             b,
781                                             form_name);
782
783         talloc_free(tmp_ctx);
784         return result;
785 }
786
787 WERROR winreg_enum_printer_key_internal(TALLOC_CTX *mem_ctx,
788                                         const struct auth_session_info *session_info,
789                                         struct messaging_context *msg_ctx,
790                                         const char *printer,
791                                         const char *key,
792                                         uint32_t *pnum_subkeys,
793                                         const char ***psubkeys)
794 {
795         WERROR result;
796         struct dcerpc_binding_handle *b;
797         TALLOC_CTX *tmp_ctx;
798
799         tmp_ctx = talloc_stackframe();
800         if (tmp_ctx == NULL) {
801                 return WERR_NOT_ENOUGH_MEMORY;
802         }
803
804         result = winreg_printer_binding_handle(tmp_ctx, session_info, msg_ctx, &b);
805         if (!W_ERROR_IS_OK(result)) {
806                 talloc_free(tmp_ctx);
807                 return result;
808         }
809
810         result = winreg_enum_printer_key(mem_ctx,
811                                          b,
812                                          printer,
813                                          key,
814                                          pnum_subkeys,
815                                          psubkeys);
816
817         talloc_free(tmp_ctx);
818         return result;
819 }