int main (int argc, char **argv) { GnomeKeyringResult res; g_test_init (&argc, &argv, NULL); g_set_prgname ("frob-unlock-keyring"); if (argc < 2) { g_printerr ("specify keyring to unlock\n"); return 2; } res = gnome_keyring_unlock_sync (argv[1], NULL); if (res == GNOME_KEYRING_RESULT_OK) { g_printerr ("ok\n"); return 0; } else if (res == GNOME_KEYRING_RESULT_CANCELLED) { g_printerr ("cancel\n"); return 0; } else { g_printerr ("failed: %s\n", gnome_keyring_result_to_message (res)); return 1; } }
int keyring_unlock(char *keyring) { GnomeKeyringInfo *info = NULL; char *password; gnome_keyring_get_info_sync(keyring, &info); if (gnome_keyring_info_get_is_locked(info)) { password = try_secure_alloc(sizeof(char) * PASSWORD_MAX_SIZE); read_password(&password, "Enter the keyring password"); GnomeKeyringResult res = gnome_keyring_unlock_sync(keyring, password); free_password(password); if (res != GNOME_KEYRING_RESULT_OK) { gnome_keyring_info_free(info); return keyring_handle_error(res); } } gnome_keyring_info_free(info); return GNOME_KEYRING_RESULT_OK; }