summaryrefslogtreecommitdiff
path: root/lib/util
Commit message (Collapse)AuthorAgeFilesLines
* smbd: add missing newline to debug message in daemon_status()Justin Maggard via samba-technical2017-09-081-1/+1
| | | | | | | | | Signed-off-by: Justin Maggard <jmaggard@netgear.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Fri Sep 8 06:26:52 CEST 2017 on sn-devel-144
* debug: Add new debug class "drs_repl" for DRS replication processingAndrew Bartlett2017-09-072-0/+2
| | | | | | | This is used in the client and in the server Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
* util: Add documentation for PID file handlingMartin Schwenke2017-08-172-7/+55
| | | | | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Thu Aug 17 19:45:32 CEST 2017 on sn-devel-144
* util: Add error handling to become_daemon()Martin Schwenke2017-08-171-1/+9
| | | | | | | | | | | | | | | Log failure and exit if fork() or setsid() fails. Leave the logic in the non-setsid() code as it is. This is probably meant to fall through on failure of either opening /dev/tty or ioctl(). Documentation for the ioctl() failure case is far from clear. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Thu Aug 17 11:48:32 CEST 2017 on sn-devel-144
* util: Move become_daemon.c to samba-util-coreMartin Schwenke2017-08-171-2/+3
| | | | | | | So that CTDB can use it. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Andreas Schneider <asn@samba.org>
* util: Modernise loggingMartin Schwenke2017-08-171-12/+14
| | | | | | | Switch to using DBG_ERR(), wrap logging/sd_notifyf() lines. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Andreas Schneider <asn@samba.org>
* util: Make function definitions consistent with header fileMartin Schwenke2017-08-171-15/+15
| | | | | | | no_process_group -> no_session, name -> daemon, drop _PUBLIC_. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Andreas Schneider <asn@samba.org>
* util: Add become_daemon.hMartin Schwenke2017-08-173-28/+88
| | | | | | | | | Rename argument no_process_group to no_session to describe what it actually does. Consistently use "daemon" for name of daemon argument. Add documentation. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Andreas Schneider <asn@samba.org>
* util: Avoid use of includes.hMartin Schwenke2017-08-171-2/+6
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Andreas Schneider <asn@samba.org>
* util: Reimplement pidfile_create() using pidfile_path_create()Martin Schwenke2017-08-021-22/+5
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
* util: New functions pidfile_path_create(), pidfile_fd_close()Martin Schwenke2017-08-022-0/+102
| | | | | | | | | Uses the core of CTDB's create_pidfile_context() for pidfile_path_create(). pidfile_fd_close() is a subset of CTDB's pidfile_context_destructor(). Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
* util: Add pidfile.* to samba-util-coreMartin Schwenke2017-08-021-2/+2
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
* util: Clean up includesMartin Schwenke2017-08-021-1/+6
| | | | | Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
* util: pidfile_pid() should not unlink PID fileMartin Schwenke2017-08-021-6/+1
| | | | | | | | | | | | | This causes a race. If 2 callers to pidfile_create() both a find a stale PID file using pidfile_pid(). The 1st may then return to pidfile_create() and create a new PID file, which can then be unlinked by the 2nd caller. Consequently, PID file creation can not depend on creating the file, so drop O_EXCL from the call to open(). Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
* lib/util: add more tfork testsRalph Boehme2017-07-031-0/+438
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* lib/util: adjust loglevel in tfork test with samba_runcmd_send()Ralph Boehme2017-07-031-1/+1
| | | | | | | | No change in behaviour, this just ensures stdout and stderror are logged with log level 0. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* lib/util: make use of tfork in samba_runcmd_send()Ralph Boehme2017-07-032-50/+59
| | | | | | | | This makes it possible to use samba_runcmd_send() in processes like smbd that install a SIGCHLD handler that reaps all terminated children. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* lib/util: enhanced tfork()Ralph Boehme2017-07-033-260/+855
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This function is a solution to the problem of fork() requiring special preperations in the caller to handle SIGCHLD signals and to reap the child by wait()ing for it. Instead, tfork provides a pollable file descriptor. The caller gets the file descriptor by calling tfork_event_fd() on the handle returned from tfork_create() and the caller can then get the status of the child with a call to tfork_status(). tfork avoids raising SIGCHLD signals in the caller by installing a temporary SIGCHLD handler from inside tfork_create() and tfork_status(). The termination signal of other child processes not created with tfork() is forwarded to the existing signal handler if any. There's one thing this thing can't protect us against and that is if a process installs a SIGCHLD handler from one thread while another thread is running inside tfork_create() or tfork_status() and the signal handler doesn't forward signals for exitted childs it didn't fork, ie our childs. Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Ralph Boehme <slow@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org>
* s3: VFS: Change SMB_VFS_GETWD to return struct smb_filename * instead of char *.Jeremy Allison2017-07-011-0/+1
| | | | | | | | We need to migrate all pathname based VFS calls to use a struct to finish modernising the VFS with extra timestamp and flags parameters. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Richard Sharpe <realrichardsharpe@gmail.com>
* debug: new debug class for kerberosAndrew Bartlett2017-06-302-0/+3
| | | | | Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
* lib: Give util_paths.c its own headerVolker Lendecke2017-06-244-25/+56
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* libbreplace: compatibility fix for AIXGuillaume Xavier Taillon2017-06-131-1/+1
| | | | | | | | | | | | | | Adds macros for preprocessor compares and replaces an incomptatible compare with one of the new macros. This fixes a comptability bug on AIX. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11621 Signed-off-by: Guillaume Xavier Taillon <gtaillon@ca.ibm.com> Reviewed-by: Björn Jacke <bjacke@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Björn Jacke <bj@sernet.de> Autobuild-Date(master): Tue Jun 13 09:11:56 CEST 2017 on sn-devel-144
* lib:util: Make loading of modules more secureAndreas Schneider2017-06-061-59/+42
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=12780 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib:util: Make probing of modules more secureAndreas Schneider2017-06-062-1/+66
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=12780 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib:util: Rename smb_load_modules()Andreas Schneider2017-06-062-2/+2
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=12780 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib:util: Add new function to load modules from absolute pathAndreas Schneider2017-06-061-2/+40
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=12780 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Fix illegal use of 0-length arraysVolker Lendecke2017-06-061-2/+8
| | | | | | | Found and confirmed to work by albert chin (china@thewrittenword.com) Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: FreeBSD needs sys/wait.h for WIFEXITEDVolker Lendecke2017-05-021-0/+1
| | | | | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Tue May 2 21:14:22 CEST 2017 on sn-devel-144
* systemd: fix detection of libsystemdAlexander Bokovoy2017-05-021-7/+8
| | | | | | | | | | | | | | | | | On Fedora 25 detection of libsystemd actually fails due to wrong assumptions in the configure test. conf.CHECK_LIB returns a list so 'not conf.CHECK_LIB(...)' is always False and we never get to check libsystemd. Instead, remember result of checking pkg-config for separate libsystemd-daemon and libsystemd-journal libraries. If they miss, attempt to use libsystemd library instead. Signed-off-by: Alexander Bokovoy <ab@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Tue May 2 13:05:43 CEST 2017 on sn-devel-144
* Revert "lib/util: make use of tfork in samba_runcmd_send()"Ralph Boehme2017-04-302-58/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 292e46ab12d8ec172c9d3b26330d8d6028a1d5a5. Processes run by tfork will have a parent pid of 1, they won't be childs of the caller anymore. When the source4 samba process uses samba_runcmd_send() to launch smbd and winbindd the resulting process hierarchy becomes: PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 1 516 510 510 ? -1 S 111 0:02 avahi-daemon: running [samba-ad.local] 1 29209 29209 29209 ? -1 Ss 0 0:00 ./bin/samba 29209 29210 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29211 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29213 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29215 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29216 29209 29209 ? -1 R 0 0:00 \_ ./bin/samba 29209 29217 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29218 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29220 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29221 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29222 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29223 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29224 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 29209 29225 29209 29209 ? -1 S 0 0:00 \_ ./bin/samba 1 29214 29209 29209 ? -1 S 0 0:00 ./bin/samba 29214 29219 29219 29219 ? -1 Ss 0 0:00 \_ /home/slow/git/samba/scratch/bin/smbd -D --option=server role check:inhibit=yes --foreground 29219 29236 29219 29219 ? -1 S 0 0:00 \_ /home/slow/git/samba/scratch/bin/smbd -D --option=server role check:inhibit=yes --foreground 29219 29237 29219 29219 ? -1 S 0 0:00 \_ /home/slow/git/samba/scratch/bin/smbd -D --option=server role check:inhibit=yes --foreground 29219 29238 29219 29219 ? -1 S 0 0:00 \_ /home/slow/git/samba/scratch/bin/smbd -D --option=server role check:inhibit=yes --foreground 1 29228 29209 29209 ? -1 S 0 0:00 ./bin/samba 29228 29230 29230 29230 ? -1 Ss 0 0:00 \_ /home/slow/git/samba/scratch/bin/winbindd -D --option=server role check:inhibit=yes --foreground 29230 29239 29230 29230 ? -1 S 0 0:00 \_ /home/slow/git/samba/scratch/bin/winbindd -D --option=server role check:inhibit=yes --foreground They will still be in the same process group and session, but just not be a child or subchild. For childs of the source4 samba process this might be non desirable. killing all processes by sending a signal to the main samba process still works, because a pipe is used between the samba process and the smbd and winbindd childs. Both watch for EOF on the pipe. In the output above smbd and winbindd are in their own process group ans session because they call become_daemon(). See also the discussion in this mailthread: <https://lists.samba.org/archive/samba-technical/2017-April/120257.html> Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Sun Apr 30 17:21:05 CEST 2017 on sn-devel-144
* lib/util: fix a Coverity finding in tforkRalph Boehme2017-04-251-5/+18
| | | | | | | If dup2() fails, fd is -1 and is later used in sys_write(). Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: modules: Change XXX_init interface from XXX_init(void) to ↵Jeremy Allison2017-04-222-6/+6
| | | | | | | | | | | | | | | | | | | | 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
* lib/util: add a test for samba_runcmd_send()Ralph Boehme2017-04-201-0/+36
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/util: make use of tfork in samba_runcmd_send()Ralph Boehme2017-04-202-48/+58
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/util: add a test for tfork()Ralph Boehme2017-04-201-0/+102
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/util: add tfork()Stefan Metzmacher2017-04-203-2/+380
| | | | | | | | | | | | | | | triple-fork to avoid handling SIGCHLD in the parent. This function is a workaround for the problem of using fork() in library code. In that case the library should avoid setting a global signal handler for SIGCHLD, because the application may wants to use its own handler. status_fd can be used to wait for the child to exit and get its exit status. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/util: add and use iov_concatRalph Boehme2017-04-183-3/+25
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* lib: debug: Avoid negative array access.Jeremy Allison2017-04-181-1/+1
| | | | | | | | | | Report and patch from Hanno Böck <hanno@hboeck.de>. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12746 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Andreas Schneider <asn@samba.org>
* lib:charset: Remove use of talloc_autofree_context() for global_iconv_handleJeremy Allison2017-04-181-3/+9
| | | | | | | | All other callers use NULL here anyway, so there's no need to use a special context for get_iconv_handle(). Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* lib:charset: Make global_iconv_handle privateJeremy Allison2017-04-182-2/+1
| | | | | Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* lib:charset: Add utility functions reinit_iconv_handle() and ↵Jeremy Allison2017-04-182-0/+23
| | | | | | | | | free_iconv_handle(void) Not yet used. Will enable us to make global_iconv_handle private. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* auth_log: Add JSON logging of Authorisation and AuthenticationsGary Lockyer2017-03-292-1/+2
| | | | | Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Pair-Programmed: Andrew Bartlett <abartlet@samba.org>
* debug: Add debug class for auth_auditAndrew Bartlett2017-03-292-0/+2
| | | | | | | | This will be an audit stream of authentication and connection-level authorization Signed-off-by: Andrew Bartlett <abartlet@samba.org> Pair-Programmed-by: Gary Lockyer <gary@catalyst.net.nz> Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
* lib/util: Add functions to escape log lines but not break all non-asciiGary Lockyer2017-03-294-0/+248
| | | | | | | | | We do not want to turn every non-ascii username into a pile of hex, so we instead focus on avoding newline insertion attacks and other low control chars Pair-programmed-by: Andrew Bartlett <abartlet@samba.org> Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Signed-off-by: Andrew Bartlett <abartlet@samba.org>
* lib: Avoid an includes.hVolker Lendecke2017-03-281-1/+3
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Avoid an includes.hVolker Lendecke2017-03-281-3/+5
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Avoid an includes.hVolker Lendecke2017-03-281-1/+2
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Avoid an includes.hVolker Lendecke2017-03-281-1/+5
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Avoid an includes.hVolker Lendecke2017-03-281-2/+2
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Avoid an includes.hVolker Lendecke2017-03-281-1/+1
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>