1996-05-04 11:50:46 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1996-05-04 11:50:46 +04:00
Main SMB server routines
2002-01-15 05:15:58 +03:00
Copyright ( C ) Andrew Tridgell 1992 - 1998
Copyright ( C ) Martin Pool 2002
2003-04-14 07:30:20 +04:00
Copyright ( C ) Jelmer Vernooij 2002 - 2003
1996-05-04 11:50:46 +04:00
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"
2005-09-08 05:05:16 +04:00
# ifdef HAVE_SYS_PRCTL_H
# include <sys/prctl.h>
# endif
2004-02-08 14:00:25 +03:00
static int am_parent = 1 ;
1996-12-10 21:00:22 +03:00
1996-05-04 11:50:46 +04:00
/* 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 ;
1996-05-04 11:50:46 +04:00
extern pstring user_socket_options ;
2002-09-25 19:19:00 +04:00
extern SIG_ATOMIC_T got_sig_term ;
extern SIG_ATOMIC_T reload_after_sighup ;
1996-05-04 11:50:46 +04:00
1998-07-29 07:08:05 +04:00
# ifdef WITH_DFS
1998-03-04 04:50:47 +03:00
extern int dcelogin_atmost_once ;
1998-07-29 07:08:05 +04:00
# endif /* WITH_DFS */
1998-03-04 04:50:47 +03:00
2000-04-11 17:55:53 +04:00
/* 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
*/
2000-05-10 02:05:39 +04:00
static int server_fd = - 1 ;
2000-04-11 17:55:53 +04:00
int smbd_server_fd ( void )
{
return server_fd ;
}
2002-07-15 14:35:28 +04:00
static void smbd_set_server_fd ( int fd )
2000-04-11 17:55:53 +04:00
{
server_fd = fd ;
client_setfd ( fd ) ;
}
1996-12-10 21:00:22 +03:00
/****************************************************************************
2002-03-14 05:15:08 +03:00
Terminate signal .
1996-12-10 21:00:22 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-03-14 05:15:08 +03:00
static void sig_term ( void )
{
got_sig_term = 1 ;
2005-06-09 19:20:11 +04:00
sys_select_signal ( SIGTERM ) ;
2002-03-14 05:15:08 +03:00
}
/****************************************************************************
Catch a sighup .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void sig_hup ( int sig )
1996-12-10 21:00:22 +03:00
{
2002-03-14 05:15:08 +03:00
reload_after_sighup = 1 ;
2005-06-09 19:20:11 +04:00
sys_select_signal ( SIGHUP ) ;
1996-12-10 21:00:22 +03:00
}
1998-08-17 18:11:44 +04:00
1996-12-10 21:00:22 +03:00
/****************************************************************************
Send a SIGTERM to our process group .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-03-14 05:15:08 +03:00
1998-09-05 09:07:05 +04:00
static void killkids ( void )
1996-12-10 21:00:22 +03:00
{
1998-08-17 18:11:44 +04:00
if ( am_parent ) kill ( 0 , SIGTERM ) ;
1996-12-10 21:00:22 +03:00
}
1996-05-04 11:50:46 +04:00
2001-08-28 10:34:53 +04:00
/****************************************************************************
2002-03-14 05:15:08 +03:00
Process a sam sync message - not sure whether to do this here or
somewhere else .
2001-08-28 10:34:53 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-03-14 05:15:08 +03:00
2005-09-30 21:13:37 +04:00
static void msg_sam_sync ( int UNUSED ( msg_type ) , struct process_id UNUSED ( pid ) ,
2002-01-09 08:27:59 +03:00
void * UNUSED ( buf ) , size_t UNUSED ( len ) )
2001-08-28 10:34:53 +04:00
{
DEBUG ( 10 , ( " ** sam sync message received, ignoring \n " ) ) ;
}
/****************************************************************************
2002-03-14 05:15:08 +03:00
Process a sam sync replicate message - not sure whether to do this here or
somewhere else .
2001-08-28 10:34:53 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-03-14 05:15:08 +03:00
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 )
2001-08-28 10:34:53 +04:00
{
uint32 low_serial ;
if ( len ! = sizeof ( uint32 ) )
return ;
low_serial = * ( ( uint32 * ) buf ) ;
DEBUG ( 3 , ( " received sam replication message, serial = 0x%04x \n " ,
low_serial ) ) ;
}
1997-09-23 23:19:06 +04:00
1997-09-30 06:38:19 +04:00
/****************************************************************************
2002-03-14 05:15:08 +03:00
Open the socket communication - inetd .
1997-09-30 06:38:19 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-03-14 05:15:08 +03:00
1998-08-17 18:11:44 +04:00
static BOOL open_sockets_inetd ( void )
1997-09-30 06:38:19 +04:00
{
1998-08-17 18:11:44 +04:00
/* Started from inetd. fd 0 is the socket. */
/* We will abort gracefully when the client or remote system
goes away */
2000-04-11 17:55:53 +04:00
smbd_set_server_fd ( dup ( 0 ) ) ;
1998-08-17 18:11:44 +04:00
/* close our standard file descriptors */
2002-08-17 19:27:10 +04:00
close_low_fds ( False ) ; /* Don't close stderr */
1998-08-17 18:11:44 +04:00
2000-04-11 17:55:53 +04:00
set_socket_options ( smbd_server_fd ( ) , " SO_KEEPALIVE " ) ;
2002-01-16 05:20:34 +03:00
set_socket_options ( smbd_server_fd ( ) , user_socket_options ) ;
1998-08-17 18:11:44 +04:00
return True ;
}
1997-10-02 03:32:22 +04:00
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 )
2002-03-29 17:28:38 +03:00
{
exit_server ( " Got a SHUTDOWN message " ) ;
}
1997-09-25 04:25:44 +04:00
2003-02-06 00:16:55 +03:00
/****************************************************************************
Have we reached the process limit ?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-02-08 11:38:42 +03:00
static BOOL allowable_number_of_smbd_processes ( void )
2003-02-06 00:16:55 +03:00
{
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 ;
}
1998-08-17 18:11:44 +04:00
/****************************************************************************
2002-03-14 05:15:08 +03:00
Open the socket communication .
1998-08-17 18:11:44 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-03-14 05:15:08 +03:00
2003-01-14 18:52:14 +03:00
static BOOL open_sockets_smbd ( BOOL is_daemon , BOOL interactive , const char * smb_ports )
1998-08-17 18:11:44 +04:00
{
int num_interfaces = iface_count ( ) ;
2002-08-17 19:27:10 +04:00
int num_sockets = 0 ;
1998-08-17 18:11:44 +04:00
int fd_listenset [ FD_SETSIZE ] ;
fd_set listen_set ;
int s ;
2004-11-19 22:32:31 +03:00
int maxfd = 0 ;
1998-08-17 18:11:44 +04:00
int i ;
2002-08-17 19:27:10 +04:00
char * ports ;
1998-08-17 18:11:44 +04:00
if ( ! is_daemon ) {
return open_sockets_inetd ( ) ;
}
1998-08-17 17:11:34 +04:00
# ifdef HAVE_ATEXIT
1998-08-17 18:11:44 +04:00
{
static int atexit_set ;
if ( atexit_set = = 0 ) {
atexit_set = 1 ;
atexit ( killkids ) ;
}
}
1998-08-17 17:11:34 +04:00
# endif
1997-10-02 07:26:07 +04:00
1998-08-17 18:11:44 +04:00
/* Stop zombies */
CatchChild ( ) ;
2002-08-17 19:27:10 +04:00
1998-08-17 18:11:44 +04:00
FD_ZERO ( & listen_set ) ;
2002-08-17 19:27:10 +04:00
/* use a reasonable default set of ports - listing on 445 and 139 */
if ( ! smb_ports ) {
ports = lp_smb_ports ( ) ;
if ( ! ports | | ! * ports ) {
2003-01-03 11:28:12 +03:00
ports = smb_xstrdup ( SMB_PORTS ) ;
} else {
ports = smb_xstrdup ( ports ) ;
2002-08-17 19:27:10 +04:00
}
} else {
2003-01-03 11:28:12 +03:00
ports = smb_xstrdup ( smb_ports ) ;
2002-08-17 19:27:10 +04:00
}
if ( lp_interfaces ( ) & & lp_bind_interfaces_only ( ) ) {
1998-08-17 18:11:44 +04:00
/* 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 ) ;
2002-08-17 19:27:10 +04:00
fstring tok ;
2002-11-13 02:20:50 +03:00
const char * ptr ;
2002-08-17 19:27:10 +04:00
1998-08-17 18:11:44 +04:00
if ( ifip = = NULL ) {
2002-08-17 19:27:10 +04:00
DEBUG ( 0 , ( " open_sockets_smbd: interface %d has NULL IP address ! \n " , i ) ) ;
1998-08-17 18:11:44 +04:00
continue ;
}
2001-08-09 16:52:05 +04:00
2005-09-30 10:37:51 +04:00
for ( ptr = ports ; next_token ( & ptr , tok , " \t , " , sizeof ( tok ) ) ; ) {
2002-08-17 19:27:10 +04:00
unsigned port = atoi ( tok ) ;
2004-11-17 22:52:26 +03:00
if ( port = = 0 ) {
continue ;
}
2002-08-17 19:27:10 +04:00
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 ) ;
2004-03-27 02:02:53 +03:00
/* Set server socket to non-blocking for the accept. */
set_blocking ( s , False ) ;
2003-10-29 07:58:48 +03:00
if ( listen ( s , SMBD_LISTEN_BACKLOG ) = = - 1 ) {
2002-08-17 19:27:10 +04:00
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 ) ;
2002-08-17 19:27:10 +04:00
num_sockets + + ;
if ( num_sockets > = FD_SETSIZE ) {
DEBUG ( 0 , ( " open_sockets_smbd: Too many sockets to bind to \n " ) ) ;
return False ;
}
1999-12-13 16:27:58 +03:00
}
1998-08-17 18:11:44 +04:00
}
} else {
/* Just bind to 0.0.0.0 - accept connections
from anywhere . */
2002-08-17 19:27:10 +04:00
fstring tok ;
2002-11-13 02:20:50 +03:00
const char * ptr ;
2002-08-17 19:27:10 +04:00
1998-08-17 18:11:44 +04:00
num_interfaces = 1 ;
2005-09-30 10:37:51 +04:00
for ( ptr = ports ; next_token ( & ptr , tok , " \t , " , sizeof ( tok ) ) ; ) {
2002-08-17 19:27:10 +04:00
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 ) ;
1999-12-13 16:27:58 +03:00
2002-08-17 19:27:10 +04:00
/* ready to listen */
set_socket_options ( s , " SO_KEEPALIVE " ) ;
set_socket_options ( s , user_socket_options ) ;
2004-03-27 02:02:53 +03:00
/* Set server socket to non-blocking for the accept. */
set_blocking ( s , False ) ;
2003-10-29 07:58:48 +03:00
if ( listen ( s , SMBD_LISTEN_BACKLOG ) = = - 1 ) {
2002-08-17 19:27:10 +04:00
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 ) ;
2002-08-17 19:27:10 +04:00
num_sockets + + ;
if ( num_sockets > = FD_SETSIZE ) {
DEBUG ( 0 , ( " open_sockets_smbd: Too many sockets to bind to \n " ) ) ;
return False ;
}
1999-12-13 16:27:58 +03:00
}
1998-08-17 18:11:44 +04:00
}
2002-08-17 19:27:10 +04:00
SAFE_FREE ( ports ) ;
2001-08-28 10:34:53 +04:00
/* Listen to messages */
message_register ( MSG_SMB_SAM_SYNC , msg_sam_sync ) ;
message_register ( MSG_SMB_SAM_REPL , msg_sam_repl ) ;
2002-03-29 17:28:38 +03:00
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 ) ;
2001-08-28 10:34:53 +04:00
1998-08-17 18:11:44 +04:00
/* 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 ;
2000-11-22 22:42:54 +03:00
/* Free up temporary memory from the main smbd. */
lp_talloc_free ( ) ;
2000-11-28 00:37:07 +03:00
/* Ensure we respond to PING and DEBUG messages from the main smbd. */
message_dispatch ( ) ;
1998-08-17 18:11:44 +04:00
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 ) ;
1998-08-17 18:11:44 +04:00
2000-07-24 10:20:13 +04:00
if ( num = = - 1 & & errno = = EINTR ) {
2002-03-14 05:15:08 +03:00
if ( got_sig_term ) {
exit_server ( " Caught TERM signal " ) ;
}
2000-07-24 10:20:13 +04:00
/* check for sighup processing */
if ( reload_after_sighup ) {
2001-10-19 00:15:12 +04:00
change_to_root_user ( ) ;
2000-07-24 10:20:13 +04:00
DEBUG ( 1 , ( " Reloading services after SIGHUP \n " ) ) ;
reload_services ( False ) ;
2002-03-14 05:15:08 +03:00
reload_after_sighup = 0 ;
2000-07-24 10:20:13 +04:00
}
1998-08-17 18:11:44 +04:00
continue ;
2000-07-24 10:20:13 +04:00
}
1998-08-17 18:11:44 +04:00
1999-12-13 16:27:58 +03:00
/* check if we need to reload services */
check_reload ( time ( NULL ) ) ;
1998-08-17 18:11:44 +04:00
/* Find the sockets that are read-ready -
accept on these . */
for ( ; num > 0 ; num - - ) {
struct sockaddr addr ;
2001-06-25 06:53:13 +04:00
socklen_t in_addrlen = sizeof ( addr ) ;
2003-02-06 00:16:55 +03:00
1998-08-17 18:11:44 +04:00
s = - 1 ;
2002-08-17 19:27:10 +04:00
for ( i = 0 ; i < num_sockets ; i + + ) {
1999-12-13 16:27:58 +03:00
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 ) ;
1999-09-08 23:37:45 +04:00
break ;
}
1998-08-17 18:11:44 +04:00
}
2000-04-11 17:55:53 +04:00
smbd_set_server_fd ( accept ( s , & addr , & in_addrlen ) ) ;
1998-08-17 18:11:44 +04:00
2000-04-11 17:55:53 +04:00
if ( smbd_server_fd ( ) = = - 1 & & errno = = EINTR )
1998-08-17 18:11:44 +04:00
continue ;
2000-04-11 17:55:53 +04:00
if ( smbd_server_fd ( ) = = - 1 ) {
2002-08-17 19:27:10 +04:00
DEBUG ( 0 , ( " open_sockets_smbd: accept: %s \n " ,
1998-08-17 18:11:44 +04:00
strerror ( errno ) ) ) ;
continue ;
}
2003-01-14 18:52:14 +03:00
2004-03-27 02:02:53 +03:00
/* Ensure child is set to blocking mode */
set_blocking ( smbd_server_fd ( ) , True ) ;
2003-01-14 18:52:14 +03:00
if ( smbd_server_fd ( ) ! = - 1 & & interactive )
return True ;
1998-08-17 18:11:44 +04:00
2003-02-06 00:16:55 +03:00
if ( allowable_number_of_smbd_processes ( ) & & smbd_server_fd ( ) ! = - 1 & & sys_fork ( ) = = 0 ) {
1998-08-17 18:11:44 +04:00
/* Child code ... */
/* close the listening socket(s) */
2002-08-17 19:27:10 +04:00
for ( i = 0 ; i < num_sockets ; i + + )
1998-08-17 18:11:44 +04:00
close ( fd_listenset [ i ] ) ;
/* close our standard file
descriptors */
2002-08-17 19:27:10 +04:00
close_low_fds ( False ) ;
1998-08-17 18:11:44 +04:00
am_parent = 0 ;
2000-04-11 17:55:53 +04:00
set_socket_options ( smbd_server_fd ( ) , " SO_KEEPALIVE " ) ;
2002-01-16 05:20:34 +03:00
set_socket_options ( smbd_server_fd ( ) , user_socket_options ) ;
1998-08-17 18:11:44 +04:00
2002-08-17 19:27:10 +04:00
/* this is needed so that we get decent entries
in smbstatus for port 445 connects */
2003-11-07 12:03:02 +03:00
set_remote_machine_name ( get_peer_addr ( smbd_server_fd ( ) ) , False ) ;
2002-08-17 19:27:10 +04:00
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 */
1998-09-26 03:40:49 +04:00
2004-07-14 08:36:01 +04:00
set_need_random_reseed ( ) ;
2004-02-19 04:55:24 +03:00
/* tdb needs special fork handling - remove CLEAR_IF_FIRST flags */
2002-11-01 02:41:00 +03:00
if ( tdb_reopen_all ( ) = = - 1 ) {
DEBUG ( 0 , ( " tdb_reopen_all failed. \n " ) ) ;
2004-02-19 04:55:24 +03:00
smb_panic ( " tdb_reopen_all failed. " ) ;
2002-11-01 02:41:00 +03:00
}
2001-09-19 09:43:15 +04:00
1998-08-17 18:11:44 +04:00
return True ;
}
/* The parent doesn't need this socket */
2000-04-11 17:55:53 +04:00
close ( smbd_server_fd ( ) ) ;
1998-08-17 18:11:44 +04:00
2001-05-08 04:03:45 +04:00
/* 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 ) ;
1998-08-17 18:11:44 +04:00
/* 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 ( ) ;
1998-08-17 17:11:34 +04:00
1998-08-17 18:11:44 +04:00
} /* end for num */
} /* end while 1 */
1998-08-28 00:38:53 +04:00
/* NOTREACHED return True; */
1997-11-19 02:30:49 +03:00
}
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 ( ) ;
}
1996-05-04 11:50:46 +04:00
/****************************************************************************
2002-03-14 05:15:08 +03:00
Reload the services file .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1996-05-04 11:50:46 +04:00
BOOL reload_services ( BOOL test )
{
1998-08-14 21:38:29 +04:00
BOOL ret ;
2000-03-09 01:14:30 +03:00
1998-08-14 21:38:29 +04:00
if ( lp_loaded ( ) ) {
pstring fname ;
pstrcpy ( fname , lp_configfile ( ) ) ;
2002-01-16 05:20:34 +03:00
if ( file_exist ( fname , NULL ) & &
! strcsequal ( fname , dyn_CONFIGFILE ) ) {
pstrcpy ( dyn_CONFIGFILE , fname ) ;
1998-08-17 17:11:34 +04:00
test = False ;
1998-08-14 21:38:29 +04:00
}
}
1996-05-04 11:50:46 +04:00
1998-08-17 17:11:34 +04:00
reopen_logs ( ) ;
1996-05-04 11:50:46 +04:00
1998-08-17 17:11:34 +04:00
if ( test & & ! lp_file_list_changed ( ) )
return ( True ) ;
1996-05-04 11:50:46 +04:00
1998-08-17 17:11:34 +04:00
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 ) ;
1996-05-04 11:50:46 +04:00
2005-01-05 19:20:35 +03:00
reload_printers ( ) ;
1996-05-04 11:50:46 +04:00
1998-08-17 17:11:34 +04:00
/* perhaps the config filename is now set */
if ( ! test )
reload_services ( True ) ;
1997-10-08 04:21:39 +04:00
1998-08-17 17:11:34 +04:00
reopen_logs ( ) ;
1996-05-04 11:50:46 +04:00
1998-08-17 17:11:34 +04:00
load_interfaces ( ) ;
1996-05-04 11:50:46 +04:00
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 ) ;
1998-08-14 21:38:29 +04:00
}
1998-01-31 17:31:08 +03:00
2002-04-11 06:20:56 +04:00
mangle_reset_cache ( ) ;
2000-05-10 15:45:16 +04:00
reset_stat_cache ( ) ;
1998-01-31 17:31:08 +03:00
1998-08-17 17:11:34 +04:00
/* this forces service parameters to be flushed */
2004-06-15 22:36:45 +04:00
set_current_service ( NULL , 0 , True ) ;
1998-01-31 17:31:08 +03:00
1998-08-17 17:11:34 +04:00
return ( ret ) ;
1998-01-31 17:31:08 +03:00
}
1996-05-04 11:50:46 +04:00
2004-02-12 08:24:02 +03:00
1996-05-04 11:50:46 +04:00
# if DUMP_CORE
/*******************************************************************
prepare to dump a core file - carefully !
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static BOOL dump_core ( void )
{
1998-08-17 18:11:44 +04:00
char * p ;
pstring dname ;
2002-01-15 05:15:58 +03:00
2001-12-21 01:27:05 +03:00
pstrcpy ( dname , lp_logfile ( ) ) ;
2002-01-16 05:20:34 +03:00
if ( ( p = strrchr_m ( dname , ' / ' ) ) ) * p = 0 ;
1998-08-17 18:11:44 +04:00
pstrcat ( dname , " /corefiles " ) ;
2002-01-16 05:20:34 +03:00
mkdir ( dname , 0700 ) ;
sys_chown ( dname , getuid ( ) , getgid ( ) ) ;
chmod ( dname , 0700 ) ;
if ( chdir ( dname ) ) return ( False ) ;
1998-08-17 18:11:44 +04:00
umask ( ~ ( 0700 ) ) ;
1996-05-04 11:50:46 +04:00
1998-07-29 07:08:05 +04:00
# ifdef HAVE_GETRLIMIT
1996-05-04 11:50:46 +04:00
# ifdef RLIMIT_CORE
1998-08-17 18:11:44 +04:00
{
struct rlimit rlp ;
getrlimit ( RLIMIT_CORE , & rlp ) ;
rlp . rlim_cur = MAX ( 4 * 1024 * 1024 , rlp . rlim_cur ) ;
setrlimit ( RLIMIT_CORE , & rlp ) ;
getrlimit ( RLIMIT_CORE , & rlp ) ;
DEBUG ( 3 , ( " Core limits now %d %d \n " ,
( int ) rlp . rlim_cur , ( int ) rlp . rlim_max ) ) ;
}
1996-05-04 11:50:46 +04:00
# endif
# endif
2002-01-16 05:20:34 +03:00
DEBUG ( 0 , ( " Dumping core in %s \n " , dname ) ) ;
2004-05-11 05:05:59 +04:00
/* Ensure we don't have a signal handler for abort. */
# ifdef SIGABRT
CatchSignal ( SIGABRT , SIGNAL_CAST SIG_DFL ) ;
# endif
1998-08-17 18:11:44 +04:00
abort ( ) ;
return ( True ) ;
1996-05-04 11:50:46 +04:00
}
# endif
/****************************************************************************
2002-03-14 05:15:08 +03:00
Exit the server .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-03-14 05:15:08 +03:00
2003-01-03 11:28:12 +03:00
void exit_server ( const char * reason )
1996-05-04 11:50:46 +04:00
{
1998-08-17 18:11:44 +04:00
static int firsttime = 1 ;
1996-05-04 11:50:46 +04:00
2001-10-19 00:15:12 +04:00
if ( ! firsttime )
exit ( 0 ) ;
1998-08-17 18:11:44 +04:00
firsttime = 0 ;
1998-08-17 10:13:32 +04:00
2001-10-19 00:15:12 +04:00
change_to_root_user ( ) ;
1998-08-17 18:11:44 +04:00
DEBUG ( 2 , ( " Closing connections \n " ) ) ;
2002-01-05 07:55:41 +03:00
if ( negprot_global_auth_context ) {
2002-01-09 10:52:51 +03:00
( negprot_global_auth_context - > free ) ( & negprot_global_auth_context ) ;
2002-01-05 07:55:41 +03:00
}
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
(This used to be commit 8d31eae52a9757739711dbb82035a4dfe6b40c99)
2001-11-24 15:12:38 +03:00
1998-08-17 18:11:44 +04:00
conn_close_all ( ) ;
1998-08-17 10:13:32 +04:00
2001-04-18 20:41:04 +04:00
invalidate_all_vuids ( ) ;
2003-01-31 02:55:58 +03:00
print_notify_send_messages ( 3 ) ; /* 3 second timeout. */
2002-09-25 19:19:00 +04:00
2001-01-09 00:19:15 +03:00
/* delete our entry in the connections database. */
2002-01-14 22:34:28 +03:00
yield_connection ( NULL , " " ) ;
2001-01-09 00:19:15 +03:00
2001-04-18 20:41:04 +04:00
respond_to_all_remaining_local_messages ( ) ;
2001-02-12 19:18:02 +03:00
decrement_smbd_process_count ( ) ;
1999-12-13 16:27:58 +03:00
1998-07-29 07:08:05 +04:00
# ifdef WITH_DFS
1998-08-17 18:11:44 +04:00
if ( dcelogin_atmost_once ) {
dfs_unlogin ( ) ;
}
1996-05-04 11:50:46 +04:00
# endif
1998-08-17 18:11:44 +04:00
if ( ! reason ) {
int oldlevel = DEBUGLEVEL ;
2005-06-28 02:53:56 +04:00
char * last_inbuf = get_InBuffer ( ) ;
1998-08-17 18:11:44 +04:00
DEBUGLEVEL = 10 ;
DEBUG ( 0 , ( " Last message was %s \n " , smb_fn_name ( last_message ) ) ) ;
if ( last_inbuf )
show_msg ( last_inbuf ) ;
DEBUGLEVEL = oldlevel ;
DEBUG ( 0 , ( " =============================================================== \n " ) ) ;
1996-05-04 11:50:46 +04:00
# if DUMP_CORE
1998-08-17 18:11:44 +04:00
if ( dump_core ( ) ) return ;
1996-05-04 11:50:46 +04:00
# endif
1998-08-17 18:11:44 +04:00
}
1997-01-09 21:02:17 +03:00
1998-08-17 18:11:44 +04:00
locking_end ( ) ;
2002-07-15 14:35:28 +04:00
printing_end ( ) ;
1997-01-09 21:02:17 +03:00
1998-08-17 18:11:44 +04:00
DEBUG ( 3 , ( " Server exit (%s) \n " , ( reason ? reason : " " ) ) ) ;
exit ( 0 ) ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2002-03-14 05:15:08 +03:00
Initialise connect , service and file structs .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-03-14 05:15:08 +03:00
2002-11-13 02:20:50 +03:00
static BOOL init_structs ( void )
1996-05-04 11:50:46 +04:00
{
1999-12-13 16:27:58 +03:00
/*
* Set the machine NETBIOS name if not already
* set from the config file .
*/
2002-11-13 02:20:50 +03:00
if ( ! init_names ( ) )
return False ;
1999-12-13 16:27:58 +03:00
1998-08-17 18:11:44 +04:00
conn_init ( ) ;
1999-12-13 16:27:58 +03:00
1998-08-17 18:11:44 +04:00
file_init ( ) ;
1999-12-13 16:27:58 +03:00
/* for RPC pipes */
init_rpc_pipe_hnd ( ) ;
1998-08-17 18:11:44 +04:00
init_dptrs ( ) ;
2000-05-08 14:42:21 +04:00
secrets_init ( ) ;
2002-01-26 09:24:53 +03:00
2002-11-13 02:20:50 +03:00
return True ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2002-03-14 05:15:08 +03:00
main program .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-03-14 05:15:08 +03:00
2003-05-27 06:35:53 +04:00
/* 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 ) ;
2002-11-09 20:08:58 +03:00
int main ( int argc , const char * argv [ ] )
1996-05-04 11:50:46 +04:00
{
1998-08-17 18:11:44 +04:00
/* shall I run as a daemon */
2002-11-09 20:08:58 +03:00
static BOOL is_daemon = False ;
static BOOL interactive = False ;
2003-01-03 20:39:30 +03:00
static BOOL Fork = True ;
static BOOL log_stdout = False ;
2002-11-09 20:08:58 +03:00
static char * ports = NULL ;
1998-08-17 18:11:44 +04:00
int opt ;
2002-11-09 20:08:58 +03:00
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) " } ,
2003-01-03 20:39:30 +03:00
{ " foreground " , ' F ' , POPT_ARG_VAL , & Fork , False , " Run daemon in foreground (for daemontools & etc) " } ,
{ " log-stdout " , ' S ' , POPT_ARG_VAL , & log_stdout , True , " Log to stdout " } ,
2002-11-09 20:08:58 +03:00
{ " build-options " , ' b ' , POPT_ARG_NONE , NULL , ' b ' , " Print build options " } ,
{ " port " , ' p ' , POPT_ARG_STRING , & ports , 0 , " Listen on the specified ports " } ,
2003-04-14 07:30:20 +04:00
POPT_COMMON_SAMBA
2002-11-09 20:08:58 +03:00
{ NULL }
} ;
2001-11-19 05:49:53 +03:00
2005-12-29 16:10:33 +03:00
load_case_tables ( ) ;
1998-07-29 07:08:05 +04:00
# ifdef HAVE_SET_AUTH_PARAMETERS
1998-08-17 18:11:44 +04:00
set_auth_parameters ( argc , argv ) ;
1996-05-04 11:50:46 +04:00
# endif
2002-11-09 20:08:58 +03:00
pc = poptGetContext ( " smbd " , argc , argv , long_options , 0 ) ;
while ( ( opt = poptGetNextOpt ( pc ) ) ! = - 1 ) {
1998-08-17 18:11:44 +04:00
switch ( opt ) {
2001-09-19 13:44:12 +04:00
case ' b ' :
2002-11-09 20:08:58 +03:00
build_options ( True ) ; /* Display output to screen as well as debug */
2001-09-19 13:44:12 +04:00
exit ( 0 ) ;
break ;
1998-08-17 18:11:44 +04:00
}
2002-11-09 20:08:58 +03:00
}
poptFreeContext ( pc ) ;
1996-05-04 11:50:46 +04:00
1999-12-13 16:27:58 +03:00
# ifdef HAVE_SETLUID
/* needed for SecureWare on SCO */
setluid ( 0 ) ;
# endif
2001-06-25 04:46:34 +04:00
sec_init ( ) ;
1999-12-13 16:27:58 +03:00
2003-03-18 12:52:55 +03:00
set_remote_machine_name ( " smbd " , False ) ;
1999-12-13 16:27:58 +03:00
2003-01-03 20:39:30 +03:00
if ( interactive ) {
Fork = False ;
log_stdout = True ;
}
2005-05-03 11:33:49 +04:00
if ( interactive & & ( DEBUGLEVEL > = 9 ) ) {
talloc_enable_leak_report ( ) ;
}
2003-01-03 20:39:30 +03:00
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 ) ;
1999-12-13 16:27:58 +03:00
/* 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 ) ;
1999-12-13 16:27:58 +03:00
/* 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 ( ) ;
fault_setup ( ( void ( * ) ( void * ) ) exit_server ) ;
2002-03-14 05:15:08 +03:00
CatchSignal ( SIGTERM , SIGNAL_CAST sig_term ) ;
CatchSignal ( SIGHUP , SIGNAL_CAST sig_hup ) ;
1999-12-13 16:27:58 +03:00
/* we are never interested in SIGPIPE */
BlockSignals ( True , SIGPIPE ) ;
# if defined(SIGFPE)
/* we are never interested in SIGFPE */
BlockSignals ( True , SIGFPE ) ;
# endif
2000-10-13 01:19:49 +04:00
# if defined(SIGUSR2)
/* We are no longer interested in USR2 */
BlockSignals ( True , SIGUSR2 ) ;
# endif
2001-01-25 19:36:42 +03:00
/* 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 ) ;
2002-03-14 05:15:08 +03:00
BlockSignals ( False , SIGTERM ) ;
2001-01-25 19:36:42 +03:00
1999-12-13 16:27:58 +03:00
/* we want total control over the permissions on created files,
so set our umask to 0 */
umask ( 0 ) ;
2000-06-23 09:54:49 +04:00
init_sec_ctx ( ) ;
1999-12-13 16:27:58 +03:00
1998-08-17 18:11:44 +04:00
reopen_logs ( ) ;
1996-05-04 11:50:46 +04:00
2003-08-20 21:13:38 +04:00
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 ) ) ;
1996-05-04 11:50:46 +04:00
1998-08-17 18:11:44 +04:00
DEBUG ( 2 , ( " uid=%d gid=%d euid=%d egid=%d \n " ,
( int ) getuid ( ) , ( int ) getgid ( ) , ( int ) geteuid ( ) , ( int ) getegid ( ) ) ) ;
1996-05-04 11:50:46 +04:00
2001-09-19 13:44:12 +04:00
/* Output the build options to the debug log */
build_options ( False ) ;
1998-08-17 18:11:44 +04:00
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 ) ;
}
1996-05-04 11:50:46 +04:00
1999-12-13 16:27:58 +03:00
/*
* Do this before reload_services .
*/
1999-02-08 04:46:46 +03:00
1998-08-17 18:11:44 +04:00
if ( ! reload_services ( False ) )
return ( - 1 ) ;
1996-05-04 11:50:46 +04:00
1999-02-08 04:46:46 +03:00
init_structs ( ) ;
2001-07-10 06:28:17 +04:00
2006-01-19 02:42:29 +03:00
if ( ! init_guest_info ( ) ) {
DEBUG ( 0 , ( " ERROR: failed to setup guest info. \n " ) ) ;
2004-11-06 01:53:35 +03:00
return - 1 ;
2006-01-19 02:42:29 +03:00
}
2004-11-06 01:53:35 +03:00
1999-04-01 09:22:58 +04:00
# ifdef WITH_PROFILE
if ( ! profile_setup ( False ) ) {
DEBUG ( 0 , ( " ERROR: failed to setup profiling \n " ) ) ;
return - 1 ;
}
# endif
1998-08-17 18:11:44 +04:00
DEBUG ( 3 , ( " loaded services \n " ) ) ;
1996-05-04 11:50:46 +04:00
1998-08-17 18:11:44 +04:00
if ( ! is_daemon & & ! is_a_socket ( 0 ) ) {
2002-01-30 08:45:09 +03:00
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 ( )
*/
1998-08-17 18:11:44 +04:00
is_daemon = True ;
}
1997-11-11 03:48:42 +03:00
2001-12-30 00:13:53 +03:00
if ( is_daemon & & ! interactive ) {
1998-08-17 18:11:44 +04:00
DEBUG ( 3 , ( " Becoming a daemon. \n " ) ) ;
2003-01-03 20:39:30 +03:00
become_daemon ( Fork ) ;
1998-08-17 18:11:44 +04:00
}
2000-02-07 19:22:16 +03:00
2001-12-30 04:46:38 +03:00
# if HAVE_SETPGID
/*
* If we ' re interactive we want to set our own process group for
* signal management .
*/
if ( interactive )
setpgid ( ( pid_t ) 0 , ( pid_t ) 0 ) ;
# endif
2002-12-20 23:21:31 +03:00
if ( ! directory_exist ( lp_lockdir ( ) , NULL ) )
1998-08-17 18:11:44 +04:00
mkdir ( lp_lockdir ( ) , 0755 ) ;
1996-05-04 11:50:46 +04:00
2002-12-20 23:21:31 +03:00
if ( is_daemon )
1998-08-17 18:11:44 +04:00
pidfile_create ( " smbd " ) ;
1996-08-15 19:11:34 +04:00
2004-02-19 04:55:24 +03:00
/* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
2002-12-20 23:21:31 +03:00
if ( ! message_init ( ) )
2000-10-12 23:42:18 +04:00
exit ( 1 ) ;
2002-12-20 23:21:31 +03:00
2004-02-19 04:55:24 +03:00
if ( ! session_init ( ) )
exit ( 1 ) ;
if ( conn_tdb_ctx ( ) = = NULL )
exit ( 1 ) ;
if ( ! locking_init ( 0 ) )
exit ( 1 ) ;
if ( ! share_info_db_init ( ) )
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
2002-11-01 02:41:00 +03:00
if ( ! print_backend_init ( ) )
exit ( 1 ) ;
2000-11-28 00:37:07 +03:00
/* 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 */
2002-09-25 19:19:00 +04:00
claim_connection ( NULL , " " , 0 , True , FLAG_MSG_GENERAL | FLAG_MSG_SMBD ) ;
2000-11-28 00:37:07 +03:00
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 ( ) ;
2001-10-17 03:16:00 +04:00
2003-01-14 18:52:14 +03:00
if ( ! open_sockets_smbd ( is_daemon , interactive , ports ) )
1998-08-17 18:11:44 +04:00
exit ( 1 ) ;
1998-05-19 03:57:28 +04:00
2000-01-08 05:16:15 +03:00
/*
2000-06-10 17:38:07 +04:00
* everything after this point is run after the fork ( )
2000-01-08 05:16:15 +03:00
*/
2005-09-08 05:05:16 +04:00
# if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
/* On Linux we lose the ability to dump core when we change our user
* ID . We know how to dump core safely , so let ' s make sure we have our
* dumpable flag set .
*/
prctl ( PR_SET_DUMPABLE , 1 ) ;
# endif
2003-07-07 09:11:10 +04:00
/* Initialise the password backed before the global_sam_sid
This patch cleans up some of our ldap code, for better behaviour:
We now always read the Domain SID out of LDAP. If the local secrets.tdb
is ever different to LDAP, it is overwritten out of LDAP. We also
store the 'algorithmic rid base' into LDAP, and assert if it changes.
(This ensures cross-host synchronisation, and allows for possible
integration with idmap). If we fail to read/add the domain entry, we just
fallback to the old behaviour.
We always use an existing DN when adding IDMAP entries to LDAP, unless
no suitable entry is available. This means that a user's posixAccount
will have a SID added to it, or a user's sambaSamAccount will have a UID
added. Where we cannot us an existing DN, we use
'sambaSid=S-x-y-z,....' as the DN.
The code now allows modifications to the ID mapping in many cases.
Likewise, we now check more carefully when adding new user entires to LDAP,
to not duplicate SIDs (for users, at this stage), and to add the sambaSamAccount
onto the idmap entry for that user, if it is already established (ensuring
we do not duplicate sambaSid entries in the directory).
The allocated UID code has been expanded to take into account the space
between '1000 - algorithmic rid base'. This much better fits into what
an NT4 does - allocating in the bottom part of the RID range.
On the code cleanup side of things, we now share as much code as
possible between idmap_ldap and pdb_ldap.
We also no longer use the race-prone 'enumerate all users' method for
finding the next RID to allocate. Instead, we just start at the bottom
of the range, and increment again if the user already exists. The first
time this is run, it may well take a long time, but next time will just
be able to use the next Rid.
Thanks to metze and AB for double-checking parts of this.
Andrew Bartlett
(This used to be commit 9c595c8c2327b92a86901d84c3f2c284dabd597e)
2003-07-04 17:29:42 +04:00
to ensure that we fetch from ldap before we make a domain sid up */
2002-01-14 22:34:28 +03:00
if ( ! initialize_password_db ( False ) )
1998-08-17 18:11:44 +04:00
exit ( 1 ) ;
1996-05-04 11:50:46 +04:00
This patch cleans up some of our ldap code, for better behaviour:
We now always read the Domain SID out of LDAP. If the local secrets.tdb
is ever different to LDAP, it is overwritten out of LDAP. We also
store the 'algorithmic rid base' into LDAP, and assert if it changes.
(This ensures cross-host synchronisation, and allows for possible
integration with idmap). If we fail to read/add the domain entry, we just
fallback to the old behaviour.
We always use an existing DN when adding IDMAP entries to LDAP, unless
no suitable entry is available. This means that a user's posixAccount
will have a SID added to it, or a user's sambaSamAccount will have a UID
added. Where we cannot us an existing DN, we use
'sambaSid=S-x-y-z,....' as the DN.
The code now allows modifications to the ID mapping in many cases.
Likewise, we now check more carefully when adding new user entires to LDAP,
to not duplicate SIDs (for users, at this stage), and to add the sambaSamAccount
onto the idmap entry for that user, if it is already established (ensuring
we do not duplicate sambaSid entries in the directory).
The allocated UID code has been expanded to take into account the space
between '1000 - algorithmic rid base'. This much better fits into what
an NT4 does - allocating in the bottom part of the RID range.
On the code cleanup side of things, we now share as much code as
possible between idmap_ldap and pdb_ldap.
We also no longer use the race-prone 'enumerate all users' method for
finding the next RID to allocate. Instead, we just start at the bottom
of the range, and increment again if the user already exists. The first
time this is run, it may well take a long time, but next time will just
be able to use the next Rid.
Thanks to metze and AB for double-checking parts of this.
Andrew Bartlett
(This used to be commit 9c595c8c2327b92a86901d84c3f2c284dabd597e)
2003-07-04 17:29:42 +04:00
if ( ! get_global_sam_sid ( ) ) {
DEBUG ( 0 , ( " ERROR: Samba cannot create a SAM SID. \n " ) ) ;
exit ( 1 ) ;
}
2003-04-16 16:13:07 +04:00
static_init_rpc ;
init_modules ( ) ;
1998-08-17 18:11:44 +04:00
/* possibly reload the services file. */
reload_services ( True ) ;
2000-01-03 22:19:48 +03:00
2001-12-03 20:14:23 +03:00
if ( ! init_account_policy ( ) ) {
DEBUG ( 0 , ( " Could not open account policy tdb. \n " ) ) ;
2000-01-03 22:19:48 +03:00
exit ( 1 ) ;
}
1998-08-17 18:11:44 +04:00
if ( * lp_rootdir ( ) ) {
if ( sys_chroot ( lp_rootdir ( ) ) = = 0 )
DEBUG ( 2 , ( " Changed root to %s \n " , lp_rootdir ( ) ) ) ;
}
1997-09-23 23:19:06 +04:00
2000-06-10 17:38:07 +04:00
/* Setup oplocks */
2002-01-14 22:34:28 +03:00
if ( ! init_oplocks ( ) )
1998-08-17 18:11:44 +04:00
exit ( 1 ) ;
2001-10-22 10:53:28 +04:00
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!
(This used to be commit 44766c39e0027c762bee8b33b12c621c109a3267)
2000-06-12 19:53:31 +04:00
/* Setup change notify */
2002-01-14 22:34:28 +03:00
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!
(This used to be commit 44766c39e0027c762bee8b33b12c621c109a3267)
2000-06-12 19:53:31 +04:00
exit ( 1 ) ;
2005-06-28 02:53:56 +04:00
/* Setup aio signal handler. */
initialize_async_io_handler ( ) ;
2002-08-17 19:27:10 +04:00
/* re-initialise the timezone */
TimeInit ( ) ;
/* register our message handlers */
message_register ( MSG_SMB_FORCE_TDIS , msg_force_tdis ) ;
1998-08-17 18:11:44 +04:00
smbd_process ( ) ;
2003-04-23 15:54:56 +04:00
namecache_shutdown ( ) ;
2004-11-06 00:45:02 +03:00
1998-08-17 18:11:44 +04:00
exit_server ( " normal exit " ) ;
return ( 0 ) ;
1996-05-04 11:50:46 +04:00
}