summaryrefslogtreecommitdiffstats
path: root/src/sss_client
diff options
context:
space:
mode:
Diffstat (limited to 'src/sss_client')
-rw-r--r--src/sss_client/ssh/sss_ssh_authorizedkeys.c23
-rw-r--r--src/sss_client/ssh/sss_ssh_client.c (renamed from src/sss_client/ssh/sss_ssh.c)165
-rw-r--r--src/sss_client/ssh/sss_ssh_client.h (renamed from src/sss_client/ssh/sss_ssh.h)38
-rw-r--r--src/sss_client/ssh/sss_ssh_knownhostsproxy.c23
4 files changed, 72 insertions, 177 deletions
diff --git a/src/sss_client/ssh/sss_ssh_authorizedkeys.c b/src/sss_client/ssh/sss_ssh_authorizedkeys.c
index c8aa45c30..bc3cdf473 100644
--- a/src/sss_client/ssh/sss_ssh_authorizedkeys.c
+++ b/src/sss_client/ssh/sss_ssh_authorizedkeys.c
@@ -24,8 +24,9 @@
#include "util/util.h"
#include "util/crypto/sss_crypto.h"
+#include "util/sss_ssh.h"
#include "sss_client/sss_cli.h"
-#include "sss_client/ssh/sss_ssh.h"
+#include "sss_client/ssh/sss_ssh_client.h"
int main(int argc, const char **argv)
{
@@ -43,8 +44,8 @@ int main(int argc, const char **argv)
};
poptContext pc = NULL;
const char *user;
- struct sss_ssh_pubkey *pubkeys;
- size_t num_pubkeys, i;
+ struct sss_ssh_ent *ent;
+ size_t i;
char *repr;
int ret;
@@ -96,24 +97,18 @@ int main(int argc, const char **argv)
}
/* look up public keys */
- ret = sss_ssh_get_pubkeys(mem_ctx, SSS_SSH_GET_USER_PUBKEYS, user,
- &pubkeys, &num_pubkeys);
+ ret = sss_ssh_get_ent(mem_ctx, SSS_SSH_GET_USER_PUBKEYS, user, &ent);
if (ret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE,
- ("sss_ssh_get_pubkeys() failed (%d): %s\n", ret, strerror(ret)));
ERROR("Error looking up public keys\n");
ret = EXIT_FAILURE;
goto fini;
}
/* print results */
- for (i = 0; i < num_pubkeys; i++) {
- ret = sss_ssh_format_pubkey(mem_ctx, &pubkeys[i],
- SSS_SSH_FORMAT_OPENSSH, &repr);
- if (ret != EOK) {
- DEBUG(SSSDBG_OP_FAILURE,
- ("sss_ssh_format_pubkey() failed (%d): %s\n",
- ret, strerror(ret)));
+ for (i = 0; i < ent->num_pubkeys; i++) {
+ repr = sss_ssh_format_pubkey(mem_ctx, ent, &ent->pubkeys[i],
+ SSS_SSH_FORMAT_OPENSSH);
+ if (!repr) {
continue;
}
diff --git a/src/sss_client/ssh/sss_ssh.c b/src/sss_client/ssh/sss_ssh_client.c
index bb76800a4..82507787d 100644
--- a/src/sss_client/ssh/sss_ssh.c
+++ b/src/sss_client/ssh/sss_ssh_client.c
@@ -23,7 +23,6 @@
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
-#include <arpa/inet.h>
#include <talloc.h>
#include <popt.h>
@@ -31,9 +30,11 @@
#include <libintl.h>
#include <string.h>
+#include "util/util.h"
#include "util/crypto/sss_crypto.h"
+#include "util/sss_ssh.h"
#include "sss_client/sss_cli.h"
-#include "sss_client/ssh/sss_ssh.h"
+#include "sss_client/ssh/sss_ssh_client.h"
/* FIXME - split from tools_util to create a common function */
void usage(poptContext pc, const char *error)
@@ -69,9 +70,9 @@ int set_locale(void)
/* SSH public key request:
*
- * 0..3: flags (unsigned int, must be 0)
- * 4..7: name length (unsigned int)
- * 8..$: name (null-terminated UTF-8 string)
+ * 0..3: flags (unsigned int, must be 0)
+ * 4..7: name length (unsigned int)
+ * 8..(X-1): name (null-terminated UTF-8 string)
*
* SSH public key reply:
*
@@ -85,14 +86,15 @@ int set_locale(void)
* (X+4)..Y: key (public key blob as defined in RFC4253, section 6.6)
*/
errno_t
-sss_ssh_get_pubkeys(TALLOC_CTX *mem_ctx,
- enum sss_cli_command command,
- const char *name,
- struct sss_ssh_pubkey **pubkeys,
- size_t *pubkeys_len)
+sss_ssh_get_ent(TALLOC_CTX *mem_ctx,
+ enum sss_cli_command command,
+ const char *name,
+ struct sss_ssh_ent **result)
{
TALLOC_CTX *tmp_ctx;
- errno_t ret = EOK;
+ struct sss_ssh_ent *res = NULL;
+ errno_t ret;
+ uint32_t flags;
uint32_t name_len;
size_t req_len;
uint8_t *req = NULL;
@@ -102,7 +104,6 @@ sss_ssh_get_pubkeys(TALLOC_CTX *mem_ctx,
uint8_t *rep = NULL;
size_t rep_len;
uint32_t count, reserved, len, i;
- struct sss_ssh_pubkey *result = NULL;
tmp_ctx = talloc_new(NULL);
if (!tmp_ctx) {
@@ -110,6 +111,7 @@ sss_ssh_get_pubkeys(TALLOC_CTX *mem_ctx,
}
/* build request */
+ flags = 0;
name_len = strlen(name)+1;
req_len = 2*sizeof(uint32_t) + name_len;
@@ -119,7 +121,7 @@ sss_ssh_get_pubkeys(TALLOC_CTX *mem_ctx,
goto done;
}
- SAFEALIGN_SET_UINT32(req+c, 0, &c);
+ SAFEALIGN_SET_UINT32(req+c, flags, &c);
SAFEALIGN_SET_UINT32(req+c, name_len, &c);
safealign_memcpy(req+c, name, name_len, &c);
@@ -152,12 +154,20 @@ sss_ssh_get_pubkeys(TALLOC_CTX *mem_ctx,
goto done;
}
+ res = talloc_zero(tmp_ctx, struct sss_ssh_ent);
+ if (!res) {
+ ret = ENOMEM;
+ goto done;
+ }
+
if (count > 0) {
- result = talloc_zero_array(tmp_ctx, struct sss_ssh_pubkey, count);
- if (!result) {
+ res->pubkeys = talloc_zero_array(res, struct sss_ssh_pubkey, count);
+ if (!res->pubkeys) {
ret = ENOMEM;
goto done;
}
+
+ res->num_pubkeys = count;
}
for (i = 0; i < count; i++) {
@@ -166,8 +176,8 @@ sss_ssh_get_pubkeys(TALLOC_CTX *mem_ctx,
goto done;
}
- SAFEALIGN_COPY_UINT32(&result[i].flags, rep+c, &c);
- if (result[i].flags != 0) {
+ SAFEALIGN_COPY_UINT32(&flags, rep+c, &c);
+ if (flags != 0) {
ret = EINVAL;
goto done;
}
@@ -179,16 +189,20 @@ sss_ssh_get_pubkeys(TALLOC_CTX *mem_ctx,
goto done;
}
- result[i].name = talloc_array(result, char, len);
- if (!result[i].name) {
- ret = ENOMEM;
- goto done;
- }
-
- safealign_memcpy(result[i].name, rep+c, len, &c);
- if (strnlen(result[i].name, len) != len-1) {
- ret = EINVAL;
- goto done;
+ if (!res->name) {
+ res->name = talloc_array(res, char, len);
+ if (!res->name) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ safealign_memcpy(res->name, rep+c, len, &c);
+ if (strnlen(res->name, len) != len-1) {
+ ret = EINVAL;
+ goto done;
+ }
+ } else {
+ c += len;
}
SAFEALIGN_COPY_UINT32(&len, rep+c, &c);
@@ -198,103 +212,18 @@ sss_ssh_get_pubkeys(TALLOC_CTX *mem_ctx,
goto done;
}
- result[i].key = talloc_array(result, uint8_t, len);
- if (!result[i].key) {
+ res->pubkeys[i].data = talloc_array(res, uint8_t, len);
+ if (!res->pubkeys[i].data) {
ret = ENOMEM;
goto done;
}
- safealign_memcpy(result[i].key, rep+c, len, &c);
- result[i].key_len = len;
- }
-
- *pubkeys = result ? talloc_steal(mem_ctx, result) : NULL;
- *pubkeys_len = count;
-
-done:
- talloc_free(tmp_ctx);
-
- return ret;
-}
-
-char *
-sss_ssh_get_pubkey_algorithm(TALLOC_CTX *mem_ctx,
- struct sss_ssh_pubkey *pubkey)
-{
- size_t c = 0;
- uint32_t algo_len;
- char *algo;
-
- SAFEALIGN_COPY_UINT32(&algo_len, pubkey->key, &c);
- algo_len = ntohl(algo_len);
-
- algo = talloc_zero_array(mem_ctx, char, algo_len+1);
- if (!algo) {
- return NULL;
- }
-
- memcpy(algo, pubkey->key+c, algo_len);
-
- return algo;
-}
-
-errno_t
-sss_ssh_format_pubkey(TALLOC_CTX *mem_ctx,
- struct sss_ssh_pubkey *pubkey,
- enum sss_ssh_pubkey_format format,
- char **result)
-{
- TALLOC_CTX *tmp_ctx;
- errno_t ret = EOK;
- char *pk;
- char *algo;
- char *out;
-
- if (!pubkey) {
- return EINVAL;
- }
-
- tmp_ctx = talloc_new(NULL);
- if (!tmp_ctx) {
- return ENOMEM;
- }
-
- pk = sss_base64_encode(tmp_ctx, pubkey->key, pubkey->key_len);
- if (!pk) {
- ret = ENOMEM;
- goto done;
- }
-
- switch (format) {
- case SSS_SSH_FORMAT_RAW:
- /* base64-encoded key blob */
-
- out = talloc_steal(mem_ctx, pk);
-
- break;
-
- case SSS_SSH_FORMAT_OPENSSH:
- /* OpenSSH authorized_keys/known_hosts format */
-
- algo = sss_ssh_get_pubkey_algorithm(tmp_ctx, pubkey);
- if (!algo) {
- ret = ENOMEM;
- goto done;
- }
-
- out = talloc_asprintf(tmp_ctx, "%s %s %s",
- algo, pk, pubkey->name);
- if (!out) {
- ret = ENOMEM;
- goto done;
- }
-
- talloc_steal(mem_ctx, out);
-
- break;
+ safealign_memcpy(res->pubkeys[i].data, rep+c, len, &c);
+ res->pubkeys[i].data_len = len;
}
- *result = out;
+ *result = talloc_steal(mem_ctx, res);
+ ret = EOK;
done:
talloc_free(tmp_ctx);
diff --git a/src/sss_client/ssh/sss_ssh.h b/src/sss_client/ssh/sss_ssh_client.h
index 633c3af7c..1c8db1ff3 100644
--- a/src/sss_client/ssh/sss_ssh.h
+++ b/src/sss_client/ssh/sss_ssh_client.h
@@ -18,8 +18,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _SSS_SSH_H_
-#define _SSS_SSH_H_
+#ifndef _SSS_SSH_CLIENT_H_
+#define _SSS_SSH_CLIENT_H_
void usage(poptContext pc, const char *error);
int set_locale(void);
@@ -30,34 +30,10 @@ int set_locale(void);
goto label; \
} while(0)
-struct sss_ssh_pubkey {
- uint32_t flags;
- char *name;
-
- uint8_t *key;
- size_t key_len;
-};
-
-errno_t
-sss_ssh_get_pubkeys(TALLOC_CTX *mem_ctx,
- enum sss_cli_command command,
- const char *name,
- struct sss_ssh_pubkey **pubkeys,
- size_t *pubkeys_len);
-
-char *
-sss_ssh_get_pubkey_algorithm(TALLOC_CTX *mem_ctx,
- struct sss_ssh_pubkey *pubkey);
-
-enum sss_ssh_pubkey_format {
- SSS_SSH_FORMAT_RAW,
- SSS_SSH_FORMAT_OPENSSH
-};
-
errno_t
-sss_ssh_format_pubkey(TALLOC_CTX *mem_ctx,
- struct sss_ssh_pubkey *pubkey,
- enum sss_ssh_pubkey_format format,
- char **result);
+sss_ssh_get_ent(TALLOC_CTX *mem_ctx,
+ enum sss_cli_command command,
+ const char *name,
+ struct sss_ssh_ent **result);
-#endif /* _SSS_SSH_H_ */
+#endif /* _SSS_SSH_CLIENT_H_ */
diff --git a/src/sss_client/ssh/sss_ssh_knownhostsproxy.c b/src/sss_client/ssh/sss_ssh_knownhostsproxy.c
index b95dbe8ef..fb93e4ad2 100644
--- a/src/sss_client/ssh/sss_ssh_knownhostsproxy.c
+++ b/src/sss_client/ssh/sss_ssh_knownhostsproxy.c
@@ -33,9 +33,10 @@
#include "util/util.h"
#include "util/crypto/sss_crypto.h"
+#include "util/sss_ssh.h"
#include "tools/tools_util.h"
#include "sss_client/sss_cli.h"
-#include "sss_client/ssh/sss_ssh.h"
+#include "sss_client/ssh/sss_ssh_client.h"
#define DEFAULT_FILE ".ssh/sss_known_hosts"
@@ -247,8 +248,8 @@ int main(int argc, const char **argv)
const char *host;
FILE *f;
struct addrinfo ai_hint, *ai = NULL;
- struct sss_ssh_pubkey *pubkeys;
- size_t num_pubkeys, i;
+ struct sss_ssh_ent *ent;
+ size_t i;
char *repr;
int ret;
@@ -345,11 +346,8 @@ int main(int argc, const char **argv)
}
/* look up public keys */
- ret = sss_ssh_get_pubkeys(mem_ctx, SSS_SSH_GET_HOST_PUBKEYS, host,
- &pubkeys, &num_pubkeys);
+ ret = sss_ssh_get_ent(mem_ctx, SSS_SSH_GET_HOST_PUBKEYS, host, &ent);
if (ret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE,
- ("sss_ssh_get_pubkeys failed() (%d): %s\n", ret, strerror(ret)));
ERROR("Error looking up public keys\n");
ret = EXIT_FAILURE;
goto fini;
@@ -370,13 +368,10 @@ int main(int argc, const char **argv)
fprintf(f,
"# Generated by sss_ssh_knownhostsproxy. Please do not modify.\n");
- for (i = 0; i < num_pubkeys; i++) {
- ret = sss_ssh_format_pubkey(mem_ctx, &pubkeys[i],
- SSS_SSH_FORMAT_OPENSSH, &repr);
- if (ret != EOK) {
- DEBUG(SSSDBG_OP_FAILURE,
- ("sss_ssh_format_pubkey() failed (%d): %s\n",
- ret, strerror(ret)));
+ for (i = 0; i < ent->num_pubkeys; i++) {
+ repr = sss_ssh_format_pubkey(mem_ctx, ent, &ent->pubkeys[i],
+ SSS_SSH_FORMAT_OPENSSH);
+ if (!repr) {
continue;
}