summaryrefslogtreecommitdiff
path: root/monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'monitor.c')
-rw-r--r--monitor.c130
1 files changed, 114 insertions, 16 deletions
diff --git a/monitor.c b/monitor.c
index 89b712f2d..4ad3f3d21 100644
--- a/monitor.c
+++ b/monitor.c
@@ -25,7 +25,7 @@
25 */ 25 */
26 26
27#include "includes.h" 27#include "includes.h"
28RCSID("$OpenBSD: monitor.c,v 1.18 2002/06/26 13:20:57 deraadt Exp $"); 28RCSID("$OpenBSD: monitor.c,v 1.29 2002/09/26 11:38:43 markus Exp $");
29 29
30#include <openssl/dh.h> 30#include <openssl/dh.h>
31 31
@@ -120,6 +120,13 @@ int mm_answer_sessid(int, Buffer *);
120int mm_answer_pam_start(int, Buffer *); 120int mm_answer_pam_start(int, Buffer *);
121#endif 121#endif
122 122
123#ifdef KRB4
124int mm_answer_krb4(int, Buffer *);
125#endif
126#ifdef KRB5
127int mm_answer_krb5(int, Buffer *);
128#endif
129
123static Authctxt *authctxt; 130static Authctxt *authctxt;
124static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */ 131static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
125 132
@@ -127,8 +134,8 @@ static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
127static u_char *key_blob = NULL; 134static u_char *key_blob = NULL;
128static u_int key_bloblen = 0; 135static u_int key_bloblen = 0;
129static int key_blobtype = MM_NOKEY; 136static int key_blobtype = MM_NOKEY;
130static u_char *hostbased_cuser = NULL; 137static char *hostbased_cuser = NULL;
131static u_char *hostbased_chost = NULL; 138static char *hostbased_chost = NULL;
132static char *auth_method = "unknown"; 139static char *auth_method = "unknown";
133static int session_id2_len = 0; 140static int session_id2_len = 0;
134static u_char *session_id2 = NULL; 141static u_char *session_id2 = NULL;
@@ -199,6 +206,12 @@ struct mon_table mon_dispatch_proto15[] = {
199#ifdef USE_PAM 206#ifdef USE_PAM
200 {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start}, 207 {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start},
201#endif 208#endif
209#ifdef KRB4
210 {MONITOR_REQ_KRB4, MON_ONCE|MON_AUTH, mm_answer_krb4},
211#endif
212#ifdef KRB5
213 {MONITOR_REQ_KRB5, MON_ONCE|MON_AUTH, mm_answer_krb5},
214#endif
202 {0, 0, NULL} 215 {0, 0, NULL}
203}; 216};
204 217
@@ -455,7 +468,7 @@ mm_answer_sign(int socket, Buffer *m)
455 p = buffer_get_string(m, &datlen); 468 p = buffer_get_string(m, &datlen);
456 469
457 if (datlen != 20) 470 if (datlen != 20)
458 fatal("%s: data length incorrect: %d", __func__, datlen); 471 fatal("%s: data length incorrect: %u", __func__, datlen);
459 472
460 /* save session id, it will be passed on the first call */ 473 /* save session id, it will be passed on the first call */
461 if (session_id2_len == 0) { 474 if (session_id2_len == 0) {
@@ -469,7 +482,7 @@ mm_answer_sign(int socket, Buffer *m)
469 if (key_sign(key, &signature, &siglen, p, datlen) < 0) 482 if (key_sign(key, &signature, &siglen, p, datlen) < 0)
470 fatal("%s: key_sign failed", __func__); 483 fatal("%s: key_sign failed", __func__);
471 484
472 debug3("%s: signature %p(%d)", __func__, signature, siglen); 485 debug3("%s: signature %p(%u)", __func__, signature, siglen);
473 486
474 buffer_clear(m); 487 buffer_clear(m);
475 buffer_put_string(m, signature, siglen); 488 buffer_put_string(m, signature, siglen);
@@ -559,7 +572,7 @@ int mm_answer_auth2_read_banner(int socket, Buffer *m)
559 mm_request_send(socket, MONITOR_ANS_AUTH2_READ_BANNER, m); 572 mm_request_send(socket, MONITOR_ANS_AUTH2_READ_BANNER, m);
560 573
561 if (banner != NULL) 574 if (banner != NULL)
562 free(banner); 575 xfree(banner);
563 576
564 return (0); 577 return (0);
565} 578}
@@ -587,7 +600,8 @@ mm_answer_authpassword(int socket, Buffer *m)
587{ 600{
588 static int call_count; 601 static int call_count;
589 char *passwd; 602 char *passwd;
590 int authenticated, plen; 603 int authenticated;
604 u_int plen;
591 605
592 passwd = buffer_get_string(m, &plen); 606 passwd = buffer_get_string(m, &plen);
593 /* Only authenticate if the context is valid */ 607 /* Only authenticate if the context is valid */
@@ -750,7 +764,8 @@ int
750mm_answer_keyallowed(int socket, Buffer *m) 764mm_answer_keyallowed(int socket, Buffer *m)
751{ 765{
752 Key *key; 766 Key *key;
753 u_char *cuser, *chost, *blob; 767 char *cuser, *chost;
768 u_char *blob;
754 u_int bloblen; 769 u_int bloblen;
755 enum mm_keytype type = 0; 770 enum mm_keytype type = 0;
756 int allowed = 0; 771 int allowed = 0;
@@ -826,7 +841,7 @@ static int
826monitor_valid_userblob(u_char *data, u_int datalen) 841monitor_valid_userblob(u_char *data, u_int datalen)
827{ 842{
828 Buffer b; 843 Buffer b;
829 u_char *p; 844 char *p;
830 u_int len; 845 u_int len;
831 int fail = 0; 846 int fail = 0;
832 847
@@ -879,11 +894,11 @@ monitor_valid_userblob(u_char *data, u_int datalen)
879} 894}
880 895
881static int 896static int
882monitor_valid_hostbasedblob(u_char *data, u_int datalen, u_char *cuser, 897monitor_valid_hostbasedblob(u_char *data, u_int datalen, char *cuser,
883 u_char *chost) 898 char *chost)
884{ 899{
885 Buffer b; 900 Buffer b;
886 u_char *p; 901 char *p;
887 u_int len; 902 u_int len;
888 int fail = 0; 903 int fail = 0;
889 904
@@ -1001,8 +1016,8 @@ mm_record_login(Session *s, struct passwd *pw)
1001 * the address be 0.0.0.0. 1016 * the address be 0.0.0.0.
1002 */ 1017 */
1003 memset(&from, 0, sizeof(from)); 1018 memset(&from, 0, sizeof(from));
1019 fromlen = sizeof(from);
1004 if (packet_connection_is_on_socket()) { 1020 if (packet_connection_is_on_socket()) {
1005 fromlen = sizeof(from);
1006 if (getpeername(packet_get_connection_in(), 1021 if (getpeername(packet_get_connection_in(),
1007 (struct sockaddr *) & from, &fromlen) < 0) { 1022 (struct sockaddr *) & from, &fromlen) < 0) {
1008 debug("getpeername: %.100s", strerror(errno)); 1023 debug("getpeername: %.100s", strerror(errno));
@@ -1012,7 +1027,7 @@ mm_record_login(Session *s, struct passwd *pw)
1012 /* Record that there was a login on that tty from the remote host. */ 1027 /* Record that there was a login on that tty from the remote host. */
1013 record_login(s->pid, s->tty, pw->pw_name, pw->pw_uid, 1028 record_login(s->pid, s->tty, pw->pw_name, pw->pw_uid,
1014 get_remote_name_or_ip(utmp_len, options.verify_reverse_mapping), 1029 get_remote_name_or_ip(utmp_len, options.verify_reverse_mapping),
1015 (struct sockaddr *)&from); 1030 (struct sockaddr *)&from, fromlen);
1016} 1031}
1017 1032
1018static void 1033static void
@@ -1276,6 +1291,89 @@ mm_answer_rsa_response(int socket, Buffer *m)
1276 return (success); 1291 return (success);
1277} 1292}
1278 1293
1294#ifdef KRB4
1295int
1296mm_answer_krb4(int socket, Buffer *m)
1297{
1298 KTEXT_ST auth, reply;
1299 char *client, *p;
1300 int success;
1301 u_int alen;
1302
1303 reply.length = auth.length = 0;
1304
1305 p = buffer_get_string(m, &alen);
1306 if (alen >= MAX_KTXT_LEN)
1307 fatal("%s: auth too large", __func__);
1308 memcpy(auth.dat, p, alen);
1309 auth.length = alen;
1310 memset(p, 0, alen);
1311 xfree(p);
1312
1313 success = options.kerberos_authentication &&
1314 authctxt->valid &&
1315 auth_krb4(authctxt, &auth, &client, &reply);
1316
1317 memset(auth.dat, 0, alen);
1318 buffer_clear(m);
1319 buffer_put_int(m, success);
1320
1321 if (success) {
1322 buffer_put_cstring(m, client);
1323 buffer_put_string(m, reply.dat, reply.length);
1324 if (client)
1325 xfree(client);
1326 if (reply.length)
1327 memset(reply.dat, 0, reply.length);
1328 }
1329
1330 debug3("%s: sending result %d", __func__, success);
1331 mm_request_send(socket, MONITOR_ANS_KRB4, m);
1332
1333 auth_method = "kerberos";
1334
1335 /* Causes monitor loop to terminate if authenticated */
1336 return (success);
1337}
1338#endif
1339
1340#ifdef KRB5
1341int
1342mm_answer_krb5(int socket, Buffer *m)
1343{
1344 krb5_data tkt, reply;
1345 char *client_user;
1346 u_int len;
1347 int success;
1348
1349 /* use temporary var to avoid size issues on 64bit arch */
1350 tkt.data = buffer_get_string(m, &len);
1351 tkt.length = len;
1352
1353 success = options.kerberos_authentication &&
1354 authctxt->valid &&
1355 auth_krb5(authctxt, &tkt, &client_user, &reply);
1356
1357 if (tkt.length)
1358 xfree(tkt.data);
1359
1360 buffer_clear(m);
1361 buffer_put_int(m, success);
1362
1363 if (success) {
1364 buffer_put_cstring(m, client_user);
1365 buffer_put_string(m, reply.data, reply.length);
1366 if (client_user)
1367 xfree(client_user);
1368 if (reply.length)
1369 xfree(reply.data);
1370 }
1371 mm_request_send(socket, MONITOR_ANS_KRB5, m);
1372
1373 return success;
1374}
1375#endif
1376
1279int 1377int
1280mm_answer_term(int socket, Buffer *req) 1378mm_answer_term(int socket, Buffer *req)
1281{ 1379{
@@ -1453,10 +1551,10 @@ mm_get_keystate(struct monitor *pmonitor)
1453void * 1551void *
1454mm_zalloc(struct mm_master *mm, u_int ncount, u_int size) 1552mm_zalloc(struct mm_master *mm, u_int ncount, u_int size)
1455{ 1553{
1456 int len = size * ncount; 1554 size_t len = size * ncount;
1457 void *address; 1555 void *address;
1458 1556
1459 if (len <= 0) 1557 if (len == 0 || ncount > SIZE_T_MAX / size)
1460 fatal("%s: mm_zalloc(%u, %u)", __func__, ncount, size); 1558 fatal("%s: mm_zalloc(%u, %u)", __func__, ncount, size);
1461 1559
1462 address = mm_malloc(mm, len); 1560 address = mm_malloc(mm, len);