From f7fb5211e6b22ba351e33d8d6f1dbfcfc3336eb3 Mon Sep 17 00:00:00 2001
From: Andrus Suvalau <andrus.suvalau@icloud.com>
Date: Fri, 27 Feb 2026 14:16:42 +0100
Subject: [PATCH] Changes to recover openSUSE Tumbleweed / SLES16 (#3569)

See https://github.com/rear/rear/issues/3567

* Do not finish with error when there are no RPC services

On openSUSE Tumbleweed rpcbind is running,
however, no RPC services have registered.
It does not lead to failure to mount NETFS.

* Copy sshd-auth to the rescue system

* Support NSS usrfiles module for SLES 16

On SLES 16, /etc/services was moved to /usr/etc/services,
which caused rpcbind to fail to register itself.
After successfully running 'rpcbind -s', 'rpbinfo -p'
would return 'No remote programs registered.'
The route cause is the absence of real /etc/sevices
in the rescue environment.

To find /usr/etc/services, NSS usrfiles module is required.
On SUSE, /etc/nsswitch.conf is customized:
Add 'usrfiles' for services and protocols.
---
 usr/share/rear/conf/GNU/Linux.conf                 |  8 ++++++++
 usr/share/rear/rescue/default/500_ssh.sh           |  6 ++++++
 usr/share/rear/skel/SUSE/default/etc/nsswitch.conf | 11 +++++++++++
 3 files changed, 25 insertions(+)
 create mode 100644 usr/share/rear/skel/SUSE/default/etc/nsswitch.conf

diff --git a/usr/share/rear/conf/GNU/Linux.conf b/usr/share/rear/conf/GNU/Linux.conf
index 9ebc3e70a4..c2660826ac 100644
--- a/usr/share/rear/conf/GNU/Linux.conf
+++ b/usr/share/rear/conf/GNU/Linux.conf
@@ -198,9 +198,12 @@ LIBS+=(
 ### needed for username lookups
 /lib*/libnss_dns*
 /lib*/libnss_files*
+### needed for usrfiles module on SUSE
+/lib*/libnss_usrfiles*
 ### support multiarch
 /lib/*/libnss_dns*
 /lib/*/libnss_files*
+/lib/*/libnss_usrfiles*
 
 /lib*/libgcc_s*
 /lib*/libresolv*
@@ -234,6 +237,11 @@ LIBS+=(
 
 COPY_AS_IS+=( /dev /etc/inputr[c] /etc/protocols /etc/services /etc/rpc /etc/termcap /etc/terminfo /lib*/terminfo /usr/share/terminfo /etc/netconfig /etc/mke2fs.conf /etc/*-release /etc/localtime /etc/magic /usr/share/misc/magic /etc/dracut.conf /etc/dracut.conf.d /usr/lib/dracut /sbin/modprobe.ksplice-orig /etc/sysctl.conf /etc/sysctl.d /etc/e2fsck.conf )
 
+# On SLES 16,
+# /etc/protocols was moved to /usr/etc/protocols
+# /etc/services was moved to /usr/etc/services
+COPY_AS_IS+=( /usr/etc/protocols /usr/etc/services )
+
 # Needed by vi on Fedora and derived distributions
 # where vi is a shell script that executes /usr/libexec/vi
 # see https://github.com/rear/rear/pull/2822
diff --git a/usr/share/rear/rescue/default/500_ssh.sh b/usr/share/rear/rescue/default/500_ssh.sh
index 60d9fbd5a4..41314cded9 100644
--- a/usr/share/rear/rescue/default/500_ssh.sh
+++ b/usr/share/rear/rescue/default/500_ssh.sh
-44,6 +44,12 @@ contains_visible_char "${copy_as_is_ssh_
 # Copy the usual SSH programs into the recovery system:
 PROGS+=( ssh sshd scp sftp ssh-agent ssh-keygen ssh-add )
 
+# Copy a helper needed at least on openSUSE Tumbleweed
+# Without it, sshd aborts with
+# "/usr/libexec/openssh/sshd-auth does not exist or is not executable".
+local sshdauthpath="$( sshd -T | awk '$1=="sshdauthpath" { print $2 }' )"
+test "$sshdauthpath" && COPY_AS_IS+=( "$sshdauthpath" )
 # Copy a sftp-server program (e.g. /usr/lib/ssh/sftp-server) into the recovery system (if exists).
 # Because only OpenSSH >= 3.1 is supported where /etc/ssh/ is the default directory for configuration files
 # only /etc/ssh/sshd_config is inspected to grep for a sftp-server program therein
diff --git a/usr/share/rear/skel/SUSE/default/etc/nsswitch.conf b/usr/share/rear/skel/SUSE/default/etc/nsswitch.conf
new file mode 100644
index 0000000000..332b125233
--- /dev/null
+++ b/usr/share/rear/skel/SUSE/default/etc/nsswitch.conf
@@ -0,0 +1,11 @@
+passwd: files
+shadow: files
+group:  files
+
+hosts:  	files dns
+networks:       files dns
+
+services:       files usrfiles
+protocols:      files usrfiles
+rpc:		files
+ethers:		files
