r10504: - seperate implementation specific stuff, from the generic composite
[kai/samba.git] / source4 / winbind / wb_samba3_cmd.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Main winbindd samba3 server routines
4
5    Copyright (C) Stefan Metzmacher      2005
6    Copyright (C) Volker Lendecke        2005
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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "smbd/service_stream.h"
25 #include "nsswitch/winbind_nss_config.h"
26 #include "nsswitch/winbindd_nss.h"
27 #include "winbind/wb_server.h"
28 #include "winbind/wb_samba3_protocol.h"
29 #include "winbind/wb_async_helpers.h"
30 #include "librpc/gen_ndr/nbt.h"
31 #include "libcli/raw/libcliraw.h"
32 #include "libcli/composite/composite.h"
33
34 NTSTATUS wbsrv_samba3_interface_version(struct wbsrv_samba3_call *s3call)
35 {
36         s3call->response.result                 = WINBINDD_OK;
37         s3call->response.data.interface_version = WINBIND_INTERFACE_VERSION;
38         return NT_STATUS_OK;
39 }
40
41 NTSTATUS wbsrv_samba3_priv_pipe_dir(struct wbsrv_samba3_call *s3call)
42 {
43         s3call->response.result                 = WINBINDD_OK;
44         s3call->response.extra_data             = smbd_tmp_path(s3call,
45                                                   WINBINDD_SAMBA3_PRIVILEGED_SOCKET);
46         NT_STATUS_HAVE_NO_MEMORY(s3call->response.extra_data);
47         return NT_STATUS_OK;
48 }
49
50 NTSTATUS wbsrv_samba3_ping(struct wbsrv_samba3_call *s3call)
51 {
52         s3call->response.result                 = WINBINDD_OK;
53         return NT_STATUS_OK;
54 }
55
56 struct check_machacc_state {
57         struct wb_finddcs *io;
58 };
59
60 static void wbsrv_samba3_check_machacc_reply(struct composite_context *action)
61 {
62         struct wbsrv_samba3_call *s3call =
63                 talloc_get_type(action->async.private_data,
64                                 struct wbsrv_samba3_call);
65         struct check_machacc_state *state =
66                 talloc_get_type(s3call->private_data,
67                                 struct check_machacc_state);
68         NTSTATUS status;
69
70         status = wb_finddcs_recv(action, s3call);
71         if (NT_STATUS_IS_OK(status)) {
72                 DEBUG(10, ("Got name %s\n", state->io->out.dcs[0].name));
73                 s3call->response.result = WINBINDD_OK;
74         } else {
75                 DEBUG(10, ("Got no addr: %s\n", nt_errstr(status)));
76                 s3call->response.result = WINBINDD_ERROR;
77         }
78
79         status = wbsrv_send_reply(s3call->call);
80         if (!NT_STATUS_IS_OK(status)) {
81                 wbsrv_terminate_connection(s3call->call->wbconn,
82                                            "wbsrv_queue_reply() failed");
83                 return;
84         }
85 }
86
87 NTSTATUS wbsrv_samba3_check_machacc(struct wbsrv_samba3_call *s3call)
88 {
89         struct composite_context *resolve_req;
90         struct check_machacc_state *state;
91
92         DEBUG(5, ("check_machacc called\n"));
93
94         state = talloc(s3call, struct check_machacc_state);
95         NT_STATUS_HAVE_NO_MEMORY(state);
96
97         state->io = talloc(s3call, struct wb_finddcs);
98         NT_STATUS_HAVE_NO_MEMORY(state->io);
99         s3call->private_data = state;
100
101         state->io->in.msg_ctx = s3call->call->wbconn->conn->msg_ctx;
102         state->io->in.domain = lp_workgroup();
103
104         resolve_req = wb_finddcs_send(state->io, s3call->call->event_ctx);
105         NT_STATUS_HAVE_NO_MEMORY(resolve_req);
106
107         /* setup the callbacks */
108         resolve_req->async.fn           = wbsrv_samba3_check_machacc_reply;
109         resolve_req->async.private_data = s3call;
110
111         /* tell the caller we reply later */
112         s3call->call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
113         return NT_STATUS_OK;
114 }