mirror of https://github.com/djcb/mu.git
* add mu_util_is_local_file, improve mu_util_play:
add some checks whether the file is 'local' or on some remote place (http:// etc.), and explicitly mention what is acceptible in mu_util_play; for security reasons sometimes local, and sometimes remote
This commit is contained in:
parent
f2e8927f6f
commit
5d6fe733a0
|
@ -303,7 +303,23 @@ mu_util_create_writeable_fd (const char* path, mode_t mode,
|
|||
|
||||
|
||||
gboolean
|
||||
mu_util_play (const char *path)
|
||||
mu_util_is_local_file (const char* path)
|
||||
{
|
||||
/* if it starts with file:// it's a local file (for the
|
||||
* purposes of this function -- if it's on a remote FS it's
|
||||
* still considered local) */
|
||||
if (g_ascii_strncasecmp ("file://", path, strlen("file://")) == 0)
|
||||
return TRUE;
|
||||
|
||||
if (access (path, R_OK) == 0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
mu_util_play (const char *path, gboolean allow_local, gboolean allow_remote)
|
||||
{
|
||||
#ifndef XDGOPEN
|
||||
g_warning ("opening files not supported (xdg-open missing)");
|
||||
|
@ -314,8 +330,10 @@ mu_util_play (const char *path)
|
|||
const gchar *argv[3];
|
||||
|
||||
g_return_val_if_fail (path, FALSE);
|
||||
g_return_val_if_fail (access (path, R_OK) == 0, FALSE);
|
||||
|
||||
g_return_val_if_fail (mu_util_is_local_file (path) || allow_remote,
|
||||
FALSE);
|
||||
g_return_val_if_fail (!mu_util_is_local_file (path) || allow_local,
|
||||
FALSE);
|
||||
argv[0] = XDGOPEN;
|
||||
argv[1] = path;
|
||||
argv[2] = NULL;
|
||||
|
|
|
@ -120,15 +120,29 @@ int mu_util_create_writeable_fd (const char* path, mode_t mode,
|
|||
G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* check if file is local, ie. on the local file system. this means
|
||||
* that it's either having a file URI, *or* that it's an existing file
|
||||
*
|
||||
* @param path a path
|
||||
*
|
||||
* @return TRUE if the file is local, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_util_is_local_file (const char* path);
|
||||
|
||||
/**
|
||||
* try to 'play' (ie., open with it's associated program) a
|
||||
* file. depends on xdg-open to do the actual opening
|
||||
*
|
||||
* @param path full path of the file to open
|
||||
* @param allow_local allow local files (ie. with file:// prefix or fs paths)
|
||||
* @param allow_remote allow URIs (ie., http, mailto)
|
||||
*
|
||||
* @return TRUE if it succeeded, FALSE otherwise
|
||||
*/
|
||||
gboolean mu_util_play (const char *path);
|
||||
gboolean mu_util_play (const char *path,
|
||||
gboolean allow_local, gboolean allow_remote);
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue