Commit Diff


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	
@@ -310,12 +310,16 @@ write_access_rules(int fd, const char *path,
 }
 
 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;
 
@@ -325,6 +329,10 @@ write_web_access_rules(int fd, const char *path,
 			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,
@@ -944,15 +952,17 @@ hide_gotsys_repo(int fd, const char *path)
 }
 
 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)) {
@@ -975,10 +985,15 @@ write_webrepo(int *show_repo_description, int fd, cons
 	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;
 
@@ -1015,13 +1030,14 @@ write_webrepo(int *show_repo_description, int fd, cons
 }
 
 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) 
@@ -1067,10 +1083,18 @@ write_website(int fd, const char *path, struct gotsys_
 	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);
@@ -1088,6 +1112,7 @@ write_gotwebd_conf(void)
 	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)
@@ -1151,28 +1176,6 @@ write_gotwebd_conf(void)
 		}
 	}
 
-	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;
@@ -1321,8 +1324,8 @@ write_gotwebd_conf(void)
 			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;
 
@@ -1373,7 +1376,9 @@ write_gotwebd_conf(void)
 
 			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;
 			}
@@ -1413,8 +1418,8 @@ write_gotwebd_conf(void)
 			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;
 			}
@@ -1447,6 +1452,28 @@ write_gotwebd_conf(void)
 		}
 	}
 
+	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	
@@ -171,7 +171,7 @@ EOF
 	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