git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Heikki Orsila <heikki.orsila@iki.fi>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Make core.sharedRepository more generic (version 2)
Date: Mon, 14 Apr 2008 17:08:03 -0700	[thread overview]
Message-ID: <7v3apo7zfg.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20080412195754.GA15091@zakalwe.fi> (Heikki Orsila's message of "Sat, 12 Apr 2008 22:57:54 +0300")

Heikki Orsila <heikki.orsila@iki.fi> writes:

> diff --git a/builtin-init-db.c b/builtin-init-db.c
> index 2854868..8c63295 100644
> --- a/builtin-init-db.c
> +++ b/builtin-init-db.c
> @@ -400,9 +400,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
>  		char buf[10];
>  		/* We do not spell "group" and such, so that
>  		 * the configuration can be read by older version
> -		 * of git.
> +		 * of git. Note, we use octal numbers.
>  		 */
> -		sprintf(buf, "%d", shared_repository);
> +		sprintf(buf, "0%o", shared_repository);

Unconditionally doing this makes the resulting repository unusable by git
1.5.5 and older, even when the user wanted to use the bog standard "git
init --shared".  You can limit the extent of damage if you continue
writing PERM_GROUP and PERM_EVERYBODY out as 1 and 2, and use the new
octal notation only when the user used the settings allowed only with new
git.

> @@ -438,11 +440,46 @@ int git_config_perm(const char *var, const char *value)
>  		    !strcmp(value, "world") ||
>  		    !strcmp(value, "everybody"))
>  			return PERM_EVERYBODY;
> +
> +		/* Parse octal numbers */
> +		i = strtol(value, &endptr, 8);
> +		if (*endptr != 0) {
> +			/* Not an octal number. Maybe true/false? */
> +			if (git_config_bool(var, value))
> +				return PERM_GROUP;
> +			else
> +				return PERM_UMASK;
> +		}
> +
> +		/* Handle compatibility cases */
> +		switch (i) {
> +		case PERM_UMASK:               /* 0 */
> +			return PERM_UMASK;
> +		case OLD_PERM_GROUP:           /* 1 */
> +			return PERM_GROUP;
> +		case OLD_PERM_EVERYBODY:       /* 2 */
> +			return PERM_EVERYBODY;
> +		}

This is valid only because forcing "chmod 0", "chmod 1", nor "chmod 2"
would not make any sense.  We might want to explain that in comment.

> +		/* A filemode value was given: 0xxx */
> +
> +		if ((i & 0600) != 0600)
> +			die("Problem with core.sharedRepository filemode value"
> +			    " (0%.3o).\nThe owner of files must always have "
> +			    "read and write permissions.", i);
> +
> +		if (i & 0002)
> +			warning("core.sharedRepository filemode (0%.3o) is a "
> +				"security threat.\nMasking off write "
> +				"permission for others\n", i);

I am not sure about this.

If the user explicitly asked for world-writable, I think we should allow
it.  "is a" is too strong a statement to make without knowing how the
access to the repository is arranged.  In a setting where there is nothing
but a restricted access over ssh, and "update-paranoid" hook in place, it
may not be a threat at all, and you are forbidding hosting services to use
such an access control model.

> +		/*
> +                 * Mask filemode value. Others can not get write permission.
> +		 * x flags for directories are handled separately.
> +                 */
Whitespace breakages.

> +		return i & 0664;

>  	}
> -	return git_config_bool(var, value);
> +	return PERM_GROUP;

At this point we know value is NULL so always returning PERM_GROUP
probably makes sense.  But if you did

	if (!value)
	        return PERM_GROUP

upfront, you can lose one level of indentation from the major parts
of this function (this is 70% style and 30% readability comment).

  reply	other threads:[~2008-04-15  0:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-12 19:57 [PATCH] Make core.sharedRepository more generic (version 2) Heikki Orsila
2008-04-15  0:08 ` Junio C Hamano [this message]
2008-04-15  0:43   ` Heikki Orsila
2008-04-15  1:22     ` Heikki Orsila

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=7v3apo7zfg.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=heikki.orsila@iki.fi \
    /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).