From: "Sören Krecker" <soekkle@freenet.de>
To: git@vger.kernel.org
Cc: soekkle <soekkle@freenet.de>
Subject: [PATCH 1/1] Replace SID with domain/username
Date: Thu, 28 Dec 2023 14:28:44 +0100 [thread overview]
Message-ID: <20231228132844.4240-2-soekkle@freenet.de> (raw)
In-Reply-To: <20231228132844.4240-1-soekkle@freenet.de>
From: soekkle <soekkle@freenet.de>
Replace SID with domain/username in erromessage, if owner of repository
and user are not equal on windows systems.
Signed-off-by: Sören Krecker <soekkle@freenet.de>
---
compat/mingw.c | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index 42053c1f65..7318f0e20e 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -2684,6 +2684,25 @@ static PSID get_current_user_sid(void)
return result;
}
+BOOL user_sid_to_string(PSID sid, LPSTR* str)
+{
+ SID_NAME_USE peUse;
+ DWORD lenName = { 0 }, lenDomain = { 0 };
+ LookupAccountSidA(NULL, sid, NULL, &lenName, NULL,
+ &lenDomain, &peUse); // returns only FALSE, because the string pointers are NULL
+ ALLOC_ARRAY((*str), (size_t)lenDomain + (size_t)lenName); // Alloc neded Space of the strings
+ BOOL retVal = LookupAccountSidA(NULL, sid, (*str) + lenDomain, &lenName,
+ *str,
+ &lenDomain, &peUse);
+ *(*str + lenDomain) = '/';
+ if (retVal == FALSE)
+ {
+ free(*str);
+ *str = NULL;
+ }
+ return retVal;
+}
+
static int acls_supported(const char *path)
{
size_t offset = offset_1st_component(path);
@@ -2767,7 +2786,7 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
} else if (report) {
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
- if (ConvertSidToStringSidA(sid, &str1))
+ if (user_sid_to_string(sid, &str1))
to_free1 = str1;
else
str1 = "(inconvertible)";
@@ -2776,7 +2795,7 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
str2 = "(none)";
else if (!IsValidSid(current_user_sid))
str2 = "(invalid)";
- else if (ConvertSidToStringSidA(current_user_sid, &str2))
+ else if (user_sid_to_string(current_user_sid, &str2))
to_free2 = str2;
else
str2 = "(inconvertible)";
@@ -2784,8 +2803,8 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
"'%s' is owned by:\n"
"\t'%s'\nbut the current user is:\n"
"\t'%s'\n", path, str1, str2);
- LocalFree(to_free1);
- LocalFree(to_free2);
+ free(to_free1);
+ free(to_free2);
}
}
--
2.39.2
next prev parent reply other threads:[~2023-12-28 13:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-28 13:28 [PATCH 0/1] Replace SID with domain/username on Windows Sören Krecker
2023-12-28 13:28 ` Sören Krecker [this message]
2023-12-28 19:27 ` [PATCH 1/1] Replace SID with domain/username Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231228132844.4240-2-soekkle@freenet.de \
--to=soekkle@freenet.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).