git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Preserve the protection mode for the Git config files

From
CMCatalin Marinas <catalin.marinas@arm.com>
Date
Jul 21, 2009, 15:24 UTC
Message-ID
<20090721152435.16642.47207.stgit@pc1117.cambridge.arm.com>

Every time an option is set, the config file protection mode is changed to 0666 & ~umask even if it was different before. This patch is useful if people store passwords (SMTP server in the StGit case) and do not want others to read the .gitconfig file.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
 lockfile.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/lockfile.c b/lockfile.c
index eb931ed..87ee233 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -124,8 +124,12 @@ static char *resolve_symlink(char *p, size_t s)
 
 static int lock_file(struct lock_file *lk, const char *path, int flags)
 {
+	struct stat st;
+
 	if (strlen(path) >= sizeof(lk->filename))
 		return -1;
+	if (stat(path, &st) < 0)
+		st.st_mode = 0666;
 	strcpy(lk->filename, path);
 	/*
 	 * subtract 5 from size to make sure there's room for adding
@@ -134,7 +138,7 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
 	if (!(flags & LOCK_NODEREF))
 		resolve_symlink(lk->filename, sizeof(lk->filename)-5);
 	strcat(lk->filename, ".lock");
-	lk->fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
+	lk->fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, st.st_mode);
 	if (0 <= lk->fd) {
 		if (!lock_file_list) {
 			sigchain_push_common(remove_lock_file_on_signal);
Next: Junio C Hamano
Message 1 of 5 in “Preserve the protection mode for the Git config files”
  1. Preserve the protection mode for the Git config filesCatalin Marinas, Jul 21, 2009
  2. Junio C HamanoJul 22, 2009
  3. Nanako ShiraishiJul 22, 2009
  4. Johannes SchindelinJul 22, 2009
  5. Catalin MarinasJul 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.