Changeset 3817
- Timestamp:
- Feb 19, 2014, 2:40:34 AM (11 years ago)
- 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
-
Property svn:mergeinfo
set to
/trunk/libc/include/InnoTekLIBC/backend.h merged eligible /trunk/libc/include/klibc/backend.h merged eligible
r3811 r3817 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * 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> 8 8 * 9 9 * This file is part of InnoTek LIBC. … … 337 337 338 338 /** 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 */ 348 int __libc_Back_fsSymlinkOwnerSet(const char *pszPath, uid_t uid, gid_t gid); 349 350 /** 339 351 * Stats a file. 340 352 * … … 396 408 */ 397 409 int __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 */ 420 int __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 */ 431 int __libc_Back_fsFileOwnerSetFH(int fh, uid_t uid, gid_t gid); 398 432 399 433 /** -
Property svn:mergeinfo
set to
-
branches/libc-0.6/src/emx/src/lib/io
-
Property svn:mergeinfo
set to
/trunk/libc/src/libc/io merged eligible
-
Property svn:mergeinfo
set to
-
branches/libc-0.6/src/emx/src/lib/io/fchown.c
r2254 r3817 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * 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> 7 8 * 8 9 * … … 26 27 27 28 28 29 29 /******************************************************************************* 30 30 * Header Files * 31 31 *******************************************************************************/ 32 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO 32 33 #include "libc-alias.h" 33 34 #include <unistd.h> 34 #include <e mx/io.h>35 # define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO35 #include <errno.h> 36 #include <InnoTekLIBC/backend.h> 36 37 #include <InnoTekLIBC/logstrict.h> 37 38 38 39 39 40 40 /** 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. 44 42 * 45 43 * @returns 0 on success. 46 44 * @returns -1 and errno on failure. 47 45 * @param fh Handle to the file. 48 * @param owner Owner id.49 * @param g roup 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. 50 48 */ 51 int _STD(fchown)(int fh, uid_t owner, gid_t group)49 int _STD(fchown)(int fh, uid_t uid, gid_t gid) 52 50 { 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) 56 54 LIBCLOG_RETURN_INT(0); 55 errno = -rc; 57 56 LIBCLOG_ERROR_RETURN_INT(-1); 58 57 } -
branches/libc-0.6/src/emx/src/lib/io/lchown.c
r2254 r3817 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * 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> 7 8 * 8 9 * … … 26 27 27 28 28 29 29 /******************************************************************************* 30 30 * Header Files * 31 31 *******************************************************************************/ 32 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO 32 33 #include "libc-alias.h" 33 34 #include <unistd.h> 34 #include < sys/stat.h>35 # define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO35 #include <errno.h> 36 #include <InnoTekLIBC/backend.h> 36 37 #include <InnoTekLIBC/logstrict.h> 37 38 38 39 39 40 40 /** 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. 44 42 * 45 43 * @returns 0 on success. 46 44 * @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. 50 49 */ 51 int _STD(lchown)(const char *p ath, uid_t owner, gid_t group)50 int _STD(lchown)(const char *pszPath, uid_t uid, gid_t gid) 52 51 { 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); 56 54 if (!rc) 57 55 LIBCLOG_RETURN_INT(0); 56 errno = -rc; 58 57 LIBCLOG_ERROR_RETURN_INT(-1); 59 58 } -
branches/libc-0.6/src/emx/src/lib/misc
- Property svn:mergeinfo changed
/trunk/libc/src/libc/misc merged: 3816
- Property svn:mergeinfo changed
-
branches/libc-0.6/src/emx/src/lib/misc/chown.c
r2254 r3817 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * 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> 7 8 * 8 9 * … … 26 27 27 28 28 29 29 /******************************************************************************* 30 30 * Header Files * 31 31 *******************************************************************************/ 32 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO 32 33 #include "libc-alias.h" 33 34 #include <unistd.h> 34 #include < sys/stat.h>35 # define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO35 #include <errno.h> 36 #include <InnoTekLIBC/backend.h> 36 37 #include <InnoTekLIBC/logstrict.h> 37 38 38 39 39 40 40 /** 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. 44 42 * 45 43 * @returns 0 on success. 46 44 * @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. 50 49 */ 51 int _STD(chown)(const char *p ath, uid_t owner, gid_t group)50 int _STD(chown)(const char *pszPath, uid_t uid, gid_t gid) 52 51 { 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); 56 54 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); 59 58 } 60 59 -
branches/libc-0.6/src/emx/src/lib/sys/b_fs.h
r3695 r3817 404 404 int __libc_back_fsNativeFileTimesSet(const char *pszNativePath, const struct timeval *paTimes); 405 405 406 int __libc_back_fsNativeFileOwnerSet(const char *pszNativePath, uid_t uid, gid_t gid); 407 int __libc_back_fsNativeFileOwnerSetCommon(intptr_t hNative, const char *pszNativePath, int fUnixEAs, uid_t uid, gid_t gid); 408 int __libc_back_fsNativeSetEAs(intptr_t hNative, const char *pszNativePath, struct _FEA2LIST *pEAs, struct _EAOP2 *pEaOp2); 409 406 410 /** 407 411 * Calc the Inode and Dev based on native path. -
branches/libc-0.6/src/emx/src/lib/sys/b_fsFileOwnerSet.c
r3816 r3817 1 1 /* $Id$ */ 2 2 /** @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> 7 8 * 8 9 * … … 30 31 *******************************************************************************/ 31 32 #include "b_fs.h" 32 #include <sys/stat.h>33 33 #include <InnoTekLIBC/backend.h> 34 34 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_FS … … 37 37 38 38 /** 39 * Stats a symbolic link.39 * Changes the ownership and/or group of a file or directory. 40 40 * 41 41 * @returns 0 on success. 42 42 * @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. 46 47 */ 47 int __libc_Back_fs SymlinkStat(const char *pszPath, struct stat *pStat)48 int __libc_Back_fsFileOwnerSet(const char *pszPath, uid_t uid, gid_t gid) 48 49 { 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); 50 51 51 52 /* … … 53 54 */ 54 55 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); 56 58 if (!rc) 57 rc = __libc_back_fsNativeFile Stat(szNativePath, pStat);59 rc = __libc_back_fsNativeFileOwnerSet(szNativePath, uid, gid); 58 60 59 61 if (!rc) -
branches/libc-0.6/src/emx/src/lib/sys/b_fsFileOwnerSetFH.c
r3816 r3817 1 1 /* $Id$ */ 2 2 /** @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> 7 8 * 8 9 * … … 51 52 52 53 /** 53 * Sets the file access modeof a file by filehandle.54 * Sets the file ownership of a file by filehandle. 54 55 * 55 56 * @returns 0 on success. 56 57 * @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. 59 61 */ 60 int __libc_Back_fsFile ModeSetFH(int fh, mode_t Mode)62 int __libc_Back_fsFileOwnerSetFH(int fh, uid_t uid, gid_t gid) 61 63 { 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); 63 65 64 66 /* … … 87 89 if (__predict_false(!pFH->pszNativePath)) 88 90 LIBCLOG_ERROR_RETURN_INT(-EINVAL); 89 rc = __libc_back_fsNativeFile ModeSet(pFH->pszNativePath, Mode);91 rc = __libc_back_fsNativeFileOwner(pFH->pszNativePath, uid, gid); 90 92 if (rc) 91 93 LIBCLOG_ERROR_RETURN_INT(rc); … … 100 102 if (!pFH->pOps) 101 103 { 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); 199 108 if (rc) 200 109 { -
branches/libc-0.6/src/emx/src/lib/sys/b_fsNativeFileModeSet.c
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/libc/src/kNIX/os2/b_fsNativeFileModeSet.c merged eligible /trunk/libc/src/kNIX/b_fsNativeFileModeSet.c 3768
r3792 r3817 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * 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> 7 8 * 8 9 * … … 197 198 }; 198 199 #pragma pack() 199 EAOP2 EaOp2;200 EaOp2.fpGEA2List = NULL;201 EaOp2.fpFEA2List = (PFEA2LIST)&EAs;202 EaOp2.oError = 0;203 200 204 201 if (!S_ISREG(Mode) && !S_ISDIR(Mode)) … … 206 203 207 204 /* 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); 209 207 if (__predict_false(rc != NO_ERROR)) 210 208 { 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); 212 210 if (rc == ERROR_EAS_NOT_SUPPORTED) 213 rc = 0;211 rc = NO_ERROR; 214 212 else 215 213 rc = -__libc_native2errno(rc); -
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/libc-0.6/src/emx/src/lib/sys/b_fsNativeFileOwnerSet.c
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/libc/src/kNIX/os2/b_fsNativeFileModeSet.c merged eligible /trunk/libc/src/kNIX/b_fsNativeFileModeSet.c 3768
r3816 r3817 1 1 /* $Id$ */ 2 2 /** @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> 7 8 * 8 9 * … … 47 48 48 49 /** 49 * Sets the file access modeof a native file.50 * Sets the file ownership of a native file. 50 51 * 51 52 * @returns 0 on success. 52 53 * @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 */ 59 int __libc_back_fsNativeFileOwnerSetCommon(intptr_t hNative, const char *pszNativePath, int fUnixEAs, uid_t uid, gid_t gid) 57 60 { 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) 60 64 { 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 64 159 #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 66 163 #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 */ 183 int __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); 68 186 69 187 /* … … 85 203 86 204 /* 87 * Get path info.205 * Join paths with the file handle base code path. 88 206 */ 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)) 125 209 LIBCLOG_ERROR_RETURN_INT(rc); 126 }127 128 /*129 * Update OS/2 attributes.130 */131 #if OFF_MAX > LONG_MAX132 if (fLarge)133 {134 if (Mode & S_IWRITE)135 info.fsts4L.attrFile &= ~FILE_READONLY;136 else137 info.fsts4L.attrFile = FILE_READONLY;138 rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList), 0);139 }140 else141 #endif142 {143 if (Mode & S_IWRITE)144 info.fsts4.attrFile &= ~FILE_READONLY;145 else146 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_MAX170 if ((fLarge ? info.fsts4L.attrFile : info.fsts4.attrFile) & FILE_DIRECTORY)171 #else172 if (info.fsts4.attrFile & FILE_DIRECTORY)173 #endif174 Mode |= S_IFDIR;175 else176 Mode |= S_IFREG;177 }178 else179 Mode |= CurMode & ~ALLPERMS;180 181 /* construct FEA2 stuff. */182 #pragma pack(1)183 struct __LIBC_FSUNIXATTRIBSSETMODE184 {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), Mode197 };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 else215 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();226 210 227 211 LIBCLOG_RETURN_INT(0); -
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/libc-0.6/src/emx/src/lib/sys/b_fsSymlinkOwnerSet.c
r3816 r3817 1 1 /* $Id$ */ 2 2 /** @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> 7 8 * 8 9 * … … 30 31 *******************************************************************************/ 31 32 #include "b_fs.h" 32 #include <sys/stat.h>33 33 #include <InnoTekLIBC/backend.h> 34 34 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_FS … … 37 37 38 38 /** 39 * Stats a symboliclink.39 * Changes the ownership and/or group, without following any final symlink. 40 40 * 41 41 * @returns 0 on success. 42 42 * @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. 46 47 */ 47 int __libc_Back_fsSymlink Stat(const char *pszPath, struct stat *pStat)48 int __libc_Back_fsSymlinkOwnerSet(const char *pszPath, uid_t uid, gid_t gid) 48 49 { 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); 50 51 51 52 /* … … 55 56 int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL); 56 57 if (!rc) 57 rc = __libc_back_fsNativeFile Stat(szNativePath, pStat);58 rc = __libc_back_fsNativeFileOwnerSet(szNativePath, uid, gid); 58 59 59 60 if (!rc) -
branches/libc-0.6/src/emx/src/lib/sys/fs.c
r3792 r3817 4 4 * LIBC SYS Backend - file system stuff. 5 5 * 6 * Copyright (c) 2004-20 05knut st. osmundsen <bird@innotek.de>6 * Copyright (c) 2004-2014 knut st. osmundsen <bird@innotek.de> 7 7 * 8 8 * … … 860 860 * 861 861 * @returns 0 on success. 862 * @returns Negative error code (errno.h) on fail iure.862 * @returns Negative error code (errno.h) on failure. 863 863 * @param pszUserPath The user path. 864 864 * @parm fFlags Flags controlling the operation of the function. … … 1825 1825 1826 1826 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 */ 1844 int __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; 1827 1899 } 1828 1900
Note:
See TracChangeset
for help on using the changeset viewer.