summaryrefslogtreecommitdiff
path: root/source4/smbd
Commit message (Collapse)AuthorAgeFilesLines
* s4/smdb: cppcheck: fix nullPointer: Possible null pointer dereference warning.Noel Power2019-06-041-2/+69
| | | | | | | | | | | | | | | Insert unreachable return to satisfy the following warnings source4/smbd/server.c:692: warning: nullPointer: Possible null pointer dereference: state <--[cppcheck] source4/smbd/server.c:694: warning: nullPointer: Possible null pointer dereference: state <--[cppcheck] source4/smbd/server.c:699: warning: nullPointer: Possible null pointer dereference: state <--[cppcheck] source4/smbd/server.c:758: warning: nullPointer: Possible null pointer dereference: state <--[cppcheck] source4/smbd/server.c:789: warning: nullPointer: Possible null pointer dereference: state <--[cppcheck] source4/smbd/server.c:849: warning: nullPointer: Possible null pointer dereference: state <--[cppcheck] source4/smbd/server.c:866: warning: nullPointer: Possible null pointer dereference: state <--[cppcheck] Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andreas Schneider <asn@samba.org>
* s4-server: Open and close a transaction on sam.ldb at startupAndrew Bartlett2019-03-071-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes upgrading from 4.7 and earlier releases, and makes the DB reindexing more transparent. It should also make it easier to handle future normalisation rule changes, e.g. if we change the pack-format of integer indexes in a future release. Without this change, the should have still handled reindexing the database. We don't know why exactly this wasn't happening correctly, but opening a transaction early in the samba process startup should now guarantee that the DB is correctly reindexed by the time the main samba code runs. An alternative fix would have been to open a transaction in the the DSDB module stack every time we connect to the database. However, this would add an extra write lock every time we open the DB, whereas starting samba happens much more infrequently. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13760 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Tim Beale <timbeale@catalyst.net.nz> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Thu Mar 7 04:58:42 UTC 2019 on sn-devel-144
* samba: Change default process model to preforkTim Beale2019-02-011-1/+1
| | | | | | | | Prefork is the more sensible default option now, as it better handles a large number of client connections. Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* s4:server: add support for 'smbcontrol samba shutdown'Stefan Metzmacher2019-01-291-1/+36
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=13752 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Björn Baumbach <bbaumbach@samba.org>
* s4:server: avoid using pid=0 for the parent 'samba' processStefan Metzmacher2019-01-291-1/+1
| | | | | | | | | It confuses the 'samba-tool processes' output and log messages. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13752 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Björn Baumbach <bbaumbach@samba.org>
* s4:smbd: Use C99 initializer for poptOption in serverAndreas Schneider2019-01-281-16/+51
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
* Happy New Year 2019!Stefan Metzmacher2019-01-011-1/+1
| | | | | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Tue Jan 1 16:02:05 CET 2019 on sn-devel-144
* s4 smdb standard: Limit processes forked on accept.Gary Lockyer2018-11-301-2/+31
| | | | | | | | | | | | Limit the number of processes started by the standard model on accept. For those services that support fork on accept, the standard model forks a new process for each new connection. This patch limits the number of processes to the value specified in 'max smbd processes', a value of zero indicates that there is no limit on the number of processes that can be forked. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* s4:smbd: Use #ifdef instead of #if for config.h definitionsAndreas Schneider2018-11-283-5/+5
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
* source4 smbd prefork: Add code commentsTim Beale2018-11-231-5/+46
| | | | | | | | | | Add some comments to the prefork code explaining what's going on. Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Fri Nov 23 11:40:49 CET 2018 on sn-devel-144
* source4 smbd prefork: Cleanup messaging on restartGary Lockyer2018-11-231-9/+95
| | | | | | | Clean up names registered in messaging for a terminated process. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* source4 smbd prefork: Add backoff to process restartGary Lockyer2018-11-231-150/+227
| | | | | | | | | Add new smbd.conf variables 'prefork backoff increment' and 'prefork maximum backoff' to control the rate at which failed pre-forked processes are restarted. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* source4 smbd prefork: restart on non zero exit codeGary Lockyer2018-11-236-67/+117
| | | | | | | | Restart any pre-fork master or worker process that exits with a non zero exit code. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* source4 smbd process: pass the fatal flag to terminateGary Lockyer2018-11-236-4/+9
| | | | | | | | | | Pass the fatal flag supplied to task_server_terminate to the process task_terminate method. It will be used by the task_terminate methods to set an appropriate exit code. The process_prefork model will use a non zero exit code to indicate that the process should be restarted. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* source4 smbd prefork: Restart failed processesGary Lockyer2018-11-231-4/+71
| | | | | | | | Restart any pre-forked master or worker process that terminated with SIGABRT, SIGBUS, SIGFPE, SIGILL or SIGSYS Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* source4 smbd prefork: Pass restart informationGary Lockyer2018-11-231-47/+129
| | | | | | | | Pass information about the pre-fork master and worker processes that will allow them to be restarted. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* source4 smbd: pass instance number to post_forkGary Lockyer2018-11-074-7/+20
| | | | | | | | Pass the instance number to the post_fork hook. This is required to allow the rpc_server to support the prefork process model. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* source4 smdb: Add a post fork hook to the service APIGary Lockyer2018-11-017-26/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | Add a post fork hook to the service API this will be called: - standard process model immediately after the task_init. - single process model immediately after the task_init - prefork process model, inhibit_pre_fork = true immediately after the task_init - prefork process model, inhibit_pre_fork = false after each service worker has forked. It is not run on the service master process. The post fork hook is not called in the standard model if a new process is forked on a new connection. It is instead called immediately after the task_init. The task_init hook has been changed to return an error code. This ensures the post_fork code is only run if the task_init code completed successfully. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
* source4 smbd: Make the service_details structure constant.Gary Lockyer2018-11-011-1/+1
| | | | | | Make the service_details structure a static const. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
* samba: read backup date field on init and fail if presentAaron Haslett2018-06-281-15/+68
| | | | | | | | | | | | | This prevents a backup tar file, created with the new official backup tools, from being extracted and replicated. This is done here to ensure that samba-tool and ldbsearch can still operate on the backup (eg for forensics) but starting Samba as an AD DC will fail. Signed-off-by: Aaron Haslett <aaronhaslett@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* samdb: Add remote address to connectGary Lockyer2018-05-101-4/+5
| | | | | Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* s4/smbd/server.c: create /run if missingWilliam Brown2018-04-251-0/+4
| | | | | | | | | In some cases (containers mainly) /var/run may not be present. Instead of erroring, we should create it at startup. Signed-off-by: William Brown <william@blackhats.net.au> Reviewed-by: Alexander Bokovoy <ab@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* libsocket: Add "mem_ctx" to socket_create()Volker Lendecke2018-02-271-4/+6
| | | | | | | | Every caller did a talloc_steal() after socket_create(). Just pass in the correct memory context. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* waf: Remove build system info (uname -a)Mathieu Parent2018-01-141-3/+0
| | | | | | | | | | | | Preventing reproducible builds while adding minor benefit. More information at <https://reproducible-builds.org/>. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13213 Signed-off-by: Mathieu Parent <math.parent@gmail.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlet <abartlet@samba.org>
* samba: Only use async signal-safe functions in signal handlerVolker Lendecke2018-01-061-3/+1
| | | | | | | Otherwise shutdown can hang Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* Happy New Year 2018!Stefan Metzmacher2018-01-011-1/+1
| | | | | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Mon Jan 1 19:19:22 CET 2018 on sn-devel-144
* s4:samba: Fix default to be running samba as a deamonAndrew Bartlett2017-12-191-1/+1
| | | | | | | | | | | | | Commit 8736013dc42c5755b75bbb2e843a290bcd545909 got the (confusing) sense of opt_fork wrong. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13129 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Tue Dec 19 11:24:29 CET 2017 on sn-devel-144
* s4:samba: Allow samba daemon to run in foregroundAndreas Schneider2017-11-281-2/+9
| | | | | | | | | | | | | | We are passing the no_process_group to become_daemon() that setsid() is not called. In case we are double forking, we run in SysV daemon mode, setsid() should be called! See: https://www.freedesktop.org/software/systemd/man/daemon.html BUG: https://bugzilla.samba.org/show_bug.cgi?id=13129 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* s4:samba: Do not segfault if we run into issuesAndreas Schneider2017-11-281-0/+8
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* samba: Fix CID 1420179 Code maintainability issues UNUSED_VALUEVolker Lendecke2017-10-271-1/+0
| | | | | | | I don't think pid is used at all here. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* samba: Fix CID 1420180 Null pointer dereferencesVolker Lendecke2017-10-271-1/+1
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s4:smbd: Add missing unistd.h include to fix build of process_preforkAndreas Schneider2017-10-191-0/+2
| | | | | | | | error: implicit declaration of function ‘getpgrp’; did you mean ‘getpt’? [-Werror=implicit-function-declaration] Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* source4/smbd: replace DEBUG( with DBG_Gary Lockyer2017-10-198-61/+65
| | | | | | | | Update the debug logging to use the currently preferred debug macros Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
* source4/smbd: add a prefork process model.Gary Lockyer2017-10-192-0/+398
| | | | | | | | | | | | | | | | Add a pre fork process model to bound the number processes forked by samba. Currently workers are only pre-forked for the ldap server, all the other services have pre-fork support disabled. When pre-fork support is disabled a new process is started for each service, and requests are processed by that process. This commit partially reverts commit b5be45c453bd51373bade26c29828b500ba586ec. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
* source4/smbd: Fix code formatting after refactoring.Gary Lockyer2017-10-192-22/+27
| | | | | | | | | | Fix code formatting from the refactoring in the previous commits. Done as a separate patch to make the changes to functionality easier to review. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
* process_standard: Do not log at level 2 every time a child exitsGary Lockyer2017-10-191-2/+4
| | | | | | Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
* process_standard: Honour proc_ctx->inhibit_fork_on_acceptGary Lockyer2017-10-191-0/+15
| | | | | | | | This allows the service to control if it should fork per accept() without needing to replace the whole process model with process_single. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
* process_standard: Move child pipe setup further down ↵Gary Lockyer2017-10-191-8/+5
| | | | | | | | | | standard_accept_connection() This avoids cleaning up on error from accept() but more importantly allows a future mode that acts like process_single and so has no child. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
* process_standard: Use the new process_contextGary Lockyer2017-10-191-12/+57
| | | | | | | | | | | Use the new process_context to control the from_parent_fd This avoids the use of global variables, and will in the next patch allow process_standard to run as what was known as single without over-stamping a different process model. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
* source4/smbd: refactor the process model for preforkGary Lockyer2017-10-1910-43/+105
| | | | | | | | | | | | | | | | | | Refactor the process model code to allow the addition of a prefork process model. - Add a process context to contain process model specific state - Add a service details structure to allow service to indicate which process model options they can support. In the new code the services advertise the features they support to the process model. The process model context is plumbed through to allow the process model to keep track of the supported options, and any state the process model may require. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
* source4 smbd: remove global control pipe from process_standard.Gary Lockyer2017-09-286-42/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The standard model uses a pipe to signal the worker processes spawned on accept that the controlling process has terminated and that they should shut down. This pipe is currently a static global variable in process_standard.c. This patch replaces that global pipe with a file descriptor passed into the process model init functions, giving a single mechanism across all process models. This paves the way for the addition of a pre-fork process model. Ensuring that the correct file descriptors are closed, is difficult so it is best do this only once rather than require the process models to do this individually. Notes on debugging pipe ownership: Add code to log the process id and the file descriptor of the writeable pipe. run: lsof | grep FIFO | grep samba | grep <process id> this will produce lines like: samba 25624 him 4w FIFO 0,10 0t0 472206 pipe where: 4w is the file descriptor and mode and the number to the left of "pipe" is the pipe id. then: lsof | grep FIFO | grep samba | grep <pipe id> This will display all the processes with the pipe open and the mode only the smbd master process should have it open in write mode. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Thu Sep 28 02:08:34 CEST 2017 on sn-devel-144
* s4:smbd: set samba root process titleGary Lockyer2017-09-261-0/+2
| | | | | | | | | Set the process title in the samba root process to clearly identify it in ps output. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* s4:smbd: call setproctitle_initGary Lockyer2017-09-261-0/+2
| | | | | | | | | | | | | | Call setproctitle_init() in main which suppresses the "samba: setproctitle not initialized, please either call setproctitle_init() or link against libbsd-ctor." messages, but more importantly it displays meaningful details in ps output. BUG: https://bugzilla.samba.org/show_bug.cgi?id=9816 Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
* s4/smbd: set the process group.Gary Lockyer2017-09-181-1/+17
| | | | | | | | | | | | | Set the process group in the samba daemon, the --no-process-group option allows this to be disabled. The no-process-group option needs to be disabled in self test. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Mon Sep 18 04:39:50 CEST 2017 on sn-devel-144
* stream_terminate_connection: Prevent use-after-freeGarming Sam2017-06-151-0/+10
| | | | | | | | This sometimes would show up as corrupted bytes during logs. Hammering the LDAP server enough times managed to trigger an outright segfault. Signed-off-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* s4: Add TALLOC_CTX * to register_server_service().Jeremy Allison2017-05-111-3/+4
| | | | | | | | Use the passed in context from callers. Remove one talloc_autofree_context(). Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* process_standard: clean up messaging for children after exit()Andrew Bartlett2017-04-252-1/+4
| | | | | | | | This makes sure we remove any messaging sockets if a child dies or calls exit() without running the talloc destructor for messaging Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* lib: modules: Change XXX_init interface from XXX_init(void) to ↵Jeremy Allison2017-04-224-10/+10
| | | | | | | | | | | | | | | | | | | | XXX_init(TALLOC_CTX *) Not currently used - no logic changes inside. This will make it possible to pass down a long-lived talloc context from the loading function for modules to use instead of having them internally all use talloc_autofree_context() which is a hidden global. Updated all known module interface numbers, and added a WHATSNEW. Signed-off-by: Jeremy Allison <jra@samba.org> Signed-off-by: Ralph Böhme <slow@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Sat Apr 22 01:17:00 CEST 2017 on sn-devel-144
* s4: server: Use state as the talloc context for open_schannel_session_store.Jeremy Allison2017-04-171-1/+10
| | | | | | | | | | Ensure it's freed on all error paths. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Apr 17 23:10:06 CEST 2017 on sn-devel-144
* s4: server: Remove use of talloc_autofree_context as the parent of event_ctx.Jeremy Allison2017-04-171-2/+6
| | | | | | | | | | Use state->event_ctx as the parent of the initial imessaging context. Now we control all exit paths, we can call TALLOC_FREE(state) on all of them. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>