xref: /titanic_50/usr/src/uts/common/fs/smbsrv/smb2_ofile.c (revision 24bb1048b1197ebc9afe761e4098573aeedfe8c9)
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 2013 Nexenta Systems, Inc.  All rights reserved.
14  */
15 
16 /*
17  * Helper functions for SMB2 open handles
18  */
19 
20 #include <smbsrv/smb2_kproto.h>
21 
22 uint32_t
23 smb2_ofile_getattr(smb_request_t *sr, smb_ofile_t *of, smb_attr_t *ap)
24 {
25 	uint_t mask;
26 	int rc;
27 
28 	mask = ap->sa_mask;
29 	bzero(ap, sizeof (*ap));
30 	ap->sa_mask = mask;
31 
32 	switch (of->f_ftype) {
33 	case SMB_FTYPE_DISK:
34 	case SMB_FTYPE_PRINTER:
35 		rc = smb_node_getattr(sr, of->f_node, of->f_cr, of, ap);
36 		break;
37 	case SMB_FTYPE_BYTE_PIPE:
38 	case SMB_FTYPE_MESG_PIPE:
39 		rc = smb_opipe_getattr(of, ap);
40 		break;
41 	default:
42 		rc = ENOTTY;
43 		break;
44 	}
45 	if (rc)
46 		return (smb_errno2status(rc));
47 
48 	return (0);
49 }
50 
51 /*
52  * Get the stuff needed by FileStandardInformation that was
53  * not already obtained by smb2_ofile_getattr().
54  * (qi_delete_on_close, qi_isdir)
55  */
56 uint32_t
57 smb2_ofile_getstd(smb_ofile_t *of, smb_queryinfo_t *qi)
58 {
59 	smb_node_t *node;
60 
61 	switch (of->f_ftype) {
62 	case SMB_FTYPE_DISK:
63 	case SMB_FTYPE_PRINTER:
64 		node = of->f_node;
65 		qi->qi_delete_on_close =
66 		    (node->flags & NODE_FLAGS_DELETE_ON_CLOSE) != 0;
67 		qi->qi_isdir = smb_node_is_dir(node);
68 		break;
69 	case SMB_FTYPE_BYTE_PIPE:
70 	case SMB_FTYPE_MESG_PIPE:
71 		qi->qi_delete_on_close = 1;
72 		qi->qi_isdir = 0;
73 		break;
74 	default:
75 		return (NT_STATUS_INVALID_DEVICE_REQUEST);
76 	}
77 
78 	return (0);
79 }
80 
81 /*
82  * Get info for FileNameInformation, FileAlternateNameInformation.
83  * (qi_name, qi_shortname)
84  */
85 uint32_t
86 smb2_ofile_getname(smb_ofile_t *of, smb_queryinfo_t *qi)
87 {
88 	int rc;
89 
90 	switch (of->f_ftype) {
91 	case SMB_FTYPE_DISK:
92 	case SMB_FTYPE_PRINTER:
93 		rc = smb_node_getshrpath(of->f_node, of->f_tree,
94 		    qi->qi_name, MAXPATHLEN);
95 		break;
96 	case SMB_FTYPE_BYTE_PIPE:
97 	case SMB_FTYPE_MESG_PIPE:
98 		rc = smb_opipe_getname(of, qi->qi_name, MAXPATHLEN);
99 		break;
100 	default:
101 		rc = ENOTTY;
102 		break;
103 	}
104 	if (rc)
105 		return (smb_errno2status(rc));
106 	qi->qi_namelen = smb_wcequiv_strlen(qi->qi_name);
107 
108 	return (0);
109 
110 }
111