Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooked stream_metadata(..) with chown(..). #4027

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions hphp/runtime/base/user-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,5 +518,39 @@ bool UserFile::touch(const String& path, int64_t mtime, int64_t atime) {
return false;
}

bool UserFile::chown(const String& path, const Variant& user) {
bool invoked = false;
Variant ret;
PackedArrayInit init(3);
init.append(path);
if (user.isString()) {
init
.append(2) // STREAM_META_OWNER_NAME
.append(user.toString());
ret = invoke(
m_StreamMetadata,
s_stream_metadata,
init.toArray(),
invoked
);
} else {
init
.append(3) // STREAM_META_OWNER
.append(user.toInt32());
ret = invoke(
m_StreamMetadata,
s_stream_metadata,
init.toArray(),
invoked
);
}
if (invoked && ret.toBoolean() == true) {
return true;
}

raise_warning("\"%s::chown\" call failed", m_cls->name()->data());
return false;
}

///////////////////////////////////////////////////////////////////////////////
}
1 change: 1 addition & 0 deletions hphp/runtime/base/user-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class UserFile : public File, public UserFSNode {
bool mkdir(const String& path, int mode, int options);
bool rmdir(const String& path, int options);
bool touch(const String& path, int64_t mtime, int64_t atime);
bool chown(const String& path, const Variant& user);

private:
int urlStat(const String& path, struct stat* stat_sb, int flags = 0);
Expand Down
9 changes: 9 additions & 0 deletions hphp/runtime/base/user-stream-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,21 @@ Directory* UserStreamWrapper::opendir(const String& path) {
return dir;
}

///////////////////////////////////////////////////////////////////////////////
// non-generic functions

bool UserStreamWrapper::touch(const String& path,
int64_t mtime, int64_t atime) {
auto file = NEWOBJ(UserFile)(m_cls);
Resource wrapper(file);
return file->touch(path, mtime, atime);
}

bool UserStreamWrapper::chown(const String& path, const Variant& user) {
auto file = NEWOBJ(UserFile)(m_cls);
Resource wrapper(file);
return file->chown(path, user);
}

///////////////////////////////////////////////////////////////////////////////
}
1 change: 1 addition & 0 deletions hphp/runtime/base/user-stream-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct UserStreamWrapper final : Stream::Wrapper {
int rmdir(const String& path, int options) override;
Directory* opendir(const String& path) override;
bool touch(const String& path, int64_t mtime, int64_t atime);
bool chown(const String& path, const Variant& user);

private:
String m_name;
Expand Down
7 changes: 7 additions & 0 deletions hphp/runtime/ext/ext_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,13 @@ static int get_uid(const Variant& user) {

bool f_chown(const String& filename, const Variant& user) {
CHECK_PATH_FALSE(filename, 1);

Stream::Wrapper* w = Stream::getWrapperFromURI(filename);
auto usw = dynamic_cast<UserStreamWrapper*>(w);
if (usw != nullptr) {
return usw->chown(filename, user);
}

int uid = get_uid(user);
if (uid == 0) return false;
CHECK_SYSTEM(chown(File::TranslatePath(filename).data(), uid, (gid_t)-1));
Expand Down
2 changes: 1 addition & 1 deletion hphp/test/frameworks/results/vfsstream.expect
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ org\bovigo\vfs\vfsStreamWrapperTestCase::chmod
org\bovigo\vfs\vfsStreamWrapperTestCase::chmodModifiesPermissions
F
org\bovigo\vfs\vfsStreamWrapperTestCase::chownChangesUser
F
.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinxucs: I think I missed this in f87415e, do you want to send PR? Also chgrp (and maybe some other as well?) may be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Majkl578 Almost forgot. Thanks for reminding me of that!

org\bovigo\vfs\vfsStreamWrapperTestCase::chownDoesNotWorkOnVfsStreamUrls
.
org\bovigo\vfs\vfsStreamWrapperTestCase::directoriesAndNonExistingFilesAreNeverExecutable
Expand Down