Changeset 3816
- Timestamp:
- Feb 19, 2014, 12:06:45 AM (11 years ago)
- Location:
- trunk/libc
- Files:
-
- 11 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/include/klibc/backend.h
r3811 r3816 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * kLIBC - Backend header. 5 * 6 * Copyright (c) 2004-2006 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 * … … 163 164 164 165 165 /** @defgroup __libc_Back_f skLIBC Backend - File Handle166 /** @defgroup __libc_Back_fh kLIBC Backend - File Handle 166 167 * @{ */ 167 168 … … 412 413 413 414 /** 415 * Changes the ownership and/or group, without following any final symlink. 416 * 417 * @returns 0 on success. 418 * @returns Negative error code (errno.h) on failure. 419 * @param pszPath Path to the file to modify ownership of. If this is a 420 * symbolic link, the link it self will modified. 421 * @param uid The user id of the new owner, pass -1 to not change it. 422 * @param gid The group id of the new group, pass -1 to not change it. 423 */ 424 int __libc_Back_fsSymlinkOwnerSet(const char *pszPath, uid_t uid, gid_t gid); 425 426 /** 414 427 * Stats a file. 415 428 * … … 472 485 */ 473 486 int __libc_Back_fsFileTimesSetFH(int fh, const struct timeval *paTimes); 487 488 /** 489 * Changes the ownership and/or group, following all symbolic links. 490 * 491 * @returns 0 on success. 492 * @returns Negative error code (errno.h) on failure. 493 * @param pszPath Path to the file to modify ownership of. 494 * @param uid The user id of the new owner, pass -1 to not change it. 495 * @param gid The group id of the new group, pass -1 to not change it. 496 */ 497 int __libc_Back_fsFileOwnerSet(const char *pszPath, uid_t uid, gid_t gid); 498 499 /** 500 * Changes the ownership and/or group. 501 * 502 * @returns 0 on success. 503 * @returns Negative error code (errno.h) on failure. 504 * @param fh Handle to file. 505 * @param uid The user id of the new owner, pass -1 to not change it. 506 * @param gid The group id of the new group, pass -1 to not change it. 507 */ 508 int __libc_Back_fsFileOwnerSetFH(int fh, uid_t uid, gid_t gid); 474 509 475 510 /** -
trunk/libc/include/klibc/io.h
r3689 r3816 1 1 /* $Id: $ */ 2 2 /** @file 3 *4 3 * kLIBC I/O 5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird@innotek.de> 4 */ 5 6 /* 7 * Copyright (c) 2006-2014 knut st. osmundsen <bird-src-spam@anduin.net> 7 8 * 8 9 * … … 242 243 * @returns Negated error code (errno.h) on failure. 243 244 * @param pFH Pointer to the handle structure to operate on. 244 * @param uid The id of the new owner. 245 */ 246 int (*pfnSetOwner)(struct __libc_FileHandle *pFH, uid_t uid); 245 * @param uid The id of the new owner, -1 if not to be changed. 246 * @param gid The id of the new owner group, if no change, 247 */ 248 int (*pfnSetOwner)(struct __libc_FileHandle *pFH, uid_t uid, gid_t gid); 247 249 248 250 /** -
trunk/libc/src/kNIX/Makefile.kmk
r3687 r3816 1 1 # $Id$ 2 2 ## @file 3 #4 3 # kBuild Sub-Makefile for kLIBC - src/libc/sys. 5 4 # 6 # Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net> 5 6 # 7 # Copyright (c) 2006-2014 knut st. osmundsen <bird-src-spam@anduin.net> 7 8 # 8 9 # … … 41 42 $(PATH_LIBC_SRC)/kNIX/b_fsPathResolve.c \ 42 43 $(PATH_LIBC_SRC)/kNIX/b_fsSymlinkModeSet.c \ 44 $(PATH_LIBC_SRC)/kNIX/b_fsSymlinkOwnerSet.c \ 43 45 $(PATH_LIBC_SRC)/kNIX/b_fsSymlinkCreate.c \ 44 46 $(PATH_LIBC_SRC)/kNIX/b_fsFileTimesSet.c \ … … 47 49 $(PATH_LIBC_SRC)/kNIX/b_fsFileModeSet.c \ 48 50 $(PATH_LIBC_SRC)/kNIX/b_fsFileModeSetFH.c \ 51 $(PATH_LIBC_SRC)/kNIX/b_fsFileOwnerSet.c \ 52 $(PATH_LIBC_SRC)/kNIX/b_fsFileOwnerSetFH.c \ 49 53 $(PATH_LIBC_SRC)/kNIX/b_fsFileStat.c \ 50 54 $(PATH_LIBC_SRC)/kNIX/b_fsFileStatFH.c \ … … 98 102 $(PATH_LIBC_SRC)/kNIX/os2/b_fsDriveDefaultSet.c \ 99 103 $(PATH_LIBC_SRC)/kNIX/os2/b_fsNativeFileModeSet.c \ 104 $(PATH_LIBC_SRC)/kNIX/os2/b_fsNativeFileOwnerSet.c \ 100 105 $(PATH_LIBC_SRC)/kNIX/os2/b_fsNativeFileStat.c \ 101 106 $(PATH_LIBC_SRC)/kNIX/os2/b_fsNativeFileTimesSet.c \ -
trunk/libc/src/kNIX/b_fsFileOwnerSet.c
r3807 r3816 1 1 /* $Id$ */ 2 2 /** @file 3 * 4 * kNIX - lstat. 5 * 6 * Copyright (c) 2004 knut st. osmundsen <bird-src-spam@anduin.net> 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 /** 32 * Stats a symboliclink.33 * Changes the ownership and/or group, without following any final symlink. 33 34 * 34 35 * @returns 0 on success. 35 36 * @returns Negative error code (errno.h) on failure. 36 * @param pszPath Path to the file to stat. If this is a symbolic link 37 * the link it self will be stat'ed. 38 * @param pStat Where to store the file stats. 37 * @param pszPath Path to the file to modify ownership of. If this is a 38 * symbolic link, the link it self will modified. 39 * @param uid The user id of the new owner, pass -1 to not change it. 40 * @param gid The group id of the new group, pass -1 to not change it. 39 41 */ 40 int __libc_Back_fs SymlinkStat(const char *pszPath, struct stat *pStat)42 int __libc_Back_fsFileOwnerSet(const char *pszPath, uid_t uid, gid_t gid) 41 43 { 42 LIBCLOG_ENTER("pszPath=%p:{%s} pStat=%p\n", (void *)pszPath, pszPath, (void *)pStat);44 LIBCLOG_ENTER("pszPath=%p:{%s} %ld %ld\n", (void *)pszPath, pszPath, (long)uid, (long)gid); 43 45 44 46 /* … … 46 48 */ 47 49 char szNativePath[PATH_MAX]; 48 int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL); 50 int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, 51 szNativePath, NULL); 49 52 if (!rc) 50 rc = __libc_back_fsNativeFile Stat(szNativePath, pStat);53 rc = __libc_back_fsNativeFileOwnerSet(szNativePath, uid, gid); 51 54 52 55 if (!rc) -
trunk/libc/src/kNIX/b_fsFileOwnerSetFH.c
r3807 r3816 1 1 /* $Id$ */ 2 2 /** @file 3 * 4 * kNIX - fchmod(). 5 * 6 * Copyright (c) 2005-2006 knut st. osmundsen <bird-src-spam@anduin.net> 3 * kNIX - fchown(). 4 */ 5 6 /* 7 * Copyright (c) 2005-2014 knut st. osmundsen <bird-src-spam@anduin.net> 7 8 * 8 9 * … … 31 32 32 33 /** 33 * Sets the file access modeof a file by filehandle.34 * Sets the file ownership of a file by filehandle. 34 35 * 35 36 * @returns 0 on success. 36 37 * @returns Negative error code (errno.h) on failure. 37 * @param fh Handle to file. 38 * @param fMode The filemode. 38 * @param fh Handle to file. 39 * @param uid The user id of the new owner, pass -1 to not change it. 40 * @param gid The group id of the new group, pass -1 to not change it. 39 41 */ 40 int __libc_Back_fsFile ModeSetFH(int fh, mode_t fMode)42 int __libc_Back_fsFileOwnerSetFH(int fh, uid_t uid, gid_t gid) 41 43 { 42 LIBCLOG_ENTER("fh=%d fMode=%#o (%#x)\n", fh, fMode, fMode);44 LIBCLOG_ENTER("fh=%d uid=%ld gid=%ld\n", fh, (long)uid, (long)gid); 43 45 44 46 /* … … 52 54 * If supported, do handle operation, otherwise predend it's a pipe (see SuS). 53 55 */ 54 if (pFH->pOps->pfnSet Mode)55 rc = pFH->pOps->pfnSet Mode(pFH, fMode);56 if (pFH->pOps->pfnSetOwner) 57 rc = pFH->pOps->pfnSetOwner(pFH, uid, gid); 56 58 else 57 59 rc = EINVAL; … … 61 63 } 62 64 63 -
trunk/libc/src/kNIX/b_fsSymlinkOwnerSet.c
r3807 r3816 1 1 /* $Id$ */ 2 2 /** @file 3 * 4 * kNIX - lstat. 5 * 6 * Copyright (c) 2004 knut st. osmundsen <bird-src-spam@anduin.net> 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 /** 32 * Stats a symboliclink.33 * Changes the ownership and/or group, without following any final symlink. 33 34 * 34 35 * @returns 0 on success. 35 36 * @returns Negative error code (errno.h) on failure. 36 * @param pszPath Path to the file to stat. If this is a symbolic link 37 * the link it self will be stat'ed. 38 * @param pStat Where to store the file stats. 37 * @param pszPath Path to the file to modify ownership of. If this is a 38 * symbolic link, the link it self will modified. 39 * @param uid The user id of the new owner, pass -1 to not change it. 40 * @param gid The group id of the new group, pass -1 to not change it. 39 41 */ 40 int __libc_Back_fsSymlink Stat(const char *pszPath, struct stat *pStat)42 int __libc_Back_fsSymlinkOwnerSet(const char *pszPath, uid_t uid, gid_t gid) 41 43 { 42 LIBCLOG_ENTER("pszPath=%p:{%s} pStat=%p\n", (void *)pszPath, pszPath, (void *)pStat);44 LIBCLOG_ENTER("pszPath=%p:{%s} %ld %ld\n", (void *)pszPath, pszPath, (long)uid, (long)gid); 43 45 44 46 /* … … 46 48 */ 47 49 char szNativePath[PATH_MAX]; 48 int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL); 50 int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, 51 szNativePath, NULL); 49 52 if (!rc) 50 rc = __libc_back_fsNativeFile Stat(szNativePath, pStat);53 rc = __libc_back_fsNativeFileOwnerSet(szNativePath, uid, gid); 51 54 52 55 if (!rc) -
trunk/libc/src/kNIX/kNIX.h
r3770 r3816 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * kNIX - Main header. 5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net> 4 */ 5 6 /* 7 * Copyright (c) 2006-2014 knut st. osmundsen <bird-src-spam@anduin.net> 7 8 * 8 9 * … … 232 233 int __libc_back_fsNativeFileModeSet(const char *pszNativePath, mode_t Mode); 233 234 int __libc_back_fsNativeFileTimesSet(const char *pszNativePath, const struct timeval *paTimes); 235 int __libc_back_fsNativeFileOwnerSet(const char *pszNativePath, uid_t uid, gid_t gid); 236 int __libc_back_fsNativeFileOwnerSetCommon(intptr_t hNative, const char *pszNativePath, int fUnixEAs, uid_t uid, gid_t gid); 237 int __libc_back_fsNativeSetEAs(intptr_t hNative, const char *pszNativePath, PFEA2LIST pEAs, PEAOP2 pEaOp2); 234 238 dev_t __libc_back_fsPathCalcInodeAndDev(const char *pszNativePath, ino_t *pInode); 235 239 __LIBC_PFSINFO __libc_back_fsInfoObjByDev(dev_t Dev); -
trunk/libc/src/kNIX/os2/b_fsNativeFileModeSet.c
r3794 r3816 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * kNIX - internal [l]chmod, OS/2. 5 * 6 * Copyright (c) 2005-2006 knut st. osmundsen <bird-src-spam@anduin.net> 4 */ 5 6 /* 7 * Copyright (c) 2005-2014 knut st. osmundsen <bird-src-spam@anduin.net> 7 8 * 8 9 * … … 180 181 }; 181 182 #pragma pack() 182 EAOP2 EaOp2;183 EaOp2.fpGEA2List = NULL;184 EaOp2.fpFEA2List = (PFEA2LIST)&EAs;185 EaOp2.oError = 0;186 183 187 184 if (!S_ISREG(Mode) && !S_ISDIR(Mode)) … … 189 186 190 187 /* finally, try update / add the EA. */ 191 rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0); 188 EAOP2 EaOp2; 189 rc = __libc_back_fsNativeSetEAs(-1, pszNativePath, (PFEA2LIST)&EAs, &EaOp2); 192 190 if (__predict_false(rc != NO_ERROR)) 193 191 { 194 LIBCLOG_ERROR(" DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError);192 LIBCLOG_ERROR("__libc_back_fsNativeSetEAs('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError); 195 193 if (rc == ERROR_EAS_NOT_SUPPORTED) 196 rc = 0;194 rc = NO_ERROR; 197 195 else 198 196 rc = -__libc_back_native2errno(rc); -
trunk/libc/src/kNIX/os2/b_fsNativeFileOwnerSet.c
r3807 r3816 1 1 /* $Id$ */ 2 2 /** @file 3 * 4 * kNIX - internal [l]chmod, OS/2. 5 * 6 * Copyright (c) 2005-2006 knut st. osmundsen <bird-src-spam@anduin.net> 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 * … … 29 30 #include <klibc/logstrict.h> 30 31 32 31 33 /** 32 * Sets the file access modeof a native file.34 * Sets the file ownership of a native file. 33 35 * 34 36 * @returns 0 on success. 35 37 * @returns Negative error code (errno.h) on failure. 36 * @param fh Handle to file. 37 * @param Mode The filemode. 38 * @param hNative Native handle, -1 if only the path is available. 39 * @param pszNativePath The native path. 40 * @param uid The user id of the new owner, pass -1 to not change it. 41 * @param gid The group id of the new group, pass -1 to not change it. 38 42 */ 39 int __libc_back_fsNativeFile ModeSet(const char *pszNativePath, mode_t Mode)43 int __libc_back_fsNativeFileOwnerSetCommon(intptr_t hNative, const char *pszNativePath, int fUnixEAs, uid_t uid, gid_t gid) 40 44 { 41 LIBCLOG_ENTER("pszNativePath=%p:{%s} Mode=%#x\n", (void *)pszNativePath, pszNativePath, Mode); 42 union 45 FS_VAR_SAVE_LOAD(); 46 int rc; 47 if (fUnixEAs) 43 48 { 44 FILESTATUS4 fsts4; 45 FILESTATUS4L fsts4L; 46 } info; 49 struct stat StOrg; 50 memset(&StOrg, 0, sizeof(StOrg)); 51 rc = __libc_back_fsUnixAttribsGet(hNative, pszNativePath, &StOrg); 52 if (__predict_true(!rc || rc == -ENOTSUP)) 53 { 54 /** @todo check for permissions to change file ownership. */ 55 if (uid != (uid_t)-1 || gid != (gid_t)-1) 56 { 57 /* construct FEA2 stuff. */ 58 #pragma pack(1) 59 struct __LIBC_FSUNIXATTRIBSSETOWNER 60 { 61 ULONG cbList; 62 63 ULONG offUid; 64 BYTE fUidEA; 65 BYTE cbUidName; 66 USHORT cbUidValue; 67 CHAR szUidName[sizeof(EA_UID)]; 68 USHORT usUidType; 69 USHORT cbUidData; 70 uint32_t u32Uid; 71 CHAR achUidAlign[((sizeof(EA_UID) + 4) & ~3) - sizeof(EA_UID)]; 72 73 ULONG offGid; 74 BYTE fGidEA; 75 BYTE cbGidName; 76 USHORT usGidValue; 77 CHAR szGidName[sizeof(EA_GID)]; 78 USHORT usGidType; 79 USHORT cbGidData; 80 uint32_t u32Gid; 81 CHAR achGidAlign[((sizeof(EA_GID) + 4) & ~3) - sizeof(EA_GID)]; 82 } EAs = 83 { 84 sizeof(EAs), 85 86 /* .offUid =*/ offsetof(struct __LIBC_FSUNIXATTRIBSSETOWNER, offGid) 87 - offsetof(struct __LIBC_FSUNIXATTRIBSSETOWNER, offUid), 88 /* .fUidEA =*/ 0, 89 /* .cbUidName =*/ sizeof(EA_UID) - 1, 90 /* .cbUidValue =*/ sizeof(uint32_t) + 4, 91 /* .szUidName =*/ EA_UID, 92 /* .usUidType =*/ EAT_BINARY, 93 /* .cbUidData =*/ sizeof(uint32_t), 94 /* .u32Uid =*/ uid != (uid_t)-1 ? uid : StOrg.st_uid, 95 /* .achUidAlign =*/ "", 96 97 /* .offGid =*/ 0, 98 /* .fGidEA =*/ 0, 99 /* .cbGidName =*/ sizeof(EA_GID) - 1, 100 /* .cbGidValue =*/ sizeof(uint32_t) + 4, 101 /* .szGidName =*/ EA_GID, 102 /* .usGidType =*/ EAT_BINARY, 103 /* .cbGidData =*/ sizeof(uint32_t), 104 /* .u32Gid =*/ gid != (gid_t)-1 ? gid : StOrg.st_gid, 105 /* .achGidAlign =*/ "", 106 }; 107 #pragma pack() 108 109 if (uid != -1 && uid != 0) 110 EAs.fUidEA = FEA_NEEDEA; 111 if (gid != -1 && gid != 0) 112 EAs.fGidEA = FEA_NEEDEA; 113 114 EAOP2 EaOp2; 115 rc = __libc_back_fsNativeSetEAs(hNative, pszNativePath, (PFEA2LIST)&EAs, &EaOp2); 116 if (__predict_false(rc != NO_ERROR)) 117 { 118 LIBCLOG_ERROR2("__libc_back_fsNativeSetEAs('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError); 119 if ( rc == ERROR_EAS_NOT_SUPPORTED 120 && (uid == -1 || uid == 0) 121 && (gid == -1 || gid == 0) ) 122 rc = 0; 123 else 124 rc = -__libc_back_native2errno(rc); 125 } 126 } 127 else 128 rc = 0; /* No change and thus no not-supported complaints. */ 129 } 130 } 131 else 132 { 133 /* 134 * In this mode we'll simply check if the file exists and return the 135 * appropriate errors if it doesn't or we cannot access it. 136 */ 137 union 138 { 139 FILESTATUS4 fsts4; 140 FILESTATUS4L fsts4L; 141 } info; 142 47 143 #if OFF_MAX > LONG_MAX 48 int fLarge = 0; 144 if (__libc_gpfnDosOpenL) 145 rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList)); 146 else 49 147 #endif 50 FS_VAR(); 148 rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList)); 149 150 if (rc != NO_ERROR) 151 rc = -__libc_back_native2errno(rc); 152 } 153 FS_RESTORE(); 154 return rc; 155 } 156 157 158 /** 159 * Sets the file ownership of a native file. 160 * 161 * @returns 0 on success. 162 * @returns Negative error code (errno.h) on failure. 163 * @param pszNativePath The native path. 164 * @param uid The user id of the new owner, pass -1 to not change it. 165 * @param gid The group id of the new group, pass -1 to not change it. 166 */ 167 int __libc_back_fsNativeFileOwnerSet(const char *pszNativePath, uid_t uid, gid_t gid) 168 { 169 LIBCLOG_ENTER("pszNativePath=%p:{%s} uid=%ld gid=%ld\n", (void *)pszNativePath, pszNativePath, (long)uid, (long)gid); 51 170 52 171 /* … … 68 187 69 188 /* 70 * Get path info.189 * Join paths with the file handle base code path. 71 190 */ 72 FS_SAVE_LOAD(); 73 int rc; 74 const int fUnixEAs = __libc_back_fsInfoSupportUnixEAs(pszNativePath); 75 if (fUnixEAs) 76 { 77 #if OFF_MAX > LONG_MAX 78 if (__libc_gpfnDosOpenL) 79 { 80 rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L)); 81 fLarge = 1; 82 } 83 else 84 #endif 85 rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &info, sizeof(info.fsts4)); 86 /* If the file is open in write mode, we cannot even get the EA size. stupid. 87 * It'll fail with ERROR_SHARING_VIOLATION, which we handle rigth below. */ 88 } 89 else 90 rc = ERROR_SHARING_VIOLATION; /* take the fallback path if we don't want EAs. */ 91 if (rc == ERROR_SHARING_VIOLATION) 92 { 93 #if OFF_MAX > LONG_MAX 94 if (__libc_gpfnDosOpenL) 95 { 96 rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList)); 97 fLarge = 1; 98 } 99 else 100 #endif 101 rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList)); 102 info.fsts4L.cbList = LIBC_UNIX_EA_MIN; 103 } 104 if (rc) 105 { 106 rc = -__libc_back_native2errno(rc); 107 FS_RESTORE(); 191 int rc = __libc_back_fsNativeFileOwnerSetCommon(-1, pszNativePath, __libc_back_fsInfoSupportUnixEAs(pszNativePath), uid, gid); 192 if (__predict_false(rc != 0)) 108 193 LIBCLOG_ERROR_RETURN_INT(rc); 109 }110 111 /*112 * Update OS/2 attributes.113 */114 #if OFF_MAX > LONG_MAX115 if (fLarge)116 {117 if (Mode & S_IWRITE)118 info.fsts4L.attrFile &= ~FILE_READONLY;119 else120 info.fsts4L.attrFile = FILE_READONLY;121 rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList), 0);122 }123 else124 #endif125 {126 if (Mode & S_IWRITE)127 info.fsts4.attrFile &= ~FILE_READONLY;128 else129 info.fsts4.attrFile |= FILE_READONLY;130 rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList), 0);131 }132 if (__predict_false(rc != NO_ERROR))133 {134 FS_RESTORE();135 rc = -__libc_back_native2errno(rc);136 LIBCLOG_ERROR_RETURN_INT(rc);137 }138 139 /*140 * If in unix mode we'll have to update/add the MODE too.141 */142 if (fUnixEAs)143 {144 mode_t CurMode;145 rc = __libc_back_fsUnixAttribsGetMode(-1, pszNativePath, &CurMode);146 if (__predict_true(!rc || rc == -ENOTSUP))147 {148 /* correct the passed in Mode mask. */149 Mode &= ALLPERMS; /** @todo sticky bit and set uid/gid access validation... */150 if (!(CurMode & ~ALLPERMS))151 {152 #if OFF_MAX > LONG_MAX153 if ((fLarge ? info.fsts4L.attrFile : info.fsts4.attrFile) & FILE_DIRECTORY)154 #else155 if (info.fsts4.attrFile & FILE_DIRECTORY)156 #endif157 Mode |= S_IFDIR;158 else159 Mode |= S_IFREG;160 }161 else162 Mode |= CurMode & ~ALLPERMS;163 164 /* construct FEA2 stuff. */165 #pragma pack(1)166 struct __LIBC_FSUNIXATTRIBSSETMODE167 {168 ULONG cbList;169 ULONG off;170 BYTE fEA;171 BYTE cbName;172 USHORT cbValue;173 CHAR szName[sizeof(EA_MODE)];174 USHORT usType;175 USHORT cbData;176 uint32_t u32Mode;177 } EAs =178 {179 sizeof(EAs), 0, 0, sizeof(EA_MODE) - 1, sizeof(uint32_t) + 4, EA_MODE, EAT_BINARY, sizeof(uint32_t), Mode180 };181 #pragma pack()182 EAOP2 EaOp2;183 EaOp2.fpGEA2List = NULL;184 EaOp2.fpFEA2List = (PFEA2LIST)&EAs;185 EaOp2.oError = 0;186 187 if (!S_ISREG(Mode) && !S_ISDIR(Mode))188 EAs.fEA = FEA_NEEDEA;189 190 /* finally, try update / add the EA. */191 rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0);192 if (__predict_false(rc != NO_ERROR))193 {194 LIBCLOG_ERROR("DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError);195 if (rc == ERROR_EAS_NOT_SUPPORTED)196 rc = 0;197 else198 rc = -__libc_back_native2errno(rc);199 }200 }201 if (__predict_false(rc != 0))202 {203 FS_RESTORE();204 LIBCLOG_ERROR_RETURN_INT(rc);205 }206 }207 FS_RESTORE();208 209 194 LIBCLOG_RETURN_INT(0); 210 195 } -
trunk/libc/src/kNIX/os2/fhOS2File.c
r3794 r3816 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * kNIX - Native file handles. 5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net> 4 */ 5 6 /* 7 * Copyright (c) 2006-2014 knut st. osmundsen <bird-src-spam@anduin.net> 7 8 * 8 9 * … … 635 636 }; 636 637 #pragma pack() 637 EAOP2 EaOp2;638 EaOp2.fpGEA2List = NULL;639 EaOp2.fpFEA2List = (PFEA2LIST)&EAs;640 EaOp2.oError = 0;641 638 642 639 if (!S_ISREG(fMode) && !S_ISDIR(fMode)) … … 644 641 645 642 /* finally, try update / add the EA. */ 646 rc = DosSetFileInfo(pFH->fh, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2)); 643 EAOP2 EaOp2; 644 rc = __libc_back_fsNativeSetEAs(pFH->fh, pFH->pszNativePath, (PFEA2LIST)&EAs, &EaOp2); 647 645 if (__predict_false(rc != NO_ERROR)) 648 646 { 649 LIBCLOG_ERROR("DosSetFileInfo(%d,,,,) -> %d, oError=%#lx\n", pFH->fh, rc, EaOp2.oError); 650 if (rc != ERROR_EAS_NOT_SUPPORTED && pFH->pszNativePath) 651 { 652 EaOp2.oError = 0; 653 int rc2 = DosSetPathInfo((PCSZ)pFH->pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0); 654 if (rc2) 655 LIBCLOG_ERROR("DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pFH->pszNativePath, rc2, EaOp2.oError); 656 } 647 LIBCLOG_ERROR("__libc_back_fsNativeSetEAs('%s',,,,) -> %d, oError=%#lx\n", pFH->pszNativePath, rc, EaOp2.oError); 657 648 if (rc == ERROR_EAS_NOT_SUPPORTED) 658 649 rc = 0; … … 683 674 684 675 /** @copydoc __LIBC_FHOPS::pfnSetOwner */ 685 static int fhOs2FileSetOwner(__LIBC_PFH pFH, uid_t uid )686 { 687 LIBCLOG_ENTER("pFH=%p:{.fd=%d} uid=% d\n", (void *)pFH, pFH->fh, uid);676 static int fhOs2FileSetOwner(__LIBC_PFH pFH, uid_t uid, gid_t gid) 677 { 678 LIBCLOG_ENTER("pFH=%p:{.fd=%d} uid=%ld gid=%ld\n", (void *)pFH, pFH->fh, (long)uid, (long)gid); 688 679 int rc; 689 /** @todo fchown */ 690 /*if (pFH->pszNativePath) 691 rc = -ENOSYS;//rc = __libc_back_fsNativeSetOwner(pFH->pszNativePath, uid); 692 else 693 rc = -EINVAL;*/ 694 rc = -ENOSYS; 680 if (pFH->pszNativePath) 681 rc = __libc_back_fsNativeFileOwnerSetCommon(pFH->hNative, pFH->pszNativePath, pFH->pFsInfo ? pFH->pFsInfo->fUnixEAs : 0, 682 uid, gid); 683 else 684 rc = -EINVAL; 695 685 LIBCLOG_MIX_RETURN_INT(rc); 696 686 } -
trunk/libc/src/kNIX/os2/fs-os2.c
r3778 r3816 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * kNIX - file system, OS/2 common bits. 5 * 6 * Copyright (c) 2004-2006 knut st. osmundsen <bird-src-spam@anduin.net> 4 */ 5 6 /* 7 * Copyright (c) 2004-2014 knut st. osmundsen <bird-src-spam@anduin.net> 7 8 * 8 9 * … … 1741 1742 1742 1743 /** 1744 * Helper path and handle based native functions for writing EAs. 1745 * 1746 * This tries to work around sharing issues as well as trying to use 1747 * fchmod/fchown on handles opened without write access. 1748 * 1749 * @returns Native status code. 1750 * @param hNative The native handle, -1 if not available. 1751 * @param pszNativePath The native path. 1752 * @param pEAs The list of EAs to set. 1753 * @param pEaOp2 The EA operation 2 buffer to use. This is passed in 1754 * as a parameter so that the calling code can access 1755 * error information. 1756 */ 1757 int __libc_back_fsNativeSetEAs(intptr_t hNative, const char *pszNativePath, PFEA2LIST pEAs, PEAOP2 pEaOp2) 1758 { 1759 /* 1760 * First copy the EAs so we can do a retry with a different access path. 1761 */ 1762 PFEA2LIST pCopyEAs = (PFEA2LIST)alloca(pEAs->cbList); 1763 memcpy(pCopyEAs, pEAs, pEAs->cbList); 1764 1765 /* 1766 * First try. 1767 */ 1768 APIRET rc; 1769 pEaOp2->fpGEA2List = NULL; 1770 pEaOp2->fpFEA2List = pEAs; 1771 pEaOp2->oError = 0; 1772 if (hNative != -1) 1773 rc = DosSetFileInfo(hNative, FIL_QUERYEASIZE, pEaOp2, sizeof(*pEaOp2)); 1774 else 1775 rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, pEaOp2, sizeof(*pEaOp2), 0); 1776 1777 if ( ( rc == ERROR_SHARING_VIOLATION 1778 || rc == ERROR_ACCESS_DENIED) 1779 && pszNativePath 1780 && pszNativePath[0]) 1781 { 1782 /* 1783 * To write EAs using DosSetPathInfo, the system requires deny-all 1784 * access, but when using DosSetFileInfo we're seemingly free to choose 1785 * this ourselves. So, try open the file with write access and retry. 1786 */ 1787 APIRET rc2; 1788 HFILE hFile2 = (HFILE)-1; 1789 ULONG ulAction = 0; 1790 ULONG flOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW; 1791 ULONG flOpenMode = OPEN_ACCESS_WRITEONLY | OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE; 1792 1793 #if OFF_MAX > LONG_MAX 1794 if (__libc_gpfnDosOpenL) 1795 rc2 = __libc_gpfnDosOpenL((PCSZ)pszNativePath, &hFile2, &ulAction, 0, FILE_NORMAL, flOpenFlags, flOpenMode, NULL); 1796 else 1797 #endif 1798 rc2 = DosOpen((PCSZ)pszNativePath, &hFile2, &ulAction, 0, FILE_NORMAL, flOpenFlags, flOpenMode, NULL); 1799 if (rc2 == NO_ERROR) 1800 { 1801 memcpy(pEAs, pCopyEAs, pCopyEAs->cbList); 1802 pEaOp2->fpGEA2List = NULL; 1803 pEaOp2->fpFEA2List = pEAs; 1804 pEaOp2->oError = 0; 1805 rc = DosSetFileInfo(hFile2, FIL_QUERYEASIZE, pEaOp2, sizeof(*pEaOp2)); 1806 1807 DosClose(hFile2); 1808 } 1809 } 1810 1811 return rc; 1812 } 1813 1814 1815 /** 1743 1816 * Reads the content of a symbolic link. 1744 1817 * -
trunk/libc/src/libc/io/fchown.c
r2739 r3816 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 * … … 34 34 #include <unistd.h> 35 35 #include <errno.h> 36 #include <klibc/io.h> 37 #include <klibc/logstrict.h> 38 36 #include <klibc/backend.h> 37 #include <InnoTekLIBC/logstrict.h> 39 38 40 39 41 40 /** 42 * Change the owner and group over a file. 43 * 44 * This is a stub. It only validates the filehandle and returns without changing anything. 41 * Change the owner and group if an open file. 45 42 * 46 43 * @returns 0 on success. 47 44 * @returns -1 and errno on failure. 48 45 * @param fh Handle to the file. 49 * @param owner Owner id.50 * @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. 51 48 */ 52 int _STD(fchown)(int fh, uid_t owner, gid_t group)49 int _STD(fchown)(int fh, uid_t uid, gid_t gid) 53 50 { 54 LIBCLOG_ENTER("fh=%d owner=%d group=%d\n", fh, owner, group); 55 __LIBC_PFH pFH; 56 int rc = __libc_FHGet(fh, &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); 57 53 if (!rc) 58 {59 __libc_FHPut(pFH);60 54 LIBCLOG_RETURN_INT(0); 61 }62 55 errno = -rc; 63 56 LIBCLOG_ERROR_RETURN_INT(-1); -
trunk/libc/src/libc/io/lchown.c
r2254 r3816 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 <klibc/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 } -
trunk/libc/src/libc/misc/chown.c
r2254 r3816 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 <klibc/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 -
trunk/libc/tests/libc/io/chown-1.c
r3814 r3816 56 56 } \ 57 57 else \ 58 assertOwners(fd, szTmp, a_uidExpect, a_gidExpect, #a_OperationExpr " at line " XSTR(__LINE__)); \58 assertOwners(fd, szTmp, a_uidExpect, a_gidExpect, " " #a_OperationExpr " at line " XSTR(__LINE__)); \ 59 59 } while (0) 60 60 … … 176 176 TEST_CHANGE(chown(szTmp, -1, st1.st_gid + 3), st1.st_uid + 2, st1.st_gid + 3); 177 177 178 close(fd); 179 fd = -1; 180 181 TEST_CHANGE(lchown(szTmp, st1.st_uid + 1, st1.st_gid + 1), st1.st_uid + 1, st1.st_gid + 1); 182 TEST_CHANGE(chown(szTmp, st1.st_uid + 1, st1.st_gid + 1), st1.st_uid + 1, st1.st_gid + 1); 183 184 TEST_CHANGE(lchown(szTmp, st1.st_uid + 2, -1), st1.st_uid + 2, st1.st_gid + 1); 185 TEST_CHANGE(chown(szTmp, st1.st_uid + 2, -1), st1.st_uid + 2, st1.st_gid + 1); 186 187 TEST_CHANGE(lchown(szTmp, -1, st1.st_gid + 3), st1.st_uid + 2, st1.st_gid + 3); 188 TEST_CHANGE(chown(szTmp, -1, st1.st_gid + 3), st1.st_uid + 2, st1.st_gid + 3); 189 178 190 /* 179 191 * Cleanup. 180 192 */ 181 close(fd);182 193 if (unlink(szTmp)) 183 194 {
Note:
See TracChangeset
for help on using the changeset viewer.