77#include "prompt.h"
88#include "sigchain.h"
99#include "urlmatch.h"
10+ #include "git-compat-util.h"
1011
1112void credential_init (struct credential * c )
1213{
@@ -234,6 +235,11 @@ int credential_read(struct credential *c, FILE *fp)
234235 } else if (!strcmp (key , "path" )) {
235236 free (c -> path );
236237 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 ;
237243 } else if (!strcmp (key , "url" )) {
238244 credential_from_url (c , value );
239245 } else if (!strcmp (key , "quit" )) {
@@ -269,6 +275,11 @@ void credential_write(const struct credential *c, FILE *fp)
269275 credential_write_item (fp , "path" , c -> path , 0 );
270276 credential_write_item (fp , "username" , c -> username , 0 );
271277 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+ }
272283}
273284
274285static int run_credential_helper (struct credential * c ,
@@ -342,6 +353,12 @@ void credential_fill(struct credential *c)
342353
343354 for (i = 0 ; i < c -> helpers .nr ; i ++ ) {
344355 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+ }
345362 if (c -> username && c -> password )
346363 return ;
347364 if (c -> quit )
@@ -360,7 +377,7 @@ void credential_approve(struct credential *c)
360377
361378 if (c -> approved )
362379 return ;
363- if (!c -> username || !c -> password )
380+ if (!c -> username || !c -> password || c -> password_expiry_utc < time ( NULL ) )
364381 return ;
365382
366383 credential_apply_config (c );
@@ -381,6 +398,7 @@ void credential_reject(struct credential *c)
381398
382399 FREE_AND_NULL (c -> username );
383400 FREE_AND_NULL (c -> password );
401+ c -> password_expiry_utc = TIME_MAX ;
384402 c -> approved = 0 ;
385403}
386404
0 commit comments