s3-printing: add winreg_printer_binding_handle and remove most of srv_spoolss_util.c.
[rusty/samba.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 "srv_spoolss_util.h"
24 #include "rpc_server/rpc_ncacn_np.h"
25 #include "../lib/tsocket/tsocket.h"
26 #include "../librpc/gen_ndr/ndr_winreg.h"
27
28 WERROR winreg_printer_binding_handle(TALLOC_CTX *mem_ctx,
29                                      const struct auth_serversupplied_info *session_info,
30                                      struct messaging_context *msg_ctx,
31                                      struct dcerpc_binding_handle **winreg_binding_handle)
32 {
33         struct tsocket_address *local;
34         NTSTATUS status;
35         int rc;
36
37         rc = tsocket_address_inet_from_strings(mem_ctx,
38                                                "ip",
39                                                "127.0.0.1",
40                                                0,
41                                                &local);
42         if (rc < 0) {
43                 return WERR_NOMEM;
44         }
45
46         status = rpcint_binding_handle(mem_ctx,
47                                        &ndr_table_winreg,
48                                        local,
49                                        session_info,
50                                        msg_ctx,
51                                        winreg_binding_handle);
52         if (!NT_STATUS_IS_OK(status)) {
53                 DEBUG(0, ("winreg_printer_binding_handle: Could not connect to winreg pipe: %s\n",
54                           nt_errstr(status)));
55                 return ntstatus_to_werror(status);
56         }
57
58         return WERR_OK;
59 }