Changeset 363 in code for trunk


Ignore:
Timestamp:
Jul 22, 2020, 10:16:13 AM (5 years ago)
Author:
contact
Message:

Add a sasl set-plain command

This allows to manually set the SASL credentials for a network.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/soju.1.scd

    r361 r363  
    174174        Disable SASL EXTERNAL authentication and remove stored certificate.
    175175
     176*sasl set-plain* <network name> <username> <password>
     177        Set SASL PLAIN credentials.
     178
    176179*user create* -username <username> -password <password> [-admin]
    177180        Create a new soju user. Only admin users can create new accounts.
  • trunk/service.go

    r358 r363  
    188188                        },
    189189                },
     190                "sasl": {
     191                        children: serviceCommandSet{
     192                                "set-plain": {
     193                                        usage:  "<network name> <username> <password>",
     194                                        desc:   "set SASL PLAIN credentials",
     195                                        handle: handleServiceSASLSetPlain,
     196                                },
     197                        },
     198                },
    190199                "user": {
    191200                        children: serviceCommandSet{
     
    589598}
    590599
     600func handleServiceSASLSetPlain(dc *downstreamConn, params []string) error {
     601        if len(params) != 3 {
     602                return fmt.Errorf("expected exactly 3 arguments")
     603        }
     604
     605        net := dc.user.getNetwork(params[0])
     606        if net == nil {
     607                return fmt.Errorf("unknown network %q", params[0])
     608        }
     609
     610        net.SASL.Plain.Username = params[1]
     611        net.SASL.Plain.Password = params[2]
     612        net.SASL.Mechanism = "PLAIN"
     613
     614        if err := dc.srv.db.StoreNetwork(net.Username, &net.Network); err != nil {
     615                return err
     616        }
     617
     618        sendServicePRIVMSG(dc, "credentials saved")
     619        return nil
     620}
     621
    591622func handlePasswordChange(dc *downstreamConn, params []string) error {
    592623        if len(params) != 1 {
Note: See TracChangeset for help on using the changeset viewer.