diff options
author | Simo Sorce <idra@samba.org> | 2006-07-23 18:43:07 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:10:18 -0500 |
commit | 9c66f601f1520a99b9236c32bc9f03a33bd4b2aa (patch) | |
tree | bba8797304b7db98aa205c3cb04344072be00030 /source4/smb_server | |
parent | 2dc38416b65177aca94b4de3c9cfcb5c8edb0df2 (diff) | |
download | samba-9c66f601f1520a99b9236c32bc9f03a33bd4b2aa.tar.gz samba-9c66f601f1520a99b9236c32bc9f03a33bd4b2aa.tar.bz2 samba-9c66f601f1520a99b9236c32bc9f03a33bd4b2aa.zip |
r17206: Add a modular API for share configuration.
Commit the classic backwards compatible module which is the default one
(This used to be commit a89cc346b9296cb49929898d257a064a6c2bae86)
Diffstat (limited to 'source4/smb_server')
-rw-r--r-- | source4/smb_server/config.mk | 1 | ||||
-rw-r--r-- | source4/smb_server/smb/service.c | 57 | ||||
-rw-r--r-- | source4/smb_server/smb2/tcon.c | 27 | ||||
-rw-r--r-- | source4/smb_server/smb_server.c | 6 | ||||
-rw-r--r-- | source4/smb_server/smb_server.h | 2 |
5 files changed, 52 insertions, 41 deletions
diff --git a/source4/smb_server/config.mk b/source4/smb_server/config.mk index 6eef711072..f21336ae69 100644 --- a/source4/smb_server/config.mk +++ b/source4/smb_server/config.mk @@ -18,6 +18,7 @@ OBJ_FILES = \ management.o PRIVATE_PROTO_HEADER = smb_server_proto.h PUBLIC_DEPENDENCIES = \ + share \ LIBPACKET \ SMB_PROTOCOL \ SMB2_PROTOCOL diff --git a/source4/smb_server/smb/service.c b/source4/smb_server/smb/service.c index 92967d858c..b396d2b605 100644 --- a/source4/smb_server/smb/service.c +++ b/source4/smb_server/smb/service.c @@ -27,22 +27,16 @@ Make a connection, given the snum to connect to, and the vuser of the connecting user if appropriate. ****************************************************************************/ -static NTSTATUS make_connection_snum(struct smbsrv_request *req, - int snum, enum ntvfs_type type, +static NTSTATUS make_connection_scfg(struct smbsrv_request *req, + struct share_config *scfg, + enum ntvfs_type type, DATA_BLOB password, const char *dev) { struct smbsrv_tcon *tcon; NTSTATUS status; - if (!socket_check_access(req->smb_conn->connection->socket, - lp_servicename(snum), - lp_hostsallow(snum), - lp_hostsdeny(snum))) { - return NT_STATUS_ACCESS_DENIED; - } - - tcon = smbsrv_smb_tcon_new(req->smb_conn, lp_servicename(snum)); + tcon = smbsrv_smb_tcon_new(req->smb_conn, scfg->name); if (!tcon) { DEBUG(0,("Couldn't find free connection.\n")); return NT_STATUS_INSUFFICIENT_RESOURCES; @@ -50,15 +44,15 @@ static NTSTATUS make_connection_snum(struct smbsrv_request *req, req->tcon = tcon; /* init ntvfs function pointers */ - status = ntvfs_init_connection(tcon, snum, type, + status = ntvfs_init_connection(tcon, scfg, type, req->smb_conn->negotiate.protocol, req->smb_conn->connection->event.ctx, req->smb_conn->connection->msg_ctx, req->smb_conn->connection->server_id, &tcon->ntvfs); if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("ntvfs_init_connection failed for service %s\n", - lp_servicename(snum))); + DEBUG(0, ("make_connection_scfg: connection failed for service %s\n", + scfg->name)); goto failed; } @@ -97,7 +91,7 @@ static NTSTATUS make_connection_snum(struct smbsrv_request *req, } /* Invoke NTVFS connection hook */ - status = ntvfs_connect(req->ntvfs, lp_servicename(snum)); + status = ntvfs_connect(req->ntvfs, scfg->name); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("make_connection: NTVFS make connection failed!\n")); goto failed; @@ -120,11 +114,11 @@ static NTSTATUS make_connection(struct smbsrv_request *req, const char *service, DATA_BLOB password, const char *dev) { - int snum; + NTSTATUS status; enum ntvfs_type type; const char *type_str; - - /* TODO: check the password, when it's share level security! */ + struct share_config *scfg; + const char *sharetype; /* the service might be of the form \\SERVER\SHARE. Should we put the server name we get from this somewhere? */ @@ -135,17 +129,27 @@ static NTSTATUS make_connection(struct smbsrv_request *req, } } - snum = lp_find_valid_service(service); - if (snum == -1) { - DEBUG(0,("couldn't find service %s\n", service)); + status = share_get_config(req, req->smb_conn->share_context, service, &scfg); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0,("make_connection: couldn't find service %s\n", service)); return NT_STATUS_BAD_NETWORK_NAME; } + /* TODO: check the password, when it's share level security! */ + + if (!socket_check_access(req->smb_conn->connection->socket, + scfg->name, + share_string_list_option(req, scfg, SHARE_HOSTS_ALLOW), + share_string_list_option(req, scfg, SHARE_HOSTS_DENY))) { + return NT_STATUS_ACCESS_DENIED; + } + /* work out what sort of connection this is */ - if (strcmp(lp_fstype(snum), "IPC") == 0) { + sharetype = share_string_option(scfg, "type", "DISK"); + if (sharetype && strcmp(sharetype, "IPC") == 0) { type = NTVFS_IPC; type_str = "IPC"; - } else if (lp_print_ok(snum)) { + } else if (sharetype && strcmp(sharetype, "PRINTER") == 0) { type = NTVFS_PRINT; type_str = "LPT:"; } else { @@ -158,7 +162,7 @@ static NTSTATUS make_connection(struct smbsrv_request *req, return NT_STATUS_BAD_DEVICE_TYPE; } - return make_connection_snum(req, snum, type, password, dev); + return make_connection_scfg(req, scfg, type, password, dev); } /* @@ -167,7 +171,6 @@ static NTSTATUS make_connection(struct smbsrv_request *req, NTSTATUS smbsrv_tcon_backend(struct smbsrv_request *req, union smb_tcon *con) { NTSTATUS status; - int snum; if (con->generic.level == RAW_TCON_TCON) { DATA_BLOB password; @@ -191,13 +194,11 @@ NTSTATUS smbsrv_tcon_backend(struct smbsrv_request *req, union smb_tcon *con) return status; } - snum = req->tcon->ntvfs->config.snum; - con->tconx.out.tid = req->tcon->tid; con->tconx.out.dev_type = talloc_strdup(req, req->tcon->ntvfs->dev_type); con->tconx.out.fs_type = talloc_strdup(req, req->tcon->ntvfs->fs_type); - con->tconx.out.options = SMB_SUPPORT_SEARCH_BITS | (lp_csc_policy(snum) << 2); - if (lp_msdfs_root(snum) && lp_host_msdfs()) { + con->tconx.out.options = SMB_SUPPORT_SEARCH_BITS | (share_int_option(req->tcon->ntvfs->config, SHARE_CSC_POLICY, SHARE_CSC_POLICY_DEFAULT) << 2); + if (share_bool_option(req->tcon->ntvfs->config, SHARE_MSDFS_ROOT, SHARE_MSDFS_ROOT_DEFAULT) && lp_host_msdfs()) { con->tconx.out.options |= SMB_SHARE_IN_DFS; } diff --git a/source4/smb_server/smb2/tcon.c b/source4/smb_server/smb2/tcon.c index 338fb5ed22..d01b63d446 100644 --- a/source4/smb_server/smb2/tcon.c +++ b/source4/smb_server/smb2/tcon.c @@ -157,8 +157,9 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon enum ntvfs_type type; uint16_t type_smb2; uint32_t unknown2; - int snum; const char *service = io->smb2.in.path; + struct share_config *scfg; + const char *sharetype; if (strncmp(service, "\\\\", 2) == 0) { const char *p = strchr(service+2, '\\'); @@ -167,25 +168,26 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon } } - snum = lp_find_valid_service(service); - if (snum == -1) { + status = share_get_config(req, req->smb_conn->share_context, service, &scfg); + if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("smb2srv_tcon_backend: couldn't find service %s\n", service)); return NT_STATUS_BAD_NETWORK_NAME; } if (!socket_check_access(req->smb_conn->connection->socket, - lp_servicename(snum), - lp_hostsallow(snum), - lp_hostsdeny(snum))) { + scfg->name, + share_string_list_option(req, scfg, SHARE_HOSTS_ALLOW), + share_string_list_option(req, scfg, SHARE_HOSTS_DENY))) { return NT_STATUS_ACCESS_DENIED; } /* work out what sort of connection this is */ - if (strcmp(lp_fstype(snum), "IPC") == 0) { + sharetype = share_string_option(scfg, SHARE_TYPE, "DISK"); + if (sharetype && strcmp(sharetype, "IPC") == 0) { type = NTVFS_IPC; type_smb2 = 0x0002; unknown2 = 0x00000030; - } else if (lp_print_ok(snum)) { + } else if (sharetype && strcmp(sharetype, "PRINTER") == 0) { type = NTVFS_PRINT; type_smb2 = 0x0003; unknown2 = 0x00000000; @@ -195,7 +197,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon unknown2 = 0x00000800; } - tcon = smbsrv_smb2_tcon_new(req->session, lp_servicename(snum)); + tcon = smbsrv_smb2_tcon_new(req->session, scfg->name); if (!tcon) { DEBUG(0,("smb2srv_tcon_backend: Couldn't find free connection.\n")); return NT_STATUS_INSUFFICIENT_RESOURCES; @@ -203,7 +205,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon req->tcon = tcon; /* init ntvfs function pointers */ - status = ntvfs_init_connection(tcon, snum, type, + status = ntvfs_init_connection(tcon, scfg, type, req->smb_conn->negotiate.protocol, req->smb_conn->connection->event.ctx, req->smb_conn->connection->msg_ctx, @@ -211,7 +213,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon &tcon->ntvfs); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("smb2srv_tcon_backend: ntvfs_init_connection failed for service %s\n", - lp_servicename(snum))); + scfg->name)); goto failed; } @@ -250,7 +252,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon } /* Invoke NTVFS connection hook */ - status = ntvfs_connect(req->ntvfs, lp_servicename(snum)); + status = ntvfs_connect(req->ntvfs, scfg->name); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("smb2srv_tcon_backend: NTVFS ntvfs_connect() failed!\n")); goto failed; @@ -279,7 +281,6 @@ static void smb2srv_tcon_send(struct smb2srv_request *req, union smb_tcon *io) smb2srv_send_error(req, req->status); return; } - if (io->smb2.out.unknown1 == 0x0002) { /* if it's an IPC share vista returns 0x0005 */ unknown1 = 0x0005; diff --git a/source4/smb_server/smb_server.c b/source4/smb_server/smb_server.c index 6df48f3df6..56ca686baf 100644 --- a/source4/smb_server/smb_server.c +++ b/source4/smb_server/smb_server.c @@ -31,6 +31,7 @@ #include "smb_server/smb2/smb2_server.h" #include "system/network.h" #include "netif/netif.h" +#include "param/share.h" static NTSTATUS smbsrv_recv_generic_request(void *private, DATA_BLOB blob) { @@ -155,6 +156,11 @@ static void smbsrv_accept(struct stream_connection *conn) smb_conn->statistics.connect_time = timeval_current(); smbsrv_management_init(smb_conn); + + if (!NT_STATUS_IS_OK(share_get_context(smb_conn, &(smb_conn->share_context)))) { + smbsrv_terminate_connection(smb_conn, "share_init failed!"); + return; + } } static const struct stream_server_ops smb_stream_ops = { diff --git a/source4/smb_server/smb_server.h b/source4/smb_server/smb_server.h index 9acf181c54..edd9deeafb 100644 --- a/source4/smb_server/smb_server.h +++ b/source4/smb_server/smb_server.h @@ -372,6 +372,8 @@ struct smbsrv_connection { /* the time when the last request comes in */ struct timeval last_request_time; } statistics; + + struct share_context *share_context; }; #include "smb_server/smb_server_proto.h" |