r10508: - implement WINBINDD_NETBIOS_NAME, WINBINDD_DOMAIN_NAME and WINBINDD_INFO
[jelmer/samba4-debian.git] / source / 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 #include "include/version.h"
34
35 NTSTATUS wbsrv_samba3_interface_version(struct wbsrv_samba3_call *s3call)
36 {
37         s3call->response.result                 = WINBINDD_OK;
38         s3call->response.data.interface_version = WINBIND_INTERFACE_VERSION;
39         return NT_STATUS_OK;
40 }
41
42 NTSTATUS wbsrv_samba3_info(struct wbsrv_samba3_call *s3call)
43 {
44         s3call->response.result                 = WINBINDD_OK;
45         s3call->response.data.info.winbind_separator = *lp_winbind_separator();
46         WBSRV_SAMBA3_SET_STRING(s3call->response.data.info.samba_version, SAMBA_VERSION_STRING);
47         return NT_STATUS_OK;
48 }
49
50 NTSTATUS wbsrv_samba3_domain_name(struct wbsrv_samba3_call *s3call)
51 {
52         s3call->response.result                 = WINBINDD_OK;
53         WBSRV_SAMBA3_SET_STRING(s3call->response.data.domain_name, lp_workgroup());
54         return NT_STATUS_OK;
55 }
56
57 NTSTATUS wbsrv_samba3_netbios_name(struct wbsrv_samba3_call *s3call)
58 {
59         s3call->response.result                 = WINBINDD_OK;
60         WBSRV_SAMBA3_SET_STRING(s3call->response.data.netbios_name, lp_netbios_name());
61         return NT_STATUS_OK;
62 }
63
64 NTSTATUS wbsrv_samba3_priv_pipe_dir(struct wbsrv_samba3_call *s3call)
65 {
66         s3call->response.result                 = WINBINDD_OK;
67         s3call->response.extra_data             = smbd_tmp_path(s3call,
68                                                   WINBINDD_SAMBA3_PRIVILEGED_SOCKET);
69         NT_STATUS_HAVE_NO_MEMORY(s3call->response.extra_data);
70         return NT_STATUS_OK;
71 }
72
73 NTSTATUS wbsrv_samba3_ping(struct wbsrv_samba3_call *s3call)
74 {
75         s3call->response.result                 = WINBINDD_OK;
76         return NT_STATUS_OK;
77 }
78
79 struct check_machacc_state {
80         struct wb_finddcs *io;
81 };
82
83 static void wbsrv_samba3_check_machacc_reply(struct composite_context *action)
84 {
85         struct wbsrv_samba3_call *s3call =
86                 talloc_get_type(action->async.private_data,
87                                 struct wbsrv_samba3_call);
88         struct check_machacc_state *state =
89                 talloc_get_type(s3call->private_data,
90                                 struct check_machacc_state);
91         NTSTATUS status;
92
93         status = wb_finddcs_recv(action, s3call);
94
95         s3call->response.data.auth.nt_status = NT_STATUS_V(status);
96         WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.nt_status_string, nt_errstr(status));
97         WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.error_string, nt_errstr(status));
98         s3call->response.data.auth.pam_error = nt_status_to_pam(status);
99
100         if (NT_STATUS_IS_OK(status)) {
101                 DEBUG(10, ("Got name %s\n", state->io->out.dcs[0].name));
102                 s3call->response.result = WINBINDD_OK;
103         } else {
104                 DEBUG(10, ("Got no addr: %s\n", nt_errstr(status)));
105                 s3call->response.result = WINBINDD_ERROR;
106         }
107
108         status = wbsrv_send_reply(s3call->call);
109         if (!NT_STATUS_IS_OK(status)) {
110                 wbsrv_terminate_connection(s3call->call->wbconn,
111                                            "wbsrv_queue_reply() failed");
112                 return;
113         }
114 }
115
116 NTSTATUS wbsrv_samba3_check_machacc(struct wbsrv_samba3_call *s3call)
117 {
118         struct composite_context *resolve_req;
119         struct check_machacc_state *state;
120
121         DEBUG(5, ("check_machacc called\n"));
122
123         state = talloc(s3call, struct check_machacc_state);
124         NT_STATUS_HAVE_NO_MEMORY(state);
125
126         state->io = talloc(s3call, struct wb_finddcs);
127         NT_STATUS_HAVE_NO_MEMORY(state->io);
128         s3call->private_data = state;
129
130         state->io->in.msg_ctx = s3call->call->wbconn->conn->msg_ctx;
131         state->io->in.domain = lp_workgroup();
132
133         resolve_req = wb_finddcs_send(state->io, s3call->call->event_ctx);
134         NT_STATUS_HAVE_NO_MEMORY(resolve_req);
135
136         /* setup the callbacks */
137         resolve_req->async.fn           = wbsrv_samba3_check_machacc_reply;
138         resolve_req->async.private_data = s3call;
139
140         /* tell the caller we reply later */
141         s3call->call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
142         return NT_STATUS_OK;
143 }