]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'mh/credential-erase-improvements-more'
authorJunio C Hamano <gitster@pobox.com>
Mon, 28 Aug 2023 16:51:16 +0000 (09:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Aug 2023 16:51:16 +0000 (09:51 -0700)
Update two credential helpers to correctly match which credential
to erase; they dropped not the ones with stale password.

* mh/credential-erase-improvements-more:
  credential/wincred: erase matching creds only
  credential/libsecret: erase matching creds only

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

index 31cf32ad96937e4ad06afae7fd467ea4fbea4a2e,9110714601e5ec6a4f882800598f63e4aab69866..215a81d8bae59ca2364eb762c72089ff8b6b51d7
@@@ -54,27 -52,10 +54,29 @@@ struct credential_operation 
  
  #define CREDENTIAL_OP_END { NULL, NULL }
  
+ static void credential_clear(struct credential *c);
  /* ----------------- Secret Service functions ----------------- */
  
 +static const SecretSchema schema = {
 +      "org.git.Password",
 +      /* Ignore schema name during search for backwards compatibility */
 +      SECRET_SCHEMA_DONT_MATCH_NAME,
 +      {
 +              /*
 +               * libsecret assumes attribute values are non-confidential and
 +               * unchanging, so we can't include oauth_refresh_token or
 +               * password_expiry_utc.
 +               */
 +              {  "user", SECRET_SCHEMA_ATTRIBUTE_STRING },
 +              {  "object", SECRET_SCHEMA_ATTRIBUTE_STRING },
 +              {  "protocol", SECRET_SCHEMA_ATTRIBUTE_STRING },
 +              {  "port", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
 +              {  "server", SECRET_SCHEMA_ATTRIBUTE_STRING },
 +              {  NULL, 0 },
 +      }
 +};
 +
  static char *make_label(struct credential *c)
  {
        if (c->port)
@@@ -249,8 -200,22 +252,22 @@@ static int keyring_erase(struct credent
        if (!c->protocol && !c->host && !c->path && !c->username)
                return EXIT_FAILURE;
  
+       if (c->password) {
+               existing.host = g_strdup(c->host);
+               existing.path = g_strdup(c->path);
+               existing.port = c->port;
+               existing.protocol = g_strdup(c->protocol);
+               existing.username = g_strdup(c->username);
+               keyring_get(&existing);
+               if (existing.password && strcmp(c->password, existing.password)) {
+                       credential_clear(&existing);
+                       return EXIT_SUCCESS;
+               }
+               credential_clear(&existing);
+       }
        attributes = make_attr_list(c);
 -      secret_password_clearv_sync(SECRET_SCHEMA_COMPAT_NETWORK,
 +      secret_password_clearv_sync(&schema,
                                    attributes,
                                    NULL,
                                    &error);