git » chasquid » commit c425593

chasquid-util: Handle usernames without domain

author Alberto Bertogli
2017-04-10 18:22:40 UTC
committer Alberto Bertogli
2017-04-10 18:48:35 UTC
parent b86463f1233d12b54142ef8bc71be325a41a6e7c

chasquid-util: Handle usernames without domain

Usernames must be of the form user@domain. When the domain is missing,
this patch makes chasquid-util emit a friendly error (instead of
crashing).

cmd/chasquid-util/chasquid-util.go +3 -0

diff --git a/cmd/chasquid-util/chasquid-util.go b/cmd/chasquid-util/chasquid-util.go
index 43282cb..8ced913 100644
--- a/cmd/chasquid-util/chasquid-util.go
+++ b/cmd/chasquid-util/chasquid-util.go
@@ -82,6 +82,9 @@ func userDBForDomain(domain string) string {
 func userDBFromArgs(create bool) (string, string, *userdb.DB) {
 	username := args["<username>"].(string)
 	user, domain := envelope.Split(username)
+	if domain == "" {
+		Fatalf("Domain missing, username should be of the form 'user@domain'")
+	}
 
 	db, err := userdb.Load(userDBForDomain(domain))
 	if err != nil {