Skip to content

Commit

Permalink
auth: Pass userdb fields to worker
Browse files Browse the repository at this point in the history
If this is not done, then those userdb handlers
that need access to userdb variables for e.g.
interpolation, cannot access them.
  • Loading branch information
cmouse committed Oct 12, 2016
1 parent 63b557b commit 3bfdab7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/auth/auth-request.c
Expand Up @@ -7,6 +7,7 @@
#include "sha1.h"
#include "hex-binary.h"
#include "str.h"
#include "array.h"
#include "safe-memset.h"
#include "str-sanitize.h"
#include "strescape.h"
Expand Down Expand Up @@ -334,6 +335,15 @@ void auth_request_export(struct auth_request *request, string_t *dest)
str_append(dest, "\tsuccessful");
if (request->mech_name != NULL)
auth_str_add_keyvalue(dest, "mech", request->mech_name);
/* export any userdb fields */
if (request->userdb_reply != NULL) {
const ARRAY_TYPE(auth_field) *fields = auth_fields_export(request->userdb_reply);
const struct auth_field *field;
array_foreach(fields, field) {
str_printfa(dest, "\tuserdb_%s=", field->key);
str_append_tabescaped(dest, field->value);
}
}
}

bool auth_request_import_info(struct auth_request *request,
Expand Down Expand Up @@ -442,7 +452,11 @@ bool auth_request_import(struct auth_request *request,
request->skip_password_check = TRUE;
else if (strcmp(key, "mech") == 0)
request->mech_name = p_strdup(request->pool, value);
else
else if (strncmp(key, "userdb_", 7) == 0) {
if (request->userdb_reply == NULL)
request->userdb_reply = auth_fields_init(request->pool);
auth_fields_add(request->userdb_reply, key+7, value, 0);
} else
return FALSE;

return TRUE;
Expand Down
5 changes: 3 additions & 2 deletions src/auth/auth-worker-client.c
Expand Up @@ -437,7 +437,8 @@ auth_worker_handle_user(struct auth_worker_client *client,
return FALSE;
}

auth_request_init_userdb_reply(auth_request);
if (auth_request->userdb_reply == NULL)
auth_request_init_userdb_reply(auth_request);
auth_request->userdb->userdb->iface->
lookup(auth_request, lookup_user_callback);
return TRUE;
Expand Down Expand Up @@ -605,7 +606,7 @@ auth_worker_handle_line(struct auth_worker_client *client, const char *line)
unsigned int id;
bool ret = FALSE;

args = t_strsplit_tab(line);
args = t_strsplit_tabescaped(line);
if (args[0] == NULL || args[1] == NULL || args[2] == NULL ||
str_to_uint(args[0], &id) < 0) {
i_error("BUG: Invalid input: %s", line);
Expand Down

0 comments on commit 3bfdab7

Please sign in to comment.