mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 18:04:25 +09:00
Add sftp_extension_supported() function.
This commit is contained in:
@@ -261,6 +261,26 @@ LIBSSH_API const char *sftp_extensions_get_name(SFTP_SESSION *sftp, unsigned int
|
|||||||
*/
|
*/
|
||||||
LIBSSH_API const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int index);
|
LIBSSH_API const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if the given extension is supported.
|
||||||
|
*
|
||||||
|
* @param sftp The sftp session to use.
|
||||||
|
*
|
||||||
|
* @param name The name of the extension.
|
||||||
|
*
|
||||||
|
* @param data The data of the extension.
|
||||||
|
*
|
||||||
|
* @return 1 if supported, 0 if not.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* sftp_extension_supported(sftp, "statvfs@openssh.com", "2");
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
LIBSSH_API int sftp_extension_supported(SFTP_SESSION *sftp, const char *name,
|
||||||
|
const char *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Open a directory used to obtain directory entries.
|
* @brief Open a directory used to obtain directory entries.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -45,12 +45,6 @@
|
|||||||
#define sftp_leave_function() _leave_function(sftp->channel->session)
|
#define sftp_leave_function() _leave_function(sftp->channel->session)
|
||||||
|
|
||||||
struct sftp_ext_struct {
|
struct sftp_ext_struct {
|
||||||
int rename_openssh;
|
|
||||||
int rename_openssh_version;
|
|
||||||
int statvfs_openssh;
|
|
||||||
int statvfs_openssh_version;
|
|
||||||
int fstatvfs_openssh;
|
|
||||||
int fstatvfs_openssh_version;
|
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
char **name;
|
char **name;
|
||||||
char **data;
|
char **data;
|
||||||
@@ -536,17 +530,6 @@ int sftp_init(SFTP_SESSION *sftp) {
|
|||||||
"SFTP server extension: %s, version: %s",
|
"SFTP server extension: %s, version: %s",
|
||||||
ext_name, ext_data);
|
ext_name, ext_data);
|
||||||
|
|
||||||
if (strcmp(ext_name, "posix-rename@openssh.com") == 0) {
|
|
||||||
sftp->ext->rename_openssh = 1;
|
|
||||||
sftp->ext->rename_openssh_version = strtol(ext_data, (char **) NULL, 10);
|
|
||||||
} else if (strcmp(ext_name, "statvfs@openssh.com") == 0) {
|
|
||||||
sftp->ext->statvfs_openssh = 1;
|
|
||||||
sftp->ext->statvfs_openssh_version = strtol(ext_data, (char **) NULL, 10);
|
|
||||||
} else if (strcmp(ext_name, "fstatvfs@openssh.com") == 0) {
|
|
||||||
sftp->ext->fstatvfs_openssh = 1;
|
|
||||||
sftp->ext->fstatvfs_openssh_version = strtol(ext_data, (char **) NULL, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
tmp = realloc(sftp->ext->name, count * sizeof(char *));
|
tmp = realloc(sftp->ext->name, count * sizeof(char *));
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
@@ -619,6 +602,21 @@ const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int index) {
|
|||||||
return sftp->ext->data[index];
|
return sftp->ext->data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sftp_extension_supported(SFTP_SESSION *sftp, const char *name,
|
||||||
|
const char *data) {
|
||||||
|
int i, n;
|
||||||
|
|
||||||
|
n = sftp_extensions_get_count(sftp);
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
if (strcmp(sftp_extensions_get_name(sftp, i), name) == 0 &&
|
||||||
|
strcmp(sftp_extensions_get_data(sftp, i), data) == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static REQUEST_QUEUE *request_queue_new(SFTP_MESSAGE *msg) {
|
static REQUEST_QUEUE *request_queue_new(SFTP_MESSAGE *msg) {
|
||||||
REQUEST_QUEUE *queue = NULL;
|
REQUEST_QUEUE *queue = NULL;
|
||||||
|
|
||||||
|
|||||||
120
sample.c
120
sample.c
@@ -327,67 +327,69 @@ void do_sftp(SSH_SESSION *session){
|
|||||||
|
|
||||||
sftp_unlink(sftp_session, "/tmp/sftp_symlink_test");
|
sftp_unlink(sftp_session, "/tmp/sftp_symlink_test");
|
||||||
|
|
||||||
sftpstatvfs = sftp_statvfs(sftp_session, "/tmp");
|
if (sftp_extension_supported(sftp_session, "statvfs@openssh.com", "2")) {
|
||||||
if (sftpstatvfs == NULL) {
|
sftpstatvfs = sftp_statvfs(sftp_session, "/tmp");
|
||||||
fprintf(stderr, "statvfs failed (%s)\n", ssh_get_error(session));
|
if (sftpstatvfs == NULL) {
|
||||||
return;
|
fprintf(stderr, "statvfs failed (%s)\n", ssh_get_error(session));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("sftp statvfs:\n"
|
||||||
|
"\tfile system block size: %llu\n"
|
||||||
|
"\tfundamental fs block size: %llu\n"
|
||||||
|
"\tnumber of blocks (unit f_frsize): %llu\n"
|
||||||
|
"\tfree blocks in file system: %llu\n"
|
||||||
|
"\tfree blocks for non-root: %llu\n"
|
||||||
|
"\ttotal file inodes: %llu\n"
|
||||||
|
"\tfree file inodes: %llu\n"
|
||||||
|
"\tfree file inodes for to non-root: %llu\n"
|
||||||
|
"\tfile system id: %llu\n"
|
||||||
|
"\tbit mask of f_flag values: %llu\n"
|
||||||
|
"\tmaximum filename length: %llu\n",
|
||||||
|
sftpstatvfs->f_bsize,
|
||||||
|
sftpstatvfs->f_frsize,
|
||||||
|
sftpstatvfs->f_blocks,
|
||||||
|
sftpstatvfs->f_bfree,
|
||||||
|
sftpstatvfs->f_bavail,
|
||||||
|
sftpstatvfs->f_files,
|
||||||
|
sftpstatvfs->f_ffree,
|
||||||
|
sftpstatvfs->f_favail,
|
||||||
|
sftpstatvfs->f_fsid,
|
||||||
|
sftpstatvfs->f_flag,
|
||||||
|
sftpstatvfs->f_namemax);
|
||||||
|
|
||||||
|
sftp_statvfs_free(sftpstatvfs);
|
||||||
|
|
||||||
|
if (statvfs("/tmp", &sysstatvfs) < 0) {
|
||||||
|
fprintf(stderr, "statvfs failed (%s)\n", strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("sys statvfs:\n"
|
||||||
|
"\tfile system block size: %llu\n"
|
||||||
|
"\tfundamental fs block size: %llu\n"
|
||||||
|
"\tnumber of blocks (unit f_frsize): %llu\n"
|
||||||
|
"\tfree blocks in file system: %llu\n"
|
||||||
|
"\tfree blocks for non-root: %llu\n"
|
||||||
|
"\ttotal file inodes: %llu\n"
|
||||||
|
"\tfree file inodes: %llu\n"
|
||||||
|
"\tfree file inodes for to non-root: %llu\n"
|
||||||
|
"\tfile system id: %llu\n"
|
||||||
|
"\tbit mask of f_flag values: %llu\n"
|
||||||
|
"\tmaximum filename length: %llu\n",
|
||||||
|
sysstatvfs.f_bsize,
|
||||||
|
sysstatvfs.f_frsize,
|
||||||
|
sysstatvfs.f_blocks,
|
||||||
|
sysstatvfs.f_bfree,
|
||||||
|
sysstatvfs.f_bavail,
|
||||||
|
sysstatvfs.f_files,
|
||||||
|
sysstatvfs.f_ffree,
|
||||||
|
sysstatvfs.f_favail,
|
||||||
|
sysstatvfs.f_fsid,
|
||||||
|
sysstatvfs.f_flag,
|
||||||
|
sysstatvfs.f_namemax);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("sftp statvfs:\n"
|
|
||||||
"\tfile system block size: %llu\n"
|
|
||||||
"\tfundamental fs block size: %llu\n"
|
|
||||||
"\tnumber of blocks (unit f_frsize): %llu\n"
|
|
||||||
"\tfree blocks in file system: %llu\n"
|
|
||||||
"\tfree blocks for non-root: %llu\n"
|
|
||||||
"\ttotal file inodes: %llu\n"
|
|
||||||
"\tfree file inodes: %llu\n"
|
|
||||||
"\tfree file inodes for to non-root: %llu\n"
|
|
||||||
"\tfile system id: %llu\n"
|
|
||||||
"\tbit mask of f_flag values: %llu\n"
|
|
||||||
"\tmaximum filename length: %llu\n",
|
|
||||||
sftpstatvfs->f_bsize,
|
|
||||||
sftpstatvfs->f_frsize,
|
|
||||||
sftpstatvfs->f_blocks,
|
|
||||||
sftpstatvfs->f_bfree,
|
|
||||||
sftpstatvfs->f_bavail,
|
|
||||||
sftpstatvfs->f_files,
|
|
||||||
sftpstatvfs->f_ffree,
|
|
||||||
sftpstatvfs->f_favail,
|
|
||||||
sftpstatvfs->f_fsid,
|
|
||||||
sftpstatvfs->f_flag,
|
|
||||||
sftpstatvfs->f_namemax);
|
|
||||||
|
|
||||||
sftp_statvfs_free(sftpstatvfs);
|
|
||||||
|
|
||||||
if (statvfs("/tmp", &sysstatvfs) < 0) {
|
|
||||||
fprintf(stderr, "statvfs failed (%s)\n", strerror(errno));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("sys statvfs:\n"
|
|
||||||
"\tfile system block size: %llu\n"
|
|
||||||
"\tfundamental fs block size: %llu\n"
|
|
||||||
"\tnumber of blocks (unit f_frsize): %llu\n"
|
|
||||||
"\tfree blocks in file system: %llu\n"
|
|
||||||
"\tfree blocks for non-root: %llu\n"
|
|
||||||
"\ttotal file inodes: %llu\n"
|
|
||||||
"\tfree file inodes: %llu\n"
|
|
||||||
"\tfree file inodes for to non-root: %llu\n"
|
|
||||||
"\tfile system id: %llu\n"
|
|
||||||
"\tbit mask of f_flag values: %llu\n"
|
|
||||||
"\tmaximum filename length: %llu\n",
|
|
||||||
sysstatvfs.f_bsize,
|
|
||||||
sysstatvfs.f_frsize,
|
|
||||||
sysstatvfs.f_blocks,
|
|
||||||
sysstatvfs.f_bfree,
|
|
||||||
sysstatvfs.f_bavail,
|
|
||||||
sysstatvfs.f_files,
|
|
||||||
sysstatvfs.f_ffree,
|
|
||||||
sysstatvfs.f_favail,
|
|
||||||
sysstatvfs.f_fsid,
|
|
||||||
sysstatvfs.f_flag,
|
|
||||||
sysstatvfs.f_namemax);
|
|
||||||
|
|
||||||
/* the connection is made */
|
/* the connection is made */
|
||||||
/* opening a directory */
|
/* opening a directory */
|
||||||
dir=sftp_opendir(sftp_session,"./");
|
dir=sftp_opendir(sftp_session,"./");
|
||||||
|
|||||||
Reference in New Issue
Block a user