summaryrefslogtreecommitdiff
path: root/source3/lib/system.c
AgeCommit message (Collapse)AuthorFilesLines
2026-01-14lib: Fix the build on solarisVolker Lendecke1-9/+2
Solaris does not define HAVE_POSIX_CAPABILITIES and does not have cap_value_t. Confirmed by the reporter. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Wed Jan 14 15:25:00 UTC 2026 on atb-devel-224
2026-01-12lib: Remove [set|drop]_effective_capability and enum smbd_capabilityVolker Lendecke1-132/+0
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Mon Jan 12 10:39:38 UTC 2026 on atb-devel-224
2026-01-12lib: Add capability-specific functionsVolker Lendecke1-0/+100
This makes the one-attempt logic for dac_override simpler to understand. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2026-01-12lib: Remove LEASE_CAPABILITYVolker Lendecke1-5/+0
This was only used via vfs_gpfs, and that removed its use in 2020. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2026-01-12lib: Remove KERNEL_OPLOCK_CAPABILITYVolker Lendecke1-6/+0
This was only used in the IRIX oplock code, which was removed in 2018. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2025-11-10lib: Remove some unused code #ifdef'ed out for more than 10 yearsVolker Lendecke1-47/+0
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org>
2024-06-28smbd: Simplify copy_stat_ex_timestampsVolker Lendecke1-5/+6
copy_stat_ex_timestamps doesn't need the fsp, it only needs the destination stat struct Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2024-04-01source3/smbd: Update timestamps after a successful SMB_VFS_FNTIMESAnoop C S1-0/+19
When an open file handle is used to change timestamps we fail to return updated values to clients until next open is issued. Unless we fill in the timestamps subsequent calls like GETINFO cannot see the latest value causing incorrect results. Therefore copy those timestamp values as soon as it is set on the backend. Signed-off-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2024-01-20source3/lib: Properly log the change in capabilityAnoop C S1-2/+4
We used to log the following message for both adding and dropping capability: DBG_INFO("added capability %d\n", capability); For better clarity indicate the change as "added" or "dropped" based on available functional arguments. Signed-off-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org> Autobuild-User(master): Anoop C S <anoopcs@samba.org> Autobuild-Date(master): Sat Jan 20 18:43:10 UTC 2024 on atb-devel-224
2024-01-16system.c: fix fake directory create timesBjoern Jacke1-0/+1
This was broken by c9c3d4312d7281904fc back in 2009 already. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12421 Signed-off-by: Bjoern Jacke <bjacke@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2024-01-05set_process_capability: log which capability was set or failed to be setBjörn Jacke1-2/+3
Signed-off-by: Bjoern Jacke <bjacke@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2023-11-16system.c: fall back to become_root if CAP_DAC_OVERRIDE isn't usableBjörn Jacke1-2/+29
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15093 Signed-off-by: Bjoern Jacke <bjacke@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2023-11-01smbd: Simplify sys_proc_fd_path()Volker Lendecke1-45/+10
We know the buffer size up-front, create a struct for that. Also, I think if we ever hit another /proc pattern this is very likely on a different OS that could be handled by an #ifdef. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2023-07-13s3:lib: Fix code spellingAndreas Schneider1-11/+11
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Martin Schwenke <mschwenke@ddn.com>
2022-03-31smbd: remove itime and file_id logic and codeRalph Boehme1-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>
2022-01-10s3: includes: Make the comments describing itime consistent. Always use ↵Jones Syue1-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
2022-01-10s3: lib: In create_clock_itime(), use timespec_current() -> ↵Jeremy Allison1-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>
2022-01-08s3: smbd: Create and use a common function for generating a fileid - ↵Jeremy Allison1-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
2021-09-14system: Remove kernel_flockChristof Schmitt1-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>
2021-09-09Don't use sysconf(_SC_NGROUPS_MAX) on macOS for getgroups()Alex Richardson1-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
2021-07-14s3: lib: Add sys_fstatat() wrapper.Jeremy Allison1-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>
2021-02-09s3 lib system: Change signature of sys_proc_fd_pathGary Lockyer1-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
2021-02-09s3 lib system: Fix clang compilation errorGary Lockyer1-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>
2020-12-16s3/lib: add proc fds infrastructureRalph Boehme1-0/+56
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2020-11-10lib: Fix a theoretical out-of-bounds writeVolker Lendecke1-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>
2020-11-10lib: Fix a signed/unsigned warningVolker Lendecke1-1/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2020-08-15lib/util: Standardize use of st_[acm]time nsMatthew DeVore1-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
2020-08-15s3: lib: Fix unneeded relative path in #include.Matthew DeVore1-1/+1
Signed-off-by: Matthew DeVore <matvore@google.com> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2020-01-08system: Rename argument for kernel_flock functionChristof Schmitt1-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>
2019-10-08s3: VFS: Add SMB_VFS_FCNTLAnoop C S1-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>
2019-09-10s3:lib: add update_stat_ex_from_saved_stat()Ralph Boehme1-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>
2019-08-22s3: smbd: Add sys_mknodat() wrapper call.Jeremy Allison1-0/+15
Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Böhme <slow@samba.org>
2019-07-01s3/lib: add update_stat_ex_file_id()Ralph Boehme1-0/+6
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2019-07-01s3/lib: add update_stat_ex_itime()Ralph Boehme1-0/+7
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2019-07-01s3: add st_ex_file_id to struct stat_exRalph Boehme1-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>
2019-07-01s3: add st_ex_itime to struct stat_exRalph Boehme1-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>
2019-07-01s3: convert struct stat_ex st_ex_calculated_birthtime bool to flagsRalph Boehme1-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>
2018-12-16s3:lib: Fix checking for config.h #define in system.cAndreas Schneider1-1/+1
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2018-11-28s3:lib: Use #ifdef instead of #if for config.h definitionsAndreas Schneider1-2/+2
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2017-10-04s3: VFS: Protect errno if sys_getwd() fails across free() call.Jeremy Allison1-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>
2017-10-04s3: VFS: Ensure sys_getwd() doesn't leak memory on error on really old systems.Jeremy Allison1-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>
2017-08-24configure: Centralize check for posix_fallocateVolker Lendecke1-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>
2017-04-18s3:lib: Fix incorrect logic in sys_broken_getgroups()Jeremy Allison1-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>
2016-02-23lib: Extract sys_popen()Volker Lendecke1-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>
2016-02-23lib: Remove sys_waitpidVolker Lendecke1-14/+1
We have waitpid in libreplace Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
2016-01-27s3-lib: introduce sys_realpath()Uri Simchoni1-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>
2015-05-13Convert all uint32/16/8 to _t in source3/lib.Richard Sharpe1-4/+4
Signed-off-by: Richard Sharpe <rsharpe@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-04-29Change all uses of uint32/16/8 in proto.h to uint32_t/16_t/8_t.Richard Sharpe1-3/+3
Signed-off-by: Richard Sharpe <rsharpe@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-03-09system: add hole punch support to sys_fallocate()David Disseldorp1-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>
2015-03-09s3/vfs: change fallocate mode flags from enum->uint32_tDavid Disseldorp1-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>