Fossil SCM

Add the "fossil remote scrub" command. Prompt for missing passwords on auxiliary remotes when they are needed.

drh 2021-10-25 09:22 trunk
Commit 7f2e34c5c4498b54dfa001b9f59554a673081084b21edd672b5ec1551c91b33a
3 files changed +29 -2 +1 -1 -4
+29 -2
--- src/sync.c
+++ src/sync.c
@@ -69,14 +69,25 @@
6969
azOther = fossil_realloc(azOther, sizeof(*azOther)*(nOther+1));
7070
azOther[nOther++] = fossil_strdup(zUrl);
7171
}
7272
db_finalize(&q);
7373
for(i=0; i<nOther; i++){
74
+ int rc;
7475
url_unparse(&g.url);
75
- url_parse(azOther[i], URL_PROMPT_PW);
76
+ url_parse(azOther[i], URL_PROMPT_PW|URL_ASK_REMEMBER_PW);
7677
sync_explain(syncFlags);
77
- nErr += client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
78
+ rc = client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
79
+ nErr += rc;
80
+ if( (g.url.flags & URL_REMEMBER_PW)!=0 && rc==0 ){
81
+ char *zKey = mprintf("sync-pw:%s", azOther[i]);
82
+ char *zPw = obscure(g.url.passwd);
83
+ if( zPw && zPw[0] ){
84
+ db_set(zKey/*works-like:""*/, zPw, 0);
85
+ }
86
+ fossil_free(zPw);
87
+ fossil_free(zKey);
88
+ }
7889
fossil_free(azOther[i]);
7990
azOther[i] = 0;
8091
}
8192
fossil_free(azOther);
8293
return nErr;
@@ -466,10 +477,16 @@
466477
** "fossil remote NAME" to select a previously-set named URL.
467478
**
468479
** To disable use of the default remote without forgetting its URL,
469480
** say "fossil set autosync 0" instead.
470481
**
482
+** > fossil remote scrub
483
+**
484
+** Forget any saved passwords for remote repositories, but continue
485
+** to remember the URLs themselves. You will be prompted for the
486
+** password the next time it is needed.
487
+**
471488
** > fossil remote REF
472489
**
473490
** Make REF the new default URL, replacing the prior default.
474491
** REF may be a URL or a NAME from a prior "add".
475492
*/
@@ -559,10 +576,20 @@
559576
db_multi_exec("DELETE FROM config WHERE name glob 'sync-url:%q'", zName);
560577
db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:%q'", zName);
561578
db_protect_pop();
562579
db_commit_transaction();
563580
return;
581
+ }
582
+ if( strncmp(zArg, "scrub", nArg)==0 ){
583
+ if( g.argc!=3 ) usage("scrub");
584
+ db_begin_write();
585
+ db_unprotect(PROTECT_CONFIG);
586
+ db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:*'");
587
+ db_multi_exec("DELETE FROM config WHERE name = 'last-sync-pw'");
588
+ db_protect_pop();
589
+ db_commit_transaction();
590
+ return;
564591
}
565592
if( sqlite3_strlike("http://%",zArg,0)==0
566593
|| sqlite3_strlike("https://%",zArg,0)==0
567594
|| sqlite3_strlike("ssh:%",zArg,0)==0
568595
|| sqlite3_strlike("file:%",zArg,0)==0
569596
--- src/sync.c
+++ src/sync.c
@@ -69,14 +69,25 @@
69 azOther = fossil_realloc(azOther, sizeof(*azOther)*(nOther+1));
70 azOther[nOther++] = fossil_strdup(zUrl);
71 }
72 db_finalize(&q);
73 for(i=0; i<nOther; i++){
 
74 url_unparse(&g.url);
75 url_parse(azOther[i], URL_PROMPT_PW);
76 sync_explain(syncFlags);
77 nErr += client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
 
 
 
 
 
 
 
 
 
 
78 fossil_free(azOther[i]);
79 azOther[i] = 0;
80 }
81 fossil_free(azOther);
82 return nErr;
@@ -466,10 +477,16 @@
466 ** "fossil remote NAME" to select a previously-set named URL.
467 **
468 ** To disable use of the default remote without forgetting its URL,
469 ** say "fossil set autosync 0" instead.
470 **
 
 
 
 
 
 
471 ** > fossil remote REF
472 **
473 ** Make REF the new default URL, replacing the prior default.
474 ** REF may be a URL or a NAME from a prior "add".
475 */
@@ -559,10 +576,20 @@
559 db_multi_exec("DELETE FROM config WHERE name glob 'sync-url:%q'", zName);
560 db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:%q'", zName);
561 db_protect_pop();
562 db_commit_transaction();
563 return;
 
 
 
 
 
 
 
 
 
 
564 }
565 if( sqlite3_strlike("http://%",zArg,0)==0
566 || sqlite3_strlike("https://%",zArg,0)==0
567 || sqlite3_strlike("ssh:%",zArg,0)==0
568 || sqlite3_strlike("file:%",zArg,0)==0
569
--- src/sync.c
+++ src/sync.c
@@ -69,14 +69,25 @@
69 azOther = fossil_realloc(azOther, sizeof(*azOther)*(nOther+1));
70 azOther[nOther++] = fossil_strdup(zUrl);
71 }
72 db_finalize(&q);
73 for(i=0; i<nOther; i++){
74 int rc;
75 url_unparse(&g.url);
76 url_parse(azOther[i], URL_PROMPT_PW|URL_ASK_REMEMBER_PW);
77 sync_explain(syncFlags);
78 rc = client_sync(syncFlags, configRcvMask, configSendMask, zAltPCode);
79 nErr += rc;
80 if( (g.url.flags & URL_REMEMBER_PW)!=0 && rc==0 ){
81 char *zKey = mprintf("sync-pw:%s", azOther[i]);
82 char *zPw = obscure(g.url.passwd);
83 if( zPw && zPw[0] ){
84 db_set(zKey/*works-like:""*/, zPw, 0);
85 }
86 fossil_free(zPw);
87 fossil_free(zKey);
88 }
89 fossil_free(azOther[i]);
90 azOther[i] = 0;
91 }
92 fossil_free(azOther);
93 return nErr;
@@ -466,10 +477,16 @@
477 ** "fossil remote NAME" to select a previously-set named URL.
478 **
479 ** To disable use of the default remote without forgetting its URL,
480 ** say "fossil set autosync 0" instead.
481 **
482 ** > fossil remote scrub
483 **
484 ** Forget any saved passwords for remote repositories, but continue
485 ** to remember the URLs themselves. You will be prompted for the
486 ** password the next time it is needed.
487 **
488 ** > fossil remote REF
489 **
490 ** Make REF the new default URL, replacing the prior default.
491 ** REF may be a URL or a NAME from a prior "add".
492 */
@@ -559,10 +576,20 @@
576 db_multi_exec("DELETE FROM config WHERE name glob 'sync-url:%q'", zName);
577 db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:%q'", zName);
578 db_protect_pop();
579 db_commit_transaction();
580 return;
581 }
582 if( strncmp(zArg, "scrub", nArg)==0 ){
583 if( g.argc!=3 ) usage("scrub");
584 db_begin_write();
585 db_unprotect(PROTECT_CONFIG);
586 db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:*'");
587 db_multi_exec("DELETE FROM config WHERE name = 'last-sync-pw'");
588 db_protect_pop();
589 db_commit_transaction();
590 return;
591 }
592 if( sqlite3_strlike("http://%",zArg,0)==0
593 || sqlite3_strlike("https://%",zArg,0)==0
594 || sqlite3_strlike("ssh:%",zArg,0)==0
595 || sqlite3_strlike("file:%",zArg,0)==0
596
+1 -1
--- src/url.c
+++ src/url.c
@@ -599,11 +599,11 @@
599599
if( isatty(fileno(stdin))
600600
&& (pUrlData->flags & URL_PROMPT_PW)!=0
601601
&& (pUrlData->flags & URL_PROMPTED)==0
602602
){
603603
pUrlData->flags |= URL_PROMPTED;
604
- pUrlData->passwd = prompt_for_user_password(pUrlData->user);
604
+ pUrlData->passwd = prompt_for_user_password(pUrlData->canonical);
605605
if( pUrlData->passwd[0]
606606
&& (pUrlData->flags & (URL_REMEMBER|URL_ASK_REMEMBER_PW))!=0
607607
){
608608
if( save_password_prompt(pUrlData->passwd) ){
609609
pUrlData->flags |= URL_REMEMBER_PW;
610610
--- src/url.c
+++ src/url.c
@@ -599,11 +599,11 @@
599 if( isatty(fileno(stdin))
600 && (pUrlData->flags & URL_PROMPT_PW)!=0
601 && (pUrlData->flags & URL_PROMPTED)==0
602 ){
603 pUrlData->flags |= URL_PROMPTED;
604 pUrlData->passwd = prompt_for_user_password(pUrlData->user);
605 if( pUrlData->passwd[0]
606 && (pUrlData->flags & (URL_REMEMBER|URL_ASK_REMEMBER_PW))!=0
607 ){
608 if( save_password_prompt(pUrlData->passwd) ){
609 pUrlData->flags |= URL_REMEMBER_PW;
610
--- src/url.c
+++ src/url.c
@@ -599,11 +599,11 @@
599 if( isatty(fileno(stdin))
600 && (pUrlData->flags & URL_PROMPT_PW)!=0
601 && (pUrlData->flags & URL_PROMPTED)==0
602 ){
603 pUrlData->flags |= URL_PROMPTED;
604 pUrlData->passwd = prompt_for_user_password(pUrlData->canonical);
605 if( pUrlData->passwd[0]
606 && (pUrlData->flags & (URL_REMEMBER|URL_ASK_REMEMBER_PW))!=0
607 ){
608 if( save_password_prompt(pUrlData->passwd) ){
609 pUrlData->flags |= URL_REMEMBER_PW;
610
-4
--- src/user.c
+++ src/user.c
@@ -270,14 +270,10 @@
270270
** Prompt to save Fossil user password
271271
*/
272272
int save_password_prompt(const char *passwd){
273273
Blob x;
274274
char c;
275
- const char *old = db_get("last-sync-pw", 0);
276
- if( (old!=0) && fossil_strcmp(unobscure(old), passwd)==0 ){
277
- return 0;
278
- }
279275
if( fossil_security_level()>=1 ) return 0;
280276
prompt_user("remember password (Y/n)? ", &x);
281277
c = blob_str(&x)[0];
282278
blob_reset(&x);
283279
return ( c!='n' && c!='N' );
284280
--- src/user.c
+++ src/user.c
@@ -270,14 +270,10 @@
270 ** Prompt to save Fossil user password
271 */
272 int save_password_prompt(const char *passwd){
273 Blob x;
274 char c;
275 const char *old = db_get("last-sync-pw", 0);
276 if( (old!=0) && fossil_strcmp(unobscure(old), passwd)==0 ){
277 return 0;
278 }
279 if( fossil_security_level()>=1 ) return 0;
280 prompt_user("remember password (Y/n)? ", &x);
281 c = blob_str(&x)[0];
282 blob_reset(&x);
283 return ( c!='n' && c!='N' );
284
--- src/user.c
+++ src/user.c
@@ -270,14 +270,10 @@
270 ** Prompt to save Fossil user password
271 */
272 int save_password_prompt(const char *passwd){
273 Blob x;
274 char c;
 
 
 
 
275 if( fossil_security_level()>=1 ) return 0;
276 prompt_user("remember password (Y/n)? ", &x);
277 c = blob_str(&x)[0];
278 blob_reset(&x);
279 return ( c!='n' && c!='N' );
280

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button