1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-05-01 13:44:44 +03:00

Allow default permissions to be used in sftp_mkdir (#271)

Added constant LIBSSH2_SFTP_DEFAULT_MODE to use the server default permissions when making a new directory
This commit is contained in:
Will Cosgrove 2018-11-08 10:01:21 -08:00 committed by GitHub
parent b5b6673c28
commit cf13c9925c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -79,6 +79,9 @@ typedef struct _LIBSSH2_SFTP_STATVFS LIBSSH2_SFTP_STATVFS;
#define LIBSSH2_SFTP_READLINK 1
#define LIBSSH2_SFTP_REALPATH 2
/* Flags for sftp_mkdir() */
#define LIBSSH2_SFTP_DEFAULT_MODE -1
/* SFTP attribute flag bits */
#define LIBSSH2_SFTP_ATTR_SIZE 0x00000001
#define LIBSSH2_SFTP_ATTR_UIDGID 0x00000002

View File

@ -3009,16 +3009,23 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_CHANNEL *channel = sftp->channel;
LIBSSH2_SESSION *session = channel->session;
LIBSSH2_SFTP_ATTRIBUTES attrs = {
LIBSSH2_SFTP_ATTR_PERMISSIONS, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0
};
size_t data_len;
int retcode;
/* 13 = packet_len(4) + packet_type(1) + request_id(4) + path_len(4) */
ssize_t packet_len = path_len + 13 +
sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS);
ssize_t packet_len;
unsigned char *packet, *s, *data;
int rc;
if(mode != LIBSSH2_SFTP_DEFAULT_MODE) {
/* Filetype in SFTP 3 and earlier */
attrs.flags = LIBSSH2_SFTP_ATTR_PERMISSIONS;
attrs.permissions = mode | LIBSSH2_SFTP_ATTR_PFILETYPE_DIR;
}
/* 13 = packet_len(4) + packet_type(1) + request_id(4) + path_len(4) */
packet_len = path_len + 13 + sftp_attrsize(attrs.flags);
if(sftp->mkdir_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Creating directory %s with mode 0%lo", path, mode);