upload-pack: read uploadpack.lazyFetchTrusted
Previous commits created and prepared the path_allowlist_apply()
and path_allowlist_config_apply() functions, but used them only for the
"safe.directory" configuration variable.
Let's reuse these functions for a new "uploadpack.lazyFetchTrusted"
configuration variable.
It allows us to:
- read an allowlist from that config variable,
- check if the current repo is in that list, and
- return the result from a new upload_pack_lazy_fetch_trusted()
function.
As path_allowlist_config_apply() lets each caller decide which paths
it is willing to accept using a callback, let's pass it a new
allow_trusted_path() callback. Unlike the "safe.directory" callback, it
accepts only absolute paths, and not ".", as `upload-pack` always
serves a repository given by an absolute path, so there is no "current
repository" for "." to refer to.
Note that a served repository is identified by its git directory, and
not by its worktree. This is because `upload-pack` uses enter_repo()
instead of the usual repository discovery, so it never learns about a
worktree and `r->worktree` is always NULL there. In practice this
means that a non-bare repository served as "/srv/repo" has to be
allowlisted as "/srv/repo/.git".
The new upload_pack_lazy_fetch_trusted() function will be used in a
following commit.
Note that the new config variable should be read only from protected
configuration files.
Signed-off-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
seen
parent
e63bb82850
commit
6a22bd1cf6
|
|
@ -34,6 +34,8 @@
|
|||
#include "json-writer.h"
|
||||
#include "strmap.h"
|
||||
#include "promisor-remote.h"
|
||||
#include "setup.h"
|
||||
#include "abspath.h"
|
||||
|
||||
/* Remember to update object flag allocation in object.h */
|
||||
#define THEY_HAVE (1u << 11)
|
||||
|
|
@ -1343,6 +1345,63 @@ static int upload_pack_config(const char *var, const char *value,
|
|||
return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs);
|
||||
}
|
||||
|
||||
/*
|
||||
* Only absolute paths make sense here. Unlike 'safe.directory', "."
|
||||
* is not accepted, as the served repository is always identified by
|
||||
* an absolute path.
|
||||
*/
|
||||
static bool allow_trusted_path(const char *path, void *cbdata_)
|
||||
{
|
||||
struct path_allowlist_cb_data *cbdata = cbdata_;
|
||||
|
||||
if (is_absolute_path(path))
|
||||
return true;
|
||||
|
||||
warning(_("%s '%s' not absolute"), cbdata->key, path);
|
||||
return false;
|
||||
}
|
||||
|
||||
struct lazy_fetch_trusted {
|
||||
char *repo_path;
|
||||
bool trusted;
|
||||
};
|
||||
|
||||
static int upload_pack_protected_lazy_fetch_config(const char *var, const char *value,
|
||||
const struct config_context *ctx UNUSED,
|
||||
void *cb_data)
|
||||
{
|
||||
struct lazy_fetch_trusted *data = cb_data;
|
||||
struct path_allowlist_cb_data cbdata = { .key = var };
|
||||
|
||||
if (strcmp("uploadpack.lazyfetchtrusted", var))
|
||||
return 0;
|
||||
|
||||
path_allowlist_config_apply(var, value, data->repo_path, &data->trusted,
|
||||
allow_trusted_path, &cbdata);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool upload_pack_lazy_fetch_trusted(struct repository *r)
|
||||
{
|
||||
struct lazy_fetch_trusted data = { 0 };
|
||||
|
||||
/*
|
||||
* A served repository is identified by its git directory, as
|
||||
* `upload-pack` uses enter_repo() instead of the usual repository
|
||||
* discovery, so its worktree, if any, is never known here.
|
||||
*/
|
||||
data.repo_path = real_pathdup(r->gitdir, 0);
|
||||
if (!data.repo_path)
|
||||
return false;
|
||||
|
||||
git_protected_config(upload_pack_protected_lazy_fetch_config, &data);
|
||||
|
||||
free(data.repo_path);
|
||||
|
||||
return !!data.trusted;
|
||||
}
|
||||
|
||||
static int upload_pack_protected_config(const char *var, const char *value,
|
||||
const struct config_context *ctx UNUSED,
|
||||
void *cb_data)
|
||||
|
|
|
|||
|
|
@ -12,4 +12,7 @@ struct strbuf;
|
|||
int upload_pack_advertise(struct repository *r,
|
||||
struct strbuf *value);
|
||||
|
||||
/* Is this repo trusted for lazy fetching? */
|
||||
bool upload_pack_lazy_fetch_trusted(struct repository *r);
|
||||
|
||||
#endif /* UPLOAD_PACK_H */
|
||||
|
|
|
|||
Loading…
Reference in New Issue