+static int
+gnutls_AddCADirectory( vlc_object_t *p_this,
+ gnutls_certificate_credentials cred,
+ const char *psz_dirname )
+{
+ DIR* dir;
+ struct dirent *p_ent;
+ int i_len;
+
+ if( *psz_dirname == '\0' )
+ psz_dirname = ".";
+
+ dir = opendir( psz_dirname );
+ if( dir == NULL )
+ {
+ msg_Warn( p_this, "Cannot open directory (%s) : %s", psz_dirname,
+ strerror( errno ) );
+ return VLC_EGENERIC;
+ }
+
+ i_len = strlen( psz_dirname ) + 2;
+
+ while( ( p_ent = readdir( dir ) ) != NULL )
+ {
+ char *psz_filename;
+
+ psz_filename = (char *)malloc( i_len + strlen( p_ent->d_name ) );
+ if( psz_filename == NULL )
+ return VLC_ENOMEM;
+
+ sprintf( psz_filename, "%s/%s", psz_dirname, p_ent->d_name );
+ /* we neglect the race condition here - not security sensitive */
+ if( is_regular( psz_filename ) )
+ {
+ int i;
+
+ i = gnutls_certificate_set_x509_trust_file( cred, psz_filename,
+ GNUTLS_X509_FMT_PEM );
+ if( i < 0 )
+ {
+ msg_Warn( p_this, "Cannot add trusted CA (%s) : %s",
+ psz_filename, gnutls_strerror( i ) );
+ }
+ }
+ free( psz_filename );
+ }
+
+ closedir( dir );
+ return VLC_SUCCESS;
+}
+