ad_machine_pw_renewal.c revision de8815aba87d08b6b7ac5d502dcb1755787e0857
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Sumit Bose <sbose@redhat.com>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Copyright (C) 2016 Red Hat
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes This program is free software; you can redistribute it and/or modify
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes it under the terms of the GNU General Public License as published by
0662ed52e814f8f08ef0e09956413a792584eddffuankg the Free Software Foundation; either version 3 of the License, or
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (at your option) any later version.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes This program is distributed in the hope that it will be useful,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes but WITHOUT ANY WARRANTY; without even the implied warranty of
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes GNU General Public License for more details.
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes You should have received a copy of the GNU General Public License
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes along with this program. If not, see <http://www.gnu.org/licenses/>.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char **extra_args;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic errno_t get_adcli_extra_args(const char *ad_domain,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char **args;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_CRIT_FAILURE, "Missing AD domain or hostname.\n");
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes renewal_data->prog_path = talloc_strdup(renewal_data, RENEWAL_PROG_PATH);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes args = talloc_array(renewal_data, const char *, 8);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* extra_args are added in revers order */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* first add NULL as a placeholder for the server name which is determined
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * at runtime */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes args[c++] = talloc_asprintf(args, "--computer-password-lifetime=%zu",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes args[c++] = talloc_asprintf(args, "--host-fqdn=%s", ad_hostname);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes args[c++] = talloc_asprintf(args, "--host-keytab=%s", ad_keytab);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes args[c++] = talloc_asprintf(args, "--domain=%s", ad_domain);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "talloc failed while copying arguments.\n");
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes } while (c != 1); /* is is expected that the first element is NULL */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic void ad_machine_account_password_renewal_done(struct tevent_req *subreq);
0662ed52e814f8f08ef0e09956413a792584eddffuankgad_machine_account_password_renewal_timeout(struct tevent_context *ev,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic struct tevent_req *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesad_machine_account_password_renewal_send(TALLOC_CTX *mem_ctx,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char **extra_args;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes req = tevent_req_create(mem_ctx, &state, struct renewal_state);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_OP_FAILURE, "tevent_req_create failed.\n");
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes renewal_data = talloc_get_type(pvt, struct renewal_data);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes server_name = be_fo_get_active_server_name(be_ctx, AD_SERVICE_NAME);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes renewal_data->extra_args[0] = talloc_asprintf(renewal_data->extra_args,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "--domain-controller=%s",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* if talloc_asprintf() fails we let adcli try to find a server */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes exec_child_ex(state, pipefd_to_child, pipefd_from_child,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* We should never get here */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_CRIT_FAILURE, "Could not exec renewal child\n");
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* Set up SIGCHLD handler */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ret = child_handler_setup(ev, child_pid, NULL, NULL, &state->child_ctx);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_OP_FAILURE, "Could not set up child handlers [%d]: %s\n",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* Set up timeout handler */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes tv = tevent_timeval_current_ofs(be_ptask_get_timeout(be_ptask), 0);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes state->timeout_handler = tevent_add_timer(ev, req, tv,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes subreq = read_pipe_send(state, ev, state->read_from_child_fd);
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg DEBUG(SSSDBG_OP_FAILURE, "read_pipe_send failed.\n");
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* Now either wait for the timeout to fire or the child
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes } else { /* error */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_CRIT_FAILURE, "fork failed [%d][%s].\n",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic void ad_machine_account_password_renewal_done(struct tevent_req *subreq)
0662ed52e814f8f08ef0e09956413a792584eddffuankg struct tevent_req *req = tevent_req_callback_data(subreq,
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg struct renewal_state *state = tevent_req_data(req, struct renewal_state);
int ret;
static errno_t
return EOK;
int ret;
int lifetime;
const char *dummy;
char **opt_list;
int opt_list_size;
char *endptr;
if (lifetime == 0) {
return EOK;
if (lifetime < 0) {
return EINVAL;
return ENOMEM;
goto done;
goto done;
errno = 0;
goto done;
errno = 0;
goto done;
goto done;
goto done;
done:
return ret;