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"
27 * Find a service entry. service is always in dos codepage.
29 * @param service is modified (to canonical form??)
31 static int find_service(const char *service)
35 iService = lp_servicenumber(service);
37 if (iService >= 0 && !lp_snum_ok(iService)) {
38 DEBUG(0,("Invalid snum %d for %s\n",iService, service));
43 DEBUG(3,("find_service() failed to find service %s\n", service));
50 /****************************************************************************
51 Make a connection, given the snum to connect to, and the vuser of the
52 connecting user if appropriate.
53 ****************************************************************************/
54 static NTSTATUS make_connection_snum(struct smbsrv_request *req,
55 int snum, enum ntvfs_type type,
59 struct smbsrv_tcon *tcon;
62 if (!socket_check_access(req->smb_conn->connection->socket,
65 lp_hostsdeny(snum))) {
66 return NT_STATUS_ACCESS_DENIED;
69 tcon = smbsrv_tcon_new(req->smb_conn);
71 DEBUG(0,("Couldn't find free connection.\n"));
72 return NT_STATUS_INSUFFICIENT_RESOURCES;
78 /* init ntvfs function pointers */
79 status = ntvfs_init_connection(req, type);
80 if (!NT_STATUS_IS_OK(status)) {
81 DEBUG(0, ("ntvfs_init_connection failed for service %s\n",
82 lp_servicename(tcon->service)));
88 /* Invoke NTVFS connection hook */
89 status = ntvfs_connect(req, lp_servicename(snum));
90 if (!NT_STATUS_IS_OK(status)) {
91 DEBUG(0,("make_connection: NTVFS make connection failed!\n"));
100 /****************************************************************************
101 Make a connection to a service.
104 ****************************************************************************/
105 static NTSTATUS make_connection(struct smbsrv_request *req,
106 const char *service, DATA_BLOB password,
110 enum ntvfs_type type;
111 const char *type_str;
113 /* TODO: check the password, when it's share level security! */
115 /* the service might be of the form \\SERVER\SHARE. Should we put
116 the server name we get from this somewhere? */
117 if (strncmp(service, "\\\\", 2) == 0) {
118 char *p = strchr(service+2, '\\');
124 snum = find_service(service);
127 DEBUG(0,("couldn't find service %s\n", service));
128 return NT_STATUS_BAD_NETWORK_NAME;
131 /* work out what sort of connection this is */
132 if (strcmp(lp_fstype(snum), "IPC") == 0) {
135 } else if (lp_print_ok(snum)) {
143 if (strcmp(dev, "?????") != 0 && strcasecmp(type_str, dev) != 0) {
144 /* the client gave us the wrong device type */
145 return NT_STATUS_BAD_DEVICE_TYPE;
148 return make_connection_snum(req, snum, type, password, dev);
152 backend for tree connect call
154 NTSTATUS tcon_backend(struct smbsrv_request *req, union smb_tcon *con)
158 /* can only do bare tcon in share level security */
159 if (!req->session && lp_security() != SEC_SHARE) {
160 return NT_STATUS_ACCESS_DENIED;
163 if (con->generic.level == RAW_TCON_TCON) {
165 password = data_blob(con->tcon.in.password, strlen(con->tcon.in.password) + 1);
167 status = make_connection(req, con->tcon.in.service, password, con->tcon.in.dev);
169 if (!NT_STATUS_IS_OK(status)) {
173 con->tcon.out.max_xmit = req->smb_conn->negotiate.max_recv;
174 con->tcon.out.tid = req->tcon->tid;
179 status = make_connection(req, con->tconx.in.path, con->tconx.in.password,
180 con->tconx.in.device);
181 if (!NT_STATUS_IS_OK(status)) {
185 con->tconx.out.tid = req->tcon->tid;
186 con->tconx.out.dev_type = talloc_strdup(req, req->tcon->dev_type);
187 con->tconx.out.fs_type = talloc_strdup(req, req->tcon->fs_type);
188 con->tconx.out.options = SMB_SUPPORT_SEARCH_BITS | (lp_csc_policy(req->tcon->service) << 2);
189 if (lp_msdfs_root(req->tcon->service) && lp_host_msdfs()) {
190 con->tconx.out.options |= SMB_SHARE_IN_DFS;