VirtualBox

Changeset 31288 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Aug 2, 2010 12:22:41 PM (14 years ago)
Author:
vboxsync
Message:

path-posix.cpp: Implemented RTPathSetOwnerEx and RTPathSetOwner.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/path-posix.cpp

    r28915 r31288  
    579579    LogFlow(("RTPathSetTimes(%p:{%s}, %p:{%RDtimespec}, %p:{%RDtimespec}, %p:{%RDtimespec}, %p:{%RDtimespec}): return %Rrc\n",
    580580             pszPath, pszPath, pAccessTime, pAccessTime, pModificationTime, pModificationTime,
    581              pChangeTime, pChangeTime, pBirthTime, pBirthTime));
     581             pChangeTime, pChangeTime, pBirthTime, pBirthTime, rc));
     582    return rc;
     583}
     584
     585
     586RTR3DECL(int) RTPathSetOwner(const char *pszPath, uint32_t uid, uint32_t gid)
     587{
     588    return RTPathSetOwnerEx(pszPath, uid, gid, RTPATH_F_ON_LINK);
     589}
     590
     591
     592RTR3DECL(int) RTPathSetOwnerEx(const char *pszPath, uint32_t uid, uint32_t gid, uint32_t fFlags)
     593{
     594    /*
     595     * Validate input.
     596     */
     597    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
     598    AssertReturn(*pszPath, VERR_INVALID_PARAMETER);
     599    AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
     600    uid_t uidNative = uid != UINT32_MAX ? (uid_t)uid : -1;
     601    AssertReturn(uid == uidNative, VERR_INVALID_PARAMETER);
     602    gid_t gidNative = gid != UINT32_MAX ? (gid_t)gid : -1;
     603    AssertReturn(gid == gidNative, VERR_INVALID_PARAMETER);
     604
     605    /*
     606     * Convert the path.
     607     */
     608    char const *pszNativePath;
     609    int rc = rtPathToNative(&pszNativePath, pszPath, NULL);
     610    if (RT_SUCCESS(rc))
     611    {
     612        if (fFlags & RTPATH_F_FOLLOW_LINK)
     613        {
     614            if (chown(pszNativePath, uidNative, gidNative))
     615                rc = RTErrConvertFromErrno(errno);
     616        }
     617#if 1
     618        else
     619        {
     620            if (lchown(pszNativePath, uidNative, gidNative))
     621                rc = RTErrConvertFromErrno(errno);
     622        }
     623#else
     624        else
     625        {
     626            RTFSOBJINFO ObjInfo;
     627            rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_UNIX, fFlags);
     628            if (RT_SUCCESS(rc) && RTFS_IS_SYMLINK(ObjInfo.Attr.fMode))
     629                rc = VERR_NS_SYMLINK_CHANGE_OWNER;
     630            else if (RT_SUCCESS(rc))
     631            {
     632                if (lchown(pszNativePath, uidNative, gidNative))
     633                    rc = RTErrConvertFromErrno(errno);
     634            }
     635        }
     636#endif
     637        if (RT_FAILURE(rc))
     638            Log(("RTPathSetOwnerEx('%s',%d,%d): failed with %Rrc and errno=%d\n",
     639                 pszPath, uid, gid, rc, errno));
     640
     641        rtPathFreeNative(pszNativePath, pszPath);
     642    }
     643
     644    LogFlow(("RTPathSetOwnerEx(%p:{%s}, uid, gid): return %Rrc\n",
     645             pszPath, pszPath, uid, gid, rc));
    582646    return rc;
    583647}
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