+#define OLD_NTDOMAIN 1
/*
Unix SMB/Netbios implementation.
Version 1.9.
*/
#include "includes.h"
-#include "trans2.h"
pstring servicesf = CONFIGFILE;
extern pstring debugf;
extern fstring global_myworkgroup;
-extern fstring global_sam_name;
extern pstring global_myname;
int am_parent = 1;
/* a useful macro to debug the last message processed */
#define LAST_MESSAGE() smb_fn_name(last_message)
-extern pstring scope;
extern int DEBUGLEVEL;
extern pstring user_socket_options;
extern int dcelogin_atmost_once;
#endif /* WITH_DFS */
-
extern fstring remote_machine;
-extern pstring OriginalDir;
-extern pstring myhostname;
+
+/* 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
+ */
+static int server_fd = -1;
+
+int smbd_server_fd(void)
+{
+ return server_fd;
+}
+
+void smbd_set_server_fd(int fd)
+{
+ server_fd = fd;
+ client_setfd(fd);
+}
/****************************************************************************
when exiting, take the whole family
****************************************************************************/
static BOOL open_sockets_inetd(void)
{
- extern int Client;
-
/* Started from inetd. fd 0 is the socket. */
/* We will abort gracefully when the client or remote system
goes away */
- Client = dup(0);
+ smbd_set_server_fd(dup(0));
/* close our standard file descriptors */
close_low_fds();
- set_socket_options(Client,"SO_KEEPALIVE");
- set_socket_options(Client,user_socket_options);
+ set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
+ set_socket_options(smbd_server_fd(),user_socket_options);
return True;
}
****************************************************************************/
static BOOL open_sockets(BOOL is_daemon,int port)
{
- extern int Client;
int num_interfaces = iface_count();
int fd_listenset[FD_SETSIZE];
fd_set listen_set;
DEBUG(0,("open_sockets: interface %d has NULL IP address !\n", i));
continue;
}
- s = fd_listenset[i] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr);
+ s = fd_listenset[i] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr, True);
if(s == -1)
return False;
/* ready to listen */
/* open an incoming socket */
s = open_socket_in(SOCK_STREAM, port, 0,
- interpret_addr(lp_socket_address()));
+ interpret_addr(lp_socket_address()),True);
if (s == -1)
return(False);
memcpy((char *)&lfds, (char *)&listen_set,
sizeof(listen_set));
- num = sys_select(256,&lfds,NULL);
+ num = sys_select(FD_SETSIZE,&lfds,NULL);
- if (num == -1 && errno == EINTR)
+ if (num == -1 && errno == EINTR) {
+ extern VOLATILE SIG_ATOMIC_T reload_after_sighup;
+
+ /* check for sighup processing */
+ if (reload_after_sighup) {
+ unbecome_user();
+ DEBUG(1,("Reloading services after SIGHUP\n"));
+ reload_services(False);
+ reload_after_sighup = False;
+ }
+
continue;
+ }
+ /* check if we need to reload services */
+ check_reload(time(NULL));
+
/* Find the sockets that are read-ready -
accept on these. */
for( ; num > 0; num--) {
}
}
- Client = accept(s,&addr,&in_addrlen);
+ smbd_set_server_fd(accept(s,&addr,&in_addrlen));
- if (Client == -1 && errno == EINTR)
+ if (smbd_server_fd() == -1 && errno == EINTR)
continue;
- if (Client == -1) {
+ if (smbd_server_fd() == -1) {
DEBUG(0,("open_sockets: accept: %s\n",
strerror(errno)));
continue;
}
- if (Client != -1 && fork()==0) {
+ if (smbd_server_fd() != -1 && sys_fork()==0) {
/* Child code ... */
/* close the listening socket(s) */
close_low_fds();
am_parent = 0;
- set_socket_options(Client,"SO_KEEPALIVE");
- set_socket_options(Client,user_socket_options);
+ set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
+ set_socket_options(smbd_server_fd(),user_socket_options);
/* Reset global variables in util.c so
that client substitutions will be
done correctly in the process. */
reset_globals_after_fork();
- /*
- * Ensure this child has kernel oplock
- * capabilities, but not it's children.
- */
- set_process_capability(KERNEL_OPLOCK_CAPABILITY, True);
- set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY, False);
-
return True;
}
/* The parent doesn't need this socket */
- close(Client);
+ close(smbd_server_fd());
/* Force parent to check log size after
* spawning child. Fix from
BOOL reload_services(BOOL test)
{
BOOL ret;
-
+
if (lp_loaded()) {
pstring fname;
pstrcpy(fname,lp_configfile());
return(True);
lp_killunused(conn_snum_used);
-
+
ret = lp_load(servicesf,False,False,True);
load_printers();
load_interfaces();
{
- extern int Client;
- if (Client != -1) {
- set_socket_options(Client,"SO_KEEPALIVE");
- set_socket_options(Client,user_socket_options);
+ if (smbd_server_fd() != -1) {
+ set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
+ set_socket_options(smbd_server_fd(),user_socket_options);
}
}
reset_mangled_cache();
+ reset_stat_cache();
/* this forces service parameters to be flushed */
become_service(NULL,True);
/****************************************************************************
-this prevents zombie child processes
+ Catch a sighup.
****************************************************************************/
-BOOL reload_after_sighup = False;
+
+VOLATILE SIG_ATOMIC_T reload_after_sighup = False;
static void sig_hup(int sig)
{
BlockSignals(True,SIGHUP);
DEBUG(0,("Got SIGHUP\n"));
- /*
- * Fix from <branko.cibej@hermes.si> here.
- * We used to reload in the signal handler - this
- * is a *BIG* no-no.
- */
-
+ sys_select_signal();
reload_after_sighup = True;
BlockSignals(False,SIGHUP);
}
}
#endif
-
/****************************************************************************
exit the server
****************************************************************************/
conn_close_all();
+ respond_to_all_remaining_local_messages();
+
#ifdef WITH_DFS
if (dcelogin_atmost_once) {
dfs_unlogin();
locking_end();
DEBUG(3,("Server exit (%s)\n", (reason ? reason : "")));
-#ifdef MEM_MAN
- {
- extern FILE *dbf;
- smb_mem_write_verbose(dbf);
- dbgflush();
- }
-#endif
exit(0);
}
-
-
/****************************************************************************
initialise connect, service and file structs
****************************************************************************/
-static void init_structs(void)
+static void init_structs(void )
{
+ /*
+ * Set the machine NETBIOS name if not already
+ * set from the config file.
+ */
+
+ if (!*global_myname) {
+ char *p;
+ fstrcpy( global_myname, myhostname() );
+ p = strchr( global_myname, '.' );
+ if (p)
+ *p = 0;
+ }
+
+ strupper( global_myname );
+
conn_init();
+
file_init();
- init_rpc_pipe_hnd(); /* for RPC pipes */
- init_lsa_policy_hnd(); /* for LSA handles */
+
+ /* for RPC pipes */
+ init_rpc_pipe_hnd();
+
+ /* for LSA handles */
+ init_lsa_policy_hnd();
+
+ /* for SPOOLSS handles */
+ init_printer_hnd();
+
init_dptrs();
+
+ secrets_init();
}
/****************************************************************************
****************************************************************************/
static void usage(char *pname)
{
- DEBUG(0,("Incorrect program usage - are you sure the command line is correct?\n"));
-
- printf("Usage: %s [-D] [-p port] [-d debuglevel] ", pname);
- printf("[-l log basename] [-s services file]\n" );
- printf("Version %s\n",VERSION);
- printf("\t-D become a daemon\n");
- printf("\t-p port listen on the specified port\n");
- printf("\t-d debuglevel set the debuglevel\n");
+
+ printf("Usage: %s [-DaoPh?V] [-d debuglevel] [-l log basename] [-p port]\n", pname);
+ printf(" [-O socket options] [-s services file]\n");
+ printf("\t-D Become a daemon\n");
+ printf("\t-a Append to log file (default)\n");
+ printf("\t-o Overwrite log file, don't append\n");
+ printf("\t-h Print usage\n");
+ printf("\t-? Print usage\n");
+ printf("\t-V Print version\n");
+ printf("\t-d debuglevel Set the debuglevel\n");
printf("\t-l log basename. Basename for log/debug files\n");
+ printf("\t-p port Listen on the specified port\n");
+ printf("\t-O socket options Socket options\n");
printf("\t-s services file. Filename of services file\n");
- printf("\t-P passive only\n");
- printf("\t-a append to log file (default)\n");
- printf("\t-o overwrite log file, don't append\n");
- printf("\t-i scope NetBIOS scope to use (default none)\n");
printf("\n");
}
extern BOOL append_log;
/* shall I run as a daemon */
BOOL is_daemon = False;
+ BOOL specified_logfile = False;
int port = SMB_PORT;
int opt;
extern char *optarg;
set_auth_parameters(argc,argv);
#endif
-#ifdef HAVE_SETLUID
- /* needed for SecureWare on SCO */
- setluid(0);
-#endif
-
- append_log = True;
-
- TimeInit();
-
- pstrcpy(debugf,SMBLOGFILE);
-
- pstrcpy(remote_machine, "smb");
-
- setup_logging(argv[0],False);
-
- charset_initialise();
-
- /* make absolutely sure we run as root - to handle cases where people
- are crazy enough to have it setuid */
-#ifdef HAVE_SETRESUID
- setresuid(0,0,0);
-#else
- setuid(0);
- seteuid(0);
- setuid(0);
- seteuid(0);
-#endif
-
- fault_setup((void (*)(void *))exit_server);
- CatchSignal(SIGTERM , SIGNAL_CAST dflt_sig);
-
- /* we are never interested in SIGPIPE */
- BlockSignals(True,SIGPIPE);
-
- /* we want total control over the permissions on created files,
- so set our umask to 0 */
- umask(0);
-
- dos_GetWd(OriginalDir);
-
- init_uid();
-
/* this is for people who can't start the program correctly */
while (argc > 1 && (*argv[1] != '-')) {
argv++;
argc--;
}
- while ( EOF != (opt = getopt(argc, argv, "O:i:l:s:d:Dp:h?Paof:")) )
+ while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?Vaof:")) )
switch (opt) {
case 'O':
pstrcpy(user_socket_options,optarg);
break;
- case 'i':
- pstrcpy(scope,optarg);
- break;
-
- case 'P':
- {
- extern BOOL passive;
- passive = True;
- }
- break;
-
case 's':
pstrcpy(servicesf,optarg);
break;
case 'l':
+ specified_logfile = True;
pstrcpy(debugf,optarg);
break;
exit(0);
break;
+ case 'V':
+ printf("Version %s\n",VERSION);
+ exit(0);
+ break;
default:
+ DEBUG(0,("Incorrect program usage - are you sure the command line is correct?\n"));
usage(argv[0]);
exit(1);
}
+#ifdef HAVE_SETLUID
+ /* needed for SecureWare on SCO */
+ setluid(0);
+#endif
+
+ /*
+ * gain_root_privilege uses an assert than will cause a core
+ * dump if euid != 0. Ensure this is the case.
+ */
+
+ if(geteuid() != (uid_t)0) {
+ fprintf(stderr, "%s: Version %s : Must have effective user id of zero to run.\n", argv[0], VERSION);
+ exit(1);
+ }
+
+ append_log = True;
+
+ TimeInit();
+
+ if(!specified_logfile) {
+ slprintf(debugf, sizeof(debugf), "%s/log.smbd", LOGFILEBASE);
+ }
+
+ pstrcpy(remote_machine, "smb");
+
+ setup_logging(argv[0],False);
+
+ charset_initialise();
+
+ /* we want to re-seed early to prevent time delays causing
+ client problems at a later date. (tridge) */
+ generate_random_buffer(NULL, 0, False);
+
+ /* 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);
+ CatchSignal(SIGTERM , SIGNAL_CAST dflt_sig);
+
+ /* we are never interested in SIGPIPE */
+ BlockSignals(True,SIGPIPE);
+
+#if defined(SIGFPE)
+ /* we are never interested in SIGFPE */
+ BlockSignals(True,SIGFPE);
+#endif
+
+ /* we want total control over the permissions on created files,
+ so set our umask to 0 */
+ umask(0);
+
+ init_sec_ctx();
+
reopen_logs();
DEBUG(1,( "smbd version %s started.\n", VERSION));
exit(1);
}
- get_myname(myhostname,NULL);
+ /*
+ * Do this before reload_services.
+ */
if (!reload_services(False))
return(-1);
init_structs();
- /*
- * Set the machine NETBIOS name if not already
- * set from the config file.
- */
- if (!*global_myname)
- {
- fstrcpy(global_myname, dns_to_netbios_name(myhostname));
+#ifdef WITH_PROFILE
+ if (!profile_setup(False)) {
+ DEBUG(0,("ERROR: failed to setup profiling\n"));
+ return -1;
}
- strupper(global_myname);
+#endif
#ifdef WITH_SSL
{
codepage_initialise(lp_client_code_page());
- if (!pwdb_initialise(True))
- {
- exit(1);
- }
-
- if(!initialise_sam_password_db())
- {
- exit(1);
- }
-
- if(!initialise_passgrp_db())
- {
- exit(1);
- }
-
- if(!initialise_group_db())
- {
- exit(1);
- }
-
- if(!initialise_alias_db())
- {
- exit(1);
- }
-
- if(!initialise_builtin_db())
- {
- exit(1);
- }
-
- if (!get_member_domain_sid())
- {
- DEBUG(0,("ERROR: Samba cannot obtain PDC SID from PDC(s) %s.\n",
- lp_passwordserver()));
- exit(1);
- }
+ fstrcpy(global_myworkgroup, lp_workgroup());
CatchSignal(SIGHUP,SIGNAL_CAST sig_hup);
- /* Setup the signals that allow the debug log level
- to by dynamically changed. */
-
- /* If we are using the malloc debug code we can't use
- SIGUSR1 and SIGUSR2 to do debug level changes. */
-
-#ifndef MEM_MAN
-#if defined(SIGUSR1)
- CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 );
-#endif /* SIGUSR1 */
-
-#if defined(SIGUSR2)
- CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 );
-#endif /* SIGUSR2 */
-#endif /* MEM_MAN */
-
DEBUG(3,( "loaded services\n"));
if (!is_daemon && !is_a_socket(0)) {
become_daemon();
}
- check_kernel_oplocks();
-
if (!directory_exist(lp_lockdir(), NULL)) {
mkdir(lp_lockdir(), 0755);
}
if (!open_sockets(is_daemon,port))
exit(1);
- if (!locking_init(0))
+ /*
+ * everything after this point is run after the fork()
+ */
+
+ if (!message_init()) {
+ exit(1);
+ }
+
+ if (!locking_init(0)) {
+ exit(1);
+ }
+
+ if (!print_backend_init()) {
exit(1);
+ }
+
+ if(!initialize_password_db()) {
+ exit(1);
+ }
/* possibly reload the services file. */
reload_services(True);
-
+
+ if(!pdb_generate_sam_sid()) {
+ DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
+ exit(1);
+ }
+
if (*lp_rootdir()) {
if (sys_chroot(lp_rootdir()) == 0)
DEBUG(2,("Changed root to %s\n", lp_rootdir()));
}
- /* Setup the oplock IPC socket. */
- if( !open_oplock_ipc() )
+ /* Setup oplocks */
+ if (!init_oplocks()) {
exit(1);
+ }
+
+ /* Setup change notify */
+ if (!init_change_notify()) {
+ exit(1);
+ }
smbd_process();
- close_sockets();
exit_server("normal exit");
return(0);
}
+
+#undef OLD_NTDOMAIN