diff options
author | Jan Cholasta <jcholast@redhat.com> | 2012-02-24 12:48:08 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-02-26 20:34:18 -0500 |
commit | 9e896dc45792ea7d2f267b4fbd49542d10339c63 (patch) | |
tree | fb88c688dbf56e70cae5034d894db7fe97c2ccdf /src/responder/ssh | |
parent | 3ff729e6c8a371e7a52914772816c39ca73c50a9 (diff) | |
download | sssd-9e896dc45792ea7d2f267b4fbd49542d10339c63.tar.gz sssd-9e896dc45792ea7d2f267b4fbd49542d10339c63.tar.bz2 sssd-9e896dc45792ea7d2f267b4fbd49542d10339c63.zip |
SSH: Save SSH host name aliases
Diffstat (limited to 'src/responder/ssh')
-rw-r--r-- | src/responder/ssh/sshsrv_cmd.c | 26 | ||||
-rw-r--r-- | src/responder/ssh/sshsrv_private.h | 1 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/responder/ssh/sshsrv_cmd.c b/src/responder/ssh/sshsrv_cmd.c index 0a182f31..da6a4540 100644 --- a/src/responder/ssh/sshsrv_cmd.c +++ b/src/responder/ssh/sshsrv_cmd.c @@ -22,6 +22,7 @@ #include <talloc.h> #include <string.h> +#include <netdb.h> #include "util/util.h" #include "util/crypto/sss_crypto.h" @@ -90,6 +91,8 @@ sss_ssh_cmd_get_host_pubkeys(struct cli_ctx *cctx) { struct ssh_cmd_ctx *cmd_ctx; errno_t ret; + struct addrinfo ai_hint; + struct addrinfo *ai = NULL; cmd_ctx = talloc_zero(cctx, struct ssh_cmd_ctx); if (!cmd_ctx) { @@ -107,6 +110,27 @@ sss_ssh_cmd_get_host_pubkeys(struct cli_ctx *cctx) ("Requesting SSH host public keys for [%s] from [%s]\n", cmd_ctx->name, cmd_ctx->domname ? cmd_ctx->domname : "<ALL>")); + /* canonicalize host name */ + memset(&ai_hint, 0, sizeof(struct addrinfo)); + ai_hint.ai_flags = AI_CANONNAME; + + ret = getaddrinfo(cmd_ctx->name, NULL, &ai_hint, &ai); + if (!ret) { + if (strcmp(cmd_ctx->name, ai[0].ai_canonname) != 0) { + cmd_ctx->alias = cmd_ctx->name; + cmd_ctx->name = talloc_strdup(cmd_ctx, ai[0].ai_canonname); + if (!cmd_ctx->name) { + ret = ENOMEM; + goto done; + } + } + } else { + DEBUG(SSSDBG_OP_FAILURE, + ("getaddrinfo() failed (%d): %s\n", ret, gai_strerror(ret))); + } + + freeaddrinfo(ai); + if (cmd_ctx->domname) { cmd_ctx->domain = responder_get_domain(cctx->rctx->domains, cmd_ctx->domname); @@ -312,7 +336,7 @@ ssh_host_pubkeys_search(struct ssh_cmd_ctx *cmd_ctx) if (NEED_CHECK_PROVIDER(cmd_ctx->domain->provider)) { req = sss_dp_get_account_send(cmd_ctx, cmd_ctx->cctx->rctx, cmd_ctx->domain, false, SSS_DP_HOST, - cmd_ctx->name, 0, NULL); + cmd_ctx->name, 0, cmd_ctx->alias); if (!req) { DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory sending data provider request\n")); diff --git a/src/responder/ssh/sshsrv_private.h b/src/responder/ssh/sshsrv_private.h index 26ed6b92..ffe88eb3 100644 --- a/src/responder/ssh/sshsrv_private.h +++ b/src/responder/ssh/sshsrv_private.h @@ -34,6 +34,7 @@ struct ssh_cmd_ctx { struct cli_ctx *cctx; enum sss_dp_acct_type type; char *name; + char *alias; char *domname; struct sss_domain_info *domain; |