VirtualBox

Changeset 13788

Show
Ignore:
Timestamp:
11/04/08 16:22:30 (2 months ago)
Author:
vboxsync
Message:

added (still disabled) code for additional security checks in /tmp/.vbox-*-ipc

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcdUnix.cpp

    r7049 r13788  
    9494    ELockFileOpen = -1, 
    9595    ELockFileLock = -2, 
    96  
     96    ELockFileOwner = -3, 
    9797}; 
    9898 
     
    113113    memcpy(lockFile + dirLen + 1, lockName, sizeof(lockName)); 
    114114 
     115#if 0 
     116#ifdef VBOX 
     117    // 
     118    // Security checks 
     119    // 
     120    struct stat st; 
     121    if (stat(baseDir, &st) == -1) 
     122    { 
     123        printf("Cannot stat '%s'.\n", baseDir); 
     124        return ELockFileOwner; 
     125    } 
     126 
     127    if (st.st_uid != getuid() && st.st_uid != geteuid()) 
     128    { 
     129        printf("Wrong owner (%d) of '%s'.\n", st.st_uid, baseDir); 
     130        return ELockFileOwner; 
     131    } 
     132 
     133    if (st.st_mode != (__S_IREAD | __S_IWRITE | __S_IEXEC | __S_IFDIR)) 
     134    { 
     135        printf("Wrong mode (%o) of '%s'.\n", st.st_mode, baseDir); 
     136        return ELockFileOwner; 
     137    } 
     138#endif 
     139#endif 
     140 
    115141    // 
    116142    // open lock file.  it remains open until we shutdown. 
     
    118144    ipcLockFD = open(lockFile, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR); 
    119145 
     146#if 0 
     147#ifndef VBOX 
    120148    free(lockFile); 
     149#endif 
     150#endif 
    121151 
    122152    if (ipcLockFD == -1) 
    123153        return ELockFileOpen; 
     154 
     155#if 0 
     156#ifdef VBOX 
     157    // 
     158    // Security checks 
     159    // 
     160    if (fstat(ipcLockFD, &st) == -1) 
     161    { 
     162        printf("Cannot stat '%s'.\n", lockFile); 
     163        free(lockFile); 
     164        return ELockFileOwner; 
     165    } 
     166 
     167    if (st.st_uid != getuid() && st.st_uid != geteuid()) 
     168    { 
     169        printf("Wrong owner (%d) of '%s'.\n", st.st_uid, lockFile); 
     170        free(lockFile); 
     171        return ELockFileOwner; 
     172    } 
     173 
     174    if (st.st_mode != (__S_IREAD | __S_IWRITE | __S_IFREG)) 
     175    { 
     176        printf("Wrong mode (%o) of '%s'.\n", st.st_mode, lockFile); 
     177        free(lockFile); 
     178        return ELockFileOwner; 
     179    } 
     180 
     181    free(lockFile); 
     182#endif 
     183#endif 
    124184 
    125185    // 
     
    434494            // we terminate 
    435495#ifdef VBOX 
    436             printf("Cannot create a lock file for '%s'.\n" 
    437                    "Check permissions.\n", addr.local.path); 
     496            if (status != ELockFileOwner) 
     497                printf("Cannot create a lock file for '%s'.\n" 
     498                        "Check permissions.\n", addr.local.path); 
    438499#endif 
    439500            return 0; 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy