Skip to content

Commit 5a3db11

Browse files
drafnelgitster
authored andcommitted
contrib/git-credential-gnome-keyring.c: support ancient gnome-keyring
The gnome-keyring lib distributed with RHEL 5.X is ancient and does not provide a few of the functions/defines that more recent versions do, but mostly the API is the same. Let's provide the missing bits via macro definitions and function implementation. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 81c57e2 commit 5a3db11

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

contrib/credential/gnome-keyring/git-credential-gnome-keyring.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,66 @@
2828
#include <stdlib.h>
2929
#include <glib.h>
3030
#include <gnome-keyring.h>
31+
32+
#ifdef GNOME_KEYRING_DEFAULT
33+
34+
/* Modern gnome-keyring */
35+
3136
#include <gnome-keyring-memory.h>
3237

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+
3391
/*
3492
* This credential struct and API is simplified from git's credential.{h,c}
3593
*/

0 commit comments

Comments
 (0)