commit 014fbe8cd308fa0ef1839e98ae396df9dae27848ea84bb1fcd916d89e65b752c from: Stefan Sperling date: Wed Feb 11 10:06:56 2026 UTC make gotsys-write-conf configure clone-urls for all accessible repositories Previously, clone URLs would only be written for repositories explicitly mentioned in the web server configuration section. Set clone-URLs for other repositories, too, provided they can be cloned by the anonymous user (really the login-hint user, which is usually "anonymous" or similar). Add test coverage. commit - 73a1042b23ffcc068bf3ba2f53ca03583ba74b936d2d3e2391dbbc9ba3165a39 commit + 014fbe8cd308fa0ef1839e98ae396df9dae27848ea84bb1fcd916d89e65b752c blob - c007484e8d8bbb1bffde44b0e7adb94f723ea440e2d59ac316b4c518074f8f4b blob + 47e8149e1f629f7a94a65335545503d20982da0ffe9af240b7d57ef7f934a0e2 --- gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c +++ gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c @@ -972,6 +972,118 @@ hide_gotsys_repo(int fd, const char *path) } static const struct got_error * +write_clone_url(int fd, const char *path, const char *server_name, + const char *repo_name) +{ + char *clone_url; + int ret; + + if (asprintf(&clone_url, "ssh://%s@%s%s%s/%s.git", + webcfg.login_hint_user, server_name, + webcfg.login_hint_port[0] ? ":" : "", + webcfg.login_hint_port[0] ? webcfg.login_hint_port : "", + repo_name) == -1) + return got_error_from_errno("asprintf"); + + ret = dprintf(fd, "\t\tclone_url \"%s\"\n", clone_url); + if (ret == -1) { + free(clone_url); + return got_error_from_errno2("dprintf", path); + } + if (ret != 14 + strlen(clone_url) + 1) { + free(clone_url); + return got_error_fmt(GOT_ERR_IO, + "short write to %s", path); + } + + free(clone_url); + return NULL; +} + +static const struct got_error * +canon_repo_name(char *outbuf, size_t outsize, const char *repo_name) +{ + size_t namelen; + + namelen = strlcpy(outbuf, repo_name, outsize); + if (namelen >= outsize) { + return got_error_fmt(GOT_ERR_NO_SPACE, + "repository name too long: %s", repo_name); + } + + if (namelen > 4 && strcmp(&repo_name[namelen - 4], GOTWEB_GIT_DIR) == 0) + outbuf[namelen - 4] = '\0'; + + return NULL; +} + +static const struct got_error * +write_implicit_clone_url(int fd, const char *path, const char *server_name, + const char *full_repo_name) +{ + const struct got_error *err; + char repo_name[_POSIX_PATH_MAX]; + int ret; + + err = canon_repo_name(repo_name, sizeof(repo_name), full_repo_name); + if (err) + return err; + + ret = dprintf(fd, "\trepository \"%s\" {\n", repo_name); + if (ret == -1) + return got_error_from_errno2("dprintf", path); + if (ret != 16 + strlen(repo_name) + 1) + return got_error_fmt(GOT_ERR_IO, "short write to %s", path); + + err = write_clone_url(fd, path, server_name, repo_name); + if (err) + return err; + + ret = dprintf(fd, "\t}\n"); + if (ret == -1) + return got_error_from_errno2("dprintf", path); + if (ret != 3) + return got_error_fmt(GOT_ERR_IO, "short write to %s", path); + + return NULL; +} + +/* Write clone URls for repositories which are not listed as a webrepo. */ +static const struct got_error * +write_implicit_clone_urls(int fd, const char *path, + struct gotsys_webserver *srv) +{ + const struct got_error *err = NULL; + struct gotsys_repo *repo; + struct gotsys_webrepo *webrepo; + struct gotsys_access_rule *rule; + + TAILQ_FOREACH(repo, &gotsysconf.repos, entry) { + if (strcmp(repo->name, "gotsys") == 0 || + strcmp(repo->name, "gotsys.git") == 0) + continue; + + webrepo = gotsys_find_webrepo_by_name(repo->name, &srv->repos); + if (webrepo) + continue; + + STAILQ_FOREACH(rule, &repo->access_rules, entry) { + if (rule->access == GOTSYS_ACCESS_PERMITTED && + strcmp(rule->identifier, + webcfg.login_hint_user) == 0) { + err = write_implicit_clone_url(fd, path, + srv->server_name, repo->name); + if (err) + return err; + break; + } + } + } + + return NULL; +} + +static const struct got_error * write_webrepo(int *show_repo_description, int *login_hint_user_access, int fd, const char *path, struct gotsys_webrepo *webrepo, enum gotsysd_web_auth_config webd_auth_config, @@ -981,20 +1093,13 @@ write_webrepo(int *show_repo_description, int *login_h struct gotsys_repo *repo; int ret; char repo_name[_POSIX_PATH_MAX]; - size_t namelen; int have_login_hint_user = 0; int login_hint_user_has_repo_access = 0; - namelen = strlcpy(repo_name, webrepo->repo_name, sizeof(repo_name)); - if (namelen >= sizeof(repo_name)) { - return got_error_msg(GOT_ERR_NO_SPACE, - "repository name too long"); - } + err = canon_repo_name(repo_name, sizeof(repo_name), webrepo->repo_name); + if (err) + return err; - if (namelen > 4 && - strcmp(&repo_name[namelen - 4], GOTWEB_GIT_DIR) == 0) - repo_name[namelen - 4] = '\0'; - ret = dprintf(fd, "\trepository \"%s\" {\n", repo_name); if (ret == -1) return got_error_from_errno2("dprintf", path); @@ -1068,26 +1173,9 @@ write_webrepo(int *show_repo_description, int *login_h } if (login_hint_user_has_repo_access) { - char *clone_url; - - if (asprintf(&clone_url, "ssh://%s@%s%s%s/%s.git", - webcfg.login_hint_user, server_name, - webcfg.login_hint_port[0] ? ":" : "", - webcfg.login_hint_port[0] ? webcfg.login_hint_port : "", - repo_name) == -1) - return got_error_from_errno("asprintf"); - - ret = dprintf(fd, "\t\tclone_url \"%s\"\n", clone_url); - if (ret == -1) { - free(clone_url); - return got_error_from_errno2("dprintf", path); - } - if (ret != 14 + strlen(clone_url) + 1) { - free(clone_url); - return got_error_fmt(GOT_ERR_IO, - "short write to %s", path); - } - free(clone_url); + err = write_clone_url(fd, path, server_name, repo_name); + if (err) + return err; } ret = dprintf(fd, "\t}\n"); @@ -1106,7 +1194,6 @@ write_website(int *login_hint_user_access, int fd, con const struct got_error *err; int ret; char repo_name[_POSIX_PATH_MAX]; - size_t namelen; int have_login_hint_user = 0; ret = dprintf(fd, "\twebsite \"%s\" {\n", site->url_path); @@ -1115,17 +1202,10 @@ write_website(int *login_hint_user_access, int fd, con if (ret != 13 + strlen(site->url_path) + 1) return got_error_fmt(GOT_ERR_IO, "short write to %s", path); + err = canon_repo_name(repo_name, sizeof(repo_name), site->repo_name); + if (err) + return err; - namelen = strlcpy(repo_name, site->repo_name, sizeof(repo_name)); - if (namelen >= sizeof(repo_name)) { - return got_error_msg(GOT_ERR_NO_SPACE, - "repository name too long"); - } - - if (namelen > 4 && - strcmp(&repo_name[namelen - 4], GOTWEB_GIT_DIR) == 0) - repo_name[namelen - 4] = '\0'; - ret = dprintf(fd, "\t\trepository \"%s\"\n", repo_name); if (ret == -1) return got_error_from_errno2("dprintf", path); @@ -1494,6 +1574,11 @@ write_gotwebd_conf(void) if (err) return err; } + + err = write_implicit_clone_urls(fd, path, srv); + if (err) + return err; + if (!show_repo_description) { ret = dprintf(fd, "\tshow_repo_description off\n"); blob - 57e406ea44876b6c8eef01d43db72adb5ad21a4c969ae7c146cf7bee07d645e9 blob + ac9d41d902211b9e797bf592c6ec88d9431f8af89d40d06876a58af6be0a25c4 --- regress/gotsysd/test_gotwebd.sh +++ regress/gotsysd/test_gotwebd.sh @@ -941,6 +941,166 @@ EOF return 1 fi + # Test the case where a repository inherits default setings + # without being mentioned in the web server block. + cat > ${testroot}/wt/gotsys.conf <&2 + test_done "$testroot" 1 + return 1 + fi + + (cd ${testroot}/wt && got commit -m "no-op change" >/dev/null) + local commit_id=`git_show_head $testroot/${GOTSYS_REPO}` + + got send -q -i ${GOTSYSD_SSH_KEY} -r ${testroot}/${GOTSYS_REPO} + ret=$? + if [ $ret -ne 0 ]; then + echo "got send failed unexpectedly" >&2 + test_done "$testroot" 1 + return 1 + fi + + # Wait for gotsysd to apply the new configuration. + echo "$commit_id" > $testroot/stdout.expected + for i in 1 2 3 4 5; do + sleep 1 + ssh -i ${GOTSYSD_SSH_KEY} root@${VMIP} \ + cat /var/db/gotsysd/commit > $testroot/stdout + if cmp -s $testroot/stdout.expected $testroot/stdout; then + break; + fi + done + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + echo "gotsysd failed to apply configuration" >&2 + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + got checkout -E -q $testroot/public.git $testroot/public > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got checkout failed unexpectedly" >&2 + test_done "$testroot" 1 + return 1 + fi + + cat > $testroot/public/readme.txt </dev/null) + local commit_id=`git_show_head $testroot/public.git` + local short_commit_id=`trim_obj_id 10 $commit_id` + + got send -q -i ${GOTSYSD_SSH_KEY} -b main -f -r $testroot/public.git + ret=$? + if [ $ret -ne 0 ]; then + echo "got send failed unexpectedly" >&2 + return 1 + fi + + # Attempt to access a public repository's summary + w3m "http://${VMIP}/?action=summary&path=public.git" -dump \ + > $testroot/stdout + + grep -v 'seconds ago' $testroot/stdout > $testroot/stdout.filtered + + cat > $testroot/stdout.expected <