02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose Kerberos 5 Backend Module -- Request a TGT when the system gets online
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose Sumit Bose <sbose@redhat.com>
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose Copyright (C) 2010 Red Hat
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose This program is free software; you can redistribute it and/or modify
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose it under the terms of the GNU General Public License as published by
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose the Free Software Foundation; either version 3 of the License, or
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose (at your option) any later version.
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose This program is distributed in the hope that it will be useful,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose GNU General Public License for more details.
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose You should have received a copy of the GNU General Public License
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bosestatic void *hash_talloc(const size_t size, void *pvt)
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bosestatic void hash_talloc_free(void *ptr, void *pvt)
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bosestatic void authenticate_user_done(struct tevent_req *req);
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bosestatic void authenticate_user(struct tevent_context *ev,
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose struct auth_data *auth_data = talloc_get_type(private_data,
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce keysize = keyctl_read_alloc(pd->key_serial, (void **)&password);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "keyctl_read failed [%d][%s].\n", ret, strerror(ret));
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik ret = sss_authtok_set_password(pd->authtok, password, keysize);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "failed to set password in auth token [%d][%s].\n",
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "keyctl_revoke failed [%d][%s].\n", ret, strerror(ret));
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek req = krb5_auth_queue_send(auth_data, ev, auth_data->be_ctx,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "krb5_auth_send failed.\n");
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose tevent_req_set_callback(req, authenticate_user_done, auth_data);
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozekstatic void authenticate_user_done(struct tevent_req *req)
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose struct auth_data *auth_data = tevent_req_callback_data(req,
01ec08efd0e166ac6f390f8627c6d08dcc63ccc4Jakub Hrozek ret = krb5_auth_queue_recv(req, &pam_status, &dp_err);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "krb5_auth request failed.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Successfully authenticated user [%s].\n",
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to authenticate user [%s].\n",
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose ret = get_uid_table(deferred_auth_ctx, &uid_table);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "get_uid_table failed.\n");
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose iter = new_hash_iter_context(deferred_auth_ctx->user_table);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "new_hash_iter_context failed.\n");
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose pd = talloc_get_type(entry->value.ptr, struct pam_data);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "User [%s] is still logged in, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "trying online authentication.\n", pd->user);
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose auth_data = talloc_zero(deferred_auth_ctx->be_ctx,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose auth_data->krb5_ctx = deferred_auth_ctx->krb5_ctx;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "tevent_add_timer failed.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "User [%s] is not logged in anymore, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "discarding online authentication.\n", pd->user);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "hash_delete failed [%s].\n",
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bosestatic void delayed_online_authentication_callback(void *private_data)
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose talloc_get_type(private_data, struct deferred_auth_ctx);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Delayed online authentication activated, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "but user table does not exists.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Backend is online, starting delayed online authentication.\n");
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose ret = authenticate_stored_users(deferred_auth_ctx);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "authenticate_stored_users failed.\n");
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Boseerrno_t add_user_to_delayed_online_authentication(struct krb5_ctx *krb5_ctx,
861ab44e8148208425b67c4711bc8fade10fd3edJakub Hrozek "Domain type does not support delayed authentication\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Missing context for delayed online authentication.\n");
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose if (krb5_ctx->deferred_auth_ctx->user_table == NULL) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "user_table not available.\n");
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik if (sss_authtok_get_type(pd->authtok) != SSS_AUTHTOK_TYPE_PASSWORD) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Invalid authtok for user [%s].\n", pd->user);
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose ret = copy_pam_data(krb5_ctx->deferred_auth_ctx, pd, &new_pd);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "copy_pam_data failed\n");
9acfb09f7969a69f58bd45c856b01700541853caLukas Slebodnik ret = sss_authtok_get_password(new_pd->authtok, &password, &len);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Failed to get password [%d][%s].\n", ret, strerror(ret));
64af76e2bef2565caa9738f675c108a4b3789237Simo Sorce new_pd->key_serial = add_key("user", new_pd->user, password, len,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "add_key failed [%d][%s].\n", ret, strerror(ret));
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Saved authtok of user [%s] with serial [%"SPRIkey_ser"].\n",
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose ret = hash_enter(krb5_ctx->deferred_auth_ctx->user_table,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Cannot add user [%s] to table [%s], "
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose "delayed online authentication not possible.\n",
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Added user [%s] successfully to "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "delayed online authentication.\n", pd->user);
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Boseerrno_t init_delayed_online_authentication(struct krb5_ctx *krb5_ctx,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Delayed online auth was requested "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "on an unsupported system.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Delayed online auth was requested "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "but initialisation failed.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "hash_destroy failed [%s].\n", hash_error_string(ret));
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose krb5_ctx->deferred_auth_ctx = talloc_zero(krb5_ctx,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "hash_create_ex failed [%s]\n", hash_error_string(ret));
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose krb5_ctx->deferred_auth_ctx->krb5_ctx = krb5_ctx;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "be_add_online_cb failed.\n");
02e38eae1b9cb5df2036a707dafd86f6047c17deSumit Bose /* TODO: add destructor */