Lines Matching refs:session

63 static char *userauth_list(LIBSSH2_SESSION *session, const char *username,  in userauth_list()  argument
74 if(session->userauth_list_state == libssh2_NB_state_idle) { in userauth_list()
76 memset(&session->userauth_list_packet_requirev_state, 0, in userauth_list()
77 sizeof(session->userauth_list_packet_requirev_state)); in userauth_list()
79 session->userauth_list_data_len = username_len + 27; in userauth_list()
81 s = session->userauth_list_data = in userauth_list()
82 LIBSSH2_ALLOC(session, session->userauth_list_data_len); in userauth_list()
83 if(!session->userauth_list_data) { in userauth_list()
84 _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_list()
94 session->userauth_list_state = libssh2_NB_state_created; in userauth_list()
97 if(session->userauth_list_state == libssh2_NB_state_created) { in userauth_list()
98 rc = _libssh2_transport_send(session, session->userauth_list_data, in userauth_list()
99 session->userauth_list_data_len, in userauth_list()
102 _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in userauth_list()
107 LIBSSH2_FREE(session, session->userauth_list_data); in userauth_list()
108 session->userauth_list_data = NULL; in userauth_list()
111 _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, in userauth_list()
113 session->userauth_list_state = libssh2_NB_state_idle; in userauth_list()
117 session->userauth_list_state = libssh2_NB_state_sent; in userauth_list()
120 if(session->userauth_list_state == libssh2_NB_state_sent) { in userauth_list()
121 rc = _libssh2_packet_requirev(session, reply_codes, in userauth_list()
122 &session->userauth_list_data, in userauth_list()
123 &session->userauth_list_data_len, 0, in userauth_list()
125 &session->userauth_list_packet_requirev_state); in userauth_list()
127 _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in userauth_list()
131 else if(rc || (session->userauth_list_data_len < 1)) { in userauth_list()
132 _libssh2_error(session, rc, "Failed getting response"); in userauth_list()
133 session->userauth_list_state = libssh2_NB_state_idle; in userauth_list()
137 if(session->userauth_list_data[0] == SSH_MSG_USERAUTH_SUCCESS) { in userauth_list()
139 _libssh2_error(session, LIBSSH2_ERROR_NONE, "No error"); in userauth_list()
140 LIBSSH2_FREE(session, session->userauth_list_data); in userauth_list()
141 session->userauth_list_data = NULL; in userauth_list()
142 session->state |= LIBSSH2_STATE_AUTHENTICATED; in userauth_list()
143 session->userauth_list_state = libssh2_NB_state_idle; in userauth_list()
147 if(session->userauth_list_data_len < 5) { in userauth_list()
148 LIBSSH2_FREE(session, session->userauth_list_data); in userauth_list()
149 session->userauth_list_data = NULL; in userauth_list()
150 _libssh2_error(session, LIBSSH2_ERROR_PROTO, in userauth_list()
155 methods_len = _libssh2_ntohu32(session->userauth_list_data + 1); in userauth_list()
156 if(methods_len >= session->userauth_list_data_len - 5) { in userauth_list()
157 _libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY, in userauth_list()
163 memmove(session->userauth_list_data, session->userauth_list_data + 5, in userauth_list()
165 session->userauth_list_data[methods_len] = '\0'; in userauth_list()
166 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_list()
168 session->userauth_list_data); in userauth_list()
171 session->userauth_list_state = libssh2_NB_state_idle; in userauth_list()
172 return (char *) session->userauth_list_data; in userauth_list()
183 libssh2_userauth_list(LIBSSH2_SESSION * session, const char *user, in libssh2_userauth_list() argument
187 BLOCK_ADJUST_ERRNO(ptr, session, in libssh2_userauth_list()
188 userauth_list(session, user, user_len)); in libssh2_userauth_list()
199 libssh2_userauth_authenticated(LIBSSH2_SESSION * session) in libssh2_userauth_authenticated() argument
201 return (session->state & LIBSSH2_STATE_AUTHENTICATED)?1:0; in libssh2_userauth_authenticated()
210 userauth_password(LIBSSH2_SESSION *session, in userauth_password() argument
222 if(session->userauth_pswd_state == libssh2_NB_state_idle) { in userauth_password()
224 memset(&session->userauth_pswd_packet_requirev_state, 0, in userauth_password()
225 sizeof(session->userauth_pswd_packet_requirev_state)); in userauth_password()
231 session->userauth_pswd_data_len = username_len + 40; in userauth_password()
233 session->userauth_pswd_data0 = in userauth_password()
238 s = session->userauth_pswd_data = in userauth_password()
239 LIBSSH2_ALLOC(session, session->userauth_pswd_data_len); in userauth_password()
240 if(!session->userauth_pswd_data) { in userauth_password()
241 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_password()
254 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_password()
257 session->userauth_pswd_state = libssh2_NB_state_created; in userauth_password()
260 if(session->userauth_pswd_state == libssh2_NB_state_created) { in userauth_password()
261 rc = _libssh2_transport_send(session, session->userauth_pswd_data, in userauth_password()
262 session->userauth_pswd_data_len, in userauth_password()
265 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in userauth_password()
270 LIBSSH2_FREE(session, session->userauth_pswd_data); in userauth_password()
271 session->userauth_pswd_data = NULL; in userauth_password()
274 session->userauth_pswd_state = libssh2_NB_state_idle; in userauth_password()
275 return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, in userauth_password()
279 session->userauth_pswd_state = libssh2_NB_state_sent; in userauth_password()
284 if((session->userauth_pswd_state == libssh2_NB_state_sent) in userauth_password()
285 || (session->userauth_pswd_state == libssh2_NB_state_sent1) in userauth_password()
286 || (session->userauth_pswd_state == libssh2_NB_state_sent2)) { in userauth_password()
287 if(session->userauth_pswd_state == libssh2_NB_state_sent) { in userauth_password()
288 rc = _libssh2_packet_requirev(session, reply_codes, in userauth_password()
289 &session->userauth_pswd_data, in userauth_password()
290 &session->userauth_pswd_data_len, in userauth_password()
292 &session-> in userauth_password()
297 session->userauth_pswd_state = libssh2_NB_state_idle; in userauth_password()
299 return _libssh2_error(session, rc, in userauth_password()
302 else if(session->userauth_pswd_data_len < 1) { in userauth_password()
303 session->userauth_pswd_state = libssh2_NB_state_idle; in userauth_password()
304 return _libssh2_error(session, LIBSSH2_ERROR_PROTO, in userauth_password()
308 if(session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_SUCCESS) { in userauth_password()
309 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_password()
311 LIBSSH2_FREE(session, session->userauth_pswd_data); in userauth_password()
312 session->userauth_pswd_data = NULL; in userauth_password()
313 session->state |= LIBSSH2_STATE_AUTHENTICATED; in userauth_password()
314 session->userauth_pswd_state = libssh2_NB_state_idle; in userauth_password()
317 else if(session->userauth_pswd_data[0] == in userauth_password()
319 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_password()
321 LIBSSH2_FREE(session, session->userauth_pswd_data); in userauth_password()
322 session->userauth_pswd_data = NULL; in userauth_password()
323 session->userauth_pswd_state = libssh2_NB_state_idle; in userauth_password()
324 return _libssh2_error(session, in userauth_password()
330 session->userauth_pswd_newpw = NULL; in userauth_password()
331 session->userauth_pswd_newpw_len = 0; in userauth_password()
333 session->userauth_pswd_state = libssh2_NB_state_sent1; in userauth_password()
336 if(session->userauth_pswd_data_len < 1) { in userauth_password()
337 session->userauth_pswd_state = libssh2_NB_state_idle; in userauth_password()
338 return _libssh2_error(session, LIBSSH2_ERROR_PROTO, in userauth_password()
342 if((session->userauth_pswd_data[0] == in userauth_password()
344 || (session->userauth_pswd_data0 == in userauth_password()
346 session->userauth_pswd_data0 = SSH_MSG_USERAUTH_PASSWD_CHANGEREQ; in userauth_password()
348 if((session->userauth_pswd_state == libssh2_NB_state_sent1) || in userauth_password()
349 (session->userauth_pswd_state == libssh2_NB_state_sent2)) { in userauth_password()
350 if(session->userauth_pswd_state == libssh2_NB_state_sent1) { in userauth_password()
351 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_password()
353 LIBSSH2_FREE(session, session->userauth_pswd_data); in userauth_password()
354 session->userauth_pswd_data = NULL; in userauth_password()
357 if(session->userauth_pswd_state == in userauth_password()
359 passwd_change_cb(session, in userauth_password()
360 &session->userauth_pswd_newpw, in userauth_password()
361 &session->userauth_pswd_newpw_len, in userauth_password()
362 &session->abstract); in userauth_password()
363 if(!session->userauth_pswd_newpw) { in userauth_password()
364 return _libssh2_error(session, in userauth_password()
372 session->userauth_pswd_data_len = in userauth_password()
374 s = session->userauth_pswd_data = in userauth_password()
375 LIBSSH2_ALLOC(session, in userauth_password()
376 session->userauth_pswd_data_len); in userauth_password()
379 s = session->userauth_pswd_data = NULL; in userauth_password()
380 session->userauth_pswd_data_len = 0; in userauth_password()
383 if(!session->userauth_pswd_data) { in userauth_password()
384 LIBSSH2_FREE(session, in userauth_password()
385 session->userauth_pswd_newpw); in userauth_password()
386 session->userauth_pswd_newpw = NULL; in userauth_password()
387 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_password()
402 session->userauth_pswd_newpw_len); in userauth_password()
405 session->userauth_pswd_state = libssh2_NB_state_sent2; in userauth_password()
408 if(session->userauth_pswd_state == in userauth_password()
410 rc = _libssh2_transport_send(session, in userauth_password()
411 session->userauth_pswd_data, in userauth_password()
412 session->userauth_pswd_data_len, in userauth_password()
414 session->userauth_pswd_newpw, in userauth_password()
415 session->userauth_pswd_newpw_len); in userauth_password()
417 return _libssh2_error(session, in userauth_password()
423 LIBSSH2_FREE(session, session->userauth_pswd_data); in userauth_password()
424 session->userauth_pswd_data = NULL; in userauth_password()
425 LIBSSH2_FREE(session, session->userauth_pswd_newpw); in userauth_password()
426 session->userauth_pswd_newpw = NULL; in userauth_password()
429 return _libssh2_error(session, in userauth_password()
439 session->userauth_pswd_state = libssh2_NB_state_sent; in userauth_password()
445 session->userauth_pswd_state = libssh2_NB_state_idle; in userauth_password()
446 return _libssh2_error(session, LIBSSH2_ERROR_PASSWORD_EXPIRED, in userauth_password()
454 LIBSSH2_FREE(session, session->userauth_pswd_data); in userauth_password()
455 session->userauth_pswd_data = NULL; in userauth_password()
456 session->userauth_pswd_state = libssh2_NB_state_idle; in userauth_password()
458 return _libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED, in userauth_password()
469 libssh2_userauth_password_ex(LIBSSH2_SESSION *session, const char *username, in libssh2_userauth_password_ex() argument
476 BLOCK_ADJUST(rc, session, in libssh2_userauth_password_ex()
477 userauth_password(session, username, username_len, in libssh2_userauth_password_ex()
484 memory_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, in memory_read_publickey() argument
496 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in memory_read_publickey()
500 pubkey = LIBSSH2_ALLOC(session, pubkeyfiledata_len); in memory_read_publickey()
502 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in memory_read_publickey()
515 LIBSSH2_FREE(session, pubkey); in memory_read_publickey()
516 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in memory_read_publickey()
522 LIBSSH2_FREE(session, pubkey); in memory_read_publickey()
523 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in memory_read_publickey()
535 if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len, in memory_read_publickey()
537 LIBSSH2_FREE(session, pubkey); in memory_read_publickey()
538 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in memory_read_publickey()
566 file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, in file_read_publickey() argument
578 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, "Loading public key file: %s", in file_read_publickey()
583 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in file_read_publickey()
593 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in file_read_publickey()
597 pubkey = LIBSSH2_ALLOC(session, pubkey_len); in file_read_publickey()
600 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in file_read_publickey()
604 LIBSSH2_FREE(session, pubkey); in file_read_publickey()
606 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in file_read_publickey()
618 LIBSSH2_FREE(session, pubkey); in file_read_publickey()
619 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in file_read_publickey()
625 LIBSSH2_FREE(session, pubkey); in file_read_publickey()
626 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in file_read_publickey()
639 if(libssh2_base64_decode(session, (char **) &tmp, &tmp_len, in file_read_publickey()
641 LIBSSH2_FREE(session, pubkey); in file_read_publickey()
642 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in file_read_publickey()
659 memory_read_privatekey(LIBSSH2_SESSION * session, in memory_read_privatekey() argument
681 return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, in memory_read_privatekey()
686 initPEMFromMemory(session, privkeyfiledata, privkeyfiledata_len, in memory_read_privatekey()
689 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in memory_read_privatekey()
700 file_read_privatekey(LIBSSH2_SESSION * session, in file_read_privatekey() argument
709 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, "Loading private key file: %s", in file_read_privatekey()
723 return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, in file_read_privatekey()
728 initPEM(session, privkeyfile, (unsigned char *) passphrase, in file_read_privatekey()
730 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in file_read_privatekey()
743 sign_frommemory(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, in sign_frommemory() argument
752 rc = memory_read_privatekey(session, &privkeyobj, &hostkey_abstract, in sign_frommemory()
753 session->userauth_pblc_method, in sign_frommemory()
754 session->userauth_pblc_method_len, in sign_frommemory()
765 if(privkeyobj->signv(session, sig, sig_len, 1, &datavec, in sign_frommemory()
768 privkeyobj->dtor(session, &hostkey_abstract); in sign_frommemory()
774 privkeyobj->dtor(session, &hostkey_abstract); in sign_frommemory()
780 sign_fromfile(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, in sign_fromfile() argument
789 rc = file_read_privatekey(session, &privkeyobj, &hostkey_abstract, in sign_fromfile()
790 session->userauth_pblc_method, in sign_fromfile()
791 session->userauth_pblc_method_len, in sign_fromfile()
801 if(privkeyobj->signv(session, sig, sig_len, 1, &datavec, in sign_fromfile()
804 privkeyobj->dtor(session, &hostkey_abstract); in sign_fromfile()
810 privkeyobj->dtor(session, &hostkey_abstract); in sign_fromfile()
821 userauth_hostbased_fromfile(LIBSSH2_SESSION *session, in userauth_hostbased_fromfile() argument
832 return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, in userauth_hostbased_fromfile()
836 if(session->userauth_host_state == libssh2_NB_state_idle) { in userauth_hostbased_fromfile()
847 memset(&session->userauth_host_packet_requirev_state, 0, in userauth_hostbased_fromfile()
848 sizeof(session->userauth_host_packet_requirev_state)); in userauth_hostbased_fromfile()
851 rc = file_read_publickey(session, &session->userauth_host_method, in userauth_hostbased_fromfile()
852 &session->userauth_host_method_len, in userauth_hostbased_fromfile()
860 rc = _libssh2_pub_priv_keyfile(session, in userauth_hostbased_fromfile()
861 &session->userauth_host_method, in userauth_hostbased_fromfile()
862 &session->userauth_host_method_len, in userauth_hostbased_fromfile()
876 session->userauth_host_packet_len = in userauth_hostbased_fromfile()
877 username_len + session->userauth_host_method_len + hostname_len + in userauth_hostbased_fromfile()
885 session->userauth_host_s = session->userauth_host_packet = in userauth_hostbased_fromfile()
886 LIBSSH2_ALLOC(session, in userauth_hostbased_fromfile()
887 session->userauth_host_packet_len + 4 + in userauth_hostbased_fromfile()
888 (4 + session->userauth_host_method_len) + in userauth_hostbased_fromfile()
890 if(!session->userauth_host_packet) { in userauth_hostbased_fromfile()
891 LIBSSH2_FREE(session, session->userauth_host_method); in userauth_hostbased_fromfile()
892 session->userauth_host_method = NULL; in userauth_hostbased_fromfile()
893 LIBSSH2_FREE(session, pubkeydata); in userauth_hostbased_fromfile()
894 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_hostbased_fromfile()
898 *(session->userauth_host_s++) = SSH_MSG_USERAUTH_REQUEST; in userauth_hostbased_fromfile()
899 _libssh2_store_str(&session->userauth_host_s, username, username_len); in userauth_hostbased_fromfile()
900 _libssh2_store_str(&session->userauth_host_s, "ssh-connection", 14); in userauth_hostbased_fromfile()
901 _libssh2_store_str(&session->userauth_host_s, "hostbased", 9); in userauth_hostbased_fromfile()
902 _libssh2_store_str(&session->userauth_host_s, in userauth_hostbased_fromfile()
903 (const char *)session->userauth_host_method, in userauth_hostbased_fromfile()
904 session->userauth_host_method_len); in userauth_hostbased_fromfile()
905 _libssh2_store_str(&session->userauth_host_s, (const char *)pubkeydata, in userauth_hostbased_fromfile()
907 LIBSSH2_FREE(session, pubkeydata); in userauth_hostbased_fromfile()
908 _libssh2_store_str(&session->userauth_host_s, hostname, hostname_len); in userauth_hostbased_fromfile()
909 _libssh2_store_str(&session->userauth_host_s, local_username, in userauth_hostbased_fromfile()
912 rc = file_read_privatekey(session, &privkeyobj, &abstract, in userauth_hostbased_fromfile()
913 session->userauth_host_method, in userauth_hostbased_fromfile()
914 session->userauth_host_method_len, in userauth_hostbased_fromfile()
918 LIBSSH2_FREE(session, session->userauth_host_method); in userauth_hostbased_fromfile()
919 session->userauth_host_method = NULL; in userauth_hostbased_fromfile()
920 LIBSSH2_FREE(session, session->userauth_host_packet); in userauth_hostbased_fromfile()
921 session->userauth_host_packet = NULL; in userauth_hostbased_fromfile()
925 _libssh2_htonu32(buf, session->session_id_len); in userauth_hostbased_fromfile()
929 datavec[1].iov_base = (void *)session->session_id; in userauth_hostbased_fromfile()
930 datavec[1].iov_len = session->session_id_len; in userauth_hostbased_fromfile()
931 datavec[2].iov_base = (void *)session->userauth_host_packet; in userauth_hostbased_fromfile()
932 datavec[2].iov_len = session->userauth_host_packet_len; in userauth_hostbased_fromfile()
935 privkeyobj->signv(session, &sig, &sig_len, 3, in userauth_hostbased_fromfile()
937 LIBSSH2_FREE(session, session->userauth_host_method); in userauth_hostbased_fromfile()
938 session->userauth_host_method = NULL; in userauth_hostbased_fromfile()
939 LIBSSH2_FREE(session, session->userauth_host_packet); in userauth_hostbased_fromfile()
940 session->userauth_host_packet = NULL; in userauth_hostbased_fromfile()
942 privkeyobj->dtor(session, &abstract); in userauth_hostbased_fromfile()
948 privkeyobj->dtor(session, &abstract); in userauth_hostbased_fromfile()
954 newpacket = LIBSSH2_REALLOC(session, session->userauth_host_packet, in userauth_hostbased_fromfile()
955 session->userauth_host_packet_len + 4 + in userauth_hostbased_fromfile()
956 (4 + session->userauth_host_method_len) in userauth_hostbased_fromfile()
959 LIBSSH2_FREE(session, sig); in userauth_hostbased_fromfile()
960 LIBSSH2_FREE(session, session->userauth_host_packet); in userauth_hostbased_fromfile()
961 session->userauth_host_packet = NULL; in userauth_hostbased_fromfile()
962 LIBSSH2_FREE(session, session->userauth_host_method); in userauth_hostbased_fromfile()
963 session->userauth_host_method = NULL; in userauth_hostbased_fromfile()
964 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_hostbased_fromfile()
968 session->userauth_host_packet = newpacket; in userauth_hostbased_fromfile()
971 session->userauth_host_s = in userauth_hostbased_fromfile()
972 session->userauth_host_packet + session->userauth_host_packet_len; in userauth_hostbased_fromfile()
974 _libssh2_store_u32(&session->userauth_host_s, in userauth_hostbased_fromfile()
975 4 + session->userauth_host_method_len + in userauth_hostbased_fromfile()
977 _libssh2_store_str(&session->userauth_host_s, in userauth_hostbased_fromfile()
978 (const char *)session->userauth_host_method, in userauth_hostbased_fromfile()
979 session->userauth_host_method_len); in userauth_hostbased_fromfile()
980 LIBSSH2_FREE(session, session->userauth_host_method); in userauth_hostbased_fromfile()
981 session->userauth_host_method = NULL; in userauth_hostbased_fromfile()
983 _libssh2_store_str(&session->userauth_host_s, (const char *)sig, in userauth_hostbased_fromfile()
985 LIBSSH2_FREE(session, sig); in userauth_hostbased_fromfile()
987 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_hostbased_fromfile()
990 session->userauth_host_state = libssh2_NB_state_created; in userauth_hostbased_fromfile()
993 if(session->userauth_host_state == libssh2_NB_state_created) { in userauth_hostbased_fromfile()
994 rc = _libssh2_transport_send(session, session->userauth_host_packet, in userauth_hostbased_fromfile()
995 session->userauth_host_s - in userauth_hostbased_fromfile()
996 session->userauth_host_packet, in userauth_hostbased_fromfile()
999 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in userauth_hostbased_fromfile()
1003 LIBSSH2_FREE(session, session->userauth_host_packet); in userauth_hostbased_fromfile()
1004 session->userauth_host_packet = NULL; in userauth_hostbased_fromfile()
1005 session->userauth_host_state = libssh2_NB_state_idle; in userauth_hostbased_fromfile()
1006 return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, in userauth_hostbased_fromfile()
1009 LIBSSH2_FREE(session, session->userauth_host_packet); in userauth_hostbased_fromfile()
1010 session->userauth_host_packet = NULL; in userauth_hostbased_fromfile()
1012 session->userauth_host_state = libssh2_NB_state_sent; in userauth_hostbased_fromfile()
1015 if(session->userauth_host_state == libssh2_NB_state_sent) { in userauth_hostbased_fromfile()
1019 rc = _libssh2_packet_requirev(session, reply_codes, in userauth_hostbased_fromfile()
1020 &session->userauth_host_data, in userauth_hostbased_fromfile()
1022 &session-> in userauth_hostbased_fromfile()
1025 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in userauth_hostbased_fromfile()
1029 session->userauth_host_state = libssh2_NB_state_idle; in userauth_hostbased_fromfile()
1031 return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, in userauth_hostbased_fromfile()
1035 if(session->userauth_host_data[0] == SSH_MSG_USERAUTH_SUCCESS) { in userauth_hostbased_fromfile()
1036 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_hostbased_fromfile()
1039 LIBSSH2_FREE(session, session->userauth_host_data); in userauth_hostbased_fromfile()
1040 session->userauth_host_data = NULL; in userauth_hostbased_fromfile()
1041 session->state |= LIBSSH2_STATE_AUTHENTICATED; in userauth_hostbased_fromfile()
1047 LIBSSH2_FREE(session, session->userauth_host_data); in userauth_hostbased_fromfile()
1048 session->userauth_host_data = NULL; in userauth_hostbased_fromfile()
1049 return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, in userauth_hostbased_fromfile()
1058 libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session, in libssh2_userauth_hostbased_fromfile_ex() argument
1070 BLOCK_ADJUST(rc, session, in libssh2_userauth_hostbased_fromfile_ex()
1071 userauth_hostbased_fromfile(session, user, user_len, in libssh2_userauth_hostbased_fromfile_ex()
1081 _libssh2_userauth_publickey(LIBSSH2_SESSION *session, in _libssh2_userauth_publickey() argument
1097 if(session->userauth_pblc_state == libssh2_NB_state_idle) { in _libssh2_userauth_publickey()
1104 return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, in _libssh2_userauth_publickey()
1108 memset(&session->userauth_pblc_packet_requirev_state, 0, in _libssh2_userauth_publickey()
1109 sizeof(session->userauth_pblc_packet_requirev_state)); in _libssh2_userauth_publickey()
1117 if(!session->userauth_pblc_method) { in _libssh2_userauth_publickey()
1118 session->userauth_pblc_method_len = _libssh2_ntohu32(pubkeydata); in _libssh2_userauth_publickey()
1120 if(session->userauth_pblc_method_len > pubkeydata_len - 4) in _libssh2_userauth_publickey()
1124 return _libssh2_error(session, in _libssh2_userauth_publickey()
1128 session->userauth_pblc_method = in _libssh2_userauth_publickey()
1129 LIBSSH2_ALLOC(session, session->userauth_pblc_method_len); in _libssh2_userauth_publickey()
1130 if(!session->userauth_pblc_method) { in _libssh2_userauth_publickey()
1131 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in _libssh2_userauth_publickey()
1135 memcpy(session->userauth_pblc_method, pubkeydata + 4, in _libssh2_userauth_publickey()
1136 session->userauth_pblc_method_len); in _libssh2_userauth_publickey()
1143 else if(session->userauth_pblc_method_len != in _libssh2_userauth_publickey()
1145 return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, in _libssh2_userauth_publickey()
1154 session->userauth_pblc_packet_len = in _libssh2_userauth_publickey()
1155 username_len + session->userauth_pblc_method_len + pubkeydata_len + in _libssh2_userauth_publickey()
1167 s = session->userauth_pblc_packet = in _libssh2_userauth_publickey()
1168 LIBSSH2_ALLOC(session, in _libssh2_userauth_publickey()
1169 session->userauth_pblc_packet_len + 4 + in _libssh2_userauth_publickey()
1170 (4 + session->userauth_pblc_method_len) in _libssh2_userauth_publickey()
1172 if(!session->userauth_pblc_packet) { in _libssh2_userauth_publickey()
1173 LIBSSH2_FREE(session, session->userauth_pblc_method); in _libssh2_userauth_publickey()
1174 session->userauth_pblc_method = NULL; in _libssh2_userauth_publickey()
1175 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in _libssh2_userauth_publickey()
1184 session->userauth_pblc_b = s; in _libssh2_userauth_publickey()
1188 _libssh2_store_str(&s, (const char *)session->userauth_pblc_method, in _libssh2_userauth_publickey()
1189 session->userauth_pblc_method_len); in _libssh2_userauth_publickey()
1192 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in _libssh2_userauth_publickey()
1195 session->userauth_pblc_state = libssh2_NB_state_created; in _libssh2_userauth_publickey()
1198 if(session->userauth_pblc_state == libssh2_NB_state_created) { in _libssh2_userauth_publickey()
1199 rc = _libssh2_transport_send(session, session->userauth_pblc_packet, in _libssh2_userauth_publickey()
1200 session->userauth_pblc_packet_len, in _libssh2_userauth_publickey()
1203 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in _libssh2_userauth_publickey()
1206 LIBSSH2_FREE(session, session->userauth_pblc_packet); in _libssh2_userauth_publickey()
1207 session->userauth_pblc_packet = NULL; in _libssh2_userauth_publickey()
1208 LIBSSH2_FREE(session, session->userauth_pblc_method); in _libssh2_userauth_publickey()
1209 session->userauth_pblc_method = NULL; in _libssh2_userauth_publickey()
1210 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1211 return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, in _libssh2_userauth_publickey()
1215 session->userauth_pblc_state = libssh2_NB_state_sent; in _libssh2_userauth_publickey()
1218 if(session->userauth_pblc_state == libssh2_NB_state_sent) { in _libssh2_userauth_publickey()
1219 rc = _libssh2_packet_requirev(session, reply_codes, in _libssh2_userauth_publickey()
1220 &session->userauth_pblc_data, in _libssh2_userauth_publickey()
1221 &session->userauth_pblc_data_len, 0, in _libssh2_userauth_publickey()
1223 &session-> in _libssh2_userauth_publickey()
1226 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in _libssh2_userauth_publickey()
1229 else if(rc || (session->userauth_pblc_data_len < 1)) { in _libssh2_userauth_publickey()
1230 LIBSSH2_FREE(session, session->userauth_pblc_packet); in _libssh2_userauth_publickey()
1231 session->userauth_pblc_packet = NULL; in _libssh2_userauth_publickey()
1232 LIBSSH2_FREE(session, session->userauth_pblc_method); in _libssh2_userauth_publickey()
1233 session->userauth_pblc_method = NULL; in _libssh2_userauth_publickey()
1234 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1235 return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, in _libssh2_userauth_publickey()
1239 if(session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) { in _libssh2_userauth_publickey()
1240 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in _libssh2_userauth_publickey()
1246 LIBSSH2_FREE(session, session->userauth_pblc_data); in _libssh2_userauth_publickey()
1247 session->userauth_pblc_data = NULL; in _libssh2_userauth_publickey()
1248 LIBSSH2_FREE(session, session->userauth_pblc_packet); in _libssh2_userauth_publickey()
1249 session->userauth_pblc_packet = NULL; in _libssh2_userauth_publickey()
1250 LIBSSH2_FREE(session, session->userauth_pblc_method); in _libssh2_userauth_publickey()
1251 session->userauth_pblc_method = NULL; in _libssh2_userauth_publickey()
1252 session->state |= LIBSSH2_STATE_AUTHENTICATED; in _libssh2_userauth_publickey()
1253 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1257 if(session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_FAILURE) { in _libssh2_userauth_publickey()
1259 LIBSSH2_FREE(session, session->userauth_pblc_data); in _libssh2_userauth_publickey()
1260 session->userauth_pblc_data = NULL; in _libssh2_userauth_publickey()
1261 LIBSSH2_FREE(session, session->userauth_pblc_packet); in _libssh2_userauth_publickey()
1262 session->userauth_pblc_packet = NULL; in _libssh2_userauth_publickey()
1263 LIBSSH2_FREE(session, session->userauth_pblc_method); in _libssh2_userauth_publickey()
1264 session->userauth_pblc_method = NULL; in _libssh2_userauth_publickey()
1265 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1266 return _libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED, in _libssh2_userauth_publickey()
1271 LIBSSH2_FREE(session, session->userauth_pblc_data); in _libssh2_userauth_publickey()
1272 session->userauth_pblc_data = NULL; in _libssh2_userauth_publickey()
1274 *session->userauth_pblc_b = 0x01; in _libssh2_userauth_publickey()
1275 session->userauth_pblc_state = libssh2_NB_state_sent1; in _libssh2_userauth_publickey()
1278 if(session->userauth_pblc_state == libssh2_NB_state_sent1) { in _libssh2_userauth_publickey()
1283 s = buf = LIBSSH2_ALLOC(session, 4 + session->session_id_len in _libssh2_userauth_publickey()
1284 + session->userauth_pblc_packet_len); in _libssh2_userauth_publickey()
1286 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in _libssh2_userauth_publickey()
1291 _libssh2_store_str(&s, (const char *)session->session_id, in _libssh2_userauth_publickey()
1292 session->session_id_len); in _libssh2_userauth_publickey()
1294 memcpy(s, session->userauth_pblc_packet, in _libssh2_userauth_publickey()
1295 session->userauth_pblc_packet_len); in _libssh2_userauth_publickey()
1296 s += session->userauth_pblc_packet_len; in _libssh2_userauth_publickey()
1298 rc = sign_callback(session, &sig, &sig_len, buf, s - buf, abstract); in _libssh2_userauth_publickey()
1299 LIBSSH2_FREE(session, buf); in _libssh2_userauth_publickey()
1301 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in _libssh2_userauth_publickey()
1305 LIBSSH2_FREE(session, session->userauth_pblc_method); in _libssh2_userauth_publickey()
1306 session->userauth_pblc_method = NULL; in _libssh2_userauth_publickey()
1307 LIBSSH2_FREE(session, session->userauth_pblc_packet); in _libssh2_userauth_publickey()
1308 session->userauth_pblc_packet = NULL; in _libssh2_userauth_publickey()
1309 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1310 return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, in _libssh2_userauth_publickey()
1321 newpacket = LIBSSH2_REALLOC(session, in _libssh2_userauth_publickey()
1322 session->userauth_pblc_packet, in _libssh2_userauth_publickey()
1323 session->userauth_pblc_packet_len + 4 + in _libssh2_userauth_publickey()
1324 (4 + session->userauth_pblc_method_len) in _libssh2_userauth_publickey()
1327 LIBSSH2_FREE(session, sig); in _libssh2_userauth_publickey()
1328 LIBSSH2_FREE(session, session->userauth_pblc_packet); in _libssh2_userauth_publickey()
1329 session->userauth_pblc_packet = NULL; in _libssh2_userauth_publickey()
1330 LIBSSH2_FREE(session, session->userauth_pblc_method); in _libssh2_userauth_publickey()
1331 session->userauth_pblc_method = NULL; in _libssh2_userauth_publickey()
1332 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1333 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in _libssh2_userauth_publickey()
1337 session->userauth_pblc_packet = newpacket; in _libssh2_userauth_publickey()
1340 s = session->userauth_pblc_packet + session->userauth_pblc_packet_len; in _libssh2_userauth_publickey()
1341 session->userauth_pblc_b = NULL; in _libssh2_userauth_publickey()
1344 4 + session->userauth_pblc_method_len + 4 + in _libssh2_userauth_publickey()
1346 _libssh2_store_str(&s, (const char *)session->userauth_pblc_method, in _libssh2_userauth_publickey()
1347 session->userauth_pblc_method_len); in _libssh2_userauth_publickey()
1349 LIBSSH2_FREE(session, session->userauth_pblc_method); in _libssh2_userauth_publickey()
1350 session->userauth_pblc_method = NULL; in _libssh2_userauth_publickey()
1353 LIBSSH2_FREE(session, sig); in _libssh2_userauth_publickey()
1355 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in _libssh2_userauth_publickey()
1358 session->userauth_pblc_s = s; in _libssh2_userauth_publickey()
1359 session->userauth_pblc_state = libssh2_NB_state_sent2; in _libssh2_userauth_publickey()
1362 if(session->userauth_pblc_state == libssh2_NB_state_sent2) { in _libssh2_userauth_publickey()
1363 rc = _libssh2_transport_send(session, session->userauth_pblc_packet, in _libssh2_userauth_publickey()
1364 session->userauth_pblc_s - in _libssh2_userauth_publickey()
1365 session->userauth_pblc_packet, in _libssh2_userauth_publickey()
1368 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in _libssh2_userauth_publickey()
1372 LIBSSH2_FREE(session, session->userauth_pblc_packet); in _libssh2_userauth_publickey()
1373 session->userauth_pblc_packet = NULL; in _libssh2_userauth_publickey()
1374 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1375 return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, in _libssh2_userauth_publickey()
1378 LIBSSH2_FREE(session, session->userauth_pblc_packet); in _libssh2_userauth_publickey()
1379 session->userauth_pblc_packet = NULL; in _libssh2_userauth_publickey()
1381 session->userauth_pblc_state = libssh2_NB_state_sent3; in _libssh2_userauth_publickey()
1387 rc = _libssh2_packet_requirev(session, reply_codes, in _libssh2_userauth_publickey()
1388 &session->userauth_pblc_data, in _libssh2_userauth_publickey()
1389 &session->userauth_pblc_data_len, 0, NULL, 0, in _libssh2_userauth_publickey()
1390 &session->userauth_pblc_packet_requirev_state); in _libssh2_userauth_publickey()
1392 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in _libssh2_userauth_publickey()
1395 else if(rc || session->userauth_pblc_data_len < 1) { in _libssh2_userauth_publickey()
1396 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1397 return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, in _libssh2_userauth_publickey()
1401 if(session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) { in _libssh2_userauth_publickey()
1402 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in _libssh2_userauth_publickey()
1405 LIBSSH2_FREE(session, session->userauth_pblc_data); in _libssh2_userauth_publickey()
1406 session->userauth_pblc_data = NULL; in _libssh2_userauth_publickey()
1407 session->state |= LIBSSH2_STATE_AUTHENTICATED; in _libssh2_userauth_publickey()
1408 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1413 LIBSSH2_FREE(session, session->userauth_pblc_data); in _libssh2_userauth_publickey()
1414 session->userauth_pblc_data = NULL; in _libssh2_userauth_publickey()
1415 session->userauth_pblc_state = libssh2_NB_state_idle; in _libssh2_userauth_publickey()
1416 return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, in _libssh2_userauth_publickey()
1426 userauth_publickey_frommemory(LIBSSH2_SESSION *session, in userauth_publickey_frommemory() argument
1442 return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, in userauth_publickey_frommemory()
1449 if(session->userauth_pblc_state == libssh2_NB_state_idle) { in userauth_publickey_frommemory()
1451 rc = memory_read_publickey(session, &session->userauth_pblc_method, in userauth_publickey_frommemory()
1452 &session->userauth_pblc_method_len, in userauth_publickey_frommemory()
1460 if(_libssh2_pub_priv_keyfilememory(session, in userauth_publickey_frommemory()
1461 &session->userauth_pblc_method, in userauth_publickey_frommemory()
1462 &session->userauth_pblc_method_len, in userauth_publickey_frommemory()
1466 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in userauth_publickey_frommemory()
1471 return _libssh2_error(session, LIBSSH2_ERROR_FILE, in userauth_publickey_frommemory()
1476 rc = _libssh2_userauth_publickey(session, username, username_len, in userauth_publickey_frommemory()
1480 LIBSSH2_FREE(session, pubkeydata); in userauth_publickey_frommemory()
1490 userauth_publickey_fromfile(LIBSSH2_SESSION *session, in userauth_publickey_fromfile() argument
1504 return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, in userauth_publickey_fromfile()
1511 if(session->userauth_pblc_state == libssh2_NB_state_idle) { in userauth_publickey_fromfile()
1513 rc = file_read_publickey(session, &session->userauth_pblc_method, in userauth_publickey_fromfile()
1514 &session->userauth_pblc_method_len, in userauth_publickey_fromfile()
1521 rc = _libssh2_pub_priv_keyfile(session, in userauth_publickey_fromfile()
1522 &session->userauth_pblc_method, in userauth_publickey_fromfile()
1523 &session->userauth_pblc_method_len, in userauth_publickey_fromfile()
1533 rc = _libssh2_userauth_publickey(session, username, username_len, in userauth_publickey_fromfile()
1537 LIBSSH2_FREE(session, pubkeydata); in userauth_publickey_fromfile()
1546 libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session, in libssh2_userauth_publickey_frommemory() argument
1562 BLOCK_ADJUST(rc, session, in libssh2_userauth_publickey_frommemory()
1563 userauth_publickey_frommemory(session, user, user_len, in libssh2_userauth_publickey_frommemory()
1576 libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, in libssh2_userauth_publickey_fromfile_ex() argument
1590 BLOCK_ADJUST(rc, session, in libssh2_userauth_publickey_fromfile_ex()
1591 userauth_publickey_fromfile(session, user, user_len, in libssh2_userauth_publickey_fromfile_ex()
1601 libssh2_userauth_publickey(LIBSSH2_SESSION *session, in libssh2_userauth_publickey() argument
1611 if(!session) in libssh2_userauth_publickey()
1614 BLOCK_ADJUST(rc, session, in libssh2_userauth_publickey()
1615 _libssh2_userauth_publickey(session, user, strlen(user), in libssh2_userauth_publickey()
1629 userauth_keyboard_interactive(LIBSSH2_SESSION * session, in userauth_keyboard_interactive() argument
1645 if(session->userauth_kybd_state == libssh2_NB_state_idle) { in userauth_keyboard_interactive()
1646 session->userauth_kybd_auth_name = NULL; in userauth_keyboard_interactive()
1647 session->userauth_kybd_auth_instruction = NULL; in userauth_keyboard_interactive()
1648 session->userauth_kybd_num_prompts = 0; in userauth_keyboard_interactive()
1649 session->userauth_kybd_auth_failure = 1; in userauth_keyboard_interactive()
1650 session->userauth_kybd_prompts = NULL; in userauth_keyboard_interactive()
1651 session->userauth_kybd_responses = NULL; in userauth_keyboard_interactive()
1654 memset(&session->userauth_kybd_packet_requirev_state, 0, in userauth_keyboard_interactive()
1655 sizeof(session->userauth_kybd_packet_requirev_state)); in userauth_keyboard_interactive()
1657 session->userauth_kybd_packet_len = in userauth_keyboard_interactive()
1668 session->userauth_kybd_data = s = in userauth_keyboard_interactive()
1669 LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len); in userauth_keyboard_interactive()
1671 return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_keyboard_interactive()
1693 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_keyboard_interactive()
1696 session->userauth_kybd_state = libssh2_NB_state_created; in userauth_keyboard_interactive()
1699 if(session->userauth_kybd_state == libssh2_NB_state_created) { in userauth_keyboard_interactive()
1700 rc = _libssh2_transport_send(session, session->userauth_kybd_data, in userauth_keyboard_interactive()
1701 session->userauth_kybd_packet_len, in userauth_keyboard_interactive()
1704 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in userauth_keyboard_interactive()
1708 LIBSSH2_FREE(session, session->userauth_kybd_data); in userauth_keyboard_interactive()
1709 session->userauth_kybd_data = NULL; in userauth_keyboard_interactive()
1710 session->userauth_kybd_state = libssh2_NB_state_idle; in userauth_keyboard_interactive()
1711 return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, in userauth_keyboard_interactive()
1715 LIBSSH2_FREE(session, session->userauth_kybd_data); in userauth_keyboard_interactive()
1716 session->userauth_kybd_data = NULL; in userauth_keyboard_interactive()
1718 session->userauth_kybd_state = libssh2_NB_state_sent; in userauth_keyboard_interactive()
1722 if(session->userauth_kybd_state == libssh2_NB_state_sent) { in userauth_keyboard_interactive()
1723 rc = _libssh2_packet_requirev(session, reply_codes, in userauth_keyboard_interactive()
1724 &session->userauth_kybd_data, in userauth_keyboard_interactive()
1725 &session->userauth_kybd_data_len, in userauth_keyboard_interactive()
1727 &session-> in userauth_keyboard_interactive()
1730 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in userauth_keyboard_interactive()
1733 else if(rc || session->userauth_kybd_data_len < 1) { in userauth_keyboard_interactive()
1734 session->userauth_kybd_state = libssh2_NB_state_idle; in userauth_keyboard_interactive()
1735 return _libssh2_error(session, in userauth_keyboard_interactive()
1741 if(session->userauth_kybd_data[0] == SSH_MSG_USERAUTH_SUCCESS) { in userauth_keyboard_interactive()
1742 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_keyboard_interactive()
1745 LIBSSH2_FREE(session, session->userauth_kybd_data); in userauth_keyboard_interactive()
1746 session->userauth_kybd_data = NULL; in userauth_keyboard_interactive()
1747 session->state |= LIBSSH2_STATE_AUTHENTICATED; in userauth_keyboard_interactive()
1748 session->userauth_kybd_state = libssh2_NB_state_idle; in userauth_keyboard_interactive()
1752 if(session->userauth_kybd_data[0] == SSH_MSG_USERAUTH_FAILURE) { in userauth_keyboard_interactive()
1753 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_keyboard_interactive()
1755 LIBSSH2_FREE(session, session->userauth_kybd_data); in userauth_keyboard_interactive()
1756 session->userauth_kybd_data = NULL; in userauth_keyboard_interactive()
1757 session->userauth_kybd_state = libssh2_NB_state_idle; in userauth_keyboard_interactive()
1758 return _libssh2_error(session, in userauth_keyboard_interactive()
1765 s = session->userauth_kybd_data + 1; in userauth_keyboard_interactive()
1767 if(session->userauth_kybd_data_len >= 5) { in userauth_keyboard_interactive()
1769 session->userauth_kybd_auth_name_len = _libssh2_ntohu32(s); in userauth_keyboard_interactive()
1773 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1779 if(session->userauth_kybd_auth_name_len) { in userauth_keyboard_interactive()
1780 session->userauth_kybd_auth_name = in userauth_keyboard_interactive()
1781 LIBSSH2_ALLOC(session, in userauth_keyboard_interactive()
1782 session->userauth_kybd_auth_name_len); in userauth_keyboard_interactive()
1783 if(!session->userauth_kybd_auth_name) { in userauth_keyboard_interactive()
1784 _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_keyboard_interactive()
1790 if(s + session->userauth_list_data_len <= in userauth_keyboard_interactive()
1791 session->userauth_kybd_data + in userauth_keyboard_interactive()
1792 session->userauth_kybd_data_len) { in userauth_keyboard_interactive()
1793 memcpy(session->userauth_kybd_auth_name, s, in userauth_keyboard_interactive()
1794 session->userauth_kybd_auth_name_len); in userauth_keyboard_interactive()
1795 s += session->userauth_kybd_auth_name_len; in userauth_keyboard_interactive()
1798 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1805 if(s + 4 <= session->userauth_kybd_data + in userauth_keyboard_interactive()
1806 session->userauth_kybd_data_len) { in userauth_keyboard_interactive()
1808 session->userauth_kybd_auth_instruction_len = in userauth_keyboard_interactive()
1813 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1819 if(session->userauth_kybd_auth_instruction_len) { in userauth_keyboard_interactive()
1820 session->userauth_kybd_auth_instruction = in userauth_keyboard_interactive()
1821 LIBSSH2_ALLOC(session, in userauth_keyboard_interactive()
1822 session->userauth_kybd_auth_instruction_len); in userauth_keyboard_interactive()
1823 if(!session->userauth_kybd_auth_instruction) { in userauth_keyboard_interactive()
1824 _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_keyboard_interactive()
1830 if(s + session->userauth_kybd_auth_instruction_len <= in userauth_keyboard_interactive()
1831 session->userauth_kybd_data + in userauth_keyboard_interactive()
1832 session->userauth_kybd_data_len) { in userauth_keyboard_interactive()
1833 memcpy(session->userauth_kybd_auth_instruction, s, in userauth_keyboard_interactive()
1834 session->userauth_kybd_auth_instruction_len); in userauth_keyboard_interactive()
1835 s += session->userauth_kybd_auth_instruction_len; in userauth_keyboard_interactive()
1838 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1845 if(s + 4 <= session->userauth_kybd_data + in userauth_keyboard_interactive()
1846 session->userauth_kybd_data_len) { in userauth_keyboard_interactive()
1852 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1858 if(s + language_tag_len <= session->userauth_kybd_data + in userauth_keyboard_interactive()
1859 session->userauth_kybd_data_len) { in userauth_keyboard_interactive()
1864 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1870 if(s + 4 <= session->userauth_kybd_data + in userauth_keyboard_interactive()
1871 session->userauth_kybd_data_len) { in userauth_keyboard_interactive()
1873 session->userauth_kybd_num_prompts = _libssh2_ntohu32(s); in userauth_keyboard_interactive()
1877 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1883 if(session->userauth_kybd_num_prompts > 100) { in userauth_keyboard_interactive()
1884 _libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY, in userauth_keyboard_interactive()
1890 if(session->userauth_kybd_num_prompts) { in userauth_keyboard_interactive()
1891 session->userauth_kybd_prompts = in userauth_keyboard_interactive()
1892 LIBSSH2_CALLOC(session, in userauth_keyboard_interactive()
1894 session->userauth_kybd_num_prompts); in userauth_keyboard_interactive()
1895 if(!session->userauth_kybd_prompts) { in userauth_keyboard_interactive()
1896 _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_keyboard_interactive()
1902 session->userauth_kybd_responses = in userauth_keyboard_interactive()
1903 LIBSSH2_CALLOC(session, in userauth_keyboard_interactive()
1905 session->userauth_kybd_num_prompts); in userauth_keyboard_interactive()
1906 if(!session->userauth_kybd_responses) { in userauth_keyboard_interactive()
1907 _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_keyboard_interactive()
1913 for(i = 0; i < session->userauth_kybd_num_prompts; i++) { in userauth_keyboard_interactive()
1914 if(s + 4 <= session->userauth_kybd_data + in userauth_keyboard_interactive()
1915 session->userauth_kybd_data_len) { in userauth_keyboard_interactive()
1917 session->userauth_kybd_prompts[i].length = in userauth_keyboard_interactive()
1922 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1929 session->userauth_kybd_prompts[i].text = in userauth_keyboard_interactive()
1930 LIBSSH2_CALLOC(session, in userauth_keyboard_interactive()
1931 session->userauth_kybd_prompts[i]. in userauth_keyboard_interactive()
1933 if(!session->userauth_kybd_prompts[i].text) { in userauth_keyboard_interactive()
1934 _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_keyboard_interactive()
1940 if(s + session->userauth_kybd_prompts[i].length <= in userauth_keyboard_interactive()
1941 session->userauth_kybd_data + in userauth_keyboard_interactive()
1942 session->userauth_kybd_data_len) { in userauth_keyboard_interactive()
1943 memcpy(session->userauth_kybd_prompts[i].text, s, in userauth_keyboard_interactive()
1944 session->userauth_kybd_prompts[i].length); in userauth_keyboard_interactive()
1945 s += session->userauth_kybd_prompts[i].length; in userauth_keyboard_interactive()
1948 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1953 if(s < session->userauth_kybd_data + in userauth_keyboard_interactive()
1954 session->userauth_kybd_data_len) { in userauth_keyboard_interactive()
1956 session->userauth_kybd_prompts[i].echo = *s++; in userauth_keyboard_interactive()
1959 _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, in userauth_keyboard_interactive()
1967 response_callback(session->userauth_kybd_auth_name, in userauth_keyboard_interactive()
1968 session->userauth_kybd_auth_name_len, in userauth_keyboard_interactive()
1969 session->userauth_kybd_auth_instruction, in userauth_keyboard_interactive()
1970 session->userauth_kybd_auth_instruction_len, in userauth_keyboard_interactive()
1971 session->userauth_kybd_num_prompts, in userauth_keyboard_interactive()
1972 session->userauth_kybd_prompts, in userauth_keyboard_interactive()
1973 session->userauth_kybd_responses, in userauth_keyboard_interactive()
1974 &session->abstract); in userauth_keyboard_interactive()
1976 _libssh2_debug(session, LIBSSH2_TRACE_AUTH, in userauth_keyboard_interactive()
1980 session->userauth_kybd_packet_len = in userauth_keyboard_interactive()
1985 for(i = 0; i < session->userauth_kybd_num_prompts; i++) { in userauth_keyboard_interactive()
1987 if(session->userauth_kybd_responses[i].length <= in userauth_keyboard_interactive()
1988 (SIZE_MAX - 4 - session->userauth_kybd_packet_len) ) { in userauth_keyboard_interactive()
1989 session->userauth_kybd_packet_len += in userauth_keyboard_interactive()
1990 4 + session->userauth_kybd_responses[i].length; in userauth_keyboard_interactive()
1993 _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_keyboard_interactive()
2002 LIBSSH2_FREE(session, session->userauth_kybd_data); in userauth_keyboard_interactive()
2004 session->userauth_kybd_data = s = in userauth_keyboard_interactive()
2005 LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len); in userauth_keyboard_interactive()
2007 _libssh2_error(session, LIBSSH2_ERROR_ALLOC, in userauth_keyboard_interactive()
2015 _libssh2_store_u32(&s, session->userauth_kybd_num_prompts); in userauth_keyboard_interactive()
2017 for(i = 0; i < session->userauth_kybd_num_prompts; i++) { in userauth_keyboard_interactive()
2019 session->userauth_kybd_responses[i].text, in userauth_keyboard_interactive()
2020 session->userauth_kybd_responses[i].length); in userauth_keyboard_interactive()
2023 session->userauth_kybd_state = libssh2_NB_state_sent1; in userauth_keyboard_interactive()
2026 if(session->userauth_kybd_state == libssh2_NB_state_sent1) { in userauth_keyboard_interactive()
2027 rc = _libssh2_transport_send(session, session->userauth_kybd_data, in userauth_keyboard_interactive()
2028 session->userauth_kybd_packet_len, in userauth_keyboard_interactive()
2031 return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, in userauth_keyboard_interactive()
2034 _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, in userauth_keyboard_interactive()
2040 session->userauth_kybd_auth_failure = 0; in userauth_keyboard_interactive()
2049 LIBSSH2_FREE(session, session->userauth_kybd_data); in userauth_keyboard_interactive()
2050 session->userauth_kybd_data = NULL; in userauth_keyboard_interactive()
2052 if(session->userauth_kybd_prompts) { in userauth_keyboard_interactive()
2053 for(i = 0; i < session->userauth_kybd_num_prompts; i++) { in userauth_keyboard_interactive()
2054 LIBSSH2_FREE(session, session->userauth_kybd_prompts[i].text); in userauth_keyboard_interactive()
2055 session->userauth_kybd_prompts[i].text = NULL; in userauth_keyboard_interactive()
2059 if(session->userauth_kybd_responses) { in userauth_keyboard_interactive()
2060 for(i = 0; i < session->userauth_kybd_num_prompts; i++) { in userauth_keyboard_interactive()
2061 LIBSSH2_FREE(session, in userauth_keyboard_interactive()
2062 session->userauth_kybd_responses[i].text); in userauth_keyboard_interactive()
2063 session->userauth_kybd_responses[i].text = NULL; in userauth_keyboard_interactive()
2067 if(session->userauth_kybd_prompts) { in userauth_keyboard_interactive()
2068 LIBSSH2_FREE(session, session->userauth_kybd_prompts); in userauth_keyboard_interactive()
2069 session->userauth_kybd_prompts = NULL; in userauth_keyboard_interactive()
2071 if(session->userauth_kybd_responses) { in userauth_keyboard_interactive()
2072 LIBSSH2_FREE(session, session->userauth_kybd_responses); in userauth_keyboard_interactive()
2073 session->userauth_kybd_responses = NULL; in userauth_keyboard_interactive()
2075 if(session->userauth_kybd_auth_name) { in userauth_keyboard_interactive()
2076 LIBSSH2_FREE(session, session->userauth_kybd_auth_name); in userauth_keyboard_interactive()
2077 session->userauth_kybd_auth_name = NULL; in userauth_keyboard_interactive()
2079 if(session->userauth_kybd_auth_instruction) { in userauth_keyboard_interactive()
2080 LIBSSH2_FREE(session, session->userauth_kybd_auth_instruction); in userauth_keyboard_interactive()
2081 session->userauth_kybd_auth_instruction = NULL; in userauth_keyboard_interactive()
2084 if(session->userauth_kybd_auth_failure) { in userauth_keyboard_interactive()
2085 session->userauth_kybd_state = libssh2_NB_state_idle; in userauth_keyboard_interactive()
2089 session->userauth_kybd_state = libssh2_NB_state_sent; in userauth_keyboard_interactive()
2099 libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION *session, in libssh2_userauth_keyboard_interactive_ex() argument
2106 BLOCK_ADJUST(rc, session, in libssh2_userauth_keyboard_interactive_ex()
2107 userauth_keyboard_interactive(session, user, user_len, in libssh2_userauth_keyboard_interactive_ex()