From 74085e92c095d0bf4b98e262cc07ccf9b7dfff3b Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 27 Feb 2017 11:14:42 -0800 Subject: Honor user's umask when saving files If the user wants new files to be created as 600, they will have set their umask to 077 in their environment. vis shouldn't restrict this further than the user has configured. --- text.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/text.c b/text.c index bc599f5..59af7a1 100644 --- a/text.c +++ b/text.c @@ -856,7 +856,7 @@ static bool text_save_begin_atomic(TextSave *ctx) { goto err; snprintf(ctx->tmpname, namelen, "%s~", ctx->filename); - if ((ctx->fd = open(ctx->tmpname, O_CREAT|O_WRONLY|O_TRUNC, oldfd == -1 ? S_IRUSR|S_IWUSR : oldmeta.st_mode)) == -1) + if ((ctx->fd = open(ctx->tmpname, O_CREAT|O_WRONLY|O_TRUNC, oldfd == -1 ? 0666 : oldmeta.st_mode)) == -1) goto err; if (oldfd != -1) { if (!preserve_acl(oldfd, ctx->fd) || !preserve_selinux_context(oldfd, ctx->fd)) @@ -924,7 +924,7 @@ static bool text_save_begin_inplace(TextSave *ctx) { Text *txt = ctx->txt; struct stat meta = { 0 }; int newfd = -1, saved_errno; - if ((ctx->fd = open(ctx->filename, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR)) == -1) + if ((ctx->fd = open(ctx->filename, 0666, S_IRUSR|S_IWUSR)) == -1) goto err; if (fstat(ctx->fd, &meta) == -1) goto err; -- cgit v1.2.3