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 /* 605331Samw * Definitions that should be elsewhere... 615331Samw */ 625331Samw struct mbuf *m_free(struct mbuf *); 635331Samw void m_freem(struct mbuf *); 645331Samw 655331Samw int fd_dealloc(int); 665331Samw 675331Samw off_t lseek(int fildes, off_t offset, int whence); 685331Samw 695331Samw int arpioctl(int cmd, void *data); 705331Samw /* Why? uint32_t inet_addr(char *str); */ 715331Samw int microtime(timestruc_t *tvp); 725331Samw int clock_get_uptime(void); 735331Samw 745331Samw /* 756030Sjb150015 * SMB request handers called from the dispatcher. 766030Sjb150015 */ 776139Sjb150015 #define SMB_SDT_OPS(NAME) \ 786139Sjb150015 smb_pre_##NAME, \ 796139Sjb150015 smb_com_##NAME, \ 806139Sjb150015 smb_post_##NAME 816139Sjb150015 826139Sjb150015 #define SMB_COM_DECL(NAME) \ 836139Sjb150015 smb_sdrc_t smb_pre_##NAME(smb_request_t *); \ 846139Sjb150015 smb_sdrc_t smb_com_##NAME(smb_request_t *); \ 856139Sjb150015 void smb_post_##NAME(smb_request_t *) 866030Sjb150015 876139Sjb150015 SMB_COM_DECL(check_directory); 886139Sjb150015 SMB_COM_DECL(close); 896139Sjb150015 SMB_COM_DECL(close_and_tree_disconnect); 906139Sjb150015 SMB_COM_DECL(close_print_file); 916139Sjb150015 SMB_COM_DECL(create); 926139Sjb150015 SMB_COM_DECL(create_directory); 936139Sjb150015 SMB_COM_DECL(create_new); 946139Sjb150015 SMB_COM_DECL(create_temporary); 956139Sjb150015 SMB_COM_DECL(delete); 966139Sjb150015 SMB_COM_DECL(delete_directory); 976139Sjb150015 SMB_COM_DECL(echo); 986139Sjb150015 SMB_COM_DECL(find); 996139Sjb150015 SMB_COM_DECL(find_close); 1006139Sjb150015 SMB_COM_DECL(find_close2); 1016139Sjb150015 SMB_COM_DECL(find_unique); 1026139Sjb150015 SMB_COM_DECL(flush); 1036139Sjb150015 SMB_COM_DECL(get_print_queue); 1046139Sjb150015 SMB_COM_DECL(invalid); 1056139Sjb150015 SMB_COM_DECL(ioctl); 1066139Sjb150015 SMB_COM_DECL(lock_and_read); 1076139Sjb150015 SMB_COM_DECL(lock_byte_range); 1086139Sjb150015 SMB_COM_DECL(locking_andx); 1096139Sjb150015 SMB_COM_DECL(logoff_andx); 1106139Sjb150015 SMB_COM_DECL(negotiate); 1116139Sjb150015 SMB_COM_DECL(nt_cancel); 1126139Sjb150015 SMB_COM_DECL(nt_create_andx); 1136139Sjb150015 SMB_COM_DECL(nt_transact); 1146139Sjb150015 SMB_COM_DECL(nt_transact_secondary); 1156139Sjb150015 SMB_COM_DECL(open); 1166139Sjb150015 SMB_COM_DECL(open_andx); 1176139Sjb150015 SMB_COM_DECL(open_print_file); 1186139Sjb150015 SMB_COM_DECL(process_exit); 1196139Sjb150015 SMB_COM_DECL(query_information); 1206139Sjb150015 SMB_COM_DECL(query_information2); 1216139Sjb150015 SMB_COM_DECL(query_information_disk); 1226139Sjb150015 SMB_COM_DECL(read); 1236139Sjb150015 SMB_COM_DECL(read_andx); 1246139Sjb150015 SMB_COM_DECL(read_raw); 1256139Sjb150015 SMB_COM_DECL(rename); 1266139Sjb150015 SMB_COM_DECL(search); 1276139Sjb150015 SMB_COM_DECL(seek); 1286139Sjb150015 SMB_COM_DECL(session_setup_andx); 1296139Sjb150015 SMB_COM_DECL(set_information); 1306139Sjb150015 SMB_COM_DECL(set_information2); 1316139Sjb150015 SMB_COM_DECL(transaction); 1326139Sjb150015 SMB_COM_DECL(transaction2); 1336139Sjb150015 SMB_COM_DECL(transaction2_secondary); 1346139Sjb150015 SMB_COM_DECL(transaction_secondary); 1356139Sjb150015 SMB_COM_DECL(tree_connect); 1366139Sjb150015 SMB_COM_DECL(tree_connect_andx); 1376139Sjb150015 SMB_COM_DECL(tree_disconnect); 1386139Sjb150015 SMB_COM_DECL(unlock_byte_range); 1396139Sjb150015 SMB_COM_DECL(write); 1406139Sjb150015 SMB_COM_DECL(write_and_close); 1416139Sjb150015 SMB_COM_DECL(write_and_unlock); 1426139Sjb150015 SMB_COM_DECL(write_andx); 1436139Sjb150015 SMB_COM_DECL(write_print_file); 1446139Sjb150015 SMB_COM_DECL(write_raw); 1456139Sjb150015 1466139Sjb150015 #define SMB_NT_TRANSACT_DECL(NAME) \ 1476139Sjb150015 smb_sdrc_t smb_pre_##NAME(smb_request_t *, smb_xa_t *); \ 1486139Sjb150015 smb_sdrc_t smb_##NAME(smb_request_t *, smb_xa_t *); \ 1496139Sjb150015 void smb_post_##NAME(smb_request_t *, smb_xa_t *) 1506139Sjb150015 1516139Sjb150015 SMB_NT_TRANSACT_DECL(nt_transact_create); 1526139Sjb150015 1536139Sjb150015 int smb_notify_init(void); 1546139Sjb150015 void smb_notify_fini(void); 1556139Sjb150015 1566030Sjb150015 smb_sdrc_t smb_nt_transact_notify_change(struct smb_request *, struct smb_xa *); 1576030Sjb150015 smb_sdrc_t smb_nt_transact_query_security_info(struct smb_request *, 1586030Sjb150015 struct smb_xa *); 1596030Sjb150015 smb_sdrc_t smb_nt_transact_set_security_info(struct smb_request *, 1606030Sjb150015 struct smb_xa *); 1616030Sjb150015 smb_sdrc_t smb_nt_transact_ioctl(struct smb_request *, struct smb_xa *); 1626030Sjb150015 1636030Sjb150015 smb_sdrc_t smb_com_trans2_create_directory(struct smb_request *, 1646030Sjb150015 struct smb_xa *); 1656030Sjb150015 smb_sdrc_t smb_com_trans2_find_first2(struct smb_request *, struct smb_xa *); 1666030Sjb150015 smb_sdrc_t smb_com_trans2_find_next2(struct smb_request *, struct smb_xa *); 1676030Sjb150015 smb_sdrc_t smb_com_trans2_query_fs_information(struct smb_request *, 1686030Sjb150015 struct smb_xa *); 1696030Sjb150015 smb_sdrc_t smb_com_trans2_query_path_information(struct smb_request *, 1706030Sjb150015 struct smb_xa *); 1716030Sjb150015 smb_sdrc_t smb_com_trans2_query_file_information(struct smb_request *, 1726030Sjb150015 struct smb_xa *); 1736030Sjb150015 smb_sdrc_t smb_com_trans2_set_path_information(struct smb_request *, 1746030Sjb150015 struct smb_xa *); 1756030Sjb150015 smb_sdrc_t smb_com_trans2_set_file_information(struct smb_request *, 1766030Sjb150015 struct smb_xa *); 1776030Sjb150015 1786030Sjb150015 /* 1795331Samw * Logging functions 1805331Samw */ 1815331Samw void smb_log_flush(void); 1825331Samw void smb_correct_keep_alive_values(uint32_t new_keep_alive); 1835331Samw void smb_close_all_connections(void); 1845331Samw int smb_set_file_size(struct smb_request *sr); 1855331Samw int smb_session_send(smb_session_t *, uint8_t type, struct mbuf_chain *); 1865331Samw int smb_session_xprt_gethdr(smb_session_t *, smb_xprt_t *); 1875331Samw 1885331Samw int smb_net_id(uint32_t); 1895331Samw 1905331Samw void smb_process_file_notify_change_queue(struct smb_ofile *of); 1915331Samw 1925331Samw void smb_oplock_init(void); 1935331Samw 1945331Samw DWORD smb_acquire_oplock(struct smb_request *sr, 1955331Samw struct smb_ofile *file, 1965331Samw unsigned int level_requested, 1975331Samw unsigned int *level_granted); 1985331Samw 1995331Samw DWORD smb_break_oplock(struct smb_request *sr, struct smb_node *node); 2005331Samw void smb_release_oplock(struct smb_ofile *file, int reason); 2015331Samw 2025331Samw uint32_t smb_unlock_range(struct smb_request *, struct smb_node *, 2035331Samw uint64_t, uint64_t); 204*6432Sas200622 uint32_t smb_lock_range(smb_request_t *, uint64_t, uint64_t, uint32_t, 205*6432Sas200622 uint32_t locktype); 2065772Sas200622 void smb_lock_range_error(smb_request_t *, uint32_t); 2075772Sas200622 2085772Sas200622 DWORD smb_range_check(smb_request_t *, cred_t *, smb_node_t *, 2095772Sas200622 uint64_t, uint64_t, boolean_t); 2105331Samw 2115331Samw int smb_mangle_name(ino64_t fileid, char *name, char *shortname, 2125331Samw char *name83, int force); 2135331Samw int smb_unmangle_name(struct smb_request *sr, cred_t *cred, 2145331Samw smb_node_t *dir_node, char *name, char *real_name, int realname_size, 2155331Samw char *shortname, char *name83, int od); 2165331Samw int smb_maybe_mangled_name(char *name); 2175331Samw int smb_maybe_mangled_path(const char *path, size_t pathlen); 2185331Samw int smb_needs_mangle(char *name, char **dot_pos); 2195331Samw 2205331Samw void smbsr_cleanup(struct smb_request *sr); 2215331Samw 2225331Samw int smbsr_connect_tree(struct smb_request *); 2235331Samw 2246030Sjb150015 int smb_common_create_directory(struct smb_request *); 2256030Sjb150015 2265331Samw int smb_convert_unicode_wildcards(char *); 2275331Samw int smb_ascii_or_unicode_strlen(struct smb_request *, char *); 2285331Samw int smb_ascii_or_unicode_strlen_null(struct smb_request *, char *); 2295331Samw int smb_ascii_or_unicode_null_len(struct smb_request *); 2305331Samw 2315331Samw int smb_search(struct smb_request *); 2325331Samw void smb_rdir_close(struct smb_request *); 2335331Samw int smb_rdir_open(struct smb_request *, char *, unsigned short); 2345331Samw int smb_rdir_next(smb_request_t *sr, smb_node_t **rnode, 2355331Samw smb_odir_context_t *pc); 2365331Samw 2376030Sjb150015 uint32_t smb_common_open(smb_request_t *); 2385331Samw DWORD smb_validate_object_name(char *path, unsigned int ftype); 2395331Samw 2405331Samw uint32_t smb_omode_to_amask(uint32_t desired_access); 2415331Samw 2425331Samw void sshow_distribution_info(char *); 2435331Samw 2446030Sjb150015 void smb_dispatch_request(struct smb_request *); 2456030Sjb150015 void smbsr_disconnect_file(smb_request_t *); 2466030Sjb150015 void smbsr_disconnect_dir(smb_request_t *); 2476030Sjb150015 int smbsr_encode_empty_result(struct smb_request *); 2485331Samw 2495331Samw int smbsr_decode_vwv(struct smb_request *sr, char *fmt, ...); 2505331Samw int smbsr_decode_data(struct smb_request *sr, char *fmt, ...); 2516030Sjb150015 int smbsr_encode_result(struct smb_request *, int, int, char *, ...); 2525331Samw smb_xa_t *smbsr_lookup_xa(smb_request_t *sr); 2535331Samw void smbsr_send_reply(struct smb_request *); 2545331Samw 2555772Sas200622 void smbsr_map_errno(int, smb_error_t *); 2565772Sas200622 void smbsr_set_error(smb_request_t *, smb_error_t *); 2575772Sas200622 void smbsr_errno(struct smb_request *, int); 2585772Sas200622 void smbsr_warn(struct smb_request *, DWORD, uint16_t, uint16_t); 2595772Sas200622 void smbsr_error(struct smb_request *, DWORD, uint16_t, uint16_t); 2605331Samw 2615331Samw int smb_mbc_encode(struct mbuf_chain *mbc, char *fmt, va_list ap); 2625331Samw int smb_mbc_decode(struct mbuf_chain *mbc, char *fmt, va_list ap); 2635331Samw 2645331Samw int clock_get_milli_uptime(void); 2655331Samw int dosfs_dos_to_ux_time(int, int); 2665331Samw int dosfs_ux_to_dos_time(int, short int *, short int *); 2675331Samw 2685331Samw int smb_decode_mbc(struct mbuf_chain *mbc, char *fmt, ...); 2695331Samw int smb_decode_buf(unsigned char *buf, int n_buf, char *fmt, ...); 2705331Samw int smb_encode_mbc(struct mbuf_chain *mbc, char *fmt, ...); 2715331Samw int smb_encode_buf(unsigned char *buf, int n_buf, char *fmt, ...); 2725331Samw int smb_peek_mbc(struct mbuf_chain *buf, int offset, char *fmt, ...); 2735331Samw int smb_poke_mbc(struct mbuf_chain *buf, int offset, char *fmt, ...); 2745331Samw 2755331Samw void smbsr_encode_header(struct smb_request *sr, int wct, 2765331Samw int bcc, char *fmt, ...); 2775331Samw 2785331Samw int smb_xlate_dialect_str_to_cd(char *); 2795331Samw char *smb_xlate_com_cd_to_str(int); 2805331Samw char *smb_xlate_dialect_cd_to_str(int); 2815331Samw 2825331Samw void smb_od_destruct(struct smb_session *, struct smb_odir *); 2835331Samw int smbd_fs_query(struct smb_request *, struct smb_fqi *, int); 2845331Samw int smb_component_match(struct smb_request *sr, ino64_t fileid, 2855331Samw struct smb_odir *od, smb_odir_context_t *pc); 2865331Samw 2875331Samw int smb_lock_range_access(struct smb_request *, struct smb_node *, 2885772Sas200622 uint64_t, uint64_t, boolean_t); 2895331Samw 2905521Sas200622 uint32_t smb_decode_sd(struct smb_xa *, smb_sd_t *); 2915521Sas200622 2925331Samw /* 2935331Samw * Socket functions 2945331Samw */ 2955331Samw struct sonode *smb_socreate(int domain, int type, int protocol); 2965331Samw void smb_soshutdown(struct sonode *so); 2975331Samw void smb_sodestroy(struct sonode *so); 2985331Samw int smb_sorecv(struct sonode *so, void *msg, size_t len); 2995331Samw int smb_iov_sorecv(struct sonode *so, iovec_t *iop, int iovlen, 3005331Samw size_t total_len); 3015970Sjb150015 void smb_net_txl_constructor(smb_txlst_t *); 3025970Sjb150015 void smb_net_txl_destructor(smb_txlst_t *); 3035970Sjb150015 smb_txbuf_t *smb_net_txb_alloc(void); 3045970Sjb150015 void smb_net_txb_free(smb_txbuf_t *); 3055970Sjb150015 int smb_net_txb_send(struct sonode *, smb_txlst_t *, smb_txbuf_t *); 3065331Samw 3075331Samw /* 3085331Samw * SMB RPC interface 3095331Samw */ 3106030Sjb150015 int smb_rpc_open(struct smb_request *); 3116030Sjb150015 void smb_rpc_close(struct smb_ofile *); 3126030Sjb150015 smb_sdrc_t smb_rpc_transact(struct smb_request *, struct uio *); 3136030Sjb150015 int smb_rpc_read(struct smb_request *, struct uio *); 3146030Sjb150015 int smb_rpc_write(struct smb_request *, struct uio *); 3155331Samw 3165331Samw /* 3176139Sjb150015 * SMB server functions (file smb_server.c) 3186139Sjb150015 */ 3196139Sjb150015 int smb_server_svc_init(void); 3206139Sjb150015 int smb_server_svc_fini(void); 3216139Sjb150015 int smb_server_create(void); 3226139Sjb150015 int smb_server_delete(void); 3236139Sjb150015 int smb_server_configure(smb_kmod_cfg_t *cfg); 3246139Sjb150015 int smb_server_start(struct smb_io_start *); 3256139Sjb150015 int smb_server_nbt_listen(int); 3266139Sjb150015 int smb_server_tcp_listen(int); 3276139Sjb150015 int smb_server_nbt_receive(void); 3286139Sjb150015 int smb_server_tcp_receive(void); 3296139Sjb150015 uint32_t smb_server_get_user_count(void); 3306139Sjb150015 uint32_t smb_server_get_session_count(void); 3316139Sjb150015 void smb_server_disconnect_share(char *); 3326139Sjb150015 void smb_server_disconnect_volume(fs_desc_t *); 3336139Sjb150015 int smb_server_dr_ulist_get(int, smb_dr_ulist_t *, int); 3346139Sjb150015 int smb_server_share_export(char *); 3356139Sjb150015 int smb_server_share_unexport(char *, char *); 3366139Sjb150015 int smb_server_set_gmtoff(uint32_t goff); 3376139Sjb150015 3386139Sjb150015 void smb_server_reconnection_check(smb_server_t *, smb_session_t *); 3396139Sjb150015 void smb_server_get_cfg(smb_server_t *, smb_kmod_cfg_t *); 3406139Sjb150015 3416139Sjb150015 /* 3425331Samw * SMB node functions (file smb_node.c) 3435331Samw */ 3446139Sjb150015 int smb_node_init(void); 3456139Sjb150015 void smb_node_fini(void); 3465331Samw struct smb_node *smb_node_lookup(struct smb_request *sr, struct open_param *op, 3475331Samw cred_t *cr, vnode_t *vp, char *od_name, smb_node_t *dir_snode, 3485331Samw smb_node_t *unnamed_node, smb_attr_t *attr); 3495331Samw struct smb_node *smb_stream_node_lookup(struct smb_request *sr, cred_t *cr, 3505331Samw smb_node_t *fnode, vnode_t *xattrdirvp, vnode_t *vp, char *stream_name, 3515331Samw smb_attr_t *ret_attr); 3525331Samw void smb_node_ref(smb_node_t *node); 3535331Samw void smb_node_release(smb_node_t *node); 3545331Samw int smb_node_assert(smb_node_t *node, const char *file, int line); 3555331Samw int smb_node_rename(smb_node_t *from_dir_snode, smb_node_t *ret_snode, 3565331Samw smb_node_t *to_dir_snode, char *to_name); 3576139Sjb150015 int smb_node_root_init(vnode_t *, smb_server_t *, smb_node_t **); 3585331Samw void smb_node_add_lock(smb_node_t *node, smb_lock_t *lock); 3595331Samw void smb_node_destroy_lock(smb_node_t *node, smb_lock_t *lock); 3605331Samw void smb_node_destroy_lock_by_ofile(smb_node_t *node, smb_ofile_t *file); 3615772Sas200622 void smb_node_start_crit(smb_node_t *node, krw_t mode); 3625772Sas200622 void smb_node_end_crit(smb_node_t *node); 3635772Sas200622 int smb_node_in_crit(smb_node_t *node); 3645772Sas200622 3655772Sas200622 uint32_t smb_node_open_check(smb_node_t *, cred_t *, 3665772Sas200622 uint32_t, uint32_t); 3675772Sas200622 uint32_t smb_node_share_check(smb_node_t *, cred_t *, 3685772Sas200622 uint32_t, uint32_t, smb_ofile_t *); 3695772Sas200622 DWORD smb_node_rename_check(smb_node_t *); 3705772Sas200622 DWORD smb_node_delete_check(smb_node_t *); 3715772Sas200622 372*6432Sas200622 u_offset_t smb_node_get_size(smb_node_t *, smb_attr_t *); 3735331Samw void smb_node_set_time(struct smb_node *node, timestruc_t *crtime, 3745331Samw timestruc_t *mtime, timestruc_t *atime, 3755331Samw timestruc_t *ctime, unsigned int what); 3765331Samw timestruc_t *smb_node_get_crtime(struct smb_node *node); 3775331Samw timestruc_t *smb_node_get_atime(struct smb_node *node); 3785331Samw timestruc_t *smb_node_get_ctime(struct smb_node *node); 3795331Samw timestruc_t *smb_node_get_mtime(struct smb_node *node); 3805331Samw void smb_node_set_dosattr(struct smb_node *, uint32_t); 3815331Samw uint32_t smb_node_get_dosattr(struct smb_node *node); 3825331Samw int smb_node_set_delete_on_close(smb_node_t *, cred_t *); 3835331Samw void smb_node_reset_delete_on_close(smb_node_t *); 3845331Samw 3855331Samw 3865331Samw 3875331Samw /* 3885331Samw * Pathname functions 3895331Samw */ 3905331Samw 3915331Samw int smb_pathname_reduce(struct smb_request *, cred_t *, 3925331Samw const char *, smb_node_t *, smb_node_t *, smb_node_t **, char *); 3935331Samw 3945331Samw int smb_pathname(struct smb_request *, char *, int, smb_node_t *, 3955331Samw smb_node_t *, smb_node_t **, smb_node_t **, cred_t *); 3965331Samw 3975331Samw /* 3985331Samw * smb_vfs functions 3995331Samw */ 4005331Samw 4016139Sjb150015 boolean_t smb_vfs_hold(smb_server_t *, vfs_t *); 4026139Sjb150015 void smb_vfs_rele(smb_server_t *, vfs_t *); 4036139Sjb150015 void smb_vfs_rele_all(smb_server_t *); 4045331Samw 4055331Samw /* 4065331Samw * String manipulation function 4075331Samw */ 4085331Samw char *smb_kstrdup(const char *s, size_t n); 4095331Samw 4105331Samw int smb_sync_fsattr(struct smb_request *sr, cred_t *cr, 4115331Samw struct smb_node *node); 4125331Samw 4135331Samw DWORD smb_validate_dirname(char *path); 4145331Samw 4155331Samw 4165331Samw void smb_encode_stream_info(struct smb_request *sr, struct smb_xa *xa, 4175331Samw smb_node_t *snode, smb_attr_t *attr); 4185331Samw 4195331Samw /* NOTIFY CHANGE */ 4205331Samw void smb_process_session_notify_change_queue(struct smb_session *session); 4215331Samw void smb_process_node_notify_change_queue(struct smb_node *node); 4225331Samw void smb_reply_specific_cancel_request(struct smb_request *sr); 4235331Samw 4245331Samw void smb_fem_fcn_install(smb_node_t *node); 4255331Samw void smb_fem_fcn_uninstall(smb_node_t *node); 4265331Samw 4275331Samw /* FEM */ 4285331Samw 4296139Sjb150015 int smb_fem_init(void); 4306139Sjb150015 void smb_fem_fini(void); 4315331Samw 4325331Samw int smb_try_grow(struct smb_request *sr, int64_t new_size); 4335331Samw 4345331Samw /* functions from smb_memory_manager.c */ 4355331Samw 4365331Samw void *smbsr_malloc(smb_malloc_list *, size_t); 4375331Samw void *smbsr_realloc(void *, size_t); 4385331Samw void smbsr_free_malloc_list(smb_malloc_list *); 4395331Samw 4405331Samw void smbsr_rq_notify(smb_request_t *sr, 4415331Samw smb_session_t *session, smb_tree_t *tree); 4425331Samw 4435331Samw unsigned short smb_worker_getnum(); 4445331Samw int smb_common_close(struct smb_request *sr, uint32_t last_wtime); 4455331Samw void smb_preset_delete_on_close(struct smb_ofile *file); 4465331Samw void smb_commit_delete_on_close(struct smb_ofile *file); 4475331Samw 4485331Samw int smb_stream_parse_name(char *name, char *u_stream_name, 4495331Samw char *stream_name); 4505331Samw 4515331Samw DWORD smb_trans2_set_information(struct smb_request *sr, 4525331Samw smb_trans2_setinfo_t *info, 4535331Samw smb_error_t *smberr); 4545331Samw 4555331Samw /* SMB signing routines smb_signing.c */ 4565331Samw void smb_sign_init(struct smb_request *req, 4575331Samw smb_session_key_t *session_key, char *resp, int resp_len); 4585331Samw 4595331Samw int smb_sign_check_request(struct smb_request *req); 4605331Samw 4615331Samw int smb_sign_check_secondary(struct smb_request *req, unsigned int seqnum); 4625331Samw 4635331Samw void smb_sign_reply(struct smb_request *req, struct mbuf_chain *reply); 4645331Samw 4655331Samw uint32_t smb_mode_to_dos_attributes(smb_attr_t *ap); 4665331Samw int smb_sattr_check(smb_attr_t *ap, char *name, unsigned short sattr); 4675331Samw 4685331Samw void smb_request_cancel(smb_request_t *sr); 4695331Samw 4706139Sjb150015 /* 4716139Sjb150015 * session functions (file smb_session.c) 4726139Sjb150015 */ 4736139Sjb150015 smb_session_t *smb_session_create(struct sonode *, uint16_t, smb_server_t *); 4746139Sjb150015 int smb_session_daemon(smb_session_list_t *); 4756139Sjb150015 void smb_session_reconnection_check(smb_session_list_t *, smb_session_t *); 4766139Sjb150015 void smb_session_timers(smb_session_list_t *); 4775331Samw void smb_session_delete(smb_session_t *session); 4785331Samw void smb_session_cancel(smb_session_t *session); 4795331Samw void smb_session_cancel_requests(smb_session_t *session); 4805331Samw void smb_session_config(smb_session_t *session); 4815331Samw void smb_session_reject(smb_session_t *session, char *reason); 4826139Sjb150015 void smb_session_disconnect_share(smb_session_list_t *, char *); 4836139Sjb150015 void smb_session_disconnect_volume(smb_session_list_t *, fs_desc_t *); 4846139Sjb150015 void smb_session_list_constructor(smb_session_list_t *); 4856139Sjb150015 void smb_session_list_destructor(smb_session_list_t *); 4866139Sjb150015 void smb_session_list_append(smb_session_list_t *, smb_session_t *); 4876139Sjb150015 void smb_session_list_delete_tail(smb_session_list_t *); 4886139Sjb150015 smb_session_t *smb_session_list_activate_head(smb_session_list_t *); 4896139Sjb150015 void smb_session_list_terminate(smb_session_list_t *, smb_session_t *); 4906139Sjb150015 void smb_session_list_signal(smb_session_list_t *); 4916139Sjb150015 4926139Sjb150015 void smb_session_correct_keep_alive_values(smb_session_list_t *, uint32_t); 4936139Sjb150015 smb_request_t *smb_request_alloc(smb_session_t *, int); 4946139Sjb150015 void smb_request_free(smb_request_t *); 4955331Samw 4965331Samw 4975331Samw /* 4985331Samw * ofile functions (file smb_ofile.c) 4995331Samw */ 5005331Samw smb_ofile_t *smb_ofile_lookup_by_fid(smb_tree_t *tree, uint16_t fid); 5015331Samw smb_ofile_t *smb_ofile_open(smb_tree_t *tree, smb_node_t *node, uint16_t pid, 5025331Samw uint32_t access_granted, uint32_t create_options, uint32_t share_access, 5035772Sas200622 uint16_t ftype, char *pipe_name, uint32_t rpc_fid, uint32_t uniqid, 5045772Sas200622 smb_error_t *err); 5055331Samw int smb_ofile_close(smb_ofile_t *ofile, uint32_t last_wtime); 5065331Samw uint32_t smb_ofile_access(smb_ofile_t *ofile, cred_t *cr, uint32_t access); 5075331Samw int smb_ofile_seek(smb_ofile_t *of, ushort_t mode, int32_t off, 5085331Samw uint32_t *retoff); 5095331Samw void smb_ofile_release(smb_ofile_t *ofile); 5105331Samw void smb_ofile_close_all(smb_tree_t *tree); 5115331Samw void smb_ofile_close_all_by_pid(smb_tree_t *tree, uint16_t pid); 5125331Samw void smb_ofile_set_flags(smb_ofile_t *of, uint32_t flags); 5135331Samw void smb_ofile_close_timestamp_update(smb_ofile_t *of, uint32_t last_wtime); 5145331Samw boolean_t smb_ofile_is_open(smb_ofile_t *of); 5155331Samw #define smb_ofile_granted_access(_of_) ((_of_)->f_granted_access) 5165331Samw 5175331Samw /* 5185331Samw * odir functions (file smb_odir.c) 5195331Samw */ 5205331Samw smb_odir_t *smb_odir_open(smb_tree_t *tree, smb_node_t *node, char *pattern, 5215331Samw uint16_t pid, unsigned short sattr); 5225331Samw void smb_odir_close(smb_odir_t *od); 5235331Samw void smb_odir_close_all(smb_tree_t *tree); 5245331Samw void smb_odir_close_all_by_pid(smb_tree_t *tree, uint16_t pid); 5255331Samw void smb_odir_release(smb_odir_t *od); 5265331Samw smb_odir_t *smb_odir_lookup_by_sid(smb_tree_t *tree, uint16_t sid); 5275331Samw 5285331Samw /* 5295331Samw * SMB user functions (file smb_user.c) 5305331Samw */ 5315331Samw smb_user_t *smb_user_login(smb_session_t *, cred_t *, 5325331Samw char *, char *, uint32_t, uint32_t, uint32_t); 5335331Samw smb_user_t *smb_user_dup(smb_user_t *); 5345331Samw void smb_user_logoff(smb_user_t *user); 5355331Samw void smb_user_logoff_all(smb_session_t *session); 5365331Samw smb_user_t *smb_user_lookup_by_uid(smb_session_t *, cred_t **, uint16_t); 5375331Samw smb_user_t *smb_user_lookup_by_name(smb_session_t *, char *, char *); 5385331Samw smb_user_t *smb_user_lookup_by_state(smb_session_t *, smb_user_t *user); 5395331Samw void smb_user_disconnect_share(smb_user_t *user, char *sharename); 5405331Samw void smb_user_disconnect_volume(smb_user_t *user, fs_desc_t *fsd); 5415331Samw void smb_user_release(smb_user_t *user); 5425331Samw 5435331Samw /* 5445331Samw * SMB tree functions (file smb_tree.c) 5455331Samw */ 5465331Samw smb_tree_t *smb_tree_connect(smb_user_t *user, uint16_t access_flags, 5475331Samw char *sharename, char *resource, int32_t rt_share, 5485331Samw smb_node_t *snode, fsvol_attr_t *vol_attr); 5495331Samw void smb_tree_disconnect(smb_tree_t *tree); 5505331Samw void smb_tree_disconnect_all(smb_user_t *user); 5515331Samw void smb_tree_close_all_by_pid(smb_user_t *user, uint16_t pid); 5525331Samw smb_tree_t *smb_tree_lookup_by_tid(smb_user_t *user, uint16_t tid); 5535331Samw smb_tree_t *smb_tree_lookup_by_name(smb_user_t *, char *, smb_tree_t *); 5545331Samw smb_tree_t *smb_tree_lookup_by_fsd(smb_user_t *, fs_desc_t *, smb_tree_t *); 5555331Samw void smb_tree_release(smb_tree_t *tree); 5565331Samw 5575331Samw void smb_dr_user_free(smb_dr_user_ctx_t *uinfo); 5585331Samw void smb_dr_ulist_free(smb_dr_ulist_t *ulist); 5596139Sjb150015 int smb_dr_user_create(smb_dr_user_ctx_t *, uint64_t, uint16_t, char *, char *, 5606139Sjb150015 char *, uint32_t, int32_t, time_t, uint32_t); 5616139Sjb150015 5625331Samw 5635331Samw /* 5645331Samw * SMB user's credential functions 5655331Samw */ 5665331Samw cred_t *smb_cred_create(smb_token_t *, uint32_t *); 5675331Samw void smb_cred_rele(cred_t *cr); 568*6432Sas200622 int smb_cred_is_member(cred_t *cr, smb_sid_t *sid); 5695331Samw 5705331Samw smb_xa_t *smb_xa_create(smb_session_t *session, smb_request_t *sr, 5715331Samw uint32_t total_parameter_count, uint32_t total_data_count, 5725331Samw uint32_t max_parameter_count, uint32_t max_data_count, 5735331Samw uint32_t max_setup_count, uint32_t setup_word_count); 5745331Samw void smb_xa_delete(smb_xa_t *xa); 5755331Samw smb_xa_t *smb_xa_hold(smb_xa_t *xa); 5765331Samw void smb_xa_rele(smb_session_t *session, smb_xa_t *xa); 5775331Samw int smb_xa_open(smb_xa_t *xa); 5785331Samw void smb_xa_close(smb_xa_t *xa); 5795331Samw int smb_xa_complete(smb_xa_t *xa); 5805331Samw smb_xa_t *smb_xa_find(smb_session_t *session, uint16_t pid, uint16_t mid); 5815331Samw 5825331Samw struct mbuf *smb_mbuf_get(uchar_t *buf, int nbytes); 5835331Samw struct mbuf *smb_mbuf_allocate(struct uio *uio); 5845331Samw void smb_mbuf_trim(struct mbuf *mhead, int nbytes); 5855331Samw 5865331Samw void smb_check_status(void); 5875331Samw int smb_handle_write_raw(smb_session_t *session, smb_request_t *sr); 5885331Samw 5895331Samw void smb_winpipe_init(void); 5905331Samw void smb_winpipe_fini(void); 5915521Sas200622 int smb_winpipe_open(int door_id); 5925331Samw void smb_winpipe_close(void); 5935331Samw int smb_winpipe_call(smb_request_t *, mlsvc_pipe_t *, mlsvc_stream_t *, 5945967Scp160787 uint16_t, uint32_t *, boolean_t *); 5955331Samw 5965331Samw void smb_reconnection_check(struct smb_session *session); 5975331Samw 5985331Samw uint32_t nt_to_unix_time(uint64_t nt_time, timestruc_t *unix_time); 5995331Samw uint64_t unix_to_nt_time(timestruc_t *); 6005331Samw 6015331Samw int netbios_name_isvalid(char *in, char *out); 6025331Samw 6035331Samw size_t 6045331Samw unicodestooems(char *oemstring, const mts_wchar_t *unicodestring, 6055331Samw size_t nbytes, unsigned int cpid); 6065331Samw 6075331Samw size_t oemstounicodes(mts_wchar_t *unicodestring, const char *oemstring, 6085331Samw size_t nwchars, unsigned int cpid); 6095331Samw 6105331Samw int uioxfer(struct uio *src_uio, struct uio *dst_uio, int n); 6115331Samw 6125331Samw int smb_match_name(ino64_t fileid, char *name, char *shortname, 6135331Samw char *name83, char *pattern, int ignore_case); 6145331Samw int is_dot_or_dotdot(char *name); 6155331Samw int token2buf(smb_token_t *token, char *buf); 6165331Samw 6175331Samw /* 6185331Samw * Pool ID function prototypes 6195331Samw */ 6205331Samw int smb_idpool_constructor(smb_idpool_t *pool); 6215331Samw void smb_idpool_destructor(smb_idpool_t *pool); 6225331Samw int smb_idpool_alloc(smb_idpool_t *pool, uint16_t *id); 6235331Samw void smb_idpool_free(smb_idpool_t *pool, uint16_t id); 6245331Samw 6255331Samw /* 6265331Samw * SMB thread function prototypes 6275331Samw */ 6285331Samw void smb_session_worker(void *arg); 6295331Samw 6305331Samw /* 6315331Samw * SMB locked list function prototypes 6325331Samw */ 6335331Samw void smb_llist_constructor(smb_llist_t *, size_t, size_t); 6345331Samw void smb_llist_destructor(smb_llist_t *); 6355331Samw void smb_llist_insert_head(smb_llist_t *ll, void *obj); 6365331Samw void smb_llist_insert_tail(smb_llist_t *ll, void *obj); 6375331Samw void smb_llist_remove(smb_llist_t *ll, void *obj); 6385331Samw int smb_llist_upgrade(smb_llist_t *ll); 6395331Samw uint32_t smb_llist_get_count(smb_llist_t *ll); 6405331Samw #define smb_llist_enter(ll, mode) rw_enter(&(ll)->ll_lock, mode) 6415331Samw #define smb_llist_exit(ll) rw_exit(&(ll)->ll_lock) 6425331Samw #define smb_llist_head(ll) list_head(&(ll)->ll_list) 6435331Samw #define smb_llist_next(ll, obj) list_next(&(ll)->ll_list, obj) 6445331Samw int smb_account_connected(smb_user_t *user); 6455331Samw 6465331Samw /* 6475331Samw * SMB Synchronized list function prototypes 6485331Samw */ 6495331Samw void smb_slist_constructor(smb_slist_t *, size_t, size_t); 6505331Samw void smb_slist_destructor(smb_slist_t *); 6515331Samw void smb_slist_insert_head(smb_slist_t *sl, void *obj); 6525331Samw void smb_slist_insert_tail(smb_slist_t *sl, void *obj); 6535331Samw void smb_slist_remove(smb_slist_t *sl, void *obj); 6545331Samw void smb_slist_wait_for_empty(smb_slist_t *sl); 6555331Samw void smb_slist_exit(smb_slist_t *sl); 6565331Samw uint32_t smb_slist_move_tail(list_t *lst, smb_slist_t *sl); 6575331Samw void smb_slist_obj_move(smb_slist_t *dst, smb_slist_t *src, void *obj); 6585331Samw #define smb_slist_enter(sl) mutex_enter(&(sl)->sl_mutex) 6595331Samw #define smb_slist_head(sl) list_head(&(sl)->sl_list) 6605331Samw #define smb_slist_next(sl, obj) list_next(&(sl)->sl_list, obj) 6615331Samw 6625331Samw void smb_rwx_init(smb_rwx_t *rwx); 6635331Samw void smb_rwx_destroy(smb_rwx_t *rwx); 6645331Samw #define smb_rwx_rwenter(rwx, mode) rw_enter(&(rwx)->rwx_lock, mode) 6655331Samw void smb_rwx_rwexit(smb_rwx_t *rwx); 6665331Samw int smb_rwx_rwwait(smb_rwx_t *rwx, clock_t timeout); 6675331Samw #define smb_rwx_xenter(rwx) mutex_enter(&(rwx)->rwx_mutex) 6685331Samw #define smb_rwx_xexit(rwx) mutex_exit(&(rwx)->rwx_mutex) 6695331Samw krw_t smb_rwx_rwupgrade(smb_rwx_t *rwx); 6705331Samw void smb_rwx_rwdowngrade(smb_rwx_t *rwx, krw_t mode); 6715331Samw 6725331Samw void smb_thread_init(smb_thread_t *, char *, smb_thread_ep_t, void *, 6735331Samw smb_thread_aw_t, void *); 6745331Samw void smb_thread_destroy(smb_thread_t *); 6755331Samw int smb_thread_start(smb_thread_t *); 6765331Samw void smb_thread_stop(smb_thread_t *); 6775331Samw void smb_thread_signal(smb_thread_t *); 6785331Samw boolean_t smb_thread_continue(smb_thread_t *); 6795331Samw boolean_t smb_thread_continue_nowait(smb_thread_t *); 6805331Samw boolean_t smb_thread_continue_timedwait(smb_thread_t *, int /* seconds */); 6815331Samw void smb_thread_set_awaken(smb_thread_t *, smb_thread_aw_t, void *); 6825331Samw 6835331Samw uint32_t smb_denymode_to_sharemode(uint32_t desired_access, char *fname); 6845331Samw uint32_t smb_ofun_to_crdisposition(uint16_t ofun); 6855331Samw 6865331Samw void smb_audit_buf_node_create(smb_node_t *node); 6875331Samw void smb_audit_buf_node_destroy(smb_node_t *node); 6885331Samw #define smb_audit_node(_n_) \ 6895331Samw if ((_n_)->n_audit_buf) { \ 6905331Samw smb_audit_record_node_t *anr; \ 6915331Samw \ 6925331Samw anr = (_n_)->n_audit_buf->anb_records; \ 6935331Samw anr += (_n_)->n_audit_buf->anb_index; \ 6945331Samw (_n_)->n_audit_buf->anb_index++; \ 6955331Samw (_n_)->n_audit_buf->anb_index &= \ 6965331Samw (_n_)->n_audit_buf->anb_max_index; \ 6975331Samw anr->anr_refcnt = node->n_refcnt; \ 6985331Samw anr->anr_depth = getpcstack(anr->anr_stack, \ 6995331Samw SMB_AUDIT_STACK_DEPTH); \ 7005331Samw } 7015331Samw 7025331Samw /* 100's of ns between 1/1/1970 and 1/1/1601 */ 7035331Samw #define NT_TIME_BIAS (134774LL * 24LL * 60LL * 60LL * 10000000LL) 7045331Samw 7055521Sas200622 void smb_sd_init(smb_sd_t *, uint8_t); 7065521Sas200622 void smb_sd_term(smb_sd_t *); 7075521Sas200622 uint32_t smb_sd_get_secinfo(smb_sd_t *); 7085521Sas200622 uint32_t smb_sd_len(smb_sd_t *, uint32_t); 7095521Sas200622 uint32_t smb_sd_tofs(smb_sd_t *, smb_fssd_t *); 7105521Sas200622 uint32_t smb_sd_read(smb_request_t *, smb_sd_t *, uint32_t); 7115521Sas200622 uint32_t smb_sd_write(smb_request_t *, smb_sd_t *, uint32_t); 7125521Sas200622 7135521Sas200622 void smb_fssd_init(smb_fssd_t *, uint32_t, uint32_t); 7145521Sas200622 void smb_fssd_term(smb_fssd_t *); 7155521Sas200622 7165521Sas200622 void smb_acl_sort(smb_acl_t *); 7175521Sas200622 void smb_acl_free(smb_acl_t *); 7185521Sas200622 smb_acl_t *smb_acl_alloc(uint8_t, uint16_t, uint16_t); 7195521Sas200622 smb_acl_t *smb_acl_from_zfs(acl_t *, uid_t, gid_t); 7205521Sas200622 uint32_t smb_acl_to_zfs(smb_acl_t *, uint32_t, int, acl_t **); 7215521Sas200622 uint16_t smb_acl_len(smb_acl_t *); 7225521Sas200622 boolean_t smb_acl_isvalid(smb_acl_t *, int); 7235521Sas200622 7245521Sas200622 void smb_fsacl_free(acl_t *); 7255521Sas200622 acl_t *smb_fsacl_alloc(int, int); 7265521Sas200622 acl_t *smb_fsacl_inherit(acl_t *, int, int, uid_t); 7275521Sas200622 acl_t *smb_fsacl_merge(acl_t *, acl_t *); 7285521Sas200622 void smb_fsacl_split(acl_t *, acl_t **, acl_t **, int); 7295521Sas200622 acl_t *smb_fsacl_from_vsa(vsecattr_t *, acl_type_t); 7305521Sas200622 int smb_fsacl_to_vsa(acl_t *, vsecattr_t *, int *); 7315521Sas200622 7325521Sas200622 boolean_t smb_ace_is_generic(int); 7335521Sas200622 boolean_t smb_ace_is_access(int); 7345521Sas200622 boolean_t smb_ace_is_audit(int); 7355521Sas200622 7365331Samw #ifdef __cplusplus 7375331Samw } 7385331Samw #endif 7395331Samw 7405331Samw #endif /* _SMB_KPROTO_H_ */ 741