xref: /illumos-gate/usr/src/cmd/fs.d/smbclnt/fksmbcl/fkdev.c (revision 0245b61fd282e95735b173b8d95be0d6688163b4)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
14  */
15 
16 /*
17  * This file implements device open/close/ioctl wrappers that
18  * redirect access from the real "nsmb" device to the in-process
19  * device simulation in libfknsmb.
20  */
21 
22 #include <sys/param.h>
23 #include <sys/ioctl.h>
24 #include <sys/time.h>
25 #include <sys/mount.h>
26 #include <sys/types.h>
27 #include <sys/byteorder.h>
28 
29 #include <fcntl.h>
30 #include <ctype.h>
31 #include <errno.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <strings.h>
35 #include <stdlib.h>
36 #include <pwd.h>
37 #include <grp.h>
38 #include <unistd.h>
39 #include <libintl.h>
40 #include <assert.h>
41 #include <nss_dbdefs.h>
42 
43 #include <cflib.h>
44 #include <netsmb/smb_lib.h>
45 #include <netsmb/netbios.h>
46 #include <netsmb/nb_lib.h>
47 #include <netsmb/smb_dev.h>
48 
49 #include <libfknsmb/common/libfknsmb.h>
50 
51 #include "smb/charsets.h"
52 #include "smb/private.h"
53 
54 int
55 smb_open_driver(void)
56 {
57 	dev32_t dev;
58 	int fd;
59 	int rc;
60 
61 	rc = nsmb_drv_open(&dev, 0, 0);
62 	if (rc != 0) {
63 		errno = rc;
64 		return (-1);
65 	}
66 
67 	assert((dev & 0xFFFF0000) != 0);
68 	fd = (int)dev;
69 
70 	return (fd);
71 }
72 
73 int
74 nsmb_ioctl(int fd, int cmd, void *arg)
75 {
76 	dev32_t dev;
77 	int err;
78 
79 	dev = (dev32_t)fd;
80 	assert((dev & 0xFFFF0000) != 0);
81 	err = nsmb_drv_ioctl(dev, cmd, (intptr_t)arg, 0);
82 	if (err != 0) {
83 		errno = err;
84 		return (-1);
85 	}
86 	return (0);
87 }
88 
89 int
90 nsmb_close(int fd)
91 {
92 	dev32_t dev;
93 
94 	dev = (dev32_t)fd;
95 	assert((dev & 0xFFFF0000) != 0);
96 	(void) nsmb_drv_close(dev, 0, 0);
97 	return (0);
98 }
99