Print this page
NEX-14666 Need to provide SMB 2.1 Client
NEX-17187 panic in smbfs_acl_store
NEX-17231 smbfs create xattr files finds wrong file
NEX-17224 smbfs lookup EINVAL should be ENOENT
NEX-17260 SMB1 client fails to list directory after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
and: (cleanup)
NEX-16824 SMB client connection setup rework
NEX-17232 SMB client reconnect failures
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (improve debug)
NEX-16818 Add fksmbcl development tool
NEX-17264 SMB client test tp_smbutil_013 fails after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (fix ref leaks)
1575 untangle libmlrpc from SMB server
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Richard Lowe <richlowe@richlowe.net>

@@ -31,13 +31,14 @@
  *
  * $Id: file.c,v 1.4 2004/12/13 00:25:21 lindak Exp $
  */
 
 /*
- * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  */
 
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>

@@ -60,14 +61,20 @@
 #include <netsmb/smb.h>
 #include <netsmb/smb_lib.h>
 
 #include "private.h"
 
+/*
+ * It's not actually necessary to call the CLOSEFH ioctl, but doing it
+ * makes debugging a little easier.  If we were to skip the ioctl,
+ * nsmb_close would cleanup the handle, here or in process exit.
+ */
 int
 smb_fh_close(int fd)
 {
-        return (close(fd));
+        (void) nsmb_ioctl(fd, SMBIOC_CLOSEFH, NULL);
+        return (nsmb_close(fd));
 }
 
 int
 smb_fh_ntcreate(
         struct smb_ctx *ctx, char *path,

@@ -94,11 +101,11 @@
         if (new_fd < 0) {
                 err = errno;
                 goto errout;
         }
         from_fd = ctx->ct_dev_fd;
-        if (ioctl(new_fd, SMBIOC_DUP_DEV, &from_fd) == -1) {
+        if (nsmb_ioctl(new_fd, SMBIOC_DUP_DEV, &from_fd) == -1) {
                 err = errno;
                 goto errout;
         }
 
         /*

@@ -109,20 +116,20 @@
         ioc.ioc_req_acc = req_acc;
         ioc.ioc_efattr = efattr;
         ioc.ioc_share_acc = share_acc;
         ioc.ioc_open_disp = open_disp;
         ioc.ioc_creat_opts = create_opts;
-        if (ioctl(new_fd, SMBIOC_NTCREATE, &ioc) == -1) {
+        if (nsmb_ioctl(new_fd, SMBIOC_NTCREATE, &ioc) == -1) {
                 err = errno;
                 goto errout;
         }
 
         return (new_fd);
 
 errout:
         if (new_fd != -1)
-                close(new_fd);
+                nsmb_close(new_fd);
         errno = err;
         return (-1);
 }
 
 /*

@@ -202,38 +209,36 @@
         free(ntpath);
         return (fd);
 }
 
 int
-smb_fh_read(int fd, off_t offset, size_t count,
+smb_fh_read(int fd, off64_t offset, size_t count,
         char *dst)
 {
         struct smbioc_rw rwrq;
 
         bzero(&rwrq, sizeof (rwrq));
-        rwrq.ioc_fh = -1;       /* tell driver to supply this */
         rwrq.ioc_base = dst;
         rwrq.ioc_cnt = count;
         rwrq.ioc_offset = offset;
-        if (ioctl(fd, SMBIOC_READ, &rwrq) == -1) {
+        if (nsmb_ioctl(fd, SMBIOC_READ, &rwrq) == -1) {
                 return (-1);
         }
         return (rwrq.ioc_cnt);
 }
 
 int
-smb_fh_write(int fd, off_t offset, size_t count,
+smb_fh_write(int fd, off64_t offset, size_t count,
         const char *src)
 {
         struct smbioc_rw rwrq;
 
         bzero(&rwrq, sizeof (rwrq));
-        rwrq.ioc_fh = -1;       /* tell driver to supply this */
         rwrq.ioc_base = (char *)src;
         rwrq.ioc_cnt = count;
         rwrq.ioc_offset = offset;
-        if (ioctl(fd, SMBIOC_WRITE, &rwrq) == -1) {
+        if (nsmb_ioctl(fd, SMBIOC_WRITE, &rwrq) == -1) {
                 return (-1);
         }
         return (rwrq.ioc_cnt);
 }
 

@@ -249,23 +254,25 @@
 smb_fh_xactnp(int fd,
         int tdlen, const char *tdata,   /* transmit */
         int *rdlen, char *rdata,        /* receive */
         int *more)
 {
-        int             err, rparamcnt;
-        uint16_t        setup[2];
+        smbioc_xnp_t    ioc;
 
-        setup[0] = TRANS_TRANSACT_NAMED_PIPE;
-        setup[1] = 0xFFFF; /* driver replaces this */
-        rparamcnt = 0;
+        /* this gets copyin & copyout */
+        bzero(&ioc, sizeof (ioc));
+        ioc.ioc_tdlen = tdlen;
+        ioc.ioc_rdlen = *rdlen;
+        ioc.ioc_more = 0;
+        ioc.ioc_tdata = (char *)tdata;
+        ioc.ioc_rdata = rdata;
 
-        err = smb_t2_request(fd, 2, setup, "\\PIPE\\",
-            0, NULL,    /* TX paramcnt, params */
-            tdlen, (void *)tdata,
-            &rparamcnt, NULL,   /* no RX params */
-            rdlen, rdata, more);
-
-        if (err)
+        if (nsmb_ioctl(fd, SMBIOC_XACTNP, &ioc) == -1) {
                 *rdlen = 0;
+                return (-1);
+        }
 
-        return (err);
+        *rdlen = ioc.ioc_rdlen;
+        *more  = ioc.ioc_more;
+
+        return (0);
 }