Get medieval on our ass about SMB1 file descriptors being 16 bits, not an int.
[nivanova/samba-autobuild/.git] / source3 / libsmb / libsmb_file.c
index ece056db87f1ea8d03b4ec925314e05a7f1bc7ee..4724658fe3f704b8304f2d2dfc2c9094596804f4 100644 (file)
@@ -47,7 +47,8 @@ SMBC_open_ctx(SMBCCTX *context,
        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) {
@@ -102,7 +103,7 @@ 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);
                 
@@ -115,17 +116,20 @@ 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)) {
+               if (!cli_resolve_path(frame, "", context->internal->auth_info,
+                               srv->cli, path,
+                               &targetcli, &targetpath)) {
                        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 ... */
                         
@@ -184,7 +188,7 @@ SMBC_open_ctx(SMBCCTX *context,
         
        /* Check if opendir needed ... */
         
-       if (fd == -1) {
+       if (!NT_STATUS_IS_OK(status)) {
                int eno = 0;
                 
                eno = SMBC_errno(context, srv->cli);
@@ -295,9 +299,11 @@ SMBC_read_ctx(SMBCCTX *context,
         }
         
        /*d_printf(">>>read: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", file->srv->cli, path,
-                              &targetcli, &targetpath)) {
+       if (!cli_resolve_path(frame, "", context->internal->auth_info,
+                       file->srv->cli, path,
+                       &targetcli, &targetpath)) {
                d_printf("Could not resolve %s\n", path);
+                errno = ENOENT;
                TALLOC_FREE(frame);
                return -1;
        }
@@ -382,11 +388,13 @@ SMBC_write_ctx(SMBCCTX *context,
                TALLOC_FREE(frame);
                 return -1;
         }
-        
+
        /*d_printf(">>>write: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", file->srv->cli, path,
-                              &targetcli, &targetpath)) {
+       if (!cli_resolve_path(frame, "", context->internal->auth_info,
+                       file->srv->cli, path,
+                       &targetcli, &targetpath)) {
                d_printf("Could not resolve %s\n", path);
+                errno = ENOENT;
                TALLOC_FREE(frame);
                return -1;
        }
@@ -459,9 +467,11 @@ SMBC_close_ctx(SMBCCTX *context,
         }
         
        /*d_printf(">>>close: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", file->srv->cli, path,
-                              &targetcli, &targetpath)) {
+       if (!cli_resolve_path(frame, "", context->internal->auth_info,
+                       file->srv->cli, path,
+                       &targetcli, &targetpath)) {
                d_printf("Could not resolve %s\n", path);
+                errno = ENOENT;
                TALLOC_FREE(frame);
                return -1;
        }
@@ -541,9 +551,11 @@ SMBC_getatr(SMBCCTX * context,
        }
        DEBUG(4,("SMBC_getatr: sending qpathinfo\n"));
         
-       if (!cli_resolve_path(frame, "", srv->cli, fixedpath,
-                              &targetcli, &targetpath)) {
+       if (!cli_resolve_path(frame, "", context->internal->auth_info,
+                       srv->cli, fixedpath,
+                       &targetcli, &targetpath)) {
                d_printf("Couldn't resolve %s\n", path);
+                errno = ENOENT;
                TALLOC_FREE(frame);
                return False;
        }
@@ -617,7 +629,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();
         
@@ -649,7 +661,7 @@ 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);
@@ -753,9 +765,11 @@ SMBC_lseek_ctx(SMBCCTX *context,
                }
                 
                /*d_printf(">>>lseek: resolving %s\n", path);*/
-               if (!cli_resolve_path(frame, "", file->srv->cli, path,
-                                      &targetcli, &targetpath)) {
+               if (!cli_resolve_path(frame, "", context->internal->auth_info,
+                               file->srv->cli, path,
+                               &targetcli, &targetpath)) {
                        d_printf("Could not resolve %s\n", path);
+                        errno = ENOENT;
                        TALLOC_FREE(frame);
                        return -1;
                }
@@ -844,9 +858,11 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
         }
         
        /*d_printf(">>>fstat: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", file->srv->cli, path,
-                              &targetcli, &targetpath)) {
+       if (!cli_resolve_path(frame, "", context->internal->auth_info,
+                       file->srv->cli, path,
+                       &targetcli, &targetpath)) {
                d_printf("Could not resolve %s\n", path);
+                errno = ENOENT;
                TALLOC_FREE(frame);
                return -1;
        }