Shivaram Lingamneni 4 лет назад
Родитель
Сommit
75e9476026
3 измененных файлов: 20 добавлений и 17 удалений
  1. 10
    9
      docs/MANUAL.md
  2. 3
    2
      irc/accounts.go
  3. 7
    6
      irc/authscript.go

+ 10
- 9
docs/MANUAL.md Просмотреть файл

@@ -851,15 +851,16 @@ Oragono can emulate certain capabilities of the ZNC bouncer for the benefit of c
851 851
 
852 852
 Oragono can be configured to call arbitrary scripts to authenticate users; see the `auth-script` section of the config. The API for these scripts is as follows: Oragono will invoke the script with a configurable set of arguments, then send it the authentication data as JSON on the first line (`\n`-terminated) of stdin. The input is a JSON-encoded dictionary with the following keys:
853 853
 
854
-* `AccountName`: this is a string during passphrase-based authentication, otherwise the empty string
855
-* `Passphrase`: this is a string during passphrase-based authentication, otherwise the empty string
856
-* `Certfp`: this is a string during certfp-based authentication, otherwise the empty string
854
+* `accountName`: during passphrase-based authentication, this is a string, otherwise omitted
855
+* `passphrase`: during passphrase-based authentication, this is a string, otherwise omitted
856
+* `certfp`: during certfp-based authentication, this is a string, otherwise omitted
857
+* `ip`: a string representation of the client's IP address
857 858
 
858 859
 The script must print a single line (`\n`-terminated) to its output and exit. This line must be a JSON-encoded dictionary with the following keys:
859 860
 
860
-* `Success`, a boolean indicating whether the authentication was successful
861
-* `AccountName`, a string containing the normalized account name (in the case of passphrase-based authentication, it is permissible to return the empty string or omit the value)
862
-* `Error`, containing a human-readable description of the authentication error to be logged if applicable
861
+* `success`, a boolean indicating whether the authentication was successful
862
+* `accountName`, a string containing the normalized account name (in the case of passphrase-based authentication, it is permissible to return the empty string or omit the value)
863
+* `error`, containing a human-readable description of the authentication error to be logged if applicable
863 864
 
864 865
 Here is a toy example of an authentication script in Python that checks that the account name and the password are equal (and rejects any attempts to authenticate via certfp):
865 866
 
@@ -870,10 +871,10 @@ import sys, json
870 871
 
871 872
 raw_input = sys.stdin.readline()
872 873
 input = json.loads(b)
873
-account_name = input.get("AccountName")
874
-passphrase = input.get("Passphrase")
874
+account_name = input.get("accountName")
875
+passphrase = input.get("passphrase")
875 876
 success = bool(account_name) and bool(passphrase) and account_name == passphrase
876
-print(json.dumps({"Success": success})
877
+print(json.dumps({"success": success})
877 878
 ```
878 879
 
879 880
 Note that after a failed script invocation, Oragono will proceed to check the credentials against its local database.

+ 3
- 2
irc/accounts.go Просмотреть файл

@@ -1073,7 +1073,7 @@ func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName s
1073 1073
 	if config.Accounts.AuthScript.Enabled {
1074 1074
 		var output AuthScriptOutput
1075 1075
 		output, err = CheckAuthScript(config.Accounts.AuthScript,
1076
-			AuthScriptInput{AccountName: accountName, Passphrase: passphrase})
1076
+			AuthScriptInput{AccountName: accountName, Passphrase: passphrase, IP: client.IP().String()})
1077 1077
 		if err != nil {
1078 1078
 			am.server.logger.Error("internal", "failed shell auth invocation", err.Error())
1079 1079
 			return err
@@ -1411,7 +1411,8 @@ func (am *AccountManager) AuthenticateByCertFP(client *Client, certfp, authzid s
1411 1411
 	config := am.server.Config()
1412 1412
 	if config.Accounts.AuthScript.Enabled {
1413 1413
 		var output AuthScriptOutput
1414
-		output, err = CheckAuthScript(config.Accounts.AuthScript, AuthScriptInput{Certfp: certfp})
1414
+		output, err = CheckAuthScript(config.Accounts.AuthScript,
1415
+			AuthScriptInput{Certfp: certfp, IP: client.IP().String()})
1415 1416
 		if err != nil {
1416 1417
 			am.server.logger.Error("internal", "failed shell auth invocation", err.Error())
1417 1418
 			return err

+ 7
- 6
irc/authscript.go Просмотреть файл

@@ -15,15 +15,16 @@ import (
15 15
 
16 16
 // JSON-serializable input and output types for the script
17 17
 type AuthScriptInput struct {
18
-	AccountName string
19
-	Passphrase  string
20
-	Certfp      string
18
+	AccountName string `json:"accountName,omitempty"`
19
+	Passphrase  string `json:"passphrase,omitempty"`
20
+	Certfp      string `json:"certfp,omitempty"`
21
+	IP          string `json:"ip,omitempty"`
21 22
 }
22 23
 
23 24
 type AuthScriptOutput struct {
24
-	AccountName string
25
-	Success     bool
26
-	Error       string
25
+	AccountName string `json:"accountName"`
26
+	Success     bool   `json:"success"`
27
+	Error       string `json:"error"`
27 28
 }
28 29
 
29 30
 // internal tupling of output and error for passing over a channel

Загрузка…
Отмена
Сохранить