0001-01-01 02:30:17 +02:30
/*
0001-01-01 02:30:17 +02:30
Unix SMB / CIFS implementation .
0001-01-01 02:30:17 +02:30
Main SMB server routines
0001-01-01 02:30:17 +02:30
Copyright ( C ) Andrew Tridgell 1992 - 1998
Copyright ( C ) Martin Pool 2002
0001-01-01 02:30:17 +02:30
Copyright ( C ) Jelmer Vernooij 2002 - 2003
0001-01-01 02:30:17 +02:30
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 2 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 , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
0001-01-01 02:30:17 +02:30
static int am_parent = 1 ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* 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)
2005-04-06 20:28:04 +04:00
extern struct auth_context * negprot_global_auth_context ;
0001-01-01 02:30:17 +02:30
extern pstring user_socket_options ;
0001-01-01 02:30:17 +02:30
extern SIG_ATOMIC_T got_sig_term ;
extern SIG_ATOMIC_T reload_after_sighup ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
# ifdef WITH_DFS
0001-01-01 02:30:17 +02:30
extern int dcelogin_atmost_once ;
0001-01-01 02:30:17 +02:30
# endif /* WITH_DFS */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* really we should have a top level context structure that has the
client file descriptor as an element . That would require a major rewrite : (
the following 2 functions are an alternative - they make the file
descriptor private to smbd
*/
0001-01-01 02:30:17 +02:30
static int server_fd = - 1 ;
0001-01-01 02:30:17 +02:30
int smbd_server_fd ( void )
{
return server_fd ;
}
0001-01-01 02:30:17 +02:30
static void smbd_set_server_fd ( int fd )
0001-01-01 02:30:17 +02:30
{
server_fd = fd ;
client_setfd ( fd ) ;
}
2006-02-04 01:19:41 +03:00
/*******************************************************************
What to do when smb . conf is updated .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void smb_conf_updated ( int msg_type , struct process_id src ,
void * buf , size_t len )
{
DEBUG ( 10 , ( " smb_conf_updated: Got message saying smb.conf was updated. Reloading. \n " ) ) ;
reload_services ( False ) ;
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
0001-01-01 02:30:17 +02:30
Terminate signal .
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
static void sig_term ( void )
{
got_sig_term = 1 ;
2005-06-09 19:20:11 +04:00
sys_select_signal ( SIGTERM ) ;
0001-01-01 02:30:17 +02:30
}
/****************************************************************************
Catch a sighup .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void sig_hup ( int sig )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
reload_after_sighup = 1 ;
2005-06-09 19:20:11 +04:00
sys_select_signal ( SIGHUP ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/****************************************************************************
Send a SIGTERM to our process group .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
static void killkids ( void )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
if ( am_parent ) kill ( 0 , SIGTERM ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/****************************************************************************
0001-01-01 02:30:17 +02:30
Process a sam sync message - not sure whether to do this here or
somewhere else .
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
2005-09-30 21:13:37 +04:00
static void msg_sam_sync ( int UNUSED ( msg_type ) , struct process_id UNUSED ( pid ) ,
0001-01-01 02:30:17 +02:30
void * UNUSED ( buf ) , size_t UNUSED ( len ) )
0001-01-01 02:30:17 +02:30
{
DEBUG ( 10 , ( " ** sam sync message received, ignoring \n " ) ) ;
}
/****************************************************************************
0001-01-01 02:30:17 +02:30
Process a sam sync replicate message - not sure whether to do this here or
somewhere else .
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
2005-09-30 21:13:37 +04:00
static void msg_sam_repl ( int msg_type , struct process_id pid ,
void * buf , size_t len )
0001-01-01 02:30:17 +02:30
{
uint32 low_serial ;
if ( len ! = sizeof ( uint32 ) )
return ;
low_serial = * ( ( uint32 * ) buf ) ;
DEBUG ( 3 , ( " received sam replication message, serial = 0x%04x \n " ,
low_serial ) ) ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/****************************************************************************
0001-01-01 02:30:17 +02:30
Open the socket communication - inetd .
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
static BOOL open_sockets_inetd ( void )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
/* Started from inetd. fd 0 is the socket. */
/* We will abort gracefully when the client or remote system
goes away */
0001-01-01 02:30:17 +02:30
smbd_set_server_fd ( dup ( 0 ) ) ;
0001-01-01 02:30:17 +02:30
/* close our standard file descriptors */
0001-01-01 02:30:17 +02:30
close_low_fds ( False ) ; /* Don't close stderr */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
set_socket_options ( smbd_server_fd ( ) , " SO_KEEPALIVE " ) ;
0001-01-01 02:30:17 +02:30
set_socket_options ( smbd_server_fd ( ) , user_socket_options ) ;
0001-01-01 02:30:17 +02:30
return True ;
}
0001-01-01 02:30:17 +02:30
2005-09-30 21:13:37 +04:00
static void msg_exit_server ( int msg_type , struct process_id src ,
void * buf , size_t len )
0001-01-01 02:30:17 +02:30
{
2006-04-04 04:27:50 +04:00
DEBUG ( 3 , ( " got a SHUTDOWN message \n " ) ) ;
2006-04-11 02:47:09 +04:00
exit_server_cleanly ( NULL ) ;
2006-04-04 04:27:50 +04:00
}
# ifdef DEVELOPER
static void msg_inject_fault ( int msg_type , struct process_id src ,
void * buf , size_t len )
{
int sig ;
if ( len ! = sizeof ( int ) ) {
DEBUG ( 0 , ( " Process %llu sent bogus signal injection request \n " ,
( unsigned long long ) src . pid ) ) ;
return ;
}
sig = * ( int * ) buf ;
if ( sig = = - 1 ) {
exit_server ( " internal error injected " ) ;
return ;
}
# if HAVE_STRSIGNAL
DEBUG ( 0 , ( " Process %llu requested injection of signal %d (%s) \n " ,
( unsigned long long ) src . pid , sig , strsignal ( sig ) ) ) ;
# else
DEBUG ( 0 , ( " Process %llu requested injection of signal %d \n " ,
( unsigned long long ) src . pid , sig ) ) ;
# endif
kill ( sys_getpid ( ) , sig ) ;
0001-01-01 02:30:17 +02:30
}
2006-04-04 04:27:50 +04:00
# endif /* DEVELOPER */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/****************************************************************************
Have we reached the process limit ?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
static BOOL allowable_number_of_smbd_processes ( void )
0001-01-01 02:30:17 +02:30
{
int max_processes = lp_max_smbd_processes ( ) ;
if ( ! max_processes )
return True ;
{
TDB_CONTEXT * tdb = conn_tdb_ctx ( ) ;
int32 val ;
if ( ! tdb ) {
DEBUG ( 0 , ( " allowable_number_of_smbd_processes: can't open connection tdb. \n " ) ) ;
return False ;
}
val = tdb_fetch_int32 ( tdb , " INFO/total_smbds " ) ;
if ( val = = - 1 & & ( tdb_error ( tdb ) ! = TDB_ERR_NOEXIST ) ) {
DEBUG ( 0 , ( " allowable_number_of_smbd_processes: can't fetch INFO/total_smbds. Error %s \n " ,
tdb_errorstr ( tdb ) ) ) ;
return False ;
}
if ( val > max_processes ) {
DEBUG ( 0 , ( " allowable_number_of_smbd_processes: number of processes (%d) is over allowed limit (%d) \n " ,
val , max_processes ) ) ;
return False ;
}
}
return True ;
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
0001-01-01 02:30:17 +02:30
Open the socket communication .
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
static BOOL open_sockets_smbd ( BOOL is_daemon , BOOL interactive , const char * smb_ports )
0001-01-01 02:30:17 +02:30
{
int num_interfaces = iface_count ( ) ;
0001-01-01 02:30:17 +02:30
int num_sockets = 0 ;
0001-01-01 02:30:17 +02:30
int fd_listenset [ FD_SETSIZE ] ;
fd_set listen_set ;
int s ;
2004-11-19 22:32:31 +03:00
int maxfd = 0 ;
0001-01-01 02:30:17 +02:30
int i ;
0001-01-01 02:30:17 +02:30
char * ports ;
0001-01-01 02:30:17 +02:30
if ( ! is_daemon ) {
return open_sockets_inetd ( ) ;
}
0001-01-01 02:30:17 +02:30
# ifdef HAVE_ATEXIT
0001-01-01 02:30:17 +02:30
{
static int atexit_set ;
if ( atexit_set = = 0 ) {
atexit_set = 1 ;
atexit ( killkids ) ;
}
}
0001-01-01 02:30:17 +02:30
# endif
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Stop zombies */
CatchChild ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
FD_ZERO ( & listen_set ) ;
0001-01-01 02:30:17 +02:30
/* use a reasonable default set of ports - listing on 445 and 139 */
if ( ! smb_ports ) {
ports = lp_smb_ports ( ) ;
if ( ! ports | | ! * ports ) {
0001-01-01 02:30:17 +02:30
ports = smb_xstrdup ( SMB_PORTS ) ;
} else {
ports = smb_xstrdup ( ports ) ;
0001-01-01 02:30:17 +02:30
}
} else {
0001-01-01 02:30:17 +02:30
ports = smb_xstrdup ( smb_ports ) ;
0001-01-01 02:30:17 +02:30
}
if ( lp_interfaces ( ) & & lp_bind_interfaces_only ( ) ) {
0001-01-01 02:30:17 +02:30
/* We have been given an interfaces line, and been
told to only bind to those interfaces . Create a
socket per interface and bind to only these .
*/
/* Now open a listen socket for each of the
interfaces . */
for ( i = 0 ; i < num_interfaces ; i + + ) {
struct in_addr * ifip = iface_n_ip ( i ) ;
0001-01-01 02:30:17 +02:30
fstring tok ;
0001-01-01 02:30:17 +02:30
const char * ptr ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ifip = = NULL ) {
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " open_sockets_smbd: interface %d has NULL IP address ! \n " , i ) ) ;
0001-01-01 02:30:17 +02:30
continue ;
}
0001-01-01 02:30:17 +02:30
2005-09-30 10:37:51 +04:00
for ( ptr = ports ; next_token ( & ptr , tok , " \t , " , sizeof ( tok ) ) ; ) {
0001-01-01 02:30:17 +02:30
unsigned port = atoi ( tok ) ;
2004-11-17 22:52:26 +03:00
if ( port = = 0 ) {
continue ;
}
0001-01-01 02:30:17 +02:30
s = fd_listenset [ num_sockets ] = open_socket_in ( SOCK_STREAM , port , 0 , ifip - > s_addr , True ) ;
if ( s = = - 1 )
return False ;
/* ready to listen */
set_socket_options ( s , " SO_KEEPALIVE " ) ;
set_socket_options ( s , user_socket_options ) ;
0001-01-01 02:30:17 +02:30
/* Set server socket to non-blocking for the accept. */
set_blocking ( s , False ) ;
0001-01-01 02:30:17 +02:30
if ( listen ( s , SMBD_LISTEN_BACKLOG ) = = - 1 ) {
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " listen: %s \n " , strerror ( errno ) ) ) ;
close ( s ) ;
return False ;
}
FD_SET ( s , & listen_set ) ;
2004-11-19 22:32:31 +03:00
maxfd = MAX ( maxfd , s ) ;
0001-01-01 02:30:17 +02:30
num_sockets + + ;
if ( num_sockets > = FD_SETSIZE ) {
DEBUG ( 0 , ( " open_sockets_smbd: Too many sockets to bind to \n " ) ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
}
} else {
/* Just bind to 0.0.0.0 - accept connections
from anywhere . */
0001-01-01 02:30:17 +02:30
fstring tok ;
0001-01-01 02:30:17 +02:30
const char * ptr ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
num_interfaces = 1 ;
2005-09-30 10:37:51 +04:00
for ( ptr = ports ; next_token ( & ptr , tok , " \t , " , sizeof ( tok ) ) ; ) {
0001-01-01 02:30:17 +02:30
unsigned port = atoi ( tok ) ;
if ( port = = 0 ) continue ;
/* open an incoming socket */
s = open_socket_in ( SOCK_STREAM , port , 0 ,
interpret_addr ( lp_socket_address ( ) ) , True ) ;
if ( s = = - 1 )
return ( False ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* ready to listen */
set_socket_options ( s , " SO_KEEPALIVE " ) ;
set_socket_options ( s , user_socket_options ) ;
0001-01-01 02:30:17 +02:30
/* Set server socket to non-blocking for the accept. */
set_blocking ( s , False ) ;
0001-01-01 02:30:17 +02:30
if ( listen ( s , SMBD_LISTEN_BACKLOG ) = = - 1 ) {
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " open_sockets_smbd: listen: %s \n " ,
strerror ( errno ) ) ) ;
close ( s ) ;
return False ;
}
fd_listenset [ num_sockets ] = s ;
FD_SET ( s , & listen_set ) ;
2004-11-19 22:32:31 +03:00
maxfd = MAX ( maxfd , s ) ;
0001-01-01 02:30:17 +02:30
num_sockets + + ;
if ( num_sockets > = FD_SETSIZE ) {
DEBUG ( 0 , ( " open_sockets_smbd: Too many sockets to bind to \n " ) ) ;
return False ;
}
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
SAFE_FREE ( ports ) ;
0001-01-01 02:30:17 +02:30
/* Listen to messages */
message_register ( MSG_SMB_SAM_SYNC , msg_sam_sync ) ;
message_register ( MSG_SMB_SAM_REPL , msg_sam_repl ) ;
0001-01-01 02:30:17 +02:30
message_register ( MSG_SHUTDOWN , msg_exit_server ) ;
2005-12-13 21:11:50 +03:00
message_register ( MSG_SMB_FILE_RENAME , msg_file_was_renamed ) ;
2006-02-04 01:19:41 +03:00
message_register ( MSG_SMB_CONF_UPDATED , smb_conf_updated ) ;
0001-01-01 02:30:17 +02:30
2006-04-04 04:27:50 +04:00
# ifdef DEVELOPER
message_register ( MSG_SMB_INJECT_FAULT , msg_inject_fault ) ;
# endif
0001-01-01 02:30:17 +02:30
/* now accept incoming connections - forking a new process
for each incoming connection */
DEBUG ( 2 , ( " waiting for a connection \n " ) ) ;
while ( 1 ) {
fd_set lfds ;
int num ;
0001-01-01 02:30:17 +02:30
/* Free up temporary memory from the main smbd. */
2006-02-20 20:59:58 +03:00
lp_TALLOC_FREE ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Ensure we respond to PING and DEBUG messages from the main smbd. */
message_dispatch ( ) ;
0001-01-01 02:30:17 +02:30
memcpy ( ( char * ) & lfds , ( char * ) & listen_set ,
sizeof ( listen_set ) ) ;
2004-11-19 22:32:31 +03:00
num = sys_select ( maxfd + 1 , & lfds , NULL , NULL , NULL ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( num = = - 1 & & errno = = EINTR ) {
0001-01-01 02:30:17 +02:30
if ( got_sig_term ) {
2006-04-11 02:47:09 +04:00
exit_server_cleanly ( NULL ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/* check for sighup processing */
if ( reload_after_sighup ) {
0001-01-01 02:30:17 +02:30
change_to_root_user ( ) ;
0001-01-01 02:30:17 +02:30
DEBUG ( 1 , ( " Reloading services after SIGHUP \n " ) ) ;
reload_services ( False ) ;
0001-01-01 02:30:17 +02:30
reload_after_sighup = 0 ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
continue ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* check if we need to reload services */
check_reload ( time ( NULL ) ) ;
0001-01-01 02:30:17 +02:30
/* Find the sockets that are read-ready -
accept on these . */
for ( ; num > 0 ; num - - ) {
struct sockaddr addr ;
0001-01-01 02:30:17 +02:30
socklen_t in_addrlen = sizeof ( addr ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
s = - 1 ;
0001-01-01 02:30:17 +02:30
for ( i = 0 ; i < num_sockets ; i + + ) {
0001-01-01 02:30:17 +02:30
if ( FD_ISSET ( fd_listenset [ i ] , & lfds ) ) {
s = fd_listenset [ i ] ;
/* Clear this so we don't look
at it again . */
FD_CLR ( fd_listenset [ i ] , & lfds ) ;
0001-01-01 02:30:17 +02:30
break ;
}
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
smbd_set_server_fd ( accept ( s , & addr , & in_addrlen ) ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( smbd_server_fd ( ) = = - 1 & & errno = = EINTR )
0001-01-01 02:30:17 +02:30
continue ;
0001-01-01 02:30:17 +02:30
if ( smbd_server_fd ( ) = = - 1 ) {
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " open_sockets_smbd: accept: %s \n " ,
0001-01-01 02:30:17 +02:30
strerror ( errno ) ) ) ;
continue ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Ensure child is set to blocking mode */
set_blocking ( smbd_server_fd ( ) , True ) ;
0001-01-01 02:30:17 +02:30
if ( smbd_server_fd ( ) ! = - 1 & & interactive )
return True ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( allowable_number_of_smbd_processes ( ) & & smbd_server_fd ( ) ! = - 1 & & sys_fork ( ) = = 0 ) {
0001-01-01 02:30:17 +02:30
/* Child code ... */
/* close the listening socket(s) */
0001-01-01 02:30:17 +02:30
for ( i = 0 ; i < num_sockets ; i + + )
0001-01-01 02:30:17 +02:30
close ( fd_listenset [ i ] ) ;
/* close our standard file
descriptors */
0001-01-01 02:30:17 +02:30
close_low_fds ( False ) ;
0001-01-01 02:30:17 +02:30
am_parent = 0 ;
0001-01-01 02:30:17 +02:30
set_socket_options ( smbd_server_fd ( ) , " SO_KEEPALIVE " ) ;
0001-01-01 02:30:17 +02:30
set_socket_options ( smbd_server_fd ( ) , user_socket_options ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* this is needed so that we get decent entries
in smbstatus for port 445 connects */
0001-01-01 02:30:17 +02:30
set_remote_machine_name ( get_peer_addr ( smbd_server_fd ( ) ) , False ) ;
0001-01-01 02:30:17 +02:30
2004-07-14 08:36:01 +04:00
/* Reset the state of the random
* number generation system , so
* children do not get the same random
* numbers as each other */
0001-01-01 02:30:17 +02:30
2004-07-14 08:36:01 +04:00
set_need_random_reseed ( ) ;
0001-01-01 02:30:17 +02:30
/* tdb needs special fork handling - remove CLEAR_IF_FIRST flags */
2006-04-07 02:31:45 +04:00
if ( tdb_reopen_all ( 1 ) = = - 1 ) {
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " tdb_reopen_all failed. \n " ) ) ;
0001-01-01 02:30:17 +02:30
smb_panic ( " tdb_reopen_all failed. " ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
return True ;
}
/* The parent doesn't need this socket */
0001-01-01 02:30:17 +02:30
close ( smbd_server_fd ( ) ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Sun May 6 18:56:14 2001 ackley@cs.unm.edu:
Clear the closed fd info out of server_fd - -
and more importantly , out of client_fd in
util_sock . c , to avoid a possible
getpeername failure if we reopen the logs
and use % I in the filename .
*/
smbd_set_server_fd ( - 1 ) ;
0001-01-01 02:30:17 +02:30
/* Force parent to check log size after
* spawning child . Fix from
* klausr @ ITAP . Physik . Uni - Stuttgart . De . The
* parent smbd will log to logserver . smb . It
* writes only two messages for each child
* started / finished . But each child writes ,
* say , 50 messages also in logserver . smb ,
* begining with the debug_count of the
* parent , before the child opens its own log
* file logserver . client . In a worst case
* scenario the size of logserver . smb would be
* checked after about 50 * 50 = 2500 messages
* ( ca . 100 kb ) .
* */
force_check_log_size ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
} /* end for num */
} /* end while 1 */
0001-01-01 02:30:17 +02:30
/* NOTREACHED return True; */
0001-01-01 02:30:17 +02:30
}
2005-01-05 19:20:35 +03:00
/****************************************************************************
Reload printers
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void reload_printers ( void )
{
int snum ;
int n_services = lp_numservices ( ) ;
int pnum = lp_servicenumber ( PRINTERS_NAME ) ;
const char * pname ;
pcap_cache_reload ( ) ;
/* remove stale printers */
for ( snum = 0 ; snum < n_services ; snum + + ) {
/* avoid removing PRINTERS_NAME or non-autoloaded printers */
if ( snum = = pnum | | ! ( lp_snum_ok ( snum ) & & lp_print_ok ( snum ) & &
lp_autoloaded ( snum ) ) )
continue ;
pname = lp_printername ( snum ) ;
if ( ! pcap_printername_ok ( pname ) ) {
DEBUG ( 3 , ( " removing stale printer %s \n " , pname ) ) ;
if ( is_printer_published ( NULL , snum , NULL ) )
nt_printer_publish ( NULL , snum , SPOOL_DS_UNPUBLISH ) ;
del_a_printer ( pname ) ;
lp_killservice ( snum ) ;
}
}
load_printers ( ) ;
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
0001-01-01 02:30:17 +02:30
Reload the services file .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
BOOL reload_services ( BOOL test )
{
0001-01-01 02:30:17 +02:30
BOOL ret ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( lp_loaded ( ) ) {
pstring fname ;
pstrcpy ( fname , lp_configfile ( ) ) ;
0001-01-01 02:30:17 +02:30
if ( file_exist ( fname , NULL ) & &
! strcsequal ( fname , dyn_CONFIGFILE ) ) {
pstrcpy ( dyn_CONFIGFILE , fname ) ;
0001-01-01 02:30:17 +02:30
test = False ;
0001-01-01 02:30:17 +02:30
}
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
reopen_logs ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( test & & ! lp_file_list_changed ( ) )
return ( True ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
lp_killunused ( conn_snum_used ) ;
2004-11-12 20:39:32 +03:00
2006-01-29 01:53:04 +03:00
ret = lp_load ( dyn_CONFIGFILE , False , False , True , True ) ;
0001-01-01 02:30:17 +02:30
2005-01-05 19:20:35 +03:00
reload_printers ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* perhaps the config filename is now set */
if ( ! test )
reload_services ( True ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
reopen_logs ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
load_interfaces ( ) ;
0001-01-01 02:30:17 +02:30
2004-06-15 22:36:45 +04:00
if ( smbd_server_fd ( ) ! = - 1 ) {
set_socket_options ( smbd_server_fd ( ) , " SO_KEEPALIVE " ) ;
set_socket_options ( smbd_server_fd ( ) , user_socket_options ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
mangle_reset_cache ( ) ;
0001-01-01 02:30:17 +02:30
reset_stat_cache ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* this forces service parameters to be flushed */
2004-06-15 22:36:45 +04:00
set_current_service ( NULL , 0 , True ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
return ( ret ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
0001-01-01 02:30:17 +02:30
Exit the server .
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
2006-04-04 04:27:50 +04:00
/* Reasons for shutting down a server process. */
enum server_exit_reason { SERVER_EXIT_NORMAL , SERVER_EXIT_ABNORMAL } ;
static void exit_server_common ( enum server_exit_reason how ,
const char * const reason ) NORETURN_ATTRIBUTE ;
static void exit_server_common ( enum server_exit_reason how ,
const char * const reason )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
static int firsttime = 1 ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! firsttime )
exit ( 0 ) ;
0001-01-01 02:30:17 +02:30
firsttime = 0 ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
change_to_root_user ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( negprot_global_auth_context ) {
0001-01-01 02:30:17 +02:30
( negprot_global_auth_context - > free ) ( & negprot_global_auth_context ) ;
0001-01-01 02:30:17 +02:30
}
This is another rather major change to the samba authenticaion
subystem.
The particular aim is to modularized the interface - so that we
can have arbitrary password back-ends.
This code adds one such back-end, a 'winbind' module to authenticate
against the winbind_auth_crap functionality. While fully-functional
this code is mainly useful as a demonstration, because we don't get
back the info3 as we would for direct ntdomain authentication.
This commit introduced the new 'auth methods' parameter, in the
spirit of the 'auth order' discussed on the lists. It is renamed
because not all the methods may be consulted, even if previous
methods fail - they may not have a suitable challenge for example.
Also, we have a 'local' authentication method, for old-style
'unix if plaintext, sam if encrypted' authentication and a
'guest' module to handle guest logins in a single place.
While this current design is not ideal, I feel that it does
provide a better infrastructure than the current design, and can
be built upon.
The following parameters have changed:
- use rhosts =
This has been replaced by the 'rhosts' authentication method,
and can be specified like 'auth methods = guest rhosts'
- hosts equiv =
This needs both this parameter and an 'auth methods' entry
to be effective. (auth methods = guest hostsequiv ....)
- plaintext to smbpasswd =
This is replaced by specifying 'sam' rather than 'local'
in the auth methods.
The security = parameter is unchanged, and now provides defaults
for the 'auth methods' parameter.
The available auth methods are:
guest
rhosts
hostsequiv
sam (passdb direct hash access)
unix (PAM, crypt() etc)
local (the combination of the above, based on encryption)
smbserver (old security=server)
ntdomain (old security=domain)
winbind (use winbind to cache DC connections)
Assistance in testing, or the production of new and interesting
authentication modules is always appreciated.
Andrew Bartlett
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
conn_close_all ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
invalidate_all_vuids ( ) ;
0001-01-01 02:30:17 +02:30
print_notify_send_messages ( 3 ) ; /* 3 second timeout. */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* delete our entry in the connections database. */
0001-01-01 02:30:17 +02:30
yield_connection ( NULL , " " ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
respond_to_all_remaining_local_messages ( ) ;
0001-01-01 02:30:17 +02:30
decrement_smbd_process_count ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
# ifdef WITH_DFS
0001-01-01 02:30:17 +02:30
if ( dcelogin_atmost_once ) {
dfs_unlogin ( ) ;
}
0001-01-01 02:30:17 +02:30
# endif
0001-01-01 02:30:17 +02:30
2006-04-04 04:27:50 +04:00
locking_end ( ) ;
printing_end ( ) ;
if ( how ! = SERVER_EXIT_NORMAL ) {
0001-01-01 02:30:17 +02:30
int oldlevel = DEBUGLEVEL ;
2005-06-28 02:53:56 +04:00
char * last_inbuf = get_InBuffer ( ) ;
2006-04-04 04:27:50 +04:00
0001-01-01 02:30:17 +02:30
DEBUGLEVEL = 10 ;
2006-04-04 04:27:50 +04:00
DEBUGSEP ( 0 ) ;
DEBUG ( 0 , ( " Abnormal server exit: %s \n " ,
reason ? reason : " no explanation provided " ) ) ;
DEBUGSEP ( 0 ) ;
log_stack_trace ( ) ;
if ( last_inbuf ) {
DEBUG ( 0 , ( " Last message was %s \n " , LAST_MESSAGE ( ) ) ) ;
0001-01-01 02:30:17 +02:30
show_msg ( last_inbuf ) ;
2006-04-04 04:27:50 +04:00
}
0001-01-01 02:30:17 +02:30
DEBUGLEVEL = oldlevel ;
0001-01-01 02:30:17 +02:30
# if DUMP_CORE
2006-04-01 09:41:34 +04:00
dump_core ( ) ;
0001-01-01 02:30:17 +02:30
# endif
0001-01-01 02:30:17 +02:30
2006-04-04 04:27:50 +04:00
} else {
DEBUG ( 3 , ( " Server exit (%s) \n " ,
( reason ? reason : " normal exit " ) ) ) ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
exit ( 0 ) ;
0001-01-01 02:30:17 +02:30
}
2006-04-04 04:27:50 +04:00
void exit_server ( const char * const explanation )
{
exit_server_common ( SERVER_EXIT_ABNORMAL , explanation ) ;
}
2006-04-11 02:47:09 +04:00
void exit_server_cleanly ( const char * const explanation )
2006-04-04 04:27:50 +04:00
{
2006-04-11 02:47:09 +04:00
exit_server_common ( SERVER_EXIT_NORMAL , explanation ) ;
2006-04-04 04:27:50 +04:00
}
void exit_server_fault ( void )
{
exit_server ( " critical server fault " ) ;
}
0001-01-01 02:30:17 +02:30
/****************************************************************************
0001-01-01 02:30:17 +02:30
Initialise connect , service and file structs .
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
static BOOL init_structs ( void )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
/*
* Set the machine NETBIOS name if not already
* set from the config file .
*/
0001-01-01 02:30:17 +02:30
if ( ! init_names ( ) )
return False ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
conn_init ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
file_init ( ) ;
0001-01-01 02:30:17 +02:30
/* for RPC pipes */
init_rpc_pipe_hnd ( ) ;
0001-01-01 02:30:17 +02:30
init_dptrs ( ) ;
0001-01-01 02:30:17 +02:30
secrets_init ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
return True ;
0001-01-01 02:30:17 +02:30
}
/****************************************************************************
0001-01-01 02:30:17 +02:30
main program .
0001-01-01 02:30:17 +02:30
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Declare prototype for build_options() to avoid having to run it through
mkproto . h . Mixing $ ( builddir ) and $ ( srcdir ) source files in the current
prototype generation system is too complicated . */
void build_options ( BOOL screen ) ;
0001-01-01 02:30:17 +02:30
int main ( int argc , const char * argv [ ] )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
/* shall I run as a daemon */
0001-01-01 02:30:17 +02:30
static BOOL is_daemon = False ;
static BOOL interactive = False ;
0001-01-01 02:30:17 +02:30
static BOOL Fork = True ;
2006-03-21 16:16:50 +03:00
static BOOL no_process_group = False ;
0001-01-01 02:30:17 +02:30
static BOOL log_stdout = False ;
0001-01-01 02:30:17 +02:30
static char * ports = NULL ;
0001-01-01 02:30:17 +02:30
int opt ;
0001-01-01 02:30:17 +02:30
poptContext pc ;
struct poptOption long_options [ ] = {
POPT_AUTOHELP
{ " daemon " , ' D ' , POPT_ARG_VAL , & is_daemon , True , " Become a daemon (default) " } ,
{ " interactive " , ' i ' , POPT_ARG_VAL , & interactive , True , " Run interactive (not a daemon) " } ,
0001-01-01 02:30:17 +02:30
{ " foreground " , ' F ' , POPT_ARG_VAL , & Fork , False , " Run daemon in foreground (for daemontools & etc) " } ,
2006-03-21 16:16:50 +03:00
{ " no-process-group " , 0 , POPT_ARG_VAL , & no_process_group , True , " Don't create a new process group " } ,
0001-01-01 02:30:17 +02:30
{ " log-stdout " , ' S ' , POPT_ARG_VAL , & log_stdout , True , " Log to stdout " } ,
0001-01-01 02:30:17 +02:30
{ " build-options " , ' b ' , POPT_ARG_NONE , NULL , ' b ' , " Print build options " } ,
{ " port " , ' p ' , POPT_ARG_STRING , & ports , 0 , " Listen on the specified ports " } ,
0001-01-01 02:30:17 +02:30
POPT_COMMON_SAMBA
0001-01-01 02:30:17 +02:30
{ NULL }
} ;
0001-01-01 02:30:17 +02:30
2005-12-29 16:10:33 +03:00
load_case_tables ( ) ;
0001-01-01 02:30:17 +02:30
# ifdef HAVE_SET_AUTH_PARAMETERS
0001-01-01 02:30:17 +02:30
set_auth_parameters ( argc , argv ) ;
0001-01-01 02:30:17 +02:30
# endif
0001-01-01 02:30:17 +02:30
pc = poptGetContext ( " smbd " , argc , argv , long_options , 0 ) ;
while ( ( opt = poptGetNextOpt ( pc ) ) ! = - 1 ) {
0001-01-01 02:30:17 +02:30
switch ( opt ) {
0001-01-01 02:30:17 +02:30
case ' b ' :
0001-01-01 02:30:17 +02:30
build_options ( True ) ; /* Display output to screen as well as debug */
0001-01-01 02:30:17 +02:30
exit ( 0 ) ;
break ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
}
poptFreeContext ( pc ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
# ifdef HAVE_SETLUID
/* needed for SecureWare on SCO */
setluid ( 0 ) ;
# endif
0001-01-01 02:30:17 +02:30
sec_init ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
set_remote_machine_name ( " smbd " , False ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( interactive ) {
Fork = False ;
log_stdout = True ;
}
2005-05-03 11:33:49 +04:00
if ( interactive & & ( DEBUGLEVEL > = 9 ) ) {
talloc_enable_leak_report ( ) ;
}
0001-01-01 02:30:17 +02:30
if ( log_stdout & & Fork ) {
DEBUG ( 0 , ( " ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i) \n " ) ) ;
exit ( 1 ) ;
}
setup_logging ( argv [ 0 ] , log_stdout ) ;
0001-01-01 02:30:17 +02:30
/* we want to re-seed early to prevent time delays causing
client problems at a later date . ( tridge ) */
2004-07-14 08:36:01 +04:00
generate_random_buffer ( NULL , 0 ) ;
0001-01-01 02:30:17 +02:30
/* make absolutely sure we run as root - to handle cases where people
are crazy enough to have it setuid */
gain_root_privilege ( ) ;
gain_root_group_privilege ( ) ;
2006-04-04 04:27:50 +04:00
fault_setup ( ( void ( * ) ( void * ) ) exit_server_fault ) ;
dump_core_setup ( " smbd " ) ;
0001-01-01 02:30:17 +02:30
CatchSignal ( SIGTERM , SIGNAL_CAST sig_term ) ;
CatchSignal ( SIGHUP , SIGNAL_CAST sig_hup ) ;
0001-01-01 02:30:17 +02:30
/* we are never interested in SIGPIPE */
BlockSignals ( True , SIGPIPE ) ;
# if defined(SIGFPE)
/* we are never interested in SIGFPE */
BlockSignals ( True , SIGFPE ) ;
# endif
0001-01-01 02:30:17 +02:30
# if defined(SIGUSR2)
/* We are no longer interested in USR2 */
BlockSignals ( True , SIGUSR2 ) ;
# endif
0001-01-01 02:30:17 +02:30
/* POSIX demands that signals are inherited. If the invoking process has
* these signals masked , we will have problems , as we won ' t recieve them . */
BlockSignals ( False , SIGHUP ) ;
BlockSignals ( False , SIGUSR1 ) ;
0001-01-01 02:30:17 +02:30
BlockSignals ( False , SIGTERM ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* we want total control over the permissions on created files,
so set our umask to 0 */
umask ( 0 ) ;
0001-01-01 02:30:17 +02:30
init_sec_ctx ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
reopen_logs ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
DEBUG ( 0 , ( " smbd version %s started. \n " , SAMBA_VERSION_STRING ) ) ;
2005-10-07 19:43:32 +04:00
DEBUGADD ( 0 , ( " %s \n " , COPYRIGHT_STARTUP_MESSAGE ) ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
DEBUG ( 2 , ( " uid=%d gid=%d euid=%d egid=%d \n " ,
( int ) getuid ( ) , ( int ) getgid ( ) , ( int ) geteuid ( ) , ( int ) getegid ( ) ) ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Output the build options to the debug log */
build_options ( False ) ;
0001-01-01 02:30:17 +02:30
if ( sizeof ( uint16 ) < 2 | | sizeof ( uint32 ) < 4 ) {
DEBUG ( 0 , ( " ERROR: Samba is not configured correctly for the word size on your machine \n " ) ) ;
exit ( 1 ) ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/*
* Do this before reload_services .
*/
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! reload_services ( False ) )
return ( - 1 ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
init_structs ( ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
# ifdef WITH_PROFILE
if ( ! profile_setup ( False ) ) {
DEBUG ( 0 , ( " ERROR: failed to setup profiling \n " ) ) ;
return - 1 ;
}
# endif
0001-01-01 02:30:17 +02:30
DEBUG ( 3 , ( " loaded services \n " ) ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! is_daemon & & ! is_a_socket ( 0 ) ) {
0001-01-01 02:30:17 +02:30
if ( ! interactive )
DEBUG ( 0 , ( " standard input is not a socket, assuming -D option \n " ) ) ;
/*
* Setting is_daemon here prevents us from eventually calling
* the open_sockets_inetd ( )
*/
0001-01-01 02:30:17 +02:30
is_daemon = True ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( is_daemon & & ! interactive ) {
0001-01-01 02:30:17 +02:30
DEBUG ( 3 , ( " Becoming a daemon. \n " ) ) ;
2006-03-21 16:16:50 +03:00
become_daemon ( Fork , no_process_group ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
# if HAVE_SETPGID
/*
* If we ' re interactive we want to set our own process group for
* signal management .
*/
2006-04-10 19:33:04 +04:00
if ( interactive & & ! no_process_group )
0001-01-01 02:30:17 +02:30
setpgid ( ( pid_t ) 0 , ( pid_t ) 0 ) ;
# endif
0001-01-01 02:30:17 +02:30
if ( ! directory_exist ( lp_lockdir ( ) , NULL ) )
0001-01-01 02:30:17 +02:30
mkdir ( lp_lockdir ( ) , 0755 ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( is_daemon )
0001-01-01 02:30:17 +02:30
pidfile_create ( " smbd " ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
0001-01-01 02:30:17 +02:30
if ( ! message_init ( ) )
0001-01-01 02:30:17 +02:30
exit ( 1 ) ;
0001-01-01 02:30:17 +02:30
2006-04-18 13:02:58 +04:00
/* Initialize our global sam sid first -- quite a lot of the other
* initialization routines further down depend on it .
*/
/* Initialise the password backed before the global_sam_sid
to ensure that we fetch from ldap before we make a domain sid up */
if ( ! initialize_password_db ( False ) )
exit ( 1 ) ;
/* Fail gracefully if we can't open secrets.tdb */
if ( ! secrets_init ( ) ) {
DEBUG ( 0 , ( " ERROR: smbd can not open secrets.tdb \n " ) ) ;
exit ( 1 ) ;
}
if ( ! get_global_sam_sid ( ) ) {
DEBUG ( 0 , ( " ERROR: Samba cannot create a SAM SID. \n " ) ) ;
exit ( 1 ) ;
}
0001-01-01 02:30:17 +02:30
if ( ! session_init ( ) )
exit ( 1 ) ;
if ( conn_tdb_ctx ( ) = = NULL )
exit ( 1 ) ;
if ( ! locking_init ( 0 ) )
exit ( 1 ) ;
namecache_enable ( ) ;
if ( ! init_registry ( ) )
exit ( 1 ) ;
2005-06-16 04:46:43 +04:00
#if 0
2005-06-14 07:17:31 +04:00
if ( ! init_svcctl_db ( ) )
exit ( 1 ) ;
2005-06-16 04:46:43 +04:00
# endif
2005-06-14 07:17:31 +04:00
0001-01-01 02:30:17 +02:30
if ( ! print_backend_init ( ) )
exit ( 1 ) ;
2006-02-04 01:19:41 +03:00
if ( ! init_guest_info ( ) ) {
DEBUG ( 0 , ( " ERROR: failed to setup guest info. \n " ) ) ;
return - 1 ;
}
0001-01-01 02:30:17 +02:30
/* Setup the main smbd so that we can get messages. */
2004-08-18 17:55:58 +04:00
/* don't worry about general printing messages here */
0001-01-01 02:30:17 +02:30
claim_connection ( NULL , " " , 0 , True , FLAG_MSG_GENERAL | FLAG_MSG_SMBD ) ;
0001-01-01 02:30:17 +02:30
2004-05-27 19:38:54 +04:00
/* only start the background queue daemon if we are
running as a daemon - - bad things will happen if
smbd is launched via inetd and we fork a copy of
ourselves here */
2004-11-30 18:52:46 +03:00
if ( is_daemon & & ! interactive )
2004-05-27 19:38:54 +04:00
start_background_queue ( ) ;
0001-01-01 02:30:17 +02:30
2006-03-23 02:49:09 +03:00
/* Always attempt to initialize DMAPI. We will only use it later if
* lp_dmapi_support is set on the share , but we need a single global
* session to work with .
*/
dmapi_init_session ( ) ;
0001-01-01 02:30:17 +02:30
if ( ! open_sockets_smbd ( is_daemon , interactive , ports ) )
0001-01-01 02:30:17 +02:30
exit ( 1 ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/*
0001-01-01 02:30:17 +02:30
* everything after this point is run after the fork ( )
0001-01-01 02:30:17 +02:30
*/
0001-01-01 02:30:17 +02:30
static_init_rpc ;
init_modules ( ) ;
0001-01-01 02:30:17 +02:30
/* possibly reload the services file. */
reload_services ( True ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( ! init_account_policy ( ) ) {
DEBUG ( 0 , ( " Could not open account policy tdb. \n " ) ) ;
0001-01-01 02:30:17 +02:30
exit ( 1 ) ;
}
0001-01-01 02:30:17 +02:30
if ( * lp_rootdir ( ) ) {
if ( sys_chroot ( lp_rootdir ( ) ) = = 0 )
DEBUG ( 2 , ( " Changed root to %s \n " , lp_rootdir ( ) ) ) ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Setup oplocks */
0001-01-01 02:30:17 +02:30
if ( ! init_oplocks ( ) )
0001-01-01 02:30:17 +02:30
exit ( 1 ) ;
0001-01-01 02:30:17 +02:30
totally rewrote the async signal, notification and oplock notification
handling in Samba. This was needed due to several limitations and
races in the previous code - as a side effect the new code is much
cleaner :)
in summary:
- changed sys_select() to avoid a signal/select race condition. It is a
rare race but once we have signals doing notification and oplocks it
is important.
- changed our main processing loop to take advantage of the new
sys_select semantics
- split the notify code into implementaion dependent and general
parts. Added the following structure that defines an implementation:
struct cnotify_fns {
void * (*register_notify)(connection_struct *conn, char *path, uint32 flags);
BOOL (*check_notify)(connection_struct *conn, uint16 vuid, char *path, uint32 flags, void *data, time_t t);
void (*remove_notify)(void *data);
};
then I wrote two implementations, one using hash/poll (like our old
code) and the other using the new Linux kernel change notify. It
should be easy to add other change notify implementations by creating
a sructure of the above type.
- fixed a bug in change notify where we were returning the wrong error
code.
- rewrote the core change notify code to be much simpler
- moved to real-time signals for leases and change notify
Amazingly, it all seems to work. I was very surprised!
0001-01-01 02:30:17 +02:30
/* Setup change notify */
0001-01-01 02:30:17 +02:30
if ( ! init_change_notify ( ) )
totally rewrote the async signal, notification and oplock notification
handling in Samba. This was needed due to several limitations and
races in the previous code - as a side effect the new code is much
cleaner :)
in summary:
- changed sys_select() to avoid a signal/select race condition. It is a
rare race but once we have signals doing notification and oplocks it
is important.
- changed our main processing loop to take advantage of the new
sys_select semantics
- split the notify code into implementaion dependent and general
parts. Added the following structure that defines an implementation:
struct cnotify_fns {
void * (*register_notify)(connection_struct *conn, char *path, uint32 flags);
BOOL (*check_notify)(connection_struct *conn, uint16 vuid, char *path, uint32 flags, void *data, time_t t);
void (*remove_notify)(void *data);
};
then I wrote two implementations, one using hash/poll (like our old
code) and the other using the new Linux kernel change notify. It
should be easy to add other change notify implementations by creating
a sructure of the above type.
- fixed a bug in change notify where we were returning the wrong error
code.
- rewrote the core change notify code to be much simpler
- moved to real-time signals for leases and change notify
Amazingly, it all seems to work. I was very surprised!
0001-01-01 02:30:17 +02:30
exit ( 1 ) ;
2005-06-28 02:53:56 +04:00
/* Setup aio signal handler. */
initialize_async_io_handler ( ) ;
0001-01-01 02:30:17 +02:30
/* re-initialise the timezone */
TimeInit ( ) ;
/* register our message handlers */
message_register ( MSG_SMB_FORCE_TDIS , msg_force_tdis ) ;
0001-01-01 02:30:17 +02:30
smbd_process ( ) ;
2006-04-04 04:27:50 +04:00
0001-01-01 02:30:17 +02:30
namecache_shutdown ( ) ;
2004-11-06 00:45:02 +03:00
2006-04-11 02:47:09 +04:00
exit_server_cleanly ( NULL ) ;
0001-01-01 02:30:17 +02:30
return ( 0 ) ;
0001-01-01 02:30:17 +02:30
}