~emersion/soju

2a3ae55f5205989c6d5f61b06004b5f2e6c6a0c2 — Simon Ser 1 year, 1 month ago cd3eacd
Add a `sasl set-plain` command

This allows to manually set the SASL credentials for a network.
2 files changed, 34 insertions(+), 0 deletions(-)

M doc/soju.1.scd
M service.go
M doc/soju.1.scd => doc/soju.1.scd +3 -0
@@ 173,6 173,9 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just
*certfp reset* <network name>
	Disable SASL EXTERNAL authentication and remove stored certificate.

*sasl set-plain* <network name> <username> <password>
	Set SASL PLAIN 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 +31 -0
@@ 187,6 187,15 @@ func init() {
				},
			},
		},
		"sasl": {
			children: serviceCommandSet{
				"set-plain": {
					usage:  "<network name> <username> <password>",
					desc:   "set SASL PLAIN credentials",
					handle: handleServiceSASLSetPlain,
				},
			},
		},
		"user": {
			children: serviceCommandSet{
				"create": {


@@ 588,6 597,28 @@ func handleServiceCertfpReset(dc *downstreamConn, params []string) error {
	return nil
}

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

	net := dc.user.getNetwork(params[0])
	if net == nil {
		return fmt.Errorf("unknown network %q", params[0])
	}

	net.SASL.Plain.Username = params[1]
	net.SASL.Plain.Password = params[2]
	net.SASL.Mechanism = "PLAIN"

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

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

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