From patchwork Mon Aug 8 13:27:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12938804 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C39FC25B0C for ; Mon, 8 Aug 2022 13:28:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243353AbiHHN2A (ORCPT ); Mon, 8 Aug 2022 09:28:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243298AbiHHN1z (ORCPT ); Mon, 8 Aug 2022 09:27:55 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CB72A193 for ; Mon, 8 Aug 2022 06:27:54 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id n4so9139453wrp.10 for ; Mon, 08 Aug 2022 06:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=r2kDf5GfPPgtHhXYHg1HscNJDVUfYeJJsSD9jO/tFqU=; b=Z7dyQsyrhCVuLGyD6xkRDSX7q2iPM8lpxWcobX9oGUfXz8YzZUZdhh6k7YD+Rflwas IHrP0qlSWap0ZSa1hMFj5R6QIwi+dEqQKs+yYSSaTvTGoAfblJTG5+AUAu/K1X1H4ZVf IMHPblcN6fOh9N3RxR5+DvUgUJe7rgof83//FQJ5TCVKR9NZiUBGfr3iI6eQLM45PtJg CvQzuPMei1lB+6HUfvbiJpSFEZE1I7K7WRO9BkcAB7kl7y6R/R4Gu9L41EwdvFMfdk6V BvbUELUavbbka/v3VKJFx2pzONO+zt+YHYduhVE6YIiki5h2/6LEGDGWyaSYaNXqYS9s pT1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=r2kDf5GfPPgtHhXYHg1HscNJDVUfYeJJsSD9jO/tFqU=; b=ioE2oMiqOkVUhoRl4lMLfITT8wbKVNXo0Iv2AX3ievXo5U+jE9ajPFZ/wf+PGwFeuT u/yOUnWRtt/4c6zgoV3Z6QYLgjMW2UTmam991KtNzB7hd+cwKthfbgBn85FGk0N5b/ic 47G1JipjYqGorMiXeWiegVxx0eon8dbgr6tb0XCjbfejSUV5agI+1BghEnIpjRAyzMl4 kBmK4OqJTIRGUupIrHj9nqw/4Sf/IFBnyvts/eRYUgrCeFrhERGB2jhxgis1sW/85/K+ SQt1CfiXUBLUreW7eDFQIP7jaCAv9FagvxD7cSc0munMRunQUJvl27sxToCTvhtXzpB/ buOg== X-Gm-Message-State: ACgBeo0O9/FhAfQ6dr0XTqQ1H6co6h9MgQArTrYIx6Xrk96g32XK+uSM EOGMpJogBE5xixeKjxT+OjMcvH+5Eh8= X-Google-Smtp-Source: AA6agR4+/nXjRURXbob7DaSRJl1dFo1dyOmsfJtmufZg0ja5MYzDMCzOuSNM/5kqRap6OWgOP55lrg== X-Received: by 2002:adf:ef8c:0:b0:21e:f504:6e54 with SMTP id d12-20020adfef8c000000b0021ef5046e54mr11423553wro.476.1659965272738; Mon, 08 Aug 2022 06:27:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c24-20020a7bc018000000b003a53731f273sm6065298wmb.31.2022.08.08.06.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 06:27:52 -0700 (PDT) Message-Id: <301d94f18f501b44b6b96fd7c170134d4661be38.1659965270.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 08 Aug 2022 13:27:46 +0000 Subject: [PATCH v2 1/5] setup: fix some formatting Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In preparation for touching code that was introduced in 3b0bf2704980 (setup: tighten ownership checks post CVE-2022-24765, 2022-05-10) and that was formatted differently than preferred in the Git project, fix the indentation before actually modifying the code. Signed-off-by: Johannes Schindelin --- setup.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/setup.c b/setup.c index 8c683e92b62..2f7b3e598f8 100644 --- a/setup.c +++ b/setup.c @@ -1142,7 +1142,7 @@ static int safe_directory_cb(const char *key, const char *value, void *d) * added, for bare ones their git directory. */ static int ensure_valid_ownership(const char *gitfile, - const char *worktree, const char *gitdir) + const char *worktree, const char *gitdir) { struct safe_directory_data data = { .path = worktree ? worktree : gitdir @@ -1316,10 +1316,11 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, strbuf_setlen(dir, offset); if (gitdirenv) { enum discovery_result ret; + const char *gitdir_candidate = + gitdir_path ? gitdir_path : gitdirenv; - if (ensure_valid_ownership(gitfile, - dir->buf, - (gitdir_path ? gitdir_path : gitdirenv))) { + if (ensure_valid_ownership(gitfile, dir->buf, + gitdir_candidate)) { strbuf_addstr(gitdir, gitdirenv); ret = GIT_DIR_DISCOVERED; } else From patchwork Mon Aug 8 13:27:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12938805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F28BCC25B0C for ; Mon, 8 Aug 2022 13:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243344AbiHHN2D (ORCPT ); Mon, 8 Aug 2022 09:28:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243333AbiHHN15 (ORCPT ); Mon, 8 Aug 2022 09:27:57 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 888D2A449 for ; Mon, 8 Aug 2022 06:27:55 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id z17so10902097wrq.4 for ; Mon, 08 Aug 2022 06:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=j0PQ1fijek74RD1U23MrGDGCUhUVjKLyhgHg2JC7YOU=; b=e9qqS9prU7wi2cL84upqIrB/LxwQVwHkJR54JxFbWPrT1fhszlL7aVZqA0VILSomIY NrlzRMcOOtUWCFcXazS2OxTE4WWbqNiGGGIHE1tXPHFkh+vBerU4mUR9qLRA0bPguEXb lUvJZXlmBBF+j/duwSdNfWVvgd1+Isjwq3jF9PTeAd05qt5OpP+yTz1WB2XxEbSpQNZw aCHtNqcIE/VND1kDfHEiwm27IKcGQCA0aPHrwcYxJWt0vbgfn1fJUZ8UELBSbgpOpME6 SsE0vYS3qKW9kWt4U/tS78/9HAiW4Zc6oKeX/oRYyQ73k5zMSzwXaKyE3gJSPzCmqdrR S5kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=j0PQ1fijek74RD1U23MrGDGCUhUVjKLyhgHg2JC7YOU=; b=0IENmhR8VgFx0PGJ1AfOZCK2Z0mqvyGx3u3CAKLIWXjarndR3dYUeGxx0SB7K18H97 DLpF8FthRm4m29HRiw3YPNf26yrzgLWYe6uI9J3Vbs7TTqHQQaxPoAcjuYIaVOPQ5pnS +zvIepNjJTxHjGgz1KwsboqpEkFH45ODmYDSqj5iG9ec2R6PkrBpelrMcJuVYdk3qpYc eAa053FZGihUt+mEoBF/PnwMTWm+AYntOcQAgzftAyPEInJdFlVXBnuyw8fn7L4Si8up vWquJSHss7i0idEPW/lUPQDJOJ/5NekWzg4aVdIBkzVWjUp+diAeW4YTKu4Ti30w5yrS 98GA== X-Gm-Message-State: ACgBeo3zXYrBpQqqallBQ+VJT0SV13NniCW7TFucNvGSmuK8Tw3aK/e1 uLdz2C3cxPejiXT+vMGeg+zXYw5xB3E= X-Google-Smtp-Source: AA6agR4NUmB9IpU5es8wOT7Z+VLG5uwOB9jmfYzT+DAM6taJBlEjVwoQNi05UFCEFuPHHPpPFJYs7A== X-Received: by 2002:a5d:684e:0:b0:220:63df:3760 with SMTP id o14-20020a5d684e000000b0022063df3760mr10846056wrw.508.1659965273752; Mon, 08 Aug 2022 06:27:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b6-20020adfde06000000b0022069ccb6a1sm12115573wrm.94.2022.08.08.06.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 06:27:53 -0700 (PDT) Message-Id: <8cc45e4922a6a445e9f643e709c3efaf48553a09.1659965270.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 08 Aug 2022 13:27:47 +0000 Subject: [PATCH v2 2/5] Prepare for more detailed "dubious ownership" messages Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When verifying the ownership of the Git directory, we sometimes would like to say a bit more about it, e.g. when using a platform-dependent code path (think: Windows and the permission model that is so different from Unix'), but only when it is a appropriate to actually say something. To allow for that, collect that information and hand it back to the caller (whose responsibility it is to show it or not). Note: We do not actually fill in any platform-dependent information yet, this commit just adds the infrastructure to be able to do so. Based-on-an-idea-by: Junio C Hamano Signed-off-by: Johannes Schindelin --- compat/mingw.c | 2 +- compat/mingw.h | 2 +- git-compat-util.h | 5 ++++- setup.c | 25 +++++++++++++++---------- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 2607de93af5..f12b7df16d9 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2673,7 +2673,7 @@ static PSID get_current_user_sid(void) return result; } -int is_path_owned_by_current_sid(const char *path) +int is_path_owned_by_current_sid(const char *path, struct strbuf *report) { WCHAR wpath[MAX_PATH]; PSID sid = NULL; diff --git a/compat/mingw.h b/compat/mingw.h index a74da68f313..209cf7cebad 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -463,7 +463,7 @@ char *mingw_query_user_email(void); * Verifies that the specified path is owned by the user running the * current process. */ -int is_path_owned_by_current_sid(const char *path); +int is_path_owned_by_current_sid(const char *path, struct strbuf *report); #define is_path_owned_by_current_user is_path_owned_by_current_sid /** diff --git a/git-compat-util.h b/git-compat-util.h index 58d7708296b..36a25ae252f 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -23,6 +23,9 @@ #include #endif +struct strbuf; + + #define _FILE_OFFSET_BITS 64 @@ -487,7 +490,7 @@ static inline void extract_id_from_env(const char *env, uid_t *id) } } -static inline int is_path_owned_by_current_uid(const char *path) +static inline int is_path_owned_by_current_uid(const char *path, struct strbuf *report) { struct stat st; uid_t euid; diff --git a/setup.c b/setup.c index 2f7b3e598f8..cefd5f63c46 100644 --- a/setup.c +++ b/setup.c @@ -1142,16 +1142,17 @@ static int safe_directory_cb(const char *key, const char *value, void *d) * added, for bare ones their git directory. */ static int ensure_valid_ownership(const char *gitfile, - const char *worktree, const char *gitdir) + const char *worktree, const char *gitdir, + struct strbuf *report) { struct safe_directory_data data = { .path = worktree ? worktree : gitdir }; if (!git_env_bool("GIT_TEST_ASSUME_DIFFERENT_OWNER", 0) && - (!gitfile || is_path_owned_by_current_user(gitfile)) && - (!worktree || is_path_owned_by_current_user(worktree)) && - (!gitdir || is_path_owned_by_current_user(gitdir))) + (!gitfile || is_path_owned_by_current_user(gitfile, report)) && + (!worktree || is_path_owned_by_current_user(worktree, report)) && + (!gitdir || is_path_owned_by_current_user(gitdir, report))) return 1; /* @@ -1232,6 +1233,7 @@ enum discovery_result { */ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, struct strbuf *gitdir, + struct strbuf *report, int die_on_error) { const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT); @@ -1320,7 +1322,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, gitdir_path ? gitdir_path : gitdirenv; if (ensure_valid_ownership(gitfile, dir->buf, - gitdir_candidate)) { + gitdir_candidate, report)) { strbuf_addstr(gitdir, gitdirenv); ret = GIT_DIR_DISCOVERED; } else @@ -1345,7 +1347,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, if (is_git_directory(dir->buf)) { if (get_allowed_bare_repo() == ALLOWED_BARE_REPO_EXPLICIT) return GIT_DIR_DISALLOWED_BARE; - if (!ensure_valid_ownership(NULL, NULL, dir->buf)) + if (!ensure_valid_ownership(NULL, NULL, dir->buf, report)) return GIT_DIR_INVALID_OWNERSHIP; strbuf_addstr(gitdir, "."); return GIT_DIR_BARE; @@ -1378,7 +1380,7 @@ int discover_git_directory(struct strbuf *commondir, return -1; cwd_len = dir.len; - if (setup_git_directory_gently_1(&dir, gitdir, 0) <= 0) { + if (setup_git_directory_gently_1(&dir, gitdir, NULL, 0) <= 0) { strbuf_release(&dir); return -1; } @@ -1425,7 +1427,7 @@ int discover_git_directory(struct strbuf *commondir, const char *setup_git_directory_gently(int *nongit_ok) { static struct strbuf cwd = STRBUF_INIT; - struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT; + struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT, report = STRBUF_INIT; const char *prefix = NULL; struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; @@ -1450,7 +1452,7 @@ const char *setup_git_directory_gently(int *nongit_ok) die_errno(_("Unable to read current working directory")); strbuf_addbuf(&dir, &cwd); - switch (setup_git_directory_gently_1(&dir, &gitdir, 1)) { + switch (setup_git_directory_gently_1(&dir, &gitdir, &report, 1)) { case GIT_DIR_EXPLICIT: prefix = setup_explicit_git_dir(gitdir.buf, &cwd, &repo_fmt, nongit_ok); break; @@ -1482,12 +1484,14 @@ const char *setup_git_directory_gently(int *nongit_ok) if (!nongit_ok) { struct strbuf quoted = STRBUF_INIT; + strbuf_complete(&report, '\n'); sq_quote_buf_pretty("ed, dir.buf); die(_("detected dubious ownership in repository at '%s'\n" + "%s" "To add an exception for this directory, call:\n" "\n" "\tgit config --global --add safe.directory %s"), - dir.buf, quoted.buf); + dir.buf, report.buf, quoted.buf); } *nongit_ok = 1; break; @@ -1574,6 +1578,7 @@ const char *setup_git_directory_gently(int *nongit_ok) strbuf_release(&dir); strbuf_release(&gitdir); + strbuf_release(&report); clear_repository_format(&repo_fmt); return prefix; From patchwork Mon Aug 8 13:27:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12938806 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62ED1C00140 for ; Mon, 8 Aug 2022 13:28:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243359AbiHHN2G (ORCPT ); Mon, 8 Aug 2022 09:28:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243339AbiHHN15 (ORCPT ); Mon, 8 Aug 2022 09:27:57 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84828A464 for ; Mon, 8 Aug 2022 06:27:56 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id j7so10927007wrh.3 for ; Mon, 08 Aug 2022 06:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=w1h9NraaToF+tuGu5gt0C56PoKkfBlb9sQmrKhyZZG8=; b=lrpHPmIXNgxZwBkAIdkcbYMFrQIEQXb2VjGcr1wGJZxqmL5uO7WFr53SFIuARBJVSO EX88z2lSgGINTfuE/7Cd21z6TDhbLuVEEm0pvLXkIbrYR6/ROgOQmmUb2K5VRRRFbZnn MaBG/BcMn+YdPGzaT5GNlhYaBSv5Iv/+YNaY/3CnrXsueCI5lbV/Z5iTePEFnrGJ14tL hi+ZH9OGRKPoZg+ZOWntIJfB1TCdwzndQIS+hIoBRPwi5CMjxOw0AlofEInZ3CZwE4Ay EnV2tHgXnnGgBpQ3Q+YFcfiJNohl76u5xFB6oQm/JVNq1gY4gMwOT9D+HOe0W3LBGsxU 5j5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=w1h9NraaToF+tuGu5gt0C56PoKkfBlb9sQmrKhyZZG8=; b=kpIoheWg+HMHxi0yY6UJk3eVpamagE3lVgX2JDWOesxjHIuXCEctCc18McT4hs/sJf YBQPBSP2+aAUWdAeKTWV0WNFOkqjzRWSzqtHXli7u8Q0HwgWyY2AXIc9c2LzFhbVYFSZ GoW/ZibsBxoof6mGQGbkxeeIzk53OYEmnbTjnFpRr73C2WC+V/Zem9oxNfsqsmLrzZHy ih/JhHNNH1GCZ4Ssoffp+s6eb2M/jg42ajQ+HwXwemR3VMf7HZFWtlEsaIpnm+QsHOg8 aQN7/aL5jMcZLcpM/eIijuaco8T/vHsLD5e2g3sFflLDqt30fc5kwzljPktEKZdO4FxT MUMA== X-Gm-Message-State: ACgBeo2Fv8TFALZAPkEI4NOe6IAeEHc+0T5X5SnC3NxRl2QPuYPnyPvn jianhqc2gsabm86HIbZtKb3BC544Drk= X-Google-Smtp-Source: AA6agR40OMitTlW8bhv8QqQJMiYd3SjDPD4D0MMmFkv8voKbAciSpm6LHtxJXCfXhht9eK3FstuJAw== X-Received: by 2002:a05:6000:10c3:b0:21f:15aa:1b68 with SMTP id b3-20020a05600010c300b0021f15aa1b68mr11785003wrx.693.1659965274723; Mon, 08 Aug 2022 06:27:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z9-20020a5d4d09000000b0021dd08ad8d7sm11390233wrt.46.2022.08.08.06.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 06:27:54 -0700 (PDT) Message-Id: <6349481810585d4dba2187266510d71fb2471cb7.1659965270.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 08 Aug 2022 13:27:48 +0000 Subject: [PATCH v2 3/5] mingw: provide details about unsafe directories' ownership Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When Git refuses to use an existing repository because it is owned by someone else than the current user, it can be a bit tricky on Windows to figure out what is going on. Let's help with that by providing more detailed information. Signed-off-by: Johannes Schindelin --- compat/mingw.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/compat/mingw.c b/compat/mingw.c index f12b7df16d9..2c09c5bffee 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1,6 +1,7 @@ #include "../git-compat-util.h" #include "win32.h" #include +#include #include #include #include "../strbuf.h" @@ -2720,6 +2721,29 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report) IsValidSid(current_user_sid) && EqualSid(sid, current_user_sid)) result = 1; + else if (report) { + LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL; + + if (ConvertSidToStringSidA(sid, &str1)) + to_free1 = str1; + else + str1 = "(inconvertible)"; + + if (!current_user_sid) + str2 = "(none)"; + else if (!IsValidSid(current_user_sid)) + str2 = "(invalid)"; + else if (ConvertSidToStringSidA(current_user_sid, &str2)) + to_free2 = str2; + else + str2 = "(inconvertible)"; + strbuf_addf(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); + } } /* From patchwork Mon Aug 8 13:27:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12938807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A286C25B0C for ; Mon, 8 Aug 2022 13:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243176AbiHHN2I (ORCPT ); Mon, 8 Aug 2022 09:28:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243340AbiHHN15 (ORCPT ); Mon, 8 Aug 2022 09:27:57 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91528A472 for ; Mon, 8 Aug 2022 06:27:56 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 186-20020a1c02c3000000b003a34ac64bdfso5161195wmc.1 for ; Mon, 08 Aug 2022 06:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=v6BZradEP9tTafjbmqr4IwJDt5zRjEVeDjgv2G2Ibss=; b=BZbX/7BFvH4L6ItMfTcfliRxJFoypGd8EY3gUQ4f6I2Yyw+KeFY2KmKarF8xbqYvYz WqoQROjPyRuvGhEYl/Aiau0Knbh5Vdo0UdOoyXyFyyd8SZZIvyCRws+pSZIYbvTVkCUN Dk97My/AvKD2iovXbNn5oUggLPWuqt4LghQTdr4FGXGp7dWj2NMIgjoHj0hSa5TjTPUL D7bYwDWcEcswe1F5ZrTPtSEXSQBQYca4dsNe9G3Q+O9RvVSPoNQXyoSZ3d1ST3d0vLba MzwR1j7ecTgJK7HUlLj0Q0isKrAzckQtmuo0tY3Fz7b3QLB9FEgIBtmtLU5ZvATiuPjE KwXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=v6BZradEP9tTafjbmqr4IwJDt5zRjEVeDjgv2G2Ibss=; b=tNpm5HlWzM6kbGZsDsnUVJh7qf2pBBzeAA1dua6J014vUrNglS8KIqpvBGQvAf10K5 Ws9KX9DrmXMHZVIL0xYFAKV2IrFZEOaSGrK1ywamV2t1fIF3aVb6VW0+QZtS8+lOQC4F 8W/iOzCIdM64TVtGqyi72b1y2xWLv9sWVIyg7GXzQTqGrjyvnHRDROA/UXc8ynAOb8n/ KiY6q6glgGYkvqFnfWtd8aKhleLJ4ZUtgVnp2yKfCQ1jd5H3QNfgzh4HTISQqghC6HtK WiXIfwPiTpVcAT8geJgkWtZXjtk84cvduCej7wqNVFDg/hDOVZNtFte4fkk+tDDKLlIx 521w== X-Gm-Message-State: ACgBeo0GTTPz0c3O42mvFFs4NQI6tJUGg/FSc/p7SRfDJnz7zRV4XT8R 9XvlNwhNk68GfbGT+nVPXUq3fwTsYcM= X-Google-Smtp-Source: AA6agR5dIdOsdWCUpWZNjaUVJk1ZMin4FGc+7CTmj5qzYxfZBDf3FEihnuccYvsnBiX+S9MOo2kQQA== X-Received: by 2002:a05:600c:348e:b0:3a3:5515:98b1 with SMTP id a14-20020a05600c348e00b003a3551598b1mr13019124wmq.110.1659965275817; Mon, 08 Aug 2022 06:27:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j6-20020a05600c190600b003a31b79dc0esm41242583wmq.1.2022.08.08.06.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 06:27:55 -0700 (PDT) Message-Id: <7aaa6248dfef7fb8436b5fbccf4689d0be3226a5.1659965270.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 08 Aug 2022 13:27:49 +0000 Subject: [PATCH v2 4/5] mingw: be more informative when ownership check fails on FAT32 Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The FAT file system has no concept of ACLs. Therefore, it cannot store any ownership information anyway, and the `GetNamedSecurityInfoW()` call pretends that everything is owned "by the world". Let's special-case that scenario and tell the user what's going on. This addresses https://github.com/git-for-windows/git/issues/3886 Signed-off-by: Johannes Schindelin --- compat/mingw.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/compat/mingw.c b/compat/mingw.c index 2c09c5bffee..22f960c7e34 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2674,6 +2674,21 @@ static PSID get_current_user_sid(void) return result; } +static int acls_supported(const char *path) +{ + size_t offset = offset_1st_component(path); + WCHAR wroot[MAX_PATH]; + DWORD file_system_flags; + + if (offset && + xutftowcsn(wroot, path, MAX_PATH, offset) > 0 && + GetVolumeInformationW(wroot, NULL, 0, NULL, NULL, + &file_system_flags, NULL, 0)) + return !!(file_system_flags & FILE_PERSISTENT_ACLS); + + return 0; +} + int is_path_owned_by_current_sid(const char *path, struct strbuf *report) { WCHAR wpath[MAX_PATH]; @@ -2721,7 +2736,15 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report) IsValidSid(current_user_sid) && EqualSid(sid, current_user_sid)) result = 1; - else if (report) { + else if (report && + IsWellKnownSid(sid, WinWorldSid) && + !acls_supported(path)) { + /* + * On FAT32 volumes, ownership is not actually recorded. + */ + strbuf_addf(report, "'%s' is on a file system that does" + "not record ownership\n", path); + } else if (report) { LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL; if (ConvertSidToStringSidA(sid, &str1)) From patchwork Mon Aug 8 13:27:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12938808 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A1FCC00140 for ; Mon, 8 Aug 2022 13:28:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243399AbiHHN2M (ORCPT ); Mon, 8 Aug 2022 09:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243352AbiHHN2A (ORCPT ); Mon, 8 Aug 2022 09:28:00 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5A4B9FE7 for ; Mon, 8 Aug 2022 06:27:58 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id z12so10883412wrs.9 for ; Mon, 08 Aug 2022 06:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc; bh=eLjEx9Bl9ywnepjxjVCPdZ6lH4L+q5Q+sk+026AsdWw=; b=CGlkPgwbvvJqs/7qBj/fRl9xSvrOXyT98bRe5nu1GBfN+MXErMe57E+HRZrZQziPov e2V+ecbqtireC5yF6LrDOkfAxX1/UBDeAJ/tbA1a7iArgw8P2xOognbIbu4VUMNJu1Qh qz8daoLLI3pRADSP5RN6FWeJ0NTzPBcku8cHPXG2E0Njkfw9AT1rIFO5CcJJOmMjaJwG teswRxVtumYO6sbzpmhNRONFIg6oiepQjoAmR8hvYNAIrtoD9u7hFcW1kmW95zraWJWC T/Nl8jzgaaT/czbZCCzSntl7accTvxbA7J4qQnV0UU2hl3VxxcDVmp/Iof47SXi925Q1 N7gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=eLjEx9Bl9ywnepjxjVCPdZ6lH4L+q5Q+sk+026AsdWw=; b=apm8KmcNo1Aj77omadsc7d3IwvAjDanexBWpuj1ay4I0bWJB6xrH9BccXrp8vEAXX0 BNykj1wdqQhdpKykUR3po/oyyDMnUMNR+38pk+no4U8QxYHV+PPG0zMKDKB1TUb9iCtc kKcMcw9MBmrireyUw5kS1PTXKqmAYRYqxK6aKkDNH0NpRDNyyAni/dDffa1QL4vrxRi/ cNK9+SwGXQ6+Fx0yu7l9cvjBnmSH2grYYB49Wz2cWzOEPYBbOOzjPt1QQ3OA/vkCokRQ BwWMblRZdnWMajx2GwMR+QYEQwVvxDsuPT9m9m4gkvsNtDxnEnRPPztrB3rQ5IrjGoPa dI4Q== X-Gm-Message-State: ACgBeo0nfrr6dmaBYhmGOj09u/CIiZ0kN3c1Wg9eNzphzimbe6XYO2mO Ubb0mUhDf0Ebuhk/UiMZevrvBN1Awjk= X-Google-Smtp-Source: AA6agR4CQFw4PBv6jD6zCpM88M+uUX6ZSTfCD1zmVHnYOUY1laDrkfWpwoe0//IHqgKZQbdT2iKbNQ== X-Received: by 2002:adf:efc3:0:b0:21f:15aa:1b40 with SMTP id i3-20020adfefc3000000b0021f15aa1b40mr11354920wrp.159.1659965276845; Mon, 08 Aug 2022 06:27:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w15-20020adfec4f000000b0021e6b62fde2sm11193001wrn.59.2022.08.08.06.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 06:27:56 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 08 Aug 2022 13:27:50 +0000 Subject: [PATCH v2 5/5] mingw: handle a file owned by the Administrators group correctly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When an Administrator creates a file or directory, the created file/directory is owned not by the Administrator SID, but by the _Administrators Group_ SID. The reason is that users with administrator privileges usually run in unprivileged ("non-elevated") mode, and their user SID does not change when running in elevated mode. This is is relevant e.g. when running a GitHub workflow on a build agent, which runs in elevated mode: cloning a Git repository in a script step will cause the worktree to be owned by the Administrators Group SID, for example. Let's handle this case as following: if the current user is an administrator, Git should consider a worktree owned by the Administrators Group as if it were owned by said user. Signed-off-by: Johannes Schindelin --- compat/mingw.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compat/mingw.c b/compat/mingw.c index 22f960c7e34..7aa9318db72 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2728,6 +2728,7 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report) else if (sid && IsValidSid(sid)) { /* Now, verify that the SID matches the current user's */ static PSID current_user_sid; + BOOL is_member; if (!current_user_sid) current_user_sid = get_current_user_sid(); @@ -2736,6 +2737,15 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report) IsValidSid(current_user_sid) && EqualSid(sid, current_user_sid)) result = 1; + else if (IsWellKnownSid(sid, WinBuiltinAdministratorsSid) && + CheckTokenMembership(NULL, sid, &is_member) && + is_member) + /* + * If owned by the Administrators group, and the + * current user is an administrator, we consider that + * okay, too. + */ + result = 1; else if (report && IsWellKnownSid(sid, WinWorldSid) && !acls_supported(path)) {