Skip to content

Commit 0d853f7

Browse files
sirainencmouse
authored andcommitted
auth/lua: Remove auth_request#response_from_template() and string return value
1 parent 77ab914 commit 0d853f7

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

data/updates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const updates = {
1818
crypt_des_md5_schemes: '2.4.0',
1919
auth_client_common_secured: '2.4.0',
2020
auth_imap_arg_configuration_removed: '2.4.0',
21+
auth_lua_string_response_removed: '2.4.1',
2122
auth_nss: '2.3.0',
2223
auth_oauth2_no_passdb_changed: '2.4.0',
2324
auth_policy_fail_type: '2.4.0',

docs/core/config/auth/databases/lua.md

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ Logs warning message.
111111

112112
##### `auth_request#response_from_template(template)`
113113

114+
[[removed,auth_lua_string_response_removed]] This was a bit unsafe
115+
function. Return the table instead with the necessary
116+
`auth_request#var_expand()` calls.
117+
114118
Takes in `key=value` template and expands it using `var_expand()` and produces
115119
table suitable for passdb result.
116120

@@ -216,25 +220,29 @@ Lua passdb supports two modes of function:
216220

217221
Function signature is `auth_passdb_lookup(request)`.
218222

219-
Function must return a tuple, which contains a return code, and also
220-
additionally a string or table.
223+
Function must return a tuple, which contains:
224+
* `dovecot.auth.PASSDB_RESULT_OK` and extra fields table
225+
* `dovecot.auth.PASSDB_RESULT_*` error and error string
221226

222-
Table must be in key-value format, as it will be imported into auth request.
227+
The extra fields table must be in key-value format, as it will be imported into
228+
auth request.
223229

224-
The string must be in `key=value` format, except if return code indicates
225-
internal error, the second parameter can be used as error string.
230+
[[removed,auth_lua_string_response_removed]] String can no longer be returned
231+
for `PASSDB_RESULT_OK`.
226232

227233
#### Password Verification Database
228234

229235
Function signature is `auth_password_verify(request, password)`.
230236

231-
Function must return a tuple, which contains a return code, and also
232-
additionally a string or table.
237+
Function must return a tuple, which contains:
238+
* `dovecot.auth.PASSDB_RESULT_OK` and extra fields table
239+
* `dovecot.auth.PASSDB_RESULT_*` error and error string
233240

234-
Table must be in key-value format, as it will be imported into auth request.
241+
The extra fields table must be in key-value format, as it will be imported into
242+
auth request.
235243

236-
The string must be in `key=value` format, except if return code indicates
237-
internal error, the second parameter can be used as error string.
244+
[[removed,auth_lua_string_response_removed]] String can no longer be returned
245+
for `PASSDB_RESULT_OK`.
238246

239247
## userdb
240248

@@ -254,13 +262,15 @@ Lua userdb supports both single user lookup and iteration.
254262

255263
Function signature is `auth_userdb_lookup(request)`.
256264

257-
The function must return a tuple, which contains a return code, and also
258-
additionally a string or table.
265+
Function must return a tuple, which contains:
266+
* `dovecot.auth.USERDB_RESULT_OK` and extra fields table
267+
* `dovecot.auth.USERDB_RESULT_*` error and error string
259268

260-
Table must be in key-value format, as it will be imported into auth request.
269+
The extra fields table must be in key-value format, as it will be imported into
270+
auth request.
261271

262-
The string must be in key=value format, except if return code indicates
263-
internal error, the second parameter can be used as error string.
272+
[[removed,auth_lua_string_response_removed]] String can no longer be returned
273+
for `USERDB_RESULT_OK`.
264274

265275
#### User Iteration
266276

@@ -277,14 +287,14 @@ The iteration will hold the whole user database in memory during iteration.
277287
```lua:line-numbers
278288
function auth_passdb_lookup(req)
279289
if req.user == "testuser1" then
280-
return dovecot.auth.PASSDB_RESULT_OK, "password=pass"
290+
return dovecot.auth.PASSDB_RESULT_OK, { password = "pass" }
281291
end
282292
return dovecot.auth.PASSDB_RESULT_USER_UNKNOWN, "no such user"
283293
end
284294
285295
function auth_userdb_lookup(req)
286296
if req.user == "testuser1" then
287-
return dovecot.auth.USERDB_RESULT_OK, "uid=vmail gid=vmail"
297+
return dovecot.auth.USERDB_RESULT_OK, { uid = "vmail", gid = "vmail" }
288298
end
289299
return dovecot.auth.USERDB_RESULT_USER_UNKNOWN, "no such user"
290300
end
@@ -319,12 +329,12 @@ function auth_passdb_lookup(req)
319329
for user, pass in string.gmatch(line, "(%w+)%s(.+)") do
320330
if (user == req.username) then
321331
-- you can add additional information here, like userdb_uid
322-
return dovecot.auth.PASSDB_RESULT_OK, "password=" .. pass
332+
return dovecot.auth.PASSDB_RESULT_OK, { password = pass }
323333
end
324334
end
325335
end
326336
327-
return dovecot.auth.PASSDB_RESULT_USER_UNKNOWN, ""
337+
return dovecot.auth.PASSDB_RESULT_USER_UNKNOWN
328338
end
329339
```
330340

@@ -349,18 +359,18 @@ function auth_passdb_lookup(req)
349359
res = db_lookup(req.username)
350360
if res.result == 0 then
351361
-- you can add additional information here for passdb
352-
return dovecot.auth.PASSDB_RESULT_OK, "password=" .. res.password
362+
return dovecot.auth.PASSDB_RESULT_OK, { password = res.password }
353363
end
354-
return dovecot.auth.PASSDB_RESULT_USER_UNKNOWN, ""
364+
return dovecot.auth.PASSDB_RESULT_USER_UNKNOWN
355365
end
356366
357367
function auth_userdb_lookup(req)
358368
res = db_lookup(req.username)
359369
if res.result == 0 then
360370
-- you can add additional information here for userdb, like uid or home
361-
return dovecot.auth.USERDB_RESULT_OK, "uid=vmail gid=vmail"
371+
return dovecot.auth.USERDB_RESULT_OK, { uid = "vmail, gid = "vmail" }
362372
end
363-
return dovecot.auth.USERDB_RESULT_USER_UNKNOWN, ""
373+
return dovecot.auth.USERDB_RESULT_USER_UNKNOWN
364374
end
365375
366376
function auth_userdb_iterate()

0 commit comments

Comments
 (0)