d335e1f74d26fc03049b12ce8b5ec5f73c5385b1
[ira/wip.git] / source4 / winbind / wb_samba3_protocol.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
30 uint32_t wbsrv_samba3_packet_length(DATA_BLOB blob)
31 {
32         uint32_t *len = (uint32_t *)blob.data;
33         return *len;
34 }
35
36 NTSTATUS wbsrv_samba3_pull_request(DATA_BLOB blob, TALLOC_CTX *mem_ctx,
37                                    struct wbsrv_call **_call)
38 {
39         struct wbsrv_call *call;
40         struct wbsrv_samba3_call *s3_call;
41
42         if (blob.length != sizeof(s3_call->request)) {
43                 DEBUG(0,("wbsrv_samba3_pull_request: invalid blob length %lu should be %lu\n"
44                          " make sure you use the correct winbind client tools!\n",
45                          (long)blob.length, (long)sizeof(s3_call->request)));
46                 return NT_STATUS_INVALID_PARAMETER;
47         }
48
49         call = talloc_zero(mem_ctx, struct wbsrv_call);
50         NT_STATUS_HAVE_NO_MEMORY(call);
51
52         s3_call = talloc_zero(call, struct wbsrv_samba3_call);
53         NT_STATUS_HAVE_NO_MEMORY(s3_call);
54         s3_call->call = call;
55
56         /* the packet layout is the same as the in memory layout of the request, so just copy it */
57         memcpy(&s3_call->request, blob.data, sizeof(s3_call->request));
58
59         call->private_data = s3_call;
60
61         *_call = call;
62         return NT_STATUS_OK;
63 }
64
65 NTSTATUS wbsrv_samba3_handle_call(struct wbsrv_call *call)
66 {
67         struct wbsrv_samba3_call *s3call = talloc_get_type(call->private_data,
68                                                            struct wbsrv_samba3_call);
69
70         DEBUG(10, ("Got winbind samba3 request %d\n", s3call->request.cmd));
71
72         s3call->response.length = sizeof(s3call->response);
73
74         switch(s3call->request.cmd) {
75         case WINBINDD_INTERFACE_VERSION:
76                 return wbsrv_samba3_interface_version(s3call);
77
78 #if 0
79         case WINBINDD_CHECK_MACHACC:
80                 return wbsrv_samba3_check_machacc(s3call);
81 #endif
82
83         case WINBINDD_PING:
84                 return wbsrv_samba3_ping(s3call);
85
86         case WINBINDD_INFO:
87                 return wbsrv_samba3_info(s3call);
88
89         case WINBINDD_DOMAIN_NAME:
90                 return wbsrv_samba3_domain_name(s3call);
91
92         case WINBINDD_NETBIOS_NAME:
93                 return wbsrv_samba3_netbios_name(s3call);
94
95         case WINBINDD_PRIV_PIPE_DIR:
96                 return wbsrv_samba3_priv_pipe_dir(s3call);
97
98         case WINBINDD_LOOKUPNAME:
99                 return wbsrv_samba3_lookupname(s3call);
100
101         case WINBINDD_LOOKUPSID:
102                 return wbsrv_samba3_lookupsid(s3call);
103
104         case WINBINDD_PAM_AUTH:
105                 return wbsrv_samba3_pam_auth(s3call);
106
107         case WINBINDD_PAM_AUTH_CRAP:
108                 return wbsrv_samba3_pam_auth_crap(s3call);
109
110         case WINBINDD_GETDCNAME:
111                 return wbsrv_samba3_getdcname(s3call);
112
113         case WINBINDD_GETUSERDOMGROUPS:
114                 return wbsrv_samba3_userdomgroups(s3call);
115
116         case WINBINDD_GETUSERSIDS:
117                 return wbsrv_samba3_usersids(s3call);
118
119         case WINBINDD_LIST_TRUSTDOM:
120                 return wbsrv_samba3_list_trustdom(s3call);
121
122                 /* Unimplemented commands */
123
124         case WINBINDD_GETPWNAM:
125         case WINBINDD_GETPWUID:
126         case WINBINDD_GETGRNAM:
127         case WINBINDD_GETGRGID:
128         case WINBINDD_GETGROUPS:
129         case WINBINDD_SETPWENT:
130         case WINBINDD_ENDPWENT:
131         case WINBINDD_GETPWENT:
132         case WINBINDD_SETGRENT:
133         case WINBINDD_ENDGRENT:
134         case WINBINDD_GETGRENT:
135         case WINBINDD_PAM_CHAUTHTOK:
136         case WINBINDD_LIST_USERS:
137         case WINBINDD_LIST_GROUPS:
138         case WINBINDD_SID_TO_UID:
139         case WINBINDD_SID_TO_GID:
140         case WINBINDD_UID_TO_SID:
141         case WINBINDD_GID_TO_SID:
142         case WINBINDD_ALLOCATE_RID:
143         case WINBINDD_ALLOCATE_RID_AND_GID:
144         case WINBINDD_CHECK_MACHACC:
145         case WINBINDD_DOMAIN_INFO:
146         case WINBINDD_SHOW_SEQUENCE:
147         case WINBINDD_WINS_BYIP:
148         case WINBINDD_WINS_BYNAME:
149         case WINBINDD_GETGRLST:
150         case WINBINDD_INIT_CONNECTION:
151         case WINBINDD_DUAL_SID2UID:
152         case WINBINDD_DUAL_SID2GID:
153         case WINBINDD_DUAL_IDMAPSET:
154         case WINBINDD_DUAL_UID2NAME:
155         case WINBINDD_DUAL_NAME2UID:
156         case WINBINDD_DUAL_GID2NAME:
157         case WINBINDD_DUAL_NAME2GID:
158         case WINBINDD_DUAL_USERINFO:
159         case WINBINDD_DUAL_GETSIDALIASES:
160         case WINBINDD_NUM_CMDS:
161                 DEBUG(10, ("Unimplemented winbind samba3 request %d\n", 
162                            s3call->request.cmd));
163                 break;
164         }
165
166         s3call->response.result = WINBINDD_ERROR;
167         return NT_STATUS_OK;
168 }
169
170 NTSTATUS wbsrv_samba3_push_reply(struct wbsrv_call *call, TALLOC_CTX *mem_ctx, DATA_BLOB *_blob)
171 {
172         struct wbsrv_samba3_call *s3call = talloc_get_type(call->private_data,
173                                                            struct wbsrv_samba3_call);
174         DATA_BLOB blob;
175         uint8_t *extra_data;
176         size_t extra_data_len = 0;
177
178         extra_data = s3call->response.extra_data;
179         if (extra_data) {
180                 extra_data_len = s3call->response.length -
181                         sizeof(s3call->response);
182         }
183
184         blob = data_blob_talloc(mem_ctx, NULL, s3call->response.length);
185         NT_STATUS_HAVE_NO_MEMORY(blob.data);
186
187         /* don't push real pointer values into sockets */
188         if (extra_data) {
189                 s3call->response.extra_data = (void *)0xFFFFFFFF;
190         }
191         memcpy(blob.data, &s3call->response, sizeof(s3call->response));
192         /* set back the pointer */
193         s3call->response.extra_data = extra_data;
194
195         if (extra_data) {
196                 memcpy(blob.data + sizeof(s3call->response), extra_data, extra_data_len);
197         }
198
199         *_blob = blob;
200         return NT_STATUS_OK;
201 }