Add secure libcurl transfer backend

This commit is contained in:
Mario Fetka
2026-07-14 17:01:03 +02:00
parent f3e6580ce5
commit 4a80e32f3e
19 changed files with 361 additions and 88 deletions
+23 -26
View File
@@ -31,6 +31,7 @@
#include "debug.h"
#include "ftpparse.h"
#include "ftp.h"
#include <inttypes.h>
/* #define UNIMPLEMENTED_CMD(a) ((a == 500) || (a == 502) || (a == 504)) */
@@ -188,14 +189,17 @@ uerr_t ftp_get_line(connection_t * connection, char *line)
connection->szBuffer = &ch;
while ((iBuffLen < BUFFER_SIZE)
while ((iBuffLen < BUFFER_SIZE - 1)
&& ((ret = ftp_check_msg(connection, 1)) > 0))
{
/* Now get the full string. */
iLen = ftp_read_msg(connection, 1);
if (iLen != 1)
return FTPERR;
{
connection->szBuffer = NULL;
return FTPERR;
}
iBuffLen += iLen;
*szptr = ch;
@@ -207,13 +211,14 @@ uerr_t ftp_get_line(connection_t * connection, char *line)
/* Check for error returned in ftp_check_msg(). */
if (ret == -1)
return FTPERR;
{
connection->szBuffer = NULL;
return FTPERR;
}
/* if zero bytes were found that means the server has closed the connection*/
if (ret == 0)
*(szptr) = '\0';
else
*(szptr + 1) = '\0';
*szptr = '\0';
connection->szBuffer = NULL;
proz_debug(_("Received: %s"), line);
@@ -393,7 +398,7 @@ uerr_t ftp_rest(connection_t * connection, off_t bytes)
{
uerr_t err;
err = ftp_send_msg(connection, "REST %lld\r\n", bytes);
err = ftp_send_msg(connection, "REST %jd\r\n", (intmax_t) bytes);
if (err != FTPOK)
return err;
@@ -445,7 +450,6 @@ uerr_t ftp_pwd(connection_t * connection, char *dir)
{
uerr_t err;
char *r, *l;
char szBuffer[FTP_BUFFER_SIZE];
err = ftp_send_msg(connection, "PWD\r\n");
if (err != FTPOK)
@@ -477,7 +481,7 @@ uerr_t ftp_pwd(connection_t * connection, char *dir)
if ((r = strchr(connection->serv_ret_lines->line, ' ')) != NULL)
{
*r = '\0';
strcpy(dir, szBuffer);
strcpy(dir, r + 1);
*r = ' ';
}
}
@@ -491,6 +495,8 @@ uerr_t ftp_pwd(connection_t * connection, char *dir)
uerr_t ftp_size(connection_t * connection, const char *file, off_t *size)
{
uerr_t err;
char *end;
intmax_t parsed_size;
*size = -1;
@@ -505,7 +511,12 @@ uerr_t ftp_size(connection_t * connection, const char *file, off_t *size)
/* Now lets figure out what happened. */
if (connection->serv_ret_lines->line[0] == '2')
{
sscanf(connection->serv_ret_lines->line + 3, "%lld", size);
errno = 0;
parsed_size = strtoimax(connection->serv_ret_lines->line + 3, &end, 10);
if (errno != 0 || end == connection->serv_ret_lines->line + 3
|| parsed_size < 0 || (intmax_t) (off_t) parsed_size != parsed_size)
return FTPSIZEFAIL;
*size = (off_t) parsed_size;
return FTPOK;
}
else if (connection->serv_ret_lines->line[0] == '5') /* An error occured. */
@@ -902,21 +913,7 @@ uerr_t proz_ftp_get_url_info(connection_t * connection)
user = user ? user : libprozrtinfo.ftp_default_user;
passwd = passwd ? passwd : libprozrtinfo.ftp_default_passwd;
if (strcmp(user, "anonymous") == 0)
connection_show_message(connection,
_("Logging in as user %s with password %s"),
user, passwd);
else
{
int pwd_len = strlen(passwd);
char *tmp_pwd = (char *)kmalloc(pwd_len + 1);
memset(tmp_pwd, 'x', pwd_len);
tmp_pwd[pwd_len] = 0;
connection_show_message(connection,
_("Logging in as user %s with password %s"),
user, tmp_pwd);
kfree(tmp_pwd);
}
connection_show_message(connection, _("Logging in as user %s"), user);
init_response(connection);
err = ftp_login(connection, user, passwd);