summaryrefslogtreecommitdiffstats
path: root/src/responder/ssh
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2016-01-08 17:51:06 -0500
committerJakub Hrozek <jhrozek@redhat.com>2016-06-29 21:46:03 +0200
commit4f3a9d837a55b49448eca3c713c85a406207e523 (patch)
treecf983b0fac5ddbc39ca259306342a0c05245168c /src/responder/ssh
parent9a6d162cacfaf6946a1bf974b80b643d2a052d7a (diff)
downloadsssd-4f3a9d837a55b49448eca3c713c85a406207e523.tar.gz
sssd-4f3a9d837a55b49448eca3c713c85a406207e523.tar.xz
sssd-4f3a9d837a55b49448eca3c713c85a406207e523.zip
Responders: Make the client context more generic
This is useufl to allow reusing the responder code with other protocols. Store protocol data and responder state data behind opaque pointers and use tallog_get_type to check they are of the right type. This also allows to store per responder state_ctx so that, for example, the autofs responder does not have to carry useless variables used only by the nss responder. Resolves: https://fedorahosted.org/sssd/ticket/2918 Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/responder/ssh')
-rw-r--r--src/responder/ssh/sshsrv.c1
-rw-r--r--src/responder/ssh/sshsrv_cmd.c47
2 files changed, 29 insertions, 19 deletions
diff --git a/src/responder/ssh/sshsrv.c b/src/responder/ssh/sshsrv.c
index 2be7d4bf2..f763e3b00 100644
--- a/src/responder/ssh/sshsrv.c
+++ b/src/responder/ssh/sshsrv.c
@@ -97,6 +97,7 @@ int ssh_process_init(TALLOC_CTX *mem_ctx,
&monitor_ssh_methods,
"SSH",
&ssh_dp_methods.vtable,
+ sss_connection_setup,
&rctx);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "sss_process_init() failed\n");
diff --git a/src/responder/ssh/sshsrv_cmd.c b/src/responder/ssh/sshsrv_cmd.c
index ba3b694d9..1baba8b03 100644
--- a/src/responder/ssh/sshsrv_cmd.c
+++ b/src/responder/ssh/sshsrv_cmd.c
@@ -662,9 +662,8 @@ done:
static errno_t
ssh_cmd_parse_request(struct ssh_cmd_ctx *cmd_ctx)
{
- struct cli_ctx *cctx = cmd_ctx->cctx;
- struct ssh_ctx *ssh_ctx = talloc_get_type(cctx->rctx->pvt_ctx,
- struct ssh_ctx);
+ struct cli_protocol *pctx;
+ struct ssh_ctx *ssh_ctx;
errno_t ret;
uint8_t *body;
size_t body_len;
@@ -677,7 +676,10 @@ ssh_cmd_parse_request(struct ssh_cmd_ctx *cmd_ctx)
uint32_t domain_len;
char *domain = NULL;
- sss_packet_get_body(cctx->creq->in, &body, &body_len);
+ ssh_ctx = talloc_get_type(cmd_ctx->cctx->rctx->pvt_ctx, struct ssh_ctx);
+ pctx = talloc_get_type(cmd_ctx->cctx->protocol_ctx, struct cli_protocol);
+
+ sss_packet_get_body(pctx->creq->in, &body, &body_len);
SAFEALIGN_COPY_UINT32_CHECK(&flags, body+c, body_len, &c);
if (flags & ~(uint32_t)SSS_SSH_REQ_MASK) {
@@ -752,7 +754,8 @@ ssh_cmd_parse_request(struct ssh_cmd_ctx *cmd_ctx)
DEBUG(SSSDBG_TRACE_FUNC,
"Parsing name [%s][%s]\n", name, domain ? domain : "<ALL>");
- ret = sss_parse_name_for_domains(cmd_ctx, cctx->rctx->domains,
+ ret = sss_parse_name_for_domains(cmd_ctx,
+ cmd_ctx->cctx->rctx->domains,
domain, name,
&cmd_ctx->domname,
&cmd_ctx->name);
@@ -882,7 +885,7 @@ static errno_t decode_and_add_base64_data(struct ssh_cmd_ctx *cmd_ctx,
const char *fqname,
size_t *c)
{
- struct cli_ctx *cctx = cmd_ctx->cctx;
+ struct cli_protocol *pctx;
uint8_t *key;
size_t key_len;
uint8_t *body;
@@ -902,6 +905,8 @@ static errno_t decode_and_add_base64_data(struct ssh_cmd_ctx *cmd_ctx,
return ENOMEM;
}
+ pctx = talloc_get_type(cmd_ctx->cctx->protocol_ctx, struct cli_protocol);
+
for (d = 0; d < el->num_values; d++) {
if (skip_base64_decode) {
key = el->values[d].data;
@@ -916,13 +921,13 @@ static errno_t decode_and_add_base64_data(struct ssh_cmd_ctx *cmd_ctx,
}
}
- ret = sss_packet_grow(cctx->creq->out,
+ ret = sss_packet_grow(pctx->creq->out,
3*sizeof(uint32_t) + key_len + fqname_len);
if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE, "sss_packet_grow failed.\n");
goto done;
}
- sss_packet_get_body(cctx->creq->out, &body, &body_len);
+ sss_packet_get_body(pctx->creq->out, &body, &body_len);
SAFEALIGN_SET_UINT32(body+(*c), 0, c);
SAFEALIGN_SET_UINT32(body+(*c), fqname_len, c);
@@ -943,7 +948,6 @@ done:
static errno_t
ssh_cmd_build_reply(struct ssh_cmd_ctx *cmd_ctx)
{
- struct cli_ctx *cctx = cmd_ctx->cctx;
errno_t ret;
uint8_t *body;
size_t body_len;
@@ -957,13 +961,16 @@ ssh_cmd_build_reply(struct ssh_cmd_ctx *cmd_ctx)
const char *name;
char *fqname;
uint32_t fqname_len;
- struct ssh_ctx *ssh_ctx = talloc_get_type(cctx->rctx->pvt_ctx,
- struct ssh_ctx);
TALLOC_CTX *tmp_ctx;
+ struct ssh_ctx *ssh_ctx;
+ struct cli_protocol *pctx;
- ret = sss_packet_new(cctx->creq, 0,
- sss_packet_get_cmd(cctx->creq->in),
- &cctx->creq->out);
+ ssh_ctx = talloc_get_type(cmd_ctx->cctx->rctx->pvt_ctx, struct ssh_ctx);
+ pctx = talloc_get_type(cmd_ctx->cctx->protocol_ctx, struct cli_protocol);
+
+ ret = sss_packet_new(pctx->creq, 0,
+ sss_packet_get_cmd(pctx->creq->in),
+ &pctx->creq->out);
if (ret != EOK) {
return ret;
}
@@ -1007,11 +1014,11 @@ ssh_cmd_build_reply(struct ssh_cmd_ctx *cmd_ctx)
}
}
- ret = sss_packet_grow(cctx->creq->out, 2*sizeof(uint32_t));
+ ret = sss_packet_grow(pctx->creq->out, 2*sizeof(uint32_t));
if (ret != EOK) {
goto done;
}
- sss_packet_get_body(cctx->creq->out, &body, &body_len);
+ sss_packet_get_body(pctx->creq->out, &body, &body_len);
SAFEALIGN_SET_UINT32(body+c, count, &c);
SAFEALIGN_SET_UINT32(body+c, 0, &c);
@@ -1096,17 +1103,19 @@ ssh_cmd_send_error(struct ssh_cmd_ctx *cmd_ctx,
static errno_t
ssh_cmd_send_reply(struct ssh_cmd_ctx *cmd_ctx)
{
- struct cli_ctx *cctx = cmd_ctx->cctx;
+ struct cli_protocol *pctx;
errno_t ret;
+ pctx = talloc_get_type(cmd_ctx->cctx->protocol_ctx, struct cli_protocol);
+
/* create response packet */
ret = ssh_cmd_build_reply(cmd_ctx);
if (ret != EOK) {
return ret;
}
- sss_packet_set_error(cctx->creq->out, EOK);
- sss_cmd_done(cctx, cmd_ctx);
+ sss_packet_set_error(pctx->creq->out, EOK);
+ sss_cmd_done(cmd_ctx->cctx, cmd_ctx);
return EOK;
}