summaryrefslogtreecommitdiff
path: root/source3/lib/system.c
Commit message (Collapse)AuthorAgeFilesLines
* smbd: remove itime and file_id logic and codeRalph Boehme2022-03-311-78/+0
| | | | | | | | | | | | | | | | | | This bases File-Ids on the inode numbers again. The whole stuff was added because at that time Apple clients 1. would be upset by inode number reusage and 2. had a client side bug in their fallback implemetentation that assigns File-Ids on the client side in case the server provides File-Ids of 0. After discussion with folks at Apple it should be safe these days to rely on the Mac to generate its own File-Ids and let Samba return 0 File-Ids. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3: includes: Make the comments describing itime consistent. Always use ↵Jones Syue2022-01-101-1/+1
| | | | | | | | | | | | | | "invented" time. It gets confusing if we call it "imaginary" or "instantiation" in different places. Signed-off-by: Jones Syue <jonessyue@qnap.com> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Jan 10 18:42:02 UTC 2022 on sn-devel-184
* s3: lib: In create_clock_itime(), use timespec_current() -> ↵Jeremy Allison2022-01-101-1/+1
| | | | | | | | | | | | | | | clock_gettime(CLOCK_REALTIME..). CLOCK_MONOTONIC (which we previously used) is reset when the system is rebooted. CLOCK_REALTIME is a "wall clock" time. It's still affected by NTP changes (for Linux we should probably use CLOCK_TAI instead but that is Linux-specific). For most systems CLOCK_REALTIME will be good enough. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* s3: smbd: Create and use a common function for generating a fileid - ↵Jeremy Allison2022-01-081-0/+52
| | | | | | | | | | | | | | | | | | | | | | | create_clock_itime(). This first gets the clock_gettime_mono() value, converts to an NTTIME (as this is what is stored in the dos attribute EA), then mixes in 8 bits of randomness shifted up by 55 bits to cope with poor resolution clocks to avoid duplicate inodes. Using 8 bits of randomness on top of an NTTIME gives us around 114 years headroom. We can now guarentee returning a itime-based fileid in a normal share (storing dos attributes in an EA). Remove knownfail.d/fileid-unique BUG: https://bugzilla.samba.org/show_bug.cgi?id=14928 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Sat Jan 8 06:35:22 UTC 2022 on sn-devel-184
* system: Remove kernel_flockChristof Schmitt2021-09-141-33/+0
| | | | | | | | LOCK_MAND will be deprecated in the Linux kernel, so stop using this feature and remove the kernel_flock function. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* Don't use sysconf(_SC_NGROUPS_MAX) on macOS for getgroups()Alex Richardson2021-09-091-3/+21
| | | | | | | | | | | | | | | | | | | | | On MacOS sysconf(_SC_NGROUPS_MAX) always returns 16. However, this is not the value used by getgroups(2). MacOS uses nested groups but getgroups(2) will return the flattened list which can easily exceed 16 groups. In my testing getgroups() already returns 16 groups on a freshly installed system. And on a 10.14 system the root user is in more than 16 groups by default which makes it impossible to run smbd without this change. Setting _DARWIN_UNLIMITED_GETGROUPS allows getgroups() to return more than 16 groups. This also changes set_unix_security_ctx() to only set up to 16 groups since that is the limit for initgroups() according to the manpage. BUG: https://bugzilla.samba.org/show_bug.cgi?id=8773 Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> 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): Thu Sep 9 17:43:19 UTC 2021 on sn-devel-184
* s3: lib: Add sys_fstatat() wrapper.Jeremy Allison2021-07-141-0/+26
| | | | | | | Does the usual things we need with fake_dir_create_times. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* s3 lib system: Change signature of sys_proc_fd_pathGary Lockyer2021-02-091-1/+1
| | | | | | | | | | It's always called with sizeof(buf) Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Feb 9 04:16:43 UTC 2021 on sn-devel-184
* s3 lib system: Fix clang compilation errorGary Lockyer2021-02-091-0/+7
| | | | | | | | Fix clang compilation error: error: format string is not a string literal [-Werror,-Wformat-nonliteral] Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3/lib: add proc fds infrastructureRalph Boehme2020-12-161-0/+56
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Fix a theoretical out-of-bounds writeVolker Lendecke2020-11-101-3/+8
| | | | | | | | | | | | | This routine looked fishy: We do cap_vals[num_cap_vals++] = XXX based on #ifdefs and capabilities. Then later on we did a check that we did not overwrite the stack. The change I did is to just count the number of num_cap_vals++, right now it's 5. I know it is in different switch branches, but with the #ifdefs it's a bit clumsy to read the exact number of actual num_cap_vals++ that can happen in one run. On debian buster, cap_val_t is an int, so this is not really wasting too much. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Fix a signed/unsigned warningVolker Lendecke2020-11-101-1/+1
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/util: Standardize use of st_[acm]time nsMatthew DeVore2020-08-151-118/+1
| | | | | | | | | | | | | | | | | | | | | Commit 810397f89a10, and possibly others, broke the build for macOS and other environments which don't have st_[acm]tim fields on 'struct stat'. Multiple places in the codebase used the config.h values to determine how to access the nanosecond or microsecond values of the stat timestamps, so rather than add more, centralize them all into lib/util/time.c. Also allow pvfs_fileinfo.c to read nanosecond-granularity timestamps on platforms where it didn't before, since its #if branches were not complete. Signed-off-by: Matthew DeVore <matvore@google.com> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Sat Aug 15 08:51:09 UTC 2020 on sn-devel-184
* s3: lib: Fix unneeded relative path in #include.Matthew DeVore2020-08-151-1/+1
| | | | | | Signed-off-by: Matthew DeVore <matvore@google.com> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
* system: Rename argument for kernel_flock functionChristof Schmitt2020-01-081-4/+4
| | | | | | | | MS-SMB2 and the smbd code refer to this field as share_access. Use the same name in the function argument. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3: VFS: Add SMB_VFS_FCNTLAnoop C S2019-10-081-0/+14
| | | | | | Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3:lib: add update_stat_ex_from_saved_stat()Ralph Boehme2019-09-101-0/+20
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=14121 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* s3: smbd: Add sys_mknodat() wrapper call.Jeremy Allison2019-08-221-0/+15
| | | | | Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Böhme <slow@samba.org>
* s3/lib: add update_stat_ex_file_id()Ralph Boehme2019-07-011-0/+6
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3/lib: add update_stat_ex_itime()Ralph Boehme2019-07-011-0/+7
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3: add st_ex_file_id to struct stat_exRalph Boehme2019-07-011-0/+2
| | | | | | | | st_ex_file_id is an immutable, never reused numeric identifier for objects in a filesystem. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3: add st_ex_itime to struct stat_exRalph Boehme2019-07-011-0/+3
| | | | | | | | st_ex_itime is an immutable original birth time aka instantiation time. Set when a file is created, never changes thereafter. May not be set by the client. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3: convert struct stat_ex st_ex_calculated_birthtime bool to flagsRalph Boehme2019-07-011-5/+6
| | | | | | | Subsequent commits will add more flags, this paves the way. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3:lib: Fix checking for config.h #define in system.cAndreas Schneider2018-12-161-1/+1
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
* s3:lib: Use #ifdef instead of #if for config.h definitionsAndreas Schneider2018-11-281-2/+2
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
* s3: VFS: Protect errno if sys_getwd() fails across free() call.Jeremy Allison2017-10-041-0/+4
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=13069 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* s3: VFS: Ensure sys_getwd() doesn't leak memory on error on really old systems.Jeremy Allison2017-10-041-1/+6
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=13069 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* configure: Centralize check for posix_fallocateVolker Lendecke2017-08-241-1/+1
| | | | | | | | | | | | | This checks for posix_fallocate unless we are sitting on an ancient glibc. With this we don't need HAVE_BROKEN_POSIX_FALLOCATE anymore, HAVE_POSIX_FALLOCATE will only be defined if we have a valid [g]libc. ./configure tested on Debian, FreeBSD (which does have posix_fallocate) and OpenBSD (which does not have posix_fallocate). Also tested with changing the not have an old-enough glibc around. All did the right thing. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* s3:lib: Fix incorrect logic in sys_broken_getgroups()Jeremy Allison2017-04-181-5/+7
| | | | | | | | | If setlen == 0 then the second argument must be ignored. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12747 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* lib: Extract sys_popen()Volker Lendecke2016-02-231-231/+0
| | | | | | | | | | | | This was added by Jeremy with 3cf31a194f5, do the (C) accordingly sys_popen is a pretty isolated functionality, and I'd like to use it soon without "includes.h", needed by "proto.h" Except for one malloc->talloc this is supposed to be a 1:1 copy Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* lib: Remove sys_waitpidVolker Lendecke2016-02-231-14/+1
| | | | | | | We have waitpid in libreplace Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
* s3-lib: introduce sys_realpath()Uri Simchoni2016-01-271-0/+25
| | | | | | | | Add sys_realpath() function that captures the OS variations on realpath(). Signed-off-by: Uri Simchoni <uri@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* Convert all uint32/16/8 to _t in source3/lib.Richard Sharpe2015-05-131-4/+4
| | | | | Signed-off-by: Richard Sharpe <rsharpe@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* Change all uses of uint32/16/8 in proto.h to uint32_t/16_t/8_t.Richard Sharpe2015-04-291-3/+3
| | | | | Signed-off-by: Richard Sharpe <rsharpe@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* system: add hole punch support to sys_fallocate()David Disseldorp2015-03-091-2/+9
| | | | | | | | If Samba is configured with FALLOC_FL_PUNCH_HOLE support, then allow sys_fallocate() to propogate the flag to syscall invocation. Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* s3/vfs: change fallocate mode flags from enum->uint32_tDavid Disseldorp2015-03-091-10/+11
| | | | | | | | | | | | | | | | | | | | The Linux fallocate syscall offers a mode parameter which can take the following flags: FALLOC_FL_KEEP_SIZE FALLOC_FL_PUNCH_HOLE (since 2.6.38) FALLOC_FL_COLLAPSE_RANGE (since 3.15) FALLOC_FL_ZERO_RANGE (since 3.14) The flags are not exclusive, e.g. FALLOC_FL_PUNCH_HOLE must be specified alongside FALLOC_FL_KEEP_SIZE. Samba currently takes a vfs_fallocate_mode enum parameter for the VFS fallocate hook, taking either an EXTEND_SIZE or KEEP_SIZE value. This commit changes the fallocate hook such that it accepts a uint32_t flags parameter, in preparation for PUNCH_HOLE and ZERO_RANGE support. Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/system: remove useless HAVE_LINUX_FALLOCATE64 logicDavid Disseldorp2015-03-091-3/+1
| | | | | Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Split out sys_[read|write] & friendsVolker Lendecke2014-12-071-90/+0
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* Remove a few #ifdef EWOULDBLOCkVolker Lendecke2014-09-181-16/+4
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
* s3: nmbd: Fix bug 10633 - nmbd denial of serviceJeremy Allison2014-06-251-5/+2
| | | | | | | | | | | | | | | | | The Linux kernel has a bug in that it can give spurious wakeups on a non-blocking UDP socket for a non-deliverable packet. When nmbd was changed to use non-blocking sockets it became vulnerable to a spurious wakeup from poll/epoll. Fix sys_recvfile() to return on EWOULDBLOCK/EAGAIN. CVE-2014-0244 https://bugzilla.samba.org/show_bug.cgi?id=10633 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* s3: Add DAC_OVERRIDE capability supportAbhidnya Joshi2013-12-161-0/+4
| | | | | Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
* debug: remove unused sys_adminlogDavid Disseldorp2013-11-201-25/+0
| | | | | | | | | | printing.c was the last user of this syslog wrapper. Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Guenther Deschner <gd@samba.org> Autobuild-User(master): Günther Deschner <gd@samba.org> Autobuild-Date(master): Wed Nov 20 10:19:32 CET 2013 on sn-devel-104
* s3:lib/system fix build on AIX 7Christian Ambach2013-08-021-3/+12
| | | | | | | | | | | AIX uses struct stat64 with struct timespec64, so direct assignment does not work any more. Pair-Programmed-With: Volker Lendecke <vl@samba.org> Signed-off-by: Christian Ambach <ambi@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Fri Aug 2 09:47:43 CEST 2013 on sn-devel-104
* Remove dependency on detection of HAVE_DIRFD for use of fdopendir().Jeremy Allison2013-04-121-3/+1
| | | | | | | | Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Apr 12 16:21:10 CEST 2013 on sn-devel-104
* s3: in sys_popen(), add a debug message for failed forkMichael Adam2012-09-041-0/+1
| | | | | Autobuild-User(master): Michael Adam <obnox@samba.org> Autobuild-Date(master): Tue Sep 4 22:17:30 CEST 2012 on sn-devel-104
* s3: in sys_popen(), add a debug message for failed extract_args()Michael Adam2012-09-041-0/+1
|
* s3: in sys_popen(), untangle function call from result checkMichael Adam2012-09-041-1/+3
|
* s3: in sys_popen(), untangle assigment from check and add a debug message in ↵Michael Adam2012-09-041-1/+4
| | | | failure case
* s3: in sys_popen(), improve call to pipe and report error to debugMichael Adam2012-09-041-1/+5
|
* s3: in sys_popen(), validate input before opening the pipe.Michael Adam2012-09-041-5/+5
|