diff --git a/usr.bin/xinstall/tests/install_test.sh b/usr.bin/xinstall/tests/install_test.sh --- a/usr.bin/xinstall/tests/install_test.sh +++ b/usr.bin/xinstall/tests/install_test.sh @@ -481,6 +481,21 @@ atf_check_equal "$u:$g:10$cM" "$(stat -f"%u:%g:%p" testc)" } +atf_test_case set_optional_exec +set_optional_exec_head() { + atf_set "require.user" "unprivileged" +} +set_optional_exec_body() +{ + echo "abc" > testfile.src + + atf_check install -d -m ug+rX testdir + atf_check test -x testdir + + atf_check install -m ug+rX testfile.src testfile + atf_check test ! -x testfile +} + atf_init_test_cases() { atf_add_test_case copy_to_nonexistent atf_add_test_case copy_to_nonexistent_safe @@ -523,4 +538,5 @@ atf_add_test_case mkdir_simple atf_add_test_case set_owner_group_mode atf_add_test_case set_owner_group_mode_unpriv + atf_add_test_case set_optional_exec } diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -189,6 +189,7 @@ fset = 0; iflags = 0; + set = NULL; group = owner = NULL; while ((ch = getopt(argc, argv, "B:bCcD:df:g:h:l:M:m:N:o:pSsT:Uv")) != -1) @@ -255,11 +256,10 @@ break; case 'm': haveopt_m = 1; + free(set); if (!(set = setmode(optarg))) errx(EX_USAGE, "invalid file mode: %s", optarg); - mode = getmode(set, 0); - free(set); break; case 'N': if (!setup_getid(optarg)) @@ -301,6 +301,14 @@ usage(); } + /* + * Default permissions based on whether we're a directory or not, since + * an +X may mean that we need to set the execute bit. + */ + if (set != NULL) + mode = getmode(set, dodir ? S_IFDIR : 0) & ~S_IFDIR; + free(set); + if (getenv("DONTSTRIP") != NULL) { warnx("DONTSTRIP set - will not strip installed binaries"); dostrip = 0;