Change smbd_aio_complete_mid() -> smbd_aio_complete_aio_ex(). Simplifies
[Samba/ekacnet.git] / source4 / winbind / wb_samba3_protocol.c
blob8d0127ba04fa94f6d4f51ecb88d9fb9a89907dfe
1 /*
2 Unix SMB/CIFS implementation.
3 Main winbindd samba3 server routines
5 Copyright (C) Stefan Metzmacher 2005
6 Copyright (C) Volker Lendecke 2005
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.
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.
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/>.
22 #include "includes.h"
23 #include "winbind/wb_server.h"
24 #include "smbd/service_stream.h"
25 #include "lib/stream/packet.h"
26 #include "lib/tsocket/tsocket.h"
29 work out if a packet is complete for protocols that use a 32 bit host byte
30 order length
32 NTSTATUS wbsrv_samba3_packet_full_request(void *private_data, DATA_BLOB blob, size_t *size)
34 uint32_t *len;
35 if (blob.length < 4) {
36 return STATUS_MORE_ENTRIES;
38 len = (uint32_t *)blob.data;
39 *size = (*len);
40 if (*size > blob.length) {
41 return STATUS_MORE_ENTRIES;
43 return NT_STATUS_OK;
47 NTSTATUS wbsrv_samba3_pull_request(struct wbsrv_samba3_call *call)
49 if (call->in.length != sizeof(*call->request)) {
50 DEBUG(0,("wbsrv_samba3_pull_request: invalid blob length %lu should be %lu\n"
51 " make sure you use the correct winbind client tools!\n",
52 (long)call->in.length, (long)sizeof(*call->request)));
53 return NT_STATUS_INVALID_PARAMETER;
56 call->request = talloc_zero(call, struct winbindd_request);
57 NT_STATUS_HAVE_NO_MEMORY(call->request);
59 /* the packet layout is the same as the in memory layout of the request, so just copy it */
60 memcpy(call->request, call->in.data, sizeof(*call->request));
62 return NT_STATUS_OK;
65 NTSTATUS wbsrv_samba3_handle_call(struct wbsrv_samba3_call *s3call)
67 DEBUG(10, ("Got winbind samba3 request %d\n", s3call->request->cmd));
69 s3call->response = talloc_zero(s3call, struct winbindd_response);
70 NT_STATUS_HAVE_NO_MEMORY(s3call->request);
72 s3call->response->length = sizeof(*s3call->response);
74 switch(s3call->request->cmd) {
75 case WINBINDD_INTERFACE_VERSION:
76 return wbsrv_samba3_interface_version(s3call);
78 case WINBINDD_CHECK_MACHACC:
79 return wbsrv_samba3_check_machacc(s3call);
81 case WINBINDD_PING:
82 return wbsrv_samba3_ping(s3call);
84 case WINBINDD_INFO:
85 return wbsrv_samba3_info(s3call);
87 case WINBINDD_DOMAIN_NAME:
88 return wbsrv_samba3_domain_name(s3call);
90 case WINBINDD_NETBIOS_NAME:
91 return wbsrv_samba3_netbios_name(s3call);
93 case WINBINDD_PRIV_PIPE_DIR:
94 return wbsrv_samba3_priv_pipe_dir(s3call);
96 case WINBINDD_LOOKUPNAME:
97 return wbsrv_samba3_lookupname(s3call);
99 case WINBINDD_LOOKUPSID:
100 return wbsrv_samba3_lookupsid(s3call);
102 case WINBINDD_PAM_AUTH:
103 return wbsrv_samba3_pam_auth(s3call);
105 case WINBINDD_PAM_AUTH_CRAP:
106 return wbsrv_samba3_pam_auth_crap(s3call);
108 case WINBINDD_GETDCNAME:
109 return wbsrv_samba3_getdcname(s3call);
111 case WINBINDD_GETUSERDOMGROUPS:
112 return wbsrv_samba3_userdomgroups(s3call);
114 case WINBINDD_GETUSERSIDS:
115 return wbsrv_samba3_usersids(s3call);
117 case WINBINDD_LIST_GROUPS:
118 return wbsrv_samba3_list_groups(s3call);
120 case WINBINDD_LIST_TRUSTDOM:
121 return wbsrv_samba3_list_trustdom(s3call);
123 case WINBINDD_LIST_USERS:
124 return wbsrv_samba3_list_users(s3call);
126 case WINBINDD_GETPWNAM:
127 return wbsrv_samba3_getpwnam(s3call);
129 case WINBINDD_GETPWUID:
130 return wbsrv_samba3_getpwuid(s3call);
132 case WINBINDD_SETPWENT:
133 return wbsrv_samba3_setpwent(s3call);
135 case WINBINDD_GETPWENT:
136 return wbsrv_samba3_getpwent(s3call);
138 case WINBINDD_ENDPWENT:
139 return wbsrv_samba3_endpwent(s3call);
141 case WINBINDD_GETGRNAM:
142 return wbsrv_samba3_getgrnam(s3call);
144 case WINBINDD_GETGRGID:
145 return wbsrv_samba3_getgrgid(s3call);
147 case WINBINDD_GETGROUPS:
148 return wbsrv_samba3_getgroups(s3call);
150 case WINBINDD_SETGRENT:
151 return wbsrv_samba3_setgrent(s3call);
153 case WINBINDD_GETGRENT:
154 return wbsrv_samba3_getgrent(s3call);
156 case WINBINDD_ENDGRENT:
157 return wbsrv_samba3_endgrent(s3call);
159 case WINBINDD_SID_TO_UID:
160 case WINBINDD_DUAL_SID2UID:
161 return wbsrv_samba3_sid2uid(s3call);
163 case WINBINDD_SID_TO_GID:
164 case WINBINDD_DUAL_SID2GID:
165 return wbsrv_samba3_sid2gid(s3call);
167 case WINBINDD_UID_TO_SID:
168 case WINBINDD_DUAL_UID2SID:
169 return wbsrv_samba3_uid2sid(s3call);
171 case WINBINDD_GID_TO_SID:
172 case WINBINDD_DUAL_GID2SID:
173 return wbsrv_samba3_gid2sid(s3call);
175 case WINBINDD_DOMAIN_INFO:
176 return wbsrv_samba3_domain_info(s3call);
178 case WINBINDD_PAM_LOGOFF:
179 return wbsrv_samba3_pam_logoff(s3call);
181 /* Unimplemented commands */
182 case WINBINDD_GETPWSID:
183 case WINBINDD_PAM_CHAUTHTOK:
184 case WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP:
185 case WINBINDD_LOOKUPRIDS:
186 case WINBINDD_SIDS_TO_XIDS:
187 case WINBINDD_ALLOCATE_UID:
188 case WINBINDD_ALLOCATE_GID:
189 case WINBINDD_SET_MAPPING:
190 case WINBINDD_REMOVE_MAPPING:
191 case WINBINDD_SET_HWM:
192 case WINBINDD_SHOW_SEQUENCE:
193 case WINBINDD_WINS_BYIP:
194 case WINBINDD_WINS_BYNAME:
195 case WINBINDD_GETGRLST:
196 case WINBINDD_GETSIDALIASES:
197 case WINBINDD_DSGETDCNAME:
198 case WINBINDD_INIT_CONNECTION:
199 case WINBINDD_DUAL_SIDS2XIDS:
200 case WINBINDD_DUAL_SET_MAPPING:
201 case WINBINDD_DUAL_REMOVE_MAPPING:
202 case WINBINDD_DUAL_SET_HWM:
203 case WINBINDD_DUAL_USERINFO:
204 case WINBINDD_DUAL_GETSIDALIASES:
205 case WINBINDD_DUAL_NDRCMD:
206 case WINBINDD_CCACHE_NTLMAUTH:
207 case WINBINDD_NUM_CMDS:
208 DEBUG(10, ("Unimplemented winbind samba3 request %d\n",
209 s3call->request->cmd));
210 break;
213 s3call->response->result = WINBINDD_ERROR;
214 return NT_STATUS_OK;
217 static NTSTATUS wbsrv_samba3_push_reply(struct wbsrv_samba3_call *call)
219 uint8_t *extra_data;
220 size_t extra_data_len = 0;
222 extra_data = (uint8_t *)call->response->extra_data.data;
223 if (extra_data != NULL) {
224 extra_data_len = call->response->length -
225 sizeof(*call->response);
228 call->out = data_blob_talloc(call, NULL, call->response->length);
229 NT_STATUS_HAVE_NO_MEMORY(call->out.data);
231 /* don't push real pointer values into sockets */
232 if (extra_data) {
233 call->response->extra_data.data = (void *)0xFFFFFFFF;
236 memcpy(call->out.data, call->response, sizeof(*call->response));
237 /* set back the pointer */
238 call->response->extra_data.data = extra_data;
240 if (extra_data) {
241 memcpy(call->out.data + sizeof(*call->response),
242 extra_data,
243 extra_data_len);
246 return NT_STATUS_OK;
249 static void wbsrv_samba3_send_reply_done(struct tevent_req *subreq);
252 * queue a wbsrv_call reply on a wbsrv_connection
253 * NOTE: that this implies talloc_free(call),
254 * use talloc_reference(call) if you need it after
255 * calling wbsrv_queue_reply
257 NTSTATUS wbsrv_samba3_send_reply(struct wbsrv_samba3_call *call)
259 struct wbsrv_connection *wbsrv_conn = call->wbconn;
260 struct tevent_req *subreq;
261 NTSTATUS status;
263 status = wbsrv_samba3_push_reply(call);
264 NT_STATUS_NOT_OK_RETURN(status);
266 call->out_iov[0].iov_base = call->out.data;
267 call->out_iov[0].iov_len = call->out.length;
269 subreq = tstream_writev_queue_send(call,
270 wbsrv_conn->conn->event.ctx,
271 wbsrv_conn->tstream,
272 wbsrv_conn->send_queue,
273 call->out_iov, 1);
274 if (subreq == NULL) {
275 wbsrv_terminate_connection(wbsrv_conn, "wbsrv_call_loop: "
276 "no memory for tstream_writev_queue_send");
277 return NT_STATUS_NO_MEMORY;
279 tevent_req_set_callback(subreq, wbsrv_samba3_send_reply_done, call);
281 return status;
284 static void wbsrv_samba3_send_reply_done(struct tevent_req *subreq)
286 struct wbsrv_samba3_call *call = tevent_req_callback_data(subreq,
287 struct wbsrv_samba3_call);
288 int sys_errno;
289 int rc;
291 rc = tstream_writev_queue_recv(subreq, &sys_errno);
292 TALLOC_FREE(subreq);
293 if (rc == -1) {
294 const char *reason;
296 reason = talloc_asprintf(call, "wbsrv_samba3_send_reply_done: "
297 "tstream_writev_queue_recv() - %d:%s",
298 sys_errno, strerror(sys_errno));
299 if (reason == NULL) {
300 reason = "wbsrv_samba3_send_reply_done: "
301 "tstream_writev_queue_recv() failed";
304 wbsrv_terminate_connection(call->wbconn, reason);
305 return;
308 talloc_free(call);
311 NTSTATUS wbsrv_samba3_process(struct wbsrv_samba3_call *call)
313 NTSTATUS status;
315 status = wbsrv_samba3_pull_request(call);
317 if (!NT_STATUS_IS_OK(status)) {
318 return status;
321 status = wbsrv_samba3_handle_call(call);
323 if (!NT_STATUS_IS_OK(status)) {
324 talloc_free(call);
325 return status;
328 if (call->flags & WBSRV_CALL_FLAGS_REPLY_ASYNC) {
329 return NT_STATUS_OK;
332 status = wbsrv_samba3_send_reply(call);
333 return status;