Skip to content

Commit 7d66334

Browse files
committed
Merge branch 'mh/credential-password-expiry-libsecret' into seen
* mh/credential-password-expiry-libsecret: credential/libsecret: support password_expiry_utc
2 parents b9995e8 + ee925c1 commit 7d66334

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

contrib/credential/libsecret/git-credential-libsecret.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct credential {
3939
char *path;
4040
char *username;
4141
char *password;
42+
char *password_expiry_utc;
4243
};
4344

4445
#define CREDENTIAL_INIT { 0 }
@@ -54,6 +55,20 @@ struct credential_operation {
5455

5556
/* ----------------- Secret Service functions ----------------- */
5657

58+
static const SecretSchema schema = {
59+
"org.git.Password",
60+
SECRET_SCHEMA_NONE,
61+
{
62+
{ "user", SECRET_SCHEMA_ATTRIBUTE_STRING },
63+
{ "object", SECRET_SCHEMA_ATTRIBUTE_STRING },
64+
{ "protocol", SECRET_SCHEMA_ATTRIBUTE_STRING },
65+
{ "port", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
66+
{ "server", SECRET_SCHEMA_ATTRIBUTE_STRING },
67+
{ "password_expiry_utc", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
68+
{ NULL, 0 },
69+
}
70+
};
71+
5772
static char *make_label(struct credential *c)
5873
{
5974
if (c->port)
@@ -78,6 +93,9 @@ static GHashTable *make_attr_list(struct credential *c)
7893
g_hash_table_insert(al, "port", g_strdup_printf("%hu", c->port));
7994
if (c->path)
8095
g_hash_table_insert(al, "object", g_strdup(c->path));
96+
if (c->password_expiry_utc)
97+
g_hash_table_insert(al, "password_expiry_utc",
98+
g_strdup(c->password_expiry_utc));
8199

82100
return al;
83101
}
@@ -101,9 +119,11 @@ static int keyring_get(struct credential *c)
101119

102120
attributes = make_attr_list(c);
103121
items = secret_service_search_sync(service,
104-
SECRET_SCHEMA_COMPAT_NETWORK,
122+
&schema,
105123
attributes,
106-
SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_UNLOCK,
124+
SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_UNLOCK |
125+
// for backwards compatibility
126+
SECRET_SCHEMA_DONT_MATCH_NAME,
107127
NULL,
108128
&error);
109129
g_hash_table_unref(attributes);
@@ -128,6 +148,12 @@ static int keyring_get(struct credential *c)
128148
c->username = g_strdup(s);
129149
}
130150

151+
s = g_hash_table_lookup(attributes, "password_expiry_utc");
152+
if (s) {
153+
g_free(c->password_expiry_utc);
154+
c->password_expiry_utc = g_strdup(s);
155+
}
156+
131157
s = secret_value_get_text(secret);
132158
if (s) {
133159
g_free(c->password);
@@ -162,7 +188,7 @@ static int keyring_store(struct credential *c)
162188

163189
label = make_label(c);
164190
attributes = make_attr_list(c);
165-
secret_password_storev_sync(SECRET_SCHEMA_COMPAT_NETWORK,
191+
secret_password_storev_sync(&schema,
166192
attributes,
167193
NULL,
168194
label,
@@ -198,7 +224,7 @@ static int keyring_erase(struct credential *c)
198224
return EXIT_FAILURE;
199225

200226
attributes = make_attr_list(c);
201-
secret_password_clearv_sync(SECRET_SCHEMA_COMPAT_NETWORK,
227+
secret_password_clearv_sync(&schema,
202228
attributes,
203229
NULL,
204230
&error);
@@ -238,6 +264,7 @@ static void credential_clear(struct credential *c)
238264
g_free(c->path);
239265
g_free(c->username);
240266
g_free(c->password);
267+
g_free(c->password_expiry_utc);
241268

242269
credential_init(c);
243270
}
@@ -285,6 +312,9 @@ static int credential_read(struct credential *c)
285312
} else if (!strcmp(key, "username")) {
286313
g_free(c->username);
287314
c->username = g_strdup(value);
315+
} else if (!strcmp(key, "password_expiry_utc")) {
316+
g_free(c->password_expiry_utc);
317+
c->password_expiry_utc = g_strdup(value);
288318
} else if (!strcmp(key, "password")) {
289319
g_free(c->password);
290320
c->password = g_strdup(value);
@@ -312,9 +342,11 @@ static void credential_write_item(FILE *fp, const char *key, const char *value)
312342

313343
static void credential_write(const struct credential *c)
314344
{
315-
/* only write username/password, if set */
345+
/* only write username/password/expiry, if set */
316346
credential_write_item(stdout, "username", c->username);
317347
credential_write_item(stdout, "password", c->password);
348+
credential_write_item(stdout, "password_expiry_utc",
349+
c->password_expiry_utc);
318350
}
319351

320352
static void usage(const char *name)

0 commit comments

Comments
 (0)