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