2 Unix SMB/CIFS implementation.
4 use s3compat to run s3 smbd within Samba4
6 based on smb_samba3 by Metze
8 Copyright (C) Andrew Tridgell 2010
9 Copyright (C) Stefan Metzmacher 2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "smbd/service.h"
27 #include "libcli/smb2/smb2.h"
28 #include "system/network.h"
29 #include "lib/socket/netif.h"
30 #include "param/param.h"
31 #include "dynconfig/dynconfig.h"
32 #include "smbd/process_model.h"
33 #include "tevent/tevent.h"
34 #include "s3compat_wrapper.h"
35 #include "s3compat_proto.h"
36 #include "s3compat_globals.h"
37 static struct stream_connection *samba3_conn;
39 struct stream_connection *s3compat_get_conn(void)
45 initialise a server_context from a open socket and register a event handler
46 for reading from that socket
48 static void s3compat_smb_accept(struct stream_connection *conn)
50 if (lp_parm_bool(conn->lp_ctx, NULL, "s3compat", "gdb", false)) {
51 char *cmd = talloc_asprintf(conn, "gnome-terminal -e \"gdb --pid %u\"", getpid());
55 DEBUG(0,(__location__ ": new s3compat smbd connection\n"));
58 s3compat_set_lp_ctx(conn->lp_ctx);
60 s3compat_set_tevent_ctx(conn->event.ctx);
61 s3compat_set_msg_ctx(conn->msg_ctx);
62 tevent_re_initialise(conn->event.ctx);
63 s3compat_smbd_process();
67 static const struct stream_server_ops s3compat_smb_stream_ops = {
69 .accept_connection = s3compat_smb_accept,
73 setup a listening socket on all the SMB ports for a particular address
75 static NTSTATUS s3compat_add_socket(struct tevent_context *event_context,
76 struct loadparm_context *lp_ctx,
77 const struct model_ops *model_ops,
80 const char **ports = lp_smb_ports(lp_ctx);
84 for (i=0;ports[i];i++) {
85 uint16_t port = atoi(ports[i]);
86 if (port == 0) continue;
87 status = stream_setup_socket(event_context, lp_ctx,
88 model_ops, &s3compat_smb_stream_ops,
90 lp_socket_options(lp_ctx),
92 NT_STATUS_NOT_OK_RETURN(status);
100 open the smb server sockets
102 _PUBLIC_ void s3_smbd_task_init(struct task_server *task)
105 const struct model_ops *model_ops;
107 model_ops = process_model_startup(task->event_ctx, "standard");
109 if (model_ops == NULL) {
113 task_server_set_title(task, "task[s3compat_smb]");
115 if (lp_interfaces(task->lp_ctx)
116 && lp_bind_interfaces_only(task->lp_ctx)) {
119 struct interface *ifaces;
121 load_interfaces(task, lp_interfaces(task->lp_ctx), &ifaces);
123 num_interfaces = iface_count(ifaces);
125 /* We have been given an interfaces line, and been
126 told to only bind to those interfaces. Create a
127 socket per interface and bind to only these.
129 for(i = 0; i < num_interfaces; i++) {
130 const char *address = iface_n_ip(ifaces, i);
131 status = s3compat_add_socket(task->event_ctx,
134 if (!NT_STATUS_IS_OK(status)) goto failed;
137 /* Just bind to lp_socket_address() (usually 0.0.0.0) */
138 status = s3compat_add_socket(task->event_ctx, task->lp_ctx,
140 lp_socket_address(task->lp_ctx));
141 if (!NT_STATUS_IS_OK(status)) goto failed;
146 task_server_terminate(task, "Failed to startup s3compat smb task", true);