git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Preserve the protection mode for the Git config files
@ 2009-07-21 15:24 Catalin Marinas
  2009-07-22 18:14 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Catalin Marinas @ 2009-07-21 15:24 UTC (permalink / raw)
  To: git

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);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-07-27 18:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-21 15:24 [PATCH] Preserve the protection mode for the Git config files Catalin Marinas
2009-07-22 18:14 ` Junio C Hamano
2009-07-22 22:08   ` Nanako Shiraishi
2009-07-22 22:37     ` Johannes Schindelin
2009-07-27 18:18   ` Catalin Marinas

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).