commit - 89c81c8e277632281595eb9a0780808f4806e69c92a9aae6fc51e6677b0efc95
commit + f99fadea24254db95544b7ab122595c1785f131a2f43524168c8fba8b1bd8f45
blob - 1f62383621d43dab535d4d92db8d5f29b867f16658ce3f402e5d8b1b9c545ee7
blob + 530268bb3b9584d3bca42681e7ccc112c5afb3fffefe88285e0873f28721041a
--- gotsysd/gotsysd.c
+++ gotsysd/gotsysd.c
if (gotsysd.db_commit_fd != -1)
close(gotsysd.db_commit_fd);
+ free(gotsysd.global_repo_access_rules);
+
log_info("terminating");
exit(0);
}
#endif
apply_unveil_none();
- sysconf_main(title, gotsysd.uid_start, gotsysd.uid_end);
+ sysconf_main(title, gotsysd.uid_start, gotsysd.uid_end,
+ gotsysd.global_repo_access_rules);
/* NOTREACHED */
break;
default:
blob - 10ff01dba44a3d61199435724864e89a560dfd67f138b76542dce9caba412904
blob + 8026cefcee3482e9a2c69355e86dcd285a168023d44b680084430fdbff74e415
--- gotsysd/gotsysd.conf.5
+++ gotsysd/gotsysd.conf.5
If not specified, the path
.Pa /git
will be used.
+.It Ic repository Ic deny Ar identity
+Deny repository access to users with the username
+.Ar identity .
+.Pp
+Access rules set in
+.Nm
+apply to all repositories and override conflicting per-repository access
+rules specified in
+.Xr gotsys.conf 5 .
+.Pp
+Group names may be matched by prepending a colon
+.Pq Sq \&:
+to
+.Ar identity .
+.Pp
+The special user
+.Ar identity
+.Dq *
+(an asterisk) can be used to match all users, including the
+.Dq anonymous
+user.
+.Pp
+Multiple access rules can be specified, and the last matching rule
+determines the action taken.
+If no rule matches, the per-repository rules specified in
+.Xr gotsys.conf 5
+will take effect.
+.It Ic repository Ic permit Ar mode Ar identity
+Permit repository access to users with the username
+.Ar identity .
+.Pp
+Access rules set in
+.Nm
+apply to all repositories and override conflicting per-repository access
+rules specified in
+.Xr gotsys.conf 5 .
+.Pp
+The
+.Ar mode
+argument must be set to either
+.Ic ro
+for read-only access,
+or
+.Ic rw
+for read-write access.
+Group names may be matched by prepending a colon
+.Pq Sq \&:
+to
+.Ar identity .
+.Pp
+The special user
+.Ar identity
+.Dq anonymous
+can be used when public read-only access to repositories over SSH is desired.
+The anonymous user has an empty password, cannot use an SSH public key, and
+can only be granted read-only access.
+.Pp
+The special user
+.Ar identity
+.Dq *
+(an asterisk) can be used to match all users, except the
+.Dq anonymous
+user.
+Read-only anonymous access must be enabled explicitly.
+.Pp
+Multiple access rules can be specified, and the last matching rule
+determines the action taken.
+If no rule matches, the per-repository rules specified in
+.Xr gotsys.conf 5
+will take effect.
.It Ic uid range Ar start Ar end
Set the start and end (inclusive) of the range from which
.Xr gotsysd 8
repository directory "/git"
uid range 5000 5999
.Ed
+.Pp
+Regardless of what
+.Xr gotsys.conf 5
+says, allow the user account
+.Dq backup-user
+to read any repository:
+.Bd -literal -offset indent
+repository permit ro backup-user
+.Ed
+.Pp
+Regardless of what
+.Xr gotsys.conf 5
+says, make all repositories read-only:
+.Bd -literal -offset indent
+repository permit ro "*"
+.Ed
+.Pp
+Regardless of what
+.Xr gotsys.conf 5
+says, make all repositories inaccessible:
+.Bd -literal -offset indent
+repository deny "*"
+.Ed
.Sh SEE ALSO
.Xr got 1 ,
.Xr gotd 8 ,
blob - 1c3bbe47e3922000a38b3f1b076b4225f524efcf488ff3546e088ce7d73f0ae5
blob + b1b3c98713fe8b0320c335da0d030a0ed6af9167f5dfb724175247455a12245e
--- gotsysd/gotsysd.h
+++ gotsysd/gotsysd.h
int sysconf_fd;
char *sysconf_commit_id_str;
struct gotsysd_access_rule_list access_rules;
+ struct gotsys_access_rule_list *global_repo_access_rules;
struct event sysconf_tmo;
struct gotsysd_pending_sysconf_cmd_list sysconf_pending;
GOTSYSD_IMSG_SYSCONF_AUTHORIZED_KEYS_DONE,
GOTSYSD_IMSG_SYSCONF_REPO,
GOTSYSD_IMSG_SYSCONF_REPOS_DONE,
+ GOTSYSD_IMSG_SYSCONF_GLOBAL_ACCESS_RULE,
+ GOTSYSD_IMSG_SYSCONF_GLOBAL_ACCESS_RULES_DONE,
GOTSYSD_IMSG_SYSCONF_ACCESS_RULE,
GOTSYSD_IMSG_SYSCONF_ACCESS_RULES_DONE,
GOTSYSD_IMSG_SYSCONF_PROTECTED_TAG_NAMESPACES,
struct imsg *);
const struct got_error *gotsys_imsg_recv_authorized_keys(struct imsg *,
struct gotsys_authorized_keys_list *);
+const struct got_error *gotsys_imsg_send_access_rule(struct gotsysd_imsgev *,
+ struct gotsys_access_rule *, int);
const struct got_error *gotsys_imsg_send_repositories(struct gotsysd_imsgev *,
struct gotsys_repolist *);
const struct got_error *gotsys_imsg_recv_repository(struct gotsys_repo **,
blob - 446f4ab394347b071c772f0ce8188e116feb0e7f02609562f4768bc73679a149
blob + 6e15eb13d050ee635a051da306ea8f9eda55aebedb8a1402c438331c0014c5ae
--- gotsysd/helpers.c
+++ gotsysd/helpers.c
case GOTSYSD_IMSG_SYSCONF_WRITE_CONF_GROUP_MEMBERS_DONE:
case GOTSYSD_IMSG_SYSCONF_WRITE_CONF_GROUPS_DONE:
case GOTSYSD_IMSG_SYSCONF_REPO:
+ case GOTSYSD_IMSG_SYSCONF_GLOBAL_ACCESS_RULE:
+ case GOTSYSD_IMSG_SYSCONF_GLOBAL_ACCESS_RULES_DONE:
case GOTSYSD_IMSG_SYSCONF_ACCESS_RULE:
case GOTSYSD_IMSG_SYSCONF_ACCESS_RULES_DONE:
case GOTSYSD_IMSG_SYSCONF_PROTECTED_TAG_NAMESPACES:
blob - 688a72529e245db278fc98faaa2362b5eedfbac365c7f98dcc4609d5cc319061
blob + f9d3e7f971501023a6ef5483a4af62f6db4bef59b2db8e67c7e44e90dbb67880
--- gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
+++ gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
static size_t nprotected_refs_received;
static int gotd_conf_tmpfd = -1;
static char *gotd_conf_tmppath;
+static struct gotsys_access_rule_list global_repo_access_rules;
enum writeconf_state {
WRITECONF_STATE_EXPECT_USERS,
}
static const struct got_error *
+write_access_rule(const char *access, const char * authorization,
+ const char *identifier)
+{
+ int ret;
+
+ ret = dprintf(gotd_conf_tmpfd, "\t%s%s%s\n",
+ access, authorization, identifier);
+ if (ret == -1)
+ return got_error_from_errno2("dprintf", gotd_conf_tmppath);
+ if (ret != 1 + strlen(access) + strlen(authorization) +
+ strlen(identifier) + 1) {
+ return got_error_fmt(GOT_ERR_IO,
+ "short write to %s", gotd_conf_tmppath);
+ }
+
+ return NULL;
+}
+
+static const struct got_error *
+write_global_access_rules(void)
+{
+ const struct got_error *err;
+ struct gotsys_access_rule *rule;
+
+ STAILQ_FOREACH(rule, &global_repo_access_rules, entry) {
+ const char *access, *authorization;
+
+ switch (rule->access) {
+ case GOTSYS_ACCESS_DENIED:
+ access = "deny ";
+ break;
+ case GOTSYS_ACCESS_PERMITTED:
+ access = "permit ";
+ break;
+ default:
+ return got_error_fmt(GOT_ERR_PARSE_CONFIG,
+ "access rule with unknown access flag %d",
+ rule->access);
+ }
+
+ if (rule->authorization & GOTSYS_AUTH_WRITE)
+ authorization = "rw ";
+ else if (rule->authorization & GOTSYS_AUTH_READ)
+ authorization = "ro ";
+ else
+ authorization = "";
+
+ if (strcmp(rule->identifier, "*") == 0) {
+ struct gotsys_user *user;
+
+ STAILQ_FOREACH(user, &gotsysconf.users, entry) {
+ /*
+ * Anonymous read access must be enabled
+ * explicitly, not via *.
+ */
+ if (rule->access == GOTSYS_ACCESS_PERMITTED &&
+ strcmp(user->name, "anonymous") == 0)
+ continue;
+ err = write_access_rule(access, authorization,
+ user->name);
+ if (err)
+ return err;
+ }
+ } else {
+ err = write_access_rule(access, authorization,
+ rule->identifier);
+ if (err)
+ return err;
+ }
+ }
+
+ return NULL;
+}
+
+static const struct got_error *
write_access_rules(struct gotsys_access_rule_list *rules)
{
+ const struct got_error *err;
struct gotsys_access_rule *rule;
STAILQ_FOREACH(rule, rules, entry) {
const char *access, *authorization;
- int ret;
switch (rule->access) {
case GOTSYS_ACCESS_DENIED:
else
authorization = "";
- ret = dprintf(gotd_conf_tmpfd, "\t%s%s%s\n",
- access, authorization, rule->identifier);
- if (ret == -1)
- return got_error_from_errno2("dprintf",
- gotd_conf_tmppath);
- if (ret != 1 + strlen(access) + strlen(authorization) +
- strlen(rule->identifier) + 1) {
- return got_error_fmt(GOT_ERR_IO,
- "short write to %s", gotd_conf_tmppath);
- }
+ err = write_access_rule(access, authorization,
+ rule->identifier);
+ if (err)
+ return err;
}
return NULL;
if (err)
return err;
+ err = write_global_access_rules();
+ if (err)
+ return err;
+
err = write_protected_refs(repo);
if (err)
return err;
repo_cur = repo;
break;
}
+ case GOTSYSD_IMSG_SYSCONF_GLOBAL_ACCESS_RULE: {
+ struct gotsys_access_rule *rule;
+ if (writeconf_state != WRITECONF_STATE_EXPECT_REPOS) {
+ err = got_error_fmt(GOT_ERR_PRIVSEP_MSG,
+ "received unexpected imsg %d while in "
+ "state %d\n", imsg.hdr.type,
+ writeconf_state);
+ break;
+ }
+ err = gotsys_imsg_recv_access_rule(&rule, &imsg,
+ NULL, NULL);
+ if (err)
+ break;
+ STAILQ_INSERT_TAIL(&global_repo_access_rules, rule,
+ entry);
+ break;
+ }
+ case GOTSYSD_IMSG_SYSCONF_GLOBAL_ACCESS_RULES_DONE:
+ if (writeconf_state != WRITECONF_STATE_EXPECT_REPOS) {
+ err = got_error_fmt(GOT_ERR_PRIVSEP_MSG,
+ "received unexpected imsg %d while in "
+ "state %d\n", imsg.hdr.type,
+ writeconf_state);
+ break;
+ }
+ break;
case GOTSYSD_IMSG_SYSCONF_ACCESS_RULE: {
struct gotsys_access_rule_list *rules;
struct gotsys_access_rule *rule;
while (!attached)
sleep(1);
#endif
+ STAILQ_INIT(&global_repo_access_rules);
gotsys_conf_init(&gotsysconf);
event_init();
blob - 4edb285b4263a223674828e9ddabf05b6ca326b914667716ebb8a56eca75b8fb
blob + 37b54dadf03649cf5d25ec36d430b712f03faffc31c0ff9965230b23bbd8e7af
--- gotsysd/parse.y
+++ gotsysd/parse.y
#include "log.h"
#include "gotsysd.h"
+#include "gotsys.h"
#ifndef GOTD_USER
#define GOTD_USER "_gotd"
static enum gotsysd_procid gotsysd_proc_id;
static void conf_new_access_rule(enum gotsysd_access, char *);
+static const struct got_error *conf_new_repo_access_rule(enum gotsys_access,
+ int, const char *);
typedef struct {
union {
%}
%token ERROR LISTEN ON USER GOTD DIRECTORY REPOSITORY UID RANGE PERMIT
+%token DENY RO RW
%token <v.string> STRING
%token <v.number> NUMBER
} else
free($2);
}
+ | REPOSITORY DENY numberstring {
+ const struct got_error *err;
+
+ err = conf_new_repo_access_rule(GOTSYS_ACCESS_DENIED,
+ 0, $3);
+ if (err) {
+ yyerror("%s", err->msg);
+ free($3);
+ YYERROR;
+ }
+ free($3);
+ }
+ | REPOSITORY PERMIT RO numberstring {
+ const struct got_error *err;
+
+ err = conf_new_repo_access_rule(GOTSYS_ACCESS_PERMITTED,
+ GOTSYS_AUTH_READ, $4);
+ if (err) {
+ yyerror("%s", err->msg);
+ free($4);
+ YYERROR;
+ }
+ free($4);
+ }
+ | REPOSITORY PERMIT RW numberstring {
+ const struct got_error *err;
+
+ err = conf_new_repo_access_rule(GOTSYS_ACCESS_PERMITTED,
+ GOTSYS_AUTH_READ | GOTSYS_AUTH_WRITE, $4);
+ if (err) {
+ yyerror("%s", err->msg);
+ free($4);
+ YYERROR;
+ }
+ free($4);
+ }
;
%%
{
/* This has to be sorted always. */
static const struct keywords keywords[] = {
+ { "deny", DENY },
{ "directory", DIRECTORY },
{ "gotd", GOTD },
{ "listen", LISTEN },
{ "permit", PERMIT },
{ "range", RANGE },
{ "repository", REPOSITORY },
+ { "ro", RO },
+ { "rw", RW },
{ "uid", UID },
{ "user", USER },
};
{
struct sym *sym, *next;
int require_config_file = 0;
+ struct gotsys_access_rule_list *global_repo_access_rules;
memset(pgotsysd, 0, sizeof(*pgotsysd));
STAILQ_INIT(&gotsysd->access_rules);
+ global_repo_access_rules = malloc(sizeof(*global_repo_access_rules));
+ if (global_repo_access_rules == NULL) {
+ fprintf(stderr, "%s: malloc: %s\n", __func__,
+ strerror(errno));
+ return -1;
+ }
+ gotsysd->global_repo_access_rules = global_repo_access_rules;
+ STAILQ_INIT(gotsysd->global_repo_access_rules);
+ global_repo_access_rules = NULL;
+
/* Apply default values. */
if (strlcpy(gotsysd->unix_socket_path, GOTSYSD_UNIX_SOCKET,
sizeof(gotsysd->unix_socket_path)) >=
STAILQ_INSERT_TAIL(&gotsysd->access_rules, rule, entry);
}
+
+static const struct got_error *
+conf_new_repo_access_rule(enum gotsys_access access, int authorization,
+ const char *identifier)
+{
+ const struct got_error *err;
+ struct gotsys_access_rule *rule;
+ const char *name = identifier;
+
+ if (strcmp(name, "*") != 0) {
+ if (name[0] == ':') {
+ name++;
+ err = gotsys_conf_validate_name(name, "group");
+ if (err)
+ return err;
+ } else {
+ err = gotsys_conf_validate_name(name, "user");
+ if (err)
+ return err;
+ }
+ }
+
+ err = gotsys_conf_new_access_rule(&rule, access, authorization,
+ identifier, NULL, NULL);
+ if (err)
+ return err;
+
+ STAILQ_INSERT_TAIL(gotsysd->global_repo_access_rules, rule, entry);
+ return NULL;
+}
blob - 92f05cea6040226d4499c664afa0f06bbe3a3e5e421e17d0e843d27039e35152
blob + 0a6af52718ec1a98b27ef2163ba19a8dd396c5308427ecc2f8057179c6b4ffb6
--- gotsysd/sysconf.c
+++ gotsysd/sysconf.c
size_t *nprotected_refs_cur;
size_t nprotected_refs_needed;
size_t nprotected_refs_received;
+ struct gotsys_access_rule_list *global_repo_access_rules;
} gotsysd_sysconf;
static struct gotsys_conf gotsysconf;
send_gotsysconf(struct gotsysd_imsgev *iev)
{
const struct got_error *err;
+ struct gotsys_access_rule *rule;
err = gotsys_imsg_send_users(iev, &gotsysconf.users,
GOTSYSD_IMSG_SYSCONF_WRITE_CONF_USERS,
if (err)
return err;
+ STAILQ_FOREACH(rule, gotsysd_sysconf.global_repo_access_rules, entry) {
+ err = gotsys_imsg_send_access_rule(iev, rule,
+ GOTSYSD_IMSG_SYSCONF_GLOBAL_ACCESS_RULE);
+ if (err)
+ return err;
+ }
+
+ if (gotsysd_imsg_compose_event(iev,
+ GOTSYSD_IMSG_SYSCONF_GLOBAL_ACCESS_RULES_DONE, 0, -1,
+ NULL, 0) == -1)
+ return got_error_from_errno("gotsysd_imsg_compose_event");
+
err = gotsys_imsg_send_repositories(iev, &gotsysconf.repos);
if (err)
return err;
}
void
-sysconf_main(const char *title, uid_t uid_start, uid_t uid_end)
+sysconf_main(const char *title, uid_t uid_start, uid_t uid_end,
+ struct gotsys_access_rule_list *global_repo_access_rules)
{
struct event evsigint, evsigterm, evsighup, evsigusr1;
struct gotsysd_imsgev *iev = &gotsysd_sysconf.parent_iev;
gotsysd_sysconf.state = SYSCONF_STATE_EXPECT_PARSING_SUCCESS;
gotsysd_sysconf.uid_start = uid_start;
gotsysd_sysconf.uid_end = uid_end;
+ gotsysd_sysconf.global_repo_access_rules = global_repo_access_rules;
signal_set(&evsigint, SIGINT, sysconf_sighdlr, NULL);
signal_set(&evsigterm, SIGTERM, sysconf_sighdlr, NULL);
blob - f90c5292f58137c93debf86dfb76bf1b39c98457d65c05379eaf73d6991f0b22
blob + ac55e68936ce89db218283a8193986d025980d614e41adb47542f02eddca25c7
--- gotsysd/sysconf.h
+++ gotsysd/sysconf.h
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-void sysconf_main(const char *, uid_t, uid_t);
+void sysconf_main(const char *, uid_t, uid_t, struct gotsys_access_rule_list *);
blob - f4ccd0107a3b6f3bef370ddae46a96ce27d6e429f982078d3a1065f06ec9d969
blob + d4f7a8f4216892eb2969048dd939b880938f66cac42b25c4fef5821373aaddda
--- lib/gotsys_conf.c
+++ lib/gotsys_conf.c
return got_error_fmt(GOT_ERR_PARSE_CONFIG,
"empty group name in access rule");
- STAILQ_FOREACH(group, groups, entry) {
- if (strcmp(group->name, name) == 0)
- break;
+ if (groups) {
+ STAILQ_FOREACH(group, groups, entry) {
+ if (strcmp(group->name, name) == 0)
+ break;
+ }
+ if (group == NULL) {
+ return got_error_fmt(GOT_ERR_PARSE_CONFIG,
+ "reference to undeclared group '%s' via "
+ "access rule", name);
+ }
}
- if (group == NULL) {
- return got_error_fmt(GOT_ERR_PARSE_CONFIG,
- "reference to undeclared group '%s' via "
- "access rule", name);
- }
} else if (strcmp(name, "anonymous") == 0) {
if (access == GOTSYS_ACCESS_PERMITTED &&
(authorization & GOTSYS_AUTH_WRITE)) {
"the \"anonymous\" user must not have write "
"permission");
}
- } else {
+ } else if (users) {
struct gotsys_user *user = NULL;
STAILQ_FOREACH(user, users, entry) {
blob - 9478da308f3f9151e7eafb19695cafb76eccbb7e82b2014eb06024e336a523a6
blob + e411d5b06543076adc282ccd78cc09896f9d91ef1d908c81281df68aeaf2e95e
--- lib/gotsys_imsg.c
+++ lib/gotsys_imsg.c
return err;
}
-static const struct got_error *
-send_access_rule(struct gotsysd_imsgev *iev,
- struct gotsys_access_rule *rule)
+const struct got_error *
+gotsys_imsg_send_access_rule(struct gotsysd_imsgev *iev,
+ struct gotsys_access_rule *rule, int imsg_type)
{
struct gotsysd_imsg_sysconf_access_rule irule;
struct ibuf *wbuf = NULL;
irule.authorization = rule->authorization;
irule.identifier_len = strlen(rule->identifier);
- wbuf = imsg_create(&iev->ibuf, GOTSYSD_IMSG_SYSCONF_ACCESS_RULE,
+ wbuf = imsg_create(&iev->ibuf, imsg_type,
0, 0, sizeof(irule) + irule.identifier_len);
if (wbuf == NULL)
return got_error_from_errno("imsg_create SYSCONF_ACCESS_RULE");
imsg_close(&iev->ibuf, wbuf);
STAILQ_FOREACH(rule, &repo->access_rules, entry) {
- err = send_access_rule(iev, rule);
+ err = gotsys_imsg_send_access_rule(iev, rule,
+ GOTSYSD_IMSG_SYSCONF_ACCESS_RULE);
if (err)
return err;
}
blob - 3f47bc0848b9184e512968095b23182c21908c89c0e81c5d9251bbcda1989692
blob + 3e85fc33ab1a6edf767f6cadc57f5f9fbf4d30bed37e0646886b02eb6a3a2c37
--- regress/gotsysd/test_gotsysd.sh
+++ regress/gotsysd/test_gotsysd.sh
test_done "$testroot" "$ret"
}
+test_override_access_rules() {
+ local testroot=`test_init override_access_rules 1`
+
+ # Override gotsys.conf access rules which deny access to foo.git.
+ echo "repository permit ro ${GOTSYSD_DEV_USER}" | \
+ ssh -q -i ${GOTSYSD_SSH_KEY} root@${VMIP} \
+ 'cat >> /etc/gotsysd.conf'
+
+ # Restart gotsysd (XXX need a better way to do this...)
+ ssh -q -i ${GOTSYSD_SSH_KEY} root@${VMIP} 'pkill -xf /usr/local/sbin/gotsysd'
+ sleep 1
+ ssh -q -i ${GOTSYSD_SSH_KEY} root@${VMIP} '/usr/local/sbin/gotsysd -vvv'
+ sleep 1
+ ssh -q -i ${GOTSYSD_SSH_KEY} root@${VMIP} 'gotsys apply -w' > /dev/null
+
+ # Cloning repository foo should now succeed.
+ got clone -q -i ${GOTSYSD_SSH_KEY} -b foo \
+ ${GOTSYSD_DEV_USER}@${VMIP}:foo.git $testroot/foo.git \
+ > $testroot/stdout 2> $testroot/stderr
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "got clone failed unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ # gotsys.git access should now be read-only.
+ got clone -q -i ${GOTSYSD_SSH_KEY} \
+ ${GOTSYSD_DEV_USER}@${VMIP}:gotsys.git $testroot/gotsys2.git \
+ > $testroot/stdout 2> $testroot/stderr
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "got clone failed unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+ got checkout -q $testroot/gotsys2.git $testroot/wt >/dev/null
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "got checkout failed unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ crypted_vm_pw=`echo ${GOTSYSD_VM_PASSWORD} | encrypt | tr -d '\n'`
+ crypted_pw=`echo ${GOTSYSD_DEV_PASSWORD} | encrypt | tr -d '\n'`
+ sshkey=`cat ${GOTSYSD_SSH_PUBKEY}`
+ cat > ${testroot}/wt/gotsys.conf <<EOF
+group slackers
+
+user ${GOTSYSD_TEST_USER} {
+ password "${crypted_vm_pw}"
+ authorized key ${sshkey}
+}
+user ${GOTSYSD_DEV_USER} {
+ password "${crypted_pw}"
+ authorized key ${sshkey}
+}
+repository gotsys.git {
+ permit rw ${GOTSYSD_TEST_USER}
+ permit rw ${GOTSYSD_DEV_USER}
+}
+repository "foo" {
+ deny ${GOTSYSD_DEV_USER}
+ permit ro anonymous
+ head foo
+ protect branch foo
+ protect {
+ tag namespace "refs/tags"
+ }
+}
+repository "bar" {
+ permit rw ${GOTSYSD_DEV_USER}
+}
+EOF
+ (cd ${testroot}/wt && \
+ got commit -m "add bar.git repository" >/dev/null)
+ local commit_id=`git_show_head $testroot/gotsys2.git`
+
+ got send -q -i ${GOTSYSD_SSH_KEY} -r ${testroot}/gotsys2.git \
+ > $testroot/stdout 2> $testroot/stderr
+ ret=$?
+ if [ $ret -eq 0 ]; then
+ echo "got send succeeded unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ echo "gotsh: gotsys.git: Permission denied" > $testroot/stderr.expected
+ grep '^gotsh:' $testroot/stderr > $testroot/stderr.filtered
+ cmp -s $testroot/stderr.expected $testroot/stderr.filtered
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr.filtered
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+ test_done "$testroot" "$ret"
+}
+
+test_override_all_user_access() {
+ local testroot=`test_init override_all_user_access 1`
+
+ # Override gotsys.conf access rules which deny access to foo.git.
+ echo 'repository deny "*"' | \
+ ssh -q -i ${GOTSYSD_SSH_KEY} root@${VMIP} \
+ 'cat >> /etc/gotsysd.conf'
+
+ # Restart gotsysd (XXX need a better way to do this...)
+ ssh -q -i ${GOTSYSD_SSH_KEY} root@${VMIP} 'pkill -xf /usr/local/sbin/gotsysd'
+ sleep 1
+ ssh -q -i ${GOTSYSD_SSH_KEY} root@${VMIP} '/usr/local/sbin/gotsysd -vvv'
+ sleep 1
+ ssh -q -i ${GOTSYSD_SSH_KEY} root@${VMIP} 'gotsys apply -w' > /dev/null
+
+ # Cloning any repository as any user should now fail.
+ for user in ${GOTSYSD_TEST_USER} ${GOTSYSD_DEV_USER} anonymous; do
+ got clone -q -i ${GOTSYSD_SSH_KEY} -b foo \
+ ${user}@${VMIP}:foo.git $testroot/foo-${user}.git \
+ > $testroot/stdout 2> $testroot/stderr
+ ret=$?
+ if [ $ret -eq 0 ]; then
+ echo "got clone succeeded unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ echo "got-fetch-pack: foo: Permission denied" \
+ > $testroot/stderr.expected
+ grep '^got-fetch-pack:' $testroot/stderr \
+ > $testroot/stderr.filtered
+ cmp -s $testroot/stderr.expected $testroot/stderr.filtered
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stderr.expected \
+ $testroot/stderr.filtered
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got clone -q -i ${GOTSYSD_SSH_KEY} \
+ ${user}@${VMIP}:gotsys.git \
+ $testroot/gotsys-${user}.git \
+ > $testroot/stdout 2> $testroot/stderr
+ ret=$?
+ if [ $ret -eq 0 ]; then
+ echo "got clone succeeded unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ echo "got-fetch-pack: gotsys.git: Permission denied" \
+ > $testroot/stderr.expected
+ grep '^got-fetch-pack:' $testroot/stderr \
+ > $testroot/stderr.filtered
+ cmp -s $testroot/stderr.expected $testroot/stderr.filtered
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stderr.expected \
+ $testroot/stderr.filtered
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+ done
+
+ test_done "$testroot" "$ret"
+}
+
test_parseargs "$@"
run_test test_user_add
run_test test_user_mod
run_test test_set_head
run_test test_protect_refs
run_test test_deny_access
+run_test test_override_access_rules
+run_test test_override_all_user_access