xref: /onnv-gate/usr/src/uts/common/smbsrv/smb_kproto.h (revision 6600:4e63bcd27ae9)
15331Samw /*
25331Samw  * CDDL HEADER START
35331Samw  *
45331Samw  * The contents of this file are subject to the terms of the
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * You may not use this file except in compliance with the License.
75331Samw  *
85331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw  * or http://www.opensolaris.org/os/licensing.
105331Samw  * See the License for the specific language governing permissions
115331Samw  * and limitations under the License.
125331Samw  *
135331Samw  * When distributing Covered Code, include this CDDL HEADER in each
145331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw  * If applicable, add the following below this CDDL HEADER, with the
165331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw  *
195331Samw  * CDDL HEADER END
205331Samw  */
215331Samw /*
225772Sas200622  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
235331Samw  * Use is subject to license terms.
245331Samw  */
255331Samw 
265331Samw /*
275331Samw  * Function prototypes for the SMB module.
285331Samw  */
295331Samw 
305331Samw #ifndef _SMB_KPROTO_H_
315331Samw #define	_SMB_KPROTO_H_
325331Samw 
335331Samw #pragma ident	"%Z%%M%	%I%	%E% SMI"
345331Samw 
355331Samw #ifdef	__cplusplus
365331Samw extern "C" {
375331Samw #endif
385331Samw 
395331Samw #include <sys/systm.h>
405331Samw #include <sys/socket.h>
415331Samw #include <sys/strsubr.h>
425331Samw #include <sys/socketvar.h>
435331Samw #include <sys/cred.h>
445331Samw #include <smbsrv/smb_vops.h>
455331Samw #include <smbsrv/smb_xdr.h>
465331Samw #include <smbsrv/smb_token.h>
476139Sjb150015 #include <smbsrv/smb_ktypes.h>
486139Sjb150015 #include <smbsrv/smb_ioctl.h>
496139Sjb150015 
506139Sjb150015 extern	int smb_maxbufsize;
516139Sjb150015 extern	int smb_flush_required;
526139Sjb150015 extern	int smb_dirsymlink_enable;
536139Sjb150015 extern	int smb_announce_quota;
546139Sjb150015 extern	clock_t	smb_oplock_timeout;
556139Sjb150015 
566139Sjb150015 #define	smb_gmt2local(_sr_, _gmt_)	((_gmt_) + (_sr_)->sr_gmtoff)
576139Sjb150015 #define	smb_local2gmt(_sr_, _local_)	((_local_) - (_sr_)->sr_gmtoff)
585331Samw 
595331Samw int		fd_dealloc(int);
605331Samw 
615331Samw off_t		lseek(int fildes, off_t offset, int whence);
625331Samw 
635331Samw int		arpioctl(int cmd, void *data);
645331Samw /* Why? uint32_t	inet_addr(char *str); */
655331Samw int		microtime(timestruc_t *tvp);
665331Samw int		clock_get_uptime(void);
675331Samw 
685331Samw /*
696030Sjb150015  * SMB request handers called from the dispatcher.
706030Sjb150015  */
716139Sjb150015 #define	SMB_SDT_OPS(NAME)	\
726139Sjb150015 	smb_pre_##NAME,		\
736139Sjb150015 	smb_com_##NAME,		\
746139Sjb150015 	smb_post_##NAME
756139Sjb150015 
766139Sjb150015 #define	SMB_COM_DECL(NAME)				\
776139Sjb150015 	smb_sdrc_t smb_pre_##NAME(smb_request_t *);	\
786139Sjb150015 	smb_sdrc_t smb_com_##NAME(smb_request_t *);	\
796139Sjb150015 	void smb_post_##NAME(smb_request_t *)
806030Sjb150015 
816139Sjb150015 SMB_COM_DECL(check_directory);
826139Sjb150015 SMB_COM_DECL(close);
836139Sjb150015 SMB_COM_DECL(close_and_tree_disconnect);
846139Sjb150015 SMB_COM_DECL(close_print_file);
856139Sjb150015 SMB_COM_DECL(create);
866139Sjb150015 SMB_COM_DECL(create_directory);
876139Sjb150015 SMB_COM_DECL(create_new);
886139Sjb150015 SMB_COM_DECL(create_temporary);
896139Sjb150015 SMB_COM_DECL(delete);
906139Sjb150015 SMB_COM_DECL(delete_directory);
916139Sjb150015 SMB_COM_DECL(echo);
926139Sjb150015 SMB_COM_DECL(find);
936139Sjb150015 SMB_COM_DECL(find_close);
946139Sjb150015 SMB_COM_DECL(find_close2);
956139Sjb150015 SMB_COM_DECL(find_unique);
966139Sjb150015 SMB_COM_DECL(flush);
976139Sjb150015 SMB_COM_DECL(get_print_queue);
986139Sjb150015 SMB_COM_DECL(invalid);
996139Sjb150015 SMB_COM_DECL(ioctl);
1006139Sjb150015 SMB_COM_DECL(lock_and_read);
1016139Sjb150015 SMB_COM_DECL(lock_byte_range);
1026139Sjb150015 SMB_COM_DECL(locking_andx);
1036139Sjb150015 SMB_COM_DECL(logoff_andx);
1046139Sjb150015 SMB_COM_DECL(negotiate);
1056139Sjb150015 SMB_COM_DECL(nt_cancel);
1066139Sjb150015 SMB_COM_DECL(nt_create_andx);
1076139Sjb150015 SMB_COM_DECL(nt_transact);
1086139Sjb150015 SMB_COM_DECL(nt_transact_secondary);
1096139Sjb150015 SMB_COM_DECL(open);
1106139Sjb150015 SMB_COM_DECL(open_andx);
1116139Sjb150015 SMB_COM_DECL(open_print_file);
1126139Sjb150015 SMB_COM_DECL(process_exit);
1136139Sjb150015 SMB_COM_DECL(query_information);
1146139Sjb150015 SMB_COM_DECL(query_information2);
1156139Sjb150015 SMB_COM_DECL(query_information_disk);
1166139Sjb150015 SMB_COM_DECL(read);
1176139Sjb150015 SMB_COM_DECL(read_andx);
1186139Sjb150015 SMB_COM_DECL(read_raw);
1196139Sjb150015 SMB_COM_DECL(rename);
1206139Sjb150015 SMB_COM_DECL(search);
1216139Sjb150015 SMB_COM_DECL(seek);
1226139Sjb150015 SMB_COM_DECL(session_setup_andx);
1236139Sjb150015 SMB_COM_DECL(set_information);
1246139Sjb150015 SMB_COM_DECL(set_information2);
1256139Sjb150015 SMB_COM_DECL(transaction);
1266139Sjb150015 SMB_COM_DECL(transaction2);
1276139Sjb150015 SMB_COM_DECL(transaction2_secondary);
1286139Sjb150015 SMB_COM_DECL(transaction_secondary);
1296139Sjb150015 SMB_COM_DECL(tree_connect);
1306139Sjb150015 SMB_COM_DECL(tree_connect_andx);
1316139Sjb150015 SMB_COM_DECL(tree_disconnect);
1326139Sjb150015 SMB_COM_DECL(unlock_byte_range);
1336139Sjb150015 SMB_COM_DECL(write);
1346139Sjb150015 SMB_COM_DECL(write_and_close);
1356139Sjb150015 SMB_COM_DECL(write_and_unlock);
1366139Sjb150015 SMB_COM_DECL(write_andx);
1376139Sjb150015 SMB_COM_DECL(write_print_file);
1386139Sjb150015 SMB_COM_DECL(write_raw);
1396139Sjb150015 
1406139Sjb150015 #define	SMB_NT_TRANSACT_DECL(NAME)				\
1416139Sjb150015 	smb_sdrc_t smb_pre_##NAME(smb_request_t *, smb_xa_t *);	\
1426139Sjb150015 	smb_sdrc_t smb_##NAME(smb_request_t *, smb_xa_t *);	\
1436139Sjb150015 	void smb_post_##NAME(smb_request_t *, smb_xa_t *)
1446139Sjb150015 
1456139Sjb150015 SMB_NT_TRANSACT_DECL(nt_transact_create);
1466139Sjb150015 
1476139Sjb150015 int smb_notify_init(void);
1486139Sjb150015 void smb_notify_fini(void);
1496139Sjb150015 
1506030Sjb150015 smb_sdrc_t smb_nt_transact_notify_change(struct smb_request *, struct smb_xa *);
1516030Sjb150015 smb_sdrc_t smb_nt_transact_query_security_info(struct smb_request *,
1526030Sjb150015     struct smb_xa *);
1536030Sjb150015 smb_sdrc_t smb_nt_transact_set_security_info(struct smb_request *,
1546030Sjb150015     struct smb_xa *);
1556030Sjb150015 smb_sdrc_t smb_nt_transact_ioctl(struct smb_request *, struct smb_xa *);
1566030Sjb150015 
1576030Sjb150015 smb_sdrc_t smb_com_trans2_create_directory(struct smb_request *,
1586030Sjb150015     struct smb_xa *);
1596030Sjb150015 smb_sdrc_t smb_com_trans2_find_first2(struct smb_request *, struct smb_xa *);
1606030Sjb150015 smb_sdrc_t smb_com_trans2_find_next2(struct smb_request *, struct smb_xa *);
1616030Sjb150015 smb_sdrc_t smb_com_trans2_query_fs_information(struct smb_request *,
1626030Sjb150015     struct smb_xa *);
1636030Sjb150015 smb_sdrc_t smb_com_trans2_query_path_information(struct smb_request *,
1646030Sjb150015     struct smb_xa *);
1656030Sjb150015 smb_sdrc_t smb_com_trans2_query_file_information(struct smb_request *,
1666030Sjb150015     struct smb_xa *);
1676030Sjb150015 smb_sdrc_t smb_com_trans2_set_path_information(struct smb_request *,
1686030Sjb150015     struct smb_xa *);
1696030Sjb150015 smb_sdrc_t smb_com_trans2_set_file_information(struct smb_request *,
1706030Sjb150015     struct smb_xa *);
1716030Sjb150015 
1726030Sjb150015 /*
1735331Samw  * Logging functions
1745331Samw  */
1755331Samw void smb_log_flush(void);
1765331Samw void smb_correct_keep_alive_values(uint32_t new_keep_alive);
1775331Samw void smb_close_all_connections(void);
178*6600Sas200622 int smb_set_file_size(smb_request_t *, smb_node_t *);
1795331Samw int smb_session_send(smb_session_t *, uint8_t type, struct mbuf_chain *);
1805331Samw int smb_session_xprt_gethdr(smb_session_t *, smb_xprt_t *);
1815331Samw 
1825331Samw int smb_net_id(uint32_t);
1835331Samw 
1845331Samw void smb_process_file_notify_change_queue(struct smb_ofile *of);
1855331Samw 
186*6600Sas200622 DWORD smb_oplock_acquire(struct smb_request *, struct smb_ofile *,
187*6600Sas200622     struct open_param *);
188*6600Sas200622 void smb_oplock_break(struct smb_node *);
189*6600Sas200622 void smb_oplock_release(struct smb_node *, boolean_t);
190*6600Sas200622 boolean_t smb_oplock_conflict(struct smb_node *, struct smb_session *,
191*6600Sas200622     struct open_param *);
1925331Samw 
193*6600Sas200622 /*
194*6600Sas200622  * macros used in oplock processing
195*6600Sas200622  *
196*6600Sas200622  * SMB_SAME_SESSION: Checks for equivalence
197*6600Sas200622  * of session.  If an existing oplock is
198*6600Sas200622  * from the same IP address/session as the current
199*6600Sas200622  * request, the oplock is not broken.
200*6600Sas200622  *
201*6600Sas200622  * SMB_ATTR_ONLY_OPEN: Checks to see if this is
202*6600Sas200622  * an attribute-only open with no contravening
203*6600Sas200622  * dispositions.  Such an open cannot effect an
204*6600Sas200622  * oplock break.  However, a contravening disposition
205*6600Sas200622  * of FILE_SUPERSEDE or FILE_OVERWRITE can allow
206*6600Sas200622  * an oplock break.
207*6600Sas200622  */
2085331Samw 
209*6600Sas200622 #define	SMB_SAME_SESSION(sess1, sess2)				\
210*6600Sas200622 	((sess1) && (sess2) &&					\
211*6600Sas200622 	((sess1)->ipaddr == (sess2)->ipaddr) &&			\
212*6600Sas200622 	((sess1)->s_kid == (sess2)->s_kid))			\
213*6600Sas200622 
214*6600Sas200622 #define	SMB_ATTR_ONLY_OPEN(op)					\
215*6600Sas200622 	((op) && (op)->desired_access &&			\
216*6600Sas200622 	(((op)->desired_access & ~(FILE_READ_ATTRIBUTES |	\
217*6600Sas200622 	FILE_WRITE_ATTRIBUTES | SYNCHRONIZE)) == 0) &&		\
218*6600Sas200622 	((op)->create_disposition != FILE_SUPERSEDE) &&		\
219*6600Sas200622 	((op)->create_disposition != FILE_OVERWRITE))		\
2205331Samw 
2215331Samw uint32_t smb_unlock_range(struct smb_request *, struct smb_node *,
2225331Samw     uint64_t, uint64_t);
2236432Sas200622 uint32_t smb_lock_range(smb_request_t *, uint64_t, uint64_t, uint32_t,
2246432Sas200622     uint32_t locktype);
2255772Sas200622 void smb_lock_range_error(smb_request_t *, uint32_t);
2265772Sas200622 
2275772Sas200622 DWORD smb_range_check(smb_request_t *, cred_t *, smb_node_t *,
2285772Sas200622     uint64_t, uint64_t, boolean_t);
2295331Samw 
2305331Samw int smb_mangle_name(ino64_t fileid, char *name, char *shortname,
2315331Samw     char *name83, int force);
2325331Samw int smb_unmangle_name(struct smb_request *sr, cred_t *cred,
2335331Samw     smb_node_t *dir_node, char *name, char *real_name, int realname_size,
2345331Samw     char *shortname, char *name83, int od);
2355331Samw int smb_maybe_mangled_name(char *name);
2365331Samw int smb_maybe_mangled_path(const char *path, size_t pathlen);
2375331Samw int smb_needs_mangle(char *name, char **dot_pos);
2385331Samw 
2395331Samw void smbsr_cleanup(struct smb_request *sr);
2405331Samw 
2415331Samw int smbsr_connect_tree(struct smb_request *);
2425331Samw 
2436030Sjb150015 int smb_common_create_directory(struct smb_request *);
2446030Sjb150015 
2455331Samw int		smb_convert_unicode_wildcards(char *);
2465331Samw int	smb_ascii_or_unicode_strlen(struct smb_request *, char *);
2475331Samw int	smb_ascii_or_unicode_strlen_null(struct smb_request *, char *);
2485331Samw int	smb_ascii_or_unicode_null_len(struct smb_request *);
2495331Samw 
2505331Samw int	smb_search(struct smb_request *);
2515331Samw void smb_rdir_close(struct smb_request *);
2525331Samw int	smb_rdir_open(struct smb_request *, char *, unsigned short);
2535331Samw int smb_rdir_next(smb_request_t *sr, smb_node_t **rnode,
2545331Samw     smb_odir_context_t *pc);
2555331Samw 
2566030Sjb150015 uint32_t smb_common_open(smb_request_t *);
2575331Samw DWORD smb_validate_object_name(char *path, unsigned int ftype);
2585331Samw 
2595331Samw uint32_t smb_omode_to_amask(uint32_t desired_access);
2605331Samw 
2615331Samw void	sshow_distribution_info(char *);
2625331Samw 
2636030Sjb150015 void	smb_dispatch_request(struct smb_request *);
2646030Sjb150015 void	smbsr_disconnect_file(smb_request_t *);
2656030Sjb150015 void	smbsr_disconnect_dir(smb_request_t *);
2666030Sjb150015 int	smbsr_encode_empty_result(struct smb_request *);
2675331Samw 
2685331Samw int	smbsr_decode_vwv(struct smb_request *sr, char *fmt, ...);
2695331Samw int	smbsr_decode_data(struct smb_request *sr, char *fmt, ...);
2706030Sjb150015 int	smbsr_encode_result(struct smb_request *, int, int, char *, ...);
2715331Samw smb_xa_t *smbsr_lookup_xa(smb_request_t *sr);
2725331Samw void	smbsr_send_reply(struct smb_request *);
2735331Samw 
2745772Sas200622 void	smbsr_map_errno(int, smb_error_t *);
2755772Sas200622 void	smbsr_set_error(smb_request_t *, smb_error_t *);
2765772Sas200622 void	smbsr_errno(struct smb_request *, int);
2775772Sas200622 void	smbsr_warn(struct smb_request *, DWORD, uint16_t, uint16_t);
2785772Sas200622 void	smbsr_error(struct smb_request *, DWORD, uint16_t, uint16_t);
2795331Samw 
2805331Samw int	smb_mbc_encode(struct mbuf_chain *mbc, char *fmt, va_list ap);
2815331Samw int	smb_mbc_decode(struct mbuf_chain *mbc, char *fmt, va_list ap);
2825331Samw 
2835331Samw int	clock_get_milli_uptime(void);
2845331Samw int	dosfs_dos_to_ux_time(int, int);
2855331Samw int	dosfs_ux_to_dos_time(int, short int *, short int *);
2865331Samw 
2875331Samw int	smb_decode_mbc(struct  mbuf_chain *mbc, char *fmt, ...);
2885331Samw int	smb_decode_buf(unsigned char *buf, int n_buf, char *fmt, ...);
2895331Samw int	smb_encode_mbc(struct mbuf_chain *mbc, char *fmt, ...);
2905331Samw int	smb_encode_buf(unsigned char *buf, int n_buf, char *fmt, ...);
2915331Samw int	smb_peek_mbc(struct mbuf_chain *buf, int offset, char *fmt, ...);
2925331Samw int	smb_poke_mbc(struct mbuf_chain *buf, int offset, char *fmt, ...);
2935331Samw 
2945331Samw void	smbsr_encode_header(struct smb_request *sr, int wct,
2955331Samw 		    int bcc, char *fmt, ...);
2965331Samw 
2975331Samw int	smb_xlate_dialect_str_to_cd(char *);
2985331Samw char	*smb_xlate_com_cd_to_str(int);
2995331Samw char	*smb_xlate_dialect_cd_to_str(int);
3005331Samw 
3015331Samw void	smb_od_destruct(struct smb_session *, struct smb_odir *);
3025331Samw int	smbd_fs_query(struct smb_request *, struct smb_fqi *, int);
3035331Samw int smb_component_match(struct smb_request *sr, ino64_t fileid,
3045331Samw     struct smb_odir *od, smb_odir_context_t *pc);
3055331Samw 
3065331Samw int smb_lock_range_access(struct smb_request *, struct smb_node *,
3075772Sas200622     uint64_t, uint64_t, boolean_t);
3085331Samw 
3095521Sas200622 uint32_t smb_decode_sd(struct smb_xa *, smb_sd_t *);
3105521Sas200622 
3115331Samw /*
3125331Samw  * Socket functions
3135331Samw  */
3145331Samw struct sonode *smb_socreate(int domain, int type, int protocol);
3155331Samw void smb_soshutdown(struct sonode *so);
3165331Samw void smb_sodestroy(struct sonode *so);
3175331Samw int smb_sorecv(struct sonode *so, void *msg, size_t len);
3185331Samw int smb_iov_sorecv(struct sonode *so, iovec_t *iop, int iovlen,
3195331Samw     size_t total_len);
3206496Sjb150015 int smb_net_init(void);
3216496Sjb150015 void smb_net_fini(void);
3225970Sjb150015 void smb_net_txl_constructor(smb_txlst_t *);
3235970Sjb150015 void smb_net_txl_destructor(smb_txlst_t *);
3246496Sjb150015 smb_txreq_t *smb_net_txr_alloc(void);
3256496Sjb150015 void smb_net_txr_free(smb_txreq_t *);
3266496Sjb150015 int smb_net_txr_send(struct sonode *, smb_txlst_t *, smb_txreq_t *);
3275331Samw 
3285331Samw /*
3295331Samw  * SMB RPC interface
3305331Samw  */
3316030Sjb150015 int smb_rpc_open(struct smb_request *);
3326030Sjb150015 void smb_rpc_close(struct smb_ofile *);
3336030Sjb150015 smb_sdrc_t smb_rpc_transact(struct smb_request *, struct uio *);
3346030Sjb150015 int smb_rpc_read(struct smb_request *, struct uio *);
3356030Sjb150015 int smb_rpc_write(struct smb_request *, struct uio *);
3365331Samw 
3375331Samw /*
3386139Sjb150015  * SMB server functions (file smb_server.c)
3396139Sjb150015  */
3406139Sjb150015 int smb_server_svc_init(void);
3416139Sjb150015 int smb_server_svc_fini(void);
3426139Sjb150015 int smb_server_create(void);
3436139Sjb150015 int smb_server_delete(void);
3446139Sjb150015 int smb_server_configure(smb_kmod_cfg_t *cfg);
3456139Sjb150015 int smb_server_start(struct smb_io_start *);
3466139Sjb150015 int smb_server_nbt_listen(int);
3476139Sjb150015 int smb_server_tcp_listen(int);
3486139Sjb150015 int smb_server_nbt_receive(void);
3496139Sjb150015 int smb_server_tcp_receive(void);
3506139Sjb150015 uint32_t smb_server_get_user_count(void);
3516139Sjb150015 uint32_t smb_server_get_session_count(void);
3526139Sjb150015 void smb_server_disconnect_share(char *);
3536139Sjb150015 void smb_server_disconnect_volume(fs_desc_t *);
3546139Sjb150015 int smb_server_dr_ulist_get(int, smb_dr_ulist_t *, int);
3556139Sjb150015 int smb_server_share_export(char *);
3566139Sjb150015 int smb_server_share_unexport(char *, char *);
3576139Sjb150015 int smb_server_set_gmtoff(uint32_t goff);
3586139Sjb150015 
3596139Sjb150015 void smb_server_reconnection_check(smb_server_t *, smb_session_t *);
3606139Sjb150015 void smb_server_get_cfg(smb_server_t *, smb_kmod_cfg_t *);
3616139Sjb150015 
3626139Sjb150015 /*
3635331Samw  * SMB node functions (file smb_node.c)
3645331Samw  */
3656139Sjb150015 int smb_node_init(void);
3666139Sjb150015 void smb_node_fini(void);
3675331Samw struct smb_node *smb_node_lookup(struct smb_request *sr, struct open_param *op,
3685331Samw     cred_t *cr, vnode_t *vp, char *od_name, smb_node_t *dir_snode,
3695331Samw     smb_node_t *unnamed_node, smb_attr_t *attr);
3705331Samw struct smb_node *smb_stream_node_lookup(struct smb_request *sr, cred_t *cr,
3715331Samw     smb_node_t *fnode, vnode_t *xattrdirvp, vnode_t *vp, char *stream_name,
3725331Samw     smb_attr_t *ret_attr);
3735331Samw void smb_node_ref(smb_node_t *node);
3745331Samw void smb_node_release(smb_node_t *node);
3755331Samw int smb_node_assert(smb_node_t *node, const char *file, int line);
3765331Samw int smb_node_rename(smb_node_t *from_dir_snode, smb_node_t *ret_snode,
3775331Samw     smb_node_t *to_dir_snode, char *to_name);
3786139Sjb150015 int smb_node_root_init(vnode_t *, smb_server_t *, smb_node_t **);
3795331Samw void smb_node_add_lock(smb_node_t *node, smb_lock_t *lock);
3805331Samw void smb_node_destroy_lock(smb_node_t *node, smb_lock_t *lock);
3815331Samw void smb_node_destroy_lock_by_ofile(smb_node_t *node, smb_ofile_t *file);
3825772Sas200622 void smb_node_start_crit(smb_node_t *node, krw_t mode);
3835772Sas200622 void smb_node_end_crit(smb_node_t *node);
3845772Sas200622 int smb_node_in_crit(smb_node_t *node);
3855772Sas200622 
3865772Sas200622 uint32_t smb_node_open_check(smb_node_t *, cred_t *,
3875772Sas200622     uint32_t, uint32_t);
3885772Sas200622 uint32_t smb_node_share_check(smb_node_t *, cred_t *,
3895772Sas200622     uint32_t, uint32_t, smb_ofile_t *);
3905772Sas200622 DWORD smb_node_rename_check(smb_node_t *);
3915772Sas200622 DWORD smb_node_delete_check(smb_node_t *);
3925772Sas200622 
3936432Sas200622 u_offset_t smb_node_get_size(smb_node_t *, smb_attr_t *);
3945331Samw void smb_node_set_time(struct smb_node *node, timestruc_t *crtime,
3955331Samw     timestruc_t *mtime, timestruc_t *atime,
3965331Samw     timestruc_t *ctime, unsigned int what);
3975331Samw timestruc_t *smb_node_get_crtime(struct smb_node *node);
3985331Samw timestruc_t *smb_node_get_atime(struct smb_node *node);
3995331Samw timestruc_t *smb_node_get_ctime(struct smb_node *node);
4005331Samw timestruc_t *smb_node_get_mtime(struct smb_node *node);
4015331Samw void smb_node_set_dosattr(struct smb_node *, uint32_t);
4025331Samw uint32_t smb_node_get_dosattr(struct smb_node *node);
4035331Samw int smb_node_set_delete_on_close(smb_node_t *, cred_t *);
4045331Samw void smb_node_reset_delete_on_close(smb_node_t *);
4055331Samw 
4065331Samw 
4075331Samw 
4085331Samw /*
4095331Samw  * Pathname functions
4105331Samw  */
4115331Samw 
4125331Samw int smb_pathname_reduce(struct smb_request *, cred_t *,
4135331Samw     const char *, smb_node_t *, smb_node_t *, smb_node_t **, char *);
4145331Samw 
4155331Samw int smb_pathname(struct smb_request *, char *, int, smb_node_t *,
4165331Samw     smb_node_t *, smb_node_t **, smb_node_t **, cred_t *);
4175331Samw 
4185331Samw /*
4195331Samw  * smb_vfs functions
4205331Samw  */
4215331Samw 
4226139Sjb150015 boolean_t smb_vfs_hold(smb_server_t *, vfs_t *);
4236139Sjb150015 void smb_vfs_rele(smb_server_t *, vfs_t *);
4246139Sjb150015 void smb_vfs_rele_all(smb_server_t *);
4255331Samw 
4265331Samw /*
4275331Samw  * String manipulation function
4285331Samw  */
4295331Samw char *smb_kstrdup(const char *s, size_t n);
4305331Samw 
4315331Samw int smb_sync_fsattr(struct smb_request *sr, cred_t *cr,
4325331Samw     struct smb_node *node);
4335331Samw 
4345331Samw DWORD	smb_validate_dirname(char *path);
4355331Samw 
4365331Samw 
4375331Samw void smb_encode_stream_info(struct smb_request *sr, struct smb_xa *xa,
4385331Samw     smb_node_t *snode, smb_attr_t *attr);
4395331Samw 
4405331Samw /* NOTIFY CHANGE */
4415331Samw void smb_process_session_notify_change_queue(struct smb_session *session);
4425331Samw void smb_process_node_notify_change_queue(struct smb_node *node);
4435331Samw void smb_reply_specific_cancel_request(struct smb_request *sr);
4445331Samw 
4455331Samw void smb_fem_fcn_install(smb_node_t *node);
4465331Samw void smb_fem_fcn_uninstall(smb_node_t *node);
4475331Samw 
4485331Samw /* FEM */
4495331Samw 
4506139Sjb150015 int smb_fem_init(void);
4516139Sjb150015 void smb_fem_fini(void);
4525331Samw 
4535331Samw int smb_try_grow(struct smb_request *sr, int64_t new_size);
4545331Samw 
4555331Samw /* functions from smb_memory_manager.c */
4565331Samw 
4575331Samw void	*smbsr_malloc(smb_malloc_list *, size_t);
4585331Samw void	*smbsr_realloc(void *, size_t);
4595331Samw void	smbsr_free_malloc_list(smb_malloc_list *);
4605331Samw 
4615331Samw void smbsr_rq_notify(smb_request_t *sr,
4625331Samw     smb_session_t *session, smb_tree_t *tree);
4635331Samw 
4645331Samw unsigned short smb_worker_getnum();
4655331Samw int smb_common_close(struct smb_request *sr, uint32_t last_wtime);
4665331Samw void smb_preset_delete_on_close(struct smb_ofile *file);
4675331Samw void smb_commit_delete_on_close(struct smb_ofile *file);
4685331Samw 
4695331Samw int smb_stream_parse_name(char *name, char *u_stream_name,
4705331Samw     char *stream_name);
4715331Samw 
4725331Samw DWORD smb_trans2_set_information(struct smb_request *sr,
4735331Samw     smb_trans2_setinfo_t *info,
4745331Samw     smb_error_t *smberr);
4755331Samw 
4765331Samw /* SMB signing routines smb_signing.c */
4775331Samw void smb_sign_init(struct smb_request *req,
4785331Samw 	smb_session_key_t *session_key, char *resp, int resp_len);
4795331Samw 
4805331Samw int smb_sign_check_request(struct smb_request *req);
4815331Samw 
4825331Samw int smb_sign_check_secondary(struct smb_request *req, unsigned int seqnum);
4835331Samw 
4845331Samw void smb_sign_reply(struct smb_request *req, struct mbuf_chain *reply);
4855331Samw 
4865331Samw uint32_t smb_mode_to_dos_attributes(smb_attr_t *ap);
4875331Samw int smb_sattr_check(smb_attr_t *ap, char *name, unsigned short sattr);
4885331Samw 
4895331Samw void smb_request_cancel(smb_request_t *sr);
4905331Samw 
4916139Sjb150015 /*
4926139Sjb150015  * session functions (file smb_session.c)
4936139Sjb150015  */
4946139Sjb150015 smb_session_t *smb_session_create(struct sonode *, uint16_t, smb_server_t *);
4956139Sjb150015 int smb_session_daemon(smb_session_list_t *);
4966139Sjb150015 void smb_session_reconnection_check(smb_session_list_t *, smb_session_t *);
4976139Sjb150015 void smb_session_timers(smb_session_list_t *);
4985331Samw void smb_session_delete(smb_session_t *session);
4995331Samw void smb_session_cancel(smb_session_t *session);
5005331Samw void smb_session_cancel_requests(smb_session_t *session);
5015331Samw void smb_session_config(smb_session_t *session);
5026139Sjb150015 void smb_session_disconnect_share(smb_session_list_t *, char *);
5036139Sjb150015 void smb_session_disconnect_volume(smb_session_list_t *, fs_desc_t *);
5046139Sjb150015 void smb_session_list_constructor(smb_session_list_t *);
5056139Sjb150015 void smb_session_list_destructor(smb_session_list_t *);
5066139Sjb150015 void smb_session_list_append(smb_session_list_t *, smb_session_t *);
5076139Sjb150015 void smb_session_list_delete_tail(smb_session_list_t *);
5086139Sjb150015 smb_session_t *smb_session_list_activate_head(smb_session_list_t *);
5096139Sjb150015 void smb_session_list_terminate(smb_session_list_t *, smb_session_t *);
5106139Sjb150015 void smb_session_list_signal(smb_session_list_t *);
5116139Sjb150015 
5126139Sjb150015 void smb_session_correct_keep_alive_values(smb_session_list_t *, uint32_t);
5136139Sjb150015 smb_request_t *smb_request_alloc(smb_session_t *, int);
5146139Sjb150015 void smb_request_free(smb_request_t *);
5155331Samw 
5165331Samw 
5175331Samw /*
5185331Samw  * ofile functions (file smb_ofile.c)
5195331Samw  */
5205331Samw smb_ofile_t *smb_ofile_lookup_by_fid(smb_tree_t *tree, uint16_t fid);
5215331Samw smb_ofile_t *smb_ofile_open(smb_tree_t *tree, smb_node_t *node, uint16_t pid,
5225331Samw     uint32_t access_granted, uint32_t create_options, uint32_t share_access,
5235772Sas200622     uint16_t ftype, char *pipe_name, uint32_t rpc_fid, uint32_t uniqid,
5245772Sas200622     smb_error_t *err);
5255331Samw int smb_ofile_close(smb_ofile_t *ofile, uint32_t last_wtime);
5265331Samw uint32_t smb_ofile_access(smb_ofile_t *ofile, cred_t *cr, uint32_t access);
5275331Samw int smb_ofile_seek(smb_ofile_t *of, ushort_t mode, int32_t off,
5285331Samw     uint32_t *retoff);
5295331Samw void smb_ofile_release(smb_ofile_t *ofile);
5305331Samw void smb_ofile_close_all(smb_tree_t *tree);
5315331Samw void smb_ofile_close_all_by_pid(smb_tree_t *tree, uint16_t pid);
5325331Samw void smb_ofile_set_flags(smb_ofile_t *of, uint32_t flags);
5335331Samw void smb_ofile_close_timestamp_update(smb_ofile_t *of, uint32_t last_wtime);
5345331Samw boolean_t smb_ofile_is_open(smb_ofile_t *of);
535*6600Sas200622 
5365331Samw #define	smb_ofile_granted_access(_of_)	((_of_)->f_granted_access)
5375331Samw 
5385331Samw /*
5395331Samw  * odir functions (file smb_odir.c)
5405331Samw  */
5415331Samw smb_odir_t *smb_odir_open(smb_tree_t *tree, smb_node_t *node, char *pattern,
5425331Samw     uint16_t pid, unsigned short sattr);
5435331Samw void smb_odir_close(smb_odir_t *od);
5445331Samw void smb_odir_close_all(smb_tree_t *tree);
5455331Samw void smb_odir_close_all_by_pid(smb_tree_t *tree, uint16_t pid);
5465331Samw void smb_odir_release(smb_odir_t *od);
5475331Samw smb_odir_t *smb_odir_lookup_by_sid(smb_tree_t *tree, uint16_t sid);
5485331Samw 
5495331Samw /*
5505331Samw  * SMB user functions (file smb_user.c)
5515331Samw  */
5525331Samw smb_user_t *smb_user_login(smb_session_t *, cred_t *,
5535331Samw     char *, char *, uint32_t, uint32_t, uint32_t);
5545331Samw smb_user_t *smb_user_dup(smb_user_t *);
5555331Samw void smb_user_logoff(smb_user_t *user);
5565331Samw void smb_user_logoff_all(smb_session_t *session);
5575331Samw smb_user_t *smb_user_lookup_by_uid(smb_session_t *, cred_t **, uint16_t);
5585331Samw smb_user_t *smb_user_lookup_by_name(smb_session_t *, char *, char *);
5595331Samw smb_user_t *smb_user_lookup_by_state(smb_session_t *, smb_user_t *user);
5605331Samw void smb_user_disconnect_share(smb_user_t *user, char *sharename);
5615331Samw void smb_user_disconnect_volume(smb_user_t *user, fs_desc_t *fsd);
5625331Samw void smb_user_release(smb_user_t *user);
5635331Samw 
5645331Samw /*
5655331Samw  * SMB tree functions (file smb_tree.c)
5665331Samw  */
5675331Samw smb_tree_t *smb_tree_connect(smb_user_t *user, uint16_t access_flags,
5685331Samw     char *sharename, char *resource, int32_t rt_share,
5695331Samw     smb_node_t *snode, fsvol_attr_t *vol_attr);
5705331Samw void smb_tree_disconnect(smb_tree_t *tree);
5715331Samw void smb_tree_disconnect_all(smb_user_t *user);
5725331Samw void smb_tree_close_all_by_pid(smb_user_t *user, uint16_t pid);
5735331Samw smb_tree_t *smb_tree_lookup_by_tid(smb_user_t *user, uint16_t tid);
5745331Samw smb_tree_t *smb_tree_lookup_by_name(smb_user_t *, char *, smb_tree_t *);
5755331Samw smb_tree_t *smb_tree_lookup_by_fsd(smb_user_t *, fs_desc_t *, smb_tree_t *);
5765331Samw void smb_tree_release(smb_tree_t *tree);
5775331Samw 
5785331Samw void smb_dr_user_free(smb_dr_user_ctx_t *uinfo);
5795331Samw void smb_dr_ulist_free(smb_dr_ulist_t *ulist);
5806139Sjb150015 int smb_dr_user_create(smb_dr_user_ctx_t *, uint64_t, uint16_t, char *, char *,
5816139Sjb150015     char *, uint32_t, int32_t, time_t, uint32_t);
5826139Sjb150015 
5835331Samw 
5845331Samw /*
5855331Samw  * SMB user's credential functions
5865331Samw  */
5875331Samw cred_t *smb_cred_create(smb_token_t *, uint32_t *);
5885331Samw void smb_cred_rele(cred_t *cr);
5896432Sas200622 int smb_cred_is_member(cred_t *cr, smb_sid_t *sid);
5905331Samw 
5915331Samw smb_xa_t *smb_xa_create(smb_session_t *session, smb_request_t *sr,
5925331Samw     uint32_t total_parameter_count, uint32_t total_data_count,
5935331Samw     uint32_t max_parameter_count, uint32_t max_data_count,
5945331Samw     uint32_t max_setup_count, uint32_t setup_word_count);
5955331Samw void smb_xa_delete(smb_xa_t *xa);
5965331Samw smb_xa_t *smb_xa_hold(smb_xa_t *xa);
5975331Samw void smb_xa_rele(smb_session_t *session, smb_xa_t *xa);
5985331Samw int smb_xa_open(smb_xa_t *xa);
5995331Samw void smb_xa_close(smb_xa_t *xa);
6005331Samw int smb_xa_complete(smb_xa_t *xa);
6015331Samw smb_xa_t *smb_xa_find(smb_session_t *session, uint16_t pid, uint16_t mid);
6025331Samw 
6035331Samw struct mbuf *smb_mbuf_get(uchar_t *buf, int nbytes);
6045331Samw struct mbuf *smb_mbuf_allocate(struct uio *uio);
6055331Samw void smb_mbuf_trim(struct mbuf *mhead, int nbytes);
6065331Samw 
6075331Samw void smb_check_status(void);
6085331Samw int smb_handle_write_raw(smb_session_t *session, smb_request_t *sr);
6095331Samw 
6105331Samw void smb_winpipe_init(void);
6115331Samw void smb_winpipe_fini(void);
6125521Sas200622 int smb_winpipe_open(int door_id);
6135331Samw void smb_winpipe_close(void);
6145331Samw int smb_winpipe_call(smb_request_t *, mlsvc_pipe_t *, mlsvc_stream_t *,
6155967Scp160787     uint16_t, uint32_t *, boolean_t *);
6165331Samw 
6175331Samw void smb_reconnection_check(struct smb_session *session);
6185331Samw 
6195331Samw uint32_t nt_to_unix_time(uint64_t nt_time, timestruc_t *unix_time);
6205331Samw uint64_t unix_to_nt_time(timestruc_t *);
6215331Samw 
6225331Samw int netbios_name_isvalid(char *in, char *out);
6235331Samw 
6245331Samw size_t
6255331Samw unicodestooems(char *oemstring, const mts_wchar_t *unicodestring,
6265331Samw     size_t nbytes, unsigned int cpid);
6275331Samw 
6285331Samw size_t oemstounicodes(mts_wchar_t *unicodestring, const char *oemstring,
6295331Samw     size_t nwchars, unsigned int cpid);
6305331Samw 
6315331Samw int uioxfer(struct uio *src_uio, struct uio *dst_uio, int n);
6325331Samw 
6335331Samw int smb_match_name(ino64_t fileid, char *name, char *shortname,
6345331Samw     char *name83, char *pattern, int ignore_case);
6355331Samw int is_dot_or_dotdot(char *name);
6365331Samw int token2buf(smb_token_t *token, char *buf);
6375331Samw 
6385331Samw /*
6395331Samw  * Pool ID function prototypes
6405331Samw  */
6415331Samw int	smb_idpool_constructor(smb_idpool_t *pool);
6425331Samw void	smb_idpool_destructor(smb_idpool_t  *pool);
6435331Samw int	smb_idpool_alloc(smb_idpool_t *pool, uint16_t *id);
6445331Samw void	smb_idpool_free(smb_idpool_t *pool, uint16_t id);
6455331Samw 
6465331Samw /*
6475331Samw  * SMB thread function prototypes
6485331Samw  */
6495331Samw void	smb_session_worker(void *arg);
6505331Samw 
6515331Samw /*
6525331Samw  * SMB locked list function prototypes
6535331Samw  */
6545331Samw void	smb_llist_constructor(smb_llist_t *, size_t, size_t);
6555331Samw void	smb_llist_destructor(smb_llist_t *);
6565331Samw void	smb_llist_insert_head(smb_llist_t *ll, void *obj);
6575331Samw void	smb_llist_insert_tail(smb_llist_t *ll, void *obj);
6585331Samw void	smb_llist_remove(smb_llist_t *ll, void *obj);
6595331Samw int	smb_llist_upgrade(smb_llist_t *ll);
6605331Samw uint32_t smb_llist_get_count(smb_llist_t *ll);
6615331Samw #define	smb_llist_enter(ll, mode)	rw_enter(&(ll)->ll_lock, mode)
6625331Samw #define	smb_llist_exit(ll)		rw_exit(&(ll)->ll_lock)
6635331Samw #define	smb_llist_head(ll)		list_head(&(ll)->ll_list)
6645331Samw #define	smb_llist_next(ll, obj)		list_next(&(ll)->ll_list, obj)
6655331Samw int	smb_account_connected(smb_user_t *user);
6665331Samw 
6675331Samw /*
6685331Samw  * SMB Synchronized list function prototypes
6695331Samw  */
6705331Samw void	smb_slist_constructor(smb_slist_t *, size_t, size_t);
6715331Samw void	smb_slist_destructor(smb_slist_t *);
6725331Samw void	smb_slist_insert_head(smb_slist_t *sl, void *obj);
6735331Samw void	smb_slist_insert_tail(smb_slist_t *sl, void *obj);
6745331Samw void	smb_slist_remove(smb_slist_t *sl, void *obj);
6755331Samw void	smb_slist_wait_for_empty(smb_slist_t *sl);
6765331Samw void	smb_slist_exit(smb_slist_t *sl);
6775331Samw uint32_t smb_slist_move_tail(list_t *lst, smb_slist_t *sl);
6785331Samw void    smb_slist_obj_move(smb_slist_t *dst, smb_slist_t *src, void *obj);
6795331Samw #define	smb_slist_enter(sl)		mutex_enter(&(sl)->sl_mutex)
6805331Samw #define	smb_slist_head(sl)		list_head(&(sl)->sl_list)
6815331Samw #define	smb_slist_next(sl, obj)		list_next(&(sl)->sl_list, obj)
6825331Samw 
6835331Samw void    smb_rwx_init(smb_rwx_t *rwx);
6845331Samw void    smb_rwx_destroy(smb_rwx_t *rwx);
6855331Samw #define	smb_rwx_rwenter(rwx, mode)	rw_enter(&(rwx)->rwx_lock, mode)
6865331Samw void    smb_rwx_rwexit(smb_rwx_t *rwx);
6875331Samw int	smb_rwx_rwwait(smb_rwx_t *rwx, clock_t timeout);
6885331Samw #define	smb_rwx_xenter(rwx)		mutex_enter(&(rwx)->rwx_mutex)
6895331Samw #define	smb_rwx_xexit(rwx)		mutex_exit(&(rwx)->rwx_mutex)
6905331Samw krw_t   smb_rwx_rwupgrade(smb_rwx_t *rwx);
6915331Samw void    smb_rwx_rwdowngrade(smb_rwx_t *rwx, krw_t mode);
6925331Samw 
6935331Samw void	smb_thread_init(smb_thread_t *, char *, smb_thread_ep_t, void *,
6945331Samw     smb_thread_aw_t, void *);
6955331Samw void	smb_thread_destroy(smb_thread_t *);
6965331Samw int	smb_thread_start(smb_thread_t *);
6975331Samw void	smb_thread_stop(smb_thread_t *);
6985331Samw void    smb_thread_signal(smb_thread_t *);
6995331Samw boolean_t smb_thread_continue(smb_thread_t *);
7005331Samw boolean_t smb_thread_continue_nowait(smb_thread_t *);
7015331Samw boolean_t smb_thread_continue_timedwait(smb_thread_t *, int /* seconds */);
7025331Samw void smb_thread_set_awaken(smb_thread_t *, smb_thread_aw_t, void *);
7035331Samw 
7045331Samw uint32_t smb_denymode_to_sharemode(uint32_t desired_access, char *fname);
7055331Samw uint32_t smb_ofun_to_crdisposition(uint16_t ofun);
7065331Samw 
7075331Samw void    smb_audit_buf_node_create(smb_node_t *node);
7085331Samw void    smb_audit_buf_node_destroy(smb_node_t *node);
7095331Samw #define	smb_audit_node(_n_)					\
7105331Samw 	if ((_n_)->n_audit_buf) {				\
7115331Samw 		smb_audit_record_node_t	*anr;			\
7125331Samw 								\
7135331Samw 		anr = (_n_)->n_audit_buf->anb_records;		\
7145331Samw 		anr += (_n_)->n_audit_buf->anb_index;		\
7155331Samw 		(_n_)->n_audit_buf->anb_index++;		\
7165331Samw 		(_n_)->n_audit_buf->anb_index &=		\
7175331Samw 		    (_n_)->n_audit_buf->anb_max_index;		\
7185331Samw 		anr->anr_refcnt = node->n_refcnt;		\
7195331Samw 		anr->anr_depth = getpcstack(anr->anr_stack,	\
7205331Samw 		    SMB_AUDIT_STACK_DEPTH);			\
7215331Samw 	}
7225331Samw 
7235331Samw /* 100's of ns between 1/1/1970 and 1/1/1601 */
7245331Samw #define	NT_TIME_BIAS	(134774LL * 24LL * 60LL * 60LL * 10000000LL)
7255331Samw 
7265521Sas200622 void smb_sd_init(smb_sd_t *, uint8_t);
7275521Sas200622 void smb_sd_term(smb_sd_t *);
7285521Sas200622 uint32_t smb_sd_get_secinfo(smb_sd_t *);
7295521Sas200622 uint32_t smb_sd_len(smb_sd_t *, uint32_t);
7305521Sas200622 uint32_t smb_sd_tofs(smb_sd_t *, smb_fssd_t *);
7315521Sas200622 uint32_t smb_sd_read(smb_request_t *, smb_sd_t *, uint32_t);
7325521Sas200622 uint32_t smb_sd_write(smb_request_t *, smb_sd_t *, uint32_t);
7335521Sas200622 
7345521Sas200622 void smb_fssd_init(smb_fssd_t *, uint32_t, uint32_t);
7355521Sas200622 void smb_fssd_term(smb_fssd_t *);
7365521Sas200622 
7375521Sas200622 void smb_acl_sort(smb_acl_t *);
7385521Sas200622 void smb_acl_free(smb_acl_t *);
7395521Sas200622 smb_acl_t *smb_acl_alloc(uint8_t, uint16_t, uint16_t);
7405521Sas200622 smb_acl_t *smb_acl_from_zfs(acl_t *, uid_t, gid_t);
7415521Sas200622 uint32_t smb_acl_to_zfs(smb_acl_t *, uint32_t, int, acl_t **);
7425521Sas200622 uint16_t smb_acl_len(smb_acl_t *);
7435521Sas200622 boolean_t smb_acl_isvalid(smb_acl_t *, int);
7445521Sas200622 
7455521Sas200622 void smb_fsacl_free(acl_t *);
7465521Sas200622 acl_t *smb_fsacl_alloc(int, int);
7475521Sas200622 acl_t *smb_fsacl_inherit(acl_t *, int, int, uid_t);
7485521Sas200622 acl_t *smb_fsacl_merge(acl_t *, acl_t *);
7495521Sas200622 void smb_fsacl_split(acl_t *, acl_t **, acl_t **, int);
7505521Sas200622 acl_t *smb_fsacl_from_vsa(vsecattr_t *, acl_type_t);
7515521Sas200622 int smb_fsacl_to_vsa(acl_t *, vsecattr_t *, int *);
7525521Sas200622 
7535521Sas200622 boolean_t smb_ace_is_generic(int);
7545521Sas200622 boolean_t smb_ace_is_access(int);
7555521Sas200622 boolean_t smb_ace_is_audit(int);
7565521Sas200622 
7575331Samw #ifdef	__cplusplus
7585331Samw }
7595331Samw #endif
7605331Samw 
7615331Samw #endif /* _SMB_KPROTO_H_ */
762