Example #1
0
void
libvlc_InternalKeystoreClean(libvlc_int_t *p_libvlc)
{
    assert(p_libvlc != NULL);
    libvlc_priv_t *p_priv = libvlc_priv(p_libvlc);

    if (p_priv->p_memory_keystore != NULL)
    {
        vlc_keystore_release(p_priv->p_memory_keystore);
        p_priv->p_memory_keystore = NULL;
    }
}
Example #2
0
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);
}
Example #3
0
static void
test_module(const char *psz_module, bool b_test_all, bool b_persistent,
            int argc, const char * const *argv)
{
#define VALUES_INSERT(i_key, psz_value) ppsz_values[i_key] = psz_value
#define VALUES_REINIT() values_reinit(ppsz_values)
#define KS_FIND() do { \
    i_entries = ks_find(p_keystore, ppsz_values, psz_secret); \
} while (0)
#define KS_REMOVE() do { \
    i_entries = ks_remove(p_keystore, ppsz_values); \
} while(0)
#define KS_STORE() ks_store(p_keystore, ppsz_values, (const uint8_t *)psz_secret, -1)

    printf("\n== Testing %s keystore module ==\n\n", psz_module);

    printf("creating libvlc\n");
    libvlc_instance_t *p_libvlc = libvlc_new(argc, argv);
    assert(p_libvlc != NULL);

    vlc_interrupt_t *ctx = vlc_interrupt_create();
    assert(ctx != NULL);

    printf("creating %s keystore\n", psz_module);
    vlc_keystore *p_keystore = vlc_keystore_create(p_libvlc->p_libvlc_int);
    assert(p_keystore);

    const char *psz_secret = "libvlc test secret";
    unsigned int i_entries;
    const char *ppsz_values[KEY_MAX];

    printf("testing that there is no entry\n");
    VALUES_REINIT();
    VALUES_INSERT(KEY_PROTOCOL, "http");
    VALUES_INSERT(KEY_SERVER, "www.example.com");
    VALUES_INSERT(KEY_PATH, "/example/example.mkv");
    VALUES_INSERT(KEY_PORT, "88");
    VALUES_INSERT(KEY_USER, "user1");
    KS_FIND();
    assert(i_entries == 0);

    printf("testing adding an entry\n");
    KS_STORE();
    KS_FIND();
    assert(i_entries == 1);

    printf("testing adding an other entry\n");
    VALUES_INSERT(KEY_USER, "user2");
    KS_FIND();
    assert(i_entries == 0);
    KS_STORE();
    KS_FIND();
    assert(i_entries == 1);

    printf("testing finding the 2 previous entries\n");
    VALUES_INSERT(KEY_USER, NULL);
    KS_FIND();
    assert(i_entries == 2);

    printf("testing that we can't store 2 duplicate entries\n");
    VALUES_INSERT(KEY_USER, "user2");
    KS_STORE();
    VALUES_INSERT(KEY_USER, NULL);
    KS_FIND();
    assert(i_entries == 2);

    if (b_persistent)
    {
        printf("testing that entries are still present after a module unload\n");
        vlc_keystore_release(p_keystore);
        p_keystore = vlc_keystore_create(p_libvlc->p_libvlc_int);
        assert(p_keystore);
        KS_FIND();
        assert(i_entries == 2);
    }

    VALUES_REINIT();
    VALUES_INSERT(KEY_PROTOCOL, "smb");
    VALUES_INSERT(KEY_SERVER, "example");
    VALUES_INSERT(KEY_PATH, "/example.mkv");
    VALUES_INSERT(KEY_USER, "user1");

    if (b_persistent)
    {
        printf("testing adding a third entry from a second running instance\n");

        KS_FIND();
        assert(i_entries == 0);

        vlc_keystore *old_keystore = p_keystore;
        p_keystore = vlc_keystore_create(p_libvlc->p_libvlc_int);
        assert(p_keystore);

        KS_STORE();
        KS_FIND();
        assert(i_entries == 1);

        vlc_keystore_release(p_keystore);
        p_keystore = old_keystore;
        KS_FIND();
        assert(i_entries == 1);
    }
    else
    {
        printf("testing adding a third entry\n");
        KS_FIND();
        assert(i_entries == 0);
        KS_STORE();
        KS_FIND();
        assert(i_entries == 1);
    }


    printf("testing adding a fourth entry (without user/path)\n");
    VALUES_REINIT();
    VALUES_INSERT(KEY_PROTOCOL, "ftp");
    VALUES_INSERT(KEY_SERVER, "example.com");
    KS_FIND();
    assert(i_entries == 0);
    KS_STORE();
    KS_FIND();
    assert(i_entries == 1);

    printf("testing finding an entry only by its protocol\n");
    VALUES_REINIT();
    VALUES_INSERT(KEY_PROTOCOL, "smb");
    KS_FIND();
    assert(i_entries == 1);
    VALUES_REINIT();
    VALUES_INSERT(KEY_PROTOCOL, "http");
    KS_FIND();
    assert(i_entries == 2);
    VALUES_REINIT();
    VALUES_INSERT(KEY_PROTOCOL, "ftp");
    KS_FIND();
    assert(i_entries == 1);

    printf("testing finding all previous entries\n");
    VALUES_REINIT();
    KS_FIND();
    assert(i_entries == 4);

    if (b_test_all && b_persistent)
    {
        printf("\nPress ENTER to remove entries\n");
        getchar();
    }

    printf("testing removing entries that match user => user1\n");
    VALUES_REINIT();
    VALUES_INSERT(KEY_USER, "user1");
    KS_REMOVE();
    assert(i_entries == 2);

    printf("testing removing entries that match user => user2\n");
    VALUES_INSERT(KEY_USER, "user2");
    KS_REMOVE();
    assert(i_entries == 1);

    printf("testing removing entries that match protocol => ftp\n");
    VALUES_REINIT();
    VALUES_INSERT(KEY_PROTOCOL, "ftp");
    KS_REMOVE();
    assert(i_entries == 1);

    printf("testing that all entries are deleted\n");
    VALUES_REINIT();
    KS_FIND();
    assert(i_entries == 0);

    vlc_keystore_release(p_keystore);

    vlc_interrupt_destroy(ctx);

    libvlc_release(p_libvlc);
}