s3/libsmb: Use smbXcli_conn_nt_smbs_supported instead of SMB1 specific test
[obnox/samba/samba-obnox.git] / source3 / libsmb / libsmb_file.c
index 62b990ed00cc2f1b85ef77e565c5b43f73c8526e..14080fe1c79a2c06d1d331378066511701adec5e 100644 (file)
@@ -7,25 +7,26 @@
    Copyright (C) Tom Jansen (Ninja ISD) 2002 
    Copyright (C) Derrell Lipman 2003-2008
    Copyright (C) Jeremy Allison 2007, 2008
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
+#include "libsmb/libsmb.h"
 #include "libsmbclient.h"
 #include "libsmb_internal.h"
-
+#include "../libcli/smb/smbXcli_base.h"
 
 /*
  * Routine to open() a file ...
@@ -37,48 +38,49 @@ SMBC_open_ctx(SMBCCTX *context,
               int flags,
               mode_t mode)
 {
-       char *server = NULL, *share = NULL, *user = NULL, *password = NULL, *workgroup = NULL;
+       char *server = NULL;
+        char *share = NULL;
+        char *user = NULL;
+        char *password = NULL;
+        char *workgroup = NULL;
        char *path = NULL;
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        SMBCSRV *srv   = NULL;
        SMBCFILE *file = NULL;
-       int fd;
+       uint16_t fd;
+       NTSTATUS status = NT_STATUS_OBJECT_PATH_INVALID;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
-
                errno = EINVAL;  /* Best I can think of ... */
                TALLOC_FREE(frame);
                return NULL;
-
        }
 
        if (!fname) {
-
                errno = EINVAL;
                TALLOC_FREE(frame);
                return NULL;
-
        }
 
        if (SMBC_parse_path(frame,
-                               context,
-                               fname,
-                               &workgroup,
-                               &server,
-                               &share,
-                               &path,
-                               &user,
-                               &password,
-                               NULL)) {
+                            context,
+                            fname,
+                            &workgroup,
+                            &server,
+                            &share,
+                            &path,
+                            &user,
+                            &password,
+                            NULL)) {
                errno = EINVAL;
                TALLOC_FREE(frame);
                return NULL;
         }
 
        if (!user || user[0] == (char)0) {
-               user = talloc_strdup(frame, context->config.user);
+               user = talloc_strdup(frame, smbc_getUser(context));
                if (!user) {
                        errno = ENOMEM;
                        TALLOC_FREE(frame);
@@ -88,7 +90,6 @@ SMBC_open_ctx(SMBCCTX *context,
 
        srv = SMBC_server(frame, context, True,
                           server, share, &workgroup, &user, &password);
-
        if (!srv) {
                if (errno == EPERM) errno = EACCES;
                TALLOC_FREE(frame);
@@ -98,10 +99,9 @@ SMBC_open_ctx(SMBCCTX *context,
        /* Hmmm, the test for a directory is suspect here ... FIXME */
 
        if (strlen(path) > 0 && path[strlen(path) - 1] == '\\') {
-               fd = -1;
+               status = NT_STATUS_OBJECT_PATH_INVALID;
        } else {
                file = SMB_MALLOC_P(SMBCFILE);
-
                if (!file) {
                        errno = ENOMEM;
                        TALLOC_FREE(frame);
@@ -111,16 +111,21 @@ SMBC_open_ctx(SMBCCTX *context,
                ZERO_STRUCTP(file);
 
                /*d_printf(">>>open: resolving %s\n", path);*/
-               if (!cli_resolve_path(frame, "", srv->cli, path, &targetcli, &targetpath)) {
+               status = cli_resolve_path(
+                       frame, "", context->internal->auth_info,
+                       srv->cli, path, &targetcli, &targetpath);
+               if (!NT_STATUS_IS_OK(status)) {
                        d_printf("Could not resolve %s\n", path);
+                        errno = ENOENT;
                        SAFE_FREE(file);
                        TALLOC_FREE(frame);
                        return NULL;
                }
                /*d_printf(">>>open: resolved %s as %s\n", path, targetpath);*/
 
-               if ((fd = cli_open(targetcli, targetpath, flags,
-                                   context->internal->share_mode)) < 0) {
+               status = cli_open(targetcli, targetpath, flags,
+                                   context->internal->share_mode, &fd);
+               if (!NT_STATUS_IS_OK(status)) {
 
                        /* Handle the error ... */
 
@@ -128,7 +133,6 @@ SMBC_open_ctx(SMBCCTX *context,
                        errno = SMBC_errno(context, targetcli);
                        TALLOC_FREE(frame);
                        return NULL;
-
                }
 
                /* Fill in file struct */
@@ -174,48 +178,41 @@ SMBC_open_ctx(SMBCCTX *context,
 
                TALLOC_FREE(frame);
                return file;
-
        }
 
        /* Check if opendir needed ... */
 
-       if (fd == -1) {
+       if (!NT_STATUS_IS_OK(status)) {
                int eno = 0;
 
                eno = SMBC_errno(context, srv->cli);
-               file = (context->posix_emu.opendir_fn)(context, fname);
+               file = smbc_getFunctionOpendir(context)(context, fname);
                if (!file) errno = eno;
                TALLOC_FREE(frame);
                return file;
-
        }
 
        errno = EINVAL; /* FIXME, correct errno ? */
        TALLOC_FREE(frame);
        return NULL;
-
 }
 
 /*
  * Routine to create a file 
  */
 
-static int creat_bits = O_WRONLY | O_CREAT | O_TRUNC; /* FIXME: Do we need this */
-
 SMBCFILE *
 SMBC_creat_ctx(SMBCCTX *context,
                const char *path,
                mode_t mode)
 {
-
        if (!context || !context->internal->initialized) {
-
                errno = EINVAL;
                return NULL;
-
        }
 
-       return SMBC_open_ctx(context, path, creat_bits, mode);
+       return SMBC_open_ctx(context, path,
+                             O_WRONLY | O_CREAT | O_TRUNC, mode);
 }
 
 /*
@@ -228,12 +225,13 @@ SMBC_read_ctx(SMBCCTX *context,
               void *buf,
               size_t count)
 {
-       int ret;
+       size_t ret;
        char *server = NULL, *share = NULL, *user = NULL, *password = NULL;
        char *path = NULL;
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
+       NTSTATUS status;
 
         /*
          * offset:
@@ -247,11 +245,9 @@ SMBC_read_ctx(SMBCCTX *context,
         off_t offset;
 
        if (!context || !context->internal->initialized) {
-
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
-
        }
 
        DEBUG(4, ("smbc_read(%p, %d)\n", file, (int)count));
@@ -260,7 +256,6 @@ SMBC_read_ctx(SMBCCTX *context,
                errno = EBADF;
                TALLOC_FREE(frame);
                return -1;
-
        }
 
        offset = file->offset;
@@ -271,51 +266,50 @@ SMBC_read_ctx(SMBCCTX *context,
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
-
        }
 
        /*d_printf(">>>read: parsing %s\n", file->fname);*/
        if (SMBC_parse_path(frame,
-                               context,
-                               file->fname,
-                               NULL,
-                               &server,
-                               &share,
-                               &path,
-                               &user,
-                               &password,
-                               NULL)) {
+                            context,
+                            file->fname,
+                            NULL,
+                            &server,
+                            &share,
+                            &path,
+                            &user,
+                            &password,
+                            NULL)) {
                 errno = EINVAL;
                TALLOC_FREE(frame);
                 return -1;
         }
 
        /*d_printf(">>>read: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", 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);
                return -1;
        }
        /*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/
 
-       ret = cli_read(targetcli, file->cli_fd, (char *)buf, offset, count);
-
-       if (ret < 0) {
-
+       status = cli_read(targetcli, file->cli_fd, (char *)buf, offset,
+                         count, &ret);
+       if (!NT_STATUS_IS_OK(status)) {
                errno = SMBC_errno(context, targetcli);
                TALLOC_FREE(frame);
                return -1;
-
        }
 
        file->offset += ret;
 
-       DEBUG(4, ("  --> %d\n", ret));
+       DEBUG(4, ("  --> %ld\n", (unsigned long)ret));
 
        TALLOC_FREE(frame);
        return ret;  /* Success, ret bytes of data ... */
-
 }
 
 /*
@@ -325,25 +319,23 @@ SMBC_read_ctx(SMBCCTX *context,
 ssize_t
 SMBC_write_ctx(SMBCCTX *context,
                SMBCFILE *file,
-               void *buf,
+               const void *buf,
                size_t count)
 {
-       int ret;
         off_t offset;
        char *server = NULL, *share = NULL, *user = NULL, *password = NULL;
        char *path = NULL;
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
+       NTSTATUS status;
 
        /* First check all pointers before dereferencing them */
 
        if (!context || !context->internal->initialized) {
-
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
-
        }
 
        if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
@@ -358,49 +350,50 @@ SMBC_write_ctx(SMBCCTX *context,
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
-
        }
 
         offset = file->offset; /* See "offset" comment in SMBC_read_ctx() */
 
        /*d_printf(">>>write: parsing %s\n", file->fname);*/
        if (SMBC_parse_path(frame,
-                               context,
-                               file->fname,
-                               NULL,
-                               &server,
-                               &share,
-                               &path,
-                               &user,
-                               &password,
-                               NULL)) {
+                            context,
+                            file->fname,
+                            NULL,
+                            &server,
+                            &share,
+                            &path,
+                            &user,
+                            &password,
+                            NULL)) {
                 errno = EINVAL;
                TALLOC_FREE(frame);
                 return -1;
         }
 
        /*d_printf(">>>write: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", 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);
                return -1;
        }
        /*d_printf(">>>write: resolved path as %s\n", targetpath);*/
 
-       ret = cli_write(targetcli, file->cli_fd, 0, (char *)buf, offset, count);
-
-       if (ret <= 0) {
-               errno = SMBC_errno(context, targetcli);
+       status = cli_writeall(targetcli, file->cli_fd,
+                             0, (const uint8_t *)buf, offset, count, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
                TALLOC_FREE(frame);
                return -1;
-
        }
 
-       file->offset += ret;
+       file->offset += count;
 
        TALLOC_FREE(frame);
-       return ret;  /* Success, 0 bytes of data ... */
+       return count;  /* Success, 0 bytes of data ... */
 }
 
 /*
@@ -417,9 +410,9 @@ SMBC_close_ctx(SMBCCTX *context,
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
+       NTSTATUS status;
 
        if (!context || !context->internal->initialized) {
-
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
@@ -434,36 +427,38 @@ SMBC_close_ctx(SMBCCTX *context,
        /* IS a dir ... */
        if (!file->file) {
                TALLOC_FREE(frame);
-               return (context->posix_emu.closedir_fn)(context, file);
+               return smbc_getFunctionClosedir(context)(context, file);
        }
 
        /*d_printf(">>>close: parsing %s\n", file->fname);*/
        if (SMBC_parse_path(frame,
-                               context,
-                               file->fname,
-                               NULL,
-                               &server,
-                               &share,
-                               &path,
-                               &user,
-                               &password,
-                               NULL)) {
+                            context,
+                            file->fname,
+                            NULL,
+                            &server,
+                            &share,
+                            &path,
+                            &user,
+                            &password,
+                            NULL)) {
                 errno = EINVAL;
                TALLOC_FREE(frame);
                 return -1;
         }
 
        /*d_printf(">>>close: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", 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);
                return -1;
        }
        /*d_printf(">>>close: resolved path as %s\n", targetpath);*/
 
-       if (!cli_close(targetcli, file->cli_fd)) {
-
+       if (!NT_STATUS_IS_OK(cli_close(targetcli, file->cli_fd))) {
                DEBUG(3, ("cli_close failed on %s. purging server.\n", 
                          file->fname));
                /* Deallocate slot and remove the server 
@@ -473,17 +468,15 @@ SMBC_close_ctx(SMBCCTX *context,
                DLIST_REMOVE(context->internal->files, file);
                SAFE_FREE(file->fname);
                SAFE_FREE(file);
-               (context->server.remove_unused_server_fn)(context, srv);
+               smbc_getFunctionRemoveUnusedServer(context)(context, srv);
                TALLOC_FREE(frame);
                return -1;
-
        }
 
        DLIST_REMOVE(context->internal->files, file);
        SAFE_FREE(file->fname);
        SAFE_FREE(file);
        TALLOC_FREE(frame);
-
        return 0;
 }
 
@@ -494,9 +487,9 @@ SMBC_close_ctx(SMBCCTX *context,
 bool
 SMBC_getatr(SMBCCTX * context,
             SMBCSRV *srv,
-            char *path,
+            const char *path,
             uint16 *mode,
-            SMB_OFF_T *size,
+            off_t *size,
             struct timespec *create_time_ts,
             struct timespec *access_time_ts,
             struct timespec *write_time_ts,
@@ -508,12 +501,12 @@ SMBC_getatr(SMBCCTX * context,
        struct cli_state *targetcli = NULL;
        time_t write_time;
        TALLOC_CTX *frame = talloc_stackframe();
+       NTSTATUS status;
 
        if (!context || !context->internal->initialized) {
-
                errno = EINVAL;
                TALLOC_FREE(frame);
-               return -1;
+               return False;
        }
 
        /* path fixup for . and .. */
@@ -522,67 +515,64 @@ SMBC_getatr(SMBCCTX * context,
                if (!fixedpath) {
                        errno = ENOMEM;
                        TALLOC_FREE(frame);
-                       return -1;
+                       return False;
                }
        } else {
                fixedpath = talloc_strdup(frame, path);
                if (!fixedpath) {
                        errno = ENOMEM;
                        TALLOC_FREE(frame);
-                       return -1;
+                       return False;
                }
                trim_string(fixedpath, NULL, "\\..");
                trim_string(fixedpath, NULL, "\\.");
        }
        DEBUG(4,("SMBC_getatr: sending qpathinfo\n"));
 
-       if (!cli_resolve_path(frame, "", srv->cli, fixedpath,
-                               &targetcli, &targetpath)) {
+       status = cli_resolve_path(frame, "", context->internal->auth_info,
+                                 srv->cli, fixedpath,
+                                 &targetcli, &targetpath);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("Couldn't resolve %s\n", path);
+                errno = ENOENT;
                TALLOC_FREE(frame);
                return False;
        }
 
        if (!srv->no_pathinfo2 &&
-            cli_qpathinfo2(targetcli, targetpath,
+            NT_STATUS_IS_OK(cli_qpathinfo2(targetcli, targetpath,
                            create_time_ts,
                            access_time_ts,
                            write_time_ts,
                            change_time_ts,
-                           size, mode, ino)) {
+                          size, mode, ino))) {
                TALLOC_FREE(frame);
                return True;
         }
 
        /* if this is NT then don't bother with the getatr */
-       if (targetcli->capabilities & CAP_NT_SMBS) {
+       if (smbXcli_conn_nt_smbs_supported(targetcli->conn)) {
                 errno = EPERM;
                TALLOC_FREE(frame);
                 return False;
         }
 
-       if (cli_getatr(targetcli, targetpath, mode, size, &write_time)) {
-
+       if (NT_STATUS_IS_OK(cli_getatr(targetcli, targetpath, mode, size, &write_time))) {
                 struct timespec w_time_ts;
 
                 w_time_ts = convert_time_t_to_timespec(write_time);
-
                 if (write_time_ts != NULL) {
                        *write_time_ts = w_time_ts;
                 }
-
                 if (create_time_ts != NULL) {
                         *create_time_ts = w_time_ts;
                 }
-
                 if (access_time_ts != NULL) {
                         *access_time_ts = w_time_ts;
                 }
-
                 if (change_time_ts != NULL) {
                         *change_time_ts = w_time_ts;
                 }
-
                srv->no_pathinfo2 = True;
                TALLOC_FREE(frame);
                return True;
@@ -591,7 +581,6 @@ SMBC_getatr(SMBCCTX * context,
         errno = EPERM;
        TALLOC_FREE(frame);
        return False;
-
 }
 
 /*
@@ -612,7 +601,7 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
             time_t change_time,
             uint16 mode)
 {
-        int fd;
+        uint16_t fd;
         int ret;
        TALLOC_CTX *frame = talloc_stackframe();
 
@@ -623,12 +612,12 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
          * attributes manipulated.
          */
         if (srv->no_pathinfo ||
-            ! cli_setpathinfo(srv->cli, path,
-                              create_time,
-                              access_time,
-                              write_time,
-                              change_time,
-                              mode)) {
+            !NT_STATUS_IS_OK(cli_setpathinfo_basic(srv->cli, path,
+                                                  create_time,
+                                                  access_time,
+                                                  write_time,
+                                                  change_time,
+                                                  mode))) {
 
                 /*
                  * setpathinfo is not supported; go to plan B. 
@@ -644,18 +633,17 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
                 srv->no_pathinfo = True;
 
                 /* Open the file */
-                if ((fd = cli_open(srv->cli, path, O_RDWR, DENY_NONE)) < 0) {
-
+                if (!NT_STATUS_IS_OK(cli_open(srv->cli, path, O_RDWR, DENY_NONE, &fd))) {
                         errno = SMBC_errno(context, srv->cli);
                        TALLOC_FREE(frame);
                         return -1;
                 }
 
                 /* Set the new attributes */
-                ret = cli_setattrE(srv->cli, fd,
+                ret = NT_STATUS_IS_OK(cli_setattrE(srv->cli, fd,
                                    change_time,
                                    access_time,
-                                   write_time);
+                                   write_time));
 
                 /* Close the file */
                 cli_close(srv->cli, fd);
@@ -667,7 +655,7 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
                  * seems to work on win98.
                  */
                 if (ret && mode != (uint16) -1) {
-                        ret = cli_setatr(srv->cli, path, mode, 0);
+                        ret = NT_STATUS_IS_OK(cli_setatr(srv->cli, path, mode, 0));
                 }
 
                 if (! ret) {
@@ -691,96 +679,90 @@ SMBC_lseek_ctx(SMBCCTX *context,
                off_t offset,
                int whence)
 {
-       SMB_OFF_T size;
+       off_t size;
        char *server = NULL, *share = NULL, *user = NULL, *password = NULL;
        char *path = NULL;
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
+       NTSTATUS status;
 
        if (!context || !context->internal->initialized) {
-
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
        }
 
        if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
-
                errno = EBADF;
                TALLOC_FREE(frame);
                return -1;
-
        }
 
        if (!file->file) {
-
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;      /* Can't lseek a dir ... */
-
        }
 
        switch (whence) {
        case SEEK_SET:
                file->offset = offset;
                break;
-
        case SEEK_CUR:
                file->offset += offset;
                break;
-
        case SEEK_END:
                /*d_printf(">>>lseek: parsing %s\n", file->fname);*/
                if (SMBC_parse_path(frame,
-                                       context,
-                                       file->fname,
-                                       NULL,
-                                       &server,
-                                       &share,
-                                       &path,
-                                       &user,
-                                       &password,
-                                       NULL)) {
+                                    context,
+                                    file->fname,
+                                    NULL,
+                                    &server,
+                                    &share,
+                                    &path,
+                                    &user,
+                                    &password,
+                                    NULL)) {
                        errno = EINVAL;
                        TALLOC_FREE(frame);
                        return -1;
                }
 
                /*d_printf(">>>lseek: resolving %s\n", path);*/
-               if (!cli_resolve_path(frame, "", 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);
                        return -1;
                }
-               /*d_printf(">>>lseek: resolved path as %s\n", targetpath);*/
 
-               if (!cli_qfileinfo(targetcli, file->cli_fd, NULL,
-                                   &size, NULL, NULL, NULL, NULL, NULL))
-               {
-                   SMB_OFF_T b_size = size;
-                       if (!cli_getattrE(targetcli, file->cli_fd,
-                                          NULL, &b_size, NULL, NULL, NULL))
-                   {
-                       errno = EINVAL;
-                       TALLOC_FREE(frame);
-                       return -1;
-                   } else
-                       size = b_size;
+               /*d_printf(">>>lseek: resolved path as %s\n", targetpath);*/
+               if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
+                                            targetcli, file->cli_fd, NULL,
+                                            &size, NULL, NULL, NULL, NULL,
+                                            NULL))) {
+                        off_t b_size = size;
+                       if (!NT_STATUS_IS_OK(cli_getattrE(targetcli, file->cli_fd,
+                                          NULL, &b_size, NULL, NULL, NULL))) {
+                                errno = EINVAL;
+                                TALLOC_FREE(frame);
+                                return -1;
+                        } else
+                                size = b_size;
                }
                file->offset = size + offset;
                break;
-
        default:
                errno = EINVAL;
                break;
-
        }
 
        TALLOC_FREE(frame);
        return file->offset;
-
 }
 
 
@@ -793,7 +775,7 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
                    SMBCFILE *file,
                    off_t length)
 {
-       SMB_OFF_T size = length;
+       off_t size = length;
        char *server = NULL;
        char *share = NULL;
        char *user = NULL;
@@ -802,9 +784,9 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
         char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
+       NTSTATUS status;
 
        if (!context || !context->internal->initialized) {
-
                errno = EINVAL;
                TALLOC_FREE(frame);
                return -1;
@@ -839,15 +821,18 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
         }
 
        /*d_printf(">>>fstat: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", 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);
                return -1;
        }
        /*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/
 
-        if (!cli_ftruncate(targetcli, file->cli_fd, size)) {
+        if (!NT_STATUS_IS_OK(cli_ftruncate(targetcli, file->cli_fd, (uint64_t)size))) {
                 errno = EINVAL;
                 TALLOC_FREE(frame);
                 return -1;
@@ -855,5 +840,4 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
 
        TALLOC_FREE(frame);
        return 0;
-
 }