-/*
+/*
Unix SMB/Netbios implementation.
SMB client library implementation
Copyright (C) Andrew Tridgell 1998
Copyright (C) Richard Sharpe 2000, 2002
Copyright (C) John Terpstra 2000
- Copyright (C) Tom Jansen (Ninja ISD) 2002
+ Copyright (C) Tom Jansen (Ninja ISD) 2002
Copyright (C) Derrell Lipman 2003-2008
Copyright (C) Jeremy Allison 2007, 2008
*/
#include "includes.h"
+#include "libsmb/libsmb.h"
#include "libsmbclient.h"
#include "libsmb_internal.h"
+#include "../libcli/smb/smbXcli_base.h"
-
-/*
+/*
* Generate an inode number from file name for those things that need it
*/
static int
setup_stat(SMBCCTX *context,
struct stat *st,
- char *fname,
- SMB_OFF_T size,
+ const char *fname,
+ off_t size,
int mode)
{
TALLOC_CTX *frame = talloc_stackframe();
struct timespec write_time_ts;
struct timespec access_time_ts;
struct timespec change_time_ts;
- SMB_OFF_T size = 0;
- uint16 mode = 0;
+ off_t size = 0;
+ uint16_t mode = 0;
+ uint16_t port = 0;
SMB_INO_T ino = 0;
TALLOC_CTX *frame = talloc_stackframe();
fname,
&workgroup,
&server,
+ &port,
&share,
&path,
&user,
}
srv = SMBC_server(frame, context, True,
- server, share, &workgroup, &user, &password);
+ server, port, share, &workgroup, &user, &password);
if (!srv) {
TALLOC_FREE(frame);
return -1; /* errno set by SMBC_server */
st->st_ino = ino;
- setup_stat(context, st, (char *) fname, size, mode);
+ setup_stat(context, st, fname, size, mode);
st->st_atime = convert_timespec_to_time_t(access_time_ts);
st->st_ctime = convert_timespec_to_time_t(change_time_ts);
struct timespec change_time_ts;
struct timespec access_time_ts;
struct timespec write_time_ts;
- SMB_OFF_T size;
- uint16 mode;
+ off_t size;
+ uint16_t mode;
char *server = NULL;
char *share = NULL;
char *user = NULL;
char *targetpath = NULL;
struct cli_state *targetcli = NULL;
SMB_INO_T ino = 0;
+ uint16_t port = 0;
TALLOC_CTX *frame = talloc_stackframe();
+ NTSTATUS status;
if (!context || !context->internal->initialized) {
errno = EINVAL;
file->fname,
NULL,
&server,
+ &port,
&share,
&path,
&user,
}
/*d_printf(">>>fstat: resolving %s\n", path);*/
- if (!cli_resolve_path(frame, "", context->internal->auth_info,
- file->srv->cli, path,
- &targetcli, &targetpath)) {
+ status = cli_resolve_path(frame, "", context->internal->auth_info,
+ file->srv->cli, path,
+ &targetcli, &targetpath);
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("Could not resolve %s\n", path);
errno = ENOENT;
TALLOC_FREE(frame);
}
/*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/
- if (!cli_qfileinfo(targetcli, file->cli_fd, &mode, &size,
- NULL,
- &access_time_ts,
- &write_time_ts,
- &change_time_ts,
- &ino)) {
+ if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
+ targetcli, file->cli_fd, &mode, &size,
+ NULL,
+ &access_time_ts,
+ &write_time_ts,
+ &change_time_ts,
+ &ino))) {
time_t change_time, access_time, write_time;
if (!NT_STATUS_IS_OK(cli_getattrE(targetcli, file->cli_fd, &mode, &size,
bool bIsDir;
struct stat statbuf;
SMBCFILE * pFile;
+ TALLOC_CTX *frame = talloc_stackframe();
/* Determine if the provided path is a file or a folder */
if (SMBC_stat_ctx(context, path, &statbuf) < 0) {
+ TALLOC_FREE(frame);
return -1;
}
if (S_ISDIR(statbuf.st_mode)) {
/* It's a directory. */
if ((pFile = SMBC_opendir_ctx(context, path)) == NULL) {
+ TALLOC_FREE(frame);
return -1;
}
bIsDir = true;
/* It's a file. */
if ((pFile = SMBC_open_ctx(context, path,
O_RDONLY, 0)) == NULL) {
+ TALLOC_FREE(frame);
return -1;
}
bIsDir = false;
} else {
/* It's neither a file nor a directory. Not supported. */
+ TALLOC_FREE(frame);
errno = ENOSYS;
return -1;
}
SMBC_close_ctx(context, pFile);
}
+ TALLOC_FREE(frame);
return ret;
}
struct statvfs *st)
{
unsigned long flags = 0;
- uint32 fs_attrs = 0;
+ uint32_t fs_attrs = 0;
struct cli_state *cli = file->srv->cli;
+ struct smbXcli_tcon *tcon;
+ TALLOC_CTX *frame = talloc_stackframe();
+
+ if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+ tcon = cli->smb2.tcon;
+ } else {
+ tcon = cli->smb1.tcon;
+ }
/* Initialize all fields (at least until we actually use them) */
memset(st, 0, sizeof(*st));
uint64_t actual_allocation_units;
uint64_t sectors_per_allocation_unit;
uint64_t bytes_per_sector;
+ NTSTATUS status;
/* Nope. If size data is available... */
- if (cli_get_fs_full_size_info(cli,
- &total_allocation_units,
- &caller_allocation_units,
- &actual_allocation_units,
- §ors_per_allocation_unit,
- &bytes_per_sector)) {
+ status = cli_get_fs_full_size_info(cli,
+ &total_allocation_units,
+ &caller_allocation_units,
+ &actual_allocation_units,
+ §ors_per_allocation_unit,
+ &bytes_per_sector);
+ if (NT_STATUS_IS_OK(status)) {
/* ... then provide it */
st->f_bsize =
(unsigned long) bytes_per_sector;
-#if HAVE_FRSIZE
+#ifdef HAVE_FRSIZE
st->f_frsize =
(unsigned long) sectors_per_allocation_unit;
#endif
flags |= SMBC_VFS_FEATURE_NO_UNIXCIFS;
} else {
- uint32 optimal_transfer_size;
- uint32 block_size;
+ uint32_t optimal_transfer_size;
+ uint32_t block_size;
uint64_t total_blocks;
uint64_t blocks_available;
uint64_t user_blocks_available;
uint64_t total_file_nodes;
uint64_t free_file_nodes;
uint64_t fs_identifier;
+ NTSTATUS status;
/* Has UNIXCIFS. If POSIX filesystem info is available... */
- if (cli_get_posix_fs_info(cli,
- &optimal_transfer_size,
- &block_size,
- &total_blocks,
- &blocks_available,
- &user_blocks_available,
- &total_file_nodes,
- &free_file_nodes,
- &fs_identifier)) {
+ status = cli_get_posix_fs_info(cli,
+ &optimal_transfer_size,
+ &block_size,
+ &total_blocks,
+ &blocks_available,
+ &user_blocks_available,
+ &total_file_nodes,
+ &free_file_nodes,
+ &fs_identifier);
+ if (NT_STATUS_IS_OK(status)) {
/* ... then what's provided here takes precedence. */
st->f_bsize =
(fsfilcnt_t) total_file_nodes;
st->f_ffree =
(fsfilcnt_t) free_file_nodes;
-#if HAVE_FSID_INT
+#ifdef HAVE_FSID_INT
st->f_fsid =
(unsigned long) fs_identifier;
#endif
}
/* See if DFS is supported */
- if ((cli->capabilities & CAP_DFS) && cli->dfsroot) {
+ if (smbXcli_conn_dfs_supported(cli->conn) &&
+ smbXcli_tcon_is_dfs_share(tcon))
+ {
flags |= SMBC_VFS_FEATURE_DFS;
}
-#if HAVE_STATVFS_F_FLAG
+#if defined(HAVE_STATVFS_F_FLAG)
st->f_flag = flags;
-#elif HAVE_STATVFS_F_FLAGS
+#elif defined(HAVE_STATVFS_F_FLAGS)
st->f_flags = flags;
#endif
+ TALLOC_FREE(frame);
return 0;
}