git » chasquid » commit 4373f56

chasquid-util: Add domaininfo-remove

author Alberto Bertogli
2018-05-20 11:18:44 UTC
committer Alberto Bertogli
2018-05-24 22:02:57 UTC
parent a177fec7c3249ad117fc3d1745f3a4d5713f804a

chasquid-util: Add domaininfo-remove

This patch adds a chasquid-util subcommand to remove a domain
information entry.

The main use case is to manually allow a security level downgrade, after
performing manual verification.

cmd/chasquid-util/chasquid-util.go +28 -6
cmd/chasquid-util/test.sh +13 -2
docs/man/chasquid-util.1 +7 -1
docs/man/chasquid-util.1.pod +7 -0

diff --git a/cmd/chasquid-util/chasquid-util.go b/cmd/chasquid-util/chasquid-util.go
index 5a9b145..345ee44 100644
--- a/cmd/chasquid-util/chasquid-util.go
+++ b/cmd/chasquid-util/chasquid-util.go
@@ -8,6 +8,7 @@ package main
 import (
 	"fmt"
 	"io/ioutil"
+	"net/url"
 	"os"
 	"path/filepath"
 	"syscall"
@@ -33,6 +34,7 @@ Usage:
   chasquid-util [options] authenticate <username> [--password=<password>]
   chasquid-util [options] check-userdb <domain>
   chasquid-util [options] aliases-resolve <address>
+  chasquid-util [options] domaininfo-remove <domain>
   chasquid-util [options] print-config
 
 Options:
@@ -56,12 +58,13 @@ func main() {
 	}
 
 	commands := map[string]func(){
-		"user-add":        userAdd,
-		"user-remove":     userRemove,
-		"authenticate":    authenticate,
-		"check-userdb":    checkUserDB,
-		"aliases-resolve": aliasesResolve,
-		"print-config":    printConfig,
+		"user-add":          userAdd,
+		"user-remove":       userRemove,
+		"authenticate":      authenticate,
+		"check-userdb":      checkUserDB,
+		"aliases-resolve":   aliasesResolve,
+		"print-config":      printConfig,
+		"domaininfo-remove": domaininfoRemove,
 	}
 
 	for cmd, f := range commands {
@@ -247,3 +250,22 @@ func printConfig() {
 
 	fmt.Println(proto.MarshalTextString(conf))
 }
+
+// chasquid-util domaininfo-remove <domain>
+func domaininfoRemove() {
+	domain := args["<domain>"].(string)
+
+	conf, err := config.Load(configDir + "/chasquid.conf")
+	if err != nil {
+		Fatalf("Error reading config")
+	}
+
+	// File for the corresponding domain.
+	// Note this is making some assumptions about the data layout and
+	// protoio's storage structure, so it will need adjustment if they change.
+	file := conf.DataDir + "/domaininfo/s:" + url.QueryEscape(domain)
+	err = os.Remove(file)
+	if err != nil {
+		Fatalf("Error removing file: %v", err)
+	}
+}
diff --git a/cmd/chasquid-util/test.sh b/cmd/chasquid-util/test.sh
index 812c8e1..88bb6fb 100755
--- a/cmd/chasquid-util/test.sh
+++ b/cmd/chasquid-util/test.sh
@@ -19,8 +19,9 @@ function check_userdb() {
 }
 
 
-mkdir -p .config/domains/domain
-touch .config/chasquid.conf
+mkdir -p .config/domains/domain/ .data/domaininfo
+rm -f .config/chasquid.conf
+echo 'data_dir: ".data"' >> .config/chasquid.conf
 
 if ! r print-config > /dev/null; then
 	echo print-config failed
@@ -54,6 +55,16 @@ if r authenticate user@domain --password=passwd > /dev/null; then
 	exit 1
 fi
 
+touch '.data/domaininfo/s:dom%C3%A1in'
+if ! r domaininfo-remove domáin; then
+	echo domaininfo-remove failed
+	exit 1
+fi
+if [ -f '.data/domaininfo/s:dom%C3%A1in' ]; then
+	echo domaininfo-remove did not remove file
+	exit 1
+fi
+
 echo "alias: user@somewhere" > .config/domains/domain/aliases
 A=$(r aliases-resolve alias@domain | grep somewhere)
 if [ "$A" != "(email)  user@somewhere" ]; then
diff --git a/docs/man/chasquid-util.1 b/docs/man/chasquid-util.1
index 47e002a..f176043 100644
--- a/docs/man/chasquid-util.1
+++ b/docs/man/chasquid-util.1
@@ -129,7 +129,7 @@
 .\" ========================================================================
 .\"
 .IX Title "chasquid-util 1"
-.TH chasquid-util 1 "2018-04-03" "" ""
+.TH chasquid-util 1 "2018-05-20" "" ""
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
@@ -148,6 +148,8 @@ chasquid\-util \- chasquid management tool
 .PP
 \&\fBchasquid-util\fR [\fIoptions\fR] aliases-resolve \fIaddr\fR
 .PP
+\&\fBchasquid-util\fR [\fIoptions\fR] domaininfo-remove \fIdomain\fR
+.PP
 \&\fBchasquid-util\fR [\fIoptions\fR] print-config
 .SH "DESCRIPTION"
 .IX Header "DESCRIPTION"
@@ -169,6 +171,10 @@ Check the integrity of the domain's users database.
 .IP "\fBaliases-resolve\fR \fIaddr\fR" 8
 .IX Item "aliases-resolve addr"
 Resolve the given address.
+.IP "\fBdomaininfo-remove\fR \fIdomain\fR" 8
+.IX Item "domaininfo-remove domain"
+Remove the domain information entry. This can be used to manually allow a
+security level downgrade.
 .IP "\fBprint-config\fR" 8
 .IX Item "print-config"
 Parse and print the configuration in a human-readable way.
diff --git a/docs/man/chasquid-util.1.pod b/docs/man/chasquid-util.1.pod
index 6825a1d..2d90ac4 100644
--- a/docs/man/chasquid-util.1.pod
+++ b/docs/man/chasquid-util.1.pod
@@ -15,6 +15,8 @@ B<chasquid-util> [I<options>] check-userdb I<domain>
 
 B<chasquid-util> [I<options>] aliases-resolve I<addr>
 
+B<chasquid-util> [I<options>] domaininfo-remove I<domain>
+
 B<chasquid-util> [I<options>] print-config
 
 
@@ -46,6 +48,11 @@ Check the integrity of the domain's users database.
 
 Resolve the given address.
 
+=item B<domaininfo-remove> I<domain>
+
+Remove the domain information entry. This can be used to manually allow a
+security level downgrade.
+
 =item B<print-config>
 
 Parse and print the configuration in a human-readable way.