Compare commits

...
4 changed files with 70 additions and 16 deletions
+2 -16
View File
@@ -1575,28 +1575,14 @@ FileAttrIsOwnedCmd(
int objc,
Tcl_Obj *const objv[])
{
Tcl_StatBuf buf;
int value = 0;
int value;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "name");
return TCL_ERROR;
}
if (GetStatBuf(NULL, objv[1], Tcl_FSStat, &buf) == TCL_OK) {
/*
* For Windows, there are no user ids associated with a file, so we
* always return 1.
*
* TODO: use GetSecurityInfo to get the real owner of the file and
* test for equivalence to the current user.
*/
#if defined(__WIN32__) || defined(__CYGWIN__)
value = 1;
#else
value = (geteuid() == buf.st_uid);
#endif
}
value = TclpFileOwnedByCurrentUser(interp, objv[1]);
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(value));
return TCL_OK;
}
+2
View File
@@ -2997,6 +2997,8 @@ MODULE_SCOPE int TclParseAllWhiteSpace(const char *src, int numBytes);
MODULE_SCOPE int TclProcessReturn(Tcl_Interp *interp,
int code, int level, Tcl_Obj *returnOpts);
MODULE_SCOPE int TclpObjLstat(Tcl_Obj *pathPtr, Tcl_StatBuf *buf);
MODULE_SCOPE int TclpFileOwnedByCurrentUser(Tcl_Interp *interp,
Tcl_Obj *pathObj);
MODULE_SCOPE Tcl_Obj * TclpTempFileName(void);
MODULE_SCOPE Tcl_Obj * TclpTempFileNameForLibrary(Tcl_Interp *interp, Tcl_Obj* pathPtr);
MODULE_SCOPE Tcl_Obj * TclNewFSPathObj(Tcl_Obj *dirPtr, const char *addStrRep,
+34
View File
@@ -1176,6 +1176,40 @@ TclpUtime(
return utime(Tcl_FSGetNativePath(pathPtr), tval);
}
/*
*---------------------------------------------------------------------------
*
* TclpUtime --
*
* Check if the file named in the pathObj is owned by the current
* (effective) user.
*
* Results:
* Boolean: true if the file exists, is accessible and is owned by the
* current user.
*
* Side effects:
* pathObj may be converted to path type.
*
*---------------------------------------------------------------------------
*/
int
TclpFileOwnedByCurrentUser(
Tcl_Interp *interp,
Tcl_Obj *pathObj)
{
Tcl_StatBuf buf;
if (Tcl_FSConvertToPathType(interp, pathObj) != TCL_OK) {
return 0;
}
if (Tcl_FSStat(pathObj, &buf) < 0) {
return 0;
}
return (geteuid() == buf.st_uid);
}
#ifdef __CYGWIN__
int
+32
View File
@@ -3195,6 +3195,38 @@ TclpUtime(
}
return res;
}
/*
*---------------------------------------------------------------------------
*
* TclpUtime --
*
* Check if the file named in the pathObj is owned by the current user.
*
* Results:
* Boolean: true if the file exists, is accessible and is owned by the
* current user. BUG 3613671: not implemented yet.
*
* Side effects:
* pathObj may be converted to path type.
*
*---------------------------------------------------------------------------
*/
int
TclpFileOwnedByCurrentUser(
Tcl_Interp *interp,
Tcl_Obj *pathObj)
{
const Tcl_Filesystem *fsPtr;
if (Tcl_FSConvertToPathType(NULL, pathObj) != TCL_OK) {
return 0;
}
if (Tcl_FSGetFileSystemForPath(pathPtr) != &tclNativeFilesystem) {
return 0;
}
return (NativeAccess(Tcl_FSGetNativePath(pathObj), F_OK) == 0);
}
/*
* Local Variables: