playlist_song: add flag "secure"
Optionally allow all local files. "Insecure" mode is used for printing playlists.
This commit is contained in:
parent
5462f34ed0
commit
5274fee8a7
|
@ -747,7 +747,7 @@ handle_load(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|||
{
|
||||
enum playlist_result result;
|
||||
|
||||
result = playlist_open_into_queue(argv[1], &g_playlist);
|
||||
result = playlist_open_into_queue(argv[1], &g_playlist, true);
|
||||
if (result != PLAYLIST_RESULT_NO_SUCH_LIST)
|
||||
return result;
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ playlist_provider_print(struct client *client, const char *uri,
|
|||
char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL;
|
||||
|
||||
while ((song = playlist_plugin_read(playlist)) != NULL) {
|
||||
song = playlist_check_translate_song(song, base_uri);
|
||||
song = playlist_check_translate_song(song, base_uri, false);
|
||||
if (song == NULL)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -27,14 +27,14 @@
|
|||
|
||||
enum playlist_result
|
||||
playlist_load_into_queue(const char *uri, struct playlist_provider *source,
|
||||
struct playlist *dest)
|
||||
struct playlist *dest, bool secure)
|
||||
{
|
||||
enum playlist_result result;
|
||||
struct song *song;
|
||||
char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL;
|
||||
|
||||
while ((song = playlist_plugin_read(source)) != NULL) {
|
||||
song = playlist_check_translate_song(song, base_uri);
|
||||
song = playlist_check_translate_song(song, base_uri, secure);
|
||||
if (song == NULL)
|
||||
continue;
|
||||
|
||||
|
@ -53,7 +53,7 @@ playlist_load_into_queue(const char *uri, struct playlist_provider *source,
|
|||
}
|
||||
|
||||
enum playlist_result
|
||||
playlist_open_into_queue(const char *uri, struct playlist *dest)
|
||||
playlist_open_into_queue(const char *uri, struct playlist *dest, bool secure)
|
||||
{
|
||||
struct input_stream *is;
|
||||
struct playlist_provider *playlist = playlist_open_any(uri, &is);
|
||||
|
@ -61,7 +61,7 @@ playlist_open_into_queue(const char *uri, struct playlist *dest)
|
|||
return PLAYLIST_RESULT_NO_SUCH_LIST;
|
||||
|
||||
enum playlist_result result =
|
||||
playlist_load_into_queue(uri, playlist, dest);
|
||||
playlist_load_into_queue(uri, playlist, dest, secure);
|
||||
playlist_plugin_close(playlist);
|
||||
|
||||
if (is != NULL)
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include "playlist.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct playlist_provider;
|
||||
struct playlist;
|
||||
|
||||
|
@ -38,14 +40,14 @@ struct playlist;
|
|||
*/
|
||||
enum playlist_result
|
||||
playlist_load_into_queue(const char *uri, struct playlist_provider *source,
|
||||
struct playlist *dest);
|
||||
struct playlist *dest, bool secure);
|
||||
|
||||
/**
|
||||
* Opens a playlist with a playlist plugin and append to the specified
|
||||
* play queue.
|
||||
*/
|
||||
enum playlist_result
|
||||
playlist_open_into_queue(const char *uri, struct playlist *dest);
|
||||
playlist_open_into_queue(const char *uri, struct playlist *dest, bool secure);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@ apply_song_metadata(struct song *dest, const struct song *src)
|
|||
}
|
||||
|
||||
struct song *
|
||||
playlist_check_translate_song(struct song *song, const char *base_uri)
|
||||
playlist_check_translate_song(struct song *song, const char *base_uri,
|
||||
bool secure)
|
||||
{
|
||||
struct song *dest;
|
||||
|
||||
|
@ -111,16 +112,17 @@ playlist_check_translate_song(struct song *song, const char *base_uri)
|
|||
? map_uri_fs(base_uri)
|
||||
: map_directory_fs(db_get_root());
|
||||
|
||||
if (prefix == NULL || !g_str_has_prefix(uri, prefix) ||
|
||||
uri[strlen(prefix)] != '/') {
|
||||
if (prefix != NULL && g_str_has_prefix(uri, prefix) &&
|
||||
uri[strlen(prefix)] == '/')
|
||||
uri += strlen(prefix) + 1;
|
||||
else if (!secure) {
|
||||
/* local files must be relative to the music
|
||||
directory */
|
||||
directory when "secure" is enabled */
|
||||
g_free(prefix);
|
||||
song_free(song);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uri += strlen(prefix) + 1;
|
||||
g_free(prefix);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,18 @@
|
|||
#ifndef MPD_PLAYLIST_SONG_H
|
||||
#define MPD_PLAYLIST_SONG_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* Verifies the song, returns NULL if it is unsafe. Translate the
|
||||
* song to a new song object within the database, if it is a local
|
||||
* file. The old song object is freed.
|
||||
*
|
||||
* @param secure if true, then local files are only allowed if they
|
||||
* are relative to base_uri
|
||||
*/
|
||||
struct song *
|
||||
playlist_check_translate_song(struct song *song, const char *base_uri);
|
||||
playlist_check_translate_song(struct song *song, const char *base_uri,
|
||||
bool secure);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue