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