Lines Matching refs:data

100 static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data);
101 static CURLcode ssh_connect(struct Curl_easy *data, bool *done);
102 static CURLcode ssh_multi_statemach(struct Curl_easy *data, bool *done);
103 static CURLcode ssh_do(struct Curl_easy *data, bool *done);
104 static CURLcode scp_done(struct Curl_easy *data, CURLcode c, bool premature);
105 static CURLcode scp_doing(struct Curl_easy *data, bool *dophase_done);
106 static CURLcode scp_disconnect(struct Curl_easy *data,
108 static CURLcode sftp_done(struct Curl_easy *data, CURLcode, bool premature);
109 static CURLcode sftp_doing(struct Curl_easy *data, bool *dophase_done);
110 static CURLcode sftp_disconnect(struct Curl_easy *data,
112 static CURLcode sftp_perform(struct Curl_easy *data, bool *connected,
114 static int ssh_getsock(struct Curl_easy *data, struct connectdata *conn,
116 static CURLcode ssh_setup_connection(struct Curl_easy *data,
118 static void ssh_attach(struct Curl_easy *data, struct connectdata *conn);
186 struct Curl_easy *data = (struct Curl_easy *)*abstract; in kbd_callback() local
201 struct connectdata *conn = data->conn; in kbd_callback()
309 static void state(struct Curl_easy *data, sshstate nowstate) in state() argument
311 struct connectdata *conn = data->conn; in state()
382 infof(data, "SFTP %p state change from %s to %s", in state()
471 static CURLcode ssh_knownhost(struct Curl_easy *data) in ssh_knownhost() argument
479 if(data->set.str[STRING_SSH_KNOWNHOSTS]) { in ssh_knownhost()
481 struct connectdata *conn = data->conn; in ssh_knownhost()
497 data->set.ssh_keyfunc ? data->set.ssh_keyfunc : sshkeycallback; in ssh_knownhost()
530 infof(data, "unsupported key type, cannot check knownhosts"); in ssh_knownhost()
558 infof(data, "SSH host check: %d, key: %s", keycheck, in ssh_knownhost()
583 Curl_set_in_callback(data, TRUE); in ssh_knownhost()
584 rc = func(data, knownkeyp, /* from the knownhosts file */ in ssh_knownhost()
586 keymatch, data->set.ssh_keyfunc_userp); in ssh_knownhost()
587 Curl_set_in_callback(data, FALSE); in ssh_knownhost()
597 state(data, SSH_SESSION_FREE); in ssh_knownhost()
621 infof(data, "WARNING: adding the known host %s failed", in ssh_knownhost()
629 data->set.str[STRING_SSH_KNOWNHOSTS], in ssh_knownhost()
632 infof(data, "WARNING: writing %s failed", in ssh_knownhost()
633 data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_knownhost()
641 (void)data; in ssh_knownhost()
646 static CURLcode ssh_check_fingerprint(struct Curl_easy *data) in ssh_check_fingerprint() argument
648 struct connectdata *conn = data->conn; in ssh_check_fingerprint()
650 const char *pubkey_md5 = data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5]; in ssh_check_fingerprint()
651 const char *pubkey_sha256 = data->set.str[STRING_SSH_HOST_PUBLIC_KEY_SHA256]; in ssh_check_fingerprint()
653 infof(data, "SSH MD5 public key: %s", in ssh_check_fingerprint()
655 infof(data, "SSH SHA256 public key: %s", in ssh_check_fingerprint()
682 failf(data, in ssh_check_fingerprint()
685 state(data, SSH_SESSION_FREE); in ssh_check_fingerprint()
694 state(data, SSH_SESSION_FREE); in ssh_check_fingerprint()
700 failf(data, "sha256 fingerprint could not be encoded"); in ssh_check_fingerprint()
701 state(data, SSH_SESSION_FREE); in ssh_check_fingerprint()
706 infof(data, "SSH SHA256 fingerprint: %s", fingerprint_b64); in ssh_check_fingerprint()
724 failf(data, in ssh_check_fingerprint()
728 state(data, SSH_SESSION_FREE); in ssh_check_fingerprint()
735 infof(data, "SHA256 checksum match"); in ssh_check_fingerprint()
752 infof(data, "SSH MD5 fingerprint: %s", md5buffer); in ssh_check_fingerprint()
759 failf(data, in ssh_check_fingerprint()
764 failf(data, in ssh_check_fingerprint()
768 state(data, SSH_SESSION_FREE); in ssh_check_fingerprint()
772 infof(data, "MD5 checksum match"); in ssh_check_fingerprint()
776 if(data->set.ssh_hostkeyfunc) { in ssh_check_fingerprint()
785 Curl_set_in_callback(data, TRUE); in ssh_check_fingerprint()
786 rc = data->set.ssh_hostkeyfunc(data->set.ssh_hostkeyfunc_userp, in ssh_check_fingerprint()
788 Curl_set_in_callback(data, FALSE); in ssh_check_fingerprint()
790 state(data, SSH_SESSION_FREE); in ssh_check_fingerprint()
796 state(data, SSH_SESSION_FREE); in ssh_check_fingerprint()
803 return ssh_knownhost(data); in ssh_check_fingerprint()
816 static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data) in ssh_force_knownhost_key_type() argument
846 struct connectdata *conn = data->conn; in ssh_force_knownhost_key_type()
854 if(sshc->kh && !data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5]) { in ssh_force_knownhost_key_type()
864 infof(data, "Invalid host pattern %s in %s", in ssh_force_knownhost_key_type()
865 store->name, data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_force_knownhost_key_type()
892 infof(data, "Found host %s in %s", in ssh_force_knownhost_key_type()
893 conn->host.name, data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_force_knownhost_key_type()
932 failf(data, "Found host key type RSA1 which is not supported"); in ssh_force_knownhost_key_type()
935 failf(data, "Unknown host key type: %i", in ssh_force_knownhost_key_type()
940 infof(data, "Set \"%s\" as SSH hostkey type", hostkey_method); in ssh_force_knownhost_key_type()
947 failf(data, "libssh2: %s", errmsg); in ssh_force_knownhost_key_type()
952 infof(data, "Did not find host %s in %s", in ssh_force_knownhost_key_type()
953 conn->host.name, data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_force_knownhost_key_type()
962 static CURLcode sftp_quote(struct Curl_easy *data, in sftp_quote() argument
975 char *cmd = sshc->quote_item->data; in sftp_quote()
993 Curl_debug(data, CURLINFO_HEADER_OUT, (char *)"PWD\n", 4); in sftp_quote()
994 Curl_debug(data, CURLINFO_HEADER_IN, tmp, strlen(tmp)); in sftp_quote()
999 result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); in sftp_quote()
1002 state(data, SSH_SFTP_NEXT_QUOTE); in sftp_quote()
1012 failf(data, "Syntax error command '%s', missing parameter", cmd); in sftp_quote()
1023 failf(data, "Syntax error: Bad first parameter to '%s'", cmd); in sftp_quote()
1044 failf(data, "Syntax error in %s: Bad second parameter", cmd); in sftp_quote()
1049 state(data, SSH_SFTP_QUOTE_STAT); in sftp_quote()
1060 failf(data, "Syntax error in ln/symlink: Bad second parameter"); in sftp_quote()
1064 state(data, SSH_SFTP_QUOTE_SYMLINK); in sftp_quote()
1069 state(data, SSH_SFTP_QUOTE_MKDIR); in sftp_quote()
1079 failf(data, "Syntax error in rename: Bad second parameter"); in sftp_quote()
1083 state(data, SSH_SFTP_QUOTE_RENAME); in sftp_quote()
1088 state(data, SSH_SFTP_QUOTE_RMDIR); in sftp_quote()
1092 state(data, SSH_SFTP_QUOTE_UNLINK); in sftp_quote()
1097 state(data, SSH_SFTP_QUOTE_STATVFS); in sftp_quote()
1102 failf(data, "Unknown SFTP command"); in sftp_quote()
1109 sftp_upload_init(struct Curl_easy *data, in sftp_upload_init() argument
1123 if(data->state.resume_from) { in sftp_upload_init()
1125 if(data->state.resume_from < 0) { in sftp_upload_init()
1134 data->state.resume_from = 0; in sftp_upload_init()
1139 failf(data, "Bad file size (%" FMT_OFF_T ")", size); in sftp_upload_init()
1142 data->state.resume_from = attrs.filesize; in sftp_upload_init()
1147 if(data->set.remote_append) in sftp_upload_init()
1150 else if(data->state.resume_from > 0) in sftp_upload_init()
1160 flags, (long)data->set.new_file_perms, in sftp_upload_init()
1180 state(data, SSH_SFTP_CLOSE); in sftp_upload_init()
1183 failf(data, "Creating the dir/file failed: %s", in sftp_upload_init()
1190 (data->set.ftp_create_missing_dirs && in sftp_upload_init()
1194 state(data, SSH_SFTP_CREATE_DIRS_INIT); in sftp_upload_init()
1197 state(data, SSH_SFTP_CLOSE); in sftp_upload_init()
1207 failf(data, "Upload failed: %s (%lu/%d)", in sftp_upload_init()
1216 if(data->state.resume_from > 0) { in sftp_upload_init()
1219 if(data->set.seek_func) { in sftp_upload_init()
1220 Curl_set_in_callback(data, TRUE); in sftp_upload_init()
1221 seekerr = data->set.seek_func(data->set.seek_client, in sftp_upload_init()
1222 data->state.resume_from, SEEK_SET); in sftp_upload_init()
1223 Curl_set_in_callback(data, FALSE); in sftp_upload_init()
1230 failf(data, "Could not seek stream"); in sftp_upload_init()
1237 (data->state.resume_from - passed > in sftp_upload_init()
1239 sizeof(scratch) : curlx_sotouz(data->state.resume_from - passed); in sftp_upload_init()
1242 Curl_set_in_callback(data, TRUE); in sftp_upload_init()
1243 actuallyread = data->state.fread_func(scratch, 1, in sftp_upload_init()
1245 data->state.in); in sftp_upload_init()
1246 Curl_set_in_callback(data, FALSE); in sftp_upload_init()
1252 failf(data, "Failed to read data"); in sftp_upload_init()
1255 } while(passed < data->state.resume_from); in sftp_upload_init()
1259 if(data->state.infilesize > 0) { in sftp_upload_init()
1260 data->state.infilesize -= data->state.resume_from; in sftp_upload_init()
1261 data->req.size = data->state.infilesize; in sftp_upload_init()
1262 Curl_pgrsSetUploadSize(data, data->state.infilesize); in sftp_upload_init()
1265 SFTP_SEEK(sshc->sftp_handle, data->state.resume_from); in sftp_upload_init()
1267 if(data->state.infilesize > 0) { in sftp_upload_init()
1268 data->req.size = data->state.infilesize; in sftp_upload_init()
1269 Curl_pgrsSetUploadSize(data, data->state.infilesize); in sftp_upload_init()
1272 Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE); in sftp_upload_init()
1275 data->conn->sockfd = data->conn->writesockfd; in sftp_upload_init()
1279 sshc->orig_waitfor = data->req.keepon; in sftp_upload_init()
1284 data->state.select_bits = CURL_CSELECT_OUT; in sftp_upload_init()
1289 Curl_expire(data, 0, EXPIRE_RUN_NOW); in sftp_upload_init()
1291 state(data, SSH_STOP); in sftp_upload_init()
1296 sftp_pkey_init(struct Curl_easy *data, in sftp_pkey_init() argument
1305 if((data->set.ssh_auth_types & CURLSSH_AUTH_PUBLICKEY) && in sftp_pkey_init()
1311 if(data->set.str[STRING_SSH_PRIVATE_KEY]) in sftp_pkey_init()
1312 sshc->rsa = strdup(data->set.str[STRING_SSH_PRIVATE_KEY]); in sftp_pkey_init()
1357 if(data->set.str[STRING_SSH_PUBLIC_KEY] in sftp_pkey_init()
1359 && data->set.str[STRING_SSH_PUBLIC_KEY][0]) { in sftp_pkey_init()
1360 sshc->rsa_pub = strdup(data->set.str[STRING_SSH_PUBLIC_KEY]); in sftp_pkey_init()
1368 state(data, SSH_SESSION_FREE); in sftp_pkey_init()
1373 sshc->passphrase = data->set.ssl.key_passwd; in sftp_pkey_init()
1378 infof(data, "Using SSH public key file '%s'", sshc->rsa_pub); in sftp_pkey_init()
1379 infof(data, "Using SSH private key file '%s'", sshc->rsa); in sftp_pkey_init()
1381 state(data, SSH_AUTH_PKEY); in sftp_pkey_init()
1384 state(data, SSH_AUTH_PASS_INIT); in sftp_pkey_init()
1390 sftp_quote_stat(struct Curl_easy *data, in sftp_quote_stat() argument
1395 char *cmd = sshc->quote_item->data; in sftp_quote_stat()
1423 failf(data, "Attempt to get SFTP stats failed: %s", in sftp_quote_stat()
1435 failf(data, "Syntax error: chgrp gid not a number"); in sftp_quote_stat()
1445 failf(data, "Syntax error: chmod permissions not a number"); in sftp_quote_stat()
1454 failf(data, "Syntax error: chown uid not a number"); in sftp_quote_stat()
1464 failf(data, "incorrect date format for %.*s", 5, cmd); in sftp_quote_stat()
1470 failf(data, "date overflow"); in sftp_quote_stat()
1485 state(data, SSH_SFTP_QUOTE_SETSTAT); in sftp_quote_stat()
1494 sftp_download_stat(struct Curl_easy *data, in sftp_download_stat() argument
1516 data->req.size = -1; in sftp_download_stat()
1517 data->req.maxdownload = -1; in sftp_download_stat()
1518 Curl_pgrsSetDownloadSize(data, -1); in sftp_download_stat()
1524 failf(data, "Bad file size (%" FMT_OFF_T ")", size); in sftp_download_stat()
1527 if(data->state.use_range) { in sftp_download_stat()
1534 from_t = curlx_strtoofft(data->state.range, &ptr, 10, &from); in sftp_download_stat()
1552 failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%" in sftp_download_stat()
1568 data->req.size = size; in sftp_download_stat()
1569 data->req.maxdownload = size; in sftp_download_stat()
1570 Curl_pgrsSetDownloadSize(data, size); in sftp_download_stat()
1574 if(data->state.resume_from) { in sftp_download_stat()
1575 if(data->state.resume_from < 0) { in sftp_download_stat()
1577 if((curl_off_t)attrs.filesize < -data->state.resume_from) { in sftp_download_stat()
1578 failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%" in sftp_download_stat()
1580 data->state.resume_from, (curl_off_t)attrs.filesize); in sftp_download_stat()
1584 data->state.resume_from += attrs.filesize; in sftp_download_stat()
1587 if((curl_off_t)attrs.filesize < data->state.resume_from) { in sftp_download_stat()
1588 failf(data, "Offset (%" FMT_OFF_T in sftp_download_stat()
1590 data->state.resume_from, (curl_off_t)attrs.filesize); in sftp_download_stat()
1595 data->req.size = attrs.filesize - data->state.resume_from; in sftp_download_stat()
1596 data->req.maxdownload = attrs.filesize - data->state.resume_from; in sftp_download_stat()
1597 Curl_pgrsSetDownloadSize(data, in sftp_download_stat()
1598 attrs.filesize - data->state.resume_from); in sftp_download_stat()
1599 SFTP_SEEK(sshc->sftp_handle, data->state.resume_from); in sftp_download_stat()
1603 if(data->req.size == 0) { in sftp_download_stat()
1605 Curl_xfer_setup_nop(data); in sftp_download_stat()
1606 infof(data, "File already completely downloaded"); in sftp_download_stat()
1607 state(data, SSH_STOP); in sftp_download_stat()
1610 Curl_xfer_setup1(data, CURL_XFER_RECV, data->req.size, FALSE); in sftp_download_stat()
1613 data->conn->writesockfd = data->conn->sockfd; in sftp_download_stat()
1618 data->state.select_bits = CURL_CSELECT_IN; in sftp_download_stat()
1619 state(data, SSH_STOP); in sftp_download_stat()
1624 static CURLcode sftp_readdir(struct Curl_easy *data, in sftp_readdir() argument
1642 if(data->set.list_only) { in sftp_readdir()
1643 result = Curl_client_write(data, CLIENTWRITE_BODY, in sftp_readdir()
1647 result = Curl_client_write(data, CLIENTWRITE_BODY, in sftp_readdir()
1662 state(data, SSH_SFTP_READDIR_LINK); in sftp_readdir()
1665 state(data, SSH_SFTP_READDIR_BOTTOM); in sftp_readdir()
1672 state(data, SSH_SFTP_READDIR_DONE); in sftp_readdir()
1678 failf(data, "Could not open remote file for reading: %s :: %d", in sftp_readdir()
1681 state(data, SSH_SFTP_CLOSE); in sftp_readdir()
1692 static CURLcode ssh_statemachine(struct Curl_easy *data, bool *block) in ssh_statemachine() argument
1695 struct connectdata *conn = data->conn; in ssh_statemachine()
1696 struct SSHPROTO *sshp = data->req.p.ssh; in ssh_statemachine()
1713 result = ssh_force_knownhost_key_type(data); in ssh_statemachine()
1715 state(data, SSH_SESSION_FREE); in ssh_statemachine()
1720 state(data, SSH_S_STARTUP); in ssh_statemachine()
1731 failf(data, "Failure establishing ssh session: %d, %s", rc, err_msg); in ssh_statemachine()
1733 state(data, SSH_SESSION_FREE); in ssh_statemachine()
1738 state(data, SSH_HOSTKEY); in ssh_statemachine()
1747 result = ssh_check_fingerprint(data); in ssh_statemachine()
1749 state(data, SSH_AUTHLIST); in ssh_statemachine()
1771 infof(data, "SSH user accepted with no authentication"); in ssh_statemachine()
1772 state(data, SSH_AUTH_DONE); in ssh_statemachine()
1779 state(data, SSH_SESSION_FREE); in ssh_statemachine()
1784 infof(data, "SSH authentication methods available: %s", in ssh_statemachine()
1787 state(data, SSH_AUTH_PKEY_INIT); in ssh_statemachine()
1791 result = sftp_pkey_init(data, sshc); in ssh_statemachine()
1812 infof(data, "Initialized SSH public key authentication"); in ssh_statemachine()
1813 state(data, SSH_AUTH_DONE); in ssh_statemachine()
1827 infof(data, "SSH public key authentication failed: %s", err_msg); in ssh_statemachine()
1828 state(data, SSH_AUTH_PASS_INIT); in ssh_statemachine()
1834 if((data->set.ssh_auth_types & CURLSSH_AUTH_PASSWORD) && in ssh_statemachine()
1836 state(data, SSH_AUTH_PASS); in ssh_statemachine()
1839 state(data, SSH_AUTH_HOST_INIT); in ssh_statemachine()
1855 infof(data, "Initialized password authentication"); in ssh_statemachine()
1856 state(data, SSH_AUTH_DONE); in ssh_statemachine()
1859 state(data, SSH_AUTH_HOST_INIT); in ssh_statemachine()
1865 if((data->set.ssh_auth_types & CURLSSH_AUTH_HOST) && in ssh_statemachine()
1867 state(data, SSH_AUTH_HOST); in ssh_statemachine()
1870 state(data, SSH_AUTH_AGENT_INIT); in ssh_statemachine()
1875 state(data, SSH_AUTH_AGENT_INIT); in ssh_statemachine()
1880 if((data->set.ssh_auth_types & CURLSSH_AUTH_AGENT) in ssh_statemachine()
1889 infof(data, "Could not create agent object"); in ssh_statemachine()
1891 state(data, SSH_AUTH_KEY_INIT); in ssh_statemachine()
1900 infof(data, "Failure connecting to agent"); in ssh_statemachine()
1901 state(data, SSH_AUTH_KEY_INIT); in ssh_statemachine()
1905 state(data, SSH_AUTH_AGENT_LIST); in ssh_statemachine()
1910 state(data, SSH_AUTH_KEY_INIT); in ssh_statemachine()
1920 infof(data, "Failure requesting identities to agent"); in ssh_statemachine()
1921 state(data, SSH_AUTH_KEY_INIT); in ssh_statemachine()
1925 state(data, SSH_AUTH_AGENT); in ssh_statemachine()
1956 infof(data, "Failure requesting identities to agent"); in ssh_statemachine()
1958 infof(data, "No identity would match"); in ssh_statemachine()
1962 infof(data, "Agent based authentication successful"); in ssh_statemachine()
1963 state(data, SSH_AUTH_DONE); in ssh_statemachine()
1966 state(data, SSH_AUTH_KEY_INIT); in ssh_statemachine()
1973 if((data->set.ssh_auth_types & CURLSSH_AUTH_KEYBOARD) in ssh_statemachine()
1975 state(data, SSH_AUTH_KEY); in ssh_statemachine()
1978 state(data, SSH_AUTH_DONE); in ssh_statemachine()
1994 infof(data, "Initialized keyboard interactive authentication"); in ssh_statemachine()
1996 state(data, SSH_AUTH_DONE); in ssh_statemachine()
2001 failf(data, "Authentication failure"); in ssh_statemachine()
2002 state(data, SSH_SESSION_FREE); in ssh_statemachine()
2010 infof(data, "Authentication complete"); in ssh_statemachine()
2012 Curl_pgrsTime(data, TIMER_APPCONNECT); /* SSH is connected */ in ssh_statemachine()
2018 state(data, SSH_SFTP_INIT); in ssh_statemachine()
2021 infof(data, "SSH CONNECT phase done"); in ssh_statemachine()
2022 state(data, SSH_STOP); in ssh_statemachine()
2040 failf(data, "Failure initializing sftp session: %s", err_msg); in ssh_statemachine()
2041 state(data, SSH_SESSION_FREE); in ssh_statemachine()
2045 state(data, SSH_SFTP_REALPATH); in ssh_statemachine()
2062 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2066 data->state.most_recent_ftp_entrypath = sshc->homedir; in ssh_statemachine()
2078 DEBUGF(infof(data, "error = %lu makes libcurl = %d", in ssh_statemachine()
2080 state(data, SSH_STOP); in ssh_statemachine()
2088 DEBUGF(infof(data, "SSH CONNECT phase done")); in ssh_statemachine()
2089 state(data, SSH_STOP); in ssh_statemachine()
2094 result = Curl_getworkingpath(data, sshc->homedir, &sshp->path); in ssh_statemachine()
2097 state(data, SSH_STOP); in ssh_statemachine()
2101 if(data->set.quote) { in ssh_statemachine()
2102 infof(data, "Sending quote commands"); in ssh_statemachine()
2103 sshc->quote_item = data->set.quote; in ssh_statemachine()
2104 state(data, SSH_SFTP_QUOTE); in ssh_statemachine()
2107 state(data, SSH_SFTP_GETINFO); in ssh_statemachine()
2112 if(data->set.postquote) { in ssh_statemachine()
2113 infof(data, "Sending quote commands"); in ssh_statemachine()
2114 sshc->quote_item = data->set.postquote; in ssh_statemachine()
2115 state(data, SSH_SFTP_QUOTE); in ssh_statemachine()
2118 state(data, SSH_STOP); in ssh_statemachine()
2124 result = sftp_quote(data, sshc, sshp); in ssh_statemachine()
2126 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2139 state(data, SSH_SFTP_QUOTE); in ssh_statemachine()
2143 state(data, sshc->nextstate); in ssh_statemachine()
2147 state(data, SSH_SFTP_GETINFO); in ssh_statemachine()
2153 result = sftp_quote_stat(data, sshc, sshp, block); in ssh_statemachine()
2155 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2173 failf(data, "Attempt to set SFTP stats failed: %s", in ssh_statemachine()
2175 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2180 state(data, SSH_SFTP_NEXT_QUOTE); in ssh_statemachine()
2196 failf(data, "symlink command failed: %s", in ssh_statemachine()
2198 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2203 state(data, SSH_SFTP_NEXT_QUOTE); in ssh_statemachine()
2209 (long)data->set.new_directory_perms); in ssh_statemachine()
2216 failf(data, "mkdir command failed: %s", in ssh_statemachine()
2218 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2223 state(data, SSH_SFTP_NEXT_QUOTE); in ssh_statemachine()
2242 failf(data, "rename command failed: %s", in ssh_statemachine()
2244 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2249 state(data, SSH_SFTP_NEXT_QUOTE); in ssh_statemachine()
2261 failf(data, "rmdir command failed: %s", in ssh_statemachine()
2263 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2268 state(data, SSH_SFTP_NEXT_QUOTE); in ssh_statemachine()
2280 failf(data, "rm command failed: %s", sftp_libssh2_strerror(sftperr)); in ssh_statemachine()
2281 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2286 state(data, SSH_SFTP_NEXT_QUOTE); in ssh_statemachine()
2303 failf(data, "statvfs command failed: %s", in ssh_statemachine()
2305 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2336 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2341 result = Curl_client_write(data, CLIENTWRITE_HEADER, tmp, strlen(tmp)); in ssh_statemachine()
2344 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2349 state(data, SSH_SFTP_NEXT_QUOTE); in ssh_statemachine()
2355 if(data->set.get_filetime) { in ssh_statemachine()
2356 state(data, SSH_SFTP_FILETIME); in ssh_statemachine()
2359 state(data, SSH_SFTP_TRANS_INIT); in ssh_statemachine()
2375 data->info.filetime = (time_t)attrs.mtime; in ssh_statemachine()
2378 state(data, SSH_SFTP_TRANS_INIT); in ssh_statemachine()
2383 if(data->state.upload) in ssh_statemachine()
2384 state(data, SSH_SFTP_UPLOAD_INIT); in ssh_statemachine()
2387 state(data, SSH_SFTP_READDIR_INIT); in ssh_statemachine()
2389 state(data, SSH_SFTP_DOWNLOAD_INIT); in ssh_statemachine()
2394 result = sftp_upload_init(data, sshc, sshp, block); in ssh_statemachine()
2396 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2405 state(data, SSH_SFTP_CREATE_DIRS); in ssh_statemachine()
2408 state(data, SSH_SFTP_UPLOAD_INIT); in ssh_statemachine()
2417 infof(data, "Creating directory '%s'", sshp->path); in ssh_statemachine()
2418 state(data, SSH_SFTP_CREATE_DIRS_MKDIR); in ssh_statemachine()
2421 state(data, SSH_SFTP_UPLOAD_INIT); in ssh_statemachine()
2428 (long)data->set.new_directory_perms); in ssh_statemachine()
2445 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2451 state(data, SSH_SFTP_CREATE_DIRS); in ssh_statemachine()
2455 Curl_pgrsSetDownloadSize(data, -1); in ssh_statemachine()
2456 if(data->req.no_body) { in ssh_statemachine()
2457 state(data, SSH_STOP); in ssh_statemachine()
2477 failf(data, "Could not open directory for reading: %s", in ssh_statemachine()
2479 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2485 state(data, SSH_SFTP_READDIR); in ssh_statemachine()
2489 result = sftp_readdir(data, sshc, sshp, block); in ssh_statemachine()
2492 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2513 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2518 state(data, SSH_SFTP_READDIR_BOTTOM); in ssh_statemachine()
2524 result = Curl_client_write(data, CLIENTWRITE_BODY, in ssh_statemachine()
2530 state(data, SSH_STOP); in ssh_statemachine()
2534 state(data, SSH_SFTP_READDIR); in ssh_statemachine()
2547 Curl_xfer_setup_nop(data); in ssh_statemachine()
2548 state(data, SSH_STOP); in ssh_statemachine()
2558 LIBSSH2_FXF_READ, (long)data->set.new_file_perms, in ssh_statemachine()
2568 failf(data, "Could not open remote file for reading: %s", in ssh_statemachine()
2570 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2575 state(data, SSH_SFTP_DOWNLOAD_STAT); in ssh_statemachine()
2579 result = sftp_download_stat(data, sshc, sshp, block); in ssh_statemachine()
2581 state(data, SSH_SFTP_CLOSE); in ssh_statemachine()
2597 infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); in ssh_statemachine()
2604 DEBUGF(infof(data, "SFTP DONE done")); in ssh_statemachine()
2611 state(data, sshc->nextstate); in ssh_statemachine()
2615 state(data, SSH_STOP); in ssh_statemachine()
2634 infof(data, "Failed to close libssh2 file: %d %s", rc, err_msg); in ssh_statemachine()
2644 infof(data, "Failed to stop libssh2 sftp subsystem"); in ssh_statemachine()
2650 data->state.most_recent_ftp_entrypath = NULL; in ssh_statemachine()
2652 state(data, SSH_SESSION_DISCONNECT); in ssh_statemachine()
2656 result = Curl_getworkingpath(data, sshc->homedir, &sshp->path); in ssh_statemachine()
2659 state(data, SSH_STOP); in ssh_statemachine()
2663 if(data->state.upload) { in ssh_statemachine()
2664 if(data->state.infilesize < 0) { in ssh_statemachine()
2665 failf(data, "SCP requires a known file size for upload"); in ssh_statemachine()
2667 state(data, SSH_SCP_CHANNEL_FREE); in ssh_statemachine()
2670 state(data, SSH_SCP_UPLOAD_INIT); in ssh_statemachine()
2673 state(data, SSH_SCP_DOWNLOAD_INIT); in ssh_statemachine()
2685 SCP_SEND(sshc->ssh_session, sshp->path, data->set.new_file_perms, in ssh_statemachine()
2686 data->state.infilesize); in ssh_statemachine()
2699 failf(data, "%s", err_msg); in ssh_statemachine()
2700 state(data, SSH_SCP_CHANNEL_FREE); in ssh_statemachine()
2710 data->req.size = data->state.infilesize; in ssh_statemachine()
2711 Curl_pgrsSetUploadSize(data, data->state.infilesize); in ssh_statemachine()
2712 Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE); in ssh_statemachine()
2718 state(data, SSH_SCP_CHANNEL_FREE); in ssh_statemachine()
2724 sshc->orig_waitfor = data->req.keepon; in ssh_statemachine()
2729 data->state.select_bits = CURL_CSELECT_OUT; in ssh_statemachine()
2731 state(data, SSH_STOP); in ssh_statemachine()
2774 failf(data, "%s", err_msg); in ssh_statemachine()
2775 state(data, SSH_SCP_CHANNEL_FREE); in ssh_statemachine()
2782 data->req.maxdownload = (curl_off_t)sb.st_size; in ssh_statemachine()
2783 Curl_xfer_setup1(data, CURL_XFER_RECV, bytecount, FALSE); in ssh_statemachine()
2791 data->state.select_bits = CURL_CSELECT_IN; in ssh_statemachine()
2794 state(data, SSH_SCP_CHANNEL_FREE); in ssh_statemachine()
2798 state(data, SSH_STOP); in ssh_statemachine()
2803 if(data->state.upload) in ssh_statemachine()
2804 state(data, SSH_SCP_SEND_EOF); in ssh_statemachine()
2806 state(data, SSH_SCP_CHANNEL_FREE); in ssh_statemachine()
2819 infof(data, "Failed to send libssh2 channel EOF: %d %s", in ssh_statemachine()
2823 state(data, SSH_SCP_WAIT_EOF); in ssh_statemachine()
2836 infof(data, "Failed to get channel EOF: %d %s", rc, err_msg); in ssh_statemachine()
2839 state(data, SSH_SCP_WAIT_CLOSE); in ssh_statemachine()
2852 infof(data, "Channel failed to close: %d %s", rc, err_msg); in ssh_statemachine()
2855 state(data, SSH_SCP_CHANNEL_FREE); in ssh_statemachine()
2868 infof(data, "Failed to free libssh2 scp subsystem: %d %s", in ssh_statemachine()
2873 DEBUGF(infof(data, "SCP DONE phase complete")); in ssh_statemachine()
2875 state(data, SSH_SESSION_DISCONNECT); in ssh_statemachine()
2877 state(data, SSH_STOP); in ssh_statemachine()
2894 infof(data, "Failed to free libssh2 scp subsystem: %d %s", in ssh_statemachine()
2909 infof(data, "Failed to disconnect libssh2 session: %d %s", in ssh_statemachine()
2915 data->state.most_recent_ftp_entrypath = NULL; in ssh_statemachine()
2917 state(data, SSH_SESSION_FREE); in ssh_statemachine()
2938 infof(data, "Failed to disconnect from libssh2 agent: %d %s", in ssh_statemachine()
2960 infof(data, "Failed to free libssh2 session: %d %s", rc, err_msg); in ssh_statemachine()
2992 state(data, SSH_STOP); in ssh_statemachine()
2999 state(data, SSH_STOP); in ssh_statemachine()
3016 static int ssh_getsock(struct Curl_easy *data, in ssh_getsock() argument
3021 (void)data; in ssh_getsock()
3041 static void ssh_block2waitfor(struct Curl_easy *data, bool block) in ssh_block2waitfor() argument
3043 struct connectdata *conn = data->conn; in ssh_block2waitfor()
3061 static CURLcode ssh_multi_statemach(struct Curl_easy *data, bool *done) in ssh_multi_statemach() argument
3063 struct connectdata *conn = data->conn; in ssh_multi_statemach()
3069 result = ssh_statemachine(data, &block); in ssh_multi_statemach()
3074 ssh_block2waitfor(data, block); in ssh_multi_statemach()
3079 static CURLcode ssh_block_statemach(struct Curl_easy *data, in ssh_block_statemach() argument
3092 result = ssh_statemachine(data, &block); in ssh_block_statemach()
3097 if(Curl_pgrsUpdate(data)) in ssh_block_statemach()
3100 result = Curl_speedcheck(data, now); in ssh_block_statemach()
3104 left = Curl_timeleft(data, NULL, FALSE); in ssh_block_statemach()
3106 failf(data, "Operation timed out"); in ssh_block_statemach()
3112 failf(data, "Disconnect timed out"); in ssh_block_statemach()
3138 static CURLcode ssh_setup_connection(struct Curl_easy *data, in ssh_setup_connection() argument
3144 data->req.p.ssh = ssh = calloc(1, sizeof(struct SSHPROTO)); in ssh_setup_connection()
3158 struct Curl_easy *data = (struct Curl_easy *)*abstract; in ssh_tls_recv() local
3161 struct connectdata *conn = data->conn; in ssh_tls_recv()
3164 int socknum = Curl_conn_sockindex(data, sock); in ssh_tls_recv()
3170 result = Curl_conn_recv(data, socknum, buffer, length, &nread); in ssh_tls_recv()
3176 Curl_debug(data, CURLINFO_DATA_IN, (char *)buffer, (size_t)nread); in ssh_tls_recv()
3183 struct Curl_easy *data = (struct Curl_easy *)*abstract; in ssh_tls_send() local
3186 struct connectdata *conn = data->conn; in ssh_tls_send()
3189 int socknum = Curl_conn_sockindex(data, sock); in ssh_tls_send()
3195 result = Curl_conn_send(data, socknum, buffer, length, FALSE, &nwrite); in ssh_tls_send()
3201 Curl_debug(data, CURLINFO_DATA_OUT, (char *)buffer, nwrite); in ssh_tls_send()
3210 static CURLcode ssh_connect(struct Curl_easy *data, bool *done) in ssh_connect() argument
3217 struct connectdata *conn = data->conn; in ssh_connect()
3220 if(!data->req.p.ssh) { in ssh_connect()
3221 result = ssh_setup_connection(data, conn); in ssh_connect()
3234 infof(data, "User: %s", conn->user); in ssh_connect()
3237 infof(data, "Password: %s", conn->passwd); in ssh_connect()
3246 my_libssh2_realloc, data); in ssh_connect()
3249 failf(data, "Failure initialising ssh session"); in ssh_connect()
3255 if(data->set.server_response_timeout > 0) { in ssh_connect()
3257 (long)(data->set.server_response_timeout / 1000)); in ssh_connect()
3276 infof(data, "Uses HTTPS proxy"); in ssh_connect()
3303 infof(data, "Uses HTTPS proxy"); in ssh_connect()
3326 if(data->set.ssh_compression) { in ssh_connect()
3330 infof(data, "Failed to enable compression for ssh session"); in ssh_connect()
3334 if(data->set.str[STRING_SSH_KNOWNHOSTS]) { in ssh_connect()
3345 data->set.str[STRING_SSH_KNOWNHOSTS], in ssh_connect()
3348 infof(data, "Failed to read known hosts from %s", in ssh_connect()
3349 data->set.str[STRING_SSH_KNOWNHOSTS]); in ssh_connect()
3355 infof(data, "SSH socket: %d", (int)sock); in ssh_connect()
3358 state(data, SSH_INIT); in ssh_connect()
3360 result = ssh_multi_statemach(data, done); in ssh_connect()
3375 CURLcode scp_perform(struct Curl_easy *data, in scp_perform() argument
3381 DEBUGF(infof(data, "DO phase starts")); in scp_perform()
3386 state(data, SSH_SCP_TRANS_INIT); in scp_perform()
3389 result = ssh_multi_statemach(data, dophase_done); in scp_perform()
3391 *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); in scp_perform()
3394 DEBUGF(infof(data, "DO phase is complete")); in scp_perform()
3401 static CURLcode scp_doing(struct Curl_easy *data, in scp_doing() argument
3405 result = ssh_multi_statemach(data, dophase_done); in scp_doing()
3408 DEBUGF(infof(data, "DO phase is complete")); in scp_doing()
3418 static CURLcode ssh_do(struct Curl_easy *data, bool *done) in ssh_do() argument
3422 struct connectdata *conn = data->conn; in ssh_do()
3427 data->req.size = -1; /* make sure this is unknown at this point */ in ssh_do()
3433 Curl_pgrsSetUploadCounter(data, 0); in ssh_do()
3434 Curl_pgrsSetDownloadCounter(data, 0); in ssh_do()
3435 Curl_pgrsSetUploadSize(data, -1); in ssh_do()
3436 Curl_pgrsSetDownloadSize(data, -1); in ssh_do()
3439 result = scp_perform(data, &connected, done); in ssh_do()
3441 result = sftp_perform(data, &connected, done); in ssh_do()
3449 static CURLcode scp_disconnect(struct Curl_easy *data, in scp_disconnect() argument
3459 state(data, SSH_SESSION_DISCONNECT); in scp_disconnect()
3460 result = ssh_block_statemach(data, conn, TRUE); in scp_disconnect()
3468 static CURLcode ssh_done(struct Curl_easy *data, CURLcode status) in ssh_done() argument
3471 struct SSHPROTO *sshp = data->req.p.ssh; in ssh_done()
3472 struct connectdata *conn = data->conn; in ssh_done()
3476 result = ssh_block_statemach(data, conn, FALSE); in ssh_done()
3483 if(Curl_pgrsDone(data)) in ssh_done()
3486 data->req.keepon = 0; /* clear all bits */ in ssh_done()
3491 static CURLcode scp_done(struct Curl_easy *data, CURLcode status, in scp_done() argument
3497 state(data, SSH_SCP_DONE); in scp_done()
3499 return ssh_done(data, status); in scp_done()
3503 static ssize_t scp_send(struct Curl_easy *data, int sockindex, in scp_send() argument
3507 struct connectdata *conn = data->conn; in scp_send()
3515 ssh_block2waitfor(data, (nwrite == LIBSSH2_ERROR_EAGAIN)); in scp_send()
3529 static ssize_t scp_recv(struct Curl_easy *data, int sockindex, in scp_recv() argument
3533 struct connectdata *conn = data->conn; in scp_recv()
3540 ssh_block2waitfor(data, (nread == LIBSSH2_ERROR_EAGAIN)); in scp_recv()
3563 CURLcode sftp_perform(struct Curl_easy *data, in sftp_perform() argument
3569 DEBUGF(infof(data, "DO phase starts")); in sftp_perform()
3574 state(data, SSH_SFTP_QUOTE_INIT); in sftp_perform()
3577 result = ssh_multi_statemach(data, dophase_done); in sftp_perform()
3579 *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET); in sftp_perform()
3582 DEBUGF(infof(data, "DO phase is complete")); in sftp_perform()
3589 static CURLcode sftp_doing(struct Curl_easy *data, in sftp_doing() argument
3592 CURLcode result = ssh_multi_statemach(data, dophase_done); in sftp_doing()
3595 DEBUGF(infof(data, "DO phase is complete")); in sftp_doing()
3603 static CURLcode sftp_disconnect(struct Curl_easy *data, in sftp_disconnect() argument
3610 DEBUGF(infof(data, "SSH DISCONNECT starts now")); in sftp_disconnect()
3614 state(data, SSH_SFTP_SHUTDOWN); in sftp_disconnect()
3615 result = ssh_block_statemach(data, conn, TRUE); in sftp_disconnect()
3618 DEBUGF(infof(data, "SSH DISCONNECT is done")); in sftp_disconnect()
3624 static CURLcode sftp_done(struct Curl_easy *data, CURLcode status, in sftp_done() argument
3627 struct connectdata *conn = data->conn; in sftp_done()
3634 if(!premature && data->set.postquote && !conn->bits.retry) in sftp_done()
3636 state(data, SSH_SFTP_CLOSE); in sftp_done()
3638 return ssh_done(data, status); in sftp_done()
3642 static ssize_t sftp_send(struct Curl_easy *data, int sockindex, in sftp_send() argument
3646 struct connectdata *conn = data->conn; in sftp_send()
3653 ssh_block2waitfor(data, (nwrite == LIBSSH2_ERROR_EAGAIN)); in sftp_send()
3671 static ssize_t sftp_recv(struct Curl_easy *data, int sockindex, in sftp_recv() argument
3675 struct connectdata *conn = data->conn; in sftp_recv()
3681 ssh_block2waitfor(data, (nread == LIBSSH2_ERROR_EAGAIN)); in sftp_recv()
3787 static void ssh_attach(struct Curl_easy *data, struct connectdata *conn) in ssh_attach() argument
3789 DEBUGASSERT(data); in ssh_attach()
3796 *abstract = data; in ssh_attach()