From 43c440e600047eb144d9bd59236ea671e653de71 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 1 Dec 2021 11:03:27 +0100 Subject: [PATCH] Add "sasl status" command --- doc/soju.1.scd | 3 +++ service.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/doc/soju.1.scd b/doc/soju.1.scd index 455307b..93e07fb 100644 --- a/doc/soju.1.scd +++ b/doc/soju.1.scd @@ -344,6 +344,9 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just Show SHA-1 and SHA-256 fingerprints for the certificate currently used with the network. +*sasl status* + Show current SASL status. + *sasl set-plain* Set SASL PLAIN credentials. diff --git a/service.go b/service.go index a54f6a9..c27704d 100644 --- a/service.go +++ b/service.go @@ -241,6 +241,11 @@ func init() { }, "sasl": { children: serviceCommandSet{ + "status": { + usage: "", + desc: "show SASL status", + handle: handleServiceSaslStatus, + }, "set-plain": { usage: " ", desc: "set SASL PLAIN credentials", @@ -684,6 +689,38 @@ func handleServiceCertFPFingerprints(ctx context.Context, dc *downstreamConn, pa return nil } +func handleServiceSaslStatus(ctx context.Context, dc *downstreamConn, params []string) error { + if len(params) != 1 { + return fmt.Errorf("expected exactly one argument") + } + + net := dc.user.getNetwork(params[0]) + if net == nil { + return fmt.Errorf("unknown network %q", params[0]) + } + + switch net.SASL.Mechanism { + case "PLAIN": + sendServicePRIVMSG(dc, fmt.Sprintf("SASL PLAIN enabled with username %q", net.SASL.Plain.Username)) + case "EXTERNAL": + sendServicePRIVMSG(dc, "SASL EXTERNAL (CertFP) enabled") + case "": + sendServicePRIVMSG(dc, "SASL is disabled") + } + + if uc := net.conn; uc != nil { + if uc.account != "" { + sendServicePRIVMSG(dc, fmt.Sprintf("Authenticated on upstream network with account %q", uc.account)) + } else { + sendServicePRIVMSG(dc, "Unauthenticated on upstream network") + } + } else { + sendServicePRIVMSG(dc, "Disconnected from upstream network") + } + + return nil +} + func handleServiceSASLSetPlain(ctx context.Context, dc *downstreamConn, params []string) error { if len(params) != 3 { return fmt.Errorf("expected exactly 3 arguments")