Browse Source

Review and spec updates

tags/v1.1.0-rc1
Daniel Oaks 5 years ago
parent
commit
0b644065b7
4 changed files with 21 additions and 14 deletions
  1. 2
    0
      irc/config.go
  2. 15
    12
      irc/handlers.go
  3. 2
    1
      irc/help.go
  4. 2
    1
      irc/nickserv.go

+ 2
- 0
irc/config.go View File

@@ -13,6 +13,7 @@ import (
13 13
 	"net"
14 14
 	"os"
15 15
 	"regexp"
16
+	"sort"
16 17
 	"strings"
17 18
 	"time"
18 19
 
@@ -609,6 +610,7 @@ func LoadConfig(filename string) (config *Config, err error) {
609 610
 			config.Accounts.Registration.EnabledCallbacks[i] = "*"
610 611
 		}
611 612
 	}
613
+	sort.Strings(config.Accounts.Registration.EnabledCallbacks)
612 614
 
613 615
 	config.Accounts.RequireSasl.exemptedNets, err = utils.ParseNetList(config.Accounts.RequireSasl.Exempted)
614 616
 	if err != nil {

+ 15
- 12
irc/handlers.go View File

@@ -40,18 +40,17 @@ func accHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Respo
40 40
 
41 41
 		rb.Add(nil, server.name, "ACC", "LS", "SUBCOMMANDS", "LS REGISTER VERIFY")
42 42
 
43
-		var enabledCallbacks []string
44
-		for _, name := range config.Registration.EnabledCallbacks {
45
-			enabledCallbacks = append(enabledCallbacks, name)
46
-		}
47
-		sort.Strings(enabledCallbacks)
48
-		rb.Add(nil, server.name, "ACC", "LS", "CALLBACKS", strings.Join(enabledCallbacks, " "))
43
+		// this list is sorted by the config loader, yay
44
+		rb.Add(nil, server.name, "ACC", "LS", "CALLBACKS", strings.Join(config.Registration.EnabledCallbacks, " "))
49 45
 
50 46
 		rb.Add(nil, server.name, "ACC", "LS", "CREDTYPES", "passphrase certfp")
51 47
 
48
+		flags := []string{"nospaces"}
52 49
 		if config.NickReservation.Enabled {
53
-			rb.Add(nil, server.name, "ACC", "LS", "FLAGS", "regnick")
50
+			flags = append(flags, "regnick")
54 51
 		}
52
+		sort.Strings(flags)
53
+		rb.Add(nil, server.name, "ACC", "LS", "FLAGS", strings.Join(flags, " "))
55 54
 		return false
56 55
 	}
57 56
 
@@ -113,7 +112,7 @@ func accRegisterHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r
113 112
 		return false
114 113
 	}
115 114
 
116
-	account := strings.TrimSpace(msg.Params[1])
115
+	account := msg.Params[1]
117 116
 
118 117
 	// check for account name of *
119 118
 	if account == "*" {
@@ -166,7 +165,7 @@ func accRegisterHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r
166 165
 		}
167 166
 	}
168 167
 	if credentialType == "certfp" && client.certfp == "" {
169
-		rb.Add(nil, server.name, "FAIL", "ACC", "REG_INVALID_CRED_TYPE", account, credentialType, client.t("You are not using a TLS certificate"))
168
+		rb.Add(nil, server.name, "FAIL", "ACC", "REG_INVALID_CREDENTIAL", account, client.t("You must connect with a TLS client certificate to use certfp"))
170 169
 		return false
171 170
 	}
172 171
 
@@ -190,8 +189,8 @@ func accRegisterHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r
190 189
 
191 190
 	err = server.accounts.Register(client, account, callbackNamespace, callbackValue, passphrase, certfp)
192 191
 	if err != nil {
193
-		msg := registrationErrorToMessageAndCode(err)
194
-		rb.Add(nil, server.name, "FAIL", "ACC", "REG_UNSPECIFIED_ERROR", account, client.t(msg))
192
+		msg, code := registrationErrorToMessageAndCode(err)
193
+		rb.Add(nil, server.name, "FAIL", "ACC", code, account, client.t(msg))
195 194
 		return false
196 195
 	}
197 196
 
@@ -211,11 +210,15 @@ func accRegisterHandler(server *Server, client *Client, msg ircmsg.IrcMessage, r
211 210
 	return false
212 211
 }
213 212
 
214
-func registrationErrorToMessageAndCode(err error) (message string) {
213
+func registrationErrorToMessageAndCode(err error) (message, code string) {
215 214
 	// default responses: let's be risk-averse about displaying internal errors
216 215
 	// to the clients, especially for something as sensitive as accounts
216
+	code = "REG_UNSPECIFIED_ERROR"
217 217
 	message = `Could not register`
218 218
 	switch err {
219
+	case errAccountBadPassphrase:
220
+		code = "REG_INVALID_CREDENTIAL"
221
+		message = err.Error()
219 222
 	case errAccountAlreadyRegistered, errAccountAlreadyVerified:
220 223
 		message = err.Error()
221 224
 	case errAccountCreation, errAccountMustHoldNick, errAccountBadPassphrase, errCertfpAlreadyExists, errFeatureDisabled:

+ 2
- 1
irc/help.go View File

@@ -97,7 +97,8 @@ For instance, this would set the kill, oper, account and xline snomasks on dan:
97 97
 var Help = map[string]HelpEntry{
98 98
 	// Commands
99 99
 	"acc": {
100
-		text: `ACC REGISTER <accountname> [callback_namespace:]<callback> [cred_type] :<credential>
100
+		text: `ACC LS
101
+ACC REGISTER <accountname> [callback_namespace:]<callback> [cred_type] :<credential>
101 102
 ACC VERIFY <accountname> <auth_code>
102 103
 
103 104
 Used in account registration. See the relevant specs for more info:

+ 2
- 1
irc/nickserv.go View File

@@ -406,8 +406,9 @@ func nsRegisterHandler(server *Server, client *Client, command string, params []
406 406
 	}
407 407
 
408 408
 	// details could not be stored and relevant numerics have been dispatched, abort
409
+	message, _ := registrationErrorToMessageAndCode(err)
409 410
 	if err != nil {
410
-		nsNotice(rb, client.t(registrationErrorToMessageAndCode(err)))
411
+		nsNotice(rb, client.t(message))
411 412
 		return
412 413
 	}
413 414
 }

Loading…
Cancel
Save