Ticket #204: patch-204t.txt

File patch-204t.txt, 16.5 KB (added by Yuri Dario, 11 years ago)
Line 
1Index: libc/include/klibc/backend.h
2===================================================================
3--- libc/include/klibc/backend.h (revision 3803)
4+++ libc/include/klibc/backend.h (working copy)
5@@ -401,6 +401,16 @@
6 int __libc_Back_fsSymlinkModeSet(const char *pszPath, mode_t Mode);
7
8 /**
9+ * Sets the file group/owner of a file.
10+ *
11+ * @returns 0 on success.
12+ * @returns Negative error code (errno.h) on failure.
13+ * @param fh Handle to file.
14+ * @param Mode The filemode.
15+ */
16+int __libc_Back_fsSymlinkOwnerSet(const char *pszPath, uid_t owner, gid_t group);
17+
18+/**
19 * Sets the file times of a symlink.
20 *
21 * @returns 0 on success.
22@@ -452,6 +462,17 @@
23 int __libc_Back_fsFileModeSetFH(int fh, mode_t fMode);
24
25 /**
26+ * Sets the file group/owner of a file.
27+ *
28+ * @returns 0 on success.
29+ * @returns Negative error code (errno.h) on failure.
30+ * @param pszPath The path to the file to set the mode of.
31+ * @param owner The new owner, if -1 do not change it.
32+ * @param group The new group, if -1 do not change it.
33+ */
34+int __libc_Back_fsFileOwnerSet(const char *pszPath, uid_t owner, gid_t group);
35+
36+/**
37 * Sets the file the times of a file.
38 *
39 * @returns 0 on success.
40Index: libc/src/kNIX/b_fsFileModeSetFH.c
41===================================================================
42--- libc/src/kNIX/b_fsFileModeSetFH.c (revision 3803)
43+++ libc/src/kNIX/b_fsFileModeSetFH.c (working copy)
44@@ -61,3 +61,172 @@
45 }
46
47
48+/**
49+ * Sets the owner/group of a file by filehandle.
50+ *
51+ * @returns 0 on success.
52+ * @returns Negative error code (errno.h) on failure.
53+ * @param fh Handle to file.
54+ * @param owner The new owner, if -1 do not change it.
55+ * @param group The new group, if -1 do not change it.
56+ */
57+int __libc_Back_fsFileOwnerSetFH(int fh, uid_t owner, gid_t group)
58+{
59+ LIBCLOG_ENTER("fh=%d Owner=%#d Group=%#d\n", fh, owner, group);
60+
61+ /*
62+ * Get filehandle.
63+ */
64+ __LIBC_PFH pFH;
65+ int rc = __libc_FHGet(fh, &pFH);
66+ if (rc)
67+ {
68+ __libc_FHPut(pFH);
69+ LIBCLOG_ERROR_RETURN_INT(rc);
70+ }
71+
72+ /*
73+ * Check the type.
74+ */
75+ switch (pFH->fFlags & __LIBC_FH_TYPEMASK)
76+ {
77+ /* fail */
78+ case F_SOCKET:
79+ case F_PIPE: /* treat as socket for now */
80+ __libc_FHPut(pFH);
81+ LIBCLOG_ERROR_RETURN_INT(-EINVAL);
82+ /* ignore */
83+ case F_DEV:
84+ __libc_FHPut(pFH);
85+ LIBCLOG_RETURN_INT(0);
86+
87+ /* use the path access. */
88+ case F_DIR:
89+ if (__predict_false(!pFH->pszNativePath))
90+ {
91+ __libc_FHPut(pFH);
92+ LIBCLOG_ERROR_RETURN_INT(-EINVAL);
93+ }
94+ rc = __libc_back_fsNativeFileOwnerSet(pFH->pszNativePath, owner, group);
95+ __libc_FHPut(pFH);
96+ if (rc)
97+ LIBCLOG_ERROR_RETURN_INT(rc);
98+ LIBCLOG_RETURN_INT(rc);
99+
100+ /* treat */
101+ default:
102+ case F_FILE:
103+ break;
104+ }
105+
106+ /** @todo YD add right access check */
107+
108+ if (!pFH->pOps)
109+ {
110+ /*
111+ * Standard OS/2 file handle.
112+ */
113+ FS_VAR();
114+ FS_SAVE_LOAD();
115+ /*
116+ * update owner if specified
117+ */
118+ FS_SAVE_LOAD();
119+ int rc;
120+ if (owner != -1)
121+ {
122+ /* construct FEA2 stuff. */
123+ #pragma pack(1)
124+ struct __LIBC_FSUNIXATTRIBSSETMODE
125+ {
126+ ULONG cbList;
127+ ULONG off;
128+ BYTE fEA;
129+ BYTE cbName;
130+ USHORT cbValue;
131+ CHAR szName[sizeof(EA_UID)];
132+ USHORT usType;
133+ USHORT cbData;
134+ uint32_t u32Mode;
135+ } EAs =
136+ {
137+ sizeof(EAs), 0, FEA_NEEDEA, sizeof(EA_UID) - 1, sizeof(uint32_t) + 4, EA_UID, EAT_BINARY, sizeof(uint32_t), owner
138+ };
139+ #pragma pack()
140+ EAOP2 EaOp2;
141+ EaOp2.fpGEA2List = NULL;
142+ EaOp2.fpFEA2List = (PFEA2LIST)&EAs;
143+ EaOp2.oError = 0;
144+
145+ /* finally, try update / add the EA. */
146+ rc = DosSetFileInfo(fh, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2));
147+ if (__predict_false(rc != NO_ERROR))
148+ {
149+ LIBCLOG_ERROR("DosSetFileInfo('%d',,,,) -> %d, oError=%#lx\n", fh, rc, EaOp2.oError);
150+ if (rc == ERROR_EAS_NOT_SUPPORTED)
151+ rc = 0;
152+ else
153+ rc = -__libc_back_native2errno(rc);
154+ }
155+
156+ if (__predict_false(rc != 0))
157+ {
158+ FS_RESTORE();
159+ __libc_FHPut(pFH);
160+ LIBCLOG_ERROR_RETURN_INT(rc);
161+ }
162+ }
163+
164+ /*
165+ * update group if specified
166+ */
167+ if (group != -1)
168+ {
169+ /* construct FEA2 stuff. */
170+ #pragma pack(1)
171+ struct __LIBC_FSUNIXATTRIBSSETMODE
172+ {
173+ ULONG cbList;
174+ ULONG off;
175+ BYTE fEA;
176+ BYTE cbName;
177+ USHORT cbValue;
178+ CHAR szName[sizeof(EA_GID)];
179+ USHORT usType;
180+ USHORT cbData;
181+ uint32_t u32Mode;
182+ } EAs =
183+ {
184+ sizeof(EAs), 0, FEA_NEEDEA, sizeof(EA_GID) - 1, sizeof(uint32_t) + 4, EA_GID, EAT_BINARY, sizeof(uint32_t), group
185+ };
186+ #pragma pack()
187+ EAOP2 EaOp2;
188+ EaOp2.fpGEA2List = NULL;
189+ EaOp2.fpFEA2List = (PFEA2LIST)&EAs;
190+ EaOp2.oError = 0;
191+
192+ /* finally, try update / add the EA. */
193+ rc = DosSetFileInfo(fh, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2));
194+ if (__predict_false(rc != NO_ERROR))
195+ {
196+ LIBCLOG_ERROR("DosSetFileInfo('%d',,,,) -> %d, oError=%#lx\n", fh, rc, EaOp2.oError);
197+ if (rc == ERROR_EAS_NOT_SUPPORTED)
198+ rc = 0;
199+ else
200+ rc = -__libc_back_native2errno(rc);
201+ }
202+
203+ if (__predict_false(rc != 0))
204+ {
205+ FS_RESTORE();
206+ __libc_FHPut(pFH);
207+ LIBCLOG_ERROR_RETURN_INT(rc);
208+ }
209+ }
210+
211+ FS_RESTORE();
212+ }
213+
214+ __libc_FHPut(pFH);
215+ LIBCLOG_RETURN_INT(0);
216+}
217Index: libc/src/kNIX/b_fsSymlinkModeSet.c
218===================================================================
219--- libc/src/kNIX/b_fsSymlinkModeSet.c (revision 3803)
220+++ libc/src/kNIX/b_fsSymlinkModeSet.c (working copy)
221@@ -53,3 +53,28 @@
222 LIBCLOG_ERROR_RETURN_INT(rc);
223 }
224
225+
226+/**
227+ * Sets the file group/owner of a file.
228+ *
229+ * @returns 0 on success.
230+ * @returns Negative error code (errno.h) on failure.
231+ * @param fh Handle to file.
232++ * @param Mode The filemode.
233++ */
234+int __libc_Back_fsSymlinkOwnerSet(const char *pszPath, uid_t owner, gid_t group)
235+{
236+ LIBCLOG_ENTER("pszPath=%p:{%s} Owner=%#d Group=%#d\n", (void *)pszPath, pszPath, owner, group);
237+
238+ /*
239+ * Resolve the path.
240+ */
241+ char szNativePath[PATH_MAX];
242+ int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL_SYMLINK | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL);
243+ if (!rc)
244+ rc = __libc_back_fsNativeFileOwnerSet(szNativePath, owner, group);
245+
246+ if (!rc)
247+ LIBCLOG_RETURN_INT(rc);
248+ LIBCLOG_ERROR_RETURN_INT(rc);
249+}
250Index: libc/src/kNIX/kNIX.h
251===================================================================
252--- libc/src/kNIX/kNIX.h (revision 3803)
253+++ libc/src/kNIX/kNIX.h (working copy)
254@@ -230,6 +230,7 @@
255 int __libc_back_fsNativeSymlinkRead(const char *pszNativePath, char *pachBuf, size_t cchBuf);
256 int __libc_back_fsNativeFileStat(const char *pszNativePath, struct stat *pStat);
257 int __libc_back_fsNativeFileModeSet(const char *pszNativePath, mode_t Mode);
258+int __libc_back_fsNativeFileOwnerSet(const char *pszNativePath, uid_t owner, gid_t group);
259 int __libc_back_fsNativeFileTimesSet(const char *pszNativePath, const struct timeval *paTimes);
260 dev_t __libc_back_fsPathCalcInodeAndDev(const char *pszNativePath, ino_t *pInode);
261 __LIBC_PFSINFO __libc_back_fsInfoObjByDev(dev_t Dev);
262Index: libc/src/kNIX/os2/b_fsNativeFileModeSet.c
263===================================================================
264--- libc/src/kNIX/os2/b_fsNativeFileModeSet.c (revision 3803)
265+++ libc/src/kNIX/os2/b_fsNativeFileModeSet.c (working copy)
266@@ -209,3 +209,141 @@
267 LIBCLOG_RETURN_INT(0);
268 }
269
270+
271+/**
272+ * Sets the file group/owner of a native file.
273+ *
274+ * @returns 0 on success.
275+ * @returns Negative error code (errno.h) on failure.
276+ * @param pszNativePath Path to the file to change.
277+ * @param owner The new owner, if -1 do not change it.
278+ * @param group The new group, if -1 do not change it.
279+ */
280+int __libc_back_fsNativeFileOwnerSet(const char *pszNativePath, uid_t owner, gid_t group)
281+{
282+ LIBCLOG_ENTER("pszNativePath=%p:{%s} Owner=%#d Group=%#d\n", (void *)pszNativePath, pszNativePath, owner, group);
283+ FS_VAR();
284+
285+ /*
286+ * Validate input, refusing named pipes.
287+ */
288+ if ( (pszNativePath[0] == '/' || pszNativePath[0] == '\\')
289+ && (pszNativePath[1] == 'p' || pszNativePath[1] == 'P')
290+ && (pszNativePath[2] == 'i' || pszNativePath[2] == 'I')
291+ && (pszNativePath[3] == 'p' || pszNativePath[3] == 'P')
292+ && (pszNativePath[4] == 'e' || pszNativePath[4] == 'E')
293+ && (pszNativePath[5] == '/' || pszNativePath[5] == '\\'))
294+ LIBCLOG_ERROR_RETURN_INT(-ENOENT);
295+
296+ /*
297+ * If potential device, then perform real check.
298+ * (Devices are subject to mode in POSIX.)
299+ */
300+ /** @todo copy device check from the path resolver. */
301+
302+ /** @todo YD add right access check */
303+
304+ /*
305+ * Do we have UnixEAs on this path?
306+ */
307+ if (__predict_false(!__libc_back_fsInfoSupportUnixEAs(pszNativePath)))
308+ LIBCLOG_ERROR_RETURN(-ENOTSUP, "ret -ENOTSUP - no Unix EAs on '%s'\n", pszNativePath);
309+
310+ /*
311+ * update owner if specified
312+ */
313+ FS_SAVE_LOAD();
314+ int rc;
315+ if (owner != -1)
316+ {
317+ /* construct FEA2 stuff. */
318+ #pragma pack(1)
319+ struct __LIBC_FSUNIXATTRIBSSETMODE
320+ {
321+ ULONG cbList;
322+ ULONG off;
323+ BYTE fEA;
324+ BYTE cbName;
325+ USHORT cbValue;
326+ CHAR szName[sizeof(EA_UID)];
327+ USHORT usType;
328+ USHORT cbData;
329+ uint32_t u32Mode;
330+ } EAs =
331+ {
332+ sizeof(EAs), 0, FEA_NEEDEA, sizeof(EA_UID) - 1, sizeof(uint32_t) + 4, EA_UID, EAT_BINARY, sizeof(uint32_t), owner
333+ };
334+ #pragma pack()
335+ EAOP2 EaOp2;
336+ EaOp2.fpGEA2List = NULL;
337+ EaOp2.fpFEA2List = (PFEA2LIST)&EAs;
338+ EaOp2.oError = 0;
339+
340+ /* finally, try update / add the EA. */
341+ rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0);
342+ if (__predict_false(rc != NO_ERROR))
343+ {
344+ LIBCLOG_ERROR("DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError);
345+ if (rc == ERROR_EAS_NOT_SUPPORTED)
346+ rc = 0;
347+ else
348+ rc = -__libc_back_native2errno(rc);
349+ }
350+
351+ if (__predict_false(rc != 0))
352+ {
353+ FS_RESTORE();
354+ LIBCLOG_ERROR_RETURN_INT(rc);
355+ }
356+ }
357+
358+ /*
359+ * update group if specified
360+ */
361+ if (group != -1)
362+ {
363+ /* construct FEA2 stuff. */
364+ #pragma pack(1)
365+ struct __LIBC_FSUNIXATTRIBSSETMODE
366+ {
367+ ULONG cbList;
368+ ULONG off;
369+ BYTE fEA;
370+ BYTE cbName;
371+ USHORT cbValue;
372+ CHAR szName[sizeof(EA_GID)];
373+ USHORT usType;
374+ USHORT cbData;
375+ uint32_t u32Mode;
376+ } EAs =
377+ {
378+ sizeof(EAs), 0, FEA_NEEDEA, sizeof(EA_GID) - 1, sizeof(uint32_t) + 4, EA_GID, EAT_BINARY, sizeof(uint32_t), group
379+ };
380+ #pragma pack()
381+ EAOP2 EaOp2;
382+ EaOp2.fpGEA2List = NULL;
383+ EaOp2.fpFEA2List = (PFEA2LIST)&EAs;
384+ EaOp2.oError = 0;
385+
386+ /* finally, try update / add the EA. */
387+ rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0);
388+ if (__predict_false(rc != NO_ERROR))
389+ {
390+ LIBCLOG_ERROR("DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError);
391+ if (rc == ERROR_EAS_NOT_SUPPORTED)
392+ rc = 0;
393+ else
394+ rc = -__libc_back_native2errno(rc);
395+ }
396+
397+ if (__predict_false(rc != 0))
398+ {
399+ FS_RESTORE();
400+ LIBCLOG_ERROR_RETURN_INT(rc);
401+ }
402+ }
403+
404+ FS_RESTORE();
405+
406+ LIBCLOG_RETURN_INT(0);
407+}
408Index: libc/src/kNIX/b_fsFileModeSet.c
409===================================================================
410--- libc/src/kNIX/b_fsFileModeSet.c (revision 3803)
411+++ libc/src/kNIX/b_fsFileModeSet.c (working copy)
412@@ -53,3 +53,29 @@
413 LIBCLOG_ERROR_RETURN_INT(rc);
414 }
415
416+
417+/**
418+ * Sets the file group/owner of a file.
419+ *
420+ * @returns 0 on success.
421+ * @returns Negative error code (errno.h) on failure.
422+ * @param pszPath The path to the file to set the mode of.
423+ * @param owner The new owner, if -1 do not change it.
424+ * @param group The new group, if -1 do not change it.
425+ */
426+int __libc_Back_fsFileOwnerSet(const char *pszPath, uid_t owner, gid_t group)
427+{
428+ LIBCLOG_ENTER("pszPath=%p:{%s} Owner=%#d Owner=%#d\n", (void *)pszPath, pszPath, owner, group);
429+
430+ /*
431+ * Resolve the path.
432+ */
433+ char szNativePath[PATH_MAX];
434+ int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, NULL);
435+ if (!rc)
436+ rc = __libc_back_fsNativeFileOwnerSet(szNativePath, owner, group);
437+
438+ if (!rc)
439+ LIBCLOG_RETURN_INT(rc);
440+ LIBCLOG_ERROR_RETURN_INT(rc);
441+}
442Index: libc/src/libc/misc/chown.c
443===================================================================
444--- libc/src/libc/misc/chown.c (revision 3803)
445+++ libc/src/libc/misc/chown.c (working copy)
446@@ -30,6 +30,7 @@
447 * Header Files *
448 *******************************************************************************/
449 #include "libc-alias.h"
450+#include <errno.h>
451 #include <unistd.h>
452 #include <sys/stat.h>
453 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
454@@ -40,8 +41,6 @@
455 /**
456 * Change the owner and group over a file.
457 *
458- * This is stub. It only validates the path and returns without changing anything.
459- *
460 * @returns 0 on success.
461 * @returns -1 and errno on failure.
462 * @param path Path to the file to change owner/group of.
463@@ -52,9 +51,10 @@
464 {
465 LIBCLOG_ENTER("path=%p:{%s} owner=%d group=%d\n", (void *)path, path, owner, group);
466 struct stat st;
467- int rc = stat(path, &st);
468+ int rc = __libc_Back_fsFileOwnerSet(path, owner, group);
469 if (!rc)
470- LIBCLOG_RETURN_INT(rc);
471- LIBCLOG_ERROR_RETURN_INT(rc);
472+ LIBCLOG_RETURN_INT(0);
473+ errno = -rc;
474+ LIBCLOG_ERROR_RETURN_INT(-1);
475 }
476
477Index: libc/src/libc/libc.def
478===================================================================
479--- libc/src/libc/libc.def (revision 3803)
480+++ libc/src/libc/libc.def (working copy)
481@@ -2000,3 +2000,7 @@
482 "___libc_TermProcess" @1996
483 "___libc_Back_fsPathConf" @1997
484 "___libc_Back_ioPathConf" @1998
485+
486+ "___libc_Back_fsFileOwnerSet" @1999
487+ "___libc_Back_fsFileOwnerSetFH" @2000
488+ "___libc_Back_fsSymlinkOwnerSet" @2001
489Index: libc/src/libc/io/lchown.c
490===================================================================
491--- libc/src/libc/io/lchown.c (revision 3803)
492+++ libc/src/libc/io/lchown.c (working copy)
493@@ -30,6 +30,7 @@
494 * Header Files *
495 *******************************************************************************/
496 #include "libc-alias.h"
497+#include <errno.h>
498 #include <unistd.h>
499 #include <sys/stat.h>
500 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
501@@ -40,8 +41,6 @@
502 /**
503 * Change the owner and group over a symbolic link.
504 *
505- * This is stub. It only validates the path and returns without changing anything.
506- *
507 * @returns 0 on success.
508 * @returns -1 and errno on failure.
509 * @param path Path to the link to change owner/group of.
510@@ -52,9 +51,10 @@
511 {
512 LIBCLOG_ENTER("path=%p:{%s} owner=%d group=%d\n", (void *)path, path, owner, group);
513 struct stat st;
514- int rc = lstat(path, &st);
515+ int rc = __libc_Back_fsSymlinkOwnerSet(path, owner, group);
516 if (!rc)
517 LIBCLOG_RETURN_INT(0);
518+ errno = -rc;
519 LIBCLOG_ERROR_RETURN_INT(-1);
520 }
521