VirtualBox

Changeset 6969 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 15, 2008 1:02:28 PM (17 years ago)
Author:
vboxsync
Message:

Additions/X11: weakened SUID root permissions on VBoxClient on Linux. This may need some additional corrections for Solaris.

Location:
trunk/src/VBox/Additions
Files:
2 edited

Legend:

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

    r5999 r6969  
    110110modname=vboxadd
    111111module=$kdir/$modname
     112owner=vboxadd
     113group=1
    112114
    113115file=""
     
    167169    fi
    168170
     171    chown $owner:$group $dev 2>/dev/null || {
     172        rmmod $modname 2>/dev/null
     173        fail "Cannot change owner $owner:$group for device $dev"
     174    }
     175
    169176    succ_msg
    170177    return 0
  • trunk/src/VBox/Additions/x11/xclient/main.cpp

    r6459 r6969  
    2929#include <unistd.h>
    3030#include <getopt.h>
     31#include <errno.h>
    3132
    3233#include <X11/Xlib.h>
     
    4041
    4142static bool gbDaemonise = true;
     43static int (*gpfnOldIOErrorHandler)(Display *) = NULL;
     44
     45/**
     46 * Drop the programmes privileges to the caller's.
     47 * @returns IPRT status code
     48 * @todo move this into the R3 guest library
     49 */
     50int vboxClientDropPrivileges(void)
     51{
     52    int rc = VINF_SUCCESS;
     53    int rcSystem, rcErrno;
     54
     55#ifdef _POSIX_SAVED_IDS
     56    rcSystem = setuid(getuid());
     57#else
     58    rcSystem = setreuid(-1, getuid());
     59#endif
     60    if (rcSystem < 0)
     61    {
     62        rcErrno = errno;
     63        rc = RTErrConvertFromErrno(rcErrno);
     64        LogRel(("VBoxClient: failed to drop privileges, error %Rrc.\n", rc));
     65    }
     66    return rc;
     67}
    4268
    4369/**
     
    5278        /* This can be triggered in debug builds if a guest application passes a bad atom
    5379           in its list of supported clipboard formats.  As such it is harmless. */
    54         Log(("VBoxService: ignoring BadAtom error and returning\n"));
     80        Log(("VBoxClient: ignoring BadAtom error and returning\n"));
    5581        return 0;
    5682    }
     
    5884    {
    5985        /* This can be triggered if a guest application destroys a window before we notice. */
    60         Log(("VBoxService: ignoring BadWindow error and returning\n"));
     86        Log(("VBoxClient: ignoring BadWindow error and returning\n"));
    6187        return 0;
    6288    }
     
    6591#endif
    6692    XGetErrorText(pDisplay, pError->error_code, errorText, sizeof(errorText));
    67     LogRel(("VBoxService: an X Window protocol error occurred: %s.  Request code: %d, minor code: %d, serial number: %d\n",
    68          pError->error_code, pError->request_code, pError->minor_code, pError->serial));
     93    LogRel(("VBoxClient: an X Window protocol error occurred: %s (error code %d).  Request code: %d, minor code: %d, serial number: %d\n", errorText, pError->error_code, pError->request_code, pError->minor_code, pError->serial));
     94    VbglR3Term();
    6995    exit(1);
    7096}
    7197
     98/**
     99 * Xlib error handler for fatal errors.  This often means that the programme is still running
     100 * when X exits.
     101 */
     102int vboxClientXLibIOErrorHandler(Display *pDisplay)
     103{
     104    Log(("VBoxClient: a fatal guest X Window error occurred.  This may just mean that the Window system was shut down while the client was still running.\n"));
     105    VbglR3Term();
     106    return gpfnOldIOErrorHandler(pDisplay);
     107}
     108
    72109int main(int argc, char *argv[])
    73110{
    74     int rc;
     111    int rcClipboard, rc;
    75112#ifdef SEAMLESS_X11
    76113    /** Our instance of the seamless class. */
     
    114151        if (RT_FAILURE(rc))
    115152        {
    116             LogRel(("VBoxService: failed to daemonize. exiting."));
     153            std::cout << "VBoxClient: failed to daemonize. exiting."<< std::endl;
    117154            return 1;
    118155        }
     
    120157    /* Initialise our runtime before all else. */
    121158    RTR3Init(false);
    122     rc = VbglR3Init();
    123     if (RT_FAILURE(rc))
     159    if (RT_FAILURE(VbglR3Init()))
    124160    {
    125161        std::cout << "Failed to connect to the VirtualBox kernel service" << std::endl;
    126162        return 1;
    127163    }
    128     LogRel(("VBoxService: starting...\n"));
     164    if (RT_FAILURE(vboxClientDropPrivileges()))
     165        return 1;
     166    LogRel(("VBoxClient: starting...\n"));
    129167    /* Initialise threading in X11 and in Xt. */
    130168    if (!XInitThreads() || !XtToolkitThreadInitialize())
    131169    {
    132         LogRel(("VBoxService: error initialising threads in X11, exiting."));
     170        LogRel(("VBoxClient: error initialising threads in X11, exiting."));
    133171        return 1;
    134172    }
    135173    /* Set an X11 error handler, so that we don't die when we get unavoidable errors. */
    136174    XSetErrorHandler(vboxClientXLibErrorHandler);
     175    /* Set an X11 I/O error handler, so that we can shutdown properly on fatal errors. */
     176    gpfnOldIOErrorHandler = XSetIOErrorHandler(vboxClientXLibIOErrorHandler);
    137177#ifdef VBOX_X11_CLIPBOARD
    138178    /* Connect to the host clipboard. */
    139     LogRel(("VBoxService: starting clipboard Guest Additions...\n"));
    140     rc = vboxClipboardConnect();
    141     if (RT_SUCCESS(rc))
    142     {
    143         LogRel(("VBoxService: vboxClipboardConnect failed with rc = %Rrc\n", rc));
     179    LogRel(("VBoxClient: starting clipboard Guest Additions...\n"));
     180    rcClipboard = vboxClipboardConnect();
     181    if (RT_FAILURE(rcClipboard))
     182    {
     183        LogRel(("VBoxClient: vboxClipboardConnect failed with rc = %Rrc\n", rc));
    144184    }
    145185#endif  /* VBOX_X11_CLIPBOARD defined */
     
    147187    try
    148188    {
    149         LogRel(("VBoxService: starting seamless Guest Additions...\n"));
     189        LogRel(("VBoxClient: starting seamless Guest Additions...\n"));
    150190        rc = seamless.init();
    151191        if (RT_FAILURE(rc))
    152192        {
    153             LogRel(("VBoxService: failed to initialise seamless Additions, rc = %Rrc\n", rc));
     193            LogRel(("VBoxClient: failed to initialise seamless Additions, rc = %Rrc\n", rc));
    154194        }
    155195    }
    156196    catch (std::exception e)
    157197    {
    158         LogRel(("VBoxService: failed to initialise seamless Additions - caught exception: %s\n", e.what()));
     198        LogRel(("VBoxClient: failed to initialise seamless Additions - caught exception: %s\n", e.what()));
    159199        rc = VERR_UNRESOLVED_ERROR;
    160200    }
    161201    catch (...)
    162202    {
    163         LogRel(("VBoxService: failed to initialise seamless Additions - caught unknown exception.\n"));
     203        LogRel(("VBoxClient: failed to initialise seamless Additions - caught unknown exception.\n"));
    164204        rc = VERR_UNRESOLVED_ERROR;
    165205    }
    166206#endif /* SEAMLESS_X11 defined */
    167207#ifdef VBOX_X11_CLIPBOARD
    168     LogRel(("VBoxService: connecting to the shared clipboard service.\n"));
    169     vboxClipboardMain();
    170     vboxClipboardDisconnect();
     208    if (RT_SUCCESS(rcClipboard))
     209    {
     210        LogRel(("VBoxClient: connecting to the shared clipboard service.\n"));
     211        vboxClipboardMain();
     212        vboxClipboardDisconnect();
     213    }
    171214#else  /* VBOX_X11_CLIPBOARD not defined */
    172     LogRel(("VBoxService: sleeping...\n"));
     215    LogRel(("VBoxClient: sleeping...\n"));
    173216    pause();
    174     LogRel(("VBoxService: exiting...\n"));
     217    LogRel(("VBoxClient: exiting...\n"));
    175218#endif  /* VBOX_X11_CLIPBOARD not defined */
    176219#ifdef SEAMLESS_X11
     
    181224    catch (std::exception e)
    182225    {
    183         LogRel(("VBoxService: error shutting down seamless Additions - caught exception: %s\n", e.what()));
     226        LogRel(("VBoxClient: error shutting down seamless Additions - caught exception: %s\n", e.what()));
    184227        rc = VERR_UNRESOLVED_ERROR;
    185228    }
    186229    catch (...)
    187230    {
    188         LogRel(("VBoxService: error shutting down seamless Additions - caught unknown exception.\n"));
     231        LogRel(("VBoxClient: error shutting down seamless Additions - caught unknown exception.\n"));
    189232        rc = VERR_UNRESOLVED_ERROR;
    190233    }
    191234#endif /* SEAMLESS_X11 defined */
    192     return rc;
    193 }
     235    VbglR3Term();
     236    return RT_SUCCESS(rc) ? 0 : 1;
     237}
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