2 Unix SMB/CIFS implementation.
3 service (connection) handling
4 Copyright (C) Andrew Tridgell 1992-2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "smb_server/smb_server.h"
23 #include "smbd/service_stream.h"
24 #include "ntvfs/ntvfs.h"
28 * Find a service entry. service is always in dos codepage.
30 * @param service is modified (to canonical form??)
32 static int find_service(const char *service)
36 iService = lp_servicenumber(service);
38 if (iService >= 0 && !lp_snum_ok(iService)) {
39 DEBUG(0,("Invalid snum %d for %s\n",iService, service));
44 DEBUG(3,("find_service() failed to find service %s\n", service));
51 /****************************************************************************
52 Make a connection, given the snum to connect to, and the vuser of the
53 connecting user if appropriate.
54 ****************************************************************************/
55 static NTSTATUS make_connection_snum(struct smbsrv_request *req,
56 int snum, enum ntvfs_type type,
60 struct smbsrv_tcon *tcon;
63 if (!socket_check_access(req->smb_conn->connection->socket,
66 lp_hostsdeny(snum))) {
67 return NT_STATUS_ACCESS_DENIED;
70 tcon = smbsrv_smb_tcon_new(req->smb_conn);
72 DEBUG(0,("Couldn't find free connection.\n"));
73 return NT_STATUS_INSUFFICIENT_RESOURCES;
79 /* init ntvfs function pointers */
80 status = ntvfs_init_connection(req, type);
81 if (!NT_STATUS_IS_OK(status)) {
82 DEBUG(0, ("ntvfs_init_connection failed for service %s\n",
83 lp_servicename(tcon->service)));
89 /* Invoke NTVFS connection hook */
90 status = ntvfs_connect(req, lp_servicename(snum));
91 if (!NT_STATUS_IS_OK(status)) {
92 DEBUG(0,("make_connection: NTVFS make connection failed!\n"));
101 /****************************************************************************
102 Make a connection to a service.
105 ****************************************************************************/
106 static NTSTATUS make_connection(struct smbsrv_request *req,
107 const char *service, DATA_BLOB password,
111 enum ntvfs_type type;
112 const char *type_str;
114 /* TODO: check the password, when it's share level security! */
116 /* the service might be of the form \\SERVER\SHARE. Should we put
117 the server name we get from this somewhere? */
118 if (strncmp(service, "\\\\", 2) == 0) {
119 char *p = strchr(service+2, '\\');
125 snum = find_service(service);
128 DEBUG(0,("couldn't find service %s\n", service));
129 return NT_STATUS_BAD_NETWORK_NAME;
132 /* work out what sort of connection this is */
133 if (strcmp(lp_fstype(snum), "IPC") == 0) {
136 } else if (lp_print_ok(snum)) {
144 if (strcmp(dev, "?????") != 0 && strcasecmp(type_str, dev) != 0) {
145 /* the client gave us the wrong device type */
146 return NT_STATUS_BAD_DEVICE_TYPE;
149 return make_connection_snum(req, snum, type, password, dev);
153 backend for tree connect call
155 NTSTATUS tcon_backend(struct smbsrv_request *req, union smb_tcon *con)
159 /* can only do bare tcon in share level security */
160 if (!req->session && lp_security() != SEC_SHARE) {
161 return NT_STATUS_ACCESS_DENIED;
164 if (con->generic.level == RAW_TCON_TCON) {
166 password = data_blob(con->tcon.in.password, strlen(con->tcon.in.password) + 1);
168 status = make_connection(req, con->tcon.in.service, password, con->tcon.in.dev);
170 if (!NT_STATUS_IS_OK(status)) {
174 con->tcon.out.max_xmit = req->smb_conn->negotiate.max_recv;
175 con->tcon.out.tid = req->tcon->tid;
180 status = make_connection(req, con->tconx.in.path, con->tconx.in.password,
181 con->tconx.in.device);
182 if (!NT_STATUS_IS_OK(status)) {
186 con->tconx.out.tid = req->tcon->tid;
187 con->tconx.out.dev_type = talloc_strdup(req, req->tcon->dev_type);
188 con->tconx.out.fs_type = talloc_strdup(req, req->tcon->fs_type);
189 con->tconx.out.options = SMB_SUPPORT_SEARCH_BITS | (lp_csc_policy(req->tcon->service) << 2);
190 if (lp_msdfs_root(req->tcon->service) && lp_host_msdfs()) {
191 con->tconx.out.options |= SMB_SHARE_IN_DFS;