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