sudosrv_cmd.c revision d117004902c767d46430848b6ef1c11c3ad82835
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Pavel Březina <pbrezina@redhat.com>
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes Copyright (C) 2011 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
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes 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.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes You should have received a copy of the GNU General Public License
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes along with this program. If not, see <http://www.gnu.org/licenses/>.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic errno_t sudosrv_cmd_send_reply(struct sudo_cmd_ctx *cmd_ctx,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ("Unable to create a new packet [%d]; %s\n",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ret = sss_packet_grow(cli_ctx->creq->out, response_len);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes sss_packet_get_body(cli_ctx->creq->out, &packet_body, &packet_len);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic errno_t sudosrv_cmd_send_error(TALLOC_CTX *mem_ctx,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_MINOR_FAILURE, ("Everything is fine but we are "
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "returning error?\n"));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ret = sudosrv_build_response(mem_ctx, error, NULL, 0, NULL,
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg return sudosrv_cmd_send_reply(cmd_ctx, response_body, response_len);
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgerrno_t sudosrv_cmd_done(struct sudo_cmd_ctx *cmd_ctx, int ret)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Parent of cmd_ctx->rules is in-memory cache, we must not talloc_free it!
0662ed52e814f8f08ef0e09956413a792584eddffuankg /* filter rules by time */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ret = sysdb_sudo_filter_rules_by_time(cmd_ctx, cmd_ctx->num_rules,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* send result */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ret = sudosrv_build_response(cmd_ctx, SSS_SUDO_ERROR_OK,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ret = sudosrv_cmd_send_reply(cmd_ctx, response_body, response_len);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* async processing, just return here */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* very bad error */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* case ENOENT:
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * - means user not found
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg * - send error ENOENT
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg /* send error */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ret = sudosrv_cmd_send_error(cmd_ctx, cmd_ctx, ret);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_CRIT_FAILURE, ("Fatal error, killing connection!\n"));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic int sudosrv_cmd(enum sss_sudo_type type, struct cli_ctx *cli_ctx)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* create cmd_ctx */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes cmd_ctx = talloc_zero(cli_ctx, struct sudo_cmd_ctx);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* kill the connection here as we have no context for reply */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_FATAL_FAILURE, ("Out of memory?\n"));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes cmd_ctx->sudo_ctx = talloc_get_type(cli_ctx->rctx->pvt_ctx, struct sudo_ctx);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_FATAL_FAILURE, ("sudo_ctx not set, killing connection!\n"));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* if protocol is invalid return */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (cli_ctx->cli_protocol_version->version != SSS_SUDO_PROTOCOL_VERSION) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_FATAL_FAILURE, ("Invalid protocol! [%d]\n",
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* parse query */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes sss_packet_get_body(cli_ctx->creq->in, &query_body, &query_len);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes &cmd_ctx->uid, &cmd_ctx->username, &cmd_ctx->domain);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_CRIT_FAILURE, ("Invalid query: %s\n", strerror(ret)));
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes DEBUG(SSSDBG_FUNC_DATA, ("Requesting default options "
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* create domain ctx */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes dom_ctx = talloc_zero(cmd_ctx, struct sudo_dom_ctx);
0662ed52e814f8f08ef0e09956413a792584eddffuankg dom_ctx->domain = cmd_ctx->domain != NULL ? cmd_ctx->domain
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic int sudosrv_cmd_get_sudorules(struct cli_ctx *cli_ctx)
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgstatic int sudosrv_cmd_get_defaults(struct cli_ctx *cli_ctx)
return sudo_cli_protocol_version;
return sudo_cmds;