I would like to be able to add a song to the playlist that resides outside of the configured music_directory.
The problem I'm running into is that when I call mpd_run_add(conn, "/path/to/song.mp3"), I see an "Access denied" error.
I dug into why this error occurs in the MPD codebase. In handle_add(), the function that processes the add command, one of the first things we do is locate the URI of the file. As part of locating the URI, if we determine the file is not relative to the MPD database, we ensure that the client is authenticated by checking the UID (In Client::AllowFile()):
Code: Select all
if (uid < 0)
/* unauthenticated client */
throw ProtocolError(ACK_ERROR_PERMISSION, "Access denied");
So I continued digging into how the uid field gets set and it comes from the file descriptor of the socket MPD is using to communicate with the client. From ServerSocket.cxx:
Code: Select all
static int
get_remote_uid(int fd)
{
#ifdef HAVE_STRUCT_UCRED
struct ucred cred;
socklen_t len = sizeof (cred);
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0)
return -1;
return cred.uid;
#else
I think I've read through all of the relevant docs for libmpdclient and I've looked through code as well but I'm struggling to understand how to get it to set up the file descriptor such that the MPD server gets the correct UID from it. Does anyone know what I might be doing wrong or misunderstanding? I'm connecting via mpd_connection_new("127.0.0.1", 6600, 0);