Lines Matching +full:- +full:- +full:with +full:- +full:libssh2
21 * SPDX-License-Identifier: curl
203 struct connectdata *conn = data->conn; in kbd_callback()
204 responses[0].text = strdup(conn->passwd); in kbd_callback()
206 responses[0].text == NULL ? 0 : curlx_uztoui(strlen(conn->passwd)); in kbd_callback()
246 /* Ordered by order of appearance in libssh2.h */ in libssh2_session_error_to_CURLE()
284 /* These functions are made to use the libcurl memory functions - NOT the
285 debugmem functions, as that leads us to trigger on libssh2 memory leaks
303 if(ptr) /* ssh2 agent sometimes call free with null ptr */ in LIBSSH2_FREE_FUNC()
313 struct connectdata *conn = data->conn; in state()
314 struct ssh_conn *sshc = &conn->proto.sshc; in state()
383 if(sshc->state != nowstate) { in state()
385 (void *)sshc, names[sshc->state], names[nowstate]); in state()
389 sshc->state = nowstate; in state()
411 * Earlier libssh2 versions did not have the ability to seek to 64-bit
412 * positions with 32-bit size_t.
421 * Earlier libssh2 versions did not do SCP properly beyond 32-bit sizes on
422 * 32-bit architectures so we check of the necessary function is present.
432 * libssh2 1.2.8 fixed the problem with 32-bit ints used for sockets on win64.
481 if(data->set.str[STRING_SSH_KNOWNHOSTS]) { in ssh_knownhost()
483 struct connectdata *conn = data->conn; in ssh_knownhost()
484 struct ssh_conn *sshc = &conn->proto.sshc; in ssh_knownhost()
486 const char *remotekey = libssh2_session_hostkey(sshc->ssh_session, in ssh_knownhost()
499 data->set.ssh_keyfunc ? data->set.ssh_keyfunc : sshkeycallback; in ssh_knownhost()
541 keycheck = libssh2_knownhost_checkp(sshc->kh, in ssh_knownhost()
542 conn->host.name, in ssh_knownhost()
543 (conn->remote_port != PORT_SSH) ? in ssh_knownhost()
544 conn->remote_port : -1, in ssh_knownhost()
551 keycheck = libssh2_knownhost_check(sshc->kh, in ssh_knownhost()
552 conn->host.name, in ssh_knownhost()
562 host->key : "<none>"); in ssh_knownhost()
566 knownkey.key = host->key; in ssh_knownhost()
588 keymatch, data->set.ssh_keyfunc_userp); in ssh_knownhost()
603 result = sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; in ssh_knownhost()
608 libssh2_knownhost_del(sshc->kh, host); in ssh_knownhost()
616 int addrc = libssh2_knownhost_add(sshc->kh, in ssh_knownhost()
617 conn->host.name, NULL, in ssh_knownhost()
624 conn->host.name); in ssh_knownhost()
627 /* now we write the entire in-memory list of known hosts to the in ssh_knownhost()
630 libssh2_knownhost_writefile(sshc->kh, in ssh_knownhost()
631 data->set.str[STRING_SSH_KNOWNHOSTS], in ssh_knownhost()
635 data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_knownhost()
650 struct connectdata *conn = data->conn; in ssh_check_fingerprint()
651 struct ssh_conn *sshc = &conn->proto.sshc; in ssh_check_fingerprint()
652 const char *pubkey_md5 = data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5]; in ssh_check_fingerprint()
653 const char *pubkey_sha256 = data->set.str[STRING_SSH_HOST_PUBLIC_KEY_SHA256]; in ssh_check_fingerprint()
669 fingerprint = libssh2_hostkey_hash(sshc->ssh_session, in ssh_check_fingerprint()
676 hostkey = libssh2_session_hostkey(sshc->ssh_session, &len, NULL); in ssh_check_fingerprint()
688 sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; in ssh_check_fingerprint()
689 return sshc->actualcode; in ssh_check_fingerprint()
697 sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; in ssh_check_fingerprint()
698 return sshc->actualcode; in ssh_check_fingerprint()
704 sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; in ssh_check_fingerprint()
705 return sshc->actualcode; in ssh_check_fingerprint()
731 sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; in ssh_check_fingerprint()
732 return sshc->actualcode; in ssh_check_fingerprint()
744 fingerprint = libssh2_hostkey_hash(sshc->ssh_session, in ssh_check_fingerprint()
771 sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; in ssh_check_fingerprint()
772 return sshc->actualcode; in ssh_check_fingerprint()
778 if(data->set.ssh_hostkeyfunc) { in ssh_check_fingerprint()
783 const char *remotekey = libssh2_session_hostkey(sshc->ssh_session, in ssh_check_fingerprint()
788 rc = data->set.ssh_hostkeyfunc(data->set.ssh_hostkeyfunc_userp, in ssh_check_fingerprint()
793 sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; in ssh_check_fingerprint()
794 return sshc->actualcode; in ssh_check_fingerprint()
799 sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; in ssh_check_fingerprint()
800 return sshc->actualcode; in ssh_check_fingerprint()
826 = "ssh-ed25519"; in ssh_force_knownhost_key_type()
830 = "ecdsa-sha2-nistp521"; in ssh_force_knownhost_key_type()
834 = "ecdsa-sha2-nistp384"; in ssh_force_knownhost_key_type()
838 = "ecdsa-sha2-nistp256"; in ssh_force_knownhost_key_type()
841 = "ssh-rsa"; in ssh_force_knownhost_key_type()
843 = "rsa-sha2-256,rsa-sha2-512,ssh-rsa"; in ssh_force_knownhost_key_type()
845 = "ssh-dss"; in ssh_force_knownhost_key_type()
848 struct connectdata *conn = data->conn; in ssh_force_knownhost_key_type()
849 struct ssh_conn *sshc = &conn->proto.sshc; in ssh_force_knownhost_key_type()
856 if(sshc->kh && !data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5]) { in ssh_force_knownhost_key_type()
858 while(!libssh2_knownhost_get(sshc->kh, &store, store)) { in ssh_force_knownhost_key_type()
859 /* For non-standard ports, the name will be enclosed in */ in ssh_force_knownhost_key_type()
862 if(store->name) { in ssh_force_knownhost_key_type()
863 if(store->name[0] == '[') { in ssh_force_knownhost_key_type()
864 kh_name_end = strstr(store->name, "]:"); in ssh_force_knownhost_key_type()
867 store->name, data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_force_knownhost_key_type()
871 if(kh_name_end && (port == conn->remote_port)) { in ssh_force_knownhost_key_type()
872 kh_name_size = strlen(store->name) - 1 - strlen(kh_name_end); in ssh_force_knownhost_key_type()
873 if(strncmp(store->name + 1, in ssh_force_knownhost_key_type()
874 conn->host.name, kh_name_size) == 0) { in ssh_force_knownhost_key_type()
880 else if(strcmp(store->name, conn->host.name) == 0) { in ssh_force_knownhost_key_type()
895 conn->host.name, data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_force_knownhost_key_type()
897 switch(store->typemask & LIBSSH2_KNOWNHOST_KEY_MASK) { in ssh_force_knownhost_key_type()
925 /* old libssh2 which cannot correctly remove unsupported methods due in ssh_force_knownhost_key_type()
938 (store->typemask & LIBSSH2_KNOWNHOST_KEY_MASK)); in ssh_force_knownhost_key_type()
943 rc = libssh2_session_method_pref(sshc->ssh_session, in ssh_force_knownhost_key_type()
948 libssh2_session_last_error(sshc->ssh_session, &errmsg, &errlen, 0); in ssh_force_knownhost_key_type()
949 failf(data, "libssh2: %s", errmsg); in ssh_force_knownhost_key_type()
955 conn->host.name, data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_force_knownhost_key_type()
974 * 'sshc->quote_item' is already verified to be non-NULL before it in sftp_quote()
977 char *cmd = sshc->quote_item->data; in sftp_quote()
978 sshc->acceptfail = FALSE; in sftp_quote()
980 /* if a command starts with an asterisk, which a legal SFTP command never in sftp_quote()
987 sshc->acceptfail = TRUE; in sftp_quote()
992 char *tmp = aprintf("257 \"%s\" is current directory.\n", sshp->path); in sftp_quote()
998 /* this sends an FTP-like "header" to the header callback so that the in sftp_quote()
1010 * command with a space so we can check for it unconditionally in sftp_quote()
1022 result = Curl_get_pathname(&cp, &sshc->quote_path1, sshc->homedir); in sftp_quote()
1032 * appropriate libssh2 functions. in sftp_quote()
1041 /* sshc->quote_path1 contains the mode to set */ in sftp_quote()
1043 result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir); in sftp_quote()
1047 Curl_safefree(sshc->quote_path1); in sftp_quote()
1050 memset(&sshp->quote_attrs, 0, sizeof(LIBSSH2_SFTP_ATTRIBUTES)); in sftp_quote()
1057 /* sshc->quote_path1 is the source */ in sftp_quote()
1059 result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir); in sftp_quote()
1063 Curl_safefree(sshc->quote_path1); in sftp_quote()
1078 result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir); in sftp_quote()
1082 Curl_safefree(sshc->quote_path1); in sftp_quote()
1105 Curl_safefree(sshc->quote_path1); in sftp_quote()
1106 Curl_safefree(sshc->quote_path2); in sftp_quote()
1119 * NOTE!!! libssh2 requires that the destination path is a full path in sftp_upload_init()
1125 if(data->state.resume_from) { in sftp_upload_init()
1127 if(data->state.resume_from < 0) { in sftp_upload_init()
1128 int rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshp->path, in sftp_upload_init()
1129 curlx_uztoui(strlen(sshp->path)), in sftp_upload_init()
1136 data->state.resume_from = 0; in sftp_upload_init()
1144 data->state.resume_from = attrs.filesize; in sftp_upload_init()
1149 if(data->set.remote_append) in sftp_upload_init()
1152 else if(data->state.resume_from > 0) in sftp_upload_init()
1159 sshc->sftp_handle = in sftp_upload_init()
1160 libssh2_sftp_open_ex(sshc->sftp_session, sshp->path, in sftp_upload_init()
1161 curlx_uztoui(strlen(sshp->path)), in sftp_upload_init()
1162 flags, (long)data->set.new_file_perms, in sftp_upload_init()
1165 if(!sshc->sftp_handle) { in sftp_upload_init()
1167 int rc = libssh2_session_last_errno(sshc->ssh_session); in sftp_upload_init()
1177 sftperr = libssh2_sftp_last_error(sshc->sftp_session); in sftp_upload_init()
1181 if(sshc->secondCreateDirs) { in sftp_upload_init()
1183 sshc->actualcode = sftperr != LIBSSH2_FX_OK ? in sftp_upload_init()
1192 (data->set.ftp_create_missing_dirs && in sftp_upload_init()
1193 (strlen(sshp->path) > 1))) { in sftp_upload_init()
1195 sshc->secondCreateDirs = 1; in sftp_upload_init()
1200 sshc->actualcode = sftperr != LIBSSH2_FX_OK ? in sftp_upload_init()
1202 if(!sshc->actualcode) { in sftp_upload_init()
1206 sshc->actualcode = CURLE_SSH; in sftp_upload_init()
1213 return sshc->actualcode; in sftp_upload_init()
1218 if(data->state.resume_from > 0) { in sftp_upload_init()
1221 if(data->set.seek_func) { in sftp_upload_init()
1223 seekerr = data->set.seek_func(data->set.seek_client, in sftp_upload_init()
1224 data->state.resume_from, SEEK_SET); in sftp_upload_init()
1239 (data->state.resume_from - passed > in sftp_upload_init()
1241 sizeof(scratch) : curlx_sotouz(data->state.resume_from - passed); in sftp_upload_init()
1245 actuallyread = data->state.fread_func(scratch, 1, in sftp_upload_init()
1247 data->state.in); in sftp_upload_init()
1252 /* this checks for greater-than only to make sure that the in sftp_upload_init()
1257 } while(passed < data->state.resume_from); in sftp_upload_init()
1261 if(data->state.infilesize > 0) { in sftp_upload_init()
1262 data->state.infilesize -= data->state.resume_from; in sftp_upload_init()
1263 data->req.size = data->state.infilesize; in sftp_upload_init()
1264 Curl_pgrsSetUploadSize(data, data->state.infilesize); in sftp_upload_init()
1267 SFTP_SEEK(sshc->sftp_handle, data->state.resume_from); in sftp_upload_init()
1269 if(data->state.infilesize > 0) { in sftp_upload_init()
1270 data->req.size = data->state.infilesize; in sftp_upload_init()
1271 Curl_pgrsSetUploadSize(data, data->state.infilesize); in sftp_upload_init()
1274 Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE); in sftp_upload_init()
1277 data->conn->sockfd = data->conn->writesockfd; in sftp_upload_init()
1281 sshc->orig_waitfor = data->req.keepon; in sftp_upload_init()
1284 out readable as the underlying libssh2 sftp send function will deal in sftp_upload_init()
1285 with both accordingly */ in sftp_upload_init()
1286 data->state.select_bits = CURL_CSELECT_OUT; in sftp_upload_init()
1303 * with the requested type of authentication in sftp_pkey_init()
1305 sshc->authed = FALSE; in sftp_pkey_init()
1307 if((data->set.ssh_auth_types & CURLSSH_AUTH_PUBLICKEY) && in sftp_pkey_init()
1308 (strstr(sshc->authlist, "publickey") != NULL)) { in sftp_pkey_init()
1311 sshc->rsa_pub = sshc->rsa = NULL; in sftp_pkey_init()
1313 if(data->set.str[STRING_SSH_PRIVATE_KEY]) in sftp_pkey_init()
1314 sshc->rsa = strdup(data->set.str[STRING_SSH_PRIVATE_KEY]); in sftp_pkey_init()
1316 /* To ponder about: should really the lib be messing about with the in sftp_pkey_init()
1324 sshc->rsa = aprintf("%s/.ssh/id_rsa", home); in sftp_pkey_init()
1325 if(!sshc->rsa) in sftp_pkey_init()
1327 else if(stat(sshc->rsa, &sbuf)) { in sftp_pkey_init()
1328 Curl_safefree(sshc->rsa); in sftp_pkey_init()
1329 sshc->rsa = aprintf("%s/.ssh/id_dsa", home); in sftp_pkey_init()
1330 if(!sshc->rsa) in sftp_pkey_init()
1332 else if(stat(sshc->rsa, &sbuf)) { in sftp_pkey_init()
1333 Curl_safefree(sshc->rsa); in sftp_pkey_init()
1338 if(!out_of_memory && !sshc->rsa) { in sftp_pkey_init()
1340 sshc->rsa = strdup("id_rsa"); in sftp_pkey_init()
1341 if(sshc->rsa && stat(sshc->rsa, &sbuf)) { in sftp_pkey_init()
1342 Curl_safefree(sshc->rsa); in sftp_pkey_init()
1343 sshc->rsa = strdup("id_dsa"); in sftp_pkey_init()
1344 if(sshc->rsa && stat(sshc->rsa, &sbuf)) { in sftp_pkey_init()
1345 Curl_safefree(sshc->rsa); in sftp_pkey_init()
1348 sshc->rsa = strdup(""); in sftp_pkey_init()
1356 * libssh2 extract the public key from the private key file. in sftp_pkey_init()
1357 * This is done by simply passing sshc->rsa_pub = NULL. in sftp_pkey_init()
1359 if(data->set.str[STRING_SSH_PUBLIC_KEY] in sftp_pkey_init()
1361 && data->set.str[STRING_SSH_PUBLIC_KEY][0]) { in sftp_pkey_init()
1362 sshc->rsa_pub = strdup(data->set.str[STRING_SSH_PUBLIC_KEY]); in sftp_pkey_init()
1363 if(!sshc->rsa_pub) in sftp_pkey_init()
1367 if(out_of_memory || !sshc->rsa) { in sftp_pkey_init()
1368 Curl_safefree(sshc->rsa); in sftp_pkey_init()
1369 Curl_safefree(sshc->rsa_pub); in sftp_pkey_init()
1371 sshc->actualcode = CURLE_OUT_OF_MEMORY; in sftp_pkey_init()
1375 sshc->passphrase = data->set.ssl.key_passwd; in sftp_pkey_init()
1376 if(!sshc->passphrase) in sftp_pkey_init()
1377 sshc->passphrase = ""; in sftp_pkey_init()
1379 if(sshc->rsa_pub) in sftp_pkey_init()
1380 infof(data, "Using SSH public key file '%s'", sshc->rsa_pub); in sftp_pkey_init()
1381 infof(data, "Using SSH private key file '%s'", sshc->rsa); in sftp_pkey_init()
1397 char *cmd = sshc->quote_item->data; in sftp_quote_stat()
1398 sshc->acceptfail = FALSE; in sftp_quote_stat()
1400 /* if a command starts with an asterisk, which a legal SFTP command never in sftp_quote_stat()
1407 sshc->acceptfail = TRUE; in sftp_quote_stat()
1411 /* Since chown and chgrp only set owner OR group but libssh2 wants to set in sftp_quote_stat()
1415 int rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshc->quote_path2, in sftp_quote_stat()
1416 curlx_uztoui(strlen(sshc->quote_path2)), in sftp_quote_stat()
1418 &sshp->quote_attrs); in sftp_quote_stat()
1423 if(rc && !sshc->acceptfail) { /* get those attributes */ in sftp_quote_stat()
1424 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in sftp_quote_stat()
1433 sshp->quote_attrs.gid = strtoul(sshc->quote_path1, NULL, 10); in sftp_quote_stat()
1434 sshp->quote_attrs.flags = LIBSSH2_SFTP_ATTR_UIDGID; in sftp_quote_stat()
1435 if(sshp->quote_attrs.gid == 0 && !ISDIGIT(sshc->quote_path1[0]) && in sftp_quote_stat()
1436 !sshc->acceptfail) { in sftp_quote_stat()
1442 sshp->quote_attrs.permissions = strtoul(sshc->quote_path1, NULL, 8); in sftp_quote_stat()
1443 sshp->quote_attrs.flags = LIBSSH2_SFTP_ATTR_PERMISSIONS; in sftp_quote_stat()
1445 if(sshp->quote_attrs.permissions == 0 && in sftp_quote_stat()
1446 !ISDIGIT(sshc->quote_path1[0])) { in sftp_quote_stat()
1452 sshp->quote_attrs.uid = strtoul(sshc->quote_path1, NULL, 10); in sftp_quote_stat()
1453 sshp->quote_attrs.flags = LIBSSH2_SFTP_ATTR_UIDGID; in sftp_quote_stat()
1454 if(sshp->quote_attrs.uid == 0 && !ISDIGIT(sshc->quote_path1[0]) && in sftp_quote_stat()
1455 !sshc->acceptfail) { in sftp_quote_stat()
1462 time_t date = Curl_getdate_capped(sshc->quote_path1); in sftp_quote_stat()
1465 if(date == -1) { in sftp_quote_stat()
1471 /* if 'long' cannot old >32-bit, this date cannot be sent */ in sftp_quote_stat()
1479 sshp->quote_attrs.atime = (unsigned long)date; in sftp_quote_stat()
1481 sshp->quote_attrs.mtime = (unsigned long)date; in sftp_quote_stat()
1483 sshp->quote_attrs.flags = LIBSSH2_SFTP_ATTR_ACMODTIME; in sftp_quote_stat()
1490 Curl_safefree(sshc->quote_path1); in sftp_quote_stat()
1491 Curl_safefree(sshc->quote_path2); in sftp_quote_stat()
1502 int rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshp->path, in sftp_download_stat()
1503 curlx_uztoui(strlen(sshp->path)), in sftp_download_stat()
1515 * OR the server does not return a file size with a stat() in sftp_download_stat()
1518 data->req.size = -1; in sftp_download_stat()
1519 data->req.maxdownload = -1; in sftp_download_stat()
1520 Curl_pgrsSetDownloadSize(data, -1); in sftp_download_stat()
1529 if(data->state.use_range) { in sftp_download_stat()
1536 from_t = curlx_strtoofft(data->state.range, &ptr, 10, &from); in sftp_download_stat()
1539 while(*ptr && (ISBLANK(*ptr) || (*ptr == '-'))) in sftp_download_stat()
1546 to = size - 1; in sftp_download_stat()
1550 from = size - to; in sftp_download_stat()
1551 to = size - 1; in sftp_download_stat()
1563 if((to - from) == CURL_OFF_T_MAX) in sftp_download_stat()
1565 size = to - from + 1; in sftp_download_stat()
1568 SFTP_SEEK(sshc->sftp_handle, from); in sftp_download_stat()
1570 data->req.size = size; in sftp_download_stat()
1571 data->req.maxdownload = size; in sftp_download_stat()
1576 if(data->state.resume_from) { in sftp_download_stat()
1577 if(data->state.resume_from < 0) { in sftp_download_stat()
1579 if((curl_off_t)attrs.filesize < -data->state.resume_from) { in sftp_download_stat()
1582 data->state.resume_from, (curl_off_t)attrs.filesize); in sftp_download_stat()
1586 data->state.resume_from += attrs.filesize; in sftp_download_stat()
1589 if((curl_off_t)attrs.filesize < data->state.resume_from) { in sftp_download_stat()
1592 data->state.resume_from, (curl_off_t)attrs.filesize); in sftp_download_stat()
1597 data->req.size = attrs.filesize - data->state.resume_from; in sftp_download_stat()
1598 data->req.maxdownload = attrs.filesize - data->state.resume_from; in sftp_download_stat()
1600 attrs.filesize - data->state.resume_from); in sftp_download_stat()
1601 SFTP_SEEK(sshc->sftp_handle, data->state.resume_from); in sftp_download_stat()
1605 if(data->req.size == 0) { in sftp_download_stat()
1612 Curl_xfer_setup1(data, CURL_XFER_RECV, data->req.size, FALSE); in sftp_download_stat()
1615 data->conn->writesockfd = data->conn->sockfd; in sftp_download_stat()
1618 out writableable as the underlying libssh2 recv function will deal in sftp_download_stat()
1619 with both accordingly */ in sftp_download_stat()
1620 data->state.select_bits = CURL_CSELECT_IN; in sftp_download_stat()
1632 int rc = libssh2_sftp_readdir_ex(sshc->sftp_handle, in sftp_readdir()
1633 sshp->readdir_filename, CURL_PATH_MAX, in sftp_readdir()
1634 sshp->readdir_longentry, CURL_PATH_MAX, in sftp_readdir()
1635 &sshp->readdir_attrs); in sftp_readdir()
1642 sshp->readdir_filename[readdir_len] = '\0'; in sftp_readdir()
1644 if(data->set.list_only) { in sftp_readdir()
1646 sshp->readdir_filename, in sftp_readdir()
1655 result = Curl_dyn_add(&sshp->readdir, sshp->readdir_longentry); in sftp_readdir()
1658 if((sshp->readdir_attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) && in sftp_readdir()
1659 ((sshp->readdir_attrs.permissions & LIBSSH2_SFTP_S_IFMT) == in sftp_readdir()
1661 Curl_dyn_init(&sshp->readdir_link, CURL_PATH_MAX); in sftp_readdir()
1662 result = Curl_dyn_addf(&sshp->readdir_link, "%s%s", sshp->path, in sftp_readdir()
1663 sshp->readdir_filename); in sftp_readdir()
1677 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in sftp_readdir()
1679 sshc->actualcode = result ? result : CURLE_SSH; in sftp_readdir()
1682 libssh2_session_last_errno(sshc->ssh_session)); in sftp_readdir()
1690 * to will be set to TRUE if the libssh2 function returns LIBSSH2_ERROR_EAGAIN
1697 struct connectdata *conn = data->conn; in ssh_statemachine()
1698 struct SSHPROTO *sshp = data->req.p.ssh; in ssh_statemachine()
1699 struct ssh_conn *sshc = &conn->proto.sshc; in ssh_statemachine()
1705 switch(sshc->state) { in ssh_statemachine()
1707 sshc->secondCreateDirs = 0; in ssh_statemachine()
1708 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
1709 sshc->actualcode = CURLE_OK; in ssh_statemachine()
1711 /* Set libssh2 to non-blocking, since everything internally is in ssh_statemachine()
1712 non-blocking */ in ssh_statemachine()
1713 libssh2_session_set_blocking(sshc->ssh_session, 0); in ssh_statemachine()
1718 sshc->actualcode = result; in ssh_statemachine()
1726 rc = session_startup(sshc->ssh_session, conn->sock[FIRSTSOCKET]); in ssh_statemachine()
1732 (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0); in ssh_statemachine()
1736 sshc->actualcode = CURLE_FAILED_INIT; in ssh_statemachine()
1760 * here, even though the libssh2 docs kind of indicate that it should be in ssh_statemachine()
1761 * possible to get a 'generic' list (not user-specific) of authentication in ssh_statemachine()
1762 * methods, presumably with a blank username. That will not work in my in ssh_statemachine()
1766 sshc->authlist = libssh2_userauth_list(sshc->ssh_session, in ssh_statemachine()
1767 conn->user, in ssh_statemachine()
1768 curlx_uztoui(strlen(conn->user))); in ssh_statemachine()
1770 if(!sshc->authlist) { in ssh_statemachine()
1771 if(libssh2_userauth_authenticated(sshc->ssh_session)) { in ssh_statemachine()
1772 sshc->authed = TRUE; in ssh_statemachine()
1773 infof(data, "SSH user accepted with no authentication"); in ssh_statemachine()
1777 rc = libssh2_session_last_errno(sshc->ssh_session); in ssh_statemachine()
1782 sshc->actualcode = libssh2_session_error_to_CURLE(rc); in ssh_statemachine()
1787 sshc->authlist); in ssh_statemachine()
1799 rc = libssh2_userauth_publickey_fromfile_ex(sshc->ssh_session, in ssh_statemachine()
1800 conn->user, in ssh_statemachine()
1802 strlen(conn->user)), in ssh_statemachine()
1803 sshc->rsa_pub, in ssh_statemachine()
1804 sshc->rsa, sshc->passphrase); in ssh_statemachine()
1809 Curl_safefree(sshc->rsa_pub); in ssh_statemachine()
1810 Curl_safefree(sshc->rsa); in ssh_statemachine()
1813 sshc->authed = TRUE; in ssh_statemachine()
1819 char unknown[] = "Reason unknown (-1)"; in ssh_statemachine()
1820 if(rc == -1) { in ssh_statemachine()
1826 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
1836 if((data->set.ssh_auth_types & CURLSSH_AUTH_PASSWORD) && in ssh_statemachine()
1837 (strstr(sshc->authlist, "password") != NULL)) { in ssh_statemachine()
1847 rc = libssh2_userauth_password_ex(sshc->ssh_session, conn->user, in ssh_statemachine()
1848 curlx_uztoui(strlen(conn->user)), in ssh_statemachine()
1849 conn->passwd, in ssh_statemachine()
1850 curlx_uztoui(strlen(conn->passwd)), in ssh_statemachine()
1856 sshc->authed = TRUE; in ssh_statemachine()
1867 if((data->set.ssh_auth_types & CURLSSH_AUTH_HOST) && in ssh_statemachine()
1868 (strstr(sshc->authlist, "hostbased") != NULL)) { in ssh_statemachine()
1882 if((data->set.ssh_auth_types & CURLSSH_AUTH_AGENT) in ssh_statemachine()
1883 && (strstr(sshc->authlist, "publickey") != NULL)) { in ssh_statemachine()
1885 /* Connect to the ssh-agent */ in ssh_statemachine()
1888 if(!sshc->ssh_agent) { in ssh_statemachine()
1889 sshc->ssh_agent = libssh2_agent_init(sshc->ssh_session); in ssh_statemachine()
1890 if(!sshc->ssh_agent) { in ssh_statemachine()
1898 rc = libssh2_agent_connect(sshc->ssh_agent); in ssh_statemachine()
1917 rc = libssh2_agent_list_identities(sshc->ssh_agent); in ssh_statemachine()
1928 sshc->sshagent_prev_identity = NULL; in ssh_statemachine()
1938 rc = libssh2_agent_get_identity(sshc->ssh_agent, in ssh_statemachine()
1939 &sshc->sshagent_identity, in ssh_statemachine()
1940 sshc->sshagent_prev_identity); in ssh_statemachine()
1945 rc = libssh2_agent_userauth(sshc->ssh_agent, conn->user, in ssh_statemachine()
1946 sshc->sshagent_identity); in ssh_statemachine()
1951 sshc->sshagent_prev_identity = sshc->sshagent_identity; in ssh_statemachine()
1963 sshc->authed = TRUE; in ssh_statemachine()
1975 if((data->set.ssh_auth_types & CURLSSH_AUTH_KEYBOARD) in ssh_statemachine()
1976 && (strstr(sshc->authlist, "keyboard-interactive") != NULL)) { in ssh_statemachine()
1985 /* Authentication failed. Continue with keyboard-interactive now. */ in ssh_statemachine()
1986 rc = libssh2_userauth_keyboard_interactive_ex(sshc->ssh_session, in ssh_statemachine()
1987 conn->user, in ssh_statemachine()
1989 strlen(conn->user)), in ssh_statemachine()
1995 sshc->authed = TRUE; in ssh_statemachine()
2002 if(!sshc->authed) { in ssh_statemachine()
2005 sshc->actualcode = CURLE_LOGIN_DENIED; in ssh_statemachine()
2016 conn->sockfd = conn->sock[FIRSTSOCKET]; in ssh_statemachine()
2017 conn->writesockfd = CURL_SOCKET_BAD; in ssh_statemachine()
2019 if(conn->handler->protocol == CURLPROTO_SFTP) { in ssh_statemachine()
2029 * Start the libssh2 sftp session in ssh_statemachine()
2031 sshc->sftp_session = libssh2_sftp_init(sshc->ssh_session); in ssh_statemachine()
2032 if(!sshc->sftp_session) { in ssh_statemachine()
2034 if(libssh2_session_last_errno(sshc->ssh_session) == in ssh_statemachine()
2040 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2044 sshc->actualcode = CURLE_FAILED_INIT; in ssh_statemachine()
2054 rc = sftp_libssh2_realpath(sshc->sftp_session, ".", in ssh_statemachine()
2055 sshp->readdir_filename, CURL_PATH_MAX); in ssh_statemachine()
2061 sshp->readdir_filename[rc] = '\0'; in ssh_statemachine()
2062 sshc->homedir = strdup(sshp->readdir_filename); in ssh_statemachine()
2063 if(!sshc->homedir) { in ssh_statemachine()
2065 sshc->actualcode = CURLE_OUT_OF_MEMORY; in ssh_statemachine()
2068 data->state.most_recent_ftp_entrypath = sshc->homedir; in ssh_statemachine()
2072 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2077 a time-out or similar */ in ssh_statemachine()
2079 sshc->actualcode = result; in ssh_statemachine()
2096 result = Curl_getworkingpath(data, sshc->homedir, &sshp->path); in ssh_statemachine()
2098 sshc->actualcode = result; in ssh_statemachine()
2103 if(data->set.quote) { in ssh_statemachine()
2105 sshc->quote_item = data->set.quote; in ssh_statemachine()
2114 if(data->set.postquote) { in ssh_statemachine()
2116 sshc->quote_item = data->set.postquote; in ssh_statemachine()
2129 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2130 sshc->actualcode = result; in ssh_statemachine()
2135 Curl_safefree(sshc->quote_path1); in ssh_statemachine()
2136 Curl_safefree(sshc->quote_path2); in ssh_statemachine()
2138 sshc->quote_item = sshc->quote_item->next; in ssh_statemachine()
2140 if(sshc->quote_item) { in ssh_statemachine()
2144 if(sshc->nextstate != SSH_NO_STATE) { in ssh_statemachine()
2145 state(data, sshc->nextstate); in ssh_statemachine()
2146 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2158 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2159 sshc->actualcode = result; in ssh_statemachine()
2164 rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshc->quote_path2, in ssh_statemachine()
2165 curlx_uztoui(strlen(sshc->quote_path2)), in ssh_statemachine()
2167 &sshp->quote_attrs); in ssh_statemachine()
2171 if(rc && !sshc->acceptfail) { in ssh_statemachine()
2172 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2173 Curl_safefree(sshc->quote_path1); in ssh_statemachine()
2174 Curl_safefree(sshc->quote_path2); in ssh_statemachine()
2178 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2179 sshc->actualcode = CURLE_QUOTE_ERROR; in ssh_statemachine()
2186 rc = libssh2_sftp_symlink_ex(sshc->sftp_session, sshc->quote_path1, in ssh_statemachine()
2187 curlx_uztoui(strlen(sshc->quote_path1)), in ssh_statemachine()
2188 sshc->quote_path2, in ssh_statemachine()
2189 curlx_uztoui(strlen(sshc->quote_path2)), in ssh_statemachine()
2194 if(rc && !sshc->acceptfail) { in ssh_statemachine()
2195 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2196 Curl_safefree(sshc->quote_path1); in ssh_statemachine()
2197 Curl_safefree(sshc->quote_path2); in ssh_statemachine()
2201 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2202 sshc->actualcode = CURLE_QUOTE_ERROR; in ssh_statemachine()
2209 rc = libssh2_sftp_mkdir_ex(sshc->sftp_session, sshc->quote_path1, in ssh_statemachine()
2210 curlx_uztoui(strlen(sshc->quote_path1)), in ssh_statemachine()
2211 (long)data->set.new_directory_perms); in ssh_statemachine()
2215 if(rc && !sshc->acceptfail) { in ssh_statemachine()
2216 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2217 Curl_safefree(sshc->quote_path1); in ssh_statemachine()
2221 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2222 sshc->actualcode = CURLE_QUOTE_ERROR; in ssh_statemachine()
2229 rc = libssh2_sftp_rename_ex(sshc->sftp_session, sshc->quote_path1, in ssh_statemachine()
2230 curlx_uztoui(strlen(sshc->quote_path1)), in ssh_statemachine()
2231 sshc->quote_path2, in ssh_statemachine()
2232 curlx_uztoui(strlen(sshc->quote_path2)), in ssh_statemachine()
2240 if(rc && !sshc->acceptfail) { in ssh_statemachine()
2241 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2242 Curl_safefree(sshc->quote_path1); in ssh_statemachine()
2243 Curl_safefree(sshc->quote_path2); in ssh_statemachine()
2247 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2248 sshc->actualcode = CURLE_QUOTE_ERROR; in ssh_statemachine()
2255 rc = libssh2_sftp_rmdir_ex(sshc->sftp_session, sshc->quote_path1, in ssh_statemachine()
2256 curlx_uztoui(strlen(sshc->quote_path1))); in ssh_statemachine()
2260 if(rc && !sshc->acceptfail) { in ssh_statemachine()
2261 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2262 Curl_safefree(sshc->quote_path1); in ssh_statemachine()
2266 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2267 sshc->actualcode = CURLE_QUOTE_ERROR; in ssh_statemachine()
2274 rc = libssh2_sftp_unlink_ex(sshc->sftp_session, sshc->quote_path1, in ssh_statemachine()
2275 curlx_uztoui(strlen(sshc->quote_path1))); in ssh_statemachine()
2279 if(rc && !sshc->acceptfail) { in ssh_statemachine()
2280 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2281 Curl_safefree(sshc->quote_path1); in ssh_statemachine()
2284 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2285 sshc->actualcode = CURLE_QUOTE_ERROR; in ssh_statemachine()
2295 rc = libssh2_sftp_statvfs(sshc->sftp_session, sshc->quote_path1, in ssh_statemachine()
2296 curlx_uztoui(strlen(sshc->quote_path1)), in ssh_statemachine()
2302 if(rc && !sshc->acceptfail) { in ssh_statemachine()
2303 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2304 Curl_safefree(sshc->quote_path1); in ssh_statemachine()
2308 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2309 sshc->actualcode = CURLE_QUOTE_ERROR; in ssh_statemachine()
2339 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2347 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2348 sshc->actualcode = result; in ssh_statemachine()
2357 if(data->set.get_filetime) { in ssh_statemachine()
2370 rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshp->path, in ssh_statemachine()
2371 curlx_uztoui(strlen(sshp->path)), in ssh_statemachine()
2377 data->info.filetime = (time_t)attrs.mtime; in ssh_statemachine()
2385 if(data->state.upload) in ssh_statemachine()
2388 if(sshp->path[strlen(sshp->path)-1] == '/') in ssh_statemachine()
2399 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2400 sshc->actualcode = result; in ssh_statemachine()
2405 if(strlen(sshp->path) > 1) { in ssh_statemachine()
2406 sshc->slash_pos = sshp->path + 1; /* ignore the leading '/' */ in ssh_statemachine()
2415 sshc->slash_pos = strchr(sshc->slash_pos, '/'); in ssh_statemachine()
2416 if(sshc->slash_pos) { in ssh_statemachine()
2417 *sshc->slash_pos = 0; in ssh_statemachine()
2419 infof(data, "Creating directory '%s'", sshp->path); in ssh_statemachine()
2427 /* 'mode' - parameter is preliminary - default to 0644 */ in ssh_statemachine()
2428 rc = libssh2_sftp_mkdir_ex(sshc->sftp_session, sshp->path, in ssh_statemachine()
2429 curlx_uztoui(strlen(sshp->path)), in ssh_statemachine()
2430 (long)data->set.new_directory_perms); in ssh_statemachine()
2434 *sshc->slash_pos = '/'; in ssh_statemachine()
2435 ++sshc->slash_pos; in ssh_statemachine()
2440 * path) - retry on unspecific FAILURE also in ssh_statemachine()
2442 unsigned long sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2448 sshc->actualcode = result ? result : CURLE_SSH; in ssh_statemachine()
2457 Curl_pgrsSetDownloadSize(data, -1); in ssh_statemachine()
2458 if(data->req.no_body) { in ssh_statemachine()
2467 sshc->sftp_handle = in ssh_statemachine()
2468 libssh2_sftp_open_ex(sshc->sftp_session, sshp->path, in ssh_statemachine()
2469 curlx_uztoui(strlen(sshp->path)), in ssh_statemachine()
2471 if(!sshc->sftp_handle) { in ssh_statemachine()
2473 if(libssh2_session_last_errno(sshc->ssh_session) == in ssh_statemachine()
2478 sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2483 sshc->actualcode = result ? result : CURLE_SSH; in ssh_statemachine()
2486 Curl_dyn_init(&sshp->readdir, CURL_PATH_MAX * 2); in ssh_statemachine()
2493 sshc->actualcode = result; in ssh_statemachine()
2500 libssh2_sftp_symlink_ex(sshc->sftp_session, in ssh_statemachine()
2501 Curl_dyn_ptr(&sshp->readdir_link), in ssh_statemachine()
2503 Curl_dyn_len(&sshp->readdir_link), in ssh_statemachine()
2504 sshp->readdir_filename, in ssh_statemachine()
2509 Curl_dyn_free(&sshp->readdir_link); in ssh_statemachine()
2512 result = Curl_dyn_addf(&sshp->readdir, " -> %s", sshp->readdir_filename); in ssh_statemachine()
2516 sshc->actualcode = result; in ssh_statemachine()
2524 result = Curl_dyn_addn(&sshp->readdir, "\n", 1); in ssh_statemachine()
2527 Curl_dyn_ptr(&sshp->readdir), in ssh_statemachine()
2528 Curl_dyn_len(&sshp->readdir)); in ssh_statemachine()
2531 Curl_dyn_free(&sshp->readdir); in ssh_statemachine()
2535 Curl_dyn_reset(&sshp->readdir); in ssh_statemachine()
2541 if(libssh2_sftp_closedir(sshc->sftp_handle) == in ssh_statemachine()
2546 sshc->sftp_handle = NULL; in ssh_statemachine()
2557 sshc->sftp_handle = in ssh_statemachine()
2558 libssh2_sftp_open_ex(sshc->sftp_session, sshp->path, in ssh_statemachine()
2559 curlx_uztoui(strlen(sshp->path)), in ssh_statemachine()
2560 LIBSSH2_FXF_READ, (long)data->set.new_file_perms, in ssh_statemachine()
2562 if(!sshc->sftp_handle) { in ssh_statemachine()
2564 if(libssh2_session_last_errno(sshc->ssh_session) == in ssh_statemachine()
2569 sftperr = libssh2_sftp_last_error(sshc->sftp_session); in ssh_statemachine()
2574 sshc->actualcode = result ? result : CURLE_SSH; in ssh_statemachine()
2584 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
2585 sshc->actualcode = result; in ssh_statemachine()
2590 if(sshc->sftp_handle) { in ssh_statemachine()
2591 rc = libssh2_sftp_close(sshc->sftp_handle); in ssh_statemachine()
2597 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2599 infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); in ssh_statemachine()
2601 sshc->sftp_handle = NULL; in ssh_statemachine()
2604 Curl_safefree(sshp->path); in ssh_statemachine()
2611 if(sshc->nextstate != SSH_NO_STATE && in ssh_statemachine()
2612 sshc->nextstate != SSH_SFTP_CLOSE) { in ssh_statemachine()
2613 state(data, sshc->nextstate); in ssh_statemachine()
2614 sshc->nextstate = SSH_SFTP_CLOSE; in ssh_statemachine()
2618 result = sshc->actualcode; in ssh_statemachine()
2627 if(sshc->sftp_handle) { in ssh_statemachine()
2628 rc = libssh2_sftp_close(sshc->sftp_handle); in ssh_statemachine()
2634 (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, in ssh_statemachine()
2636 infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); in ssh_statemachine()
2638 sshc->sftp_handle = NULL; in ssh_statemachine()
2640 if(sshc->sftp_session) { in ssh_statemachine()
2641 rc = libssh2_sftp_shutdown(sshc->sftp_session); in ssh_statemachine()
2646 infof(data, "Failed to stop libssh2 sftp subsystem"); in ssh_statemachine()
2648 sshc->sftp_session = NULL; in ssh_statemachine()
2651 Curl_safefree(sshc->homedir); in ssh_statemachine()
2652 data->state.most_recent_ftp_entrypath = NULL; in ssh_statemachine()
2658 result = Curl_getworkingpath(data, sshc->homedir, &sshp->path); in ssh_statemachine()
2660 sshc->actualcode = result; in ssh_statemachine()
2665 if(data->state.upload) { in ssh_statemachine()
2666 if(data->state.infilesize < 0) { in ssh_statemachine()
2668 sshc->actualcode = CURLE_UPLOAD_FAILED; in ssh_statemachine()
2681 * libssh2 requires that the destination path is a full path that in ssh_statemachine()
2686 sshc->ssh_channel = in ssh_statemachine()
2687 SCP_SEND(sshc->ssh_session, sshp->path, data->set.new_file_perms, in ssh_statemachine()
2688 data->state.infilesize); in ssh_statemachine()
2689 if(!sshc->ssh_channel) { in ssh_statemachine()
2693 if(libssh2_session_last_errno(sshc->ssh_session) == in ssh_statemachine()
2699 ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2703 sshc->actualcode = libssh2_session_error_to_CURLE(ssh_err); in ssh_statemachine()
2705 if(sshc->actualcode == CURLE_SSH || in ssh_statemachine()
2706 sshc->actualcode == CURLE_REMOTE_FILE_NOT_FOUND) in ssh_statemachine()
2707 sshc->actualcode = CURLE_UPLOAD_FAILED; in ssh_statemachine()
2712 data->req.size = data->state.infilesize; in ssh_statemachine()
2713 Curl_pgrsSetUploadSize(data, data->state.infilesize); in ssh_statemachine()
2714 Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE); in ssh_statemachine()
2717 conn->sockfd = conn->writesockfd; in ssh_statemachine()
2721 sshc->actualcode = result; in ssh_statemachine()
2726 sshc->orig_waitfor = data->req.keepon; in ssh_statemachine()
2729 out readable as the underlying libssh2 scp send function will deal in ssh_statemachine()
2730 with both accordingly */ in ssh_statemachine()
2731 data->state.select_bits = CURL_CSELECT_OUT; in ssh_statemachine()
2754 sshc->ssh_channel = libssh2_scp_recv(sshc->ssh_session, in ssh_statemachine()
2755 sshp->path, &sb); in ssh_statemachine()
2759 sshc->ssh_channel = libssh2_scp_recv2(sshc->ssh_session, in ssh_statemachine()
2760 sshp->path, &sb); in ssh_statemachine()
2763 if(!sshc->ssh_channel) { in ssh_statemachine()
2767 if(libssh2_session_last_errno(sshc->ssh_session) == in ssh_statemachine()
2774 ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2778 sshc->actualcode = libssh2_session_error_to_CURLE(ssh_err); in ssh_statemachine()
2784 data->req.maxdownload = (curl_off_t)sb.st_size; in ssh_statemachine()
2788 conn->writesockfd = conn->sockfd; in ssh_statemachine()
2791 out writableable as the underlying libssh2 recv function will deal in ssh_statemachine()
2792 with both accordingly */ in ssh_statemachine()
2793 data->state.select_bits = CURL_CSELECT_IN; in ssh_statemachine()
2797 sshc->actualcode = result; in ssh_statemachine()
2805 if(data->state.upload) in ssh_statemachine()
2812 if(sshc->ssh_channel) { in ssh_statemachine()
2813 rc = libssh2_channel_send_eof(sshc->ssh_channel); in ssh_statemachine()
2819 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2821 infof(data, "Failed to send libssh2 channel EOF: %d %s", in ssh_statemachine()
2829 if(sshc->ssh_channel) { in ssh_statemachine()
2830 rc = libssh2_channel_wait_eof(sshc->ssh_channel); in ssh_statemachine()
2836 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2845 if(sshc->ssh_channel) { in ssh_statemachine()
2846 rc = libssh2_channel_wait_closed(sshc->ssh_channel); in ssh_statemachine()
2852 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2861 if(sshc->ssh_channel) { in ssh_statemachine()
2862 rc = libssh2_channel_free(sshc->ssh_channel); in ssh_statemachine()
2868 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2870 infof(data, "Failed to free libssh2 scp subsystem: %d %s", in ssh_statemachine()
2873 sshc->ssh_channel = NULL; in ssh_statemachine()
2880 result = sshc->actualcode; in ssh_statemachine()
2887 if(sshc->ssh_channel) { in ssh_statemachine()
2888 rc = libssh2_channel_free(sshc->ssh_channel); in ssh_statemachine()
2894 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2896 infof(data, "Failed to free libssh2 scp subsystem: %d %s", in ssh_statemachine()
2899 sshc->ssh_channel = NULL; in ssh_statemachine()
2902 if(sshc->ssh_session) { in ssh_statemachine()
2903 rc = libssh2_session_disconnect(sshc->ssh_session, "Shutdown"); in ssh_statemachine()
2909 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2911 infof(data, "Failed to disconnect libssh2 session: %d %s", in ssh_statemachine()
2916 Curl_safefree(sshc->homedir); in ssh_statemachine()
2917 data->state.most_recent_ftp_entrypath = NULL; in ssh_statemachine()
2924 if(sshc->kh) { in ssh_statemachine()
2925 libssh2_knownhost_free(sshc->kh); in ssh_statemachine()
2926 sshc->kh = NULL; in ssh_statemachine()
2931 if(sshc->ssh_agent) { in ssh_statemachine()
2932 rc = libssh2_agent_disconnect(sshc->ssh_agent); in ssh_statemachine()
2938 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2940 infof(data, "Failed to disconnect from libssh2 agent: %d %s", in ssh_statemachine()
2943 libssh2_agent_free(sshc->ssh_agent); in ssh_statemachine()
2944 sshc->ssh_agent = NULL; in ssh_statemachine()
2948 sshc->sshagent_identity = NULL; in ssh_statemachine()
2949 sshc->sshagent_prev_identity = NULL; in ssh_statemachine()
2953 if(sshc->ssh_session) { in ssh_statemachine()
2954 rc = libssh2_session_free(sshc->ssh_session); in ssh_statemachine()
2960 (void)libssh2_session_last_error(sshc->ssh_session, in ssh_statemachine()
2962 infof(data, "Failed to free libssh2 session: %d %s", rc, err_msg); in ssh_statemachine()
2964 sshc->ssh_session = NULL; in ssh_statemachine()
2967 /* worst-case scenario cleanup */ in ssh_statemachine()
2969 DEBUGASSERT(sshc->ssh_session == NULL); in ssh_statemachine()
2970 DEBUGASSERT(sshc->ssh_channel == NULL); in ssh_statemachine()
2971 DEBUGASSERT(sshc->sftp_session == NULL); in ssh_statemachine()
2972 DEBUGASSERT(sshc->sftp_handle == NULL); in ssh_statemachine()
2974 DEBUGASSERT(sshc->kh == NULL); in ssh_statemachine()
2977 DEBUGASSERT(sshc->ssh_agent == NULL); in ssh_statemachine()
2980 Curl_safefree(sshc->rsa_pub); in ssh_statemachine()
2981 Curl_safefree(sshc->rsa); in ssh_statemachine()
2982 Curl_safefree(sshc->quote_path1); in ssh_statemachine()
2983 Curl_safefree(sshc->quote_path2); in ssh_statemachine()
2984 Curl_safefree(sshc->homedir); in ssh_statemachine()
2987 result = sshc->actualcode; in ssh_statemachine()
2992 sshc->state = SSH_SESSION_FREE; /* current */ in ssh_statemachine()
2993 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
3000 sshc->nextstate = SSH_NO_STATE; in ssh_statemachine()
3005 } while(!rc && (sshc->state != SSH_STOP)); in ssh_statemachine()
3025 sock[0] = conn->sock[FIRSTSOCKET]; in ssh_getsock()
3027 if(conn->waitfor & KEEP_RECV) in ssh_getsock()
3030 if(conn->waitfor & KEEP_SEND) in ssh_getsock()
3037 * When one of the libssh2 functions has returned LIBSSH2_ERROR_EAGAIN this
3045 struct connectdata *conn = data->conn; in ssh_block2waitfor()
3046 struct ssh_conn *sshc = &conn->proto.sshc; in ssh_block2waitfor()
3049 dir = libssh2_session_block_directions(sshc->ssh_session); in ssh_block2waitfor()
3051 /* translate the libssh2 define bits into our own bit defines */ in ssh_block2waitfor()
3052 conn->waitfor = ((dir&LIBSSH2_SESSION_BLOCK_INBOUND) ? KEEP_RECV : 0) | in ssh_block2waitfor()
3057 /* It did not block or libssh2 did not reveal in which direction, put back in ssh_block2waitfor()
3059 conn->waitfor = sshc->orig_waitfor; in ssh_block2waitfor()
3065 struct connectdata *conn = data->conn; in ssh_multi_statemach()
3066 struct ssh_conn *sshc = &conn->proto.sshc; in ssh_multi_statemach()
3072 *done = (sshc->state == SSH_STOP); in ssh_multi_statemach()
3085 struct ssh_conn *sshc = &conn->proto.sshc; in ssh_block_statemach()
3089 while((sshc->state != SSH_STOP) && !result) { in ssh_block_statemach()
3120 int dir = libssh2_session_block_directions(sshc->ssh_session); in ssh_block_statemach()
3121 curl_socket_t sock = conn->sock[FIRSTSOCKET]; in ssh_block_statemach()
3146 data->req.p.ssh = ssh = calloc(1, sizeof(struct SSHPROTO)); in ssh_setup_connection()
3163 struct connectdata *conn = data->conn; in ssh_tls_recv()
3164 Curl_recv *backup = conn->recv[0]; in ssh_tls_recv()
3165 struct ssh_conn *ssh = &conn->proto.sshc; in ssh_tls_recv()
3171 conn->recv[0] = ssh->tls_recv; in ssh_tls_recv()
3173 conn->recv[0] = backup; in ssh_tls_recv()
3175 return -EAGAIN; /* magic return code for libssh2 */ in ssh_tls_recv()
3177 return -1; /* generic error */ in ssh_tls_recv()
3188 struct connectdata *conn = data->conn; in ssh_tls_send()
3189 Curl_send *backup = conn->send[0]; in ssh_tls_send()
3190 struct ssh_conn *ssh = &conn->proto.sshc; in ssh_tls_send()
3196 conn->send[0] = ssh->tls_send; in ssh_tls_send()
3198 conn->send[0] = backup; in ssh_tls_send()
3200 return -EAGAIN; /* magic return code for libssh2 */ in ssh_tls_send()
3202 return -1; /* error */ in ssh_tls_send()
3210 * do protocol-specific actions at connect-time.
3219 struct connectdata *conn = data->conn; in ssh_connect()
3221 /* initialize per-handle data if not already */ in ssh_connect()
3222 if(!data->req.p.ssh) { in ssh_connect()
3232 sshc = &conn->proto.sshc; in ssh_connect()
3235 if(conn->user) { in ssh_connect()
3236 infof(data, "User: %s", conn->user); in ssh_connect()
3238 if(conn->passwd) { in ssh_connect()
3239 infof(data, "Password: %s", conn->passwd); in ssh_connect()
3241 sock = conn->sock[FIRSTSOCKET]; in ssh_connect()
3246 sshc->ssh_session = libssh2_session_init_ex(my_libssh2_malloc, in ssh_connect()
3250 if(!sshc->ssh_session) { in ssh_connect()
3255 /* Set the packet read timeout if the libssh2 version supports it */ in ssh_connect()
3257 if(data->set.server_response_timeout > 0) { in ssh_connect()
3258 libssh2_session_set_read_timeout(sshc->ssh_session, in ssh_connect()
3259 (long)(data->set.server_response_timeout / 1000)); in ssh_connect()
3264 if(conn->http_proxy.proxytype == CURLPROXY_HTTPS) { in ssh_connect()
3266 Setup libssh2 callbacks to make it read/write TLS from the socket. in ssh_connect()
3279 libssh2_session_callback_set2(sshc->ssh_session, in ssh_connect()
3282 libssh2_session_callback_set2(sshc->ssh_session, in ssh_connect()
3289 * libssh2 has such an API... in ssh_connect()
3306 libssh2_session_callback_set(sshc->ssh_session, in ssh_connect()
3308 libssh2_session_callback_set(sshc->ssh_session, in ssh_connect()
3314 sshc->tls_recv = conn->recv[FIRSTSOCKET]; in ssh_connect()
3315 sshc->tls_send = conn->send[FIRSTSOCKET]; in ssh_connect()
3319 if(conn->handler->protocol & CURLPROTO_SCP) { in ssh_connect()
3320 conn->recv[FIRSTSOCKET] = scp_recv; in ssh_connect()
3321 conn->send[FIRSTSOCKET] = scp_send; in ssh_connect()
3324 conn->recv[FIRSTSOCKET] = sftp_recv; in ssh_connect()
3325 conn->send[FIRSTSOCKET] = sftp_send; in ssh_connect()
3328 if(data->set.ssh_compression) { in ssh_connect()
3330 if(libssh2_session_flag(sshc->ssh_session, LIBSSH2_FLAG_COMPRESS, 1) < 0) in ssh_connect()
3336 if(data->set.str[STRING_SSH_KNOWNHOSTS]) { in ssh_connect()
3338 sshc->kh = libssh2_knownhost_init(sshc->ssh_session); in ssh_connect()
3339 if(!sshc->kh) { in ssh_connect()
3340 libssh2_session_free(sshc->ssh_session); in ssh_connect()
3341 sshc->ssh_session = NULL; in ssh_connect()
3346 rc = libssh2_knownhost_readfile(sshc->kh, in ssh_connect()
3347 data->set.str[STRING_SSH_KNOWNHOSTS], in ssh_connect()
3351 data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_connect()
3356 libssh2_trace(sshc->ssh_session, ~0); in ssh_connect()
3390 /* run the state-machine */ in scp_perform()
3393 *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); in scp_perform()
3424 struct connectdata *conn = data->conn; in ssh_do()
3425 struct ssh_conn *sshc = &conn->proto.sshc; in ssh_do()
3429 data->req.size = -1; /* make sure this is unknown at this point */ in ssh_do()
3431 sshc->actualcode = CURLE_OK; /* reset error code */ in ssh_do()
3432 sshc->secondCreateDirs = 0; /* reset the create dir attempt state in ssh_do()
3437 Curl_pgrsSetUploadSize(data, -1); in ssh_do()
3438 Curl_pgrsSetDownloadSize(data, -1); in ssh_do()
3440 if(conn->handler->protocol & CURLPROTO_SCP) in ssh_do()
3456 struct ssh_conn *sshc = &conn->proto.sshc; in scp_disconnect()
3459 if(sshc->ssh_session) { in scp_disconnect()
3473 struct SSHPROTO *sshp = data->req.p.ssh; in ssh_done()
3474 struct connectdata *conn = data->conn; in ssh_done()
3477 /* run the state-machine */ in ssh_done()
3482 Curl_safefree(sshp->path); in ssh_done()
3483 Curl_dyn_free(&sshp->readdir); in ssh_done()
3488 data->req.keepon = 0; /* clear all bits */ in ssh_done()
3509 struct connectdata *conn = data->conn; in scp_send()
3510 struct ssh_conn *sshc = &conn->proto.sshc; in scp_send()
3515 nwrite = (ssize_t) libssh2_channel_write(sshc->ssh_channel, mem, len); in scp_send()
3525 nwrite = -1; in scp_send()
3535 struct connectdata *conn = data->conn; in scp_recv()
3536 struct ssh_conn *sshc = &conn->proto.sshc; in scp_recv()
3540 nread = (ssize_t) libssh2_channel_read(sshc->ssh_channel, mem, len); in scp_recv()
3545 nread = -1; in scp_recv()
3578 /* run the state-machine */ in sftp_perform()
3581 *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); in sftp_perform()
3609 struct ssh_conn *sshc = &conn->proto.sshc; in sftp_disconnect()
3614 if(sshc->ssh_session) { in sftp_disconnect()
3629 struct connectdata *conn = data->conn; in sftp_done()
3630 struct ssh_conn *sshc = &conn->proto.sshc; in sftp_done()
3636 if(!premature && data->set.postquote && !conn->bits.retry) in sftp_done()
3637 sshc->nextstate = SSH_SFTP_POSTQUOTE_INIT; in sftp_done()
3648 struct connectdata *conn = data->conn; in sftp_send()
3649 struct ssh_conn *sshc = &conn->proto.sshc; in sftp_send()
3653 nwrite = libssh2_sftp_write(sshc->sftp_handle, mem, len); in sftp_send()
3663 nwrite = -1; in sftp_send()
3677 struct connectdata *conn = data->conn; in sftp_recv()
3678 struct ssh_conn *sshc = &conn->proto.sshc; in sftp_recv()
3681 nread = libssh2_sftp_read(sshc->sftp_handle, mem, len); in sftp_recv()
3687 nread = -1; in sftp_recv()
3759 return "Unknown error in libssh2"; in sftp_libssh2_strerror()
3782 (void)msnprintf(buffer, buflen, "libssh2/%s", CURL_LIBSSH2_VERSION); in Curl_ssh_version()
3785 /* The SSH session is associated with the *CONNECTION* but the callback user
3793 if(conn->handler->protocol & PROTO_FAMILY_SSH) { in ssh_attach()
3794 struct ssh_conn *sshc = &conn->proto.sshc; in ssh_attach()
3795 if(sshc->ssh_session) { in ssh_attach()
3796 /* only re-attach if the session already exists */ in ssh_attach()
3797 void **abstract = libssh2_session_abstract(sshc->ssh_session); in ssh_attach()