1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _LIBSMB_H 27 #define _LIBSMB_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #include <sys/types.h> 34 #include <sys/list.h> 35 #include <arpa/inet.h> 36 #include <net/if.h> 37 #include <inet/tcp.h> 38 #include <uuid/uuid.h> 39 #include <netdb.h> 40 #include <stdlib.h> 41 #include <libscf.h> 42 #include <libshare.h> 43 #include <sqlite/sqlite.h> 44 #include <uuid/uuid.h> 45 46 #include <smbsrv/string.h> 47 #include <smbsrv/smb_idmap.h> 48 #include <smbsrv/netbios.h> 49 #include <smbsrv/smb_share.h> 50 #include <smbsrv/ntstatus.h> 51 #include <smbsrv/smb_door_svc.h> 52 #include <smbsrv/alloc.h> 53 #include <smbsrv/codepage.h> 54 #include <smbsrv/ctype.h> 55 #include <smbsrv/hash_table.h> 56 #include <smbsrv/msgbuf.h> 57 #include <smbsrv/oem.h> 58 #include <smbsrv/smb_i18n.h> 59 #include <smbsrv/wintypes.h> 60 #include <smbsrv/smb_xdr.h> 61 #include <smbsrv/smbinfo.h> 62 #include <smbsrv/ntifs.h> 63 64 #define SMB_VARRUN_DIR "/var/run/smb" 65 #define SMB_CCACHE_FILE "ccache" 66 #define SMB_CCACHE_PATH SMB_VARRUN_DIR "/" SMB_CCACHE_FILE 67 68 69 /* Max value length of all SMB properties */ 70 #define MAX_VALUE_BUFLEN 512 71 72 #define SMBD_FMRI_PREFIX "network/smb/server" 73 #define SMBD_DEFAULT_INSTANCE_FMRI "svc:/network/smb/server:default" 74 #define SMBD_PG_NAME "smbd" 75 #define SMBD_PROTECTED_PG_NAME "read" 76 #define SMBD_EXEC_PG_NAME "exec" 77 78 #define SMBD_SMF_OK 0 79 #define SMBD_SMF_NO_MEMORY 1 /* no memory for data structures */ 80 #define SMBD_SMF_SYSTEM_ERR 2 /* system error, use errno */ 81 #define SMBD_SMF_NO_PERMISSION 3 /* no permission for operation */ 82 #define SMBD_SMF_INVALID_ARG 4 83 84 #define SCH_STATE_UNINIT 0 85 #define SCH_STATE_INITIALIZING 1 86 #define SCH_STATE_INIT 2 87 88 typedef struct smb_scfhandle { 89 scf_handle_t *scf_handle; 90 int scf_state; 91 scf_service_t *scf_service; 92 scf_scope_t *scf_scope; 93 scf_transaction_t *scf_trans; 94 scf_transaction_entry_t *scf_entry; 95 scf_propertygroup_t *scf_pg; 96 scf_instance_t *scf_instance; 97 scf_iter_t *scf_inst_iter; 98 scf_iter_t *scf_pg_iter; 99 } smb_scfhandle_t; 100 101 /* 102 * CIFS Configuration Management 103 */ 104 typedef enum { 105 SMB_CI_OPLOCK_ENABLE = 0, 106 107 SMB_CI_AUTOHOME_MAP, 108 109 SMB_CI_DOMAIN_SID, 110 SMB_CI_DOMAIN_MEMB, 111 SMB_CI_DOMAIN_NAME, 112 SMB_CI_DOMAIN_FQDN, 113 SMB_CI_DOMAIN_FOREST, 114 SMB_CI_DOMAIN_GUID, 115 SMB_CI_DOMAIN_SRV, 116 117 SMB_CI_WINS_SRV1, 118 SMB_CI_WINS_SRV2, 119 SMB_CI_WINS_EXCL, 120 121 SMB_CI_MAX_WORKERS, 122 SMB_CI_MAX_CONNECTIONS, 123 SMB_CI_KEEPALIVE, 124 SMB_CI_RESTRICT_ANON, 125 126 SMB_CI_SIGNING_ENABLE, 127 SMB_CI_SIGNING_REQD, 128 129 SMB_CI_SYNC_ENABLE, 130 131 SMB_CI_SECURITY, 132 SMB_CI_NBSCOPE, 133 SMB_CI_SYS_CMNT, 134 SMB_CI_LM_LEVEL, 135 136 SMB_CI_ADS_SITE, 137 138 SMB_CI_DYNDNS_ENABLE, 139 140 SMB_CI_MACHINE_PASSWD, 141 SMB_CI_KPASSWD_SRV, 142 SMB_CI_KPASSWD_DOMAIN, 143 SMB_CI_KPASSWD_SEQNUM, 144 SMB_CI_NETLOGON_SEQNUM, 145 SMB_CI_IPV6_ENABLE, 146 SMB_CI_MAP, 147 SMB_CI_UNMAP, 148 SMB_CI_DISPOSITION, 149 SMB_CI_MAX 150 } smb_cfg_id_t; 151 152 /* SMF helper functions */ 153 extern smb_scfhandle_t *smb_smf_scf_init(char *); 154 extern void smb_smf_scf_fini(smb_scfhandle_t *); 155 extern int smb_smf_start_transaction(smb_scfhandle_t *); 156 extern int smb_smf_end_transaction(smb_scfhandle_t *); 157 extern int smb_smf_set_string_property(smb_scfhandle_t *, char *, char *); 158 extern int smb_smf_get_string_property(smb_scfhandle_t *, char *, 159 char *, size_t); 160 extern int smb_smf_set_integer_property(smb_scfhandle_t *, char *, int64_t); 161 extern int smb_smf_get_integer_property(smb_scfhandle_t *, char *, int64_t *); 162 extern int smb_smf_set_boolean_property(smb_scfhandle_t *, char *, uint8_t); 163 extern int smb_smf_get_boolean_property(smb_scfhandle_t *, char *, uint8_t *); 164 extern int smb_smf_set_opaque_property(smb_scfhandle_t *, char *, 165 void *, size_t); 166 extern int smb_smf_get_opaque_property(smb_scfhandle_t *, char *, 167 void *, size_t); 168 extern int smb_smf_create_service_pgroup(smb_scfhandle_t *, char *); 169 extern int smb_smf_restart_service(void); 170 extern int smb_smf_maintenance_mode(void); 171 172 /* ZFS interface */ 173 int smb_getdataset(const char *, char *, size_t); 174 175 /* Configuration management functions */ 176 extern int smb_config_get(smb_cfg_id_t, char *, int); 177 extern char *smb_config_getname(smb_cfg_id_t); 178 extern int smb_config_getstr(smb_cfg_id_t, char *, int); 179 extern int smb_config_getnum(smb_cfg_id_t, int64_t *); 180 extern boolean_t smb_config_getbool(smb_cfg_id_t); 181 182 extern int smb_config_set(smb_cfg_id_t, char *); 183 extern int smb_config_setstr(smb_cfg_id_t, char *); 184 extern int smb_config_setnum(smb_cfg_id_t, int64_t); 185 extern int smb_config_setbool(smb_cfg_id_t, boolean_t); 186 187 extern uint8_t smb_config_get_fg_flag(void); 188 extern char *smb_config_get_localsid(void); 189 extern int smb_config_secmode_fromstr(char *); 190 extern char *smb_config_secmode_tostr(int); 191 extern int smb_config_get_secmode(void); 192 extern int smb_config_set_secmode(int); 193 extern int smb_config_set_idmap_domain(char *); 194 extern int smb_config_refresh_idmap(void); 195 extern int smb_config_getip(smb_cfg_id_t, smb_inaddr_t *); 196 197 extern void smb_load_kconfig(smb_kmod_cfg_t *kcfg); 198 extern uint32_t smb_crc_gen(uint8_t *, size_t); 199 200 extern boolean_t smb_match_netlogon_seqnum(void); 201 extern int smb_setdomainprops(char *, char *, char *); 202 extern void smb_update_netlogon_seqnum(void); 203 204 /* maximum password length on Windows 2000 and above */ 205 #define SMB_PASSWD_MAXLEN 127 206 #define SMB_USERNAME_MAXLEN 40 207 208 typedef struct smb_joininfo { 209 char domain_name[MAXHOSTNAMELEN]; 210 char domain_username[SMB_USERNAME_MAXLEN + 1]; 211 char domain_passwd[SMB_PASSWD_MAXLEN + 1]; 212 uint32_t mode; 213 } smb_joininfo_t; 214 215 /* APIs to communicate with SMB daemon via door calls */ 216 extern uint32_t smb_join(smb_joininfo_t *info); 217 extern bool_t xdr_smb_dr_joininfo_t(XDR *, smb_joininfo_t *); 218 extern boolean_t smb_find_ads_server(char *, char *, int); 219 220 extern void smb_config_getdomaininfo(char *, char *, char *, char *, char *); 221 extern void smb_config_setdomaininfo(char *, char *, char *, char *, char *); 222 extern uint32_t smb_get_dcinfo(char *, uint32_t, smb_inaddr_t *); 223 224 /* 225 * buffer context structure. This is used to keep track of the buffer 226 * context. 227 * 228 * basep: points to the beginning of the buffer 229 * curp: points to the current offset 230 * endp: points to the limit of the buffer 231 */ 232 typedef struct { 233 unsigned char *basep; 234 unsigned char *curp; 235 unsigned char *endp; 236 } smb_ctxbuf_t; 237 238 extern int smb_ctxbuf_init(smb_ctxbuf_t *ctx, unsigned char *buf, 239 size_t buflen); 240 extern int smb_ctxbuf_len(smb_ctxbuf_t *ctx); 241 extern int smb_ctxbuf_printf(smb_ctxbuf_t *ctx, const char *fmt, ...); 242 243 /* Functions to handle SMB daemon communications with idmap service */ 244 extern int smb_idmap_start(void); 245 extern void smb_idmap_stop(void); 246 extern int smb_idmap_restart(void); 247 248 /* Miscellaneous functions */ 249 extern void hexdump(unsigned char *, int); 250 extern size_t bintohex(const char *, size_t, char *, size_t); 251 extern size_t hextobin(const char *, size_t, char *, size_t); 252 extern char *strstrip(char *, const char *); 253 extern char *strtrim(char *, const char *); 254 extern char *trim_whitespace(char *); 255 extern void randomize(char *, unsigned); 256 extern void rand_hash(unsigned char *, size_t, unsigned char *, size_t); 257 258 extern int smb_getdomainname(char *, size_t); 259 extern int smb_getfqdomainname(char *, size_t); 260 extern int smb_gethostname(char *, size_t, int); 261 extern int smb_getfqhostname(char *, size_t); 262 extern int smb_getnetbiosname(char *, size_t); 263 extern struct hostent *smb_gethostbyname(const char *, int *); 264 extern struct hostent *smb_gethostbyaddr(const char *, int, int, int *); 265 266 #define SMB_SAMACCT_MAXLEN (NETBIOS_NAME_SZ + 1) 267 extern int smb_getsamaccount(char *, size_t); 268 269 extern int smb_get_nameservers(smb_inaddr_t *, int); 270 extern void smb_tonetbiosname(char *, char *, char); 271 272 extern int smb_chk_hostaccess(smb_inaddr_t *, char *); 273 274 extern int smb_getnameinfo(smb_inaddr_t *, char *, int, int); 275 276 void smb_trace(const char *s); 277 void smb_tracef(const char *fmt, ...); 278 279 /* 280 * Authentication 281 */ 282 283 #define SMBAUTH_LM_MAGIC_STR "KGS!@#$%" 284 285 #define SMBAUTH_HASH_SZ 16 /* also LM/NTLM/NTLMv2 Hash size */ 286 #define SMBAUTH_LM_RESP_SZ 24 /* also NTLM Response size */ 287 #define SMBAUTH_LM_PWD_SZ 14 /* LM password size */ 288 #define SMBAUTH_V2_CLNT_CHALLENGE_SZ 8 /* both LMv2 and NTLMv2 */ 289 #define SMBAUTH_SESSION_KEY_SZ SMBAUTH_HASH_SZ 290 #define SMBAUTH_HEXHASH_SZ (SMBAUTH_HASH_SZ * 2) 291 292 #define SMBAUTH_FAILURE 1 293 #define SMBAUTH_SUCCESS 0 294 #define MD_DIGEST_LEN 16 295 296 /* 297 * Name Types 298 * 299 * The list of names near the end of the data blob (i.e. the ndb_names 300 * field of the smb_auth_data_blob_t data structure) can be classify into 301 * the following types: 302 * 303 * 0x0000 Indicates the end of the list. 304 * 0x0001 The name is a NetBIOS machine name (e.g. server name) 305 * 0x0002 The name is an NT Domain NetBIOS name. 306 * 0x0003 The name is the server's DNS hostname. 307 * 0x0004 The name is a W2K Domain name (a DNS name). 308 */ 309 #define SMBAUTH_NAME_TYPE_LIST_END 0x0000 310 #define SMBAUTH_NAME_TYPE_SERVER_NETBIOS 0x0001 311 #define SMBAUTH_NAME_TYPE_DOMAIN_NETBIOS 0x0002 312 #define SMBAUTH_NAME_TYPE_SERVER_DNS 0x0003 313 #define SMBAUTH_NAME_TYPE_DOMAIN_DNS 0x0004 314 315 /* 316 * smb_auth_name_entry_t 317 * 318 * Each name entry in the data blob consists of the following 3 fields: 319 * 320 * nne_type - name type 321 * nne_len - the length of the name 322 * nne_name - the name, in uppercase UCS-2LE Unicode format 323 */ 324 typedef struct smb_auth_name_entry { 325 unsigned short nne_type; 326 unsigned short nne_len; 327 mts_wchar_t nne_name[SMB_PI_MAX_DOMAIN * 2]; 328 } smb_auth_name_entry_t; 329 330 /* 331 * smb_auth_data_blob 332 * 333 * The format of this NTLMv2 data blob structure is as follow: 334 * 335 * - Blob Signature 0x01010000 (4 bytes) 336 * - Reserved (0x00000000) (4 bytes) 337 * - Timestamp Little-endian, 64-bit signed value representing 338 * the number of tenths of a microsecond since January 1, 1601. 339 * (8 bytes) 340 * - Client Challenge (8 bytes) 341 * - Unknown1 (4 bytes) 342 * - List of Target Information (variable length) 343 * - Unknown2 (4 bytes) 344 */ 345 typedef struct smb_auth_data_blob { 346 unsigned char ndb_signature[4]; 347 unsigned char ndb_reserved[4]; 348 uint64_t ndb_timestamp; 349 unsigned char ndb_clnt_challenge[SMBAUTH_V2_CLNT_CHALLENGE_SZ]; 350 unsigned char ndb_unknown[4]; 351 smb_auth_name_entry_t ndb_names[2]; 352 unsigned char ndb_unknown2[4]; 353 } smb_auth_data_blob_t; 354 355 #define SMBAUTH_BLOB_MAXLEN (sizeof (smb_auth_data_blob_t)) 356 #define SMBAUTH_CI_MAXLEN SMBAUTH_LM_RESP_SZ 357 #define SMBAUTH_CS_MAXLEN (SMBAUTH_BLOB_MAXLEN + SMBAUTH_HASH_SZ) 358 359 /* 360 * smb_auth_info_t 361 * 362 * The structure contains all the authentication information 363 * needed for the preparaton of the SMBSessionSetupAndx request 364 * and the user session key. 365 * 366 * hash - NTLM hash 367 * hash_v2 - NTLMv2 hash 368 * ci_len - the length of the case-insensitive password 369 * ci - case-insensitive password 370 * (If NTLMv2 authentication mechanism is used, it 371 * represents the LMv2 response. Otherwise, it 372 * is empty.) 373 * cs_len - the length of the case-sensitive password 374 * cs - case-sensitive password 375 * (If NTLMv2 authentication mechanism is used, it 376 * represents the NTLMv2 response. Otherwise, it 377 * represents the NTLM response.) 378 * data_blob - NTLMv2 data blob 379 */ 380 typedef struct smb_auth_info { 381 unsigned char hash[SMBAUTH_HASH_SZ]; 382 unsigned char hash_v2[SMBAUTH_HASH_SZ]; 383 unsigned short ci_len; 384 unsigned char ci[SMBAUTH_CI_MAXLEN]; 385 unsigned short cs_len; 386 unsigned char cs[SMBAUTH_CS_MAXLEN]; 387 int lmcompatibility_lvl; 388 smb_auth_data_blob_t data_blob; 389 } smb_auth_info_t; 390 391 /* 392 * SMB password management 393 */ 394 395 #define SMB_PWF_LM 0x01 /* LM hash is present */ 396 #define SMB_PWF_NT 0x02 /* NT hash is present */ 397 #define SMB_PWF_DISABLE 0x04 /* Account is disabled */ 398 399 typedef struct smb_passwd { 400 uid_t pw_uid; 401 uint32_t pw_flags; 402 char pw_name[SMB_USERNAME_MAXLEN]; 403 uint8_t pw_lmhash[SMBAUTH_HASH_SZ]; 404 uint8_t pw_nthash[SMBAUTH_HASH_SZ]; 405 } smb_passwd_t; 406 407 /* 408 * Control flags passed to smb_pwd_setcntl 409 */ 410 #define SMB_PWC_DISABLE 0x01 411 #define SMB_PWC_ENABLE 0x02 412 #define SMB_PWC_NOLM 0x04 413 414 #define SMB_PWE_SUCCESS 0 415 #define SMB_PWE_USER_UNKNOWN 1 416 #define SMB_PWE_USER_DISABLE 2 417 #define SMB_PWE_CLOSE_FAILED 3 418 #define SMB_PWE_OPEN_FAILED 4 419 #define SMB_PWE_WRITE_FAILED 6 420 #define SMB_PWE_UPDATE_FAILED 7 421 #define SMB_PWE_STAT_FAILED 8 422 #define SMB_PWE_BUSY 9 423 #define SMB_PWE_DENIED 10 424 #define SMB_PWE_SYSTEM_ERROR 11 425 #define SMB_PWE_INVALID_PARAM 12 426 #define SMB_PWE_NO_MEMORY 13 427 #define SMB_PWE_MAX 14 428 429 typedef struct smb_pwditer { 430 void *spi_next; 431 } smb_pwditer_t; 432 433 typedef struct smb_luser { 434 char *su_name; 435 char *su_fullname; 436 char *su_desc; 437 uint32_t su_rid; 438 uint32_t su_ctrl; 439 } smb_luser_t; 440 441 extern void smb_pwd_init(boolean_t); 442 extern void smb_pwd_fini(void); 443 extern smb_passwd_t *smb_pwd_getpwnam(const char *, smb_passwd_t *); 444 extern smb_passwd_t *smb_pwd_getpwuid(uid_t, smb_passwd_t *); 445 extern int smb_pwd_setpasswd(const char *, const char *); 446 extern int smb_pwd_setcntl(const char *, int); 447 448 extern int smb_pwd_iteropen(smb_pwditer_t *); 449 extern smb_luser_t *smb_pwd_iterate(smb_pwditer_t *); 450 extern void smb_pwd_iterclose(smb_pwditer_t *); 451 452 extern int smb_auth_qnd_unicode(mts_wchar_t *, const char *, int); 453 extern int smb_auth_hmac_md5(unsigned char *, int, unsigned char *, int, 454 unsigned char *); 455 456 /* 457 * A variation on HMAC-MD5 known as HMACT64 is used by Windows systems. 458 * The HMACT64() function is the same as the HMAC-MD5() except that 459 * it truncates the input key to 64 bytes rather than hashing it down 460 * to 16 bytes using the MD5() function. 461 */ 462 #define SMBAUTH_HMACT64(D, Ds, K, Ks, digest) \ 463 smb_auth_hmac_md5(D, Ds, K, (Ks > 64) ? 64 : Ks, digest) 464 465 extern int smb_auth_DES(unsigned char *, int, unsigned char *, int, 466 unsigned char *, int); 467 468 extern int smb_auth_md4(unsigned char *, unsigned char *, int); 469 extern int smb_auth_lm_hash(const char *, unsigned char *); 470 extern int smb_auth_ntlm_hash(const char *, unsigned char *); 471 472 extern int smb_auth_set_info(char *, char *, 473 unsigned char *, char *, unsigned char *, 474 int, int, smb_auth_info_t *); 475 476 extern int smb_auth_ntlmv2_hash(unsigned char *, 477 char *, char *, unsigned char *); 478 479 extern int smb_auth_gen_session_key(smb_auth_info_t *, unsigned char *); 480 481 boolean_t smb_auth_validate_lm(unsigned char *, uint32_t, smb_passwd_t *, 482 unsigned char *, int, char *, char *); 483 boolean_t smb_auth_validate_nt(unsigned char *, uint32_t, smb_passwd_t *, 484 unsigned char *, int, char *, char *, uchar_t *); 485 486 /* 487 * SMB authenticated IPC 488 */ 489 extern void smb_ipc_commit(void); 490 extern void smb_ipc_get_user(char *, size_t); 491 extern void smb_ipc_get_passwd(uint8_t *, size_t); 492 extern void smb_ipc_init(void); 493 extern void smb_ipc_rollback(void); 494 extern void smb_ipc_set(char *, uint8_t *); 495 496 /* 497 * SMB MAC Signing 498 */ 499 500 #define SMB_MAC_KEY_SZ (SMBAUTH_SESSION_KEY_SZ + SMBAUTH_CS_MAXLEN) 501 #define SMB_SIG_OFFS 14 /* signature field offset within header */ 502 #define SMB_SIG_SIZE 8 /* SMB signature size */ 503 504 /* 505 * Signing flags: 506 * 507 * SMB_SCF_ENABLE Signing is enabled. 508 * 509 * SMB_SCF_REQUIRED Signing is enabled and required. 510 * This flag shouldn't be set if 511 * SMB_SCF_ENABLE isn't set. 512 * 513 * SMB_SCF_STARTED Signing will start after receiving 514 * the first non-anonymous SessionSetup 515 * request. 516 * 517 * SMB_SCF_KEY_ISSET_THIS_LOGON Indicates whether the MAC key has just 518 * been set for this logon. (prior to 519 * sending the SMBSessionSetup request) 520 * 521 */ 522 #define SMB_SCF_ENABLE 0x01 523 #define SMB_SCF_REQUIRED 0x02 524 #define SMB_SCF_STARTED 0x04 525 #define SMB_SCF_KEY_ISSET_THIS_LOGON 0x08 526 527 /* 528 * smb_sign_ctx 529 * 530 * SMB signing context. 531 * 532 * ssc_seqnum sequence number 533 * ssc_keylen mac key length 534 * ssc_mid multiplex id - reserved 535 * ssc_flags flags 536 * ssc_mackey mac key 537 * ssc_sign mac signature 538 * 539 */ 540 typedef struct smb_sign_ctx { 541 unsigned int ssc_seqnum; 542 unsigned short ssc_keylen; 543 unsigned short ssc_mid; 544 unsigned int ssc_flags; 545 unsigned char ssc_mackey[SMB_MAC_KEY_SZ]; 546 unsigned char ssc_sign[SMB_SIG_SIZE]; 547 } smb_sign_ctx_t; 548 549 extern int smb_mac_init(smb_sign_ctx_t *sign_ctx, smb_auth_info_t *auth); 550 extern int smb_mac_calc(smb_sign_ctx_t *sign_ctx, 551 const unsigned char *buf, size_t buf_len, unsigned char *mac_sign); 552 extern int smb_mac_chk(smb_sign_ctx_t *sign_ctx, 553 const unsigned char *buf, size_t buf_len); 554 extern int smb_mac_sign(smb_sign_ctx_t *sign_ctx, 555 unsigned char *buf, size_t buf_len); 556 extern void smb_mac_inc_seqnum(smb_sign_ctx_t *sign_ctx); 557 extern void smb_mac_dec_seqnum(smb_sign_ctx_t *sign_ctx); 558 559 /* 560 * Each domain is categorized using the enum values below. 561 * The local domain refers to the local machine and is named 562 * after the local hostname. The primary domain is the domain 563 * that the system joined. All other domains are either 564 * trusted or untrusted, as defined by the primary domain PDC. 565 */ 566 typedef enum smb_domain_type { 567 SMB_DOMAIN_NULL, 568 SMB_DOMAIN_BUILTIN, 569 SMB_DOMAIN_LOCAL, 570 SMB_DOMAIN_PRIMARY, 571 SMB_DOMAIN_ACCOUNT, 572 SMB_DOMAIN_TRUSTED, 573 SMB_DOMAIN_UNTRUSTED, 574 SMB_DOMAIN_NUM_TYPES 575 } smb_domain_type_t; 576 577 /* 578 * Information specific to trusted domains 579 */ 580 typedef struct smb_domain_trust { 581 uint32_t dti_trust_direction; 582 uint32_t dti_trust_type; 583 uint32_t dti_trust_attrs; 584 } smb_domain_trust_t; 585 586 /* 587 * DNS information for domain types that this info is 588 * obtained/available. Currently this is only obtained 589 * for the primary domain. 590 */ 591 typedef struct smb_domain_dns { 592 char ddi_forest[MAXHOSTNAMELEN]; 593 char ddi_guid[UUID_PRINTABLE_STRING_LENGTH]; 594 } smb_domain_dns_t; 595 596 /* 597 * This is the information that is held about each domain. 598 */ 599 typedef struct smb_domain { 600 list_node_t di_lnd; 601 smb_domain_type_t di_type; 602 char di_sid[SMB_SID_STRSZ]; 603 char di_nbname[NETBIOS_NAME_SZ]; 604 char di_fqname[MAXHOSTNAMELEN]; 605 smb_sid_t *di_binsid; 606 union { 607 smb_domain_dns_t di_dns; 608 smb_domain_trust_t di_trust; 609 } di_u; 610 } smb_domain_t; 611 612 typedef struct smb_trusted_domains { 613 uint32_t td_num; 614 smb_domain_t *td_domains; 615 } smb_trusted_domains_t; 616 617 #define SMB_DOMAIN_SUCCESS 0 618 #define SMB_DOMAIN_NOMACHINE_SID 1 619 #define SMB_DOMAIN_NODOMAIN_SID 2 620 #define SMB_DOMAIN_NODOMAIN_NAME 3 621 #define SMB_DOMAIN_INTERNAL_ERR 4 622 #define SMB_DOMAIN_INVALID_ARG 5 623 #define SMB_DOMAIN_NO_MEMORY 6 624 #define SMB_DOMAIN_NO_CACHE 7 625 626 /* 627 * This structure could contain information about 628 * the primary domain the name of selected domain controller 629 * for the primary domain and a list of trusted domains if 630 * any. The "ex" in the structure name stands for extended. 631 * This is to differentiate this structure from smb_domain_t 632 * which only contains information about a single domain. 633 */ 634 typedef struct smb_domainex { 635 char d_dc[MAXHOSTNAMELEN]; 636 smb_domain_t d_primary; 637 smb_trusted_domains_t d_trusted; 638 } smb_domainex_t; 639 640 int smb_domain_init(uint32_t); 641 void smb_domain_fini(void); 642 void smb_domain_show(void); 643 void smb_domain_save(void); 644 boolean_t smb_domain_lookup_name(char *, smb_domain_t *); 645 boolean_t smb_domain_lookup_sid(smb_sid_t *, smb_domain_t *); 646 boolean_t smb_domain_lookup_type(smb_domain_type_t, smb_domain_t *); 647 boolean_t smb_domain_getinfo(smb_domainex_t *); 648 void smb_domain_update(smb_domainex_t *); 649 uint32_t smb_domain_start_update(void); 650 void smb_domain_end_update(void); 651 void smb_domain_set_basic_info(char *, char *, char *, smb_domain_t *); 652 void smb_domain_set_dns_info(char *, char *, char *, char *, char *, 653 smb_domain_t *); 654 void smb_domain_set_trust_info(char *, char *, char *, 655 uint32_t, uint32_t, uint32_t, smb_domain_t *); 656 657 typedef enum { 658 SMB_LGRP_BUILTIN = 1, 659 SMB_LGRP_LOCAL 660 } smb_gdomain_t; 661 662 typedef struct smb_gsid { 663 smb_sid_t *gs_sid; 664 uint16_t gs_type; 665 } smb_gsid_t; 666 667 typedef struct smb_giter { 668 sqlite_vm *sgi_vm; 669 sqlite *sgi_db; 670 } smb_giter_t; 671 672 typedef struct smb_group { 673 char *sg_name; 674 char *sg_cmnt; 675 uint32_t sg_attr; 676 uint32_t sg_rid; 677 smb_gsid_t sg_id; 678 smb_gdomain_t sg_domain; 679 smb_privset_t *sg_privs; 680 uint32_t sg_nmembers; 681 smb_gsid_t *sg_members; 682 } smb_group_t; 683 684 int smb_lgrp_start(void); 685 void smb_lgrp_stop(void); 686 int smb_lgrp_add(char *, char *); 687 int smb_lgrp_rename(char *, char *); 688 int smb_lgrp_delete(char *); 689 int smb_lgrp_setcmnt(char *, char *); 690 int smb_lgrp_getcmnt(char *, char **); 691 int smb_lgrp_getpriv(char *, uint8_t, boolean_t *); 692 int smb_lgrp_setpriv(char *, uint8_t, boolean_t); 693 int smb_lgrp_add_member(char *, smb_sid_t *, uint16_t); 694 int smb_lgrp_del_member(char *, smb_sid_t *, uint16_t); 695 int smb_lgrp_getbyname(char *, smb_group_t *); 696 int smb_lgrp_getbyrid(uint32_t, smb_gdomain_t, smb_group_t *); 697 void smb_lgrp_free(smb_group_t *); 698 boolean_t smb_lgrp_is_member(smb_group_t *, smb_sid_t *); 699 char *smb_lgrp_strerror(int); 700 int smb_lgrp_iteropen(smb_giter_t *); 701 void smb_lgrp_iterclose(smb_giter_t *); 702 int smb_lgrp_iterate(smb_giter_t *, smb_group_t *); 703 704 int smb_lookup_sid(smb_sid_t *, char *buf, int buflen); 705 int smb_lookup_name(char *, smb_gsid_t *); 706 707 #define SMB_LGRP_SUCCESS 0 708 #define SMB_LGRP_INVALID_ARG 1 709 #define SMB_LGRP_INVALID_MEMBER 2 710 #define SMB_LGRP_INVALID_NAME 3 711 #define SMB_LGRP_NOT_FOUND 4 712 #define SMB_LGRP_EXISTS 5 713 #define SMB_LGRP_NO_SID 6 714 #define SMB_LGRP_NO_LOCAL_SID 7 715 #define SMB_LGRP_SID_NOTLOCAL 8 716 #define SMB_LGRP_WKSID 9 717 #define SMB_LGRP_NO_MEMORY 10 718 #define SMB_LGRP_DB_ERROR 11 719 #define SMB_LGRP_DBINIT_ERROR 12 720 #define SMB_LGRP_INTERNAL_ERROR 13 721 #define SMB_LGRP_MEMBER_IN_GROUP 14 722 #define SMB_LGRP_MEMBER_NOT_IN_GROUP 15 723 #define SMB_LGRP_NO_SUCH_PRIV 16 724 #define SMB_LGRP_NO_SUCH_DOMAIN 17 725 #define SMB_LGRP_PRIV_HELD 18 726 #define SMB_LGRP_PRIV_NOT_HELD 19 727 #define SMB_LGRP_BAD_DATA 20 728 #define SMB_LGRP_NO_MORE 21 729 #define SMB_LGRP_DBOPEN_FAILED 22 730 #define SMB_LGRP_DBEXEC_FAILED 23 731 #define SMB_LGRP_DBINIT_FAILED 24 732 #define SMB_LGRP_DOMLKP_FAILED 25 733 #define SMB_LGRP_DOMINS_FAILED 26 734 #define SMB_LGRP_INSERT_FAILED 27 735 #define SMB_LGRP_DELETE_FAILED 28 736 #define SMB_LGRP_UPDATE_FAILED 29 737 #define SMB_LGRP_LOOKUP_FAILED 30 738 #define SMB_LGRP_NOT_SUPPORTED 31 739 740 #define SMB_LGRP_NAME_CHAR_MAX 32 741 #define SMB_LGRP_COMMENT_MAX 256 742 #define SMB_LGRP_NAME_MAX (SMB_LGRP_NAME_CHAR_MAX * MTS_MB_CHAR_MAX + 1) 743 744 /* 745 * values for smb_nic_t.smbflags 746 */ 747 #define SMB_NICF_NBEXCL 0x01 /* Excluded from Netbios activities */ 748 #define SMB_NICF_ALIAS 0x02 /* This is an alias */ 749 750 /* 751 * smb_nic_t 752 * nic_host actual host name 753 * nic_nbname 16-byte NetBIOS host name 754 */ 755 typedef struct { 756 char nic_host[MAXHOSTNAMELEN]; 757 char nic_nbname[NETBIOS_NAME_SZ]; 758 char nic_cmnt[SMB_PI_MAX_COMMENT]; 759 char nic_ifname[LIFNAMSIZ]; 760 smb_inaddr_t nic_ip; 761 uint32_t nic_mask; 762 uint32_t nic_bcast; 763 uint32_t nic_smbflags; 764 uint64_t nic_sysflags; 765 } smb_nic_t; 766 767 typedef struct smb_niciter { 768 smb_nic_t ni_nic; 769 int ni_cookie; 770 int ni_seqnum; 771 } smb_niciter_t; 772 773 /* NIC config functions */ 774 int smb_nic_init(void); 775 void smb_nic_fini(void); 776 int smb_nic_getnum(char *); 777 int smb_nic_addhost(const char *, const char *, int, const char **); 778 int smb_nic_delhost(const char *); 779 int smb_nic_getfirst(smb_niciter_t *); 780 int smb_nic_getnext(smb_niciter_t *); 781 boolean_t smb_nic_is_local(smb_inaddr_t *); 782 boolean_t smb_nic_is_same_subnet(smb_inaddr_t *); 783 784 /* NIC Monitoring functions */ 785 int smb_nicmon_start(const char *); 786 void smb_nicmon_stop(void); 787 788 /* 789 * Well-known account structure 790 * 791 * A security identifier (SID) is a unique value of variable length that 792 * is used to identify a security principal or security group in 793 * Windows. Well-known SIDs are a group of SIDs that identify generic 794 * users or generic groups. Their values remain constant across all 795 * operating systems. 796 * 797 * This structure is defined to store these SIDs and other related 798 * information about them (e.g. account and domain names) in a 799 * predefined table. 800 */ 801 typedef struct smb_wka { 802 uint8_t wka_domidx; 803 char *wka_sid; 804 char *wka_name; 805 uint16_t wka_type; 806 uint16_t wka_flags; 807 char *wka_desc; 808 smb_sid_t *wka_binsid; 809 } smb_wka_t; 810 811 /* 812 * Defined values for smb_wka.wka_flags 813 * 814 * SMB_WKAFLG_LGRP_ENABLE Can be added as local group 815 */ 816 #define SMB_WKAFLG_LGRP_ENABLE 0x1 817 818 /* 819 * Well-known account interfaces 820 */ 821 int smb_wka_init(void); 822 void smb_wka_fini(void); 823 smb_wka_t *smb_wka_lookup_name(char *); 824 smb_wka_t *smb_wka_lookup_sid(smb_sid_t *); 825 smb_sid_t *smb_wka_get_sid(char *); 826 char *smb_wka_get_domain(int); 827 uint32_t smb_wka_token_groups(uint32_t, smb_ids_t *); 828 829 /* 830 * In memory account representation 831 */ 832 typedef struct smb_account { 833 char *a_name; 834 char *a_domain; 835 uint16_t a_type; 836 smb_sid_t *a_sid; 837 smb_sid_t *a_domsid; 838 uint32_t a_rid; 839 } smb_account_t; 840 841 uint32_t smb_sam_lookup_name(char *, char *, uint16_t, smb_account_t *); 842 uint32_t smb_sam_lookup_sid(smb_sid_t *, smb_account_t *); 843 int smb_sam_usr_cnt(void); 844 uint32_t smb_sam_usr_groups(smb_sid_t *, smb_ids_t *); 845 int smb_sam_grp_cnt(smb_domain_type_t); 846 void smb_account_free(smb_account_t *); 847 boolean_t smb_account_validate(smb_account_t *); 848 849 /* 850 * Security Descriptor functions. 851 */ 852 uint32_t smb_sd_read(char *path, smb_sd_t *, uint32_t); 853 uint32_t smb_sd_write(char *path, smb_sd_t *, uint32_t); 854 855 /* Kernel Module Interface */ 856 int smb_kmod_bind(void); 857 int smb_kmod_setcfg(smb_kmod_cfg_t *); 858 int smb_kmod_setgmtoff(int32_t); 859 int smb_kmod_start(int, int, int); 860 int smb_kmod_tcplisten(int); 861 int smb_kmod_nbtlisten(int); 862 int smb_kmod_tcpreceive(void); 863 int smb_kmod_nbtreceive(void); 864 void smb_kmod_unbind(void); 865 int smb_kmod_share(char *, char *); 866 int smb_kmod_unshare(char *, char *); 867 int smb_kmod_get_open_num(smb_opennum_t *); 868 int smb_kmod_enum(smb_netsvc_t *); 869 smb_netsvc_t *smb_kmod_enum_init(smb_svcenum_t *); 870 void smb_kmod_enum_fini(smb_netsvc_t *); 871 int smb_kmod_session_close(const char *, const char *); 872 int smb_kmod_file_close(uint32_t); 873 874 /* 875 * Interposer library validation 876 */ 877 #define SMBEX_VERSION 1 878 #define SMBEX_KEY "82273fdc-e32a-18c3-3f78-827929dc23ea" 879 typedef struct smbex_version { 880 uint32_t v_version; 881 uuid_t v_uuid; 882 } smbex_version_t; 883 void *smb_dlopen(void); 884 void smb_dlclose(void *); 885 886 #ifdef __cplusplus 887 } 888 #endif 889 890 #endif /* _LIBSMB_H */ 891