Browse Source

changes to nick reservation

* Clients are now renamed, not disconnected, on reservation timeout
* Nick reservation config is now its own subsection
tags/v0.11.0-beta
Shivaram Lingamneni 6 years ago
parent
commit
988cb22692
7 changed files with 88 additions and 58 deletions
  1. 7
    1
      irc/accounts.go
  2. 4
    3
      irc/client_lookup_set.go
  3. 36
    33
      irc/config.go
  4. 5
    5
      irc/idletimer.go
  5. 17
    0
      irc/nickname.go
  6. 2
    9
      irc/server.go
  7. 17
    7
      oragono.yaml

+ 7
- 1
irc/accounts.go View File

@@ -51,7 +51,7 @@ func NewAccountManager(server *Server) *AccountManager {
51 51
 }
52 52
 
53 53
 func (am *AccountManager) buildNickToAccountIndex() {
54
-	if am.server.AccountConfig().NickReservation == NickReservationDisabled {
54
+	if am.server.AccountConfig().NickReservation.Enabled {
55 55
 		return
56 56
 	}
57 57
 
@@ -98,6 +98,12 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
98 98
 		return errAccountCreation
99 99
 	}
100 100
 
101
+	// can't register a guest nickname
102
+	renamePrefix := strings.ToLower(am.server.AccountConfig().NickReservation.RenamePrefix)
103
+	if renamePrefix != "" && strings.HasPrefix(casefoldedAccount, renamePrefix) {
104
+		return errAccountAlreadyRegistered
105
+	}
106
+
101 107
 	accountKey := fmt.Sprintf(keyAccountExists, casefoldedAccount)
102 108
 	accountNameKey := fmt.Sprintf(keyAccountName, casefoldedAccount)
103 109
 	registeredTimeKey := fmt.Sprintf(keyAccountRegTime, casefoldedAccount)

+ 4
- 3
irc/client_lookup_set.go View File

@@ -99,9 +99,10 @@ func (clients *ClientManager) SetNick(client *Client, newNick string) error {
99 99
 	}
100 100
 
101 101
 	var reservedAccount string
102
-	reservation := client.server.AccountConfig().NickReservation
103
-	if reservation != NickReservationDisabled {
102
+	var method NickReservationMethod
103
+	if client.server.AccountConfig().NickReservation.Enabled {
104 104
 		reservedAccount = client.server.accounts.NickToAccount(newcfnick)
105
+		method = client.server.AccountConfig().NickReservation.Method
105 106
 	}
106 107
 
107 108
 	clients.Lock()
@@ -113,7 +114,7 @@ func (clients *ClientManager) SetNick(client *Client, newNick string) error {
113 114
 	if currentNewEntry != nil && currentNewEntry != client {
114 115
 		return errNicknameInUse
115 116
 	}
116
-	if reservation == NickReservationStrict && reservedAccount != client.Account() {
117
+	if method == NickReservationStrict && reservedAccount != client.Account() {
117 118
 		return errNicknameReserved
118 119
 	}
119 120
 	clients.byNick[newcfnick] = client

+ 36
- 33
irc/config.go View File

@@ -58,40 +58,10 @@ func (conf *PassConfig) PasswordBytes() []byte {
58 58
 	return bytes
59 59
 }
60 60
 
61
-type NickReservation int
62
-
63
-const (
64
-	NickReservationDisabled NickReservation = iota
65
-	NickReservationWithTimeout
66
-	NickReservationStrict
67
-)
68
-
69
-func (nr *NickReservation) UnmarshalYAML(unmarshal func(interface{}) error) error {
70
-	var orig, raw string
71
-	var err error
72
-	if err = unmarshal(&orig); err != nil {
73
-		return err
74
-	}
75
-	if raw, err = Casefold(orig); err != nil {
76
-		return err
77
-	}
78
-	if raw == "disabled" || raw == "false" || raw == "" {
79
-		*nr = NickReservationDisabled
80
-	} else if raw == "timeout" {
81
-		*nr = NickReservationWithTimeout
82
-	} else if raw == "strict" {
83
-		*nr = NickReservationStrict
84
-	} else {
85
-		return errors.New(fmt.Sprintf("invalid nick-reservation value: %s", orig))
86
-	}
87
-	return nil
88
-}
89
-
90 61
 type AccountConfig struct {
91
-	Registration           AccountRegistrationConfig
92
-	AuthenticationEnabled  bool            `yaml:"authentication-enabled"`
93
-	NickReservation        NickReservation `yaml:"nick-reservation"`
94
-	NickReservationTimeout time.Duration   `yaml:"nick-reservation-timeout"`
62
+	Registration          AccountRegistrationConfig
63
+	AuthenticationEnabled bool                  `yaml:"authentication-enabled"`
64
+	NickReservation       NickReservationConfig `yaml:"nick-reservation"`
95 65
 }
96 66
 
97 67
 // AccountRegistrationConfig controls account registration.
@@ -119,6 +89,39 @@ type AccountRegistrationConfig struct {
119 89
 	AllowMultiplePerConnection bool `yaml:"allow-multiple-per-connection"`
120 90
 }
121 91
 
92
+type NickReservationMethod int
93
+
94
+const (
95
+	NickReservationWithTimeout NickReservationMethod = iota
96
+	NickReservationStrict
97
+)
98
+
99
+func (nr *NickReservationMethod) UnmarshalYAML(unmarshal func(interface{}) error) error {
100
+	var orig, raw string
101
+	var err error
102
+	if err = unmarshal(&orig); err != nil {
103
+		return err
104
+	}
105
+	if raw, err = Casefold(orig); err != nil {
106
+		return err
107
+	}
108
+	if raw == "timeout" {
109
+		*nr = NickReservationWithTimeout
110
+	} else if raw == "strict" {
111
+		*nr = NickReservationStrict
112
+	} else {
113
+		return errors.New(fmt.Sprintf("invalid nick-reservation.method value: %s", orig))
114
+	}
115
+	return nil
116
+}
117
+
118
+type NickReservationConfig struct {
119
+	Enabled       bool
120
+	Method        NickReservationMethod
121
+	RenameTimeout time.Duration `yaml:"rename-timeout"`
122
+	RenamePrefix  string        `yaml:"rename-prefix"`
123
+}
124
+
122 125
 // ChannelRegistrationConfig controls channel registration.
123 126
 type ChannelRegistrationConfig struct {
124 127
 	Enabled bool

+ 5
- 5
irc/idletimer.go View File

@@ -183,13 +183,13 @@ type NickTimer struct {
183 183
 
184 184
 // NewNickTimer sets up a new nick timer (returning nil if timeout enforcement is not enabled)
185 185
 func NewNickTimer(client *Client) *NickTimer {
186
-	config := client.server.AccountConfig()
187
-	if config.NickReservation != NickReservationWithTimeout {
186
+	config := client.server.AccountConfig().NickReservation
187
+	if !(config.Enabled && config.Method == NickReservationWithTimeout) {
188 188
 		return nil
189 189
 	}
190 190
 	nt := NickTimer{
191 191
 		client:  client,
192
-		timeout: config.NickReservationTimeout,
192
+		timeout: config.RenameTimeout,
193 193
 	}
194 194
 	return &nt
195 195
 }
@@ -239,6 +239,6 @@ func (nt *NickTimer) sendWarning() {
239 239
 
240 240
 func (nt *NickTimer) processTimeout() {
241 241
 	baseMsg := "Nick is reserved and authentication timeout expired: %v"
242
-	nt.client.Quit(fmt.Sprintf(nt.client.t(baseMsg), nt.timeout))
243
-	nt.client.destroy(false)
242
+	nt.client.Notice(fmt.Sprintf(nt.client.t(baseMsg), nt.timeout))
243
+	nt.client.server.RandomlyRename(nt.client)
244 244
 }

+ 17
- 0
irc/nickname.go View File

@@ -5,6 +5,8 @@
5 5
 package irc
6 6
 
7 7
 import (
8
+	"crypto/rand"
9
+	"encoding/hex"
8 10
 	"fmt"
9 11
 	"strings"
10 12
 
@@ -72,3 +74,18 @@ func performNickChange(server *Server, client *Client, target *Client, newnick s
72 74
 	}
73 75
 	return false
74 76
 }
77
+
78
+func (server *Server) RandomlyRename(client *Client) {
79
+	prefix := server.AccountConfig().NickReservation.RenamePrefix
80
+	if prefix == "" {
81
+		prefix = "Guest-"
82
+	}
83
+	buf := make([]byte, 8)
84
+	rand.Read(buf)
85
+	nick := fmt.Sprintf("%s%s", prefix, hex.EncodeToString(buf))
86
+	rb := NewResponseBuffer(client)
87
+	performNickChange(server, client, client, nick, rb)
88
+	rb.Send()
89
+	// technically performNickChange can fail to change the nick,
90
+	// but if they're still delinquent, the timer will get them later
91
+}

+ 2
- 9
irc/server.go View File

@@ -810,8 +810,8 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
810 810
 	server.accountConfig = &config.Accounts
811 811
 	server.configurableStateMutex.Unlock()
812 812
 
813
-	nickReservationPreviouslyDisabled := oldAccountConfig != nil && oldAccountConfig.NickReservation == NickReservationDisabled
814
-	nickReservationNowEnabled := config.Accounts.NickReservation != NickReservationDisabled
813
+	nickReservationPreviouslyDisabled := oldAccountConfig != nil && !oldAccountConfig.NickReservation.Enabled
814
+	nickReservationNowEnabled := config.Accounts.NickReservation.Enabled
815 815
 	if nickReservationPreviouslyDisabled && nickReservationNowEnabled {
816 816
 		server.accounts.buildNickToAccountIndex()
817 817
 	}
@@ -1113,13 +1113,6 @@ func (server *Server) setupListeners(config *Config) {
1113 1113
 	}
1114 1114
 }
1115 1115
 
1116
-// GetDefaultChannelModes returns our default channel modes.
1117
-func (server *Server) GetDefaultChannelModes() modes.Modes {
1118
-	server.configurableStateMutex.RLock()
1119
-	defer server.configurableStateMutex.RUnlock()
1120
-	return server.defaultChannelModes
1121
-}
1122
-
1123 1116
 // elistMatcher takes and matches ELIST conditions
1124 1117
 type elistMatcher struct {
1125 1118
 	MinClientsActive bool

+ 17
- 7
oragono.yaml View File

@@ -159,13 +159,23 @@ accounts:
159 159
     # is account authentication enabled?
160 160
     authentication-enabled: true
161 161
 
162
-    # will the server enforce that only the account holder can use the account name as a nick?
163
-    # options:
164
-    # `disabled`: no enforcement
165
-    # `timeout` (auth to nickserv within some period of time or you're disconnected)
166
-    # `strict`: must authenticate up front with SASL
167
-    nick-reservation: disabled
168
-    nick-reservation-timeout: 30s
162
+    # nick-reservation controls how, and whether, nicknames are linked to accounts
163
+    nick-reservation:
164
+        # is there any enforcement of reserved nicknames?
165
+        enabled: false
166
+
167
+        # method describes how nickname reservation is handled
168
+        #   timeout: let the user change to the registered nickname, give them X seconds
169
+        #            to login and then rename them if they haven't done so
170
+        #   strict:  don't let the user change to the registered nickname unless they're
171
+        #            already logged-in using SASL or NickServ
172
+        method: timeout
173
+
174
+        # rename-timeout - this is how long users have 'til they're renamed
175
+        rename-timeout: 30s
176
+
177
+        # rename-prefix - this is the prefix to use when renaming clients (e.g. Guest-AB54U31)
178
+        rename-prefix: Guest-
169 179
 
170 180
 # channel options
171 181
 channels:

Loading…
Cancel
Save