7
7
#include "prompt.h"
8
8
#include "sigchain.h"
9
9
#include "urlmatch.h"
10
+ #include "git-compat-util.h"
10
11
11
12
void credential_init (struct credential * c )
12
13
{
@@ -234,6 +235,11 @@ int credential_read(struct credential *c, FILE *fp)
234
235
} else if (!strcmp (key , "path" )) {
235
236
free (c -> path );
236
237
c -> path = xstrdup (value );
238
+ } else if (!strcmp (key , "password_expiry_utc" )) {
239
+ errno = 0 ;
240
+ c -> password_expiry_utc = parse_timestamp (value , NULL , 10 );
241
+ if (c -> password_expiry_utc == 0 || errno == ERANGE )
242
+ c -> password_expiry_utc = TIME_MAX ;
237
243
} else if (!strcmp (key , "url" )) {
238
244
credential_from_url (c , value );
239
245
} else if (!strcmp (key , "quit" )) {
@@ -269,6 +275,11 @@ void credential_write(const struct credential *c, FILE *fp)
269
275
credential_write_item (fp , "path" , c -> path , 0 );
270
276
credential_write_item (fp , "username" , c -> username , 0 );
271
277
credential_write_item (fp , "password" , c -> password , 0 );
278
+ if (c -> password_expiry_utc != TIME_MAX ) {
279
+ char * s = xstrfmt ("%" PRItime , c -> password_expiry_utc );
280
+ credential_write_item (fp , "password_expiry_utc" , s , 0 );
281
+ free (s );
282
+ }
272
283
}
273
284
274
285
static int run_credential_helper (struct credential * c ,
@@ -342,6 +353,12 @@ void credential_fill(struct credential *c)
342
353
343
354
for (i = 0 ; i < c -> helpers .nr ; i ++ ) {
344
355
credential_do (c , c -> helpers .items [i ].string , "get" );
356
+ if (c -> password_expiry_utc < time (NULL )) {
357
+ /* Discard expired password */
358
+ FREE_AND_NULL (c -> password );
359
+ /* Reset expiry to maintain consistency */
360
+ c -> password_expiry_utc = TIME_MAX ;
361
+ }
345
362
if (c -> username && c -> password )
346
363
return ;
347
364
if (c -> quit )
@@ -360,7 +377,7 @@ void credential_approve(struct credential *c)
360
377
361
378
if (c -> approved )
362
379
return ;
363
- if (!c -> username || !c -> password )
380
+ if (!c -> username || !c -> password || c -> password_expiry_utc < time ( NULL ) )
364
381
return ;
365
382
366
383
credential_apply_config (c );
@@ -381,6 +398,7 @@ void credential_reject(struct credential *c)
381
398
382
399
FREE_AND_NULL (c -> username );
383
400
FREE_AND_NULL (c -> password );
401
+ c -> password_expiry_utc = TIME_MAX ;
384
402
c -> approved = 0 ;
385
403
}
386
404
0 commit comments