/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _LIBSMB_H #define _LIBSMB_H #ifdef __cplusplus extern "C" { #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define SMB_VARRUN_DIR "/var/run/smb" #define SMB_CCACHE_FILE "ccache" #define SMB_CCACHE_PATH SMB_VARRUN_DIR "/" SMB_CCACHE_FILE /* Max value length of all SMB properties */ #define MAX_VALUE_BUFLEN 512 #define SMBD_FMRI_PREFIX "network/smb/server" #define SMBD_DEFAULT_INSTANCE_FMRI "svc:/network/smb/server:default" #define SMBD_PG_NAME "smbd" #define SMBD_PROTECTED_PG_NAME "read" #define SMBD_EXEC_PG_NAME "exec" #define SMBD_SMF_OK 0 #define SMBD_SMF_NO_MEMORY 1 /* no memory for data structures */ #define SMBD_SMF_SYSTEM_ERR 2 /* system error, use errno */ #define SMBD_SMF_NO_PERMISSION 3 /* no permission for operation */ #define SMBD_SMF_INVALID_ARG 4 #define SCH_STATE_UNINIT 0 #define SCH_STATE_INITIALIZING 1 #define SCH_STATE_INIT 2 typedef struct smb_scfhandle { scf_handle_t *scf_handle; int scf_state; scf_service_t *scf_service; scf_scope_t *scf_scope; scf_transaction_t *scf_trans; scf_transaction_entry_t *scf_entry; scf_propertygroup_t *scf_pg; scf_instance_t *scf_instance; scf_iter_t *scf_inst_iter; scf_iter_t *scf_pg_iter; } smb_scfhandle_t; /* * CIFS Configuration Management */ typedef enum { SMB_CI_OPLOCK_ENABLE = 0, SMB_CI_AUTOHOME_MAP, SMB_CI_DOMAIN_SID, SMB_CI_DOMAIN_MEMB, SMB_CI_DOMAIN_NAME, SMB_CI_DOMAIN_FQDN, SMB_CI_DOMAIN_FOREST, SMB_CI_DOMAIN_GUID, SMB_CI_DOMAIN_SRV, SMB_CI_WINS_SRV1, SMB_CI_WINS_SRV2, SMB_CI_WINS_EXCL, SMB_CI_MAX_WORKERS, SMB_CI_MAX_CONNECTIONS, SMB_CI_KEEPALIVE, SMB_CI_RESTRICT_ANON, SMB_CI_SIGNING_ENABLE, SMB_CI_SIGNING_REQD, SMB_CI_SYNC_ENABLE, SMB_CI_SECURITY, SMB_CI_NBSCOPE, SMB_CI_SYS_CMNT, SMB_CI_LM_LEVEL, SMB_CI_ADS_SITE, SMB_CI_DYNDNS_ENABLE, SMB_CI_MACHINE_PASSWD, SMB_CI_KPASSWD_SRV, SMB_CI_KPASSWD_DOMAIN, SMB_CI_KPASSWD_SEQNUM, SMB_CI_NETLOGON_SEQNUM, SMB_CI_IPV6_ENABLE, SMB_CI_MAP, SMB_CI_UNMAP, SMB_CI_DISPOSITION, SMB_CI_MAX } smb_cfg_id_t; /* SMF helper functions */ extern smb_scfhandle_t *smb_smf_scf_init(char *); extern void smb_smf_scf_fini(smb_scfhandle_t *); extern int smb_smf_start_transaction(smb_scfhandle_t *); extern int smb_smf_end_transaction(smb_scfhandle_t *); extern int smb_smf_set_string_property(smb_scfhandle_t *, char *, char *); extern int smb_smf_get_string_property(smb_scfhandle_t *, char *, char *, size_t); extern int smb_smf_set_integer_property(smb_scfhandle_t *, char *, int64_t); extern int smb_smf_get_integer_property(smb_scfhandle_t *, char *, int64_t *); extern int smb_smf_set_boolean_property(smb_scfhandle_t *, char *, uint8_t); extern int smb_smf_get_boolean_property(smb_scfhandle_t *, char *, uint8_t *); extern int smb_smf_set_opaque_property(smb_scfhandle_t *, char *, void *, size_t); extern int smb_smf_get_opaque_property(smb_scfhandle_t *, char *, void *, size_t); extern int smb_smf_create_service_pgroup(smb_scfhandle_t *, char *); extern int smb_smf_restart_service(void); extern int smb_smf_maintenance_mode(void); /* ZFS interface */ int smb_getdataset(const char *, char *, size_t); /* Configuration management functions */ extern int smb_config_get(smb_cfg_id_t, char *, int); extern char *smb_config_getname(smb_cfg_id_t); extern int smb_config_getstr(smb_cfg_id_t, char *, int); extern int smb_config_getnum(smb_cfg_id_t, int64_t *); extern boolean_t smb_config_getbool(smb_cfg_id_t); extern int smb_config_set(smb_cfg_id_t, char *); extern int smb_config_setstr(smb_cfg_id_t, char *); extern int smb_config_setnum(smb_cfg_id_t, int64_t); extern int smb_config_setbool(smb_cfg_id_t, boolean_t); extern uint8_t smb_config_get_fg_flag(void); extern char *smb_config_get_localsid(void); extern int smb_config_secmode_fromstr(char *); extern char *smb_config_secmode_tostr(int); extern int smb_config_get_secmode(void); extern int smb_config_set_secmode(int); extern int smb_config_set_idmap_domain(char *); extern int smb_config_refresh_idmap(void); extern int smb_config_getip(smb_cfg_id_t, smb_inaddr_t *); extern void smb_load_kconfig(smb_kmod_cfg_t *kcfg); extern uint32_t smb_crc_gen(uint8_t *, size_t); extern boolean_t smb_match_netlogon_seqnum(void); extern int smb_setdomainprops(char *, char *, char *); extern void smb_update_netlogon_seqnum(void); /* maximum password length on Windows 2000 and above */ #define SMB_PASSWD_MAXLEN 127 #define SMB_USERNAME_MAXLEN 40 typedef struct smb_joininfo { char domain_name[MAXHOSTNAMELEN]; char domain_username[SMB_USERNAME_MAXLEN + 1]; char domain_passwd[SMB_PASSWD_MAXLEN + 1]; uint32_t mode; } smb_joininfo_t; /* APIs to communicate with SMB daemon via door calls */ extern uint32_t smb_join(smb_joininfo_t *info); extern bool_t xdr_smb_dr_joininfo_t(XDR *, smb_joininfo_t *); extern boolean_t smb_find_ads_server(char *, char *, int); extern void smb_config_getdomaininfo(char *, char *, char *, char *, char *); extern void smb_config_setdomaininfo(char *, char *, char *, char *, char *); extern uint32_t smb_get_dcinfo(char *, uint32_t, smb_inaddr_t *); /* * buffer context structure. This is used to keep track of the buffer * context. * * basep: points to the beginning of the buffer * curp: points to the current offset * endp: points to the limit of the buffer */ typedef struct { unsigned char *basep; unsigned char *curp; unsigned char *endp; } smb_ctxbuf_t; extern int smb_ctxbuf_init(smb_ctxbuf_t *ctx, unsigned char *buf, size_t buflen); extern int smb_ctxbuf_len(smb_ctxbuf_t *ctx); extern int smb_ctxbuf_printf(smb_ctxbuf_t *ctx, const char *fmt, ...); /* Functions to handle SMB daemon communications with idmap service */ extern int smb_idmap_start(void); extern void smb_idmap_stop(void); extern int smb_idmap_restart(void); /* Miscellaneous functions */ extern void hexdump(unsigned char *, int); extern size_t bintohex(const char *, size_t, char *, size_t); extern size_t hextobin(const char *, size_t, char *, size_t); extern char *strstrip(char *, const char *); extern char *strtrim(char *, const char *); extern char *trim_whitespace(char *); extern void randomize(char *, unsigned); extern void rand_hash(unsigned char *, size_t, unsigned char *, size_t); extern int smb_getdomainname(char *, size_t); extern int smb_getfqdomainname(char *, size_t); extern int smb_gethostname(char *, size_t, int); extern int smb_getfqhostname(char *, size_t); extern int smb_getnetbiosname(char *, size_t); extern struct hostent *smb_gethostbyname(const char *, int *); extern struct hostent *smb_gethostbyaddr(const char *, int, int, int *); #define SMB_SAMACCT_MAXLEN (NETBIOS_NAME_SZ + 1) extern int smb_getsamaccount(char *, size_t); extern int smb_get_nameservers(smb_inaddr_t *, int); extern void smb_tonetbiosname(char *, char *, char); extern int smb_chk_hostaccess(smb_inaddr_t *, char *); extern int smb_getnameinfo(smb_inaddr_t *, char *, int, int); extern smb_ulist_t *smb_ulist_alloc(void); extern void smb_ulist_free(smb_ulist_t *); extern void smb_ulist_cleanup(smb_ulist_t *); void smb_trace(const char *s); void smb_tracef(const char *fmt, ...); /* * Authentication */ #define SMBAUTH_LM_MAGIC_STR "KGS!@#$%" #define SMBAUTH_HASH_SZ 16 /* also LM/NTLM/NTLMv2 Hash size */ #define SMBAUTH_LM_RESP_SZ 24 /* also NTLM Response size */ #define SMBAUTH_LM_PWD_SZ 14 /* LM password size */ #define SMBAUTH_V2_CLNT_CHALLENGE_SZ 8 /* both LMv2 and NTLMv2 */ #define SMBAUTH_SESSION_KEY_SZ SMBAUTH_HASH_SZ #define SMBAUTH_HEXHASH_SZ (SMBAUTH_HASH_SZ * 2) #define SMBAUTH_FAILURE 1 #define SMBAUTH_SUCCESS 0 #define MD_DIGEST_LEN 16 /* * Name Types * * The list of names near the end of the data blob (i.e. the ndb_names * field of the smb_auth_data_blob_t data structure) can be classify into * the following types: * * 0x0000 Indicates the end of the list. * 0x0001 The name is a NetBIOS machine name (e.g. server name) * 0x0002 The name is an NT Domain NetBIOS name. * 0x0003 The name is the server's DNS hostname. * 0x0004 The name is a W2K Domain name (a DNS name). */ #define SMBAUTH_NAME_TYPE_LIST_END 0x0000 #define SMBAUTH_NAME_TYPE_SERVER_NETBIOS 0x0001 #define SMBAUTH_NAME_TYPE_DOMAIN_NETBIOS 0x0002 #define SMBAUTH_NAME_TYPE_SERVER_DNS 0x0003 #define SMBAUTH_NAME_TYPE_DOMAIN_DNS 0x0004 /* * smb_auth_name_entry_t * * Each name entry in the data blob consists of the following 3 fields: * * nne_type - name type * nne_len - the length of the name * nne_name - the name, in uppercase UCS-2LE Unicode format */ typedef struct smb_auth_name_entry { unsigned short nne_type; unsigned short nne_len; mts_wchar_t nne_name[SMB_PI_MAX_DOMAIN * 2]; } smb_auth_name_entry_t; /* * smb_auth_data_blob * * The format of this NTLMv2 data blob structure is as follow: * * - Blob Signature 0x01010000 (4 bytes) * - Reserved (0x00000000) (4 bytes) * - Timestamp Little-endian, 64-bit signed value representing * the number of tenths of a microsecond since January 1, 1601. * (8 bytes) * - Client Challenge (8 bytes) * - Unknown1 (4 bytes) * - List of Target Information (variable length) * - Unknown2 (4 bytes) */ typedef struct smb_auth_data_blob { unsigned char ndb_signature[4]; unsigned char ndb_reserved[4]; uint64_t ndb_timestamp; unsigned char ndb_clnt_challenge[SMBAUTH_V2_CLNT_CHALLENGE_SZ]; unsigned char ndb_unknown[4]; smb_auth_name_entry_t ndb_names[2]; unsigned char ndb_unknown2[4]; } smb_auth_data_blob_t; #define SMBAUTH_BLOB_MAXLEN (sizeof (smb_auth_data_blob_t)) #define SMBAUTH_CI_MAXLEN SMBAUTH_LM_RESP_SZ #define SMBAUTH_CS_MAXLEN (SMBAUTH_BLOB_MAXLEN + SMBAUTH_HASH_SZ) /* * smb_auth_info_t * * The structure contains all the authentication information * needed for the preparaton of the SMBSessionSetupAndx request * and the user session key. * * hash - NTLM hash * hash_v2 - NTLMv2 hash * ci_len - the length of the case-insensitive password * ci - case-insensitive password * (If NTLMv2 authentication mechanism is used, it * represents the LMv2 response. Otherwise, it * is empty.) * cs_len - the length of the case-sensitive password * cs - case-sensitive password * (If NTLMv2 authentication mechanism is used, it * represents the NTLMv2 response. Otherwise, it * represents the NTLM response.) * data_blob - NTLMv2 data blob */ typedef struct smb_auth_info { unsigned char hash[SMBAUTH_HASH_SZ]; unsigned char hash_v2[SMBAUTH_HASH_SZ]; unsigned short ci_len; unsigned char ci[SMBAUTH_CI_MAXLEN]; unsigned short cs_len; unsigned char cs[SMBAUTH_CS_MAXLEN]; int lmcompatibility_lvl; smb_auth_data_blob_t data_blob; } smb_auth_info_t; /* * SMB password management */ #define SMB_PWF_LM 0x01 /* LM hash is present */ #define SMB_PWF_NT 0x02 /* NT hash is present */ #define SMB_PWF_DISABLE 0x04 /* Account is disabled */ typedef struct smb_passwd { uid_t pw_uid; uint32_t pw_flags; char pw_name[SMB_USERNAME_MAXLEN]; uint8_t pw_lmhash[SMBAUTH_HASH_SZ]; uint8_t pw_nthash[SMBAUTH_HASH_SZ]; } smb_passwd_t; /* * Control flags passed to smb_pwd_setcntl */ #define SMB_PWC_DISABLE 0x01 #define SMB_PWC_ENABLE 0x02 #define SMB_PWC_NOLM 0x04 #define SMB_PWE_SUCCESS 0 #define SMB_PWE_USER_UNKNOWN 1 #define SMB_PWE_USER_DISABLE 2 #define SMB_PWE_CLOSE_FAILED 3 #define SMB_PWE_OPEN_FAILED 4 #define SMB_PWE_WRITE_FAILED 6 #define SMB_PWE_UPDATE_FAILED 7 #define SMB_PWE_STAT_FAILED 8 #define SMB_PWE_BUSY 9 #define SMB_PWE_DENIED 10 #define SMB_PWE_SYSTEM_ERROR 11 #define SMB_PWE_INVALID_PARAM 12 #define SMB_PWE_NO_MEMORY 13 #define SMB_PWE_MAX 14 typedef struct smb_pwditer { void *spi_next; } smb_pwditer_t; typedef struct smb_luser { char *su_name; char *su_fullname; char *su_desc; uint32_t su_rid; uint32_t su_ctrl; } smb_luser_t; extern void smb_pwd_init(boolean_t); extern void smb_pwd_fini(void); extern smb_passwd_t *smb_pwd_getpwnam(const char *, smb_passwd_t *); extern smb_passwd_t *smb_pwd_getpwuid(uid_t, smb_passwd_t *); extern int smb_pwd_setpasswd(const char *, const char *); extern int smb_pwd_setcntl(const char *, int); extern int smb_pwd_iteropen(smb_pwditer_t *); extern smb_luser_t *smb_pwd_iterate(smb_pwditer_t *); extern void smb_pwd_iterclose(smb_pwditer_t *); extern int smb_auth_qnd_unicode(mts_wchar_t *, const char *, int); extern int smb_auth_hmac_md5(unsigned char *, int, unsigned char *, int, unsigned char *); /* * A variation on HMAC-MD5 known as HMACT64 is used by Windows systems. * The HMACT64() function is the same as the HMAC-MD5() except that * it truncates the input key to 64 bytes rather than hashing it down * to 16 bytes using the MD5() function. */ #define SMBAUTH_HMACT64(D, Ds, K, Ks, digest) \ smb_auth_hmac_md5(D, Ds, K, (Ks > 64) ? 64 : Ks, digest) extern int smb_auth_DES(unsigned char *, int, unsigned char *, int, unsigned char *, int); extern int smb_auth_md4(unsigned char *, unsigned char *, int); extern int smb_auth_lm_hash(const char *, unsigned char *); extern int smb_auth_ntlm_hash(const char *, unsigned char *); extern int smb_auth_set_info(char *, char *, unsigned char *, char *, unsigned char *, int, int, smb_auth_info_t *); extern int smb_auth_ntlmv2_hash(unsigned char *, char *, char *, unsigned char *); extern int smb_auth_gen_session_key(smb_auth_info_t *, unsigned char *); boolean_t smb_auth_validate_lm(unsigned char *, uint32_t, smb_passwd_t *, unsigned char *, int, char *, char *); boolean_t smb_auth_validate_nt(unsigned char *, uint32_t, smb_passwd_t *, unsigned char *, int, char *, char *, uchar_t *); /* * SMB MAC Signing */ #define SMB_MAC_KEY_SZ (SMBAUTH_SESSION_KEY_SZ + SMBAUTH_CS_MAXLEN) #define SMB_SIG_OFFS 14 /* signature field offset within header */ #define SMB_SIG_SIZE 8 /* SMB signature size */ /* * Signing flags: * * SMB_SCF_ENABLE Signing is enabled. * * SMB_SCF_REQUIRED Signing is enabled and required. * This flag shouldn't be set if * SMB_SCF_ENABLE isn't set. * * SMB_SCF_STARTED Signing will start after receiving * the first non-anonymous SessionSetup * request. * * SMB_SCF_KEY_ISSET_THIS_LOGON Indicates whether the MAC key has just * been set for this logon. (prior to * sending the SMBSessionSetup request) * */ #define SMB_SCF_ENABLE 0x01 #define SMB_SCF_REQUIRED 0x02 #define SMB_SCF_STARTED 0x04 #define SMB_SCF_KEY_ISSET_THIS_LOGON 0x08 /* * smb_sign_ctx * * SMB signing context. * * ssc_seqnum sequence number * ssc_keylen mac key length * ssc_mid multiplex id - reserved * ssc_flags flags * ssc_mackey mac key * ssc_sign mac signature * */ typedef struct smb_sign_ctx { unsigned int ssc_seqnum; unsigned short ssc_keylen; unsigned short ssc_mid; unsigned int ssc_flags; unsigned char ssc_mackey[SMB_MAC_KEY_SZ]; unsigned char ssc_sign[SMB_SIG_SIZE]; } smb_sign_ctx_t; extern int smb_mac_init(smb_sign_ctx_t *sign_ctx, smb_auth_info_t *auth); extern int smb_mac_calc(smb_sign_ctx_t *sign_ctx, const unsigned char *buf, size_t buf_len, unsigned char *mac_sign); extern int smb_mac_chk(smb_sign_ctx_t *sign_ctx, const unsigned char *buf, size_t buf_len); extern int smb_mac_sign(smb_sign_ctx_t *sign_ctx, unsigned char *buf, size_t buf_len); extern void smb_mac_inc_seqnum(smb_sign_ctx_t *sign_ctx); extern void smb_mac_dec_seqnum(smb_sign_ctx_t *sign_ctx); /* * Each domain is categorized using the enum values below. * The local domain refers to the local machine and is named * after the local hostname. The primary domain is the domain * that the system joined. All other domains are either * trusted or untrusted, as defined by the primary domain PDC. */ typedef enum nt_domain_type { NT_DOMAIN_NULL, NT_DOMAIN_BUILTIN, NT_DOMAIN_LOCAL, NT_DOMAIN_PRIMARY, NT_DOMAIN_ACCOUNT, NT_DOMAIN_TRUSTED, NT_DOMAIN_UNTRUSTED, NT_DOMAIN_NUM_TYPES } nt_domain_type_t; /* * Information specific to trusted domains */ typedef struct smb_domain_trust { uint32_t dti_trust_direction; uint32_t dti_trust_type; uint32_t dti_trust_attrs; } smb_domain_trust_t; /* * DNS information for domain types that this info is * obtained/available. Currently this is only obtained * for the primary domain. */ typedef struct smb_domain_dns { char ddi_forest[MAXHOSTNAMELEN]; char ddi_guid[UUID_PRINTABLE_STRING_LENGTH]; } smb_domain_dns_t; /* * This is the information that is held about each domain. */ typedef struct nt_domain { list_node_t di_lnd; nt_domain_type_t di_type; char di_sid[SMB_SID_STRSZ]; char di_nbname[NETBIOS_NAME_SZ]; char di_fqname[MAXHOSTNAMELEN]; smb_sid_t *di_binsid; union { smb_domain_dns_t di_dns; smb_domain_trust_t di_trust; } di_u; } nt_domain_t; typedef struct smb_trusted_domains { uint32_t td_num; nt_domain_t *td_domains; } smb_trusted_domains_t; #define SMB_DOMAIN_SUCCESS 0 #define SMB_DOMAIN_NOMACHINE_SID 1 #define SMB_DOMAIN_NODOMAIN_SID 2 #define SMB_DOMAIN_NODOMAIN_NAME 3 #define SMB_DOMAIN_INTERNAL_ERR 4 #define SMB_DOMAIN_INVALID_ARG 5 #define SMB_DOMAIN_NO_MEMORY 6 typedef struct smb_domain { char d_dc[MAXHOSTNAMELEN]; nt_domain_t d_info; smb_trusted_domains_t d_trusted; } smb_domain_t; int nt_domain_init(uint32_t); void nt_domain_fini(void); void nt_domain_show(void); void nt_domain_save(void); boolean_t nt_domain_lookup_name(char *, nt_domain_t *); boolean_t nt_domain_lookup_sid(smb_sid_t *, nt_domain_t *); boolean_t nt_domain_lookup_type(nt_domain_type_t, nt_domain_t *); boolean_t nt_domain_get_primary(smb_domain_t *); void nt_domain_update(smb_domain_t *); void nt_domain_start_update(void); void nt_domain_end_update(void); void nt_domain_set_basic_info(char *, char *, char *, nt_domain_t *); void nt_domain_set_dns_info(char *, char *, char *, char *, char *, nt_domain_t *); void nt_domain_set_trust_info(char *, char *, char *, uint32_t, uint32_t, uint32_t, nt_domain_t *); typedef enum { SMB_LGRP_BUILTIN = 1, SMB_LGRP_LOCAL } smb_gdomain_t; typedef struct smb_gsid { smb_sid_t *gs_sid; uint16_t gs_type; } smb_gsid_t; typedef struct smb_giter { sqlite_vm *sgi_vm; sqlite *sgi_db; } smb_giter_t; typedef struct smb_group { char *sg_name; char *sg_cmnt; uint32_t sg_attr; uint32_t sg_rid; smb_gsid_t sg_id; smb_gdomain_t sg_domain; smb_privset_t *sg_privs; uint32_t sg_nmembers; smb_gsid_t *sg_members; } smb_group_t; int smb_lgrp_start(void); void smb_lgrp_stop(void); int smb_lgrp_add(char *, char *); int smb_lgrp_rename(char *, char *); int smb_lgrp_delete(char *); int smb_lgrp_setcmnt(char *, char *); int smb_lgrp_getcmnt(char *, char **); int smb_lgrp_getpriv(char *, uint8_t, boolean_t *); int smb_lgrp_setpriv(char *, uint8_t, boolean_t); int smb_lgrp_add_member(char *, smb_sid_t *, uint16_t); int smb_lgrp_del_member(char *, smb_sid_t *, uint16_t); int smb_lgrp_getbyname(char *, smb_group_t *); int smb_lgrp_getbyrid(uint32_t, smb_gdomain_t, smb_group_t *); void smb_lgrp_free(smb_group_t *); boolean_t smb_lgrp_is_member(smb_group_t *, smb_sid_t *); char *smb_lgrp_strerror(int); int smb_lgrp_iteropen(smb_giter_t *); void smb_lgrp_iterclose(smb_giter_t *); int smb_lgrp_iterate(smb_giter_t *, smb_group_t *); int smb_lookup_sid(smb_sid_t *, char *buf, int buflen); int smb_lookup_name(char *, smb_gsid_t *); #define SMB_LGRP_SUCCESS 0 #define SMB_LGRP_INVALID_ARG 1 #define SMB_LGRP_INVALID_MEMBER 2 #define SMB_LGRP_INVALID_NAME 3 #define SMB_LGRP_NOT_FOUND 4 #define SMB_LGRP_EXISTS 5 #define SMB_LGRP_NO_SID 6 #define SMB_LGRP_NO_LOCAL_SID 7 #define SMB_LGRP_SID_NOTLOCAL 8 #define SMB_LGRP_WKSID 9 #define SMB_LGRP_NO_MEMORY 10 #define SMB_LGRP_DB_ERROR 11 #define SMB_LGRP_DBINIT_ERROR 12 #define SMB_LGRP_INTERNAL_ERROR 13 #define SMB_LGRP_MEMBER_IN_GROUP 14 #define SMB_LGRP_MEMBER_NOT_IN_GROUP 15 #define SMB_LGRP_NO_SUCH_PRIV 16 #define SMB_LGRP_NO_SUCH_DOMAIN 17 #define SMB_LGRP_PRIV_HELD 18 #define SMB_LGRP_PRIV_NOT_HELD 19 #define SMB_LGRP_BAD_DATA 20 #define SMB_LGRP_NO_MORE 21 #define SMB_LGRP_DBOPEN_FAILED 22 #define SMB_LGRP_DBEXEC_FAILED 23 #define SMB_LGRP_DBINIT_FAILED 24 #define SMB_LGRP_DOMLKP_FAILED 25 #define SMB_LGRP_DOMINS_FAILED 26 #define SMB_LGRP_INSERT_FAILED 27 #define SMB_LGRP_DELETE_FAILED 28 #define SMB_LGRP_UPDATE_FAILED 29 #define SMB_LGRP_LOOKUP_FAILED 30 #define SMB_LGRP_NOT_SUPPORTED 31 #define SMB_LGRP_NAME_CHAR_MAX 32 #define SMB_LGRP_COMMENT_MAX 256 #define SMB_LGRP_NAME_MAX (SMB_LGRP_NAME_CHAR_MAX * MTS_MB_CHAR_MAX + 1) /* * values for smb_nic_t.smbflags */ #define SMB_NICF_NBEXCL 0x01 /* Excluded from Netbios activities */ #define SMB_NICF_ALIAS 0x02 /* This is an alias */ /* * smb_nic_t * nic_host actual host name * nic_nbname 16-byte NetBIOS host name */ typedef struct { char nic_host[MAXHOSTNAMELEN]; char nic_nbname[NETBIOS_NAME_SZ]; char nic_cmnt[SMB_PI_MAX_COMMENT]; char nic_ifname[LIFNAMSIZ]; smb_inaddr_t nic_ip; uint32_t nic_mask; uint32_t nic_bcast; uint32_t nic_smbflags; uint64_t nic_sysflags; } smb_nic_t; typedef struct smb_niciter { smb_nic_t ni_nic; int ni_cookie; int ni_seqnum; } smb_niciter_t; /* NIC config functions */ int smb_nic_init(void); void smb_nic_fini(void); int smb_nic_getnum(char *); int smb_nic_addhost(const char *, const char *, int, const char **); int smb_nic_delhost(const char *); int smb_nic_getfirst(smb_niciter_t *); int smb_nic_getnext(smb_niciter_t *); boolean_t smb_nic_is_local(smb_inaddr_t *); boolean_t smb_nic_is_same_subnet(smb_inaddr_t *); /* NIC Monitoring functions */ int smb_nicmon_start(const char *); void smb_nicmon_stop(void); /* * Well-known account structure * * A security identifier (SID) is a unique value of variable length that * is used to identify a security principal or security group in * Windows. Well-known SIDs are a group of SIDs that identify generic * users or generic groups. Their values remain constant across all * operating systems. * * This structure is defined to store these SIDs and other related * information about them (e.g. account and domain names) in a * predefined table. */ typedef struct smb_wka { uint8_t wka_domidx; char *wka_sid; char *wka_name; uint16_t wka_type; uint16_t wka_flags; char *wka_desc; smb_sid_t *wka_binsid; } smb_wka_t; /* * Defined values for smb_wka.wka_flags * * SMB_WKAFLG_LGRP_ENABLE Can be added as local group */ #define SMB_WKAFLG_LGRP_ENABLE 0x1 /* * Well-known account interfaces */ int smb_wka_init(void); void smb_wka_fini(void); smb_wka_t *smb_wka_lookup_name(char *); smb_wka_t *smb_wka_lookup_sid(smb_sid_t *); smb_sid_t *smb_wka_get_sid(char *); char *smb_wka_get_domain(int); uint32_t smb_wka_token_groups(uint32_t, smb_ids_t *); /* * In memory account representation */ typedef struct smb_account { char *a_name; char *a_domain; uint16_t a_type; smb_sid_t *a_sid; smb_sid_t *a_domsid; uint32_t a_rid; } smb_account_t; uint32_t smb_sam_lookup_name(char *, char *, uint16_t, smb_account_t *); uint32_t smb_sam_lookup_sid(smb_sid_t *, smb_account_t *); int smb_sam_usr_cnt(void); uint32_t smb_sam_usr_groups(smb_sid_t *, smb_ids_t *); int smb_sam_grp_cnt(nt_domain_type_t); void smb_account_free(smb_account_t *); boolean_t smb_account_validate(smb_account_t *); /* * Security Descriptor functions. */ uint32_t smb_sd_read(char *path, smb_sd_t *, uint32_t); uint32_t smb_sd_write(char *path, smb_sd_t *, uint32_t); /* Kernel Module Interface */ int smb_kmod_bind(void); int smb_kmod_setcfg(smb_kmod_cfg_t *); int smb_kmod_setgmtoff(int32_t); int smb_kmod_start(int, int, int); int smb_kmod_tcplisten(int); int smb_kmod_nbtlisten(int); int smb_kmod_tcpreceive(void); int smb_kmod_nbtreceive(void); void smb_kmod_unbind(void); int smb_kmod_share(char *, char *); int smb_kmod_unshare(char *, char *); int smb_kmod_get_usernum(uint32_t *); int smb_kmod_get_userlist(smb_ulist_t *); #ifdef __cplusplus } #endif #endif /* _LIBSMB_H */