cifs-utils.git
9 months agocifs-utils: bump version to 7.5 cifs-utils-7.5
Steve French [Tue, 10 Jun 2025 23:48:48 +0000 (23:48 +0000)]
cifs-utils: bump version to 7.5

Signed-off-by: Steve French <stfrench@microsoft.com>
9 months agodocs: update echo_interval description
Paulo Alcantara [Tue, 25 Nov 2025 20:58:29 +0000 (17:58 -0300)]
docs: update echo_interval description

It is '3 * echo_interval' since upstream commit f2caf901c1b7 ("cifs:
Fix a race condition with cifs_echo_request").

Reported-by: Alexandros Panagiotou <apanagio@redhat.com>
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Cc: Steve French <smfrench@gmail.com>
Cc: linux-cifs@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
9 months agocifscreds: fix parsing of commands and parameters
Paulo Alcantara [Tue, 25 Nov 2025 19:55:41 +0000 (16:55 -0300)]
cifscreds: fix parsing of commands and parameters

Fix the parsing of '--username' and '--timeout' options as both
require an argument by fixing the value passed in @optstring when
calling getopt_long(3).

Also fix the matching of commands by breaking the loop when an exact
match is found.  Otherwise `cifscreds clear ...` would return
"Ambiguous command" due to "clearall" command.

* Before patch

$ ./cifscreds add -u testuser w22-root2.zelda.test
error: Could not resolve address for testuser
$ ./cifscreds add -u testuser -d ZELDA
Password:
$ grep 'cifs:[ad]' /proc/keys
198de7a1 I--Q---     1 perm 0d0d0000     0     0 logon     cifs:d:testuser: 13
                                                                  ^^ wrong desc
$ ./cifscreds clear -u testuser w22-root2.zelda.test
Ambiguous command
$ ./cifscreds clear -u testuser -d ZELDA
Ambiguous command

* After patch

$ ./cifscreds add -u testuser w22-root2.zelda.test
Password:
$ ./cifscreds add -u testuser -d ZELDA
Password:
$ grep 'cifs:[ad]' /proc/keys
089183a9 I--Q---     1 perm 0d0d0000     0     0 logon     cifs:a:192.168.124.32: 17
0ca5ed80 I--Q---     1 perm 0d0d0000     0     0 logon     cifs:d:ZELDA: 17
$ ./cifscreds clear -u testuser w22-root2.zelda.test
$ ./cifscreds clear -u testuser -d ZELDA

Reported-by: Xiaoli Feng <xifeng@redhat.com>
Reported-by: Jay Shin <jaeshin@redhat.com>
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Cc: Steve French <smfrench@gmail.com>
Cc: linux-cifs@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
9 months agocifs-utils: Fix documentation for character remappings.
Eduard Bachmakov [Thu, 14 Aug 2025 21:22:14 +0000 (23:22 +0200)]
cifs-utils: Fix documentation for character remappings.

Current documentation swapped the relevant specs. Additionally,
elaborate on SFM a bit.

Supported by fs/cifs/cifs_unicode.c:{convert_to_sfu_char,
convert_to_sfm_char}.

Previously raised in:

  https://lore.kernel.org/linux-cifs/CADCRUiMn_2Vk3HZzU0WKu3xPgo1P-1aqDy+NjEzOz03W-HFChw@mail.gmail.com/

Signed-off-by: Eduard Bachmakov <e.bachmakov@gmail.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
15 months agocifs-utils: bump version to 7.4 cifs-utils-7.4
Pavel Shilovsky [Tue, 10 Jun 2025 23:48:48 +0000 (23:48 +0000)]
cifs-utils: bump version to 7.4

16 months agomount.cifs: retry mount on -EINPROGRESS
Enzo Matsumiya [Tue, 3 Jun 2025 15:07:36 +0000 (12:07 -0300)]
mount.cifs: retry mount on -EINPROGRESS

cifs.ko mount might return -EINPROGRESS even for blocking sockets.

This patch makes mount.cifs retry mount when DNS resolution
returns >1 IP addresses for a server and such error occurs.

It's ok to retry because cifs.ko will consider it a hard error and abort
the mount anyway, so there's no risk of duplicate mounts.

Signed-off-by: Enzo Matsumiya <ematsumiya@suse.de>
Reviewed-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
16 months agocifs.upcall: correctly treat UPTARGET_UNSPECIFIED as UPTARGET_APP
Henrique Carvalho [Fri, 30 May 2025 15:28:14 +0000 (12:28 -0300)]
cifs.upcall: correctly treat UPTARGET_UNSPECIFIED as UPTARGET_APP

Kernels lacking commit db363b0a1d9e ("CIFS: New mount option for
cifs.upcall namespace resolution") omit the field upcall_target from the
key description sent to cifs.upcall, leaving args->upcall_target as
UPTARGET_UNSPECIFIED. That makes get_cachename_from_process_env() search
root's environment instead of the applications's environment (default
behavior), breaking some mounts.

Explicitly set arg->upcall_target to UPTARGET_APP.

Fixes: 89b679228cc1 ("CIFS.upcall to accommodate new namespace mount opt")
Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
16 months agocifscreds: use <libgen.h> for basename
Z. Liu [Mon, 12 May 2025 23:31:46 +0000 (07:31 +0800)]
cifscreds: use <libgen.h> for basename

fix another implicit declaration of function 'basename' in musl

Signed-off-by: Z. Liu <zhixu.liu@gmail.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
17 months agogetcifsacl, setcifsacl: use <libgen.h> for basename
Z. Liu [Fri, 2 May 2025 15:08:41 +0000 (23:08 +0800)]
getcifsacl, setcifsacl: use <libgen.h> for basename

basename() is defined in <libgen.h> only in musl, while glibc defines it
in <string.h> too, which is not standard behavior.

Signed-off-by: Z. Liu <zhixu.liu@gmail.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
17 months agocifs.upcall: fix memory leaks in check_service_ticket_exits()
Paulo Alcantara [Tue, 15 Apr 2025 16:20:52 +0000 (13:20 -0300)]
cifs.upcall: fix memory leaks in check_service_ticket_exits()

The error message returned by krb5_get_error_message() must be freed
using krb5_free_error_message().

Fixes: af76bf2a11a0 ("cifs-utils: Skip TGT check if valid service ticket is already available")
Acked-by: Bharath SM <bharathsm@microsoft.com>
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
18 months agocifs-utils: bump version to 7.3 cifs-utils-7.3
Pavel Shilovsky [Thu, 20 Mar 2025 22:54:33 +0000 (22:54 +0000)]
cifs-utils: bump version to 7.3

18 months agoFix regression in mount.cifs with guest mount option
Meetakshi Setiya [Sat, 15 Mar 2025 06:49:13 +0000 (06:49 +0000)]
Fix regression in mount.cifs with guest mount option

mount.cifs was erroneously passing the empty password and password2
strings to the linux smb client for "guest" mounts. Handling empty
password2 has not been implemented on the client yet, which ends up
failing the mount with "cifs: Bad value for password2".

This patch contains fixes for the mentioned scenario.

Signed-off-by: Meetakshi Setiya <msetiya@microsoft.com>
Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Reviewed-by: Bharath SM <bharathsm@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
18 months agoresolve_host.c: Initialize site_name
Pavel Filipenský [Wed, 9 Oct 2024 10:39:23 +0000 (12:39 +0200)]
resolve_host.c: Initialize site_name

reported by Red Hat code analyzer:

cifs-utils-7.1/resolve_host.c:188:3: uninit_use_in_call: Using
uninitialized value "*site_name" as argument to "%s" when calling
"snprintf".

Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
18 months agocldap_ping: Fix socket fd leak
Pavel Filipenský [Wed, 9 Oct 2024 10:37:12 +0000 (12:37 +0200)]
cldap_ping: Fix socket fd leak

reported by Red Hat code analyzer:

cifs-utils-7.1/cldap_ping.c:323:3: leaked_handle: Handle variable "sock" going out of scope leaks the handle.

Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
19 months agocifs-utils: bump version to 7.2 cifs-utils-7.2
Pavel Shilovsky [Mon, 7 Oct 2024 00:07:14 +0000 (17:07 -0700)]
cifs-utils: bump version to 7.2

Signed-off-by: Steve French <stfrench@microsoft.com>
19 months agogetcifsacl: fix return code check for getting full ACL
Steve French [Thu, 13 Feb 2025 02:22:00 +0000 (20:22 -0600)]
getcifsacl: fix return code check for getting full ACL

Older clients incorrectly mapped STATUS_PRIVILEGE_NOT_HELD to
EIO instead of EPERM, so make sure we check for either of these rc
when deciding whether to fall back to querying just the DACL (and
owner) when  querying the complete ACL including SACL (ie Auditing
information) fails with insufficient permissions.

Cc: Boris Protopopov <pboris@amazon.com>
Acked-by: Bharath SM <bharathsm@microsoft.com>
Reported-by: Jianhong Yin <jiyin@redhat.com>
Closes: https://lore.kernel.org/r/2bdf635d3ebd000480226ee8568c32fb@manguebit.com
Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agocifs-utils: add documentation for upcall_target
Ritvik Budhiraja [Thu, 30 Jan 2025 14:13:10 +0000 (14:13 +0000)]
cifs-utils: add documentation for upcall_target

Update man page with documentation for upcal_target
mount parameter.

Signed-off-by: Ritvik Budhiraja <rbudhiraja@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agocifs-utils: avoid using mktemp when updating mtab
Steve French [Tue, 21 Jan 2025 00:34:38 +0000 (18:34 -0600)]
cifs-utils: avoid using mktemp when updating mtab

Fix build warning: cifs-utils/mount.cifs.c:1726:
    warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'

Use of mktemp() has been deprecated (e.g. due to security issues with
symlink races), and instead mkstemp is often recommended.  Change
the use of mktemp to mkstemp in del_mtab in cifs-utils

Tested-by: Meetakshi Setiya <msetiya@microsoft.com>
Reviewed-by: Meetakshi Setiya <msetiya@microsoft.com>
Reviewed-by: Shyam Prasad N <sprasad@microsoft.com>
Fixes: f46dd7661cfb ("mount.cifs: Properly update mtab during remount")
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agocldap_ping.c: add missing <sys/types.h> include
Thomas Petazzoni [Thu, 26 Dec 2024 20:42:35 +0000 (21:42 +0100)]
cldap_ping.c: add missing <sys/types.h> include

Fixes:

cldap_ping.c: In function ‘read_dns_string’:
cldap_ping.c:72:37: error: ‘u_char’ undeclared (first use in this function)

when building with the musl C library, but even with glibc u_char is
defined in <sys/types.h>, it happens to work with glibc <sys/types.h>
gets included by another header.

Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agoconfigure.ac: libtalloc is now mandatory
Thomas Petazzoni [Thu, 26 Dec 2024 20:42:12 +0000 (21:42 +0100)]
configure.ac: libtalloc is now mandatory

Since commit c6bf4d9a59809fbb0c22ef9eb167c099ab8089fb ("Implement
CLDAP Ping to find the closest site"), libtalloc is mandatory to
cifs-utils. This needs to be reflected in the configure.ac script to
get a failure at configure time and not build time.

Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agocifscreds: allow user to set the key's timeout
Thiago Becker [Fri, 24 Jan 2025 17:52:57 +0000 (14:52 -0300)]
cifscreds: allow user to set the key's timeout

Allow the user to set the key's timeout when adding a new credential.

Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Thiago Becker <tbecker@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agocifscreds: use continue instead of break when matching commands
Thiago Becker [Tue, 14 Jan 2025 20:34:49 +0000 (17:34 -0300)]
cifscreds: use continue instead of break when matching commands

While matching the commands in cifscreds, continue attempting to
match to detect ambiguous commands.

Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Thiago Becker <tbecker@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agoDo not pass passwords with sec=none and sec=krb5
Meetakshi Setiya [Thu, 2 Jan 2025 10:42:22 +0000 (10:42 +0000)]
Do not pass passwords with sec=none and sec=krb5

Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agodocs: add esize description
Henrique Carvalho [Wed, 18 Dec 2024 22:10:13 +0000 (19:10 -0300)]
docs: add esize description

Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agodocs: add max_cached_dirs description
Henrique Carvalho [Wed, 18 Dec 2024 21:03:41 +0000 (18:03 -0300)]
docs: add max_cached_dirs description

Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agodocs: update actimeo description
Henrique Carvalho [Sat, 5 Oct 2024 14:50:53 +0000 (11:50 -0300)]
docs: update actimeo description

Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agoFix compiler warnings in mount.cifs
Meetakshi Setiya [Fri, 6 Dec 2024 06:58:50 +0000 (01:58 -0500)]
Fix compiler warnings in mount.cifs

Signed-off-by: Meetakshi Setiya <msetiya@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agoCIFS.upcall to accomodate new namespace mount opt
Ritvik Budhiraja [Tue, 19 Nov 2024 06:07:58 +0000 (06:07 +0000)]
CIFS.upcall to accomodate new namespace mount opt

NOTE: This patch is dependent on one of the previously sent patches:
[PATCH] CIFS: New mount option for cifs.upcall namespace resolution
which introduces a new mount option called upcall_target, to
customise the upcall behaviour.

Building upon the above patch, the following patch adds functionality
to handle upcall_target as a mount option in cifs.upcall. It can have 2 values -
mount, app.
Having this new mount option allows the mount command to specify where the
upcall should happen: 'mount' for resolving the upcall to the host
namespace, and 'app' for resolving the upcall to the ns of the calling
thread. This will enable both the scenarios where the Kerberos credentials
can be found on the application namespace or the host namespace to which
just the mount operation is "delegated".
This aids use cases like Kubernetes where the mount
happens on behalf of the application in another container altogether.

Signed-off-by: Ritvik Budhiraja <rbudhiraja@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agocifs-utils: Skip TGT check if valid service ticket is already available
Bharath SM [Tue, 26 Nov 2024 17:27:44 +0000 (22:57 +0530)]
cifs-utils: Skip TGT check if valid service ticket is already available

When handling upcalls from the kernel for SMB session setup requests using
Kerberos authentication, if the credential cache already contains a valid
service ticket, it can be used directly without checking for the TGT again.

Signed-off-by: Bharath SM <bharathsm@microsoft.com>
Reviewed-by: Shyam Prasad N <sprasad@microsoft.com>
Acked-by: Alexander Bokovoy <ab@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agouse enums to check password or password2 in set_password, get_password_from_file...
Meetakshi Setiya [Mon, 11 Nov 2024 05:10:53 +0000 (00:10 -0500)]
use enums to check password or password2 in set_password, get_password_from_file and minor documentation additions

Signed-off-by: Meetakshi Setiya <msetiya@microsoft.com>
Reviewed-by: Bharath SM <bharathsm@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
20 months agocifs-utils: support and document password2 mount option
Meetakshi Setiya [Tue, 22 Oct 2024 16:59:30 +0000 (12:59 -0400)]
cifs-utils: support and document password2 mount option

Currently, there are some issues when using the password2 mount option:

1.  When password2 is provided in the credential file, mount.cifs overwrites
password1 with the alternate password2.
2. There is no support to retrieve password2 from the environment.
3. password2 is not masked when mounting with verbose option.

This commit fixes the aforementioned issues and adds documentation for the
password2 mount option.

Signed-off-by: Meetakshi Setiya <msetiya@microsoft.com>
Reviewed-by: Bharath SM <bharathsm@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
23 months agosmbinfo: add bash completion support for filestreaminfo, keys, gettconinfo
Pavel Filipenský [Mon, 7 Oct 2024 19:48:31 +0000 (21:48 +0200)]
smbinfo: add bash completion support for filestreaminfo, keys, gettconinfo

Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
23 months agocifs-utils: bump version to 7.1 cifs-utils-7.1
Pavel Shilovsky [Mon, 7 Oct 2024 00:07:14 +0000 (17:07 -0700)]
cifs-utils: bump version to 7.1

Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org>
2 years agocifs: update documentation for sloppy mount option
Bharath SM [Fri, 4 Oct 2024 05:37:18 +0000 (11:07 +0530)]
cifs: update documentation for sloppy mount option

Signed-off-by: Steve French <stfrench@microsoft.com>
2 years agodocs: add closetimeo description
Henrique Carvalho [Tue, 17 Sep 2024 20:26:03 +0000 (17:26 -0300)]
docs: add closetimeo description

Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
2 years agodocs: add compress description
Henrique Carvalho [Tue, 17 Sep 2024 21:30:59 +0000 (18:30 -0300)]
docs: add compress description

Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
2 years agocheckopts: update it to work with latest kernel version
Henrique Carvalho [Mon, 16 Sep 2024 19:02:13 +0000 (16:02 -0300)]
checkopts: update it to work with latest kernel version

The script checkopts checks for inconsistencies between documented
mount options and implemented kernel options. It was broken for
current mainline kernel version (6.11) and has now been fixed.

Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
2 years agocifs-utils: add documentation for multichannel and max_channels
Bharath SM [Tue, 3 Sep 2024 09:24:48 +0000 (14:54 +0530)]
cifs-utils: add documentation for multichannel and max_channels

update man page with documentation for multichannel and max_channels
mount parameters

Signed-off-by: Bharath SM <bharathsm@microsoft.com>
2 years agocifs-utils: smbinfo: add gettconinfo command
Anthony Nandaa [Fri, 5 Jul 2024 20:43:52 +0000 (23:43 +0300)]
cifs-utils: smbinfo: add gettconinfo command

As a follow up on the patch on Linux: de4eceab578e
("smb3: allow dumping session and tcon id to improve stats analysis
and debugging") [1]

Add `gettconinfo` command to dump both the TCON Id and Session Id of
a given SMB mount; to help with correlation in cases when multiple
mounts are to the same share.

Example run:
```
./smbinfo gettconinfo /mnt/smb_share
TCON Id: 0x1
Session Id: 0xa40000000001
```

[1] https://github.com/torvalds/linux/commit/de4eceab578ead12a71e5b5588a57e142bbe8ceb

Cc: Pavel Shilovsky <pshilovsky@samba.org>
Cc: Steve French <stfrench@microsoft.com>
Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
2 years agoImplement CLDAP Ping to find the closest site
David Voit [Wed, 3 Apr 2024 05:24:48 +0000 (07:24 +0200)]
Implement CLDAP Ping to find the closest site

For domain based DFS we always need to contact the domain controllers.
On setups, which are using bigger AD installations you could get random dc on the other side of the world,
if you don't have site support. This can lead to network timeouts and other problems.

CLDAP-Ping uses ASN.1 + UDP (CLDAP) and custom-DCE encoding including DName compressions without
field separation. Finally after finding the sitename we now need to do a DNS SRV lookups to find
the correct IPs to our closest site and fill up the remaining IPs from the global list.

Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Reviewed-by: Jacob Shivers <jshivers@redhat.com>
Signed-off-by: David Voit <david.voit@gmail.com>
2 years agomount.cifs.rst: update section about xattr/acl support
Paulo Alcantara [Mon, 11 Mar 2024 01:24:25 +0000 (22:24 -0300)]
mount.cifs.rst: update section about xattr/acl support

Update section about required xattr/acl support for UID/GID mapping.

Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
2 years agomount.cifs.rst: add missing reference for sssd
Paulo Alcantara [Mon, 11 Mar 2024 01:24:24 +0000 (22:24 -0300)]
mount.cifs.rst: add missing reference for sssd

Reference sssd in mount.cifs(8) as it can be used instead of winbind
via cifs.idmap utility.  It's also enabled by default in most systems.

Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
2 years agogetcifsacl, setcifsacl: add missing <endian.h> include for le32toh
Sam James [Tue, 16 Aug 2022 00:43:35 +0000 (01:43 +0100)]
getcifsacl, setcifsacl: add missing <endian.h> include for le32toh

Needed to fix build on musl libc. It only works by chance on glibc
because of transitive includes (which could break at any time).

Example failure:
```
getcifsacl.c: In function 'print_ace':
getcifsacl.c:284:16: warning: implicit declaration of function 'le16toh' [-Wimplicit-function-declaration]
  284 |         size = le16toh(pace->size);
      |                ^~~~~~~
```

Bug: https://bugs.gentoo.org/842195
Signed-off-by: Sam James <sam@gentoo.org>
2 years agogetcifsacl, setcifsacl: add missing <linux/limits.h> include for XATTR_SIZE_MAX
Sam James [Tue, 16 Aug 2022 00:43:34 +0000 (01:43 +0100)]
getcifsacl, setcifsacl: add missing <linux/limits.h> include for XATTR_SIZE_MAX

Needed to build on musl. It only works on glibc because of transitive includes
(which could break in future).

Example failure:
```
getcifsacl.c: In function 'getcifsacl':
getcifsacl.c:429:24: error: 'XATTR_SIZE_MAX' undeclared (first use in this function)
  429 |         if (bufsize >= XATTR_SIZE_MAX) {
      |                        ^~~~~~~~~~~~~~
```

Bug: https://bugs.gentoo.org/842195
Signed-off-by: Sam James <sam@gentoo.org>
2 years agocifs-utils: Make automake treat /sbin as exec, not data
Daniel Parks [Fri, 3 Jun 2022 20:34:59 +0000 (15:34 -0500)]
cifs-utils: Make automake treat /sbin as exec, not data

Otherwise, $(DESTDIR)/sbin doesn't get created until install-data on a
-j1 build and install-exec-hook can fail because it might not exist.

Steps to reproduce this bug:
$ autoreconf -i
$ ./configure
$ mkdir image
$ make DESTDIR=image install -j1

Signed-off-by: Daniel Parks <danielrparks@ti.com>
2 years agopam_cifscreds: fix warning on NULL arg passed to %s in pam_syslog()
Paulo Alcantara [Fri, 8 Mar 2024 16:25:22 +0000 (13:25 -0300)]
pam_cifscreds: fix warning on NULL arg passed to %s in pam_syslog()

Fix the following compiler warning with -Wformat-overflow in
cifscreds_pam_update():

  pam_cifscreds.c: In function ‘cifscreds_pam_update’:
  pam_cifscreds.c:340:83: warning: ‘%s’ directive argument is null
  [-Wformat-overflow=]
    340 | pam_syslog(ph, LOG_ERR, "error: Update credential key for %s: %s",
        |                                                           ^~

Fixes: cbbcd6e71c0a ("cifscreds: create PAM module to insert credentials at login")
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
2 years agocifs.upcall: fix UAF in get_cachename_from_process_env()
Paulo Alcantara [Fri, 8 Mar 2024 15:06:15 +0000 (12:06 -0300)]
cifs.upcall: fix UAF in get_cachename_from_process_env()

Whether lseek(2) fails or @bufsize * 2 > ENV_BUF_MAX, then @buf would
end up being freed twice.  For instance:

  cifs-utils-7.0/cifs.upcall.c:501: freed_arg: "free" frees "buf".
  cifs-utils-7.0/cifs.upcall.c:524: double_free: Calling "free" frees
  pointer "buf" which has already been freed.
    522|           }
    523|   out_close:
    524|->         free(buf);
    525|           close(fd);
    526|           return cachename;

Fix this by setting @buf to NULL after freeing it to prevent UAF.

Fixes: ed97e4ecab4e ("cifs.upcall: allow scraping of KRB5CCNAME out of initiating task's /proc/<pid>/environ file")
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
2 years agocifs-utils: add documentation for acregmax and acdirmax
Bharath SM [Fri, 1 Mar 2024 19:31:57 +0000 (01:01 +0530)]
cifs-utils: add documentation for acregmax and acdirmax

update man page with documentation for acregmax and acdirmax
mount parameters.

Signed-off-by: Bharath SM <bharathsm@microsoft.com>
2 years agosetcifsacl: Fix uninitialized value.
Pavel Filipenský [Fri, 3 Feb 2023 14:54:01 +0000 (15:54 +0100)]
setcifsacl: Fix uninitialized value.

This is to fix Red Hat internal static analyzer report.

Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
2 years agoUse explicit "#!/usr/bin/python3"
Pavel Filipenský [Fri, 20 Jan 2023 19:53:44 +0000 (20:53 +0100)]
Use explicit "#!/usr/bin/python3"

Fix Red Hat internal report for "ambiguous python shebang".

Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
4 years agocifs-utils: bump version to 7.0 cifs-utils-7.0
Pavel Shilovsky [Thu, 11 Aug 2022 20:40:15 +0000 (13:40 -0700)]
cifs-utils: bump version to 7.0

Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org>
4 years agocifs-utils: don't return uninitialized value in cifs_gss_get_req
atheik [Sat, 30 Apr 2022 21:48:26 +0000 (00:48 +0300)]
cifs-utils: don't return uninitialized value in cifs_gss_get_req

If the first malloc fails, maj_stat is uninitialized and used as
the return value through the GSS_ERROR() macro. Use GSS_S_FAILURE to
indicate a miscellaneous error.

Signed-off-by: atheik <atteh.mailbox@gmail.com>
4 years agocifs-utils: make GSSAPI usage compatible with Heimdal
atheik [Sat, 30 Apr 2022 21:47:54 +0000 (00:47 +0300)]
cifs-utils: make GSSAPI usage compatible with Heimdal

The gssapi symbols are in gssapi_krb5 and gssapi in MIT and Heimdal
Kerberos, respectively. Including gssapi_generic.h is not necessary.

Signed-off-by: atheik <atteh.mailbox@gmail.com>
4 years agocifs-utils: work around missing krb5_free_string in Heimdal
atheik [Fri, 4 Mar 2022 22:24:49 +0000 (00:24 +0200)]
cifs-utils: work around missing krb5_free_string in Heimdal

The krb5_free_string function is not present in Heimdal and instead
krb5_xfree should be used for freeing the string allocation done by
krb5_cc_get_full_name. Heimdal documentation does specify that
krb5_xfree should be used here and krb5_unparse_name is freed with
just free.

Signed-off-by: atheik <atteh.mailbox@gmail.com>
4 years agofix warnings for -Waddress-of-packed-member
Alexander Bokovoy [Wed, 16 Feb 2022 12:18:16 +0000 (14:18 +0200)]
fix warnings for -Waddress-of-packed-member

When structure members are packed, GCC will issue a warning that taking
an address of the packed structure member might cause an unaligned
access.

In all cases where this happen we simply can use a local variable
instead and then assign the result in a proper way.

Signed-off-by: Alexander Bokovoy <ab@samba.org>
4 years agosetcifsacl: fix memory allocation for struct cifs_ace
Alexander Bokovoy [Wed, 16 Feb 2022 12:04:47 +0000 (14:04 +0200)]
setcifsacl: fix memory allocation for struct cifs_ace

We don't have 'struct cifs_aces' so the correct struct name is 'struct
cifs_ace'. The code only worked because 'struct unknown *' is compatible
with 'struct cifs_ace *'.

Signed-off-by: Alexander Bokovoy <ab@samba.org>
4 years agosetcifsacl: fix comparison of actions reported by covscan
Alexander Bokovoy [Wed, 16 Feb 2022 11:58:24 +0000 (13:58 +0200)]
setcifsacl: fix comparison of actions reported by covscan

Signed-off-by: Alexander Bokovoy <ab@samba.org>
4 years agocifs.upcall: remove unused variable and fix syslog message
Alexander Bokovoy [Wed, 16 Feb 2022 11:56:32 +0000 (13:56 +0200)]
cifs.upcall: remove unused variable and fix syslog message

The code already checks arg->have and has no use for local 'have'
variable other than syslog() print. That variable is not initialized and
the intent is really to use arg->have instead.

Signed-off-by: Alexander Bokovoy <ab@samba.org>
4 years agocifs.upcall: Switch to RFC principal type naming
Michael Weiser [Tue, 26 Oct 2021 09:11:48 +0000 (11:11 +0200)]
cifs.upcall: Switch to RFC principal type naming

Switch from old-style MIT krb5 gss_nt_service_name principal type
constant name to the now preferred GSS_C_NT_HOSTBASED_SERVICE.

Signed-off-by: Michael Weiser <michael.weiser@atos.net>
4 years agoman-pages: Update cifs.upcall to mention GSS_USE_PROXY
Jacob Shivers [Tue, 26 Oct 2021 14:57:41 +0000 (10:57 -0400)]
man-pages: Update cifs.upcall to mention GSS_USE_PROXY

Add ENVIRONMENT VARIABLES section with the usage of gssproxy as
a credential retrieval method.

Signed-off-by: Jacob Shivers <jshivers@redhat.com>
4 years agocifs.upcall: fix compiler warning
Ronnie Sahlberg [Thu, 21 Oct 2021 23:41:24 +0000 (09:41 +1000)]
cifs.upcall: fix compiler warning

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
4 years agocifs.upcall: add gssproxy support
Michael Weiser [Tue, 5 Jan 2021 16:08:30 +0000 (17:08 +0100)]
cifs.upcall: add gssproxy support

Add support for gssproxy usage through GSS-API. If no useable ticket cache or
keytab can be found, fall on through into credential handling anyway but then
divert into GSS routines. If no gssproxy is available this will still error out
silently because no ticket cache is available. With gssproxy enabled,
credentials can be retrieved from there and allow unattended access to shares
e.g. from batch jobs.

Signed-off-by: Michael Weiser <michael.weiser@atos.net>
4 years agocifs-utils: bump version to 6.15 cifs-utils-6.15
Pavel Shilovsky [Fri, 29 Apr 2022 21:45:41 +0000 (14:45 -0700)]
cifs-utils: bump version to 6.15

Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org>
4 years agomount.cifs: fix verbose messages on option parsing
Jeffrey Bencteux [Sat, 19 Mar 2022 17:41:15 +0000 (13:41 -0400)]
mount.cifs: fix verbose messages on option parsing

When verbose logging is enabled, invalid credentials file lines may be
dumped to stderr. This may lead to information disclosure in particular
conditions when the credentials file given is sensitive and contains '='
signs.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=15026

Signed-off-by: Jeffrey Bencteux <jbe@improsec.com>
Reviewed-by: David Disseldorp <ddiss@suse.de>
4 years agoCVE-2022-27239: mount.cifs: fix length check for ip option parsing
Jeffrey Bencteux [Thu, 17 Mar 2022 16:58:52 +0000 (12:58 -0400)]
CVE-2022-27239: mount.cifs: fix length check for ip option parsing

Previous check was true whatever the length of the input string was,
leading to a buffer overflow in the subsequent strcpy call.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=15025

Signed-off-by: Jeffrey Bencteux <jbe@improsec.com>
Reviewed-by: David Disseldorp <ddiss@suse.de>
5 years agocifs-utils: bump version to 6.14 cifs-utils-6.14
Pavel Shilovsky [Thu, 23 Sep 2021 23:48:45 +0000 (16:48 -0700)]
cifs-utils: bump version to 6.14

Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org>
5 years agosetcifsacl: fix formatting
Pavel Shilovsky [Thu, 23 Sep 2021 23:30:57 +0000 (16:30 -0700)]
setcifsacl: fix formatting

Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org>
5 years agosmbinfo: add support for new key dump ioctl
Aurelien Aptel [Fri, 21 May 2021 15:29:40 +0000 (17:29 +0200)]
smbinfo: add support for new key dump ioctl

* try new one first, fall back on old one otherwise => retrocompatible
* use better cipher descriptions

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
5 years agomount.cifs: fix crash when mount point does not exist
Paulo Alcantara [Thu, 6 May 2021 19:25:13 +0000 (16:25 -0300)]
mount.cifs: fix crash when mount point does not exist

@mountpointp is initially set to a statically allocated string in
main(), and if we fail to update it in acquire_mountpoint(), make sure
to set it to NULL and avoid freeing it at mount_exit.

This fixes the following crash

$ mount.cifs //srv/share /mnt/foo/bar -o ...
Couldn't chdir to /mnt/foo/bar: No such file or directory
munmap_chunk(): invalid pointer
Aborted

Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
5 years agocifs.upcall: fix regression in kerberos mount
Aurelien Aptel [Wed, 21 Apr 2021 14:22:15 +0000 (16:22 +0200)]
cifs.upcall: fix regression in kerberos mount

The fix for CVE-2021-20208 in commit e461afd ("cifs.upcall: try to use
container ipc/uts/net/pid/mnt/user namespaces") introduced a
regression for kerberos mounts when cifs-utils is built with
libcap-ng. It makes mount fail with ENOKEY "Required key not
available".

Current state:

mount.cifs
 '---> mount() ---> kernel
                   negprot, session setup (need security blob for krb)
                   request_key("cifs.spnego",  payload="pid=%d;username=...")
                               upcall
  /sbin/request-key <--------------'
   reads /etc/request-keys.conf
   dispatch cifs.spnego request
   calls /usr/sbin/cifs.upcall <key id>
   - drop privileges (capabilities)
   - fetch keyid
   - parse payload
   - switch to mount.cifs namespaces
   - call krb5_xxx() funcs
   - generate security blob
   - set key value to security blob
      '-----------------------------------> kernel
                                         put blob in session setup packet
          continue auth
          open tcon
          get share root
          setup superblock
mount.cifs mount() returns    <-----------'

By the time cifs.upcall tries to switch to namespaces, enough
capabilities have dropped in trim_capabilities() that it makes setns()
fail with EPERM.

setns() requires CAP_SYS_ADMIN.

With libcap trim_capabilities() is a no-op.

This fix:

- moves the namespace switch earlier so that operations like
  setgroups(), setgid(), scanning of pid environment, ... happens in the
  contained namespaces.
- moves trim_capabilities() after the namespace switch
- moves the string processing to decode the key request payload in a
  child process with minimum capabilities. the decoded data is shared
  with the parent process via shared memory obtained with mmap().

Fixes: e461afd ("cifs.upcall: try to use container ipc/uts/net/pid/mnt/user namespaces")
Signed-off-by: Aurelien Aptel <aaptel@suse.com>
5 years agosmbinfo: Add command for displaying alternate data streams
Juan Pablo González [Thu, 8 Apr 2021 10:02:20 +0000 (12:02 +0200)]
smbinfo: Add command for displaying alternate data streams

This patch adds a new command to smbinfo which retrieves and displays
the list of alternate data streams for a file.

Signed-off-by: Juan Pablo González <disablez@gmail.com>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
5 years agoReorder ACEs in preferred order during setcifsacl
Rohith Surabattula [Thu, 4 Feb 2021 18:08:31 +0000 (18:08 +0000)]
Reorder ACEs in preferred order during setcifsacl

Have added new option "-A" in setcifsacl utility to reorder ACEs in
preferred order.

5 years agocifs-utils: bump version to 6.13 cifs-utils-6.13
Pavel Shilovsky [Mon, 12 Apr 2021 23:34:48 +0000 (16:34 -0700)]
cifs-utils: bump version to 6.13

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
5 years agocifs.upcall: try to use container ipc/uts/net/pid/mnt/user namespaces
Alastair Houghton [Tue, 29 Dec 2020 14:02:39 +0000 (14:02 +0000)]
cifs.upcall: try to use container ipc/uts/net/pid/mnt/user namespaces

In certain scenarios (e.g. kerberos multimount), when a process does
syscalls, the kernel sometimes has to query information or trigger
some actions in userspace. To do so it calls the cifs.upcall binary
with information on the process that triggered the syscall in the
first place.

ls(pid=10) ====> open("foo") ====> kernel

                                   that user doesn't have an SMB
                                   session, lets create one using his
                                   kerberos credential cache

                                   call cifs.upcall and ask for krb info
                                   for whoever owns pid=10
                                                         |
                  cifs.upcall --pid 10 <=================+

               ...gather info...
                  return binary blob used
                  when establishing SMB session
                        ===================> kernel
                                              open SMB session, handle
                                              open() syscall
ls <===================================   return open() result to ls

On a system using containers, the kernel is still calling the host
cifs.upcall and using the host configuration (for network, pid, etc).

This patch changes the behaviour of cifs.upcall so that it uses the
calling process namespaces (ls in the example) when doing its
job.

Note that the kernel still calls the binary in the host, but the
binary will place itself the contexts of the calling process
namespaces.

This code makes use of (but shouldn't require) the following kernel
config options and syscall flags:

approx. year   |
introduced     |  config/flags
---------------+----------------
2008           | CONFIG_NAMESPACES=y
2007           | CONFIG_UTS_NS=y
2020           | CONFIG_TIME_NS=y
2006           | CONFIG_IPC_NS=y
2007           | CONFIG_USER_NS
2008           | CONFIG_PID_NS=y
2007           | CONFIG_NET_NS=y
2007           | CONFIG_CGROUPS
2016           | CLONE_NEWCGROUP setns() flag

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Signed-off-by: Alastair Houghton <alastair@alastairs-place.net>
5 years agocifs-utils: bump version to 6.12 cifs-utils-6.12
Pavel Shilovsky [Thu, 31 Dec 2020 18:26:10 +0000 (10:26 -0800)]
cifs-utils: bump version to 6.12

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
5 years agosmbinfo: fix fsctl-getobjid output
Pavel Shilovsky [Tue, 29 Dec 2020 20:00:33 +0000 (12:00 -0800)]
smbinfo: fix fsctl-getobjid output

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
5 years agosmbinfo: fix list-snapshots output and installation
Pavel Shilovsky [Tue, 29 Dec 2020 19:43:26 +0000 (11:43 -0800)]
smbinfo: fix list-snapshots output and installation

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
5 years agocifs.upcall: drop bounding capabilities only if CAP_SETPCAP is given
Alexander Koch [Wed, 16 Dec 2020 21:44:56 +0000 (22:44 +0100)]
cifs.upcall: drop bounding capabilities only if CAP_SETPCAP is given

Make drop_call_capabilities() in cifs.upcall update the bounding capabilities
only if CAP_SETCAP is present.

This is an addendum to the patch recently provided in [1]. Without this
additional change, cifs.upcall can still fail while trying to mount a CIFS
network share with krb5:

  kernel: CIFS: Attempting to mount //server.domain.lan/myshare
  cifs.upcall[39484]: key description: cifs.spnego;0;0;39010000;ver=0x2;host=server.domain.lan>
  cifs.upcall[39484]: ver=2
  cifs.upcall[39484]: host=server.domain.lan
  cifs.upcall[39484]: ip=172.22.3.14
  cifs.upcall[39484]: sec=1
  cifs.upcall[39484]: uid=1000
  cifs.upcall[39484]: creduid=1000
  cifs.upcall[39484]: user=username
  cifs.upcall[39484]: pid=39481
  cifs.upcall[39484]: get_cachename_from_process_env: pathname=/proc/39481/environ
  cifs.upcall[39484]: get_cachename_from_process_env: cachename = FILE:/tmp/.krb5cc_1000
  cifs.upcall[39484]: drop_all_capabilities: Unable to apply capability set: Success
  cifs.upcall[39484]: Exit status 1

[1] https://marc.info/?l=linux-cifs&m=160595758021261

Signed-off-by: Alexander Koch <mail@alexanderkoch.net>
Signed-off-by: Jonas Witschel <diabonas@archlinux.org>
5 years agomount.cifs: use SUDO_UID env variable for cruid
Shyam Prasad N [Wed, 16 Sep 2020 07:18:44 +0000 (00:18 -0700)]
mount.cifs: use SUDO_UID env variable for cruid

In the current mount.cifs logic, when sudo is used for mount,
uid=0, so the mount command searches for cruid=0 unless explicitly
specified by the user. The user may already have cred cache populated
but mount.cifs would end up searching cred cache for uid=0.

mount.cifs can avoid this confusion by reading the cruid from SUDO_UID
environment variable. If it is set to non-zero, we can make cruid=$SUDO_UID.

However, to maintain backward compatibility, keeping this as a fallback option.
If mount fails with ENOKEY, then retry with this option.
To enable this fallback, I had to make a few minor changes in the flow.

Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
5 years agomount.cifs: fix max buffer size when parsing snapshot option
Pavel Shilovsky [Wed, 9 Dec 2020 19:29:40 +0000 (11:29 -0800)]
mount.cifs: fix max buffer size when parsing snapshot option

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
5 years agoAdd missing position handling to mount parameters gid/backup_gid/snapshot
Simon Arlott [Thu, 26 Nov 2020 00:28:08 +0000 (00:28 +0000)]
Add missing position handling to mount parameters gid/backup_gid/snapshot

The code tries to optimise for the last parameter not needing to update
the position which means that every time a new one is added to the end
by copying and pasting, the string position is not updated.

That makes it impossible to use backup_uid=/backup_gid=/snapshot= after
gid= or snapshot= after backup_gid= because part of the string is
overwritten and contains invalid keys like "gbackup_uid".

Prepare for the next parameter to be added on the end by updating the
position for snapshot= even though it will be unused.

5 years agocifs.upcall: update the cap bounding set only when CAP_SETPCAP is given
Jonas Witschel [Sat, 21 Nov 2020 11:11:45 +0000 (12:11 +0100)]
cifs.upcall: update the cap bounding set only when CAP_SETPCAP is given

libcap-ng 0.8.1 tightened the error checking on capng_apply, returning an error
of -4 when trying to update the capability bounding set without having the
CAP_SETPCAP capability to be able to do so. Previous versions of libcap-ng
silently skipped updating the bounding set and only updated the normal
CAPNG_SELECT_CAPS capabilities instead.

Check beforehand whether we have CAP_SETPCAP, in which case we can use
CAPNG_SELECT_BOTH to update both the normal capabilities and the bounding set.
Otherwise, we can at least update the normal capabilities, but refrain from
trying to update the bounding set to avoid getting an error.

Signed-off-by: Jonas Witschel <diabonas@archlinux.org>
5 years agomount.cifs: update the cap bounding set only when CAP_SETPCAP is given
Jonas Witschel [Sat, 21 Nov 2020 11:11:44 +0000 (12:11 +0100)]
mount.cifs: update the cap bounding set only when CAP_SETPCAP is given

libcap-ng 0.8.1 tightened the error checking on capng_apply, returning an error
of -4 when trying to update the capability bounding set without having the
CAP_SETPCAP capability to be able to do so. Previous versions of libcap-ng
silently skipped updating the bounding set and only updated the normal
CAPNG_SELECT_CAPS capabilities instead.

Check beforehand whether we have CAP_SETPCAP, in which case we can use
CAPNG_SELECT_BOTH to update both the normal capabilities and the bounding set.
Otherwise, we can at least update the normal capabilities, but refrain from
trying to update the bounding set to avoid getting an error.

Signed-off-by: Jonas Witschel <diabonas@archlinux.org>
5 years agoExtend cifs acl utilities to handle SACLs
Boris Protopopov [Thu, 19 Nov 2020 21:40:42 +0000 (21:40 +0000)]
Extend cifs acl utilities to handle SACLs

Extend getcifsacl/setcifsacl utilities to handle System ACLs (SACLs)
in addition to Discretionary ACLs (DACLs). The SACL extensions depend
on CIFS client support for system.cifs_ntsd_full extended attribute.

Signed-off-by: Boris Protopopov <pboris@amazon.com>
5 years agogetcifsacl: return error if input path doesn't exist
Pavel Shilovsky [Mon, 9 Nov 2020 23:27:51 +0000 (15:27 -0800)]
getcifsacl: return error if input path doesn't exist

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
5 years agoFix mount error when mount point has an extra trailing slash.
Rohith Surabattula [Fri, 6 Nov 2020 10:19:59 +0000 (10:19 +0000)]
Fix mount error when mount point has an extra trailing slash.

5 years agomount.cifs: ignore comment mount option
Martin Schwenke [Fri, 25 Sep 2020 01:16:39 +0000 (11:16 +1000)]
mount.cifs: ignore comment mount option

mount.cifs currently complains about the "comment" option:

  CIFS: Unknown mount option "comment=foo"

mount(8) on Linux says:

  The command mount does not pass the mount options unbindable,
  runbindable, private, rprivate, slave, rslave, shared, rshared,
  auto, noauto, comment, x-*, loop, offset and sizelimit to the
  mount.<suffix> helpers.

So if mount.cifs decides to re-read /etc/fstab it should ignore the
comment option.

A lot of online posts say to use comment=x-gvfs-show as an option to
have a Linux file manager display a mountpoint for a user mountable
filesystem.  While the "comment=" part is superfluous when combined
with an x-* option, the problem is still difficult to debug.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
6 years agosetcifsacl: fix quoting of backslash in man page
Bjoern Jacke [Mon, 1 Jun 2020 17:23:51 +0000 (19:23 +0200)]
setcifsacl: fix quoting of backslash in man page

Signed-off-by: Bjoern Jacke <bjacke@samba.org>
6 years agoSeparate binary names using comma in mount.cifs.rst
Sergio Durigan Junior [Tue, 9 Jun 2020 18:00:44 +0000 (14:00 -0400)]
Separate binary names using comma in mount.cifs.rst

According to lexgrog(1), when a manpage refers to multiple programs
their names should be separated using a comma and a whitespace.  This
helps silence a lintian warning when building cifs-utils on Debian.

Signed-off-by: Sergio Durigan Junior <sergio.durigan@canonical.com>
6 years agocifs-utils: fix probabilistic compiling error
lizhe [Tue, 26 May 2020 03:54:11 +0000 (11:54 +0800)]
cifs-utils: fix probabilistic compiling error

When we compile cifs-utils, we may probabilistic
encounter install error like:
cd ***/sbin && ln -sf mount.cifs mount.smb3
***/sbin: No such file or directory

The reason of this problem is that if we compile
cifs-utils using multithreading, target
'install-sbinPROGRAMS' may be built after
target 'install-exec-hook' of the main Makefile.
Target 'install-sbinPROGRAMS' will copy the
executable file 'mount.cifs' to the $(ROOTSBINDIR),
which target 'install-exec-hook' will do the
'ln' command on.

This patch add the dependency of target
'install-exec-hook' to ensure the correct order
of the compiling.

Signed-off-by: lizhe <lizhe67@huawei.com>
6 years agocifs-utils: Don't create symlinks for mans if mans are disabled
Mikhail Novosyolov [Fri, 24 Jan 2020 22:12:31 +0000 (01:12 +0300)]
cifs-utils: Don't create symlinks for mans if mans are disabled

6 years agocifs-utils: Respect DESTDIR when installing smb3 stuff
Mikhail Novosyolov [Fri, 24 Jan 2020 22:11:12 +0000 (01:11 +0300)]
cifs-utils: Respect DESTDIR when installing smb3 stuff

When make install is run during package building, DESTDIR parameter is passed, e.g.:
$ rpm --eval %makeinstall_std
make DESTDIR=/root/rpmbuild/BUILDROOT/%{name}-%{version}-%{release}-rosa2016.1.x86_64-buildroot install

Without DESTDIR build scripts tried to create symlinks outside of the build root:
make[3]: Entering directory '/tmp/abf/rpmbuild/BUILD/cifs-utils-6.10'
(cd /sbin && ln -sf mount.cifs mount.smb3)
ln: failed to create symbolic link 'mount.smb3': Permission denied

The same fix was introduced in Arch Linux package when updating from 6.9 to 6.10:
https://git.archlinux.org/svntogit/packages.git/commit/trunk/PKGBUILD?h=packages/cifs-utils&id=c75b246a762ea9b90db404dfebc6d35d5b16972f

6 years agomount.cifs.rst: add nolease mount option
Pavel Shilovsky [Tue, 25 Feb 2020 19:15:06 +0000 (11:15 -0800)]
mount.cifs.rst: add nolease mount option

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
6 years agoAdd support for setting owner and group in ntsd
Boris Protopopov [Mon, 6 Jan 2020 16:31:19 +0000 (16:31 +0000)]
Add support for setting owner and group in ntsd

Extend setcifsacl utility to allow setting owner and group SIDs
in the security descriptor in addition to setting ACLs. This is
a user-friendly intefrace for setting owner and group SIDs that
takes advantage of the recent extensions in the CIFS kernel
client, and it complements setting raw values via setfattr.

Signed-off-by: Boris Protopopov <boris.v.protopopov@gmail.com>
6 years agoConvert owner and group SID offsets to LE format
Boris Protopopov [Mon, 6 Jan 2020 16:31:18 +0000 (16:31 +0000)]
Convert owner and group SID offsets to LE format

Convert owner and group SID offsets to LE format
when writing to ntsd

Signed-off-by: Boris Protopopov <boris.v.protopopov@gmail.com>
6 years agosmbinfo: remove invalid arguments to ioctl method
Ronnie Sahlberg [Fri, 20 Dec 2019 00:58:48 +0000 (10:58 +1000)]
smbinfo: remove invalid arguments to ioctl method

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
6 years agosmbinfo: rewrite in python
Aurelien Aptel [Mon, 14 Oct 2019 17:07:38 +0000 (19:07 +0200)]
smbinfo: rewrite in python

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
6 years agocifs-utils: bump version to 6.11 cifs-utils-6.11
Pavel Shilovsky [Thu, 3 Sep 2020 16:58:46 +0000 (09:58 -0700)]
cifs-utils: bump version to 6.11

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
6 years agoCVE-2020-14342: mount.cifs: fix shell command injection
Aurelien Aptel [Mon, 27 Jul 2020 08:34:44 +0000 (10:34 +0200)]
CVE-2020-14342: mount.cifs: fix shell command injection

A bug has been reported recently for the mount.cifs utility which is
part of the cifs-utils package. The tool has a shell injection issue
where one can embed shell commands via the username mount option. Those
commands will be run via popen() in the context of the user calling
mount.

The bug requires cifs-utils to be built with --with-systemd (enabled
by default if supported).

A quick test to check if the mount.cifs binary is vulnerable is to look
for popen() calls like so:

    $ nm mount.cifs | grep popen
    U popen@@GLIBC_2.2.5

If the user is allowed to run mount.cifs via sudo, he can obtain a root
shell.

    sudo mount.cifs -o username='`sh`' //1 /mnt

If mount.cifs has the setuid bit, the command will still be run as the
calling user (no privilege escalation).

The bug was introduced in June 2012 with commit 4e264031d0da7d3f2
("mount.cifs: Use systemd's mechanism for getting password, if
present.").

Affected versions:
  cifs-utils-5.6
  cifs-utils-5.7
  cifs-utils-5.8
  cifs-utils-5.9
  cifs-utils-6.0
  cifs-utils-6.1
  cifs-utils-6.2
  cifs-utils-6.3
  cifs-utils-6.4
  cifs-utils-6.5
  cifs-utils-6.6
  cifs-utils-6.7
  cifs-utils-6.8
  cifs-utils-6.9
  cifs-utils-6.10

Bug: https://bugzilla.samba.org/show_bug.cgi?id=14442
Reported-by: Vadim Lebedev <vadim@mbdsys.com>
Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: Aurelien Aptel <aaptel@suse.com>
6 years agocifs-utils: bump version to 6.10 cifs-utils-6.10
Pavel Shilovsky [Mon, 16 Dec 2019 23:34:56 +0000 (15:34 -0800)]
cifs-utils: bump version to 6.10

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>