Commit 8172a7de authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Add mode parameter to utf8_mkdir, and stop creating configuration

directories as world-writable - fixes #1306
parent 942772a0
......@@ -45,7 +45,7 @@ VLC_EXPORT( DIR *, utf8_opendir, ( const char *dirname ) );
VLC_EXPORT( char *, utf8_readdir, ( DIR *dir ) );
VLC_EXPORT( int, utf8_loaddir, ( DIR *dir, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) ) );
VLC_EXPORT( int, utf8_scandir, ( const char *dirname, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) ) );
VLC_EXPORT( int, utf8_mkdir, ( const char *filename ) );
VLC_EXPORT( int, utf8_mkdir, ( const char *filename, mode_t mode ) );
#ifdef WIN32
# define stat _stati64
......
......@@ -597,7 +597,7 @@ gnutls_Addx509Directory( vlc_object_t *p_this,
msg_Dbg (p_this, "creating empty certificate directory: %s",
psz_dirname);
utf8_mkdir (psz_dirname);
utf8_mkdir (psz_dirname, b_priv ? 0700 : 0755);
return VLC_SUCCESS;
}
#ifdef S_ISLNK
......
......@@ -222,12 +222,9 @@ int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item )
return i_ret;
}
#ifndef MAX_PATH
# define MAX_PATH 250
#endif
static void ArtCacheCreateDir( const char *psz_dir )
{
char newdir[MAX_PATH+1];
char newdir[strlen( psz_dir ) + 1];
strcpy( newdir, psz_dir );
char * psz_newdir = newdir;
char * psz = psz_newdir;
......@@ -237,11 +234,12 @@ static void ArtCacheCreateDir( const char *psz_dir )
while( *psz && *psz != DIR_SEP_CHAR) psz++;
if( !*psz ) break;
*psz = 0;
if( !EMPTY_STR( psz_newdir ) ) utf8_mkdir( psz_newdir );
if( !EMPTY_STR( psz_newdir ) )
utf8_mkdir( psz_newdir, 0700 );
*psz = DIR_SEP_CHAR;
psz++;
}
utf8_mkdir( psz_dir );
utf8_mkdir( psz_dir, 0700 );
}
static char * ArtCacheGetSanitizedFileName( const char *psz )
......@@ -273,7 +271,7 @@ static void __ArtCacheGetDirPath( vlc_object_t *p_obj,
char * psz_album_sanitized = ArtCacheGetSanitizedFileName( psz_album );
char * psz_artist_sanitized = ArtCacheGetSanitizedFileName( psz_artist );
snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP
snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
"art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s",
p_obj->p_libvlc->psz_cachedir,
psz_artist_sanitized, psz_album_sanitized );
......@@ -283,7 +281,7 @@ static void __ArtCacheGetDirPath( vlc_object_t *p_obj,
else
{
char * psz_title_sanitized = ArtCacheGetSanitizedFileName( psz_title );
snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP
snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
"art" DIR_SEP "title" DIR_SEP "%s",
p_obj->p_libvlc->psz_cachedir,
psz_title_sanitized );
......@@ -300,7 +298,7 @@ static void __ArtCacheGetFilePath( vlc_object_t *p_obj,
const char *psz_artist, const char *psz_album,
const char *psz_extension )
{
char psz_dir[MAX_PATH+1];
char psz_dir[PATH_MAX+1];
char * psz_ext;
ArtCacheGetDirPath( p_obj, psz_dir, psz_title, psz_artist, psz_album );
......@@ -311,7 +309,7 @@ static void __ArtCacheGetFilePath( vlc_object_t *p_obj,
}
else psz_ext = strdup( "" );
snprintf( psz_filename, MAX_PATH, "file://%s" DIR_SEP "art%s",
snprintf( psz_filename, PATH_MAX, "file://%s" DIR_SEP "art%s",
psz_dir, psz_ext );
free( psz_ext );
......@@ -322,8 +320,8 @@ static int __input_FindArtInCache( vlc_object_t *p_obj, input_item_t *p_item )
char *psz_artist;
char *psz_album;
char *psz_title;
char psz_dirpath[MAX_PATH+1];
char psz_filepath[MAX_PATH+1];
char psz_dirpath[PATH_MAX+1];
char psz_filepath[PATH_MAX+1];
char * psz_filename;
DIR * p_dir;
......@@ -356,7 +354,7 @@ static int __input_FindArtInCache( vlc_object_t *p_obj, input_item_t *p_item )
{
if( !strncmp( psz_filename, "art", 3 ) )
{
snprintf( psz_filepath, MAX_PATH, "file://%s" DIR_SEP "%s",
snprintf( psz_filepath, PATH_MAX, "file://%s" DIR_SEP "%s",
psz_dirpath, psz_filename );
input_item_SetArtURL( p_item, psz_filepath );
free( psz_filename );
......@@ -379,7 +377,7 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item )
{
int i_status = VLC_EGENERIC;
stream_t *p_stream;
char psz_filename[MAX_PATH+1];
char psz_filename[PATH_MAX+1];
char *psz_artist = NULL;
char *psz_album = NULL;
char *psz_title = NULL;
......@@ -480,7 +478,7 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
char *psz_album = NULL;
char *psz_title = NULL;
char *psz_type = NULL;
char psz_filename[MAX_PATH+1];
char psz_filename[PATH_MAX+1];
FILE *f;
input_attachment_t *p_attachment;
struct stat s;
......
......@@ -1047,32 +1047,35 @@ int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname )
{
if( !psz_dirname && !*psz_dirname ) return -1;
if( utf8_mkdir( psz_dirname ) && ( errno != EEXIST ) )
if( utf8_mkdir( psz_dirname, 0700 ) == 0 )
return 0;
switch( errno )
{
if( errno == ENOENT )
case EEXIST:
return 0;
case ENOENT:
{
/* Let's try to create the parent directory */
char *psz_parent = strdup( psz_dirname );
char *psz_end = strrchr( psz_parent, DIR_SEP_CHAR );
char psz_parent[strlen( psz_dirname ) + 1], *psz_end;
strcpy( psz_parent, psz_dirname );
psz_end = strrchr( psz_parent, DIR_SEP_CHAR );
if( psz_end && psz_end != psz_parent )
{
*psz_end = '\0';
if( config_CreateDir( p_this, psz_parent ) == 0 )
{
if( !utf8_mkdir( psz_dirname ) )
{
free( psz_parent );
if( !utf8_mkdir( psz_dirname, 0755 ) )
return 0;
}
}
}
free( psz_parent );
}
msg_Err( p_this, "could not create %s: %m", psz_dirname );
return -1;
}
return 0;
msg_Err( p_this, "could not create %s: %m", psz_dirname );
return -1;
}
/*****************************************************************************
......
......@@ -325,7 +325,7 @@ FILE *utf8_fopen (const char *filename, const char *mode)
* @return A 0 return value indicates success. A -1 return value indicates an
* error, and an error code is stored in errno
*/
int utf8_mkdir( const char *dirname )
int utf8_mkdir( const char *dirname, mode_t mode )
{
#if defined (UNDER_CE) || defined (WIN32)
wchar_t wname[MAX_PATH + 1];
......@@ -372,7 +372,7 @@ int utf8_mkdir( const char *dirname )
errno = ENOENT;
return -1;
}
res = mkdir( locname, 0755 );
res = mkdir( locname, mode );
LocaleFree( locname );
return res;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment