コード例 #1
0
gpgme_error_t
gpgmegtk_passphrase_cb(void *opaque, const char *uid_hint,
        const char *passphrase_hint, int prev_bad, int fd)
{
    const char *pass;
#ifdef G_OS_WIN32
    HANDLE hd = (HANDLE)fd;
    DWORD n;
#endif

    if (prefs_common.store_passphrase && last_pass != NULL && !prev_bad) {
#ifdef G_OS_WIN32
        WriteFile(hd, last_pass, strlen(last_pass), &n, NULL);
        WriteFile(hd, "\n", 1, &n, NULL);
#else
        write(fd, last_pass, strlen(last_pass));
        write(fd, "\n", 1);
#endif
        return GPG_ERR_NO_ERROR;
    }
    gpgmegtk_set_passphrase_grab (prefs_common.passphrase_grab);
    debug_print ("%% requesting passphrase for `%s':\n", uid_hint);
    pass = passphrase_mbox (uid_hint, passphrase_hint, prev_bad);
    gpgmegtk_free_passphrase();
    if (!pass) {
        debug_print ("%% cancel passphrase entry\n");
#ifdef G_OS_WIN32
        WriteFile(hd, "\n", 1, &n, NULL);
        CloseHandle(hd); /* somehow it will block without this */
#else
        write(fd, "\n", 1);
#endif
        return GPG_ERR_CANCELED;
    }
    else {
        if (prefs_common.store_passphrase) {
            last_pass = g_strdup(pass);
#if HAVE_MLOCK
            if (mlock(last_pass, strlen(last_pass)) == -1)
                debug_print("%% locking passphrase failed\n");
#endif

            if (prefs_common.store_passphrase_timeout > 0) {
                g_timeout_add_full(G_PRIORITY_LOW, prefs_common.store_passphrase_timeout * 60 * 1000, free_passphrase, NULL, NULL);
            }
        }
        debug_print ("%% sending passphrase\n");
    }
#ifdef G_OS_WIN32
    WriteFile(hd, pass, strlen(pass), &n, NULL);
    WriteFile(hd, "\n", 1, &n, NULL);
#else
    write(fd, pass, strlen(pass));
    write(fd, "\n", 1);
#endif
    return GPG_ERR_NO_ERROR;
}
コード例 #2
0
ファイル: passphrase.c プロジェクト: moreorless/claws-mail
const char*
gpgmegtk_passphrase_cb (void *opaque, const char *desc, void **r_hd)
{
    struct passphrase_cb_info_s *info = opaque;
    GpgmeCtx ctx = info ? info->c : NULL;
    const char *pass;

    if (!desc) {
        /* FIXME: cleanup by looking at *r_hd */
        return NULL;
    }
    if (prefs_gpg_get_config()->store_passphrase && last_pass != NULL &&
        strncmp(desc, "TRY_AGAIN", 9) != 0)
        return g_strdup(last_pass);

    gpgmegtk_set_passphrase_grab (prefs_gpg_get_config()->passphrase_grab);
    debug_print ("%% requesting passphrase for `%s': ", desc);
    pass = passphrase_mbox (desc);
    gpgmegtk_free_passphrase();
    if (!pass) {
        debug_print ("%% cancel passphrase entry");
        gpgme_cancel (ctx);
    }
    else {
        if (prefs_gpg_get_config()->store_passphrase) {
            last_pass = g_strdup(pass);
            if (mlock(last_pass, strlen(last_pass)) == -1)
                debug_print("%% locking passphrase failed");

            if (prefs_gpg_get_config()->store_passphrase_timeout > 0) {
                gtk_timeout_add(prefs_gpg_get_config()->store_passphrase_timeout*60*1000,
                                free_passphrase, NULL);
            }
        }
        debug_print ("%% sending passphrase");
    }

    return pass;
}