lib: remove unused function nttime_from_string()
[bbaumbach/samba-autobuild/.git] / source3 / libsmb / libsmb_stat.c
index f8614d3154eae7ffb00d44d1d0e6bb4f939261fb..f8b35bdb9eac83719dcad86f396e9686d130c05e 100644 (file)
@@ -1,10 +1,10 @@
-/* 
+/*
    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
  */
 
@@ -52,8 +53,8 @@ generate_inode(SMBCCTX *context,
 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();
@@ -117,8 +118,9 @@ SMBC_stat_ctx(SMBCCTX *context,
        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();
 
@@ -141,6 +143,7 @@ SMBC_stat_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -161,7 +164,7 @@ SMBC_stat_ctx(SMBCCTX *context,
        }
 
        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 */
@@ -180,7 +183,7 @@ SMBC_stat_ctx(SMBCCTX *context,
 
        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);
@@ -203,8 +206,8 @@ SMBC_fstat_ctx(SMBCCTX *context,
        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;
@@ -213,7 +216,9 @@ SMBC_fstat_ctx(SMBCCTX *context,
         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;
@@ -238,6 +243,7 @@ SMBC_fstat_ctx(SMBCCTX *context,
                             file->fname,
                             NULL,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -249,9 +255,10 @@ SMBC_fstat_ctx(SMBCCTX *context,
         }
 
        /*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);
@@ -259,12 +266,13 @@ SMBC_fstat_ctx(SMBCCTX *context,
        }
        /*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,
@@ -304,9 +312,11 @@ SMBC_statvfs_ctx(SMBCCTX *context,
         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;
         }
 
@@ -314,6 +324,7 @@ SMBC_statvfs_ctx(SMBCCTX *context,
         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;
@@ -321,11 +332,13 @@ SMBC_statvfs_ctx(SMBCCTX *context,
                 /* 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;
         }
@@ -340,6 +353,7 @@ SMBC_statvfs_ctx(SMBCCTX *context,
                 SMBC_close_ctx(context, pFile);
         }
 
+       TALLOC_FREE(frame);
         return ret;
 }
 
@@ -354,8 +368,16 @@ SMBC_fstatvfs_ctx(SMBCCTX *context,
                   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));
@@ -376,19 +398,21 @@ SMBC_fstatvfs_ctx(SMBCCTX *context,
                 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,
-                                              &sectors_per_allocation_unit,
-                                              &bytes_per_sector)) {
+               status = cli_get_fs_full_size_info(cli,
+                                                  &total_allocation_units,
+                                                  &caller_allocation_units,
+                                                  &actual_allocation_units,
+                                                  &sectors_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
@@ -400,25 +424,27 @@ SMBC_fstatvfs_ctx(SMBCCTX *context,
 
                 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 =
@@ -433,7 +459,7 @@ SMBC_fstatvfs_ctx(SMBCCTX *context,
                                 (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
@@ -457,15 +483,18 @@ SMBC_fstatvfs_ctx(SMBCCTX *context,
         }
 
         /* 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;
 }