diff options
author | markus@openbsd.org <markus@openbsd.org> | 2018-07-09 21:37:55 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2018-07-10 15:28:30 +1000 |
commit | b8d9214d969775e409e1408ecdf0d58fad99b344 (patch) | |
tree | a14a0ac02bd578cb35129946f86aaa12797d0199 /gss-genr.c | |
parent | c7d39ac8dc3587c5f05bdd5bcd098eb5c201c0c8 (diff) |
upstream: sshd: switch GSSAPI to sshbuf API; ok djm@
OpenBSD-Commit-ID: e48449ab4be3f006f7ba33c66241b7d652973e30
Diffstat (limited to 'gss-genr.c')
-rw-r--r-- | gss-genr.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/gss-genr.c b/gss-genr.c index 62559ed9e..f794e05b7 100644 --- a/gss-genr.c +++ b/gss-genr.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: gss-genr.c,v 1.24 2016/09/12 01:22:38 deraadt Exp $ */ | 1 | /* $OpenBSD: gss-genr.c,v 1.25 2018/07/09 21:37:55 markus Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved. | 4 | * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved. |
@@ -37,7 +37,8 @@ | |||
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | 38 | ||
39 | #include "xmalloc.h" | 39 | #include "xmalloc.h" |
40 | #include "buffer.h" | 40 | #include "ssherr.h" |
41 | #include "sshbuf.h" | ||
41 | #include "log.h" | 42 | #include "log.h" |
42 | #include "ssh2.h" | 43 | #include "ssh2.h" |
43 | 44 | ||
@@ -94,10 +95,12 @@ ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status, | |||
94 | OM_uint32 lmin; | 95 | OM_uint32 lmin; |
95 | gss_buffer_desc msg = GSS_C_EMPTY_BUFFER; | 96 | gss_buffer_desc msg = GSS_C_EMPTY_BUFFER; |
96 | OM_uint32 ctx; | 97 | OM_uint32 ctx; |
97 | Buffer b; | 98 | struct sshbuf *b; |
98 | char *ret; | 99 | char *ret; |
100 | int r; | ||
99 | 101 | ||
100 | buffer_init(&b); | 102 | if ((b = sshbuf_new()) == NULL) |
103 | fatal("%s: sshbuf_new failed", __func__); | ||
101 | 104 | ||
102 | if (major_status != NULL) | 105 | if (major_status != NULL) |
103 | *major_status = ctxt->major; | 106 | *major_status = ctxt->major; |
@@ -110,8 +113,9 @@ ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status, | |||
110 | gss_display_status(&lmin, ctxt->major, | 113 | gss_display_status(&lmin, ctxt->major, |
111 | GSS_C_GSS_CODE, ctxt->oid, &ctx, &msg); | 114 | GSS_C_GSS_CODE, ctxt->oid, &ctx, &msg); |
112 | 115 | ||
113 | buffer_append(&b, msg.value, msg.length); | 116 | if ((r = sshbuf_put(b, msg.value, msg.length)) != 0 || |
114 | buffer_put_char(&b, '\n'); | 117 | (r = sshbuf_put_u8(b, '\n')) != 0) |
118 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
115 | 119 | ||
116 | gss_release_buffer(&lmin, &msg); | 120 | gss_release_buffer(&lmin, &msg); |
117 | } while (ctx != 0); | 121 | } while (ctx != 0); |
@@ -121,16 +125,17 @@ ssh_gssapi_last_error(Gssctxt *ctxt, OM_uint32 *major_status, | |||
121 | gss_display_status(&lmin, ctxt->minor, | 125 | gss_display_status(&lmin, ctxt->minor, |
122 | GSS_C_MECH_CODE, ctxt->oid, &ctx, &msg); | 126 | GSS_C_MECH_CODE, ctxt->oid, &ctx, &msg); |
123 | 127 | ||
124 | buffer_append(&b, msg.value, msg.length); | 128 | if ((r = sshbuf_put(b, msg.value, msg.length)) != 0 || |
125 | buffer_put_char(&b, '\n'); | 129 | (r = sshbuf_put_u8(b, '\n')) != 0) |
130 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
126 | 131 | ||
127 | gss_release_buffer(&lmin, &msg); | 132 | gss_release_buffer(&lmin, &msg); |
128 | } while (ctx != 0); | 133 | } while (ctx != 0); |
129 | 134 | ||
130 | buffer_put_char(&b, '\0'); | 135 | if ((r = sshbuf_put_u8(b, '\n')) != 0) |
131 | ret = xmalloc(buffer_len(&b)); | 136 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
132 | buffer_get(&b, ret, buffer_len(&b)); | 137 | ret = xstrdup((const char *)sshbuf_ptr(b)); |
133 | buffer_free(&b); | 138 | sshbuf_free(b); |
134 | return (ret); | 139 | return (ret); |
135 | } | 140 | } |
136 | 141 | ||
@@ -238,15 +243,18 @@ ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash) | |||
238 | } | 243 | } |
239 | 244 | ||
240 | void | 245 | void |
241 | ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service, | 246 | ssh_gssapi_buildmic(struct sshbuf *b, const char *user, const char *service, |
242 | const char *context) | 247 | const char *context) |
243 | { | 248 | { |
244 | buffer_init(b); | 249 | int r; |
245 | buffer_put_string(b, session_id2, session_id2_len); | 250 | |
246 | buffer_put_char(b, SSH2_MSG_USERAUTH_REQUEST); | 251 | sshbuf_reset(b); |
247 | buffer_put_cstring(b, user); | 252 | if ((r = sshbuf_put_string(b, session_id2, session_id2_len)) != 0 || |
248 | buffer_put_cstring(b, service); | 253 | (r = sshbuf_put_u8(b, SSH2_MSG_USERAUTH_REQUEST)) != 0 || |
249 | buffer_put_cstring(b, context); | 254 | (r = sshbuf_put_cstring(b, user)) != 0 || |
255 | (r = sshbuf_put_cstring(b, service)) != 0 || | ||
256 | (r = sshbuf_put_cstring(b, context)) != 0) | ||
257 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
250 | } | 258 | } |
251 | 259 | ||
252 | int | 260 | int |