~emersion/soju

cc01ffc19dd770aa68332e94690c3850a70ec40b — Simon Ser 1 year, 2 months ago 2a3ae55
Rename `certfp reset` to `sasl reset`

And make it reset all SASL credentials.
2 files changed, 26 insertions(+), 26 deletions(-)

M doc/soju.1.scd
M service.go
M doc/soju.1.scd => doc/soju.1.scd +3 -3
@@ 170,12 170,12 @@ 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.

*certfp reset* <network name>
	Disable SASL EXTERNAL authentication and remove stored certificate.

*sasl set-plain* <network name> <username> <password>
	Set SASL PLAIN credentials.

*sasl reset* <network name>
	Disable SASL authentication and remove stored credentials.

*user create* -username <username> -password <password> [-admin]
	Create a new soju user. Only admin users can create new accounts.


M service.go => service.go +23 -23
@@ 180,11 180,6 @@ func init() {
					desc:   "show fingerprints of certificate associated with the network",
					handle: handleServiceCertfpFingerprints,
				},
				"reset": {
					usage:  "<network name>",
					desc:   "disable SASL EXTERNAL authentication and remove stored certificate",
					handle: handleServiceCertfpReset,
				},
			},
		},
		"sasl": {


@@ 194,6 189,11 @@ func init() {
					desc:   "set SASL PLAIN credentials",
					handle: handleServiceSASLSetPlain,
				},
				"reset": {
					usage:  "<network name>",
					desc:   "disable SASL authentication and remove stored credentials",
					handle: handleServiceSASLReset,
				},
			},
		},
		"user": {


@@ 573,9 573,9 @@ func handleServiceCertfpFingerprints(dc *downstreamConn, params []string) error 
	return nil
}

func handleServiceCertfpReset(dc *downstreamConn, params []string) error {
	if len(params) != 1 {
		return fmt.Errorf("expected exactly one argument")
func handleServiceSASLSetPlain(dc *downstreamConn, params []string) error {
	if len(params) != 3 {
		return fmt.Errorf("expected exactly 3 arguments")
	}

	net := dc.user.getNetwork(params[0])


@@ 583,23 583,21 @@ func handleServiceCertfpReset(dc *downstreamConn, params []string) error {
		return fmt.Errorf("unknown network %q", params[0])
	}

	net.SASL.External.CertBlob = nil
	net.SASL.External.PrivKeyBlob = nil
	net.SASL.Plain.Username = params[1]
	net.SASL.Plain.Password = params[2]
	net.SASL.Mechanism = "PLAIN"

	if net.SASL.Mechanism == "EXTERNAL" {
		net.SASL.Mechanism = ""
	}
	if err := dc.srv.db.StoreNetwork(dc.user.Username, &net.Network); err != nil {
	if err := dc.srv.db.StoreNetwork(net.Username, &net.Network); err != nil {
		return err
	}

	sendServicePRIVMSG(dc, "certificate reset")
	sendServicePRIVMSG(dc, "credentials saved")
	return nil
}

func handleServiceSASLSetPlain(dc *downstreamConn, params []string) error {
	if len(params) != 3 {
		return fmt.Errorf("expected exactly 3 arguments")
func handleServiceSASLReset(dc *downstreamConn, params []string) error {
	if len(params) != 1 {
		return fmt.Errorf("expected exactly one argument")
	}

	net := dc.user.getNetwork(params[0])


@@ 607,15 605,17 @@ func handleServiceSASLSetPlain(dc *downstreamConn, params []string) error {
		return fmt.Errorf("unknown network %q", params[0])
	}

	net.SASL.Plain.Username = params[1]
	net.SASL.Plain.Password = params[2]
	net.SASL.Mechanism = "PLAIN"
	net.SASL.Plain.Username = ""
	net.SASL.Plain.Password = ""
	net.SASL.External.CertBlob = nil
	net.SASL.External.PrivKeyBlob = nil
	net.SASL.Mechanism = ""

	if err := dc.srv.db.StoreNetwork(net.Username, &net.Network); err != nil {
	if err := dc.srv.db.StoreNetwork(dc.user.Username, &net.Network); err != nil {
		return err
	}

	sendServicePRIVMSG(dc, "credentials saved")
	sendServicePRIVMSG(dc, "credentials reset")
	return nil
}