void passdb_template_export(struct passdb_template *tmpl, struct auth_request *auth_request) { const struct var_expand_table *table; string_t *str; const char *const *args, *value; unsigned int i, count; str = t_str_new(256); table = auth_request_get_var_expand_table(auth_request, NULL); args = array_get(&tmpl->args, &count); i_assert((count % 2) == 0); for (i = 0; i < count; i += 2) { if (args[i+1] == NULL) value = ""; else { str_truncate(str, 0); auth_request_var_expand_with_table(str, args[i+1], auth_request, table, NULL); value = str_c(str); } auth_request_set_field(auth_request, args[i], value, STATIC_PASS_SCHEME); } }
static void passwd_file_lookup(struct auth_request *auth_request, userdb_callback_t *callback) { struct userdb_module *_module = auth_request->userdb->userdb; struct passwd_file_userdb_module *module = (struct passwd_file_userdb_module *)_module; struct passwd_user *pu; const struct var_expand_table *table; string_t *str; const char *key, *value; char **p; pu = db_passwd_file_lookup(module->pwf, auth_request, module->username_format); if (pu == NULL || pu->uid == 0) { callback(USERDB_RESULT_USER_UNKNOWN, auth_request); return; } if (pu->uid != (uid_t)-1) { auth_request_set_userdb_field(auth_request, "uid", dec2str(pu->uid)); } if (pu->gid != (gid_t)-1) { auth_request_set_userdb_field(auth_request, "gid", dec2str(pu->gid)); } if (pu->home != NULL) auth_request_set_userdb_field(auth_request, "home", pu->home); if (pu->extra_fields != NULL) { str = t_str_new(512); table = auth_request_get_var_expand_table(auth_request, NULL); for (p = pu->extra_fields; *p != NULL; p++) { if (strncmp(*p, "userdb_", 7) != 0) continue; key = *p + 7; value = strchr(key, '='); if (value != NULL) { key = t_strdup_until(key, value); str_truncate(str, 0); auth_request_var_expand_with_table(str, value + 1, auth_request, table, NULL); value = str_c(str); } else { value = ""; } auth_request_set_userdb_field(auth_request, key, value); } } callback(USERDB_RESULT_OK, auth_request); }
static void passwd_file_save_results(struct auth_request *request, const struct passwd_user *pu, const char **crypted_pass_r, const char **scheme_r) { const struct var_expand_table *table; const char *key, *value; string_t *str; char **p; *crypted_pass_r = pu->password != NULL ? pu->password : ""; *scheme_r = password_get_scheme(crypted_pass_r); if (*scheme_r == NULL) *scheme_r = request->passdb->passdb->default_pass_scheme; /* save the password so cache can use it */ auth_request_set_field(request, "password", *crypted_pass_r, *scheme_r); if (pu->extra_fields != NULL) { str = t_str_new(512); table = auth_request_get_var_expand_table(request, NULL); for (p = pu->extra_fields; *p != NULL; p++) { value = strchr(*p, '='); if (value != NULL) { key = t_strdup_until(*p, value); str_truncate(str, 0); auth_request_var_expand_with_table(str, value + 1, request, table, NULL); value = str_c(str); } else { key = *p; value = ""; } auth_request_set_field(request, key, value, NULL); } } }