Changeset 3817


Ignore:
Timestamp:
Feb 19, 2014, 2:40:34 AM (11 years ago)
Author:
bird
Message:

0.6: Untested backport of the *chown and *chmod changes that hit trunk in r3816.

Location:
branches/libc-0.6/src/emx
Files:
9 edited
4 copied

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/include/InnoTekLIBC/backend.h

    r3811 r3817  
    11/* $Id$ */
    22/** @file
    3  *
    43 * LIBC - Backend header.
    5  *
    6  * Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
    7  *
     4 */
     5
     6/*
     7 * Copyright (c) 2004-2014 knut st. osmundsen <bird-srcspam@anduin.net>
    88 *
    99 * This file is part of InnoTek LIBC.
     
    337337
    338338/**
     339 * Changes the ownership and/or group, without following any final symlink.
     340 *
     341 * @returns 0 on success.
     342 * @returns Negative error code (errno.h) on failure.
     343 * @param   pszPath     Path to the file to modify ownership of.  If this is a
     344 *                      symbolic link, the link it self will modified.
     345 * @param   uid         The user id of the new owner, pass -1 to not change it.
     346 * @param   gid         The group id of the new group, pass -1 to not change it.
     347 */
     348int __libc_Back_fsSymlinkOwnerSet(const char *pszPath, uid_t uid, gid_t gid);
     349
     350/**
    339351 * Stats a file.
    340352 *
     
    396408 */
    397409int __libc_Back_fsFileTimesSetFH(int fh, const struct timeval *paTimes);
     410
     411/**
     412 * Changes the ownership and/or group, following all symbolic links.
     413 *
     414 * @returns 0 on success.
     415 * @returns Negative error code (errno.h) on failure.
     416 * @param   pszPath     Path to the file to modify ownership of.
     417 * @param   uid         The user id of the new owner, pass -1 to not change it.
     418 * @param   gid         The group id of the new group, pass -1 to not change it.
     419 */
     420int __libc_Back_fsFileOwnerSet(const char *pszPath, uid_t uid, gid_t gid);
     421
     422/**
     423 * Changes the ownership and/or group.
     424 *
     425 * @returns 0 on success.
     426 * @returns Negative error code (errno.h) on failure.
     427 * @param   fh          Handle to file.
     428 * @param   uid         The user id of the new owner, pass -1 to not change it.
     429 * @param   gid         The group id of the new group, pass -1 to not change it.
     430 */
     431int __libc_Back_fsFileOwnerSetFH(int fh, uid_t uid, gid_t gid);
    398432
    399433/**
  • branches/libc-0.6/src/emx/src/lib/io

  • branches/libc-0.6/src/emx/src/lib/io/fchown.c

    r2254 r3817  
    11/* $Id$ */
    22/** @file
    3  *
    43 * fchown()
    5  *
    6  * Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
     4 */
     5
     6/*
     7 * Copyright (c) 2004-2014 knut st. osmundsen <bird-srcspam@anduin.net>
    78 *
    89 *
     
    2627
    2728
    28 
    2929/*******************************************************************************
    3030*   Header Files                                                               *
    3131*******************************************************************************/
     32#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
    3233#include "libc-alias.h"
    3334#include <unistd.h>
    34 #include <emx/io.h>
    35 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
     35#include <errno.h>
     36#include <InnoTekLIBC/backend.h>
    3637#include <InnoTekLIBC/logstrict.h>
    3738
    3839
    39 
    4040/**
    41  * Change the owner and group over a file.
    42  *
    43  * This is stub. It only validates the filehandle and returns without changing anything.
     41 * Change the owner and group if an open file.
    4442 *
    4543 * @returns 0 on success.
    4644 * @returns -1 and errno on failure.
    4745 * @param   fh      Handle to the file.
    48  * @param   owner   Owner id.
    49  * @param   group   Group id.
     46 * @param   uid     The user id of the new owner, pass -1 to not change it.
     47 * @param   gid     The group id of the new group, pass -1 to not change it.
    5048 */
    51 int      _STD(fchown)(int fh, uid_t owner, gid_t group)
     49int _STD(fchown)(int fh, uid_t uid, gid_t gid)
    5250{
    53     LIBCLOG_ENTER("fh=%d owner=%d group=%d\n", fh, owner, group);
    54     __LIBC_PFH  pFH = __libc_FH(fh);
    55     if (pFH)
     51    LIBCLOG_ENTER("fh=%d uid=%ld gid=%ld\n", fh, (long)uid, (long)gid);
     52    int rc = __libc_Back_fsFileOwnerSetFH(fh, uid, gid);
     53    if (!rc)
    5654        LIBCLOG_RETURN_INT(0);
     55    errno = -rc;
    5756    LIBCLOG_ERROR_RETURN_INT(-1);
    5857}
  • branches/libc-0.6/src/emx/src/lib/io/lchown.c

    r2254 r3817  
    11/* $Id$ */
    22/** @file
    3  *
    43 * lchown()
    5  *
    6  * Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
     4 */
     5
     6/*
     7 * Copyright (c) 2004-2014 knut st. osmundsen <bird-srcspam@anduin.net>
    78 *
    89 *
     
    2627
    2728
    28 
    2929/*******************************************************************************
    3030*   Header Files                                                               *
    3131*******************************************************************************/
     32#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
    3233#include "libc-alias.h"
    3334#include <unistd.h>
    34 #include <sys/stat.h>
    35 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
     35#include <errno.h>
     36#include <InnoTekLIBC/backend.h>
    3637#include <InnoTekLIBC/logstrict.h>
    3738
    3839
    39 
    4040/**
    41  * Change the owner and group over a symbolic link.
    42  *
    43  * This is stub. It only validates the path and returns without changing anything.
     41 * Change the owner and group of a symbolic link or file.
    4442 *
    4543 * @returns 0 on success.
    4644 * @returns -1 and errno on failure.
    47  * @param   path    Path to the link to change owner/group of.
    48  * @param   owner   Owner id.
    49  * @param   group   Group id.
     45 * @param   pszPath Path to the file to change owner/group of, symbolic link in
     46 *                  the final component is not followed.
     47 * @param   uid     The user id of the new owner, pass -1 to not change it.
     48 * @param   gid     The group id of the new group, pass -1 to not change it.
    5049 */
    51 int      _STD(lchown)(const char *path, uid_t owner, gid_t group)
     50int      _STD(lchown)(const char *pszPath, uid_t uid, gid_t gid)
    5251{
    53     LIBCLOG_ENTER("path=%p:{%s} owner=%d group=%d\n", (void *)path, path, owner, group);
    54     struct stat st;
    55     int rc = lstat(path, &st);
     52    LIBCLOG_ENTER("pszPath=%p:{%s} uid=%ld gid=%ld\n", (void *)pszPath, pszPath, (long)uid, (long)gid);
     53    int rc = __libc_Back_fsSymlinkOwnerSet(pszPath, uid, gid);
    5654    if (!rc)
    5755        LIBCLOG_RETURN_INT(0);
     56    errno = -rc;
    5857    LIBCLOG_ERROR_RETURN_INT(-1);
    5958}
  • branches/libc-0.6/src/emx/src/lib/misc

  • branches/libc-0.6/src/emx/src/lib/misc/chown.c

    r2254 r3817  
    11/* $Id$ */
    22/** @file
    3  *
    43 * chown()
    5  *
    6  * Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
     4 */
     5
     6/*
     7 * Copyright (c) 2004-2014 knut st. osmundsen <bird-srcspam@anduin.net>
    78 *
    89 *
     
    2627
    2728
    28 
    2929/*******************************************************************************
    3030*   Header Files                                                               *
    3131*******************************************************************************/
     32#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
    3233#include "libc-alias.h"
    3334#include <unistd.h>
    34 #include <sys/stat.h>
    35 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
     35#include <errno.h>
     36#include <InnoTekLIBC/backend.h>
    3637#include <InnoTekLIBC/logstrict.h>
    3738
    3839
    39 
    4040/**
    41  * Change the owner and group over a file.
    42  *
    43  * This is stub. It only validates the path and returns without changing anything.
     41 * Change the owner and group of a file.
    4442 *
    4543 * @returns 0 on success.
    4644 * @returns -1 and errno on failure.
    47  * @param   path    Path to the file to change owner/group of.
    48  * @param   owner   Owner id.
    49  * @param   group   Group id.
     45 * @param   pszPath Path to the file to change owner/group of, all symbolic
     46 *                  links are followed.
     47 * @param   uid     The user id of the new owner, pass -1 to not change it.
     48 * @param   gid     The group id of the new group, pass -1 to not change it.
    5049 */
    51 int      _STD(chown)(const char *path, uid_t owner, gid_t group)
     50int      _STD(chown)(const char *pszPath, uid_t uid, gid_t gid)
    5251{
    53     LIBCLOG_ENTER("path=%p:{%s} owner=%d group=%d\n", (void *)path, path, owner, group);
    54     struct stat st;
    55     int rc = stat(path, &st);
     52    LIBCLOG_ENTER("pszPath=%p:{%s} uid=%ld gid=%ld\n", (void *)pszPath, pszPath, (long)uid, (long)gid);
     53    int rc = __libc_Back_fsFileOwnerSet(pszPath, uid, gid);
    5654    if (!rc)
    57         LIBCLOG_RETURN_INT(rc);
    58     LIBCLOG_ERROR_RETURN_INT(rc);
     55        LIBCLOG_RETURN_INT(0);
     56    errno = -rc;
     57    LIBCLOG_ERROR_RETURN_INT(-1);
    5958}
    6059
  • branches/libc-0.6/src/emx/src/lib/sys/b_fs.h

    r3695 r3817  
    404404int __libc_back_fsNativeFileTimesSet(const char *pszNativePath, const struct timeval *paTimes);
    405405
     406int __libc_back_fsNativeFileOwnerSet(const char *pszNativePath, uid_t uid, gid_t gid);
     407int __libc_back_fsNativeFileOwnerSetCommon(intptr_t hNative, const char *pszNativePath, int fUnixEAs, uid_t uid, gid_t gid);
     408int __libc_back_fsNativeSetEAs(intptr_t hNative, const char *pszNativePath, struct _FEA2LIST *pEAs, struct _EAOP2 *pEaOp2);
     409
    406410/**
    407411 * Calc the Inode and Dev based on native path.
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsFileOwnerSet.c

    r3816 r3817  
    11/* $Id$ */
    22/** @file
    3  *
    4  * LIBC SYS Backend - lstat.
    5  *
    6  * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>
     3 * kNIX - chown.
     4 */
     5
     6/*
     7 * Copyright (c) 2004-2014 knut st. osmundsen <bird-src-spam@anduin.net>
    78 *
    89 *
     
    3031*******************************************************************************/
    3132#include "b_fs.h"
    32 #include <sys/stat.h>
    3333#include <InnoTekLIBC/backend.h>
    3434#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_FS
     
    3737
    3838/**
    39  * Stats a symbolic link.
     39 * Changes the ownership and/or group of a file or directory.
    4040 *
    4141 * @returns 0 on success.
    4242 * @returns Negative error code (errno.h) on failure.
    43  * @param   pszPath     Path to the file to stat. If this is a symbolic link
    44  *                      the link it self will be stat'ed.
    45  * @param   pStat       Where to store the file stats.
     43 * @param   pszPath     Path to the file to modify ownership of, following all
     44 *                      symbolic links.
     45 * @param   uid         The user id of the new owner, pass -1 to not change it.
     46 * @param   gid         The group id of the new group, pass -1 to not change it.
    4647 */
    47 int __libc_Back_fsSymlinkStat(const char *pszPath, struct stat *pStat)
     48int __libc_Back_fsFileOwnerSet(const char *pszPath, uid_t uid, gid_t gid)
    4849{
    49     LIBCLOG_ENTER("pszPath=%p:{%s} pStat=%p\n", (void *)pszPath, pszPath, (void *)pStat);
     50    LIBCLOG_ENTER("pszPath=%p:{%s} %ld %ld\n", (void *)pszPath, pszPath, (long)uid, (long)gid);
    5051
    5152    /*
     
    5354     */
    5455    char szNativePath[PATH_MAX];
    55     int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL);
     56    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_DIR_MAYBE,
     57                                   szNativePath, NULL);
    5658    if (!rc)
    57         rc = __libc_back_fsNativeFileStat(szNativePath, pStat);
     59        rc = __libc_back_fsNativeFileOwnerSet(szNativePath, uid, gid);
    5860
    5961    if (!rc)
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsFileOwnerSetFH.c

    r3816 r3817  
    11/* $Id$ */
    22/** @file
    3  *
    4  * LIBC SYS Backend - fchmod.
    5  *
    6  * Copyright (c) 2005 knut st. osmundsen <bird@innotek.de>
     3 * kNIX - fchown().
     4 */
     5
     6/*
     7 * Copyright (c) 2005-2014 knut st. osmundsen <bird-src-spam@anduin.net>
    78 *
    89 *
     
    5152
    5253/**
    53  * Sets the file access mode of a file by filehandle.
     54 * Sets the file ownership of a file by filehandle.
    5455 *
    5556 * @returns 0 on success.
    5657 * @returns Negative error code (errno.h) on failure.
    57  * @param   fh      Handle to file.
    58  * @param   Mode    The filemode.
     58 * @param   fh          Handle to file.
     59 * @param   uid         The user id of the new owner, pass -1 to not change it.
     60 * @param   gid         The group id of the new group, pass -1 to not change it.
    5961 */
    60 int __libc_Back_fsFileModeSetFH(int fh, mode_t Mode)
     62int __libc_Back_fsFileOwnerSetFH(int fh, uid_t uid, gid_t gid)
    6163{
    62     LIBCLOG_ENTER("fh=%d Mode=%#x\n", fh, Mode);
     64    LIBCLOG_ENTER("fh=%d uid=%ld gid=%ld\n", fh, (long)uid, (long)gid);
    6365
    6466    /*
     
    8789            if (__predict_false(!pFH->pszNativePath))
    8890                LIBCLOG_ERROR_RETURN_INT(-EINVAL);
    89             rc = __libc_back_fsNativeFileModeSet(pFH->pszNativePath, Mode);
     91            rc = __libc_back_fsNativeFileOwner(pFH->pszNativePath, uid, gid);
    9092            if (rc)
    9193                LIBCLOG_ERROR_RETURN_INT(rc);
     
    100102    if (!pFH->pOps)
    101103    {
    102         /*
    103          * Standard OS/2 file handle.
    104          */
    105         FS_VAR();
    106         FS_SAVE_LOAD();
    107         FILESTATUS3 fsts3;
    108 
    109         /*
    110          * Get file info, we don't need EA size nor large file sizes.
    111          */
    112         rc = DosQueryFileInfo(fh, FIL_STANDARD, &fsts3, sizeof(FILESTATUS3));
    113         if (rc)
    114         {
    115             FS_RESTORE();
    116             rc = -__libc_native2errno(rc);
    117             LIBCLOG_ERROR_RETURN_INT(rc);
    118         }
    119 
    120         /*
    121          * If in unix mode we'll have to update/add the MODE too.
    122          */
    123         if (    !__libc_gfNoUnix
    124             &&  pFH->pFsInfo
    125             &&  pFH->pFsInfo->fUnixEAs)
    126         {
    127             mode_t CurMode;
    128             rc = __libc_back_fsUnixAttribsGetMode(fh, pFH->pszNativePath, &CurMode);
    129             if (__predict_true(!rc || rc == -ENOTSUP))
    130             {
    131                 /* correct the passed in Mode mask. */
    132                 Mode &= ALLPERMS; /** @todo sticky bit and set uid/gid access validation... */
    133                 if (!(CurMode & ~ALLPERMS))
    134                     Mode |= S_IFREG;
    135                 else
    136                     Mode |= CurMode & ~ALLPERMS;
    137 
    138                 /* construct FEA2 stuff. */
    139                 #pragma pack(1)
    140                 struct __LIBC_FSUNIXATTRIBSSETMODE
    141                 {
    142                     ULONG   cbList;
    143                     ULONG   off;
    144                     BYTE    fEA;
    145                     BYTE    cbName;
    146                     USHORT  cbValue;
    147                     CHAR    szName[sizeof(EA_MODE)];
    148                     USHORT  usType;
    149                     USHORT  cbData;
    150                     uint32_t u32Mode;
    151                 } EAs =
    152                 {
    153                     sizeof(EAs), 0, 0, sizeof(EA_MODE) - 1, sizeof(uint32_t) + 4, EA_MODE, EAT_BINARY, sizeof(uint32_t), Mode
    154                 };
    155                 #pragma pack()
    156                 EAOP2 EaOp2;
    157                 EaOp2.fpGEA2List = NULL;
    158                 EaOp2.fpFEA2List = (PFEA2LIST)&EAs;
    159                 EaOp2.oError = 0;
    160 
    161                 if (!S_ISREG(Mode) && !S_ISDIR(Mode))
    162                     EAs.fEA = FEA_NEEDEA;
    163 
    164                 /* finally, try update / add the EA. */
    165                 rc = DosSetFileInfo(fh, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2));
    166                 if (__predict_false(rc != NO_ERROR))
    167                 {
    168                     LIBCLOG_ERROR("DosSetFileInfo(%d,,,,) -> %d, oError=%#lx\n", fh, rc, EaOp2.oError);
    169                     if (rc != ERROR_EAS_NOT_SUPPORTED && pFH->pszNativePath)
    170                     {
    171                         EaOp2.oError = 0;
    172                         int rc2 = DosSetPathInfo((PCSZ)pFH->pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0);
    173                         if (rc2)
    174                             LIBCLOG_ERROR("DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pFH->pszNativePath, rc2, EaOp2.oError);
    175                     }
    176                     if (rc == ERROR_EAS_NOT_SUPPORTED)
    177                         rc = 0;
    178                     else
    179                         rc = -__libc_native2errno(rc);
    180                 }
    181             }
    182 
    183             if (__predict_false(rc != 0))
    184             {
    185                 FS_RESTORE();
    186                 LIBCLOG_ERROR_RETURN_INT(rc);
    187             }
    188         }
    189 
    190         /*
    191          * Update OS/2 bits.
    192          */
    193         if (Mode & S_IWRITE)
    194             fsts3.attrFile &= ~FILE_READONLY;
    195         else
    196             fsts3.attrFile |= FILE_READONLY;
    197         rc = DosSetFileInfo(fh, FIL_STANDARD, &fsts3, sizeof(fsts3));
    198         FS_RESTORE();
     104        int fUnixEAs = !__libc_gfNoUnix
     105                    && pFH->pFsInfo
     106                    && pFH->pFsInfo->fUnixEAs;
     107        rc = __libc_back_fsNativeFileOwnerSetCommon(fh, pFH->pszNativePath, fUnixEAs, uid, gid);
    199108        if (rc)
    200109        {
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsNativeFileModeSet.c

    r3792 r3817  
    11/* $Id$ */
    22/** @file
    3  *
    43 * LIBC SYS Backend - internal [l]chmod.
    5  *
    6  * Copyright (c) 2005 knut st. osmundsen <bird@innotek.de>
     4 */
     5
     6/*
     7 * Copyright (c) 2005-2014 knut st. osmundsen <bird-src-spam@anduin.net>
    78 *
    89 *
     
    197198            };
    198199            #pragma pack()
    199             EAOP2 EaOp2;
    200             EaOp2.fpGEA2List = NULL;
    201             EaOp2.fpFEA2List = (PFEA2LIST)&EAs;
    202             EaOp2.oError = 0;
    203200
    204201            if (!S_ISREG(Mode) && !S_ISDIR(Mode))
     
    206203
    207204            /* finally, try update / add the EA. */
    208             rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0);
     205            EAOP2 EaOp2;
     206            rc = __libc_back_fsNativeSetEAs(-1, pszNativePath, (PFEA2LIST)&EAs, &EaOp2);
    209207            if (__predict_false(rc != NO_ERROR))
    210208            {
    211                 LIBCLOG_ERROR("DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError);
     209                LIBCLOG_ERROR("__libc_back_fsNativeSetEAs('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError);
    212210                if (rc == ERROR_EAS_NOT_SUPPORTED)
    213                     rc = 0;
     211                    rc = NO_ERROR;
    214212                else
    215213                    rc = -__libc_native2errno(rc);
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsNativeFileOwnerSet.c

    r3816 r3817  
    11/* $Id$ */
    22/** @file
    3  *
    4  * LIBC SYS Backend - internal [l]chmod.
    5  *
    6  * Copyright (c) 2005 knut st. osmundsen <bird@innotek.de>
     3 * kNIX - internal [l]chown, OS/2.
     4 */
     5
     6/*
     7 * Copyright (c) 2005-2014 knut st. osmundsen <bird-src-spam@anduin.net>
    78 *
    89 *
     
    4748
    4849/**
    49  * Sets the file access mode of a native file.
     50 * Sets the file ownership of a native file.
    5051 *
    5152 * @returns 0 on success.
    5253 * @returns Negative error code (errno.h) on failure.
    53  * @param   fh      Handle to file.
    54  * @param   Mode    The filemode.
    55  */
    56 int __libc_back_fsNativeFileModeSet(const char *pszNativePath, mode_t Mode)
     54 * @param   hNative         Native handle, -1 if only the path is available.
     55 * @param   pszNativePath   The native path.
     56 * @param   uid             The user id of the new owner, pass -1 to not change it.
     57 * @param   gid             The group id of the new group, pass -1 to not change it.
     58 */
     59int __libc_back_fsNativeFileOwnerSetCommon(intptr_t hNative, const char *pszNativePath, int fUnixEAs, uid_t uid, gid_t gid)
    5760{
    58     LIBCLOG_ENTER("pszNativePath=%p:{%s} Mode=%#x\n", (void *)pszNativePath, pszNativePath, Mode);
    59     union
     61    FS_VAR_SAVE_LOAD();
     62    int rc;
     63    if (fUnixEAs)
    6064    {
    61         FILESTATUS4     fsts4;
    62         FILESTATUS4L    fsts4L;
    63     } info;
     65        struct stat StOrg;
     66        memset(&StOrg, 0, sizeof(StOrg));
     67        rc = __libc_back_fsUnixAttribsGet(hNative, pszNativePath, &StOrg);
     68        if (__predict_true(!rc || rc == -ENOTSUP))
     69        {
     70            /** @todo check for permissions to change file ownership. */
     71            if (uid != (uid_t)-1 || gid != (gid_t)-1)
     72            {
     73                /* construct FEA2 stuff. */
     74                #pragma pack(1)
     75                struct __LIBC_FSUNIXATTRIBSSETOWNER
     76                {
     77                    ULONG   cbList;
     78
     79                    ULONG   offUid;
     80                    BYTE    fUidEA;
     81                    BYTE    cbUidName;
     82                    USHORT  cbUidValue;
     83                    CHAR    szUidName[sizeof(EA_UID)];
     84                    USHORT  usUidType;
     85                    USHORT  cbUidData;
     86                    uint32_t u32Uid;
     87                    CHAR    achUidAlign[((sizeof(EA_UID) + 4) & ~3) - sizeof(EA_UID)];
     88
     89                    ULONG   offGid;
     90                    BYTE    fGidEA;
     91                    BYTE    cbGidName;
     92                    USHORT  usGidValue;
     93                    CHAR    szGidName[sizeof(EA_GID)];
     94                    USHORT  usGidType;
     95                    USHORT  cbGidData;
     96                    uint32_t u32Gid;
     97                    CHAR    achGidAlign[((sizeof(EA_GID) + 4) & ~3) - sizeof(EA_GID)];
     98                } EAs =
     99                {
     100                    sizeof(EAs),
     101
     102                    /* .offUid      =*/ offsetof(struct __LIBC_FSUNIXATTRIBSSETOWNER, offGid)
     103                                      - offsetof(struct __LIBC_FSUNIXATTRIBSSETOWNER, offUid),
     104                    /* .fUidEA      =*/ 0,
     105                    /* .cbUidName   =*/ sizeof(EA_UID) - 1,
     106                    /* .cbUidValue  =*/ sizeof(uint32_t) + 4,
     107                    /* .szUidName   =*/ EA_UID,
     108                    /* .usUidType   =*/ EAT_BINARY,
     109                    /* .cbUidData   =*/ sizeof(uint32_t),
     110                    /* .u32Uid      =*/ uid != (uid_t)-1 ? uid : StOrg.st_uid,
     111                    /* .achUidAlign =*/ "",
     112
     113                    /* .offGid      =*/ 0,
     114                    /* .fGidEA      =*/ 0,
     115                    /* .cbGidName   =*/ sizeof(EA_GID) - 1,
     116                    /* .cbGidValue  =*/ sizeof(uint32_t) + 4,
     117                    /* .szGidName   =*/ EA_GID,
     118                    /* .usGidType   =*/ EAT_BINARY,
     119                    /* .cbGidData   =*/ sizeof(uint32_t),
     120                    /* .u32Gid      =*/ gid != (gid_t)-1 ? gid : StOrg.st_gid,
     121                    /* .achGidAlign =*/ "",
     122                };
     123                #pragma pack()
     124
     125                if (uid != -1 && uid != 0)
     126                    EAs.fUidEA = FEA_NEEDEA;
     127                if (gid != -1 && gid != 0)
     128                    EAs.fGidEA = FEA_NEEDEA;
     129
     130                EAOP2 EaOp2;
     131                rc = __libc_back_fsNativeSetEAs(hNative, pszNativePath, (PFEA2LIST)&EAs, &EaOp2);
     132                if (__predict_false(rc != NO_ERROR))
     133                {
     134                    LIBCLOG_ERROR2("__libc_back_fsNativeSetEAs('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError);
     135                    if (   rc == ERROR_EAS_NOT_SUPPORTED
     136                        && (uid == -1 || uid == 0)
     137                        && (gid == -1 || gid == 0))
     138                        rc = 0;
     139                    else
     140                        rc = -__libc_back_native2errno(rc);
     141                }
     142            }
     143            else
     144                rc = 0; /* No change and thus no not-supported complaints. */
     145        }
     146    }
     147    else
     148    {
     149        /*
     150         * In this mode we'll simply check if the file exists and return the
     151         * appropriate errors if it doesn't or we cannot access it.
     152         */
     153        union
     154        {
     155            FILESTATUS4     fsts4;
     156            FILESTATUS4L    fsts4L;
     157        } info;
     158
    64159#if OFF_MAX > LONG_MAX
    65     int     fLarge = 0;
     160        if (__libc_gpfnDosOpenL)
     161            rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList));
     162        else
    66163#endif
    67     FS_VAR();
     164            rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList));
     165
     166        if (rc != NO_ERROR)
     167            rc = -__libc_back_native2errno(rc);
     168    }
     169    FS_RESTORE();
     170    return rc;
     171}
     172
     173
     174/**
     175 * Sets the file ownership of a native file.
     176 *
     177 * @returns 0 on success.
     178 * @returns Negative error code (errno.h) on failure.
     179 * @param   pszNativePath   The native path.
     180 * @param   uid             The user id of the new owner, pass -1 to not change it.
     181 * @param   gid             The group id of the new group, pass -1 to not change it.
     182 */
     183int __libc_back_fsNativeFileOwnerSet(const char *pszNativePath, uid_t uid, gid_t gid)
     184{
     185    LIBCLOG_ENTER("pszNativePath=%p:{%s} uid=%ld gid=%ld\n", (void *)pszNativePath, pszNativePath, (long)uid, (long)gid);
    68186
    69187    /*
     
    85203
    86204    /*
    87      * Get path info.
     205     * Join paths with the file handle base code path.
    88206     */
    89     FS_SAVE_LOAD();
    90     int rc;
    91     const int fUnixEAs = __libc_back_fsInfoSupportUnixEAs(pszNativePath);
    92     if (fUnixEAs)
    93     {
    94 #if OFF_MAX > LONG_MAX
    95         if (__libc_gpfnDosOpenL)
    96         {
    97             rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
    98             fLarge = 1;
    99         }
    100         else
    101 #endif
    102             rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
    103         /* If the file is open in write mode, we cannot even get the EA size. stupid.
    104          * It'll fail with ERROR_SHARING_VIOLATION, which we handle rigth below. */
    105     }
    106     else
    107         rc = ERROR_SHARING_VIOLATION; /* take the fallback path if we don't want EAs. */
    108     if (rc == ERROR_SHARING_VIOLATION)
    109     {
    110 #if OFF_MAX > LONG_MAX
    111         if (__libc_gpfnDosOpenL)
    112         {
    113             rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList));
    114             fLarge = 1;
    115         }
    116         else
    117 #endif
    118             rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList));
    119         info.fsts4L.cbList = LIBC_UNIX_EA_MIN;
    120     }
    121     if (rc)
    122     {
    123         rc = -__libc_native2errno(rc);
    124         FS_RESTORE();
     207    int rc = __libc_back_fsNativeFileOwnerSetCommon(-1, pszNativePath, __libc_back_fsInfoSupportUnixEAs(pszNativePath), uid, gid);
     208    if (__predict_false(rc != 0))
    125209        LIBCLOG_ERROR_RETURN_INT(rc);
    126     }
    127 
    128     /*
    129      * Update OS/2 attributes.
    130      */
    131 #if OFF_MAX > LONG_MAX
    132     if (fLarge)
    133     {
    134         if (Mode & S_IWRITE)
    135             info.fsts4L.attrFile &= ~FILE_READONLY;
    136         else
    137             info.fsts4L.attrFile = FILE_READONLY;
    138         rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList), 0);
    139     }
    140     else
    141 #endif
    142     {
    143         if (Mode & S_IWRITE)
    144             info.fsts4.attrFile &= ~FILE_READONLY;
    145         else
    146             info.fsts4.attrFile |= FILE_READONLY;
    147         rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList), 0);
    148     }
    149     if (__predict_false(rc != NO_ERROR))
    150     {
    151         FS_RESTORE();
    152         rc = -__libc_native2errno(rc);
    153         LIBCLOG_ERROR_RETURN_INT(rc);
    154     }
    155 
    156     /*
    157      * If in unix mode we'll have to update/add the MODE too.
    158      */
    159     if (fUnixEAs)
    160     {
    161         mode_t CurMode;
    162         rc = __libc_back_fsUnixAttribsGetMode(-1, pszNativePath, &CurMode);
    163         if (__predict_true(!rc || rc == -ENOTSUP))
    164         {
    165             /* correct the passed in Mode mask. */
    166             Mode &= ALLPERMS; /** @todo sticky bit and set uid/gid access validation... */
    167             if (!(CurMode & ~ALLPERMS))
    168             {
    169 #if OFF_MAX > LONG_MAX
    170                 if ((fLarge ? info.fsts4L.attrFile : info.fsts4.attrFile) & FILE_DIRECTORY)
    171 #else
    172                 if (info.fsts4.attrFile & FILE_DIRECTORY)
    173 #endif
    174                     Mode |= S_IFDIR;
    175                 else
    176                     Mode |= S_IFREG;
    177             }
    178             else
    179                 Mode |= CurMode & ~ALLPERMS;
    180 
    181             /* construct FEA2 stuff. */
    182             #pragma pack(1)
    183             struct __LIBC_FSUNIXATTRIBSSETMODE
    184             {
    185                 ULONG   cbList;
    186                 ULONG   off;
    187                 BYTE    fEA;
    188                 BYTE    cbName;
    189                 USHORT  cbValue;
    190                 CHAR    szName[sizeof(EA_MODE)];
    191                 USHORT  usType;
    192                 USHORT  cbData;
    193                 uint32_t u32Mode;
    194             } EAs =
    195             {
    196                 sizeof(EAs), 0, 0, sizeof(EA_MODE) - 1, sizeof(uint32_t) + 4, EA_MODE, EAT_BINARY, sizeof(uint32_t), Mode
    197             };
    198             #pragma pack()
    199             EAOP2 EaOp2;
    200             EaOp2.fpGEA2List = NULL;
    201             EaOp2.fpFEA2List = (PFEA2LIST)&EAs;
    202             EaOp2.oError = 0;
    203 
    204             if (!S_ISREG(Mode) && !S_ISDIR(Mode))
    205                 EAs.fEA = FEA_NEEDEA;
    206 
    207             /* finally, try update / add the EA. */
    208             rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0);
    209             if (__predict_false(rc != NO_ERROR))
    210             {
    211                 LIBCLOG_ERROR("DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError);
    212                 if (rc == ERROR_EAS_NOT_SUPPORTED)
    213                     rc = 0;
    214                 else
    215                     rc = -__libc_native2errno(rc);
    216             }
    217         }
    218 
    219         if (__predict_false(rc != 0))
    220         {
    221             FS_RESTORE();
    222             LIBCLOG_ERROR_RETURN_INT(rc);
    223         }
    224     }
    225     FS_RESTORE();
    226210
    227211    LIBCLOG_RETURN_INT(0);
  • branches/libc-0.6/src/emx/src/lib/sys/b_fsSymlinkOwnerSet.c

    r3816 r3817  
    11/* $Id$ */
    22/** @file
    3  *
    4  * LIBC SYS Backend - lstat.
    5  *
    6  * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>
     3 * kNIX - lchown.
     4 */
     5
     6/*
     7 * Copyright (c) 2004-2014 knut st. osmundsen <bird-src-spam@anduin.net>
    78 *
    89 *
     
    3031*******************************************************************************/
    3132#include "b_fs.h"
    32 #include <sys/stat.h>
    3333#include <InnoTekLIBC/backend.h>
    3434#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_FS
     
    3737
    3838/**
    39  * Stats a symbolic link.
     39 * Changes the ownership and/or group, without following any final symlink.
    4040 *
    4141 * @returns 0 on success.
    4242 * @returns Negative error code (errno.h) on failure.
    43  * @param   pszPath     Path to the file to stat. If this is a symbolic link
    44  *                      the link it self will be stat'ed.
    45  * @param   pStat       Where to store the file stats.
     43 * @param   pszPath     Path to the file to modify ownership of.  If this is a
     44 *                      symbolic link, the link it self will modified.
     45 * @param   uid         The user id of the new owner, pass -1 to not change it.
     46 * @param   gid         The group id of the new group, pass -1 to not change it.
    4647 */
    47 int __libc_Back_fsSymlinkStat(const char *pszPath, struct stat *pStat)
     48int __libc_Back_fsSymlinkOwnerSet(const char *pszPath, uid_t uid, gid_t gid)
    4849{
    49     LIBCLOG_ENTER("pszPath=%p:{%s} pStat=%p\n", (void *)pszPath, pszPath, (void *)pStat);
     50    LIBCLOG_ENTER("pszPath=%p:{%s} %ld %ld\n", (void *)pszPath, pszPath, (long)uid, (long)gid);
    5051
    5152    /*
     
    5556    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL);
    5657    if (!rc)
    57         rc = __libc_back_fsNativeFileStat(szNativePath, pStat);
     58        rc = __libc_back_fsNativeFileOwnerSet(szNativePath, uid, gid);
    5859
    5960    if (!rc)
  • branches/libc-0.6/src/emx/src/lib/sys/fs.c

    r3792 r3817  
    44 * LIBC SYS Backend - file system stuff.
    55 *
    6  * Copyright (c) 2004-2005 knut st. osmundsen <bird@innotek.de>
     6 * Copyright (c) 2004-2014 knut st. osmundsen <bird@innotek.de>
    77 *
    88 *
     
    860860 *
    861861 * @returns 0 on success.
    862  * @returns Negative error code (errno.h) on failiure.
     862 * @returns Negative error code (errno.h) on failure.
    863863 * @param   pszUserPath     The user path.
    864864 * @parm    fFlags          Flags controlling the operation of the function.
     
    18251825
    18261826     LIBCLOG_RETURN_MSG(rc, "ret %d *pMode=#%x\n", rc, *pMode);
     1827}
     1828
     1829
     1830/**
     1831 * Helper path and handle based native functions for writing EAs.
     1832 *
     1833 * This tries to work around sharing issues as well as trying to use
     1834 * fchmod/fchown on handles opened without write access.
     1835 *
     1836 * @returns Native status code.
     1837 * @param   hNative         The native handle, -1 if not available.
     1838 * @param   pszNativePath   The native path.
     1839 * @param   pEAs            The list of EAs to set.
     1840 * @param   pEaOp2          The EA operation 2 buffer to use.  This is passed in
     1841 *                          as a parameter so that the calling code can access
     1842 *                          error information.
     1843 */
     1844int __libc_back_fsNativeSetEAs(intptr_t hNative, const char *pszNativePath, PFEA2LIST pEAs, PEAOP2 pEaOp2)
     1845{
     1846    /*
     1847     * First copy the EAs so we can do a retry with a different access path.
     1848     */
     1849    PFEA2LIST pCopyEAs = (PFEA2LIST)alloca(pEAs->cbList);
     1850    memcpy(pCopyEAs, pEAs, pEAs->cbList);
     1851
     1852    /*
     1853     * First try.
     1854     */
     1855    APIRET rc;
     1856    pEaOp2->fpGEA2List = NULL;
     1857    pEaOp2->fpFEA2List = pEAs;
     1858    pEaOp2->oError     = 0;
     1859    if (hNative != -1)
     1860        rc = DosSetFileInfo(hNative, FIL_QUERYEASIZE, pEaOp2, sizeof(*pEaOp2));
     1861    else
     1862        rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, pEaOp2, sizeof(*pEaOp2), 0);
     1863
     1864    if (   (   rc == ERROR_SHARING_VIOLATION
     1865            || rc == ERROR_ACCESS_DENIED)
     1866        && pszNativePath
     1867        && pszNativePath[0])
     1868    {
     1869        /*
     1870         * To write EAs using DosSetPathInfo, the system requires deny-all
     1871         * access, but when using DosSetFileInfo we're seemingly free to choose
     1872         * this ourselves. So, try open the file with write access and retry.
     1873         */
     1874        APIRET rc2;
     1875        HFILE  hFile2      = (HFILE)-1;
     1876        ULONG  ulAction    = 0;
     1877        ULONG  flOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
     1878        ULONG  flOpenMode  = OPEN_ACCESS_WRITEONLY | OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE;
     1879
     1880#if OFF_MAX > LONG_MAX
     1881        if (__libc_gpfnDosOpenL)
     1882            rc2 = __libc_gpfnDosOpenL((PCSZ)pszNativePath, &hFile2, &ulAction, 0, FILE_NORMAL, flOpenFlags, flOpenMode, NULL);
     1883        else
     1884#endif
     1885            rc2 = DosOpen((PCSZ)pszNativePath, &hFile2, &ulAction, 0, FILE_NORMAL, flOpenFlags, flOpenMode, NULL);
     1886    if (rc2 == NO_ERROR)
     1887    {
     1888            memcpy(pEAs, pCopyEAs, pCopyEAs->cbList);
     1889            pEaOp2->fpGEA2List = NULL;
     1890            pEaOp2->fpFEA2List = pEAs;
     1891            pEaOp2->oError     = 0;
     1892            rc = DosSetFileInfo(hFile2, FIL_QUERYEASIZE, pEaOp2, sizeof(*pEaOp2));
     1893
     1894            DosClose(hFile2);
     1895        }
     1896    }
     1897
     1898    return rc;
    18271899}
    18281900
Note: See TracChangeset for help on using the changeset viewer.