Parcourir la source

Merge pull request #531 from slingamn/issue410.1

fix #410
tags/v1.1.0-rc1
Daniel Oaks il y a 5 ans
Parent
révision
236f8fa9fd
Aucun compte lié à l'adresse e-mail de l'auteur
5 fichiers modifiés avec 58 ajouts et 49 suppressions
  1. 7
    7
      docs/MANUAL.md
  2. 4
    0
      irc/accounts.go
  3. 6
    5
      irc/hostserv.go
  4. 22
    23
      irc/nickserv.go
  5. 19
    14
      irc/services.go

+ 7
- 7
docs/MANUAL.md Voir le fichier

@@ -129,17 +129,17 @@ In this section, we'll explain and go through using various features of the Orag
129 129
 
130 130
 In most IRC servers you can use `NickServ` to register an account. You can do the same thing with Oragono, by default, with no other software needed!
131 131
 
132
-These are the two ways you can register an account:
132
+These are the two ways you can register an account, either one will work:
133 133
 
134
-    /QUOTE ACC REGISTER <username> * passphrase :<password>
135
-    /NS REGISTER <username> * <password>
134
+    /QUOTE ACC REGISTER <username> * passphrase <password>
135
+    /NS REGISTER <password>
136 136
 
137
-This is the way to go if you want to use a regular password. `<username>` and `<password>` are your username and password, respectively (make sure the leave that one `:` before your actual password!).
137
+This is the way to go if you want to use a regular password. `<username>` and `<password>` are your username and password, respectively; if you go the `/NS REGISTER` route, then your current nickname will become your username. Your password cannot contain spaces, but make sure to use a strong one anyway.
138 138
 
139
-    /QUOTE ACC REGISTER <username> * certfp *
140
-    /NS REGISTER <username>
139
+If you want to use a TLS client certificate instead of a password to authenticate (`SASL EXTERNAL`), then you can use the commands below to do so. (If you're not sure what this is, don't worry – just use the above password method to register an account.)
141 140
 
142
-If you want to use a TLS client certificate to authenticate (`SASL CERTFP`), then you can use the above method to do so. If you're not sure what this is, don't worry – just use the above password method to register an account.
141
+    /QUOTE ACC REGISTER <username> * certfp *
142
+    /NS REGISTER *
143 143
 
144 144
 Once you've registered, you'll need to setup SASL to login (or use NickServ IDENTIFY). One of the more complete SASL instruction pages is Freenode's page [here](https://freenode.net/kb/answer/sasl). Open up that page, find your IRC client and then setup SASL with your chosen username and password!
145 145
 

+ 4
- 0
irc/accounts.go Voir le fichier

@@ -397,6 +397,10 @@ func validatePassphrase(passphrase string) error {
397 397
 	if len(passphrase) == 0 || len(passphrase) > 600 {
398 398
 		return errAccountBadPassphrase
399 399
 	}
400
+	// we use * as a placeholder in some places, if it's gotten this far then fail
401
+	if passphrase == "*" {
402
+		return errAccountBadPassphrase
403
+	}
400 404
 	// for now, just enforce that spaces are not allowed
401 405
 	for _, r := range passphrase {
402 406
 		if unicode.IsSpace(r) {

+ 6
- 5
irc/hostserv.go Voir le fichier

@@ -120,11 +120,12 @@ APPROVE approves a user's vhost request.`,
120 120
 
121 121
 REJECT rejects a user's vhost request, optionally giving them a reason
122 122
 for the rejection.`,
123
-			helpShort: `$bREJECT$b rejects a user's vhost request.`,
124
-			capabs:    []string{"vhosts"},
125
-			enabled:   hostservEnabled,
126
-			minParams: 1,
127
-			maxParams: 2,
123
+			helpShort:         `$bREJECT$b rejects a user's vhost request.`,
124
+			capabs:            []string{"vhosts"},
125
+			enabled:           hostservEnabled,
126
+			minParams:         1,
127
+			maxParams:         2,
128
+			unsplitFinalParam: true,
128 129
 		},
129 130
 	}
130 131
 )

+ 22
- 23
irc/nickserv.go Voir le fichier

@@ -110,16 +110,17 @@ INFO gives you information about the given (or your own) user account.`,
110 110
 			handler: nsRegisterHandler,
111 111
 			// TODO: "email" is an oversimplification here; it's actually any callback, e.g.,
112 112
 			// person@example.com, mailto:person@example.com, tel:16505551234.
113
-			help: `Syntax: $bREGISTER <username> <email> [password]$b
113
+			help: `Syntax: $bREGISTER <password> [email]$b
114 114
 
115
-REGISTER lets you register a user account. If the server allows anonymous
116
-registration, you can send an asterisk (*) as the email address.
115
+REGISTER lets you register your current nickname as a user account. If the
116
+server allows anonymous registration, you can omit the e-mail address.
117 117
 
118
-If the password is left out, your account will be registered to your TLS client
119
-certificate (and you will need to use that certificate to login in future).`,
118
+If you are currently logged in with a TLS client certificate and wish to use
119
+it instead of a password to log in, send * as the password.`,
120 120
 			helpShort: `$bREGISTER$b lets you register a user account.`,
121 121
 			enabled:   servCmdRequiresAccreg,
122
-			minParams: 2,
122
+			minParams: 1,
123
+			maxParams: 2,
123 124
 		},
124 125
 		"sadrop": {
125 126
 			handler: nsDropHandler,
@@ -586,20 +587,25 @@ func nsInfoHandler(server *Server, client *Client, command string, params []stri
586 587
 }
587 588
 
588 589
 func nsRegisterHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
589
-	// get params
590
-	account, email := params[0], params[1]
591
-	var passphrase string
592
-	if len(params) > 2 {
593
-		passphrase = params[2]
590
+	details := client.Details()
591
+	account := details.nick
592
+	passphrase := params[0]
593
+	var email string
594
+	if 1 < len(params) {
595
+		email = params[1]
594 596
 	}
595 597
 
596 598
 	certfp := client.certfp
597
-	if passphrase == "" && certfp == "" {
598
-		nsNotice(rb, client.t("You need to either supply a passphrase or be connected via TLS with a client cert"))
599
-		return
599
+	if passphrase == "*" {
600
+		if certfp == "" {
601
+			nsNotice(rb, client.t("You must be connected with TLS and a client certificate to do this"))
602
+			return
603
+		} else {
604
+			passphrase = ""
605
+		}
600 606
 	}
601 607
 
602
-	if client.LoggedIntoAccount() {
608
+	if details.account != "" {
603 609
 		nsNotice(rb, client.t("You're already logged into an account"))
604 610
 		return
605 611
 	}
@@ -608,13 +614,6 @@ func nsRegisterHandler(server *Server, client *Client, command string, params []
608 614
 		return
609 615
 	}
610 616
 
611
-	// band-aid to let users know if they mix up the order of registration params
612
-	if email == "*" {
613
-		nsNotice(rb, client.t("Registering your account with no email address"))
614
-	} else {
615
-		nsNotice(rb, fmt.Sprintf(client.t("Registering your account with email address %s"), email))
616
-	}
617
-
618 617
 	config := server.AccountConfig()
619 618
 	var callbackNamespace, callbackValue string
620 619
 	noneCallbackAllowed := false
@@ -630,7 +629,7 @@ func nsRegisterHandler(server *Server, client *Client, command string, params []
630 629
 		callbackNamespace = "*"
631 630
 	} else {
632 631
 		callbackNamespace, callbackValue = parseCallback(email, config)
633
-		if callbackNamespace == "" {
632
+		if callbackNamespace == "" || callbackValue == "" {
634 633
 			nsNotice(rb, client.t("Registration requires a valid e-mail address"))
635 634
 			return
636 635
 		}

+ 19
- 14
irc/services.go Voir le fichier

@@ -26,17 +26,18 @@ type ircService struct {
26 26
 
27 27
 // defines a command associated with a service, e.g., NICKSERV IDENTIFY
28 28
 type serviceCommand struct {
29
-	aliasOf      string   // marks this command as an alias of another
30
-	capabs       []string // oper capabs the given user has to have to access this command
31
-	handler      func(server *Server, client *Client, command string, params []string, rb *ResponseBuffer)
32
-	help         string
33
-	helpStrings  []string
34
-	helpShort    string
35
-	authRequired bool
36
-	hidden       bool
37
-	enabled      func(*Config) bool // is this command enabled in the server config?
38
-	minParams    int
39
-	maxParams    int // split into at most n params, with last param containing remaining unsplit text
29
+	aliasOf           string   // marks this command as an alias of another
30
+	capabs            []string // oper capabs the given user has to have to access this command
31
+	handler           func(server *Server, client *Client, command string, params []string, rb *ResponseBuffer)
32
+	help              string
33
+	helpStrings       []string
34
+	helpShort         string
35
+	enabled           func(*Config) bool // is this command enabled in the server config?
36
+	authRequired      bool
37
+	hidden            bool
38
+	minParams         int
39
+	maxParams         int  // optional, if set it's an error if the user passes more than this many params
40
+	unsplitFinalParam bool // split into at most maxParams, with last param containing unsplit text
40 41
 }
41 42
 
42 43
 // looks up a command in the table of command definitions for a service, resolving aliases
@@ -109,7 +110,7 @@ func serviceCmdHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb
109 110
 	params := msg.Params[1:]
110 111
 	cmd := lookupServiceCommand(service.Commands, commandName)
111 112
 	// for a maxParams command, join all final parameters together if necessary
112
-	if cmd != nil && cmd.maxParams != 0 && cmd.maxParams < len(params) {
113
+	if cmd != nil && cmd.unsplitFinalParam && cmd.maxParams < len(params) {
113 114
 		newParams := make([]string, cmd.maxParams)
114 115
 		copy(newParams, params[:cmd.maxParams-1])
115 116
 		newParams[cmd.maxParams-1] = strings.Join(params[cmd.maxParams-1:], " ")
@@ -130,7 +131,7 @@ func servicePrivmsgHandler(service *ircService, server *Server, client *Client,
130 131
 	commandName := strings.ToLower(params[0])
131 132
 	cmd := lookupServiceCommand(service.Commands, commandName)
132 133
 	// reparse if needed
133
-	if cmd != nil && cmd.maxParams != 0 {
134
+	if cmd != nil && cmd.unsplitFinalParam {
134 135
 		params = utils.FieldsN(message, cmd.maxParams+1)[1:]
135 136
 	} else {
136 137
 		params = params[1:]
@@ -150,7 +151,7 @@ func serviceRunCommand(service *ircService, server *Server, client *Client, cmd
150 151
 		return
151 152
 	}
152 153
 
153
-	if len(params) < cmd.minParams {
154
+	if len(params) < cmd.minParams || (0 < cmd.maxParams && cmd.maxParams < len(params)) {
154 155
 		sendNotice(fmt.Sprintf(client.t("Invalid parameters. For usage, do /msg %[1]s HELP %[2]s"), service.Name, strings.ToUpper(commandName)))
155 156
 		return
156 157
 	}
@@ -277,6 +278,10 @@ func initializeServices() {
277 278
 					log.Fatal(fmt.Sprintf("help entry missing for %s command %s", serviceName, commandName))
278 279
 				}
279 280
 			}
281
+
282
+			if commandInfo.maxParams == 0 && commandInfo.unsplitFinalParam {
283
+				log.Fatal("unsplitFinalParam requires use of maxParams")
284
+			}
280 285
 		}
281 286
 	}
282 287
 

Chargement…
Annuler
Enregistrer