Procházet zdrojové kódy

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 před 6 roky
rodič
revize
988cb22692
7 změnil soubory, kde provedl 88 přidání a 58 odebrání
  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 Zobrazit soubor

51
 }
51
 }
52
 
52
 
53
 func (am *AccountManager) buildNickToAccountIndex() {
53
 func (am *AccountManager) buildNickToAccountIndex() {
54
-	if am.server.AccountConfig().NickReservation == NickReservationDisabled {
54
+	if am.server.AccountConfig().NickReservation.Enabled {
55
 		return
55
 		return
56
 	}
56
 	}
57
 
57
 
98
 		return errAccountCreation
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
 	accountKey := fmt.Sprintf(keyAccountExists, casefoldedAccount)
107
 	accountKey := fmt.Sprintf(keyAccountExists, casefoldedAccount)
102
 	accountNameKey := fmt.Sprintf(keyAccountName, casefoldedAccount)
108
 	accountNameKey := fmt.Sprintf(keyAccountName, casefoldedAccount)
103
 	registeredTimeKey := fmt.Sprintf(keyAccountRegTime, casefoldedAccount)
109
 	registeredTimeKey := fmt.Sprintf(keyAccountRegTime, casefoldedAccount)

+ 4
- 3
irc/client_lookup_set.go Zobrazit soubor

99
 	}
99
 	}
100
 
100
 
101
 	var reservedAccount string
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
 		reservedAccount = client.server.accounts.NickToAccount(newcfnick)
104
 		reservedAccount = client.server.accounts.NickToAccount(newcfnick)
105
+		method = client.server.AccountConfig().NickReservation.Method
105
 	}
106
 	}
106
 
107
 
107
 	clients.Lock()
108
 	clients.Lock()
113
 	if currentNewEntry != nil && currentNewEntry != client {
114
 	if currentNewEntry != nil && currentNewEntry != client {
114
 		return errNicknameInUse
115
 		return errNicknameInUse
115
 	}
116
 	}
116
-	if reservation == NickReservationStrict && reservedAccount != client.Account() {
117
+	if method == NickReservationStrict && reservedAccount != client.Account() {
117
 		return errNicknameReserved
118
 		return errNicknameReserved
118
 	}
119
 	}
119
 	clients.byNick[newcfnick] = client
120
 	clients.byNick[newcfnick] = client

+ 36
- 33
irc/config.go Zobrazit soubor

58
 	return bytes
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
 type AccountConfig struct {
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
 // AccountRegistrationConfig controls account registration.
67
 // AccountRegistrationConfig controls account registration.
119
 	AllowMultiplePerConnection bool `yaml:"allow-multiple-per-connection"`
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
 // ChannelRegistrationConfig controls channel registration.
125
 // ChannelRegistrationConfig controls channel registration.
123
 type ChannelRegistrationConfig struct {
126
 type ChannelRegistrationConfig struct {
124
 	Enabled bool
127
 	Enabled bool

+ 5
- 5
irc/idletimer.go Zobrazit soubor

183
 
183
 
184
 // NewNickTimer sets up a new nick timer (returning nil if timeout enforcement is not enabled)
184
 // NewNickTimer sets up a new nick timer (returning nil if timeout enforcement is not enabled)
185
 func NewNickTimer(client *Client) *NickTimer {
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
 		return nil
188
 		return nil
189
 	}
189
 	}
190
 	nt := NickTimer{
190
 	nt := NickTimer{
191
 		client:  client,
191
 		client:  client,
192
-		timeout: config.NickReservationTimeout,
192
+		timeout: config.RenameTimeout,
193
 	}
193
 	}
194
 	return &nt
194
 	return &nt
195
 }
195
 }
239
 
239
 
240
 func (nt *NickTimer) processTimeout() {
240
 func (nt *NickTimer) processTimeout() {
241
 	baseMsg := "Nick is reserved and authentication timeout expired: %v"
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 Zobrazit soubor

5
 package irc
5
 package irc
6
 
6
 
7
 import (
7
 import (
8
+	"crypto/rand"
9
+	"encoding/hex"
8
 	"fmt"
10
 	"fmt"
9
 	"strings"
11
 	"strings"
10
 
12
 
72
 	}
74
 	}
73
 	return false
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 Zobrazit soubor

810
 	server.accountConfig = &config.Accounts
810
 	server.accountConfig = &config.Accounts
811
 	server.configurableStateMutex.Unlock()
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
 	if nickReservationPreviouslyDisabled && nickReservationNowEnabled {
815
 	if nickReservationPreviouslyDisabled && nickReservationNowEnabled {
816
 		server.accounts.buildNickToAccountIndex()
816
 		server.accounts.buildNickToAccountIndex()
817
 	}
817
 	}
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
 // elistMatcher takes and matches ELIST conditions
1116
 // elistMatcher takes and matches ELIST conditions
1124
 type elistMatcher struct {
1117
 type elistMatcher struct {
1125
 	MinClientsActive bool
1118
 	MinClientsActive bool

+ 17
- 7
oragono.yaml Zobrazit soubor

159
     # is account authentication enabled?
159
     # is account authentication enabled?
160
     authentication-enabled: true
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
 # channel options
180
 # channel options
171
 channels:
181
 channels:

Načítá se…
Zrušit
Uložit