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 33*7348SJose.Borrego@Sun.COM #pragma ident "@(#)smb_kproto.h 1.18 08/08/08 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; 55*7348SJose.Borrego@Sun.COM extern int smb_sign_debug; 566139Sjb150015 57*7348SJose.Borrego@Sun.COM #define smb_gmt2local(_sr_, _gmt_) ((_gmt_) - (_sr_)->sr_gmtoff) 58*7348SJose.Borrego@Sun.COM #define smb_local2gmt(_sr_, _local_) ((_local_) + (_sr_)->sr_gmtoff) 595331Samw 605331Samw int fd_dealloc(int); 615331Samw 625331Samw off_t lseek(int fildes, off_t offset, int whence); 635331Samw 645331Samw int arpioctl(int cmd, void *data); 655331Samw /* Why? uint32_t inet_addr(char *str); */ 665331Samw int microtime(timestruc_t *tvp); 675331Samw int clock_get_uptime(void); 685331Samw 695331Samw /* 706030Sjb150015 * SMB request handers called from the dispatcher. 716030Sjb150015 */ 726139Sjb150015 #define SMB_SDT_OPS(NAME) \ 736139Sjb150015 smb_pre_##NAME, \ 746139Sjb150015 smb_com_##NAME, \ 756139Sjb150015 smb_post_##NAME 766139Sjb150015 776139Sjb150015 #define SMB_COM_DECL(NAME) \ 786139Sjb150015 smb_sdrc_t smb_pre_##NAME(smb_request_t *); \ 796139Sjb150015 smb_sdrc_t smb_com_##NAME(smb_request_t *); \ 806139Sjb150015 void smb_post_##NAME(smb_request_t *) 816030Sjb150015 826139Sjb150015 SMB_COM_DECL(check_directory); 836139Sjb150015 SMB_COM_DECL(close); 846139Sjb150015 SMB_COM_DECL(close_and_tree_disconnect); 856139Sjb150015 SMB_COM_DECL(close_print_file); 866139Sjb150015 SMB_COM_DECL(create); 876139Sjb150015 SMB_COM_DECL(create_directory); 886139Sjb150015 SMB_COM_DECL(create_new); 896139Sjb150015 SMB_COM_DECL(create_temporary); 906139Sjb150015 SMB_COM_DECL(delete); 916139Sjb150015 SMB_COM_DECL(delete_directory); 926139Sjb150015 SMB_COM_DECL(echo); 936139Sjb150015 SMB_COM_DECL(find); 946139Sjb150015 SMB_COM_DECL(find_close); 956139Sjb150015 SMB_COM_DECL(find_close2); 966139Sjb150015 SMB_COM_DECL(find_unique); 976139Sjb150015 SMB_COM_DECL(flush); 986139Sjb150015 SMB_COM_DECL(get_print_queue); 996139Sjb150015 SMB_COM_DECL(invalid); 1006139Sjb150015 SMB_COM_DECL(ioctl); 1016139Sjb150015 SMB_COM_DECL(lock_and_read); 1026139Sjb150015 SMB_COM_DECL(lock_byte_range); 1036139Sjb150015 SMB_COM_DECL(locking_andx); 1046139Sjb150015 SMB_COM_DECL(logoff_andx); 1056139Sjb150015 SMB_COM_DECL(negotiate); 1066139Sjb150015 SMB_COM_DECL(nt_cancel); 1076139Sjb150015 SMB_COM_DECL(nt_create_andx); 1086139Sjb150015 SMB_COM_DECL(nt_transact); 1096139Sjb150015 SMB_COM_DECL(nt_transact_secondary); 1106139Sjb150015 SMB_COM_DECL(open); 1116139Sjb150015 SMB_COM_DECL(open_andx); 1126139Sjb150015 SMB_COM_DECL(open_print_file); 1136139Sjb150015 SMB_COM_DECL(process_exit); 1146139Sjb150015 SMB_COM_DECL(query_information); 1156139Sjb150015 SMB_COM_DECL(query_information2); 1166139Sjb150015 SMB_COM_DECL(query_information_disk); 1176139Sjb150015 SMB_COM_DECL(read); 1186139Sjb150015 SMB_COM_DECL(read_andx); 1196139Sjb150015 SMB_COM_DECL(read_raw); 1206139Sjb150015 SMB_COM_DECL(rename); 1216139Sjb150015 SMB_COM_DECL(search); 1226139Sjb150015 SMB_COM_DECL(seek); 1236139Sjb150015 SMB_COM_DECL(session_setup_andx); 1246139Sjb150015 SMB_COM_DECL(set_information); 1256139Sjb150015 SMB_COM_DECL(set_information2); 1266139Sjb150015 SMB_COM_DECL(transaction); 1276139Sjb150015 SMB_COM_DECL(transaction2); 1286139Sjb150015 SMB_COM_DECL(transaction2_secondary); 1296139Sjb150015 SMB_COM_DECL(transaction_secondary); 1306139Sjb150015 SMB_COM_DECL(tree_connect); 1316139Sjb150015 SMB_COM_DECL(tree_connect_andx); 1326139Sjb150015 SMB_COM_DECL(tree_disconnect); 1336139Sjb150015 SMB_COM_DECL(unlock_byte_range); 1346139Sjb150015 SMB_COM_DECL(write); 1356139Sjb150015 SMB_COM_DECL(write_and_close); 1366139Sjb150015 SMB_COM_DECL(write_and_unlock); 1376139Sjb150015 SMB_COM_DECL(write_andx); 1386139Sjb150015 SMB_COM_DECL(write_print_file); 1396139Sjb150015 SMB_COM_DECL(write_raw); 1406139Sjb150015 1416139Sjb150015 #define SMB_NT_TRANSACT_DECL(NAME) \ 1426139Sjb150015 smb_sdrc_t smb_pre_##NAME(smb_request_t *, smb_xa_t *); \ 1436139Sjb150015 smb_sdrc_t smb_##NAME(smb_request_t *, smb_xa_t *); \ 1446139Sjb150015 void smb_post_##NAME(smb_request_t *, smb_xa_t *) 1456139Sjb150015 1466139Sjb150015 SMB_NT_TRANSACT_DECL(nt_transact_create); 1476139Sjb150015 1486139Sjb150015 int smb_notify_init(void); 1496139Sjb150015 void smb_notify_fini(void); 1506139Sjb150015 1516030Sjb150015 smb_sdrc_t smb_nt_transact_notify_change(struct smb_request *, struct smb_xa *); 1526030Sjb150015 smb_sdrc_t smb_nt_transact_query_security_info(struct smb_request *, 1536030Sjb150015 struct smb_xa *); 1546030Sjb150015 smb_sdrc_t smb_nt_transact_set_security_info(struct smb_request *, 1556030Sjb150015 struct smb_xa *); 1566030Sjb150015 smb_sdrc_t smb_nt_transact_ioctl(struct smb_request *, struct smb_xa *); 1576030Sjb150015 1586030Sjb150015 smb_sdrc_t smb_com_trans2_create_directory(struct smb_request *, 1596030Sjb150015 struct smb_xa *); 1606030Sjb150015 smb_sdrc_t smb_com_trans2_find_first2(struct smb_request *, struct smb_xa *); 1616030Sjb150015 smb_sdrc_t smb_com_trans2_find_next2(struct smb_request *, struct smb_xa *); 1626030Sjb150015 smb_sdrc_t smb_com_trans2_query_fs_information(struct smb_request *, 1636030Sjb150015 struct smb_xa *); 1646030Sjb150015 smb_sdrc_t smb_com_trans2_query_path_information(struct smb_request *, 1656030Sjb150015 struct smb_xa *); 1666030Sjb150015 smb_sdrc_t smb_com_trans2_query_file_information(struct smb_request *, 1676030Sjb150015 struct smb_xa *); 1686030Sjb150015 smb_sdrc_t smb_com_trans2_set_path_information(struct smb_request *, 1696030Sjb150015 struct smb_xa *); 1706030Sjb150015 smb_sdrc_t smb_com_trans2_set_file_information(struct smb_request *, 1716030Sjb150015 struct smb_xa *); 1726030Sjb150015 1736030Sjb150015 /* 1745331Samw * Logging functions 1755331Samw */ 1765331Samw void smb_log_flush(void); 1775331Samw void smb_correct_keep_alive_values(uint32_t new_keep_alive); 1785331Samw void smb_close_all_connections(void); 1796600Sas200622 int smb_set_file_size(smb_request_t *, smb_node_t *); 1805331Samw int smb_session_send(smb_session_t *, uint8_t type, struct mbuf_chain *); 1815331Samw int smb_session_xprt_gethdr(smb_session_t *, smb_xprt_t *); 1825331Samw 1835331Samw int smb_net_id(uint32_t); 1845331Samw 1855331Samw void smb_process_file_notify_change_queue(struct smb_ofile *of); 1865331Samw 1876600Sas200622 DWORD smb_oplock_acquire(struct smb_request *, struct smb_ofile *, 1886600Sas200622 struct open_param *); 1896600Sas200622 void smb_oplock_break(struct smb_node *); 1906600Sas200622 void smb_oplock_release(struct smb_node *, boolean_t); 1916600Sas200622 boolean_t smb_oplock_conflict(struct smb_node *, struct smb_session *, 1926600Sas200622 struct open_param *); 1935331Samw 1946600Sas200622 /* 1956600Sas200622 * macros used in oplock processing 1966600Sas200622 * 1976600Sas200622 * SMB_SAME_SESSION: Checks for equivalence 1986600Sas200622 * of session. If an existing oplock is 1996600Sas200622 * from the same IP address/session as the current 2006600Sas200622 * request, the oplock is not broken. 2016600Sas200622 * 2026600Sas200622 * SMB_ATTR_ONLY_OPEN: Checks to see if this is 2036600Sas200622 * an attribute-only open with no contravening 2046600Sas200622 * dispositions. Such an open cannot effect an 2056600Sas200622 * oplock break. However, a contravening disposition 2066600Sas200622 * of FILE_SUPERSEDE or FILE_OVERWRITE can allow 2076600Sas200622 * an oplock break. 2086600Sas200622 */ 2095331Samw 2106600Sas200622 #define SMB_SAME_SESSION(sess1, sess2) \ 2116600Sas200622 ((sess1) && (sess2) && \ 2126600Sas200622 ((sess1)->ipaddr == (sess2)->ipaddr) && \ 2136600Sas200622 ((sess1)->s_kid == (sess2)->s_kid)) \ 2146600Sas200622 2156600Sas200622 #define SMB_ATTR_ONLY_OPEN(op) \ 2166600Sas200622 ((op) && (op)->desired_access && \ 2176600Sas200622 (((op)->desired_access & ~(FILE_READ_ATTRIBUTES | \ 2186600Sas200622 FILE_WRITE_ATTRIBUTES | SYNCHRONIZE)) == 0) && \ 2196600Sas200622 ((op)->create_disposition != FILE_SUPERSEDE) && \ 2206600Sas200622 ((op)->create_disposition != FILE_OVERWRITE)) \ 2215331Samw 2225331Samw uint32_t smb_unlock_range(struct smb_request *, struct smb_node *, 2235331Samw uint64_t, uint64_t); 2246432Sas200622 uint32_t smb_lock_range(smb_request_t *, uint64_t, uint64_t, uint32_t, 2256432Sas200622 uint32_t locktype); 2265772Sas200622 void smb_lock_range_error(smb_request_t *, uint32_t); 2275772Sas200622 228*7348SJose.Borrego@Sun.COM DWORD smb_range_check(smb_request_t *, smb_node_t *, uint64_t, uint64_t, 229*7348SJose.Borrego@Sun.COM boolean_t); 2305331Samw 2315331Samw int smb_mangle_name(ino64_t fileid, char *name, char *shortname, 2325331Samw char *name83, int force); 2335331Samw int smb_unmangle_name(struct smb_request *sr, cred_t *cred, 2345331Samw smb_node_t *dir_node, char *name, char *real_name, int realname_size, 2355331Samw char *shortname, char *name83, int od); 2365331Samw int smb_maybe_mangled_name(char *name); 2375331Samw int smb_maybe_mangled_path(const char *path, size_t pathlen); 2385331Samw int smb_needs_mangle(char *name, char **dot_pos); 2395331Samw 2405331Samw void smbsr_cleanup(struct smb_request *sr); 2415331Samw 2425331Samw int smbsr_connect_tree(struct smb_request *); 2435331Samw 2446030Sjb150015 int smb_common_create_directory(struct smb_request *); 2456030Sjb150015 2465331Samw int smb_convert_unicode_wildcards(char *); 2475331Samw int smb_ascii_or_unicode_strlen(struct smb_request *, char *); 2485331Samw int smb_ascii_or_unicode_strlen_null(struct smb_request *, char *); 2495331Samw int smb_ascii_or_unicode_null_len(struct smb_request *); 2505331Samw 2515331Samw int smb_search(struct smb_request *); 2525331Samw void smb_rdir_close(struct smb_request *); 2535331Samw int smb_rdir_open(struct smb_request *, char *, unsigned short); 2545331Samw int smb_rdir_next(smb_request_t *sr, smb_node_t **rnode, 2555331Samw smb_odir_context_t *pc); 2565331Samw 2576030Sjb150015 uint32_t smb_common_open(smb_request_t *); 2585331Samw DWORD smb_validate_object_name(char *path, unsigned int ftype); 2595331Samw 2605331Samw uint32_t smb_omode_to_amask(uint32_t desired_access); 2615331Samw 2625331Samw void sshow_distribution_info(char *); 2635331Samw 2646030Sjb150015 void smb_dispatch_request(struct smb_request *); 2656030Sjb150015 void smbsr_disconnect_file(smb_request_t *); 2666030Sjb150015 void smbsr_disconnect_dir(smb_request_t *); 2676030Sjb150015 int smbsr_encode_empty_result(struct smb_request *); 2685331Samw 2695331Samw int smbsr_decode_vwv(struct smb_request *sr, char *fmt, ...); 2705331Samw int smbsr_decode_data(struct smb_request *sr, char *fmt, ...); 2716030Sjb150015 int smbsr_encode_result(struct smb_request *, int, int, char *, ...); 2725331Samw smb_xa_t *smbsr_lookup_xa(smb_request_t *sr); 2735331Samw void smbsr_send_reply(struct smb_request *); 2745331Samw 2755772Sas200622 void smbsr_map_errno(int, smb_error_t *); 2765772Sas200622 void smbsr_set_error(smb_request_t *, smb_error_t *); 2775772Sas200622 void smbsr_errno(struct smb_request *, int); 2785772Sas200622 void smbsr_warn(struct smb_request *, DWORD, uint16_t, uint16_t); 2795772Sas200622 void smbsr_error(struct smb_request *, DWORD, uint16_t, uint16_t); 2805331Samw 2815331Samw int clock_get_milli_uptime(void); 282*7348SJose.Borrego@Sun.COM int32_t smb_dos_to_ux_time(int16_t, int16_t); 283*7348SJose.Borrego@Sun.COM int32_t smb_ux_to_dos_time(int32_t, int16_t *, int16_t *); 2845331Samw 2857052Samw int smb_mbc_vencodef(mbuf_chain_t *, char *, va_list); 2867052Samw int smb_mbc_vdecodef(mbuf_chain_t *, char *, va_list); 2877052Samw int smb_mbc_decodef(mbuf_chain_t *, char *, ...); 2887052Samw int smb_mbc_encodef(mbuf_chain_t *, char *, ...); 2897052Samw int smb_mbc_peek(mbuf_chain_t *, int, char *, ...); 2907052Samw int smb_mbc_poke(mbuf_chain_t *, int, char *, ...); 2915331Samw 2925331Samw void smbsr_encode_header(struct smb_request *sr, int wct, 2935331Samw int bcc, char *fmt, ...); 2945331Samw 2955331Samw int smb_xlate_dialect_str_to_cd(char *); 2965331Samw char *smb_xlate_com_cd_to_str(int); 2975331Samw char *smb_xlate_dialect_cd_to_str(int); 2985331Samw 2995331Samw void smb_od_destruct(struct smb_session *, struct smb_odir *); 3005331Samw int smbd_fs_query(struct smb_request *, struct smb_fqi *, int); 3015331Samw int smb_component_match(struct smb_request *sr, ino64_t fileid, 3025331Samw struct smb_odir *od, smb_odir_context_t *pc); 3035331Samw 3045331Samw int smb_lock_range_access(struct smb_request *, struct smb_node *, 3055772Sas200622 uint64_t, uint64_t, boolean_t); 3065331Samw 3075521Sas200622 uint32_t smb_decode_sd(struct smb_xa *, smb_sd_t *); 3085521Sas200622 3095331Samw /* 3105331Samw * Socket functions 3115331Samw */ 3125331Samw struct sonode *smb_socreate(int domain, int type, int protocol); 3135331Samw void smb_soshutdown(struct sonode *so); 3145331Samw void smb_sodestroy(struct sonode *so); 3155331Samw int smb_sorecv(struct sonode *so, void *msg, size_t len); 3165331Samw int smb_iov_sorecv(struct sonode *so, iovec_t *iop, int iovlen, 3175331Samw size_t total_len); 3186496Sjb150015 int smb_net_init(void); 3196496Sjb150015 void smb_net_fini(void); 3205970Sjb150015 void smb_net_txl_constructor(smb_txlst_t *); 3215970Sjb150015 void smb_net_txl_destructor(smb_txlst_t *); 3226496Sjb150015 smb_txreq_t *smb_net_txr_alloc(void); 3236496Sjb150015 void smb_net_txr_free(smb_txreq_t *); 3246496Sjb150015 int smb_net_txr_send(struct sonode *, smb_txlst_t *, smb_txreq_t *); 3255331Samw 3265331Samw /* 3275331Samw * SMB RPC interface 3285331Samw */ 3297052Samw int smb_opipe_open(smb_request_t *); 3307052Samw void smb_opipe_close(smb_ofile_t *); 3317052Samw smb_sdrc_t smb_opipe_transact(smb_request_t *, struct uio *); 3327052Samw int smb_opipe_read(smb_request_t *, struct uio *); 3337052Samw int smb_opipe_write(smb_request_t *, struct uio *); 3347052Samw 3357052Samw void smb_opipe_door_init(void); 3367052Samw void smb_opipe_door_fini(void); 3377052Samw int smb_opipe_door_open(int); 3387052Samw void smb_opipe_door_close(void); 3397052Samw void smb_user_context_init(smb_user_t *, smb_opipe_context_t *); 3407052Samw void smb_user_list_free(smb_dr_ulist_t *); 3415331Samw 3425331Samw /* 3436139Sjb150015 * SMB server functions (file smb_server.c) 3446139Sjb150015 */ 3456139Sjb150015 int smb_server_svc_init(void); 3466139Sjb150015 int smb_server_svc_fini(void); 3476139Sjb150015 int smb_server_create(void); 3486139Sjb150015 int smb_server_delete(void); 3496139Sjb150015 int smb_server_configure(smb_kmod_cfg_t *cfg); 3506139Sjb150015 int smb_server_start(struct smb_io_start *); 3516139Sjb150015 int smb_server_nbt_listen(int); 3526139Sjb150015 int smb_server_tcp_listen(int); 3536139Sjb150015 int smb_server_nbt_receive(void); 3546139Sjb150015 int smb_server_tcp_receive(void); 3556139Sjb150015 uint32_t smb_server_get_user_count(void); 3566139Sjb150015 uint32_t smb_server_get_session_count(void); 3576139Sjb150015 void smb_server_disconnect_share(char *); 358*7348SJose.Borrego@Sun.COM void smb_server_disconnect_volume(const char *); 3596139Sjb150015 int smb_server_dr_ulist_get(int, smb_dr_ulist_t *, int); 3606139Sjb150015 int smb_server_share_export(char *); 3616139Sjb150015 int smb_server_share_unexport(char *, char *); 362*7348SJose.Borrego@Sun.COM int smb_server_set_gmtoff(int32_t goff); 3636139Sjb150015 3646139Sjb150015 void smb_server_reconnection_check(smb_server_t *, smb_session_t *); 3656139Sjb150015 void smb_server_get_cfg(smb_server_t *, smb_kmod_cfg_t *); 3666139Sjb150015 3676139Sjb150015 /* 3685331Samw * SMB node functions (file smb_node.c) 3695331Samw */ 3706139Sjb150015 int smb_node_init(void); 3716139Sjb150015 void smb_node_fini(void); 3725331Samw struct smb_node *smb_node_lookup(struct smb_request *sr, struct open_param *op, 3735331Samw cred_t *cr, vnode_t *vp, char *od_name, smb_node_t *dir_snode, 3745331Samw smb_node_t *unnamed_node, smb_attr_t *attr); 3755331Samw struct smb_node *smb_stream_node_lookup(struct smb_request *sr, cred_t *cr, 3765331Samw smb_node_t *fnode, vnode_t *xattrdirvp, vnode_t *vp, char *stream_name, 3775331Samw smb_attr_t *ret_attr); 3785331Samw void smb_node_ref(smb_node_t *node); 3795331Samw void smb_node_release(smb_node_t *node); 3805331Samw int smb_node_assert(smb_node_t *node, const char *file, int line); 3815331Samw int smb_node_rename(smb_node_t *from_dir_snode, smb_node_t *ret_snode, 3825331Samw smb_node_t *to_dir_snode, char *to_name); 3836139Sjb150015 int smb_node_root_init(vnode_t *, smb_server_t *, smb_node_t **); 3845331Samw void smb_node_add_lock(smb_node_t *node, smb_lock_t *lock); 3855331Samw void smb_node_destroy_lock(smb_node_t *node, smb_lock_t *lock); 3865331Samw void smb_node_destroy_lock_by_ofile(smb_node_t *node, smb_ofile_t *file); 3875772Sas200622 void smb_node_start_crit(smb_node_t *node, krw_t mode); 3885772Sas200622 void smb_node_end_crit(smb_node_t *node); 3895772Sas200622 int smb_node_in_crit(smb_node_t *node); 3905772Sas200622 3915772Sas200622 uint32_t smb_node_open_check(smb_node_t *, cred_t *, 3925772Sas200622 uint32_t, uint32_t); 3935772Sas200622 DWORD smb_node_rename_check(smb_node_t *); 3945772Sas200622 DWORD smb_node_delete_check(smb_node_t *); 3955772Sas200622 3966432Sas200622 u_offset_t smb_node_get_size(smb_node_t *, smb_attr_t *); 3975331Samw void smb_node_set_time(struct smb_node *node, timestruc_t *crtime, 3985331Samw timestruc_t *mtime, timestruc_t *atime, 3995331Samw timestruc_t *ctime, unsigned int what); 4005331Samw timestruc_t *smb_node_get_crtime(struct smb_node *node); 4015331Samw timestruc_t *smb_node_get_atime(struct smb_node *node); 4025331Samw timestruc_t *smb_node_get_ctime(struct smb_node *node); 4035331Samw timestruc_t *smb_node_get_mtime(struct smb_node *node); 4045331Samw void smb_node_set_dosattr(struct smb_node *, uint32_t); 4055331Samw uint32_t smb_node_get_dosattr(struct smb_node *node); 4065331Samw int smb_node_set_delete_on_close(smb_node_t *, cred_t *); 4075331Samw void smb_node_reset_delete_on_close(smb_node_t *); 4085331Samw 4095331Samw 4105331Samw 4115331Samw /* 4125331Samw * Pathname functions 4135331Samw */ 4145331Samw 4155331Samw int smb_pathname_reduce(struct smb_request *, cred_t *, 4165331Samw const char *, smb_node_t *, smb_node_t *, smb_node_t **, char *); 4175331Samw 4185331Samw int smb_pathname(struct smb_request *, char *, int, smb_node_t *, 4195331Samw smb_node_t *, smb_node_t **, smb_node_t **, cred_t *); 4205331Samw 4215331Samw /* 4225331Samw * smb_vfs functions 4235331Samw */ 4245331Samw 4256139Sjb150015 boolean_t smb_vfs_hold(smb_server_t *, vfs_t *); 4266139Sjb150015 void smb_vfs_rele(smb_server_t *, vfs_t *); 4276139Sjb150015 void smb_vfs_rele_all(smb_server_t *); 428*7348SJose.Borrego@Sun.COM boolean_t smb_vfs_cmp(vfs_t *, vfs_t *); 429*7348SJose.Borrego@Sun.COM boolean_t smb_vfs_is_readonly(vfs_t *); 430*7348SJose.Borrego@Sun.COM 4315331Samw 4325331Samw /* 4335331Samw * String manipulation function 4345331Samw */ 4355331Samw char *smb_kstrdup(const char *s, size_t n); 4365331Samw 4375331Samw int smb_sync_fsattr(struct smb_request *sr, cred_t *cr, 4385331Samw struct smb_node *node); 4395331Samw 4405331Samw DWORD smb_validate_dirname(char *path); 4415331Samw 4425331Samw 4435331Samw void smb_encode_stream_info(struct smb_request *sr, struct smb_xa *xa, 4445331Samw smb_node_t *snode, smb_attr_t *attr); 4455331Samw 4465331Samw /* NOTIFY CHANGE */ 447*7348SJose.Borrego@Sun.COM void smb_process_session_notify_change_queue(smb_session_t *, smb_tree_t *); 448*7348SJose.Borrego@Sun.COM void smb_process_node_notify_change_queue(struct smb_node *); 449*7348SJose.Borrego@Sun.COM void smb_reply_specific_cancel_request(struct smb_request *); 4505331Samw 451*7348SJose.Borrego@Sun.COM void smb_fem_fcn_install(smb_node_t *); 452*7348SJose.Borrego@Sun.COM void smb_fem_fcn_uninstall(smb_node_t *); 4535331Samw 4545331Samw /* FEM */ 4555331Samw 4566139Sjb150015 int smb_fem_init(void); 4576139Sjb150015 void smb_fem_fini(void); 4585331Samw 4595331Samw int smb_try_grow(struct smb_request *sr, int64_t new_size); 4605331Samw 4615331Samw /* functions from smb_memory_manager.c */ 4625331Samw 4635331Samw void *smbsr_malloc(smb_malloc_list *, size_t); 4645331Samw void *smbsr_realloc(void *, size_t); 4655331Samw void smbsr_free_malloc_list(smb_malloc_list *); 4665331Samw 4675331Samw unsigned short smb_worker_getnum(); 4685331Samw void smb_preset_delete_on_close(struct smb_ofile *file); 4695331Samw void smb_commit_delete_on_close(struct smb_ofile *file); 4705331Samw 4715331Samw int smb_stream_parse_name(char *name, char *u_stream_name, 4725331Samw char *stream_name); 4735331Samw 4745331Samw DWORD smb_trans2_set_information(struct smb_request *sr, 4755331Samw smb_trans2_setinfo_t *info, 4765331Samw smb_error_t *smberr); 4775331Samw 4785331Samw /* SMB signing routines smb_signing.c */ 4795331Samw void smb_sign_init(struct smb_request *req, 4805331Samw smb_session_key_t *session_key, char *resp, int resp_len); 4815331Samw 4825331Samw int smb_sign_check_request(struct smb_request *req); 4835331Samw 4845331Samw int smb_sign_check_secondary(struct smb_request *req, unsigned int seqnum); 4855331Samw 4865331Samw void smb_sign_reply(struct smb_request *req, struct mbuf_chain *reply); 4875331Samw 4887052Samw boolean_t smb_sattr_check(smb_attr_t *, char *, unsigned short); 4895331Samw 4905331Samw void smb_request_cancel(smb_request_t *sr); 4915331Samw 4926139Sjb150015 /* 4936139Sjb150015 * session functions (file smb_session.c) 4946139Sjb150015 */ 4956139Sjb150015 smb_session_t *smb_session_create(struct sonode *, uint16_t, smb_server_t *); 4966139Sjb150015 int smb_session_daemon(smb_session_list_t *); 4976139Sjb150015 void smb_session_reconnection_check(smb_session_list_t *, smb_session_t *); 4986139Sjb150015 void smb_session_timers(smb_session_list_t *); 4995331Samw void smb_session_delete(smb_session_t *session); 5005331Samw void smb_session_cancel(smb_session_t *session); 501*7348SJose.Borrego@Sun.COM void smb_session_cancel_requests(smb_session_t *, smb_tree_t *, 502*7348SJose.Borrego@Sun.COM smb_request_t *); 5035331Samw void smb_session_config(smb_session_t *session); 5046139Sjb150015 void smb_session_disconnect_share(smb_session_list_t *, char *); 505*7348SJose.Borrego@Sun.COM void smb_session_disconnect_volume(smb_session_list_t *, const char *); 5066139Sjb150015 void smb_session_list_constructor(smb_session_list_t *); 5076139Sjb150015 void smb_session_list_destructor(smb_session_list_t *); 5086139Sjb150015 void smb_session_list_append(smb_session_list_t *, smb_session_t *); 5096139Sjb150015 void smb_session_list_delete_tail(smb_session_list_t *); 5106139Sjb150015 smb_session_t *smb_session_list_activate_head(smb_session_list_t *); 5116139Sjb150015 void smb_session_list_terminate(smb_session_list_t *, smb_session_t *); 5126139Sjb150015 void smb_session_list_signal(smb_session_list_t *); 5136139Sjb150015 5146139Sjb150015 void smb_session_correct_keep_alive_values(smb_session_list_t *, uint32_t); 5156139Sjb150015 smb_request_t *smb_request_alloc(smb_session_t *, int); 5166139Sjb150015 void smb_request_free(smb_request_t *); 5175331Samw 5185331Samw 5195331Samw /* 5205331Samw * ofile functions (file smb_ofile.c) 5215331Samw */ 522*7348SJose.Borrego@Sun.COM smb_ofile_t *smb_ofile_lookup_by_fid(smb_tree_t *, uint16_t); 523*7348SJose.Borrego@Sun.COM smb_ofile_t *smb_ofile_open(smb_tree_t *, smb_node_t *, uint16_t, 524*7348SJose.Borrego@Sun.COM struct open_param *, uint16_t, uint32_t, smb_error_t *); 525*7348SJose.Borrego@Sun.COM void smb_ofile_close(smb_ofile_t *, uint32_t); 526*7348SJose.Borrego@Sun.COM uint32_t smb_ofile_access(smb_ofile_t *, cred_t *, uint32_t); 527*7348SJose.Borrego@Sun.COM int smb_ofile_seek(smb_ofile_t *, ushort_t, int32_t, uint32_t *); 528*7348SJose.Borrego@Sun.COM void smb_ofile_release(smb_ofile_t *); 529*7348SJose.Borrego@Sun.COM void smb_ofile_close_all(smb_tree_t *); 530*7348SJose.Borrego@Sun.COM void smb_ofile_close_all_by_pid(smb_tree_t *, uint16_t); 531*7348SJose.Borrego@Sun.COM void smb_ofile_set_flags(smb_ofile_t *, uint32_t); 532*7348SJose.Borrego@Sun.COM void smb_ofile_close_timestamp_update(smb_ofile_t *, uint32_t); 533*7348SJose.Borrego@Sun.COM boolean_t smb_ofile_is_open(smb_ofile_t *); 5346771Sjb150015 uint32_t smb_ofile_open_check(smb_ofile_t *, cred_t *, 5356771Sjb150015 uint32_t, uint32_t); 5366771Sjb150015 uint32_t smb_ofile_rename_check(smb_ofile_t *); 5376771Sjb150015 uint32_t smb_ofile_delete_check(smb_ofile_t *); 5386771Sjb150015 5396600Sas200622 5405331Samw #define smb_ofile_granted_access(_of_) ((_of_)->f_granted_access) 5415331Samw 5425331Samw /* 5435331Samw * odir functions (file smb_odir.c) 5445331Samw */ 5455331Samw smb_odir_t *smb_odir_open(smb_tree_t *tree, smb_node_t *node, char *pattern, 5465331Samw uint16_t pid, unsigned short sattr); 5475331Samw void smb_odir_close(smb_odir_t *od); 5485331Samw void smb_odir_close_all(smb_tree_t *tree); 5495331Samw void smb_odir_close_all_by_pid(smb_tree_t *tree, uint16_t pid); 5505331Samw void smb_odir_release(smb_odir_t *od); 5515331Samw smb_odir_t *smb_odir_lookup_by_sid(smb_tree_t *tree, uint16_t sid); 5525331Samw 5535331Samw /* 5545331Samw * SMB user functions (file smb_user.c) 5555331Samw */ 556*7348SJose.Borrego@Sun.COM int smb_user_init(void); 557*7348SJose.Borrego@Sun.COM void smb_user_fini(void); 5585331Samw smb_user_t *smb_user_login(smb_session_t *, cred_t *, 5595331Samw char *, char *, uint32_t, uint32_t, uint32_t); 5605331Samw smb_user_t *smb_user_dup(smb_user_t *); 561*7348SJose.Borrego@Sun.COM void smb_user_logoff(smb_user_t *); 562*7348SJose.Borrego@Sun.COM void smb_user_logoff_all(smb_session_t *); 5635331Samw smb_user_t *smb_user_lookup_by_uid(smb_session_t *, cred_t **, uint16_t); 5645331Samw smb_user_t *smb_user_lookup_by_name(smb_session_t *, char *, char *); 565*7348SJose.Borrego@Sun.COM smb_user_t *smb_user_lookup_by_state(smb_session_t *, smb_user_t *); 566*7348SJose.Borrego@Sun.COM smb_tree_t *smb_user_lookup_tree(smb_user_t *, uint16_t); 567*7348SJose.Borrego@Sun.COM smb_tree_t *smb_user_lookup_share(smb_user_t *, const char *, smb_tree_t *); 568*7348SJose.Borrego@Sun.COM smb_tree_t *smb_user_lookup_volume(smb_user_t *, const char *, smb_tree_t *); 569*7348SJose.Borrego@Sun.COM boolean_t smb_user_is_admin(smb_user_t *); 570*7348SJose.Borrego@Sun.COM void smb_user_close_pid(smb_user_t *, uint16_t); 571*7348SJose.Borrego@Sun.COM void smb_user_disconnect_trees(smb_user_t *user); 572*7348SJose.Borrego@Sun.COM void smb_user_disconnect_share(smb_user_t *, const char *); 573*7348SJose.Borrego@Sun.COM void smb_user_disconnect_volume(smb_user_t *, const char *); 574*7348SJose.Borrego@Sun.COM void smb_user_release(smb_user_t *); 5755331Samw 5765331Samw /* 5775331Samw * SMB tree functions (file smb_tree.c) 5785331Samw */ 579*7348SJose.Borrego@Sun.COM smb_tree_t *smb_tree_connect(smb_request_t *); 580*7348SJose.Borrego@Sun.COM void smb_tree_disconnect(smb_tree_t *); 581*7348SJose.Borrego@Sun.COM void smb_tree_close_pid(smb_tree_t *, uint16_t); 582*7348SJose.Borrego@Sun.COM boolean_t smb_tree_has_feature(smb_tree_t *, uint_t); 583*7348SJose.Borrego@Sun.COM boolean_t smb_tree_hold(smb_tree_t *); 584*7348SJose.Borrego@Sun.COM void smb_tree_release(smb_tree_t *); 5855331Samw 5865331Samw void smb_dr_ulist_free(smb_dr_ulist_t *ulist); 5875331Samw 5885331Samw /* 5895331Samw * SMB user's credential functions 5905331Samw */ 5915331Samw cred_t *smb_cred_create(smb_token_t *, uint32_t *); 5925331Samw void smb_cred_rele(cred_t *cr); 5936432Sas200622 int smb_cred_is_member(cred_t *cr, smb_sid_t *sid); 5945331Samw 5955331Samw smb_xa_t *smb_xa_create(smb_session_t *session, smb_request_t *sr, 5965331Samw uint32_t total_parameter_count, uint32_t total_data_count, 5975331Samw uint32_t max_parameter_count, uint32_t max_data_count, 5985331Samw uint32_t max_setup_count, uint32_t setup_word_count); 5995331Samw void smb_xa_delete(smb_xa_t *xa); 6005331Samw smb_xa_t *smb_xa_hold(smb_xa_t *xa); 6015331Samw void smb_xa_rele(smb_session_t *session, smb_xa_t *xa); 6025331Samw int smb_xa_open(smb_xa_t *xa); 6035331Samw void smb_xa_close(smb_xa_t *xa); 6045331Samw int smb_xa_complete(smb_xa_t *xa); 6055331Samw smb_xa_t *smb_xa_find(smb_session_t *session, uint16_t pid, uint16_t mid); 6065331Samw 6075331Samw struct mbuf *smb_mbuf_get(uchar_t *buf, int nbytes); 6085331Samw struct mbuf *smb_mbuf_allocate(struct uio *uio); 6095331Samw void smb_mbuf_trim(struct mbuf *mhead, int nbytes); 6105331Samw 6115331Samw void smb_check_status(void); 6125331Samw int smb_handle_write_raw(smb_session_t *session, smb_request_t *sr); 6135331Samw 6145331Samw void smb_reconnection_check(struct smb_session *session); 6155331Samw 6165331Samw uint32_t nt_to_unix_time(uint64_t nt_time, timestruc_t *unix_time); 6175331Samw uint64_t unix_to_nt_time(timestruc_t *); 6185331Samw 6195331Samw int netbios_name_isvalid(char *in, char *out); 6205331Samw 6215331Samw size_t 6225331Samw unicodestooems(char *oemstring, const mts_wchar_t *unicodestring, 6235331Samw size_t nbytes, unsigned int cpid); 6245331Samw 6255331Samw size_t oemstounicodes(mts_wchar_t *unicodestring, const char *oemstring, 6265331Samw size_t nwchars, unsigned int cpid); 6275331Samw 6285331Samw int uioxfer(struct uio *src_uio, struct uio *dst_uio, int n); 6295331Samw 630*7348SJose.Borrego@Sun.COM int smb_match_name(ino64_t, char *, char *, char *, char *, boolean_t); 6317052Samw boolean_t smb_is_dot_or_dotdot(const char *); 6325331Samw int token2buf(smb_token_t *token, char *buf); 6335331Samw 6345331Samw /* 6355331Samw * Pool ID function prototypes 6365331Samw */ 6375331Samw int smb_idpool_constructor(smb_idpool_t *pool); 6385331Samw void smb_idpool_destructor(smb_idpool_t *pool); 6395331Samw int smb_idpool_alloc(smb_idpool_t *pool, uint16_t *id); 6405331Samw void smb_idpool_free(smb_idpool_t *pool, uint16_t id); 6415331Samw 6425331Samw /* 6435331Samw * SMB thread function prototypes 6445331Samw */ 6455331Samw void smb_session_worker(void *arg); 6465331Samw 6475331Samw /* 6485331Samw * SMB locked list function prototypes 6495331Samw */ 6505331Samw void smb_llist_constructor(smb_llist_t *, size_t, size_t); 6515331Samw void smb_llist_destructor(smb_llist_t *); 6525331Samw void smb_llist_insert_head(smb_llist_t *ll, void *obj); 6535331Samw void smb_llist_insert_tail(smb_llist_t *ll, void *obj); 6545331Samw void smb_llist_remove(smb_llist_t *ll, void *obj); 6555331Samw int smb_llist_upgrade(smb_llist_t *ll); 6565331Samw uint32_t smb_llist_get_count(smb_llist_t *ll); 6575331Samw #define smb_llist_enter(ll, mode) rw_enter(&(ll)->ll_lock, mode) 6585331Samw #define smb_llist_exit(ll) rw_exit(&(ll)->ll_lock) 6595331Samw #define smb_llist_head(ll) list_head(&(ll)->ll_list) 6605331Samw #define smb_llist_next(ll, obj) list_next(&(ll)->ll_list, obj) 6615331Samw int smb_account_connected(smb_user_t *user); 6625331Samw 6635331Samw /* 6645331Samw * SMB Synchronized list function prototypes 6655331Samw */ 6665331Samw void smb_slist_constructor(smb_slist_t *, size_t, size_t); 6675331Samw void smb_slist_destructor(smb_slist_t *); 6685331Samw void smb_slist_insert_head(smb_slist_t *sl, void *obj); 6695331Samw void smb_slist_insert_tail(smb_slist_t *sl, void *obj); 6705331Samw void smb_slist_remove(smb_slist_t *sl, void *obj); 6715331Samw void smb_slist_wait_for_empty(smb_slist_t *sl); 6725331Samw void smb_slist_exit(smb_slist_t *sl); 6735331Samw uint32_t smb_slist_move_tail(list_t *lst, smb_slist_t *sl); 6745331Samw void smb_slist_obj_move(smb_slist_t *dst, smb_slist_t *src, void *obj); 6755331Samw #define smb_slist_enter(sl) mutex_enter(&(sl)->sl_mutex) 6765331Samw #define smb_slist_head(sl) list_head(&(sl)->sl_list) 6775331Samw #define smb_slist_next(sl, obj) list_next(&(sl)->sl_list, obj) 6785331Samw 6795331Samw void smb_rwx_init(smb_rwx_t *rwx); 6805331Samw void smb_rwx_destroy(smb_rwx_t *rwx); 6815331Samw #define smb_rwx_rwenter(rwx, mode) rw_enter(&(rwx)->rwx_lock, mode) 6825331Samw void smb_rwx_rwexit(smb_rwx_t *rwx); 6835331Samw int smb_rwx_rwwait(smb_rwx_t *rwx, clock_t timeout); 6845331Samw #define smb_rwx_xenter(rwx) mutex_enter(&(rwx)->rwx_mutex) 6855331Samw #define smb_rwx_xexit(rwx) mutex_exit(&(rwx)->rwx_mutex) 6865331Samw krw_t smb_rwx_rwupgrade(smb_rwx_t *rwx); 6875331Samw void smb_rwx_rwdowngrade(smb_rwx_t *rwx, krw_t mode); 6885331Samw 6895331Samw void smb_thread_init(smb_thread_t *, char *, smb_thread_ep_t, void *, 6905331Samw smb_thread_aw_t, void *); 6915331Samw void smb_thread_destroy(smb_thread_t *); 6925331Samw int smb_thread_start(smb_thread_t *); 6935331Samw void smb_thread_stop(smb_thread_t *); 6945331Samw void smb_thread_signal(smb_thread_t *); 6955331Samw boolean_t smb_thread_continue(smb_thread_t *); 6965331Samw boolean_t smb_thread_continue_nowait(smb_thread_t *); 6975331Samw boolean_t smb_thread_continue_timedwait(smb_thread_t *, int /* seconds */); 6985331Samw void smb_thread_set_awaken(smb_thread_t *, smb_thread_aw_t, void *); 6995331Samw 7005331Samw uint32_t smb_denymode_to_sharemode(uint32_t desired_access, char *fname); 7015331Samw uint32_t smb_ofun_to_crdisposition(uint16_t ofun); 7025331Samw 7035331Samw void smb_audit_buf_node_create(smb_node_t *node); 7045331Samw void smb_audit_buf_node_destroy(smb_node_t *node); 7055331Samw #define smb_audit_node(_n_) \ 7065331Samw if ((_n_)->n_audit_buf) { \ 7075331Samw smb_audit_record_node_t *anr; \ 7085331Samw \ 7095331Samw anr = (_n_)->n_audit_buf->anb_records; \ 7105331Samw anr += (_n_)->n_audit_buf->anb_index; \ 7115331Samw (_n_)->n_audit_buf->anb_index++; \ 7125331Samw (_n_)->n_audit_buf->anb_index &= \ 7135331Samw (_n_)->n_audit_buf->anb_max_index; \ 7145331Samw anr->anr_refcnt = node->n_refcnt; \ 7155331Samw anr->anr_depth = getpcstack(anr->anr_stack, \ 7165331Samw SMB_AUDIT_STACK_DEPTH); \ 7175331Samw } 7185331Samw 7195331Samw /* 100's of ns between 1/1/1970 and 1/1/1601 */ 7205331Samw #define NT_TIME_BIAS (134774LL * 24LL * 60LL * 60LL * 10000000LL) 7215331Samw 7225521Sas200622 void smb_sd_init(smb_sd_t *, uint8_t); 7235521Sas200622 void smb_sd_term(smb_sd_t *); 7245521Sas200622 uint32_t smb_sd_get_secinfo(smb_sd_t *); 7255521Sas200622 uint32_t smb_sd_len(smb_sd_t *, uint32_t); 7265521Sas200622 uint32_t smb_sd_tofs(smb_sd_t *, smb_fssd_t *); 7275521Sas200622 uint32_t smb_sd_read(smb_request_t *, smb_sd_t *, uint32_t); 7285521Sas200622 uint32_t smb_sd_write(smb_request_t *, smb_sd_t *, uint32_t); 7295521Sas200622 7305521Sas200622 void smb_fssd_init(smb_fssd_t *, uint32_t, uint32_t); 7315521Sas200622 void smb_fssd_term(smb_fssd_t *); 7325521Sas200622 7335521Sas200622 void smb_acl_sort(smb_acl_t *); 7345521Sas200622 void smb_acl_free(smb_acl_t *); 7355521Sas200622 smb_acl_t *smb_acl_alloc(uint8_t, uint16_t, uint16_t); 7365521Sas200622 smb_acl_t *smb_acl_from_zfs(acl_t *, uid_t, gid_t); 7375521Sas200622 uint32_t smb_acl_to_zfs(smb_acl_t *, uint32_t, int, acl_t **); 7385521Sas200622 uint16_t smb_acl_len(smb_acl_t *); 7395521Sas200622 boolean_t smb_acl_isvalid(smb_acl_t *, int); 7405521Sas200622 7415521Sas200622 void smb_fsacl_free(acl_t *); 7425521Sas200622 acl_t *smb_fsacl_alloc(int, int); 7435521Sas200622 acl_t *smb_fsacl_inherit(acl_t *, int, int, uid_t); 7445521Sas200622 acl_t *smb_fsacl_merge(acl_t *, acl_t *); 7455521Sas200622 void smb_fsacl_split(acl_t *, acl_t **, acl_t **, int); 7465521Sas200622 acl_t *smb_fsacl_from_vsa(vsecattr_t *, acl_type_t); 7475521Sas200622 int smb_fsacl_to_vsa(acl_t *, vsecattr_t *, int *); 7485521Sas200622 7495521Sas200622 boolean_t smb_ace_is_generic(int); 7505521Sas200622 boolean_t smb_ace_is_access(int); 7515521Sas200622 boolean_t smb_ace_is_audit(int); 7525521Sas200622 7535331Samw #ifdef __cplusplus 7545331Samw } 7555331Samw #endif 7565331Samw 7575331Samw #endif /* _SMB_KPROTO_H_ */ 758