{"thread":{"id":"59470","subject":"[PATCH] credential/wincred: include wincred.h","startedAt":"2023-03-25T01:23:22Z","lastAt":"2023-03-30T06:04:57Z","messageCount":3,"participants":["M Hickford via GitGitGadget","Johannes Schindelin","M Hickford"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"474145","messageId":"pull.1496.git.1679707396407.gitgitgadget@gmail.com","threadId":"59470","inReplyTo":null,"subject":"[PATCH] credential/wincred: include wincred.h","fromName":"M Hickford via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-03-25T01:23:16Z","receivedAt":"2023-03-25T01:23:22Z","isPatch":true,"sender":{"key":"mirth.hickford@gmail.com","avatar":"https://avatars.githubusercontent.com/u/105314?v=4"},"body":"From: M Hickford <mirth.hickford@gmail.com>\n\nDelete redundant definitions. Mingw-w64 has wincred.h since 2007 [1].\n\n[1] https://github.com/mingw-w64/mingw-w64/blob/9d937a7f4f766f903c9433044f77bfa97a0bc1d8/mingw-w64-headers/include/wincred.h\n\nSigned-off-by: M Hickford <mirth.hickford@gmail.com>\n---\n    credential/wincred: include wincred.h\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1496%2Fhickford%2Fwincred-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1496/hickford/wincred-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1496\n\n .../wincred/git-credential-wincred.c          | 61 +------------------\n 1 file changed, 1 insertion(+), 60 deletions(-)\n\ndiff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c\nindex ead6e267c78..6e5a91a7168 100644\n--- a/contrib/credential/wincred/git-credential-wincred.c\n+++ b/contrib/credential/wincred/git-credential-wincred.c\n@@ -6,6 +6,7 @@\n #include <stdio.h>\n #include <io.h>\n #include <fcntl.h>\n+#include <wincred.h>\n \n /* common helpers */\n \n@@ -33,64 +34,6 @@ static void *xmalloc(size_t size)\n \treturn ret;\n }\n \n-/* MinGW doesn't have wincred.h, so we need to define stuff */\n-\n-typedef struct _CREDENTIAL_ATTRIBUTEW {\n-\tLPWSTR Keyword;\n-\tDWORD  Flags;\n-\tDWORD  ValueSize;\n-\tLPBYTE Value;\n-} CREDENTIAL_ATTRIBUTEW, *PCREDENTIAL_ATTRIBUTEW;\n-\n-typedef struct _CREDENTIALW {\n-\tDWORD                  Flags;\n-\tDWORD                  Type;\n-\tLPWSTR                 TargetName;\n-\tLPWSTR                 Comment;\n-\tFILETIME               LastWritten;\n-\tDWORD                  CredentialBlobSize;\n-\tLPBYTE                 CredentialBlob;\n-\tDWORD                  Persist;\n-\tDWORD                  AttributeCount;\n-\tPCREDENTIAL_ATTRIBUTEW Attributes;\n-\tLPWSTR                 TargetAlias;\n-\tLPWSTR                 UserName;\n-} CREDENTIALW, *PCREDENTIALW;\n-\n-#define CRED_TYPE_GENERIC 1\n-#define CRED_PERSIST_LOCAL_MACHINE 2\n-#define CRED_MAX_ATTRIBUTES 64\n-\n-typedef BOOL (WINAPI *CredWriteWT)(PCREDENTIALW, DWORD);\n-typedef BOOL (WINAPI *CredEnumerateWT)(LPCWSTR, DWORD, DWORD *,\n-    PCREDENTIALW **);\n-typedef VOID (WINAPI *CredFreeT)(PVOID);\n-typedef BOOL (WINAPI *CredDeleteWT)(LPCWSTR, DWORD, DWORD);\n-\n-static HMODULE advapi;\n-static CredWriteWT CredWriteW;\n-static CredEnumerateWT CredEnumerateW;\n-static CredFreeT CredFree;\n-static CredDeleteWT CredDeleteW;\n-\n-static void load_cred_funcs(void)\n-{\n-\t/* load DLLs */\n-\tadvapi = LoadLibraryExA(\"advapi32.dll\", NULL,\n-\t\t\t\tLOAD_LIBRARY_SEARCH_SYSTEM32);\n-\tif (!advapi)\n-\t\tdie(\"failed to load advapi32.dll\");\n-\n-\t/* get function pointers */\n-\tCredWriteW = (CredWriteWT)GetProcAddress(advapi, \"CredWriteW\");\n-\tCredEnumerateW = (CredEnumerateWT)GetProcAddress(advapi,\n-\t    \"CredEnumerateW\");\n-\tCredFree = (CredFreeT)GetProcAddress(advapi, \"CredFree\");\n-\tCredDeleteW = (CredDeleteWT)GetProcAddress(advapi, \"CredDeleteW\");\n-\tif (!CredWriteW || !CredEnumerateW || !CredFree || !CredDeleteW)\n-\t\tdie(\"failed to load functions\");\n-}\n-\n static WCHAR *wusername, *password, *protocol, *host, *path, target[1024];\n \n static void write_item(const char *what, LPCWSTR wbuf, int wlen)\n@@ -300,8 +243,6 @@ int main(int argc, char *argv[])\n \n \tread_credential();\n \n-\tload_cred_funcs();\n-\n \tif (!protocol || !(host || path))\n \t\treturn 0;\n \n\nbase-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e\n-- \ngitgitgadget\n"},{"id":"474275","messageId":"8511e030-8167-715c-5ed4-1646e6e9ef85@gmx.de","threadId":"59470","inReplyTo":"pull.1496.git.1679707396407.gitgitgadget@gmail.com","subject":"Re: [PATCH] credential/wincred: include wincred.h","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2023-03-28T12:15:54Z","receivedAt":"2023-03-28T12:16:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi M,\n\nOn Sat, 25 Mar 2023, M Hickford via GitGitGadget wrote:\n\n> From: M Hickford <mirth.hickford@gmail.com>\n>\n> Delete redundant definitions. Mingw-w64 has wincred.h since 2007 [1].\n>\n> [1] https://github.com/mingw-w64/mingw-w64/blob/9d937a7f4f766f903c9433044f77bfa97a0bc1d8/mingw-w64-headers/include/wincred.h\n\nSounds good, and the diffstat is nice. But not as nice as it would look if\nwe retired the `wincred` helper. As I pointed out in\nhttps://lore.kernel.org/git/35e1ebe6-e15b-1712-f030-70ab708740db@gmx.de/,\nI'd much rather spend my time on other things than reviewing patches to a\ncredential helper I consider unsafe.\n\nCiao,\nJohannes\n\n>\n> Signed-off-by: M Hickford <mirth.hickford@gmail.com>\n> ---\n>     credential/wincred: include wincred.h\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1496%2Fhickford%2Fwincred-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1496/hickford/wincred-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/1496\n>\n>  .../wincred/git-credential-wincred.c          | 61 +------------------\n>  1 file changed, 1 insertion(+), 60 deletions(-)\n>\n> diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c\n> index ead6e267c78..6e5a91a7168 100644\n> --- a/contrib/credential/wincred/git-credential-wincred.c\n> +++ b/contrib/credential/wincred/git-credential-wincred.c\n> @@ -6,6 +6,7 @@\n>  #include <stdio.h>\n>  #include <io.h>\n>  #include <fcntl.h>\n> +#include <wincred.h>\n>\n>  /* common helpers */\n>\n> @@ -33,64 +34,6 @@ static void *xmalloc(size_t size)\n>  \treturn ret;\n>  }\n>\n> -/* MinGW doesn't have wincred.h, so we need to define stuff */\n> -\n> -typedef struct _CREDENTIAL_ATTRIBUTEW {\n> -\tLPWSTR Keyword;\n> -\tDWORD  Flags;\n> -\tDWORD  ValueSize;\n> -\tLPBYTE Value;\n> -} CREDENTIAL_ATTRIBUTEW, *PCREDENTIAL_ATTRIBUTEW;\n> -\n> -typedef struct _CREDENTIALW {\n> -\tDWORD                  Flags;\n> -\tDWORD                  Type;\n> -\tLPWSTR                 TargetName;\n> -\tLPWSTR                 Comment;\n> -\tFILETIME               LastWritten;\n> -\tDWORD                  CredentialBlobSize;\n> -\tLPBYTE                 CredentialBlob;\n> -\tDWORD                  Persist;\n> -\tDWORD                  AttributeCount;\n> -\tPCREDENTIAL_ATTRIBUTEW Attributes;\n> -\tLPWSTR                 TargetAlias;\n> -\tLPWSTR                 UserName;\n> -} CREDENTIALW, *PCREDENTIALW;\n> -\n> -#define CRED_TYPE_GENERIC 1\n> -#define CRED_PERSIST_LOCAL_MACHINE 2\n> -#define CRED_MAX_ATTRIBUTES 64\n> -\n> -typedef BOOL (WINAPI *CredWriteWT)(PCREDENTIALW, DWORD);\n> -typedef BOOL (WINAPI *CredEnumerateWT)(LPCWSTR, DWORD, DWORD *,\n> -    PCREDENTIALW **);\n> -typedef VOID (WINAPI *CredFreeT)(PVOID);\n> -typedef BOOL (WINAPI *CredDeleteWT)(LPCWSTR, DWORD, DWORD);\n> -\n> -static HMODULE advapi;\n> -static CredWriteWT CredWriteW;\n> -static CredEnumerateWT CredEnumerateW;\n> -static CredFreeT CredFree;\n> -static CredDeleteWT CredDeleteW;\n> -\n> -static void load_cred_funcs(void)\n> -{\n> -\t/* load DLLs */\n> -\tadvapi = LoadLibraryExA(\"advapi32.dll\", NULL,\n> -\t\t\t\tLOAD_LIBRARY_SEARCH_SYSTEM32);\n> -\tif (!advapi)\n> -\t\tdie(\"failed to load advapi32.dll\");\n> -\n> -\t/* get function pointers */\n> -\tCredWriteW = (CredWriteWT)GetProcAddress(advapi, \"CredWriteW\");\n> -\tCredEnumerateW = (CredEnumerateWT)GetProcAddress(advapi,\n> -\t    \"CredEnumerateW\");\n> -\tCredFree = (CredFreeT)GetProcAddress(advapi, \"CredFree\");\n> -\tCredDeleteW = (CredDeleteWT)GetProcAddress(advapi, \"CredDeleteW\");\n> -\tif (!CredWriteW || !CredEnumerateW || !CredFree || !CredDeleteW)\n> -\t\tdie(\"failed to load functions\");\n> -}\n> -\n>  static WCHAR *wusername, *password, *protocol, *host, *path, target[1024];\n>\n>  static void write_item(const char *what, LPCWSTR wbuf, int wlen)\n> @@ -300,8 +243,6 @@ int main(int argc, char *argv[])\n>\n>  \tread_credential();\n>\n> -\tload_cred_funcs();\n> -\n>  \tif (!protocol || !(host || path))\n>  \t\treturn 0;\n>\n>\n> base-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e\n> --\n> gitgitgadget\n>\n"},{"id":"474446","messageId":"CAGJzqsmd9XAP3wyqTJ2yJt6hTx9LxB0e6qd6YWRt=k_PLuA9Kg@mail.gmail.com","threadId":"59470","inReplyTo":"8511e030-8167-715c-5ed4-1646e6e9ef85@gmx.de","subject":"Re: [PATCH] credential/wincred: include wincred.h","fromName":"M Hickford","fromEmail":"mirth.hickford@gmail.com","sentAt":"2023-03-30T06:04:13Z","receivedAt":"2023-03-30T06:04:57Z","isPatch":true,"sender":{"key":"mirth.hickford@gmail.com","avatar":"https://avatars.githubusercontent.com/u/105314?v=4"},"body":"On Tue, 28 Mar 2023 at 13:15, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>\n> Hi M,\n>\n> On Sat, 25 Mar 2023, M Hickford via GitGitGadget wrote:\n>\n> > From: M Hickford <mirth.hickford@gmail.com>\n> >\n> > Delete redundant definitions. Mingw-w64 has wincred.h since 2007 [1].\n> >\n> > [1] https://github.com/mingw-w64/mingw-w64/blob/9d937a7f4f766f903c9433044f77bfa97a0bc1d8/mingw-w64-headers/include/wincred.h\n>\n> Sounds good, and the diffstat is nice. But not as nice as it would look if\n> we retired the `wincred` helper. As I pointed out in\n> https://lore.kernel.org/git/35e1ebe6-e15b-1712-f030-70ab708740db@gmx.de/,\n> I'd much rather spend my time on other things than reviewing patches to a\n> credential helper I consider unsafe.\n\nThanks Johannes for your reply. What do you mean by \"unsafe\"? Not\nuseful in the modern world of 2FA? Doch! You can use\ngit-credential-wincred to store OAuth credentials [1].\n\nFor storage, both git-credential-wincred and Git Credential Manager\nuse the same wincred.h CredWrite API [2]. This is surely preferable\nto plaintext git-credential-store [3].\n\n[1] https://lore.kernel.org/git/CAGJzqs=D8hmcxJKGCcz-NqEQ+QDYgi_aO02fj59kQoHZgiW3OQ@mail.gmail.com/T/#md6a0bbf7a36801652c16afe6f5c9dbd19914b2a7\n[2] https://github.com/git-ecosystem/git-credential-manager/blob/main/src/shared/Core/Interop/Windows/WindowsCredentialManager.cs\n[3] https://lore.kernel.org/git/CAGJzqskRYN49SeS8kSEN5-vbB_Jt1QvAV9QhS6zNuKh0u8wxPQ@mail.gmail.com/\n\n\n>\n> Ciao,\n> Johannes\n>\n> >\n> > Signed-off-by: M Hickford <mirth.hickford@gmail.com>\n> > ---\n> >     credential/wincred: include wincred.h\n> >\n> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1496%2Fhickford%2Fwincred-v1\n> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1496/hickford/wincred-v1\n> > Pull-Request: https://github.com/gitgitgadget/git/pull/1496\n> >\n> >  .../wincred/git-credential-wincred.c          | 61 +------------------\n> >  1 file changed, 1 insertion(+), 60 deletions(-)\n> >\n> > diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c\n> > index ead6e267c78..6e5a91a7168 100644\n> > --- a/contrib/credential/wincred/git-credential-wincred.c\n> > +++ b/contrib/credential/wincred/git-credential-wincred.c\n> > @@ -6,6 +6,7 @@\n> >  #include <stdio.h>\n> >  #include <io.h>\n> >  #include <fcntl.h>\n> > +#include <wincred.h>\n> >\n> >  /* common helpers */\n> >\n> > @@ -33,64 +34,6 @@ static void *xmalloc(size_t size)\n> >       return ret;\n> >  }\n> >\n> > -/* MinGW doesn't have wincred.h, so we need to define stuff */\n> > -\n> > -typedef struct _CREDENTIAL_ATTRIBUTEW {\n> > -     LPWSTR Keyword;\n> > -     DWORD  Flags;\n> > -     DWORD  ValueSize;\n> > -     LPBYTE Value;\n> > -} CREDENTIAL_ATTRIBUTEW, *PCREDENTIAL_ATTRIBUTEW;\n> > -\n> > -typedef struct _CREDENTIALW {\n> > -     DWORD                  Flags;\n> > -     DWORD                  Type;\n> > -     LPWSTR                 TargetName;\n> > -     LPWSTR                 Comment;\n> > -     FILETIME               LastWritten;\n> > -     DWORD                  CredentialBlobSize;\n> > -     LPBYTE                 CredentialBlob;\n> > -     DWORD                  Persist;\n> > -     DWORD                  AttributeCount;\n> > -     PCREDENTIAL_ATTRIBUTEW Attributes;\n> > -     LPWSTR                 TargetAlias;\n> > -     LPWSTR                 UserName;\n> > -} CREDENTIALW, *PCREDENTIALW;\n> > -\n> > -#define CRED_TYPE_GENERIC 1\n> > -#define CRED_PERSIST_LOCAL_MACHINE 2\n> > -#define CRED_MAX_ATTRIBUTES 64\n> > -\n> > -typedef BOOL (WINAPI *CredWriteWT)(PCREDENTIALW, DWORD);\n> > -typedef BOOL (WINAPI *CredEnumerateWT)(LPCWSTR, DWORD, DWORD *,\n> > -    PCREDENTIALW **);\n> > -typedef VOID (WINAPI *CredFreeT)(PVOID);\n> > -typedef BOOL (WINAPI *CredDeleteWT)(LPCWSTR, DWORD, DWORD);\n> > -\n> > -static HMODULE advapi;\n> > -static CredWriteWT CredWriteW;\n> > -static CredEnumerateWT CredEnumerateW;\n> > -static CredFreeT CredFree;\n> > -static CredDeleteWT CredDeleteW;\n> > -\n> > -static void load_cred_funcs(void)\n> > -{\n> > -     /* load DLLs */\n> > -     advapi = LoadLibraryExA(\"advapi32.dll\", NULL,\n> > -                             LOAD_LIBRARY_SEARCH_SYSTEM32);\n> > -     if (!advapi)\n> > -             die(\"failed to load advapi32.dll\");\n> > -\n> > -     /* get function pointers */\n> > -     CredWriteW = (CredWriteWT)GetProcAddress(advapi, \"CredWriteW\");\n> > -     CredEnumerateW = (CredEnumerateWT)GetProcAddress(advapi,\n> > -         \"CredEnumerateW\");\n> > -     CredFree = (CredFreeT)GetProcAddress(advapi, \"CredFree\");\n> > -     CredDeleteW = (CredDeleteWT)GetProcAddress(advapi, \"CredDeleteW\");\n> > -     if (!CredWriteW || !CredEnumerateW || !CredFree || !CredDeleteW)\n> > -             die(\"failed to load functions\");\n> > -}\n> > -\n> >  static WCHAR *wusername, *password, *protocol, *host, *path, target[1024];\n> >\n> >  static void write_item(const char *what, LPCWSTR wbuf, int wlen)\n> > @@ -300,8 +243,6 @@ int main(int argc, char *argv[])\n> >\n> >       read_credential();\n> >\n> > -     load_cred_funcs();\n> > -\n> >       if (!protocol || !(host || path))\n> >               return 0;\n> >\n> >\n> > base-commit: 27d43aaaf50ef0ae014b88bba294f93658016a2e\n> > --\n> > gitgitgadget\n> >\n"}]}