Add a sasl set-plain command

This allows to manually set the SASL credentials for a network.
This commit is contained in:
Simon Ser 2020-07-22 12:16:13 +02:00
parent cd3eacdbfc
commit 2a3ae55f52
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 34 additions and 0 deletions

View File

@ -173,6 +173,9 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just
*certfp reset* <network name> *certfp reset* <network name>
Disable SASL EXTERNAL authentication and remove stored certificate. 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] *user create* -username <username> -password <password> [-admin]
Create a new soju user. Only admin users can create new accounts. Create a new soju user. Only admin users can create new accounts.

View File

@ -187,6 +187,15 @@ func init() {
}, },
}, },
}, },
"sasl": {
children: serviceCommandSet{
"set-plain": {
usage: "<network name> <username> <password>",
desc: "set SASL PLAIN credentials",
handle: handleServiceSASLSetPlain,
},
},
},
"user": { "user": {
children: serviceCommandSet{ children: serviceCommandSet{
"create": { "create": {
@ -588,6 +597,28 @@ func handleServiceCertfpReset(dc *downstreamConn, params []string) error {
return nil 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 { func handlePasswordChange(dc *downstreamConn, params []string) error {
if len(params) != 1 { if len(params) != 1 {
return fmt.Errorf("expected exactly one argument") return fmt.Errorf("expected exactly one argument")