VirtualBox

Ignore:
Timestamp:
Apr 21, 2023 5:29:06 PM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157007
Message:

Additions: Linux: rcvboxadd: Check for root user on those actions which require root privileges, bugref:10359.

This prevents unexpected messages in stdout when script does not have permissions to write log files in /var.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/installer/vboxadd.sh

    r99508 r99510  
    108108}
    109109
     110# When script is running as non-root, it does not have access to log
     111# files in /var. In this case, lets print error message to stdout and
     112# exit with bad status.
     113early_fail()
     114{
     115    echo "$1" >&2
     116    exit 1
     117}
     118
    110119fail()
    111120{
     
    215224        cat "$version_string_path"
    216225    else
    217         echo "UNKNOWN"
     226        echo "unknown"
    218227    fi
    219228}
     
    944953}
    945954
     955check_root()
     956{
     957    # Check if script is running with root privileges and exit if it does not.
     958    [ `id -u` -eq 0 ] || early_fail "root privileges are required"
     959}
     960
    946961# Check if process with this PID is running.
    947962check_pid()
     
    10481063{
    10491064    begin "reloading kernel modules and services"
    1050 
    1051     # Check if script was started with root privileges.
    1052     [ `id -u` -eq 0 ] || fail "root privileges are required"
    10531065
    10541066    # Stop VBoxService if running.
     
    11461158# system so that we can see later if any were added.
    11471159start)
     1160    check_root
    11481161    start
    11491162    ;;
     
    11521165# this fast enough at start time if we discover we do not want to use them.
    11531166stop)
     1167    check_root
    11541168    stop
    11551169    ;;
    11561170restart)
     1171    check_root
    11571172    restart
    11581173    ;;
    11591174# Tries to reload kernel modules and restart user processes.
    11601175reload)
     1176    check_root
    11611177    reload
    11621178    ;;
     
    11651181# current kernel.
    11661182setup)
     1183    check_root
    11671184    cleanup && start
    11681185    ;;
    11691186# Builds kernel modules for the specified kernels if they are not already built.
    11701187quicksetup)
     1188    check_root
    11711189    if test x"$2" = xall; then
    11721190       for topi in /lib/modules/*; do
     
    11841202# including all kernel modules.
    11851203cleanup)
     1204    check_root
    11861205    cleanup
    11871206    ;;
     
    11901209    ;;
    11911210status-kernel)
     1211    check_root
    11921212    check_status_kernel && info "Kernel modules are loaded"
    11931213    ;;
    11941214status-user)
     1215    check_root
    11951216    check_status_user
    11961217    if [ $? -eq 0 ]; then
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette