More TANDEM changes

- Handle a non-0 root uid.
- Handle alternate major/minor/MAKEDEV funcs.
- Other misc compatibility tweaks.
This commit is contained in:
Wayne Davison
2020-07-06 00:00:36 -07:00
parent bb16db1747
commit 59cb358fda
9 changed files with 75 additions and 31 deletions

View File

@@ -119,7 +119,7 @@ static const char *check_secret(int module, const char *user, const char *group,
if ((st.st_mode & 06) != 0) {
rprintf(FLOG, "secrets file must not be other-accessible (see strict modes option)\n");
ok = 0;
} else if (MY_UID() == 0 && st.st_uid != 0) {
} else if (MY_UID() == ROOT_UID && st.st_uid != ROOT_UID) {
rprintf(FLOG, "secrets file must be owned by root when running as root (see strict modes)\n");
ok = 0;
}
@@ -196,7 +196,7 @@ static const char *getpassf(const char *filename)
rprintf(FERROR, "ERROR: password file must not be other-accessible\n");
exit_cleanup(RERR_SYNTAX);
}
if (MY_UID() == 0 && st.st_uid != 0) {
if (MY_UID() == ROOT_UID && st.st_uid != ROOT_UID) {
rprintf(FERROR, "ERROR: password file must be owned by root when running as root\n");
exit_cleanup(RERR_SYNTAX);
}

View File

@@ -704,7 +704,7 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
logfile_format_has_o_or_i = 1;
uid = MY_UID();
am_root = (uid == 0);
am_root = (uid == ROOT_UID);
p = *lp_uid(module_id) ? lp_uid(module_id) : am_root ? NOBODY_USER : NULL;
if (p) {
@@ -959,7 +959,7 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
}
our_uid = MY_UID();
am_root = (our_uid == 0);
am_root = (our_uid == ROOT_UID);
}
if (lp_temp_dir(module_id) && *lp_temp_dir(module_id)) {
@@ -1213,7 +1213,7 @@ int start_daemon(int f_in, int f_out)
return -1;
}
our_uid = MY_UID();
am_root = (our_uid == 0);
am_root = (our_uid == ROOT_UID);
}
addr = client_addr(f_in);

4
main.c
View File

@@ -299,7 +299,7 @@ static void become_copy_as_user()
our_uid = MY_UID();
our_gid = MY_GID();
am_root = (our_uid == 0);
am_root = (our_uid == ROOT_UID);
if (gname)
gname[-1] = ':';
@@ -1667,7 +1667,7 @@ int main(int argc,char *argv[])
starttime = time(NULL);
our_uid = MY_UID();
our_gid = MY_GID();
am_root = our_uid == 0;
am_root = our_uid == ROOT_UID;
memset(&stats, 0, sizeof(stats));

View File

@@ -11,6 +11,10 @@ extern __const __int32_t *__ctype_toupper;
/*@=declundef@*/
#endif
#ifdef __TANDEM
# include <floss.h(floss_execvp,floss_read)>
#endif
#include <ctype.h>
#include <errno.h>

16
rsync.h
View File

@@ -473,7 +473,23 @@ enum delret {
#ifdef MAKEDEV_TAKES_3_ARGS
#define MAKEDEV(devmajor,devminor) makedev(0,devmajor,devminor)
#else
#ifndef __TANDEM
#define MAKEDEV(devmajor,devminor) makedev(devmajor,devminor)
#else
# include <sys/stat.h>
# define major DEV_TO_MAJOR
# define minor DEV_TO_MINOR
# define MAKEDEV MAJORMINOR_TO_DEV
#endif
#endif
#ifdef __TANDEM
# include <floss.h(floss_read,floss_write,floss_fork,floss_execvp)>
# include <floss.h(floss_getpwuid,floss_select,floss_seteuid)>
# define S_IEXEC S_IXUSR
# define ROOT_UID 65535
#else
# define ROOT_UID 0
#endif
#ifdef HAVE_COMPAT_H

View File

@@ -48,15 +48,16 @@ EOF
;;
*)
RSYNC="$RSYNC --super"
case `get_testuid` in
'') ;; # If "id" failed, try to continue...
0) ;;
*) if [ -e "$FAKEROOT_PATH" ]; then
my_uid=`get_testuid`
root_uid=`get_rootuid`
if test x"$my_uid" = x; then
: # If "id" failed, try to continue...
elif test x"$my_uid" != x"$root_uid"; then
if [ -e "$FAKEROOT_PATH" ]; then
echo "Let's try re-running the script under fakeroot..."
exec "$FAKEROOT_PATH" "$SHELL_PATH" "$0"
fi
;;
esac
fi
;;
esac

View File

@@ -41,14 +41,14 @@ cd "$scratchdir"
ln -s test-rsyncd.conf rsyncd.conf
my_uid=`get_testuid`
root_uid=`get_rootuid`
confopt=''
case `get_testuid` in
0)
if test x"$my_uid" = x"$root_uid"; then
# Root needs to specify the config file, or it uses /etc/rsyncd.conf.
echo "Forcing --config=$conf"
confopt=" --config=$conf"
;;
esac
fi
# These have a space-padded 15-char name, then a tab, then a comment.
sed 's/NOCOMMENT//' <<EOT >"$chkfile"

View File

@@ -67,16 +67,17 @@ EOF
esac
;;
*)
case `get_testuid` in
'') ;; # If "id" failed, try to continue...
0) ;;
*) if [ -e "$FAKEROOT_PATH" ]; then
my_uid=`get_testuid`
root_uid=`get_rootuid`
if test x"$my_uid" = x; then
: # If "id" failed, try to continue...
elif test x"$my_uid" != x"$root_uid"; then
if [ -e "$FAKEROOT_PATH" ]; then
echo "Let's try re-running the script under fakeroot..."
exec "$FAKEROOT_PATH" "$SHELL_PATH" $RUNSHFLAGS "$0"
fi
test_skipped "Rsync needs root/fakeroot for device tests"
;;
esac
fi
;;
esac

View File

@@ -102,7 +102,27 @@ rsync_ls_lR() {
}
get_testuid() {
id 2>/dev/null | sed 's/^[^0-9]*\([0-9][0-9]*\).*/\1/'
uid=`id -u 2>/dev/null`
case "$uid" in
[0-9]*) echo "$uid" ;;
*) id 2>/dev/null | sed 's/^[^0-9]*\([0-9][0-9]*\).*/\1/' ;;
esac
}
get_rootuid() {
uid=`id -u root 2>/dev/null`
case "$uid" in
[0-9]*) echo "$uid" ;;
*) echo 0 ;;
esac
}
get_rootgid() {
gid=`id -g root 2>/dev/null`
case "$gid" in
[0-9]*) echo "$gid" ;;
*) echo 0 ;;
esac
}
check_perms() {
@@ -278,16 +298,18 @@ build_rsyncd_conf() {
logfile="$scratchdir/rsyncd.log"
hostname=`uname -n`
uid_setting='uid = 0'
gid_setting='gid = 0'
case `get_testuid` in
0) ;;
*)
my_uid=`get_testuid`
root_uid=`get_rootuid`
root_gid=`get_rootgid`
uid_setting="uid = $root_uid"
gid_setting="gid = $root_gid"
if test x"$my_uid" != x"$root_uid"; then
# Non-root cannot specify uid & gid settings
uid_setting="#$uid_setting"
gid_setting="#$gid_setting"
;;
esac
fi
cat >"$conf" <<EOF
# rsyncd configuration file autogenerated by $0