-/*
+/*
Unix SMB/CIFS implementation.
Main SMB server routines
Copyright (C) Andrew Tridgell 1992-1998
Copyright (C) Martin Pool 2002
Copyright (C) Jelmer Vernooij 2002-2003
-
+ Copyright (C) Volker Lendecke 1993-2007
+ Copyright (C) Jeremy Allison 1993-2007
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
static int am_parent = 1;
-/* the last message the was processed */
-int last_message = -1;
-
-/* a useful macro to debug the last message processed */
-#define LAST_MESSAGE() smb_fn_name(last_message)
-
extern struct auth_context *negprot_global_auth_context;
-extern pstring user_socket_options;
extern SIG_ATOMIC_T got_sig_term;
extern SIG_ATOMIC_T reload_after_sighup;
static SIG_ATOMIC_T got_sig_cld;
static void smbd_set_server_fd(int fd)
{
server_fd = fd;
- client_setfd(fd);
+}
+
+int get_client_fd(void)
+{
+ return server_fd;
}
struct event_context *smbd_event_context(void)
return ctx;
}
+struct memcache *smbd_memcache(void)
+{
+ static struct memcache *cache;
+
+ if (!cache
+ && !(cache = memcache_init(NULL,
+ lp_max_stat_cache_size()*1024))) {
+
+ smb_panic("Could not init smbd memcache");
+ }
+ return cache;
+}
+
/*******************************************************************
What to do when smb.conf is updated.
********************************************************************/
close_low_fds(False); /* Don't close stderr */
set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
- set_socket_options(smbd_server_fd(), user_socket_options);
+ set_socket_options(smbd_server_fd(), lp_socket_options());
return True;
}
int maxfd = 0;
int i;
char *ports;
+ struct dns_reg_state * dns_reg = NULL;
+ unsigned dns_port = 0;
if (!is_daemon) {
return open_sockets_inetd();
/* Now open a listen socket for each of the
interfaces. */
for(i = 0; i < num_interfaces; i++) {
+ TALLOC_CTX *frame = NULL;
const struct sockaddr_storage *ifss =
iface_n_sockaddr_storage(i);
- fstring tok;
+ char *tok;
const char *ptr;
if (ifss == NULL) {
continue;
}
- for (ptr=ports; next_token(&ptr, tok, " \t,",
- sizeof(tok)); ) {
+ frame = talloc_stackframe();
+ for (ptr=ports;
+ next_token_talloc(frame,&ptr, &tok, " \t,");) {
unsigned port = atoi(tok);
if (port == 0 || port > 0xffff) {
continue;
}
+
+ /* Keep the first port for mDNS service
+ * registration.
+ */
+ if (dns_port == 0) {
+ dns_port = port;
+ }
+
s = fd_listenset[num_sockets] =
open_socket_in(SOCK_STREAM, port, 0,
ifss, True);
/* ready to listen */
set_socket_options(s,"SO_KEEPALIVE");
- set_socket_options(s,user_socket_options);
+ set_socket_options(s,lp_socket_options());
/* Set server socket to
* non-blocking for the accept. */
DEBUG(0,("open_sockets_smbd: listen: "
"%s\n", strerror(errno)));
close(s);
+ TALLOC_FREE(frame);
return False;
}
FD_SET(s,&listen_set);
if (num_sockets >= FD_SETSIZE) {
DEBUG(0,("open_sockets_smbd: Too "
"many sockets to bind to\n"));
+ TALLOC_FREE(frame);
return False;
}
}
+ TALLOC_FREE(frame);
}
} else {
/* Just bind to 0.0.0.0 - accept connections
from anywhere. */
- fstring tok;
+ TALLOC_CTX *frame = talloc_stackframe();
+ char *tok;
const char *ptr;
const char *sock_addr = lp_socket_address();
- fstring sock_tok;
+ char *sock_tok;
const char *sock_ptr;
if (strequal(sock_addr, "0.0.0.0") ||
#endif
}
- for (sock_ptr=sock_addr; next_token(&sock_ptr, sock_tok, " \t,",
- sizeof(sock_tok)); ) {
- for (ptr=ports; next_token(&ptr, tok, " \t,",
- sizeof(tok)); ) {
+ for (sock_ptr=sock_addr;
+ next_token_talloc(frame, &sock_ptr, &sock_tok, " \t,"); ) {
+ for (ptr=ports; next_token_talloc(frame, &ptr, &tok, " \t,"); ) {
struct sockaddr_storage ss;
unsigned port = atoi(tok);
if (port == 0 || port > 0xffff) {
continue;
}
+
+ /* Keep the first port for mDNS service
+ * registration.
+ */
+ if (dns_port == 0) {
+ dns_port = port;
+ }
+
/* open an incoming socket */
if (!interpret_string_addr(&ss, sock_tok,
AI_NUMERICHOST|AI_PASSIVE)) {
/* ready to listen */
set_socket_options(s,"SO_KEEPALIVE");
- set_socket_options(s,user_socket_options);
+ set_socket_options(s,lp_socket_options());
/* Set server socket to non-blocking
* for the accept. */
"listen: %s\n",
strerror(errno)));
close(s);
+ TALLOC_FREE(frame);
return False;
}
if (num_sockets >= FD_SETSIZE) {
DEBUG(0,("open_sockets_smbd: Too "
"many sockets to bind to\n"));
+ TALLOC_FREE(frame);
return False;
}
}
}
+ TALLOC_FREE(frame);
}
SAFE_FREE(ports);
FD_ZERO(&w_fds);
GetTimeOfDay(&now);
+ /* Kick off our mDNS registration. */
+ if (dns_port != 0) {
+ dns_register_smbd(&dns_reg, dns_port, &maxfd,
+ &r_fds, &idle_timeout);
+ }
+
event_add_to_select_args(smbd_event_context(), &now,
&r_fds, &w_fds, &idle_timeout,
&maxfd);
continue;
}
+ /* process pending nDNS responses */
+ if (dns_register_smbd_reply(dns_reg, &r_fds, &idle_timeout)) {
+ --num;
+ }
+
if (run_events(smbd_event_context(), num, &r_fds, &w_fds)) {
continue;
}
if (allowable_number_of_smbd_processes() &&
smbd_server_fd() != -1 &&
((child = sys_fork())==0)) {
+ char remaddr[INET6_ADDRSTRLEN];
+
/* Child code ... */
/* Stop zombies, the parent explicitly handles
for(i = 0; i < num_sockets; i++)
close(fd_listenset[i]);
+ /* close our mDNS daemon handle */
+ dns_register_close(&dns_reg);
+
/* close our standard file
descriptors */
close_low_fds(False);
am_parent = 0;
set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
- set_socket_options(smbd_server_fd(),user_socket_options);
+ set_socket_options(smbd_server_fd(),
+ lp_socket_options());
/* this is needed so that we get decent entries
in smbstatus for port 445 connects */
- set_remote_machine_name(get_peer_addr(smbd_server_fd()),
- False);
+ set_remote_machine_name(get_peer_addr(smbd_server_fd(),
+ remaddr,
+ sizeof(remaddr)),
+ false);
/* Reset the state of the random
* number generation system, so
bool reload_services(bool test)
{
bool ret;
-
+
if (lp_loaded()) {
- pstring fname;
- pstrcpy(fname,lp_configfile());
+ char *fname = lp_configfile();
if (file_exist(fname, NULL) &&
- !strcsequal(fname, dyn_CONFIGFILE)) {
- pstrcpy(dyn_CONFIGFILE, fname);
+ !strcsequal(fname, get_dyn_CONFIGFILE())) {
+ set_dyn_CONFIGFILE(fname);
test = False;
}
}
lp_killunused(conn_snum_used);
- ret = lp_load(dyn_CONFIGFILE, False, False, True, True);
+ ret = lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
reload_printers();
load_interfaces();
- if (smbd_server_fd() != -1) {
+ if (smbd_server_fd() != -1) {
set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
- set_socket_options(smbd_server_fd(), user_socket_options);
+ set_socket_options(smbd_server_fd(), lp_socket_options());
}
mangle_reset_cache();
POPT_COMMON_DYNCONFIG
POPT_TABLEEND
};
-
- load_case_tables();
+ TALLOC_CTX *frame = talloc_stackframe(); /* Setup tos. */
TimeInit();
}
poptFreeContext(pc);
+ if (interactive) {
+ Fork = False;
+ log_stdout = True;
+ }
+
+ setup_logging(argv[0],log_stdout);
+
if (print_build_options) {
build_options(True); /* Display output to screen as well as debug */
exit(0);
}
+ load_case_tables();
+
#ifdef HAVE_SETLUID
/* needed for SecureWare on SCO */
setluid(0);
set_remote_machine_name("smbd", False);
- if (interactive) {
- Fork = False;
- log_stdout = True;
- }
-
if (interactive && (DEBUGLEVEL >= 9)) {
talloc_enable_leak_report();
}
exit(1);
}
- setup_logging(argv[0],log_stdout);
-
/* we want to re-seed early to prevent time delays causing
client problems at a later date. (tridge) */
generate_random_buffer(NULL, 0);
reopen_logs();
- DEBUG(0,( "smbd version %s started.\n", SAMBA_VERSION_STRING));
- DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) );
+ DEBUG(0,("smbd version %s started.\n", SAMBA_VERSION_STRING));
+ DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE));
DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
(int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));
if (smbd_messaging_context() == NULL)
exit(1);
+ if (smbd_memcache() == NULL) {
+ exit(1);
+ }
+
+ memcache_set_global(smbd_memcache());
+
/* Initialise the password backed before the global_sam_sid
to ensure that we fetch from ldap before we make a domain sid up */
if (!connections_init(True))
exit(1);
- if (!locking_init(0))
+ if (!locking_init())
exit(1);
namecache_enable();
/* Setup oplocks */
if (!init_oplocks(smbd_messaging_context()))
exit(1);
-
+
/* Setup aio signal handler. */
initialize_async_io_handler();
exit(1);
}
+ TALLOC_FREE(frame);
+
smbd_process();
namecache_shutdown();