commit - de3ada86e34282186fb0fffb169c74e4cca0216f9bbb1d053aa78c440c94c36c
commit + c381a9c462498f67f93338e33ae530dd95b57dbd3e40e4aede7d89db0e5edb52
blob - a4661acb08b133c3f72fc9349bfae1e9fcd8f8a23158eac7bb5d983023bca5fb
blob + 156a3f313fc90a6df2aac13a704945f76eadec7ba8ee43b7320ba28603a58236
--- gotwebd/auth.c
+++ gotwebd/auth.c
const char *identifier = NULL;
char *request_path = NULL;
int is_repository_request = 0;
+ struct passwd *pw = NULL;
srv = gotweb_get_server(c->fcgi_params.server_name);
if (srv == NULL) {
"identifier too long");
goto done;
}
+ pw = getpwuid(uid);
+ if (pw) {
+ if (strlcpy(c->client_username, pw->pw_name,
+ sizeof(c->client_username)) >= sizeof(c->client_username)) {
+ error = got_error_msg(GOT_ERR_NO_SPACE,
+ "username too long");
+ goto done;
+ }
+ }
if (gotwebd_env->gotwebd_verbose > 0) {
log_info("authenticated UID %u as %s for server \"%s\"",
blob - 0d93057916fb19a5e672b41593c08242564928944be48a241fb7b2d5cf3b5503
blob + c847e0c272361c2cad1c16a4790eddd58a58db761cf1bc1621ccd266d3368ee5
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
uid_t client_uid;
char access_identifier[MAX_IDENTIFIER_SIZE];
+ char client_username[MAX_IDENTIFIER_SIZE];
};
TAILQ_HEAD(requestlist, request);
blob - e846dcf1482320b60b370e4e77978e7bf13606cfda3743f6046aae45e099e67a
blob + 2021ad223878857aef27e1b8ae89f5b4b0c870d5a9bdfb0e0197f62a8c24e0bd
--- gotwebd/pages.tmpl
+++ gotwebd/pages.tmpl
<img src="{{ prefix }}/{{ srv->logo }}" />
</a>
</div>
- {{ if (c->access_identifier[0]) }}
+ {{ if (c->client_username[0] || c->access_identifier[0]) }}
<div id="login_status">
- Logged in as: <b>{{ c->access_identifier }}</b>
+ Logged in as: <b>{{ c->client_username[0] ?
+ c->client_username : c->access_identifier }}</b>
(<a href="{{ render gotweb_render_url(c, &u_logout) }}">Logout</a>)
</div>
{{ end }}
blob - b6bf90d0f30abc3ab290ba8c0f79c10d0ede37d3c61b14c2dd9e98e53ff43df3
blob + 5269911176f549d7dace31847685d10735427f9286fac6df40b1889d6f71d5ef
--- regress/gotsysd/test_gotwebd.sh
+++ regress/gotsysd/test_gotwebd.sh
return 1
fi
+ # Test authentication via group membership.
+ 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 writers
+group devs
+group testers
+user ${GOTSYSD_TEST_USER} {
+ password "${crypted_vm_pw}"
+ authorized key ${sshkey}
+ group writers
+ group testers
+}
+user ${GOTSYSD_DEV_USER} {
+ password "${crypted_pw}"
+ authorized key ${sshkey}
+ group writers
+ group devs
+}
+repository gotsys.git {
+ permit rw :writers
+}
+repository public.git {
+ permit rw :writers
+}
+repository gottestdev.git {
+ permit rw :devs
+}
+repository gottest.git {
+ permit rw :testers
+}
+repository hidden.git {
+ permit rw :testers
+}
+web server "${VMIP}" {
+ repository public {
+ disable authentication
+ }
+ repository gottestdev.git {
+ permit :devs
+ deny :testers
+ }
+ repository gottest.git {
+ permit :testers
+ }
+ repository hidden {
+ permit :testers
+ deny :devs
+ hide repository on
+ }
+}
+EOF
+ (cd ${testroot}/wt && gotsys check -q)
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "bad gotsys.conf written by test" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ (cd ${testroot}/wt && got commit -m "use group auth" >/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
+
+ # Obtain a login token over ssh.
+ ssh -q -i ${GOTSYSD_SSH_KEY} ${GOTSYSD_TEST_USER}@${VMIP} \
+ 'gotsh -c weblogin' > $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "ssh login failed failed unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ url=$(cut -d: -f 2,3 < $testroot/stdout | sed -e 's/ https:/http:/')
+ w3m -cookie-jar "$testroot/cookies" "$url" -dump > $testroot/stdout
+ cat > $testroot/stdout.expected <<EOF
+[got]
+Logged in as: ${GOTSYSD_TEST_USER} (Logout)
+Repositories
+Repository
+gottest.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+public.git
+summary | briefs | commits | tags | tree | rss
+-------------------------------------------------------------------------------
+
+EOF
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ # Attempt to access the private repository's tree again with cookie
+ w3m -cookie-jar $testroot/cookies \
+ "http://${VMIP}/?action=tree&path=gottest.git" -dump \
+ > $testroot/stdout
+
+ cat > $testroot/stdout.expected <<EOF
+[got]
+Logged in as: ${GOTSYSD_TEST_USER} (Logout)
+Repositories / gottest.git / tree /
+reference refs/heads/main not found
+
+EOF
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
test_done "$testroot" "$ret"
}