commit - 2d138656a94f8999dbb0db24dbf5f8b04ca67069791e5c59e095ad2a3416de90
commit + 971ff1fa812abe04d664ff75ac8117c520bc4f2d29fce5a07c347d96331584c7
blob - e14e49da7ebe4674fc8b49b21fe25eda3da0510874d20dc4ab0c9199f0167554
blob + 10993fb797182c7a74d7faa3bf0068cc428c8a6e6224acc73148114a84184234
--- gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
+++ gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
}
static const struct got_error *
-write_web_access_rules(int fd, const char *path,
+write_web_access_rules(int *have_login_hint_user, int fd, const char *path,
const char *prefix, struct gotsys_access_rule_list *rules)
{
const struct got_error *err;
struct gotsys_access_rule *rule;
+ const char *login_hint_user = NULL;
+ if (webcfg.login_hint_user[0] != '\0')
+ login_hint_user = webcfg.login_hint_user;
+
STAILQ_FOREACH(rule, rules, entry) {
const char *access;
break;
case GOTSYS_ACCESS_PERMITTED:
access = "permit ";
+
+ if (login_hint_user != NULL &&
+ strcmp(rule->identifier, login_hint_user) == 0)
+ *have_login_hint_user = 1;
break;
default:
return got_error_fmt(GOT_ERR_PARSE_CONFIG,
}
static const struct got_error *
-write_webrepo(int *show_repo_description, int fd, const char *path,
- struct gotsys_webrepo *webrepo,
- enum gotsysd_web_auth_config webd_auth_config)
+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,
+ int hide_repositories)
{
const struct got_error *err;
struct gotsys_repo *repo;
int ret;
char repo_name[_POSIX_PATH_MAX];
size_t namelen;
+ int have_login_hint_user = 0;
namelen = strlcpy(repo_name, webrepo->repo_name, sizeof(repo_name));
if (namelen >= sizeof(repo_name)) {
if (err)
return err;
- err = write_web_access_rules(fd, path, "\t\t", &webrepo->access_rules);
+ err = write_web_access_rules(&have_login_hint_user,
+ fd, path, "\t\t", &webrepo->access_rules);
if (err)
return err;
+ if (have_login_hint_user && (webrepo->hidden == 0 ||
+ (webrepo->hidden == -1 && hide_repositories != 1)))
+ *login_hint_user_access = 1;
+
if (webrepo->hidden != -1) {
const char *val;
}
static const struct got_error *
-write_website(int fd, const char *path, struct gotsys_website *site,
- enum gotsysd_web_auth_config webd_auth_config)
+write_website(int *login_hint_user_access, int fd, const char *path,
+ struct gotsys_website *site, enum gotsysd_web_auth_config webd_auth_config)
{
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);
if (ret == -1)
if (err)
return err;
- err = write_web_access_rules(fd, path, "\t\t", &site->access_rules);
+ err = write_web_access_rules(&have_login_hint_user,
+ fd, path, "\t\t", &site->access_rules);
if (err)
return err;
+ if (have_login_hint_user &&
+ (site->auth_config == GOTSYS_AUTH_ENABLED ||
+ (site->auth_config == GOTSYS_AUTH_UNSET &&
+ (webd_auth_config == GOTSYSD_WEB_AUTH_INSECURE ||
+ webd_auth_config == GOTSYSD_WEB_AUTH_SECURE))))
+ *login_hint_user_access = 1;
+
ret = dprintf(fd, "\t}\n");
if (ret == -1)
return got_error_from_errno2("dprintf", path);
const char *path = gotwebd_conf_tmppath;
struct gotsysd_web_address *addr;
struct gotsysd_web_server *srv_cfg;
+ int login_hint_user_access = 0;
err = got_opentemp_truncatefd(fd);
if (err)
}
}
- if (webcfg.login_hint_user[0] != '\0') {
- ret = dprintf(fd, "login hint user \"%s\"\n",
- webcfg.login_hint_user);
- if (ret == -1)
- return got_error_from_errno2("dprintf", path);
- if (ret != 18 + strlen(webcfg.login_hint_user) + 1) {
- return got_error_fmt(GOT_ERR_IO, "short write to %s",
- path);
- }
- }
-
- if (webcfg.login_hint_port[0] != '\0') {
- ret = dprintf(fd, "login hint port \"%s\"\n",
- webcfg.login_hint_port);
- if (ret == -1)
- return got_error_from_errno2("dprintf", path);
- if (ret != 18 + strlen(webcfg.login_hint_port) + 1) {
- return got_error_fmt(GOT_ERR_IO, "short write to %s",
- path);
- }
- }
-
switch (webcfg.auth_config) {
case GOTSYSD_WEB_AUTH_UNSET:
break;
struct got_pathlist_entry *pe;
int show_repo_description = 0;
- err = write_web_access_rules(fd, path, "\t",
- &srv->access_rules);
+ err = write_web_access_rules(&login_hint_user_access,
+ fd, path, "\t", &srv->access_rules);
if (err)
return err;
STAILQ_FOREACH(webrepo, &srv->repos, entry) {
err = write_webrepo(&show_repo_description,
- fd, path, webrepo, srv_cfg->auth_config);
+ &login_hint_user_access,
+ fd, path, webrepo, srv_cfg->auth_config,
+ hide_repositories);
if (err)
return err;
}
RB_FOREACH(pe, got_pathlist_head, &srv->websites) {
struct gotsys_website *site = pe->data;
- err = write_website(fd, path, site,
- srv_cfg->auth_config);
+ err = write_website(&login_hint_user_access,
+ fd, path, site, srv_cfg->auth_config);
if (err)
return err;
}
}
}
+ if (login_hint_user_access) {
+ ret = dprintf(fd, "login hint user \"%s\"\n",
+ webcfg.login_hint_user);
+ if (ret == -1)
+ return got_error_from_errno2("dprintf", path);
+ if (ret != 18 + strlen(webcfg.login_hint_user) + 1) {
+ return got_error_fmt(GOT_ERR_IO, "short write to %s",
+ path);
+ }
+
+ if (webcfg.login_hint_port[0] != '\0') {
+ ret = dprintf(fd, "login hint port \"%s\"\n",
+ webcfg.login_hint_port);
+ if (ret == -1)
+ return got_error_from_errno2("dprintf", path);
+ if (ret != 18 + strlen(webcfg.login_hint_port) + 1) {
+ return got_error_fmt(GOT_ERR_IO,
+ "short write to %s", path);
+ }
+ }
+ }
+
if (fchmod(gotwebd_conf_tmpfd, 0644) == -1) {
return got_error_from_errno_fmt("chmod 0644 %s",
gotwebd_conf_tmppath);
blob - a78f6c00f7da7b68e4b79ab5ea5328e23643a4002b4db583a4d2d7fdccf0494a
blob + db23e59eb1ff46d67962f8ad7468203a3677602198e6237210a723e8fc8f95bc
--- regress/gotsysd/test_gotwebd_www.sh
+++ regress/gotsysd/test_gotwebd_www.sh
cat > $testroot/stdout.expected <<EOF
[got]
Repos
-Log in by running: ssh ${GOTSYSD_TEST_USER}@${VMIP} "weblogin ${VMIP}"
+login failed
EOF
cmp -s $testroot/stdout.expected $testroot/stdout