static void credential_find_keystore(vlc_credential *p_credential, vlc_keystore *p_keystore) { const vlc_url_t *p_url = p_credential->p_url; const char *ppsz_values[KEY_MAX] = { 0 }; ppsz_values[KEY_PROTOCOL] = p_url->psz_protocol; ppsz_values[KEY_USER] = p_credential->psz_username; ppsz_values[KEY_SERVER] = p_url->psz_host; /* don't try to match with the path */ ppsz_values[KEY_REALM] = p_credential->psz_realm; ppsz_values[KEY_AUTHTYPE] = p_credential->psz_authtype; char psz_port[21]; if (protocol_set_port(p_url, psz_port)) ppsz_values[KEY_PORT] = psz_port; vlc_keystore_entry *p_entries; unsigned int i_entries_count; i_entries_count = vlc_keystore_find(p_keystore, ppsz_values, &p_entries); /* Remove last entries after vlc_keystore_find call since * p_credential->psz_username (default username) can be a pointer to an * entry */ if (p_credential->i_entries_count > 0) { vlc_keystore_release_entries(p_credential->p_entries, p_credential->i_entries_count); p_credential->psz_username = NULL; } p_credential->p_entries = p_entries; p_credential->i_entries_count = i_entries_count; if (p_credential->i_entries_count > 0) { vlc_keystore_entry *p_entry; if (protocol_store_path(p_url)) p_entry = find_closest_path(p_credential->p_entries, p_credential->i_entries_count, p_url->psz_path); else p_entry = &p_credential->p_entries[0]; if (!p_entry || p_entry->p_secret[p_entry->i_secret_len - 1] != '\0') { vlc_keystore_release_entries(p_credential->p_entries, p_credential->i_entries_count); p_credential->i_entries_count = 0; } else { p_credential->psz_password = (const char *)p_entry->p_secret; p_credential->psz_username = p_entry->ppsz_values[KEY_USER]; p_credential->psz_realm = p_entry->ppsz_values[KEY_REALM]; p_credential->psz_authtype = p_entry->ppsz_values[KEY_AUTHTYPE]; p_credential->b_from_keystore = true; } } }
static unsigned int ks_find(vlc_keystore *p_keystore, const char *const ppsz_values[KEY_MAX], const char* psz_cmp_secret) { vlc_keystore_entry *p_entries; unsigned int i_entries = vlc_keystore_find(p_keystore, ppsz_values, &p_entries); for (unsigned int i = 0; i < i_entries; ++i) { vlc_keystore_entry *p_entry = &p_entries[i]; assert(p_entry->p_secret[p_entry->i_secret_len - 1] == '\0'); assert(strcmp((const char *)p_entry->p_secret, psz_cmp_secret) == 0); for (unsigned int j = 0; j < KEY_MAX; ++j) { const char *psz_value1 = ppsz_values[j]; const char *psz_value2 = p_entry->ppsz_values[j]; if (!psz_value1) continue; assert(psz_value2); assert(strcmp(psz_value1, psz_value2) == 0); } } if (i_entries > 0) vlc_keystore_release_entries(p_entries, i_entries); return i_entries; }
static unsigned int Remove( vlc_keystore* p_keystore, const char* const ppsz_values[KEY_MAX] ) { char* psz_key; vlc_keystore_entry* p_entries; unsigned i_count = 0; psz_key = values2key( ppsz_values, true ); if ( !psz_key ) return 0; p_entries = kwallet_read_password_list( p_keystore, psz_key, &i_count ); if ( !p_entries ) { free( psz_key ); return 0; } free( psz_key ); for ( unsigned int i = 0 ; i < i_count ; ++i ) { psz_key = values2key( ( const char* const* )p_entries[i].ppsz_values, false ); if ( !psz_key ) { vlc_keystore_release_entries( p_entries, i_count ); return i; } if ( kwallet_remove_entry( p_keystore, psz_key ) ) { vlc_keystore_release_entries( p_entries, i_count ); free( psz_key ); return i; } for ( int inc = 0 ; inc < KEY_MAX ; ++inc ) free( p_entries[i].ppsz_values[inc] ); free( p_entries[i].p_secret ); free( psz_key ); } free( p_entries ); return i_count; }
void vlc_credential_clean(vlc_credential *p_credential) { if (p_credential->i_entries_count > 0) vlc_keystore_release_entries(p_credential->p_entries, p_credential->i_entries_count); if (p_credential->p_keystore) vlc_keystore_release(p_credential->p_keystore); free(p_credential->psz_split_domain); free(p_credential->psz_var_username); free(p_credential->psz_var_password); free(p_credential->psz_dialog_username); free(p_credential->psz_dialog_password); }
static vlc_keystore_entry* kwallet_read_password_list( vlc_keystore* p_keystore, char* psz_entry_name, unsigned int* pi_count ) { vlc_keystore_sys* p_sys = p_keystore->p_sys; DBusMessage* msg = NULL; DBusMessage* repmsg = NULL; DBusMessageIter args; DBusMessageIter sub_iter; DBusMessageIter dict_iter; DBusMessageIter var_iter; vlc_keystore_entry* p_entries = NULL; size_t i_size; uint8_t* p_secret_decoded; char* p_reply; char* p_secret; int i = 0; /* init */ *pi_count = 0; if ( !( msg = vlc_dbus_new_method( p_keystore, "readPasswordList" ) ) ) { msg_Err( p_keystore, "kwallet_read_password_list : vlc_dbus_new_method failed" ); goto error; } /* argument init */ dbus_message_iter_init_append( msg, &args ); if ( !dbus_message_iter_append_basic( &args, DBUS_TYPE_INT32, &p_sys->i_handle ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &psz_folder ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &psz_entry_name ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &p_sys->psz_app_id ) ) goto error; /* sending message */ if ( !( repmsg = vlc_dbus_send_message( p_keystore, msg ) ) ) { msg_Err( p_keystore, "kwallet_read_password_list : vlc_dbus_send_message failed" ); goto error; } /* handling reply */ if ( !dbus_message_iter_init( repmsg, &args ) ) { msg_Err( p_keystore, "kwallet_read_password_list : Message has no arguments" ); goto error; } else if ( dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY ) { msg_Err( p_keystore, "kwallet_read_password_list : Wrong reply type" ); goto error; } else { /* calculating p_entries's size */ dbus_message_iter_recurse( &args, &sub_iter ); do { if ( dbus_message_iter_get_arg_type( &sub_iter ) != DBUS_TYPE_DICT_ENTRY ) continue; dbus_message_iter_recurse( &sub_iter, &dict_iter ); if ( dbus_message_iter_get_arg_type( &dict_iter ) != DBUS_TYPE_STRING ) continue; dbus_message_iter_next(&dict_iter); if ( dbus_message_iter_get_arg_type( &dict_iter ) != DBUS_TYPE_VARIANT ) continue; ++( *pi_count ); } while ( dbus_message_iter_next( &sub_iter ) ); if ( *pi_count == 0 ) goto error; if ( !( p_entries = calloc( *pi_count, sizeof( vlc_keystore_entry ) ) ) ) goto error; dbus_message_iter_init( repmsg, &args ); /* recurse into the reply array */ dbus_message_iter_recurse( &args, &sub_iter ); do { if ( dbus_message_iter_get_arg_type( &sub_iter ) != DBUS_TYPE_DICT_ENTRY ) { msg_Err( p_keystore, "Wrong type not DBUS_TYPE_DICT_ENTRY" ); continue; } /* recurse into the dict-entry in the array */ dbus_message_iter_recurse( &sub_iter, &dict_iter ); if ( dbus_message_iter_get_arg_type( &dict_iter ) != DBUS_TYPE_STRING ) { msg_Err( p_keystore, "First type of Dict-Entry is not a string" ); continue; } dbus_message_iter_get_basic( &dict_iter, &p_reply ); dbus_message_iter_next(&dict_iter); if ( dbus_message_iter_get_arg_type( &dict_iter ) != DBUS_TYPE_VARIANT ) { msg_Err( p_keystore, "Second type of Dict-Entry is not a variant" ); continue; } /* recurse into the variant in the dict-entry */ dbus_message_iter_recurse( &dict_iter, &var_iter ); dbus_message_iter_get_basic( &var_iter, &p_secret ); i_size = vlc_b64_decode_binary( &p_secret_decoded, p_secret); if ( key2values( p_reply, &p_entries[i] ) ) goto error; if ( ( vlc_keystore_entry_set_secret( &p_entries[i], p_secret_decoded, i_size ) ) ) goto error; free(p_secret_decoded); i += 1; } while ( dbus_message_iter_next( &sub_iter ) ); } dbus_message_unref( msg ); dbus_message_unref( repmsg ); return p_entries; error: *pi_count = 0; vlc_keystore_release_entries( p_entries, i ); if ( msg ) dbus_message_unref( msg ); if ( repmsg ) dbus_message_unref( repmsg ); return NULL; }