@@ -39,6 +39,7 @@ struct credential {
39
39
char * path ;
40
40
char * username ;
41
41
char * password ;
42
+ char * password_expiry_utc ;
42
43
};
43
44
44
45
#define CREDENTIAL_INIT { 0 }
@@ -54,6 +55,20 @@ struct credential_operation {
54
55
55
56
/* ----------------- Secret Service functions ----------------- */
56
57
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
+
57
72
static char * make_label (struct credential * c )
58
73
{
59
74
if (c -> port )
@@ -78,6 +93,9 @@ static GHashTable *make_attr_list(struct credential *c)
78
93
g_hash_table_insert (al , "port" , g_strdup_printf ("%hu" , c -> port ));
79
94
if (c -> path )
80
95
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 ));
81
99
82
100
return al ;
83
101
}
@@ -101,9 +119,11 @@ static int keyring_get(struct credential *c)
101
119
102
120
attributes = make_attr_list (c );
103
121
items = secret_service_search_sync (service ,
104
- SECRET_SCHEMA_COMPAT_NETWORK ,
122
+ & schema ,
105
123
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 ,
107
127
NULL ,
108
128
& error );
109
129
g_hash_table_unref (attributes );
@@ -128,6 +148,12 @@ static int keyring_get(struct credential *c)
128
148
c -> username = g_strdup (s );
129
149
}
130
150
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
+
131
157
s = secret_value_get_text (secret );
132
158
if (s ) {
133
159
g_free (c -> password );
@@ -162,7 +188,7 @@ static int keyring_store(struct credential *c)
162
188
163
189
label = make_label (c );
164
190
attributes = make_attr_list (c );
165
- secret_password_storev_sync (SECRET_SCHEMA_COMPAT_NETWORK ,
191
+ secret_password_storev_sync (& schema ,
166
192
attributes ,
167
193
NULL ,
168
194
label ,
@@ -198,7 +224,7 @@ static int keyring_erase(struct credential *c)
198
224
return EXIT_FAILURE ;
199
225
200
226
attributes = make_attr_list (c );
201
- secret_password_clearv_sync (SECRET_SCHEMA_COMPAT_NETWORK ,
227
+ secret_password_clearv_sync (& schema ,
202
228
attributes ,
203
229
NULL ,
204
230
& error );
@@ -238,6 +264,7 @@ static void credential_clear(struct credential *c)
238
264
g_free (c -> path );
239
265
g_free (c -> username );
240
266
g_free (c -> password );
267
+ g_free (c -> password_expiry_utc );
241
268
242
269
credential_init (c );
243
270
}
@@ -285,6 +312,9 @@ static int credential_read(struct credential *c)
285
312
} else if (!strcmp (key , "username" )) {
286
313
g_free (c -> username );
287
314
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 );
288
318
} else if (!strcmp (key , "password" )) {
289
319
g_free (c -> password );
290
320
c -> password = g_strdup (value );
@@ -312,9 +342,11 @@ static void credential_write_item(FILE *fp, const char *key, const char *value)
312
342
313
343
static void credential_write (const struct credential * c )
314
344
{
315
- /* only write username/password, if set */
345
+ /* only write username/password/expiry , if set */
316
346
credential_write_item (stdout , "username" , c -> username );
317
347
credential_write_item (stdout , "password" , c -> password );
348
+ credential_write_item (stdout , "password_expiry_utc" ,
349
+ c -> password_expiry_utc );
318
350
}
319
351
320
352
static void usage (const char * name )
0 commit comments