|
28 | 28 | #include <stdlib.h>
|
29 | 29 | #include <glib.h>
|
30 | 30 | #include <gnome-keyring.h>
|
| 31 | + |
| 32 | +#ifdef GNOME_KEYRING_DEFAULT |
| 33 | + |
| 34 | + /* Modern gnome-keyring */ |
| 35 | + |
31 | 36 | #include <gnome-keyring-memory.h>
|
32 | 37 |
|
| 38 | +#else |
| 39 | + |
| 40 | + /* |
| 41 | + * Support ancient gnome-keyring, circ. RHEL 5.X. |
| 42 | + * GNOME_KEYRING_DEFAULT seems to have been introduced with Gnome 2.22, |
| 43 | + * and the other features roughly around Gnome 2.20, 6 months before. |
| 44 | + * Ubuntu 8.04 used Gnome 2.22 (I think). Not sure any distro used 2.20. |
| 45 | + * So the existence/non-existence of GNOME_KEYRING_DEFAULT seems like |
| 46 | + * a decent thing to use as an indicator. |
| 47 | + */ |
| 48 | + |
| 49 | +#define GNOME_KEYRING_DEFAULT NULL |
| 50 | + |
| 51 | +/* |
| 52 | + * ancient gnome-keyring returns DENIED when an entry is not found. |
| 53 | + * Setting NO_MATCH to DENIED will prevent us from reporting DENIED |
| 54 | + * errors during get and erase operations, but we will still report |
| 55 | + * DENIED errors during a store. |
| 56 | + */ |
| 57 | +#define GNOME_KEYRING_RESULT_NO_MATCH GNOME_KEYRING_RESULT_DENIED |
| 58 | + |
| 59 | +#define gnome_keyring_memory_alloc g_malloc |
| 60 | +#define gnome_keyring_memory_free gnome_keyring_free_password |
| 61 | +#define gnome_keyring_memory_strdup g_strdup |
| 62 | + |
| 63 | +static const char* gnome_keyring_result_to_message(GnomeKeyringResult result) |
| 64 | +{ |
| 65 | + switch (result) { |
| 66 | + case GNOME_KEYRING_RESULT_OK: |
| 67 | + return "OK"; |
| 68 | + case GNOME_KEYRING_RESULT_DENIED: |
| 69 | + return "Denied"; |
| 70 | + case GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON: |
| 71 | + return "No Keyring Daemon"; |
| 72 | + case GNOME_KEYRING_RESULT_ALREADY_UNLOCKED: |
| 73 | + return "Already UnLocked"; |
| 74 | + case GNOME_KEYRING_RESULT_NO_SUCH_KEYRING: |
| 75 | + return "No Such Keyring"; |
| 76 | + case GNOME_KEYRING_RESULT_BAD_ARGUMENTS: |
| 77 | + return "Bad Arguments"; |
| 78 | + case GNOME_KEYRING_RESULT_IO_ERROR: |
| 79 | + return "IO Error"; |
| 80 | + case GNOME_KEYRING_RESULT_CANCELLED: |
| 81 | + return "Cancelled"; |
| 82 | + case GNOME_KEYRING_RESULT_ALREADY_EXISTS: |
| 83 | + return "Already Exists"; |
| 84 | + default: |
| 85 | + return "Unknown Error"; |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +#endif |
| 90 | + |
33 | 91 | /*
|
34 | 92 | * This credential struct and API is simplified from git's credential.{h,c}
|
35 | 93 | */
|
|
0 commit comments