1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Function prototypes for the SMB module.
28  */
29 
30 #ifndef _SMB_KPROTO_H_
31 #define	_SMB_KPROTO_H_
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/systm.h>
40 #include <sys/socket.h>
41 #include <sys/strsubr.h>
42 #include <sys/socketvar.h>
43 #include <sys/cred.h>
44 #include <smbsrv/smb_vops.h>
45 #include <smbsrv/smb_xdr.h>
46 #include <smbsrv/smb_token.h>
47 #include <smbsrv/smb_ktypes.h>
48 #include <smbsrv/smb_ioctl.h>
49 
50 extern	int smb_maxbufsize;
51 extern	int smb_flush_required;
52 extern	int smb_dirsymlink_enable;
53 extern	int smb_announce_quota;
54 extern	clock_t	smb_oplock_timeout;
55 
56 #define	smb_gmt2local(_sr_, _gmt_)	((_gmt_) + (_sr_)->sr_gmtoff)
57 #define	smb_local2gmt(_sr_, _local_)	((_local_) - (_sr_)->sr_gmtoff)
58 
59 int		fd_dealloc(int);
60 
61 off_t		lseek(int fildes, off_t offset, int whence);
62 
63 int		arpioctl(int cmd, void *data);
64 /* Why? uint32_t	inet_addr(char *str); */
65 int		microtime(timestruc_t *tvp);
66 int		clock_get_uptime(void);
67 
68 /*
69  * SMB request handers called from the dispatcher.
70  */
71 #define	SMB_SDT_OPS(NAME)	\
72 	smb_pre_##NAME,		\
73 	smb_com_##NAME,		\
74 	smb_post_##NAME
75 
76 #define	SMB_COM_DECL(NAME)				\
77 	smb_sdrc_t smb_pre_##NAME(smb_request_t *);	\
78 	smb_sdrc_t smb_com_##NAME(smb_request_t *);	\
79 	void smb_post_##NAME(smb_request_t *)
80 
81 SMB_COM_DECL(check_directory);
82 SMB_COM_DECL(close);
83 SMB_COM_DECL(close_and_tree_disconnect);
84 SMB_COM_DECL(close_print_file);
85 SMB_COM_DECL(create);
86 SMB_COM_DECL(create_directory);
87 SMB_COM_DECL(create_new);
88 SMB_COM_DECL(create_temporary);
89 SMB_COM_DECL(delete);
90 SMB_COM_DECL(delete_directory);
91 SMB_COM_DECL(echo);
92 SMB_COM_DECL(find);
93 SMB_COM_DECL(find_close);
94 SMB_COM_DECL(find_close2);
95 SMB_COM_DECL(find_unique);
96 SMB_COM_DECL(flush);
97 SMB_COM_DECL(get_print_queue);
98 SMB_COM_DECL(invalid);
99 SMB_COM_DECL(ioctl);
100 SMB_COM_DECL(lock_and_read);
101 SMB_COM_DECL(lock_byte_range);
102 SMB_COM_DECL(locking_andx);
103 SMB_COM_DECL(logoff_andx);
104 SMB_COM_DECL(negotiate);
105 SMB_COM_DECL(nt_cancel);
106 SMB_COM_DECL(nt_create_andx);
107 SMB_COM_DECL(nt_transact);
108 SMB_COM_DECL(nt_transact_secondary);
109 SMB_COM_DECL(open);
110 SMB_COM_DECL(open_andx);
111 SMB_COM_DECL(open_print_file);
112 SMB_COM_DECL(process_exit);
113 SMB_COM_DECL(query_information);
114 SMB_COM_DECL(query_information2);
115 SMB_COM_DECL(query_information_disk);
116 SMB_COM_DECL(read);
117 SMB_COM_DECL(read_andx);
118 SMB_COM_DECL(read_raw);
119 SMB_COM_DECL(rename);
120 SMB_COM_DECL(search);
121 SMB_COM_DECL(seek);
122 SMB_COM_DECL(session_setup_andx);
123 SMB_COM_DECL(set_information);
124 SMB_COM_DECL(set_information2);
125 SMB_COM_DECL(transaction);
126 SMB_COM_DECL(transaction2);
127 SMB_COM_DECL(transaction2_secondary);
128 SMB_COM_DECL(transaction_secondary);
129 SMB_COM_DECL(tree_connect);
130 SMB_COM_DECL(tree_connect_andx);
131 SMB_COM_DECL(tree_disconnect);
132 SMB_COM_DECL(unlock_byte_range);
133 SMB_COM_DECL(write);
134 SMB_COM_DECL(write_and_close);
135 SMB_COM_DECL(write_and_unlock);
136 SMB_COM_DECL(write_andx);
137 SMB_COM_DECL(write_print_file);
138 SMB_COM_DECL(write_raw);
139 
140 #define	SMB_NT_TRANSACT_DECL(NAME)				\
141 	smb_sdrc_t smb_pre_##NAME(smb_request_t *, smb_xa_t *);	\
142 	smb_sdrc_t smb_##NAME(smb_request_t *, smb_xa_t *);	\
143 	void smb_post_##NAME(smb_request_t *, smb_xa_t *)
144 
145 SMB_NT_TRANSACT_DECL(nt_transact_create);
146 
147 int smb_notify_init(void);
148 void smb_notify_fini(void);
149 
150 smb_sdrc_t smb_nt_transact_notify_change(struct smb_request *, struct smb_xa *);
151 smb_sdrc_t smb_nt_transact_query_security_info(struct smb_request *,
152     struct smb_xa *);
153 smb_sdrc_t smb_nt_transact_set_security_info(struct smb_request *,
154     struct smb_xa *);
155 smb_sdrc_t smb_nt_transact_ioctl(struct smb_request *, struct smb_xa *);
156 
157 smb_sdrc_t smb_com_trans2_create_directory(struct smb_request *,
158     struct smb_xa *);
159 smb_sdrc_t smb_com_trans2_find_first2(struct smb_request *, struct smb_xa *);
160 smb_sdrc_t smb_com_trans2_find_next2(struct smb_request *, struct smb_xa *);
161 smb_sdrc_t smb_com_trans2_query_fs_information(struct smb_request *,
162     struct smb_xa *);
163 smb_sdrc_t smb_com_trans2_query_path_information(struct smb_request *,
164     struct smb_xa *);
165 smb_sdrc_t smb_com_trans2_query_file_information(struct smb_request *,
166     struct smb_xa *);
167 smb_sdrc_t smb_com_trans2_set_path_information(struct smb_request *,
168     struct smb_xa *);
169 smb_sdrc_t smb_com_trans2_set_file_information(struct smb_request *,
170     struct smb_xa *);
171 
172 /*
173  * Logging functions
174  */
175 void smb_log_flush(void);
176 void smb_correct_keep_alive_values(uint32_t new_keep_alive);
177 void smb_close_all_connections(void);
178 int smb_set_file_size(smb_request_t *, smb_node_t *);
179 int smb_session_send(smb_session_t *, uint8_t type, struct mbuf_chain *);
180 int smb_session_xprt_gethdr(smb_session_t *, smb_xprt_t *);
181 
182 int smb_net_id(uint32_t);
183 
184 void smb_process_file_notify_change_queue(struct smb_ofile *of);
185 
186 DWORD smb_oplock_acquire(struct smb_request *, struct smb_ofile *,
187     struct open_param *);
188 void smb_oplock_break(struct smb_node *);
189 void smb_oplock_release(struct smb_node *, boolean_t);
190 boolean_t smb_oplock_conflict(struct smb_node *, struct smb_session *,
191     struct open_param *);
192 
193 /*
194  * macros used in oplock processing
195  *
196  * SMB_SAME_SESSION: Checks for equivalence
197  * of session.  If an existing oplock is
198  * from the same IP address/session as the current
199  * request, the oplock is not broken.
200  *
201  * SMB_ATTR_ONLY_OPEN: Checks to see if this is
202  * an attribute-only open with no contravening
203  * dispositions.  Such an open cannot effect an
204  * oplock break.  However, a contravening disposition
205  * of FILE_SUPERSEDE or FILE_OVERWRITE can allow
206  * an oplock break.
207  */
208 
209 #define	SMB_SAME_SESSION(sess1, sess2)				\
210 	((sess1) && (sess2) &&					\
211 	((sess1)->ipaddr == (sess2)->ipaddr) &&			\
212 	((sess1)->s_kid == (sess2)->s_kid))			\
213 
214 #define	SMB_ATTR_ONLY_OPEN(op)					\
215 	((op) && (op)->desired_access &&			\
216 	(((op)->desired_access & ~(FILE_READ_ATTRIBUTES |	\
217 	FILE_WRITE_ATTRIBUTES | SYNCHRONIZE)) == 0) &&		\
218 	((op)->create_disposition != FILE_SUPERSEDE) &&		\
219 	((op)->create_disposition != FILE_OVERWRITE))		\
220 
221 uint32_t smb_unlock_range(struct smb_request *, struct smb_node *,
222     uint64_t, uint64_t);
223 uint32_t smb_lock_range(smb_request_t *, uint64_t, uint64_t, uint32_t,
224     uint32_t locktype);
225 void smb_lock_range_error(smb_request_t *, uint32_t);
226 
227 DWORD smb_range_check(smb_request_t *, cred_t *, smb_node_t *,
228     uint64_t, uint64_t, boolean_t);
229 
230 int smb_mangle_name(ino64_t fileid, char *name, char *shortname,
231     char *name83, int force);
232 int smb_unmangle_name(struct smb_request *sr, cred_t *cred,
233     smb_node_t *dir_node, char *name, char *real_name, int realname_size,
234     char *shortname, char *name83, int od);
235 int smb_maybe_mangled_name(char *name);
236 int smb_maybe_mangled_path(const char *path, size_t pathlen);
237 int smb_needs_mangle(char *name, char **dot_pos);
238 
239 void smbsr_cleanup(struct smb_request *sr);
240 
241 int smbsr_connect_tree(struct smb_request *);
242 
243 int smb_common_create_directory(struct smb_request *);
244 
245 int		smb_convert_unicode_wildcards(char *);
246 int	smb_ascii_or_unicode_strlen(struct smb_request *, char *);
247 int	smb_ascii_or_unicode_strlen_null(struct smb_request *, char *);
248 int	smb_ascii_or_unicode_null_len(struct smb_request *);
249 
250 int	smb_search(struct smb_request *);
251 void smb_rdir_close(struct smb_request *);
252 int	smb_rdir_open(struct smb_request *, char *, unsigned short);
253 int smb_rdir_next(smb_request_t *sr, smb_node_t **rnode,
254     smb_odir_context_t *pc);
255 
256 uint32_t smb_common_open(smb_request_t *);
257 DWORD smb_validate_object_name(char *path, unsigned int ftype);
258 
259 uint32_t smb_omode_to_amask(uint32_t desired_access);
260 
261 void	sshow_distribution_info(char *);
262 
263 void	smb_dispatch_request(struct smb_request *);
264 void	smbsr_disconnect_file(smb_request_t *);
265 void	smbsr_disconnect_dir(smb_request_t *);
266 int	smbsr_encode_empty_result(struct smb_request *);
267 
268 int	smbsr_decode_vwv(struct smb_request *sr, char *fmt, ...);
269 int	smbsr_decode_data(struct smb_request *sr, char *fmt, ...);
270 int	smbsr_encode_result(struct smb_request *, int, int, char *, ...);
271 smb_xa_t *smbsr_lookup_xa(smb_request_t *sr);
272 void	smbsr_send_reply(struct smb_request *);
273 
274 void	smbsr_map_errno(int, smb_error_t *);
275 void	smbsr_set_error(smb_request_t *, smb_error_t *);
276 void	smbsr_errno(struct smb_request *, int);
277 void	smbsr_warn(struct smb_request *, DWORD, uint16_t, uint16_t);
278 void	smbsr_error(struct smb_request *, DWORD, uint16_t, uint16_t);
279 
280 int	smb_mbc_encode(struct mbuf_chain *mbc, char *fmt, va_list ap);
281 int	smb_mbc_decode(struct mbuf_chain *mbc, char *fmt, va_list ap);
282 
283 int	clock_get_milli_uptime(void);
284 int	dosfs_dos_to_ux_time(int, int);
285 int	dosfs_ux_to_dos_time(int, short int *, short int *);
286 
287 int	smb_decode_mbc(struct  mbuf_chain *mbc, char *fmt, ...);
288 int	smb_decode_buf(unsigned char *buf, int n_buf, char *fmt, ...);
289 int	smb_encode_mbc(struct mbuf_chain *mbc, char *fmt, ...);
290 int	smb_encode_buf(unsigned char *buf, int n_buf, char *fmt, ...);
291 int	smb_peek_mbc(struct mbuf_chain *buf, int offset, char *fmt, ...);
292 int	smb_poke_mbc(struct mbuf_chain *buf, int offset, char *fmt, ...);
293 
294 void	smbsr_encode_header(struct smb_request *sr, int wct,
295 		    int bcc, char *fmt, ...);
296 
297 int	smb_xlate_dialect_str_to_cd(char *);
298 char	*smb_xlate_com_cd_to_str(int);
299 char	*smb_xlate_dialect_cd_to_str(int);
300 
301 void	smb_od_destruct(struct smb_session *, struct smb_odir *);
302 int	smbd_fs_query(struct smb_request *, struct smb_fqi *, int);
303 int smb_component_match(struct smb_request *sr, ino64_t fileid,
304     struct smb_odir *od, smb_odir_context_t *pc);
305 
306 int smb_lock_range_access(struct smb_request *, struct smb_node *,
307     uint64_t, uint64_t, boolean_t);
308 
309 uint32_t smb_decode_sd(struct smb_xa *, smb_sd_t *);
310 
311 /*
312  * Socket functions
313  */
314 struct sonode *smb_socreate(int domain, int type, int protocol);
315 void smb_soshutdown(struct sonode *so);
316 void smb_sodestroy(struct sonode *so);
317 int smb_sorecv(struct sonode *so, void *msg, size_t len);
318 int smb_iov_sorecv(struct sonode *so, iovec_t *iop, int iovlen,
319     size_t total_len);
320 int smb_net_init(void);
321 void smb_net_fini(void);
322 void smb_net_txl_constructor(smb_txlst_t *);
323 void smb_net_txl_destructor(smb_txlst_t *);
324 smb_txreq_t *smb_net_txr_alloc(void);
325 void smb_net_txr_free(smb_txreq_t *);
326 int smb_net_txr_send(struct sonode *, smb_txlst_t *, smb_txreq_t *);
327 
328 /*
329  * SMB RPC interface
330  */
331 int smb_rpc_open(struct smb_request *);
332 void smb_rpc_close(struct smb_ofile *);
333 smb_sdrc_t smb_rpc_transact(struct smb_request *, struct uio *);
334 int smb_rpc_read(struct smb_request *, struct uio *);
335 int smb_rpc_write(struct smb_request *, struct uio *);
336 
337 /*
338  * SMB server functions (file smb_server.c)
339  */
340 int smb_server_svc_init(void);
341 int smb_server_svc_fini(void);
342 int smb_server_create(void);
343 int smb_server_delete(void);
344 int smb_server_configure(smb_kmod_cfg_t *cfg);
345 int smb_server_start(struct smb_io_start *);
346 int smb_server_nbt_listen(int);
347 int smb_server_tcp_listen(int);
348 int smb_server_nbt_receive(void);
349 int smb_server_tcp_receive(void);
350 uint32_t smb_server_get_user_count(void);
351 uint32_t smb_server_get_session_count(void);
352 void smb_server_disconnect_share(char *);
353 void smb_server_disconnect_volume(fs_desc_t *);
354 int smb_server_dr_ulist_get(int, smb_dr_ulist_t *, int);
355 int smb_server_share_export(char *);
356 int smb_server_share_unexport(char *, char *);
357 int smb_server_set_gmtoff(uint32_t goff);
358 
359 void smb_server_reconnection_check(smb_server_t *, smb_session_t *);
360 void smb_server_get_cfg(smb_server_t *, smb_kmod_cfg_t *);
361 
362 /*
363  * SMB node functions (file smb_node.c)
364  */
365 int smb_node_init(void);
366 void smb_node_fini(void);
367 struct smb_node *smb_node_lookup(struct smb_request *sr, struct open_param *op,
368     cred_t *cr, vnode_t *vp, char *od_name, smb_node_t *dir_snode,
369     smb_node_t *unnamed_node, smb_attr_t *attr);
370 struct smb_node *smb_stream_node_lookup(struct smb_request *sr, cred_t *cr,
371     smb_node_t *fnode, vnode_t *xattrdirvp, vnode_t *vp, char *stream_name,
372     smb_attr_t *ret_attr);
373 void smb_node_ref(smb_node_t *node);
374 void smb_node_release(smb_node_t *node);
375 int smb_node_assert(smb_node_t *node, const char *file, int line);
376 int smb_node_rename(smb_node_t *from_dir_snode, smb_node_t *ret_snode,
377     smb_node_t *to_dir_snode, char *to_name);
378 int smb_node_root_init(vnode_t *, smb_server_t *, smb_node_t **);
379 void smb_node_add_lock(smb_node_t *node, smb_lock_t *lock);
380 void smb_node_destroy_lock(smb_node_t *node, smb_lock_t *lock);
381 void smb_node_destroy_lock_by_ofile(smb_node_t *node, smb_ofile_t *file);
382 void smb_node_start_crit(smb_node_t *node, krw_t mode);
383 void smb_node_end_crit(smb_node_t *node);
384 int smb_node_in_crit(smb_node_t *node);
385 
386 uint32_t smb_node_open_check(smb_node_t *, cred_t *,
387     uint32_t, uint32_t);
388 DWORD smb_node_rename_check(smb_node_t *);
389 DWORD smb_node_delete_check(smb_node_t *);
390 
391 u_offset_t smb_node_get_size(smb_node_t *, smb_attr_t *);
392 void smb_node_set_time(struct smb_node *node, timestruc_t *crtime,
393     timestruc_t *mtime, timestruc_t *atime,
394     timestruc_t *ctime, unsigned int what);
395 timestruc_t *smb_node_get_crtime(struct smb_node *node);
396 timestruc_t *smb_node_get_atime(struct smb_node *node);
397 timestruc_t *smb_node_get_ctime(struct smb_node *node);
398 timestruc_t *smb_node_get_mtime(struct smb_node *node);
399 void smb_node_set_dosattr(struct smb_node *, uint32_t);
400 uint32_t smb_node_get_dosattr(struct smb_node *node);
401 int smb_node_set_delete_on_close(smb_node_t *, cred_t *);
402 void smb_node_reset_delete_on_close(smb_node_t *);
403 
404 
405 
406 /*
407  * Pathname functions
408  */
409 
410 int smb_pathname_reduce(struct smb_request *, cred_t *,
411     const char *, smb_node_t *, smb_node_t *, smb_node_t **, char *);
412 
413 int smb_pathname(struct smb_request *, char *, int, smb_node_t *,
414     smb_node_t *, smb_node_t **, smb_node_t **, cred_t *);
415 
416 /*
417  * smb_vfs functions
418  */
419 
420 boolean_t smb_vfs_hold(smb_server_t *, vfs_t *);
421 void smb_vfs_rele(smb_server_t *, vfs_t *);
422 void smb_vfs_rele_all(smb_server_t *);
423 
424 /*
425  * String manipulation function
426  */
427 char *smb_kstrdup(const char *s, size_t n);
428 
429 int smb_sync_fsattr(struct smb_request *sr, cred_t *cr,
430     struct smb_node *node);
431 
432 DWORD	smb_validate_dirname(char *path);
433 
434 
435 void smb_encode_stream_info(struct smb_request *sr, struct smb_xa *xa,
436     smb_node_t *snode, smb_attr_t *attr);
437 
438 /* NOTIFY CHANGE */
439 void smb_process_session_notify_change_queue(struct smb_session *session);
440 void smb_process_node_notify_change_queue(struct smb_node *node);
441 void smb_reply_specific_cancel_request(struct smb_request *sr);
442 
443 void smb_fem_fcn_install(smb_node_t *node);
444 void smb_fem_fcn_uninstall(smb_node_t *node);
445 
446 /* FEM */
447 
448 int smb_fem_init(void);
449 void smb_fem_fini(void);
450 
451 int smb_try_grow(struct smb_request *sr, int64_t new_size);
452 
453 /* functions from smb_memory_manager.c */
454 
455 void	*smbsr_malloc(smb_malloc_list *, size_t);
456 void	*smbsr_realloc(void *, size_t);
457 void	smbsr_free_malloc_list(smb_malloc_list *);
458 
459 void smbsr_rq_notify(smb_request_t *sr,
460     smb_session_t *session, smb_tree_t *tree);
461 
462 unsigned short smb_worker_getnum();
463 int smb_common_close(struct smb_request *sr, uint32_t last_wtime);
464 void smb_preset_delete_on_close(struct smb_ofile *file);
465 void smb_commit_delete_on_close(struct smb_ofile *file);
466 
467 int smb_stream_parse_name(char *name, char *u_stream_name,
468     char *stream_name);
469 
470 DWORD smb_trans2_set_information(struct smb_request *sr,
471     smb_trans2_setinfo_t *info,
472     smb_error_t *smberr);
473 
474 /* SMB signing routines smb_signing.c */
475 void smb_sign_init(struct smb_request *req,
476 	smb_session_key_t *session_key, char *resp, int resp_len);
477 
478 int smb_sign_check_request(struct smb_request *req);
479 
480 int smb_sign_check_secondary(struct smb_request *req, unsigned int seqnum);
481 
482 void smb_sign_reply(struct smb_request *req, struct mbuf_chain *reply);
483 
484 uint32_t smb_mode_to_dos_attributes(smb_attr_t *ap);
485 int smb_sattr_check(smb_attr_t *ap, char *name, unsigned short sattr);
486 
487 void smb_request_cancel(smb_request_t *sr);
488 
489 /*
490  * session functions (file smb_session.c)
491  */
492 smb_session_t *smb_session_create(struct sonode *, uint16_t, smb_server_t *);
493 int smb_session_daemon(smb_session_list_t *);
494 void smb_session_reconnection_check(smb_session_list_t *, smb_session_t *);
495 void smb_session_timers(smb_session_list_t *);
496 void smb_session_delete(smb_session_t *session);
497 void smb_session_cancel(smb_session_t *session);
498 void smb_session_cancel_requests(smb_session_t *session);
499 void smb_session_config(smb_session_t *session);
500 void smb_session_disconnect_share(smb_session_list_t *, char *);
501 void smb_session_disconnect_volume(smb_session_list_t *, fs_desc_t *);
502 void smb_session_list_constructor(smb_session_list_t *);
503 void smb_session_list_destructor(smb_session_list_t *);
504 void smb_session_list_append(smb_session_list_t *, smb_session_t *);
505 void smb_session_list_delete_tail(smb_session_list_t *);
506 smb_session_t *smb_session_list_activate_head(smb_session_list_t *);
507 void smb_session_list_terminate(smb_session_list_t *, smb_session_t *);
508 void smb_session_list_signal(smb_session_list_t *);
509 
510 void smb_session_correct_keep_alive_values(smb_session_list_t *, uint32_t);
511 smb_request_t *smb_request_alloc(smb_session_t *, int);
512 void smb_request_free(smb_request_t *);
513 
514 
515 /*
516  * ofile functions (file smb_ofile.c)
517  */
518 smb_ofile_t *smb_ofile_lookup_by_fid(smb_tree_t *tree, uint16_t fid);
519 smb_ofile_t *smb_ofile_open(smb_tree_t *tree, smb_node_t *node, uint16_t pid,
520     uint32_t access_granted, uint32_t create_options, uint32_t share_access,
521     uint16_t ftype, char *pipe_name, uint32_t rpc_fid, uint32_t uniqid,
522     smb_error_t *err);
523 int smb_ofile_close(smb_ofile_t *ofile, uint32_t last_wtime);
524 uint32_t smb_ofile_access(smb_ofile_t *ofile, cred_t *cr, uint32_t access);
525 int smb_ofile_seek(smb_ofile_t *of, ushort_t mode, int32_t off,
526     uint32_t *retoff);
527 void smb_ofile_release(smb_ofile_t *ofile);
528 void smb_ofile_close_all(smb_tree_t *tree);
529 void smb_ofile_close_all_by_pid(smb_tree_t *tree, uint16_t pid);
530 void smb_ofile_set_flags(smb_ofile_t *of, uint32_t flags);
531 void smb_ofile_close_timestamp_update(smb_ofile_t *of, uint32_t last_wtime);
532 boolean_t smb_ofile_is_open(smb_ofile_t *of);
533 uint32_t smb_ofile_open_check(smb_ofile_t *, cred_t *,
534     uint32_t, uint32_t);
535 uint32_t smb_ofile_rename_check(smb_ofile_t *);
536 uint32_t smb_ofile_delete_check(smb_ofile_t *);
537 
538 
539 #define	smb_ofile_granted_access(_of_)	((_of_)->f_granted_access)
540 
541 /*
542  * odir functions (file smb_odir.c)
543  */
544 smb_odir_t *smb_odir_open(smb_tree_t *tree, smb_node_t *node, char *pattern,
545     uint16_t pid, unsigned short sattr);
546 void smb_odir_close(smb_odir_t *od);
547 void smb_odir_close_all(smb_tree_t *tree);
548 void smb_odir_close_all_by_pid(smb_tree_t *tree, uint16_t pid);
549 void smb_odir_release(smb_odir_t *od);
550 smb_odir_t *smb_odir_lookup_by_sid(smb_tree_t *tree, uint16_t sid);
551 
552 /*
553  * SMB user functions (file smb_user.c)
554  */
555 smb_user_t *smb_user_login(smb_session_t *, cred_t *,
556     char *, char *, uint32_t, uint32_t, uint32_t);
557 smb_user_t *smb_user_dup(smb_user_t *);
558 void smb_user_logoff(smb_user_t *user);
559 void smb_user_logoff_all(smb_session_t *session);
560 smb_user_t *smb_user_lookup_by_uid(smb_session_t *, cred_t **, uint16_t);
561 smb_user_t *smb_user_lookup_by_name(smb_session_t *, char *, char *);
562 smb_user_t *smb_user_lookup_by_state(smb_session_t *, smb_user_t *user);
563 void smb_user_disconnect_share(smb_user_t *user, char *sharename);
564 void smb_user_disconnect_volume(smb_user_t *user, fs_desc_t *fsd);
565 void smb_user_release(smb_user_t *user);
566 
567 /*
568  * SMB tree functions (file smb_tree.c)
569  */
570 smb_tree_t *smb_tree_connect(smb_user_t *user, uint16_t access_flags,
571     char *sharename, char *resource, int32_t rt_share,
572     smb_node_t *snode, fsvol_attr_t *vol_attr);
573 void smb_tree_disconnect(smb_tree_t *tree);
574 void smb_tree_disconnect_all(smb_user_t *user);
575 void smb_tree_close_all_by_pid(smb_user_t *user, uint16_t pid);
576 smb_tree_t *smb_tree_lookup_by_tid(smb_user_t *user, uint16_t tid);
577 smb_tree_t *smb_tree_lookup_by_name(smb_user_t *, char *, smb_tree_t *);
578 smb_tree_t *smb_tree_lookup_by_fsd(smb_user_t *, fs_desc_t *, smb_tree_t *);
579 void smb_tree_release(smb_tree_t *tree);
580 
581 void smb_dr_user_free(smb_dr_user_ctx_t *uinfo);
582 void smb_dr_ulist_free(smb_dr_ulist_t *ulist);
583 int smb_dr_user_create(smb_dr_user_ctx_t *, uint64_t, uint16_t, char *, char *,
584     char *, uint32_t, int32_t, time_t, uint32_t);
585 
586 
587 /*
588  * SMB user's credential functions
589  */
590 cred_t *smb_cred_create(smb_token_t *, uint32_t *);
591 void smb_cred_rele(cred_t *cr);
592 int smb_cred_is_member(cred_t *cr, smb_sid_t *sid);
593 
594 smb_xa_t *smb_xa_create(smb_session_t *session, smb_request_t *sr,
595     uint32_t total_parameter_count, uint32_t total_data_count,
596     uint32_t max_parameter_count, uint32_t max_data_count,
597     uint32_t max_setup_count, uint32_t setup_word_count);
598 void smb_xa_delete(smb_xa_t *xa);
599 smb_xa_t *smb_xa_hold(smb_xa_t *xa);
600 void smb_xa_rele(smb_session_t *session, smb_xa_t *xa);
601 int smb_xa_open(smb_xa_t *xa);
602 void smb_xa_close(smb_xa_t *xa);
603 int smb_xa_complete(smb_xa_t *xa);
604 smb_xa_t *smb_xa_find(smb_session_t *session, uint16_t pid, uint16_t mid);
605 
606 struct mbuf *smb_mbuf_get(uchar_t *buf, int nbytes);
607 struct mbuf *smb_mbuf_allocate(struct uio *uio);
608 void smb_mbuf_trim(struct mbuf *mhead, int nbytes);
609 
610 void smb_check_status(void);
611 int smb_handle_write_raw(smb_session_t *session, smb_request_t *sr);
612 
613 void smb_winpipe_init(void);
614 void smb_winpipe_fini(void);
615 int smb_winpipe_open(int door_id);
616 void smb_winpipe_close(void);
617 int smb_winpipe_call(smb_request_t *, mlsvc_pipe_t *, mlsvc_stream_t *,
618     uint16_t, uint32_t *, boolean_t *);
619 
620 void smb_reconnection_check(struct smb_session *session);
621 
622 uint32_t nt_to_unix_time(uint64_t nt_time, timestruc_t *unix_time);
623 uint64_t unix_to_nt_time(timestruc_t *);
624 
625 int netbios_name_isvalid(char *in, char *out);
626 
627 size_t
628 unicodestooems(char *oemstring, const mts_wchar_t *unicodestring,
629     size_t nbytes, unsigned int cpid);
630 
631 size_t oemstounicodes(mts_wchar_t *unicodestring, const char *oemstring,
632     size_t nwchars, unsigned int cpid);
633 
634 int uioxfer(struct uio *src_uio, struct uio *dst_uio, int n);
635 
636 int smb_match_name(ino64_t fileid, char *name, char *shortname,
637     char *name83, char *pattern, int ignore_case);
638 int is_dot_or_dotdot(char *name);
639 int token2buf(smb_token_t *token, char *buf);
640 
641 /*
642  * Pool ID function prototypes
643  */
644 int	smb_idpool_constructor(smb_idpool_t *pool);
645 void	smb_idpool_destructor(smb_idpool_t  *pool);
646 int	smb_idpool_alloc(smb_idpool_t *pool, uint16_t *id);
647 void	smb_idpool_free(smb_idpool_t *pool, uint16_t id);
648 
649 /*
650  * SMB thread function prototypes
651  */
652 void	smb_session_worker(void *arg);
653 
654 /*
655  * SMB locked list function prototypes
656  */
657 void	smb_llist_constructor(smb_llist_t *, size_t, size_t);
658 void	smb_llist_destructor(smb_llist_t *);
659 void	smb_llist_insert_head(smb_llist_t *ll, void *obj);
660 void	smb_llist_insert_tail(smb_llist_t *ll, void *obj);
661 void	smb_llist_remove(smb_llist_t *ll, void *obj);
662 int	smb_llist_upgrade(smb_llist_t *ll);
663 uint32_t smb_llist_get_count(smb_llist_t *ll);
664 #define	smb_llist_enter(ll, mode)	rw_enter(&(ll)->ll_lock, mode)
665 #define	smb_llist_exit(ll)		rw_exit(&(ll)->ll_lock)
666 #define	smb_llist_head(ll)		list_head(&(ll)->ll_list)
667 #define	smb_llist_next(ll, obj)		list_next(&(ll)->ll_list, obj)
668 int	smb_account_connected(smb_user_t *user);
669 
670 /*
671  * SMB Synchronized list function prototypes
672  */
673 void	smb_slist_constructor(smb_slist_t *, size_t, size_t);
674 void	smb_slist_destructor(smb_slist_t *);
675 void	smb_slist_insert_head(smb_slist_t *sl, void *obj);
676 void	smb_slist_insert_tail(smb_slist_t *sl, void *obj);
677 void	smb_slist_remove(smb_slist_t *sl, void *obj);
678 void	smb_slist_wait_for_empty(smb_slist_t *sl);
679 void	smb_slist_exit(smb_slist_t *sl);
680 uint32_t smb_slist_move_tail(list_t *lst, smb_slist_t *sl);
681 void    smb_slist_obj_move(smb_slist_t *dst, smb_slist_t *src, void *obj);
682 #define	smb_slist_enter(sl)		mutex_enter(&(sl)->sl_mutex)
683 #define	smb_slist_head(sl)		list_head(&(sl)->sl_list)
684 #define	smb_slist_next(sl, obj)		list_next(&(sl)->sl_list, obj)
685 
686 void    smb_rwx_init(smb_rwx_t *rwx);
687 void    smb_rwx_destroy(smb_rwx_t *rwx);
688 #define	smb_rwx_rwenter(rwx, mode)	rw_enter(&(rwx)->rwx_lock, mode)
689 void    smb_rwx_rwexit(smb_rwx_t *rwx);
690 int	smb_rwx_rwwait(smb_rwx_t *rwx, clock_t timeout);
691 #define	smb_rwx_xenter(rwx)		mutex_enter(&(rwx)->rwx_mutex)
692 #define	smb_rwx_xexit(rwx)		mutex_exit(&(rwx)->rwx_mutex)
693 krw_t   smb_rwx_rwupgrade(smb_rwx_t *rwx);
694 void    smb_rwx_rwdowngrade(smb_rwx_t *rwx, krw_t mode);
695 
696 void	smb_thread_init(smb_thread_t *, char *, smb_thread_ep_t, void *,
697     smb_thread_aw_t, void *);
698 void	smb_thread_destroy(smb_thread_t *);
699 int	smb_thread_start(smb_thread_t *);
700 void	smb_thread_stop(smb_thread_t *);
701 void    smb_thread_signal(smb_thread_t *);
702 boolean_t smb_thread_continue(smb_thread_t *);
703 boolean_t smb_thread_continue_nowait(smb_thread_t *);
704 boolean_t smb_thread_continue_timedwait(smb_thread_t *, int /* seconds */);
705 void smb_thread_set_awaken(smb_thread_t *, smb_thread_aw_t, void *);
706 
707 uint32_t smb_denymode_to_sharemode(uint32_t desired_access, char *fname);
708 uint32_t smb_ofun_to_crdisposition(uint16_t ofun);
709 
710 void    smb_audit_buf_node_create(smb_node_t *node);
711 void    smb_audit_buf_node_destroy(smb_node_t *node);
712 #define	smb_audit_node(_n_)					\
713 	if ((_n_)->n_audit_buf) {				\
714 		smb_audit_record_node_t	*anr;			\
715 								\
716 		anr = (_n_)->n_audit_buf->anb_records;		\
717 		anr += (_n_)->n_audit_buf->anb_index;		\
718 		(_n_)->n_audit_buf->anb_index++;		\
719 		(_n_)->n_audit_buf->anb_index &=		\
720 		    (_n_)->n_audit_buf->anb_max_index;		\
721 		anr->anr_refcnt = node->n_refcnt;		\
722 		anr->anr_depth = getpcstack(anr->anr_stack,	\
723 		    SMB_AUDIT_STACK_DEPTH);			\
724 	}
725 
726 /* 100's of ns between 1/1/1970 and 1/1/1601 */
727 #define	NT_TIME_BIAS	(134774LL * 24LL * 60LL * 60LL * 10000000LL)
728 
729 void smb_sd_init(smb_sd_t *, uint8_t);
730 void smb_sd_term(smb_sd_t *);
731 uint32_t smb_sd_get_secinfo(smb_sd_t *);
732 uint32_t smb_sd_len(smb_sd_t *, uint32_t);
733 uint32_t smb_sd_tofs(smb_sd_t *, smb_fssd_t *);
734 uint32_t smb_sd_read(smb_request_t *, smb_sd_t *, uint32_t);
735 uint32_t smb_sd_write(smb_request_t *, smb_sd_t *, uint32_t);
736 
737 void smb_fssd_init(smb_fssd_t *, uint32_t, uint32_t);
738 void smb_fssd_term(smb_fssd_t *);
739 
740 void smb_acl_sort(smb_acl_t *);
741 void smb_acl_free(smb_acl_t *);
742 smb_acl_t *smb_acl_alloc(uint8_t, uint16_t, uint16_t);
743 smb_acl_t *smb_acl_from_zfs(acl_t *, uid_t, gid_t);
744 uint32_t smb_acl_to_zfs(smb_acl_t *, uint32_t, int, acl_t **);
745 uint16_t smb_acl_len(smb_acl_t *);
746 boolean_t smb_acl_isvalid(smb_acl_t *, int);
747 
748 void smb_fsacl_free(acl_t *);
749 acl_t *smb_fsacl_alloc(int, int);
750 acl_t *smb_fsacl_inherit(acl_t *, int, int, uid_t);
751 acl_t *smb_fsacl_merge(acl_t *, acl_t *);
752 void smb_fsacl_split(acl_t *, acl_t **, acl_t **, int);
753 acl_t *smb_fsacl_from_vsa(vsecattr_t *, acl_type_t);
754 int smb_fsacl_to_vsa(acl_t *, vsecattr_t *, int *);
755 
756 boolean_t smb_ace_is_generic(int);
757 boolean_t smb_ace_is_access(int);
758 boolean_t smb_ace_is_audit(int);
759 
760 #ifdef	__cplusplus
761 }
762 #endif
763 
764 #endif /* _SMB_KPROTO_H_ */
765