mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
Add two new options for the SFTP/SCP/FILE protocols: CURLOPT_NEW_FILE_PERMS
and CURLOPT_NEW_DIRECTORY_PERMS. These control the premissions for files and directories created on the remote server. CURLOPT_NEW_FILE_PERMS defaults to 0644 and CURLOPT_NEW_DIRECTORY_PERMS defaults to 0755
This commit is contained in:
parent
edd35cab5c
commit
4cd7f85410
@ -1401,6 +1401,17 @@ this curl handle use the data from the shared handle instead of keeping the
|
|||||||
data to itself. This enables several curl handles to share data. If the curl
|
data to itself. This enables several curl handles to share data. If the curl
|
||||||
handles are used simultaneously, you \fBMUST\fP use the locking methods in the
|
handles are used simultaneously, you \fBMUST\fP use the locking methods in the
|
||||||
share handle. See \fIcurl_share_setopt(3)\fP for details.
|
share handle. See \fIcurl_share_setopt(3)\fP for details.
|
||||||
|
.IP CURLOPT_NEW_FILE_PERMS
|
||||||
|
Pass a long as a parameter, containing the value of the permissions that will
|
||||||
|
be assigned to newly created files on the remote server. The default value is
|
||||||
|
\fI0644\fP, but any valid value can be used. The only protocols that can use
|
||||||
|
this are \fIsftp://\fP, \fIscp://\fP and \fIfile://\fP. (Added in 7.16.4)
|
||||||
|
.IP CURLOPT_NEW_DIRECTORY_PERMS
|
||||||
|
Pass a long as a parameter, containing the value of the permissions that will
|
||||||
|
be assigned to newly created directories on the remote server. The default
|
||||||
|
value is \fI0755\fP, but any valid value can be used. The only protocols that
|
||||||
|
can use this are \fIsftp://\fP, \fIscp://\fP and \fIfile://\fP.
|
||||||
|
(Added in 7.16.4)
|
||||||
.SH TELNET OPTIONS
|
.SH TELNET OPTIONS
|
||||||
.IP CURLOPT_TELNETOPTIONS
|
.IP CURLOPT_TELNETOPTIONS
|
||||||
Provide a pointer to a curl_slist with variables to pass to the telnet
|
Provide a pointer to a curl_slist with variables to pass to the telnet
|
||||||
|
@ -1076,6 +1076,11 @@ typedef enum {
|
|||||||
CINIT(HTTP_TRANSFER_DECODING, LONG, 157),
|
CINIT(HTTP_TRANSFER_DECODING, LONG, 157),
|
||||||
CINIT(HTTP_CONTENT_DECODING, LONG, 158),
|
CINIT(HTTP_CONTENT_DECODING, LONG, 158),
|
||||||
|
|
||||||
|
/* Permission used when creating new files and directories on the remote
|
||||||
|
server for protocols that support it, SFTP/SCP/FILE */
|
||||||
|
CINIT(NEW_FILE_PERMS, LONG, 159),
|
||||||
|
CINIT(NEW_DIRECTORY_PERMS, LONG, 160),
|
||||||
|
|
||||||
CURLOPT_LASTENTRY /* the last unused */
|
CURLOPT_LASTENTRY /* the last unused */
|
||||||
} CURLoption;
|
} CURLoption;
|
||||||
|
|
||||||
|
@ -731,6 +731,8 @@ void curl_easy_reset(CURL *curl)
|
|||||||
|
|
||||||
data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
|
data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
|
||||||
type */
|
type */
|
||||||
|
data->set.new_file_perms = 0644; /* Default permissions */
|
||||||
|
data->set.new_directory_perms = 0755; /* Default permissions */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CURL_DOES_CONVERSIONS
|
#ifdef CURL_DOES_CONVERSIONS
|
||||||
|
17
lib/file.c
17
lib/file.c
@ -217,8 +217,23 @@ static CURLcode file_upload(struct connectdata *conn)
|
|||||||
|
|
||||||
if(data->reqdata.resume_from)
|
if(data->reqdata.resume_from)
|
||||||
fp = fopen( file->path, "ab" );
|
fp = fopen( file->path, "ab" );
|
||||||
else
|
else {
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
#if defined(WIN32) || defined(MSDOS) || defined(__EMX__)
|
||||||
|
fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,
|
||||||
|
conn->data->set.new_file_perms);
|
||||||
|
#else /* !(WIN32 || MSDOS || __EMX__) */
|
||||||
|
fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC,
|
||||||
|
conn->data->set.new_file_perms);
|
||||||
|
#endif /* !(WIN32 || MSDOS || __EMX__) */
|
||||||
|
if (fd < 0) {
|
||||||
|
failf(data, "Can't open %s for writing", file->path);
|
||||||
|
return CURLE_WRITE_ERROR;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
fp = fopen(file->path, "wb");
|
fp = fopen(file->path, "wb");
|
||||||
|
}
|
||||||
|
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
failf(data, "Can't open %s for writing", file->path);
|
failf(data, "Can't open %s for writing", file->path);
|
||||||
|
36
lib/ssh.c
36
lib/ssh.c
@ -1137,10 +1137,7 @@ CURLcode Curl_scp_do(struct connectdata *conn, bool *done)
|
|||||||
#if (LIBSSH2_APINO >= 200706012030)
|
#if (LIBSSH2_APINO >= 200706012030)
|
||||||
do {
|
do {
|
||||||
scp->ssh_channel = libssh2_scp_send_ex(scp->ssh_session, scp->path,
|
scp->ssh_channel = libssh2_scp_send_ex(scp->ssh_session, scp->path,
|
||||||
LIBSSH2_SFTP_S_IRUSR|
|
conn->data->set.new_file_perms,
|
||||||
LIBSSH2_SFTP_S_IWUSR|
|
|
||||||
LIBSSH2_SFTP_S_IRGRP|
|
|
||||||
LIBSSH2_SFTP_S_IROTH,
|
|
||||||
conn->data->set.infilesize, 0, 0);
|
conn->data->set.infilesize, 0, 0);
|
||||||
if (!scp->ssh_channel &&
|
if (!scp->ssh_channel &&
|
||||||
(libssh2_session_last_errno(scp->ssh_session) !=
|
(libssh2_session_last_errno(scp->ssh_session) !=
|
||||||
@ -1150,10 +1147,7 @@ CURLcode Curl_scp_do(struct connectdata *conn, bool *done)
|
|||||||
} while (!scp->ssh_channel);
|
} while (!scp->ssh_channel);
|
||||||
#else /* !(LIBSSH2_APINO >= 200706012030) */
|
#else /* !(LIBSSH2_APINO >= 200706012030) */
|
||||||
scp->ssh_channel = libssh2_scp_send_ex(scp->ssh_session, scp->path,
|
scp->ssh_channel = libssh2_scp_send_ex(scp->ssh_session, scp->path,
|
||||||
LIBSSH2_SFTP_S_IRUSR|
|
conn->data->set.new_file_perms,
|
||||||
LIBSSH2_SFTP_S_IWUSR|
|
|
||||||
LIBSSH2_SFTP_S_IRGRP|
|
|
||||||
LIBSSH2_SFTP_S_IROTH,
|
|
||||||
conn->data->set.infilesize, 0, 0);
|
conn->data->set.infilesize, 0, 0);
|
||||||
if (!scp->ssh_channel)
|
if (!scp->ssh_channel)
|
||||||
return CURLE_FAILED_INIT;
|
return CURLE_FAILED_INIT;
|
||||||
@ -1363,8 +1357,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
|
|||||||
sftp->sftp_handle =
|
sftp->sftp_handle =
|
||||||
libssh2_sftp_open(sftp->sftp_session, sftp->path,
|
libssh2_sftp_open(sftp->sftp_session, sftp->path,
|
||||||
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
||||||
LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
|
data->set.new_file_perms);
|
||||||
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
|
|
||||||
if (!sftp->sftp_handle &&
|
if (!sftp->sftp_handle &&
|
||||||
(libssh2_session_last_errno(sftp->ssh_session) !=
|
(libssh2_session_last_errno(sftp->ssh_session) !=
|
||||||
LIBSSH2_ERROR_EAGAIN)) {
|
LIBSSH2_ERROR_EAGAIN)) {
|
||||||
@ -1381,8 +1374,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
|
|||||||
sftp->sftp_handle = libssh2_sftp_open(sftp->sftp_session,
|
sftp->sftp_handle = libssh2_sftp_open(sftp->sftp_session,
|
||||||
sftp->path,
|
sftp->path,
|
||||||
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
||||||
LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
|
data->set.new_file_perms);
|
||||||
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
|
|
||||||
if (!sftp->sftp_handle &&
|
if (!sftp->sftp_handle &&
|
||||||
(libssh2_session_last_errno(sftp->ssh_session) !=
|
(libssh2_session_last_errno(sftp->ssh_session) !=
|
||||||
LIBSSH2_ERROR_EAGAIN)) {
|
LIBSSH2_ERROR_EAGAIN)) {
|
||||||
@ -1406,8 +1398,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
|
|||||||
sftp->sftp_handle =
|
sftp->sftp_handle =
|
||||||
libssh2_sftp_open(sftp->sftp_session, sftp->path,
|
libssh2_sftp_open(sftp->sftp_session, sftp->path,
|
||||||
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
||||||
LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
|
data->set.new_file_perms);
|
||||||
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
|
|
||||||
if (!sftp->sftp_handle) {
|
if (!sftp->sftp_handle) {
|
||||||
err = libssh2_sftp_last_error(sftp->sftp_session);
|
err = libssh2_sftp_last_error(sftp->sftp_session);
|
||||||
if (((err == LIBSSH2_FX_NO_SUCH_FILE) ||
|
if (((err == LIBSSH2_FX_NO_SUCH_FILE) ||
|
||||||
@ -1420,8 +1411,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
|
|||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
sftp->sftp_handle = libssh2_sftp_open(sftp->sftp_session, sftp->path,
|
sftp->sftp_handle = libssh2_sftp_open(sftp->sftp_session, sftp->path,
|
||||||
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
||||||
LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
|
data->set.new_file_perms);
|
||||||
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sftp->sftp_handle) {
|
if (!sftp->sftp_handle) {
|
||||||
@ -1636,8 +1626,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
|
|||||||
do {
|
do {
|
||||||
sftp->sftp_handle =
|
sftp->sftp_handle =
|
||||||
libssh2_sftp_open(sftp->sftp_session, sftp->path, LIBSSH2_FXF_READ,
|
libssh2_sftp_open(sftp->sftp_session, sftp->path, LIBSSH2_FXF_READ,
|
||||||
LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
|
data->set.new_file_perms);
|
||||||
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
|
|
||||||
if (!sftp->sftp_handle &&
|
if (!sftp->sftp_handle &&
|
||||||
(libssh2_session_last_errno(sftp->ssh_session) !=
|
(libssh2_session_last_errno(sftp->ssh_session) !=
|
||||||
LIBSSH2_ERROR_EAGAIN)) {
|
LIBSSH2_ERROR_EAGAIN)) {
|
||||||
@ -1650,8 +1639,7 @@ CURLcode Curl_sftp_do(struct connectdata *conn, bool *done)
|
|||||||
#else /* !(LIBSSH2_APINO >= 200706012030) */
|
#else /* !(LIBSSH2_APINO >= 200706012030) */
|
||||||
sftp->sftp_handle =
|
sftp->sftp_handle =
|
||||||
libssh2_sftp_open(sftp->sftp_session, sftp->path, LIBSSH2_FXF_READ,
|
libssh2_sftp_open(sftp->sftp_session, sftp->path, LIBSSH2_FXF_READ,
|
||||||
LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
|
data->set.new_file_perms);
|
||||||
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
|
|
||||||
if (!sftp->sftp_handle) {
|
if (!sftp->sftp_handle) {
|
||||||
err = libssh2_sftp_last_error(sftp->sftp_session);
|
err = libssh2_sftp_last_error(sftp->sftp_session);
|
||||||
failf(conn->data, "Could not open remote file for reading: %s",
|
failf(conn->data, "Could not open remote file for reading: %s",
|
||||||
@ -2304,15 +2292,11 @@ static CURLcode sftp_create_dirs(struct connectdata *conn) {
|
|||||||
/* 'mode' - parameter is preliminary - default to 0644 */
|
/* 'mode' - parameter is preliminary - default to 0644 */
|
||||||
#if (LIBSSH2_APINO >= 200706012030)
|
#if (LIBSSH2_APINO >= 200706012030)
|
||||||
while ((rc = libssh2_sftp_mkdir(sftp->sftp_session, sftp->path,
|
while ((rc = libssh2_sftp_mkdir(sftp->sftp_session, sftp->path,
|
||||||
LIBSSH2_SFTP_S_IRWXU |
|
conn->data->set.new_directory_perms)) ==
|
||||||
LIBSSH2_SFTP_S_IRGRP | LIBSSH2_SFTP_S_IXGRP |
|
|
||||||
LIBSSH2_SFTP_S_IROTH | LIBSSH2_SFTP_S_IXOTH)) ==
|
|
||||||
LIBSSH2_ERROR_EAGAIN);
|
LIBSSH2_ERROR_EAGAIN);
|
||||||
#else /* !(LIBSSH2_APINO >= 200706012030) */
|
#else /* !(LIBSSH2_APINO >= 200706012030) */
|
||||||
rc = libssh2_sftp_mkdir(sftp->sftp_session, sftp->path,
|
rc = libssh2_sftp_mkdir(sftp->sftp_session, sftp->path,
|
||||||
LIBSSH2_SFTP_S_IRWXU |
|
conn->data->set.new_directory_perms);
|
||||||
LIBSSH2_SFTP_S_IRGRP | LIBSSH2_SFTP_S_IXGRP |
|
|
||||||
LIBSSH2_SFTP_S_IROTH | LIBSSH2_SFTP_S_IXOTH);
|
|
||||||
#endif /* !(LIBSSH2_APINO >= 200706012030) */
|
#endif /* !(LIBSSH2_APINO >= 200706012030) */
|
||||||
*slash_pos = '/';
|
*slash_pos = '/';
|
||||||
++slash_pos;
|
++slash_pos;
|
||||||
|
17
lib/url.c
17
lib/url.c
@ -595,6 +595,8 @@ CURLcode Curl_open(struct SessionHandle **curl)
|
|||||||
|
|
||||||
data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
|
data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
|
||||||
type */
|
type */
|
||||||
|
data->set.new_file_perms = 0644; /* Default permissions */
|
||||||
|
data->set.new_directory_perms = 0755; /* Default permissions */
|
||||||
|
|
||||||
/* most recent connection is not yet defined */
|
/* most recent connection is not yet defined */
|
||||||
data->state.lastconnect = -1;
|
data->state.lastconnect = -1;
|
||||||
@ -1759,6 +1761,21 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
|||||||
*/
|
*/
|
||||||
data->set.http_ce_skip = (bool)(0 == va_arg(param, long));
|
data->set.http_ce_skip = (bool)(0 == va_arg(param, long));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CURLOPT_NEW_FILE_PERMS:
|
||||||
|
/*
|
||||||
|
* Uses these permissions instead of 0644
|
||||||
|
*/
|
||||||
|
data->set.new_file_perms = va_arg(param, long);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CURLOPT_NEW_DIRECTORY_PERMS:
|
||||||
|
/*
|
||||||
|
* Uses these permissions instead of 0755
|
||||||
|
*/
|
||||||
|
data->set.new_directory_perms = va_arg(param, long);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* unknown tag and its companion, just ignore: */
|
/* unknown tag and its companion, just ignore: */
|
||||||
result = CURLE_FAILED_INIT; /* correct this */
|
result = CURLE_FAILED_INIT; /* correct this */
|
||||||
|
@ -1356,6 +1356,8 @@ struct UserDefined {
|
|||||||
transfer-encoded (chunked, compressed) */
|
transfer-encoded (chunked, compressed) */
|
||||||
bool http_ce_skip; /* pass the raw body data to the user, even when
|
bool http_ce_skip; /* pass the raw body data to the user, even when
|
||||||
content-encoded (chunked, compressed) */
|
content-encoded (chunked, compressed) */
|
||||||
|
long new_file_perms; /* Permissions to use when creating remote files */
|
||||||
|
long new_directory_perms; /* Permissions to use when creating remote dirs */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Names {
|
struct Names {
|
||||||
|
Loading…
Reference in New Issue
Block a user