Commit Diff


commit - 495d04dbb73deee316ed8b2d081a9da2c9c972eda21f9dc26a6b53ea9c80f640
commit + dd152df4207f178669abaaf92d388783006a56893830c630b2d1882bd64eb1c2
blob - 2277906a75b307d6e8f3a9e1fd343833c5fe7957ec0c5ac48156d5223c92985e
blob + 69c8cdd96b2bb0c2782b93187af48c812c6ef3a96bb2ef57fd9270a2f072fc86
--- gotwebd/auth.c	
+++ gotwebd/auth.c	
@@ -412,6 +412,26 @@ err:
 	}
 }
 
+static const struct got_error *
+login_error_hint(struct request *c)
+{
+	struct server *srv;
+	char msg[512];
+	int ret;
+
+	srv = gotweb_get_server(c->fcgi_params.server_name);
+	if (srv == NULL || srv->login_hint_user[0] == '\0')
+		return got_error(GOT_ERR_LOGIN_FAILED);
+
+	ret = snprintf(msg, sizeof(msg),
+	    "Log in by running: ssh %s@%s \"weblogin %s\"",
+	    srv->login_hint_user, srv->name, srv->name);
+	if (ret == -1 || (size_t)ret >= sizeof(msg))
+		return got_error(GOT_ERR_LOGIN_FAILED);
+
+	return got_error_msg(GOT_ERR_LOGIN_FAILED, msg);
+}
+
 static void
 process_request(struct request *c)
 {
@@ -452,7 +472,7 @@ process_request(struct request *c)
 	if (login_check_token(&uid, &hostname, c->fcgi_params.auth_cookie,
 	    auth_token_secret, sizeof(auth_token_secret),
 	    "authentication") == -1) {
-		error = got_error(GOT_ERR_LOGIN_FAILED);
+		error = login_error_hint(c);
 		goto done;
 	}
 
@@ -461,7 +481,7 @@ process_request(struct request *c)
 	 * occurred. This user is not allowed in authentication cookies.
 	 */
 	if (uid == env->www_uid) {
-		error = got_error(GOT_ERR_LOGIN_FAILED);
+		error = login_error_hint(c);
 		goto done;
 	}
 
blob - ddb7c7b887ac519fb319476594caab11ad58e2de6068e64f853f0fb0e580e87d
blob + 639d1a8f5efb02809f6ab8403cf35437e56968b55f78d616e7557b0a930395d6
--- gotwebd/gotwebd.conf.5	
+++ gotwebd/gotwebd.conf.5	
@@ -114,6 +114,20 @@ While the specified
 .Ar path
 must be absolute, it should usually point inside the web server's chroot
 directory such that the web server can access the socket.
+.It Ic login hint user Ar name
+Sets the user name displayed in login hints which are shown on the error
+page if authentication has failed.
+This can be used to advertise the name of an anonymous user account which
+has been given read access to one or more repositories via the
+.Ic permit
+directive.
+.Pp
+If not set then no login hint will be displayed and users will somehow
+need to learn about using the
+.Xr gotsh 1
+weblogin command via other means.
+.Pp
+This setting can also be configured on a per-server basis.
 .It Ic login socket Ar path
 Set the
 .Ar path
@@ -239,6 +253,10 @@ parameter is set to
 .Ar off .
 Repositories will be hidden regardless of whether authentication is
 enabled and has failed or succeeded.
+.It Ic login hint user Ar name
+Sets the user name to use in login hints displayed when authentication fails.
+If not set then the login hint setting in the global configuration context
+will be used.
 .It Ic logo_url Ar url
 Set a hyperlink for the logo.
 Defaults to
@@ -466,12 +484,16 @@ server "secure.example.com" {
 
 	repos_path		"/var/git"
 
+	# Tell vistors who see a "login failed" error page that
+	# they can log in as the "anonymous" user via ssh.
+	login hint user "anonymous"
+
 	repository "got" {  # /var/git/got and /var/git/got.git
 		# Grant access to users who have authenticated as
 		# the anonymous user to gotsh(1), which anyone with
 		# an SSH client sbould be able to do.
 		# Dumb web crawlers will remain locked out.
-		permit anonymous
+		permit "anonymous"
 	}
 
 	repository "public" {
blob - 2d16de8dd022bf5683672653b1c563790f7335a4e1816394e854da294b577acb
blob + d1d662166aef5cc21a7869fcd77ebb8e40cc9cd2e6121d6550aaa00bed3c0cc1
--- gotwebd/gotwebd.h	
+++ gotwebd/gotwebd.h	
@@ -402,6 +402,7 @@ struct server {
 	char		 logo[GOTWEBD_MAXTEXT];
 	char		 logo_url[GOTWEBD_MAXTEXT];
 	char		 custom_css[PATH_MAX];
+	char		 login_hint_user[MAX_IDENTIFIER_SIZE];
 
 	size_t		 max_repos_display;
 	size_t		 max_commits_display;
@@ -489,6 +490,8 @@ struct gotwebd {
 
 	char		 httpd_chroot[PATH_MAX];
 	uid_t		 www_uid;
+
+	char		 login_hint_user[MAX_IDENTIFIER_SIZE];
 };
 
 /*
blob - 3112724f97a0b206e2fc35dcdab71fee3236b29718435f1aa29c2194ac539afb
blob + badb1e0087836cbc64ed02712c320097d69ad4ce8f006e6af80e9e22fe6b101b
--- gotwebd/parse.y	
+++ gotwebd/parse.y	
@@ -124,7 +124,7 @@ typedef struct {
 %token	LOGO_URL SHOW_REPO_OWNER SHOW_REPO_AGE SHOW_REPO_DESCRIPTION
 %token	MAX_REPOS_DISPLAY REPOS_PATH MAX_COMMITS_DISPLAY ON ERROR
 %token	SHOW_SITE_OWNER SHOW_REPO_CLONEURL PORT PREFORK RESPECT_EXPORTOK
-%token	SERVER CHROOT CUSTOM_CSS SOCKET
+%token	SERVER CHROOT CUSTOM_CSS SOCKET HINT
 %token	SUMMARY_COMMITS_DISPLAY SUMMARY_TAGS_DISPLAY USER AUTHENTICATION
 %token	ENABLE DISABLE INSECURE REPOSITORY REPOSITORIES PERMIT DENY HIDE
 
@@ -324,6 +324,18 @@ main		: PREFORK NUMBER {
 			gotwebd->login_sock = sockets_conf_new_socket(-1, h);
 			free($3);
 		}
+		| GOTWEBD_LOGIN HINT USER STRING {
+			n = strlcpy(gotwebd->login_hint_user, $4,
+			    sizeof(gotwebd->login_hint_user));
+			if (n >= sizeof(gotwebd->login_hint_user)) {
+				yyerror("login hint user name too long, "
+				    "exceeds %zd bytes",
+				    sizeof(gotwebd->login_hint_user) - 1);
+				free($4);
+				YYERROR;
+			}
+			free($4);
+		}
 		;
 
 server		: SERVER STRING {
@@ -449,6 +461,18 @@ serveropts1	: REPOS_PATH STRING {
 		| HIDE REPOSITORIES boolean {
 			new_srv->hide_repositories = $3;
 		}
+		| GOTWEBD_LOGIN HINT USER STRING {
+			n = strlcpy(new_srv->login_hint_user, $4,
+			    sizeof(new_srv->login_hint_user));
+			if (n >= sizeof(new_srv->login_hint_user)) {
+				yyerror("login hint user name too long, "
+				    "exceeds %zd bytes",
+				    sizeof(new_srv->login_hint_user) - 1);
+				free($4);
+				YYERROR;
+			}
+			free($4);
+		}
 		| MAX_REPOS_DISPLAY NUMBER {
 			if ($2 < 0) {
 				yyerror("max_repos_display is too small: %lld",
@@ -634,6 +658,7 @@ lookup(char *s)
 		{ "disable",			DISABLE },
 		{ "enable",			ENABLE },
 		{ "hide",			HIDE },
+		{ "hint",			HINT },
 		{ "insecure",			INSECURE },
 		{ "listen",			LISTEN },
 		{ "login",			GOTWEBD_LOGIN },
@@ -1093,6 +1118,17 @@ parse_config(const char *filename, struct gotwebd *env
 			if (repo->hidden == -1)
 				repo->hidden = srv->hide_repositories;
 		}
+
+		if (srv->login_hint_user[0] == '\0') {
+			if (strlcpy(srv->login_hint_user, env->login_hint_user,
+			    sizeof(srv->login_hint_user)) >=
+			    sizeof(srv->login_hint_user)) {
+				yyerror("login hint user name too long, "
+				    "exceeds %zd bytes",
+				    sizeof(srv->login_hint_user) - 1);
+			}
+		}
+	
 	}
 
 	return (0);
blob - 2f0a4112e5f0fc9bf5a4ae560aeaa07eda0350beed3d96cbac1c021369273e7c
blob + ce493782d6b9acca0f806c951093872374d845a8050154d7be2da70e75d798f4
--- regress/gotsysd/Makefile	
+++ regress/gotsysd/Makefile	
@@ -229,6 +229,7 @@ $(GOTWEBD_CONF):
 	@${UNPRIV} 'echo server \"VMIP\" { >> $@'
 	@${UNPRIV} 'echo \ \ repos_path \"/git\" >> $@'
 	@${UNPRIV} 'echo \ \ hide repositories on >> $@'
+	@${UNPRIV} 'echo \ \ login hint user anonymous >> $@'
 	@${UNPRIV} 'echo \ \ show_repo_age off >> $@'
 	@${UNPRIV} 'echo \ \ show_repo_description off >> $@'
 	@${UNPRIV} 'echo \ \ show_repo_owner off >> $@'
blob - 2c946294ce7011edcf39db032e6ea4b34aed9add7afe6534da2b43ab0097a35d
blob + bbb73458ad1a0a7372146e34a4efd99176fddffdb0616e90c9bbf324f6646a56
--- regress/gotsysd/test_gotwebd.sh	
+++ regress/gotsysd/test_gotwebd.sh	
@@ -25,7 +25,7 @@ test_login() {
 	cat > $testroot/stdout.expected <<EOF
 [got]
 Repos
-login failed
+Log in by running: ssh anonymous@${VMIP} "weblogin ${VMIP}"
 
 EOF
 	cmp -s $testroot/stdout.expected $testroot/stdout
@@ -116,7 +116,7 @@ EOF
 	cat > $testroot/stdout.expected <<EOF
 [got]
 Repos / gotsys.git / tree /
-login failed
+Log in by running: ssh anonymous@${VMIP} "weblogin ${VMIP}"
 
 EOF
 	cmp -s $testroot/stdout.expected $testroot/stdout
@@ -140,7 +140,7 @@ EOF
 	cat > $testroot/stdout.expected <<EOF
 [got]
 Repos / nonexistent.git / tree /
-login failed
+Log in by running: ssh anonymous@${VMIP} "weblogin ${VMIP}"
 
 EOF
 	cmp -s $testroot/stdout.expected $testroot/stdout
@@ -337,7 +337,7 @@ EOF
 	cat > $testroot/stdout.expected <<EOF
 [got]
 Repos / gottest.git / tree /
-login failed
+Log in by running: ssh anonymous@${VMIP} "weblogin ${VMIP}"
 
 EOF
 	cmp -s $testroot/stdout.expected $testroot/stdout