Created
February 22, 2017 22:18
-
-
Save joshkunz/5a87e8ba51d7d6088e91c9ec24b8ff60 to your computer and use it in GitHub Desktop.
This patch allows you to play any file on your local filesystem (that the MPD server can read) using the `file://` URI syntax.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/client/ClientFile.cxx b/src/client/ClientFile.cxx | |
index 0382789..9c41d2c 100644 | |
--- a/src/client/ClientFile.cxx | |
+++ b/src/client/ClientFile.cxx | |
@@ -33,19 +33,17 @@ Client::AllowFile(Path path_fs) const | |
throw ProtocolError(ACK_ERROR_PERMISSION, "Access denied"); | |
#else | |
- if (uid >= 0 && (uid_t)uid == geteuid()) | |
- /* always allow access if user runs his own MPD | |
- instance */ | |
- return; | |
- | |
- if (uid < 0) | |
- /* unauthenticated client */ | |
- throw ProtocolError(ACK_ERROR_PERMISSION, "Access denied"); | |
- | |
const FileInfo fi(path_fs); | |
- if (fi.GetUid() != (uid_t)uid && (fi.GetMode() & 0444) != 0444) | |
- /* client is not owner */ | |
- throw ProtocolError(ACK_ERROR_PERMISSION, "Access denied"); | |
+ /* Check to see if the MPD process has read privlidges on the | |
+ * requested file. */ | |
+ if ((geteuid() == fi.GetUid() && (fi.GetMode() & 0400) == 0400) || | |
+ (getegid() == fi.GetGid() && (fi.GetMode() & 0040) == 0040) || | |
+ ((fi.GetMode() & 0004) == 0004)) { | |
+ return; | |
+ } | |
+ | |
+ /* otherwise, we can't read these files */ | |
+ throw ProtocolError(ACK_ERROR_PERMISSION, "Access denied"); | |
#endif | |
} | |
diff --git a/src/fs/FileInfo.hxx b/src/fs/FileInfo.hxx | |
index f82da87..ece97a0 100644 | |
--- a/src/fs/FileInfo.hxx | |
+++ b/src/fs/FileInfo.hxx | |
@@ -113,6 +113,10 @@ public: | |
return st.st_uid; | |
} | |
+ gid_t GetGid() const { | |
+ return st.st_gid; | |
+ } | |
+ | |
mode_t GetMode() const { | |
return st.st_mode; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment