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 45 #include <smbsrv/string.h> 46 #include <smbsrv/smb_idmap.h> 47 #include <smbsrv/netbios.h> 48 #include <smbsrv/smb_share.h> 49 #include <smbsrv/ntstatus.h> 50 #include <smbsrv/smb_door_svc.h> 51 #include <smbsrv/alloc.h> 52 #include <smbsrv/codepage.h> 53 #include <smbsrv/ctype.h> 54 #include <smbsrv/hash_table.h> 55 #include <smbsrv/msgbuf.h> 56 #include <smbsrv/oem.h> 57 #include <smbsrv/smb_i18n.h> 58 #include <smbsrv/wintypes.h> 59 #include <smbsrv/smb_xdr.h> 60 #include <smbsrv/smbinfo.h> 61 #include <smbsrv/ntifs.h> 62 63 #define SMB_VARRUN_DIR "/var/run/smb" 64 #define SMB_CCACHE_FILE "ccache" 65 #define SMB_CCACHE_PATH SMB_VARRUN_DIR "/" SMB_CCACHE_FILE 66 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 extern smb_ulist_t *smb_ulist_alloc(void); 276 extern void smb_ulist_free(smb_ulist_t *); 277 extern void smb_ulist_cleanup(smb_ulist_t *); 278 279 void smb_trace(const char *s); 280 void smb_tracef(const char *fmt, ...); 281 282 /* 283 * Authentication 284 */ 285 286 #define SMBAUTH_LM_MAGIC_STR "KGS!@#$%" 287 288 #define SMBAUTH_HASH_SZ 16 /* also LM/NTLM/NTLMv2 Hash size */ 289 #define SMBAUTH_LM_RESP_SZ 24 /* also NTLM Response size */ 290 #define SMBAUTH_LM_PWD_SZ 14 /* LM password size */ 291 #define SMBAUTH_V2_CLNT_CHALLENGE_SZ 8 /* both LMv2 and NTLMv2 */ 292 #define SMBAUTH_SESSION_KEY_SZ SMBAUTH_HASH_SZ 293 #define SMBAUTH_HEXHASH_SZ (SMBAUTH_HASH_SZ * 2) 294 295 #define SMBAUTH_FAILURE 1 296 #define SMBAUTH_SUCCESS 0 297 #define MD_DIGEST_LEN 16 298 299 /* 300 * Name Types 301 * 302 * The list of names near the end of the data blob (i.e. the ndb_names 303 * field of the smb_auth_data_blob_t data structure) can be classify into 304 * the following types: 305 * 306 * 0x0000 Indicates the end of the list. 307 * 0x0001 The name is a NetBIOS machine name (e.g. server name) 308 * 0x0002 The name is an NT Domain NetBIOS name. 309 * 0x0003 The name is the server's DNS hostname. 310 * 0x0004 The name is a W2K Domain name (a DNS name). 311 */ 312 #define SMBAUTH_NAME_TYPE_LIST_END 0x0000 313 #define SMBAUTH_NAME_TYPE_SERVER_NETBIOS 0x0001 314 #define SMBAUTH_NAME_TYPE_DOMAIN_NETBIOS 0x0002 315 #define SMBAUTH_NAME_TYPE_SERVER_DNS 0x0003 316 #define SMBAUTH_NAME_TYPE_DOMAIN_DNS 0x0004 317 318 /* 319 * smb_auth_name_entry_t 320 * 321 * Each name entry in the data blob consists of the following 3 fields: 322 * 323 * nne_type - name type 324 * nne_len - the length of the name 325 * nne_name - the name, in uppercase UCS-2LE Unicode format 326 */ 327 typedef struct smb_auth_name_entry { 328 unsigned short nne_type; 329 unsigned short nne_len; 330 mts_wchar_t nne_name[SMB_PI_MAX_DOMAIN * 2]; 331 } smb_auth_name_entry_t; 332 333 /* 334 * smb_auth_data_blob 335 * 336 * The format of this NTLMv2 data blob structure is as follow: 337 * 338 * - Blob Signature 0x01010000 (4 bytes) 339 * - Reserved (0x00000000) (4 bytes) 340 * - Timestamp Little-endian, 64-bit signed value representing 341 * the number of tenths of a microsecond since January 1, 1601. 342 * (8 bytes) 343 * - Client Challenge (8 bytes) 344 * - Unknown1 (4 bytes) 345 * - List of Target Information (variable length) 346 * - Unknown2 (4 bytes) 347 */ 348 typedef struct smb_auth_data_blob { 349 unsigned char ndb_signature[4]; 350 unsigned char ndb_reserved[4]; 351 uint64_t ndb_timestamp; 352 unsigned char ndb_clnt_challenge[SMBAUTH_V2_CLNT_CHALLENGE_SZ]; 353 unsigned char ndb_unknown[4]; 354 smb_auth_name_entry_t ndb_names[2]; 355 unsigned char ndb_unknown2[4]; 356 } smb_auth_data_blob_t; 357 358 #define SMBAUTH_BLOB_MAXLEN (sizeof (smb_auth_data_blob_t)) 359 #define SMBAUTH_CI_MAXLEN SMBAUTH_LM_RESP_SZ 360 #define SMBAUTH_CS_MAXLEN (SMBAUTH_BLOB_MAXLEN + SMBAUTH_HASH_SZ) 361 362 /* 363 * smb_auth_info_t 364 * 365 * The structure contains all the authentication information 366 * needed for the preparaton of the SMBSessionSetupAndx request 367 * and the user session key. 368 * 369 * hash - NTLM hash 370 * hash_v2 - NTLMv2 hash 371 * ci_len - the length of the case-insensitive password 372 * ci - case-insensitive password 373 * (If NTLMv2 authentication mechanism is used, it 374 * represents the LMv2 response. Otherwise, it 375 * is empty.) 376 * cs_len - the length of the case-sensitive password 377 * cs - case-sensitive password 378 * (If NTLMv2 authentication mechanism is used, it 379 * represents the NTLMv2 response. Otherwise, it 380 * represents the NTLM response.) 381 * data_blob - NTLMv2 data blob 382 */ 383 typedef struct smb_auth_info { 384 unsigned char hash[SMBAUTH_HASH_SZ]; 385 unsigned char hash_v2[SMBAUTH_HASH_SZ]; 386 unsigned short ci_len; 387 unsigned char ci[SMBAUTH_CI_MAXLEN]; 388 unsigned short cs_len; 389 unsigned char cs[SMBAUTH_CS_MAXLEN]; 390 int lmcompatibility_lvl; 391 smb_auth_data_blob_t data_blob; 392 } smb_auth_info_t; 393 394 /* 395 * SMB password management 396 */ 397 398 #define SMB_PWF_LM 0x01 /* LM hash is present */ 399 #define SMB_PWF_NT 0x02 /* NT hash is present */ 400 #define SMB_PWF_DISABLE 0x04 /* Account is disabled */ 401 402 typedef struct smb_passwd { 403 uid_t pw_uid; 404 uint32_t pw_flags; 405 char pw_name[SMB_USERNAME_MAXLEN]; 406 uint8_t pw_lmhash[SMBAUTH_HASH_SZ]; 407 uint8_t pw_nthash[SMBAUTH_HASH_SZ]; 408 } smb_passwd_t; 409 410 /* 411 * Control flags passed to smb_pwd_setcntl 412 */ 413 #define SMB_PWC_DISABLE 0x01 414 #define SMB_PWC_ENABLE 0x02 415 #define SMB_PWC_NOLM 0x04 416 417 #define SMB_PWE_SUCCESS 0 418 #define SMB_PWE_USER_UNKNOWN 1 419 #define SMB_PWE_USER_DISABLE 2 420 #define SMB_PWE_CLOSE_FAILED 3 421 #define SMB_PWE_OPEN_FAILED 4 422 #define SMB_PWE_WRITE_FAILED 6 423 #define SMB_PWE_UPDATE_FAILED 7 424 #define SMB_PWE_STAT_FAILED 8 425 #define SMB_PWE_BUSY 9 426 #define SMB_PWE_DENIED 10 427 #define SMB_PWE_SYSTEM_ERROR 11 428 #define SMB_PWE_INVALID_PARAM 12 429 #define SMB_PWE_NO_MEMORY 13 430 #define SMB_PWE_MAX 14 431 432 typedef struct smb_pwditer { 433 void *spi_next; 434 } smb_pwditer_t; 435 436 typedef struct smb_luser { 437 char *su_name; 438 char *su_fullname; 439 char *su_desc; 440 uint32_t su_rid; 441 uint32_t su_ctrl; 442 } smb_luser_t; 443 444 extern void smb_pwd_init(boolean_t); 445 extern void smb_pwd_fini(void); 446 extern smb_passwd_t *smb_pwd_getpwnam(const char *, smb_passwd_t *); 447 extern smb_passwd_t *smb_pwd_getpwuid(uid_t, smb_passwd_t *); 448 extern int smb_pwd_setpasswd(const char *, const char *); 449 extern int smb_pwd_setcntl(const char *, int); 450 451 extern int smb_pwd_iteropen(smb_pwditer_t *); 452 extern smb_luser_t *smb_pwd_iterate(smb_pwditer_t *); 453 extern void smb_pwd_iterclose(smb_pwditer_t *); 454 455 extern int smb_auth_qnd_unicode(mts_wchar_t *, const char *, int); 456 extern int smb_auth_hmac_md5(unsigned char *, int, unsigned char *, int, 457 unsigned char *); 458 459 /* 460 * A variation on HMAC-MD5 known as HMACT64 is used by Windows systems. 461 * The HMACT64() function is the same as the HMAC-MD5() except that 462 * it truncates the input key to 64 bytes rather than hashing it down 463 * to 16 bytes using the MD5() function. 464 */ 465 #define SMBAUTH_HMACT64(D, Ds, K, Ks, digest) \ 466 smb_auth_hmac_md5(D, Ds, K, (Ks > 64) ? 64 : Ks, digest) 467 468 extern int smb_auth_DES(unsigned char *, int, unsigned char *, int, 469 unsigned char *, int); 470 471 extern int smb_auth_md4(unsigned char *, unsigned char *, int); 472 extern int smb_auth_lm_hash(const char *, unsigned char *); 473 extern int smb_auth_ntlm_hash(const char *, unsigned char *); 474 475 extern int smb_auth_set_info(char *, char *, 476 unsigned char *, char *, unsigned char *, 477 int, int, smb_auth_info_t *); 478 479 extern int smb_auth_ntlmv2_hash(unsigned char *, 480 char *, char *, unsigned char *); 481 482 extern int smb_auth_gen_session_key(smb_auth_info_t *, unsigned char *); 483 484 boolean_t smb_auth_validate_lm(unsigned char *, uint32_t, smb_passwd_t *, 485 unsigned char *, int, char *, char *); 486 boolean_t smb_auth_validate_nt(unsigned char *, uint32_t, smb_passwd_t *, 487 unsigned char *, int, char *, char *, uchar_t *); 488 489 /* 490 * SMB MAC Signing 491 */ 492 493 #define SMB_MAC_KEY_SZ (SMBAUTH_SESSION_KEY_SZ + SMBAUTH_CS_MAXLEN) 494 #define SMB_SIG_OFFS 14 /* signature field offset within header */ 495 #define SMB_SIG_SIZE 8 /* SMB signature size */ 496 497 /* 498 * Signing flags: 499 * 500 * SMB_SCF_ENABLE Signing is enabled. 501 * 502 * SMB_SCF_REQUIRED Signing is enabled and required. 503 * This flag shouldn't be set if 504 * SMB_SCF_ENABLE isn't set. 505 * 506 * SMB_SCF_STARTED Signing will start after receiving 507 * the first non-anonymous SessionSetup 508 * request. 509 * 510 * SMB_SCF_KEY_ISSET_THIS_LOGON Indicates whether the MAC key has just 511 * been set for this logon. (prior to 512 * sending the SMBSessionSetup request) 513 * 514 */ 515 #define SMB_SCF_ENABLE 0x01 516 #define SMB_SCF_REQUIRED 0x02 517 #define SMB_SCF_STARTED 0x04 518 #define SMB_SCF_KEY_ISSET_THIS_LOGON 0x08 519 520 /* 521 * smb_sign_ctx 522 * 523 * SMB signing context. 524 * 525 * ssc_seqnum sequence number 526 * ssc_keylen mac key length 527 * ssc_mid multiplex id - reserved 528 * ssc_flags flags 529 * ssc_mackey mac key 530 * ssc_sign mac signature 531 * 532 */ 533 typedef struct smb_sign_ctx { 534 unsigned int ssc_seqnum; 535 unsigned short ssc_keylen; 536 unsigned short ssc_mid; 537 unsigned int ssc_flags; 538 unsigned char ssc_mackey[SMB_MAC_KEY_SZ]; 539 unsigned char ssc_sign[SMB_SIG_SIZE]; 540 } smb_sign_ctx_t; 541 542 extern int smb_mac_init(smb_sign_ctx_t *sign_ctx, smb_auth_info_t *auth); 543 extern int smb_mac_calc(smb_sign_ctx_t *sign_ctx, 544 const unsigned char *buf, size_t buf_len, unsigned char *mac_sign); 545 extern int smb_mac_chk(smb_sign_ctx_t *sign_ctx, 546 const unsigned char *buf, size_t buf_len); 547 extern int smb_mac_sign(smb_sign_ctx_t *sign_ctx, 548 unsigned char *buf, size_t buf_len); 549 extern void smb_mac_inc_seqnum(smb_sign_ctx_t *sign_ctx); 550 extern void smb_mac_dec_seqnum(smb_sign_ctx_t *sign_ctx); 551 552 /* 553 * Each domain is categorized using the enum values below. 554 * The local domain refers to the local machine and is named 555 * after the local hostname. The primary domain is the domain 556 * that the system joined. All other domains are either 557 * trusted or untrusted, as defined by the primary domain PDC. 558 */ 559 typedef enum nt_domain_type { 560 NT_DOMAIN_NULL, 561 NT_DOMAIN_BUILTIN, 562 NT_DOMAIN_LOCAL, 563 NT_DOMAIN_PRIMARY, 564 NT_DOMAIN_ACCOUNT, 565 NT_DOMAIN_TRUSTED, 566 NT_DOMAIN_UNTRUSTED, 567 NT_DOMAIN_NUM_TYPES 568 } nt_domain_type_t; 569 570 /* 571 * Information specific to trusted domains 572 */ 573 typedef struct smb_domain_trust { 574 uint32_t dti_trust_direction; 575 uint32_t dti_trust_type; 576 uint32_t dti_trust_attrs; 577 } smb_domain_trust_t; 578 579 /* 580 * DNS information for domain types that this info is 581 * obtained/available. Currently this is only obtained 582 * for the primary domain. 583 */ 584 typedef struct smb_domain_dns { 585 char ddi_forest[MAXHOSTNAMELEN]; 586 char ddi_guid[UUID_PRINTABLE_STRING_LENGTH]; 587 } smb_domain_dns_t; 588 589 /* 590 * This is the information that is held about each domain. 591 */ 592 typedef struct nt_domain { 593 list_node_t di_lnd; 594 nt_domain_type_t di_type; 595 char di_sid[SMB_SID_STRSZ]; 596 char di_nbname[NETBIOS_NAME_SZ]; 597 char di_fqname[MAXHOSTNAMELEN]; 598 smb_sid_t *di_binsid; 599 union { 600 smb_domain_dns_t di_dns; 601 smb_domain_trust_t di_trust; 602 } di_u; 603 } nt_domain_t; 604 605 typedef struct smb_trusted_domains { 606 uint32_t td_num; 607 nt_domain_t *td_domains; 608 } smb_trusted_domains_t; 609 610 #define SMB_DOMAIN_SUCCESS 0 611 #define SMB_DOMAIN_NOMACHINE_SID 1 612 #define SMB_DOMAIN_NODOMAIN_SID 2 613 #define SMB_DOMAIN_NODOMAIN_NAME 3 614 #define SMB_DOMAIN_INTERNAL_ERR 4 615 #define SMB_DOMAIN_INVALID_ARG 5 616 #define SMB_DOMAIN_NO_MEMORY 6 617 618 typedef struct smb_domain { 619 char d_dc[MAXHOSTNAMELEN]; 620 nt_domain_t d_info; 621 smb_trusted_domains_t d_trusted; 622 } smb_domain_t; 623 624 int nt_domain_init(uint32_t); 625 void nt_domain_fini(void); 626 void nt_domain_show(void); 627 void nt_domain_save(void); 628 boolean_t nt_domain_lookup_name(char *, nt_domain_t *); 629 boolean_t nt_domain_lookup_sid(smb_sid_t *, nt_domain_t *); 630 boolean_t nt_domain_lookup_type(nt_domain_type_t, nt_domain_t *); 631 boolean_t nt_domain_get_primary(smb_domain_t *); 632 void nt_domain_update(smb_domain_t *); 633 void nt_domain_start_update(void); 634 void nt_domain_end_update(void); 635 void nt_domain_set_basic_info(char *, char *, char *, nt_domain_t *); 636 void nt_domain_set_dns_info(char *, char *, char *, char *, char *, 637 nt_domain_t *); 638 void nt_domain_set_trust_info(char *, char *, char *, 639 uint32_t, uint32_t, uint32_t, nt_domain_t *); 640 641 typedef enum { 642 SMB_LGRP_BUILTIN = 1, 643 SMB_LGRP_LOCAL 644 } smb_gdomain_t; 645 646 typedef struct smb_gsid { 647 smb_sid_t *gs_sid; 648 uint16_t gs_type; 649 } smb_gsid_t; 650 651 typedef struct smb_giter { 652 sqlite_vm *sgi_vm; 653 sqlite *sgi_db; 654 } smb_giter_t; 655 656 typedef struct smb_group { 657 char *sg_name; 658 char *sg_cmnt; 659 uint32_t sg_attr; 660 uint32_t sg_rid; 661 smb_gsid_t sg_id; 662 smb_gdomain_t sg_domain; 663 smb_privset_t *sg_privs; 664 uint32_t sg_nmembers; 665 smb_gsid_t *sg_members; 666 } smb_group_t; 667 668 int smb_lgrp_start(void); 669 void smb_lgrp_stop(void); 670 int smb_lgrp_add(char *, char *); 671 int smb_lgrp_rename(char *, char *); 672 int smb_lgrp_delete(char *); 673 int smb_lgrp_setcmnt(char *, char *); 674 int smb_lgrp_getcmnt(char *, char **); 675 int smb_lgrp_getpriv(char *, uint8_t, boolean_t *); 676 int smb_lgrp_setpriv(char *, uint8_t, boolean_t); 677 int smb_lgrp_add_member(char *, smb_sid_t *, uint16_t); 678 int smb_lgrp_del_member(char *, smb_sid_t *, uint16_t); 679 int smb_lgrp_getbyname(char *, smb_group_t *); 680 int smb_lgrp_getbyrid(uint32_t, smb_gdomain_t, smb_group_t *); 681 void smb_lgrp_free(smb_group_t *); 682 boolean_t smb_lgrp_is_member(smb_group_t *, smb_sid_t *); 683 char *smb_lgrp_strerror(int); 684 int smb_lgrp_iteropen(smb_giter_t *); 685 void smb_lgrp_iterclose(smb_giter_t *); 686 int smb_lgrp_iterate(smb_giter_t *, smb_group_t *); 687 688 int smb_lookup_sid(smb_sid_t *, char *buf, int buflen); 689 int smb_lookup_name(char *, smb_gsid_t *); 690 691 #define SMB_LGRP_SUCCESS 0 692 #define SMB_LGRP_INVALID_ARG 1 693 #define SMB_LGRP_INVALID_MEMBER 2 694 #define SMB_LGRP_INVALID_NAME 3 695 #define SMB_LGRP_NOT_FOUND 4 696 #define SMB_LGRP_EXISTS 5 697 #define SMB_LGRP_NO_SID 6 698 #define SMB_LGRP_NO_LOCAL_SID 7 699 #define SMB_LGRP_SID_NOTLOCAL 8 700 #define SMB_LGRP_WKSID 9 701 #define SMB_LGRP_NO_MEMORY 10 702 #define SMB_LGRP_DB_ERROR 11 703 #define SMB_LGRP_DBINIT_ERROR 12 704 #define SMB_LGRP_INTERNAL_ERROR 13 705 #define SMB_LGRP_MEMBER_IN_GROUP 14 706 #define SMB_LGRP_MEMBER_NOT_IN_GROUP 15 707 #define SMB_LGRP_NO_SUCH_PRIV 16 708 #define SMB_LGRP_NO_SUCH_DOMAIN 17 709 #define SMB_LGRP_PRIV_HELD 18 710 #define SMB_LGRP_PRIV_NOT_HELD 19 711 #define SMB_LGRP_BAD_DATA 20 712 #define SMB_LGRP_NO_MORE 21 713 #define SMB_LGRP_DBOPEN_FAILED 22 714 #define SMB_LGRP_DBEXEC_FAILED 23 715 #define SMB_LGRP_DBINIT_FAILED 24 716 #define SMB_LGRP_DOMLKP_FAILED 25 717 #define SMB_LGRP_DOMINS_FAILED 26 718 #define SMB_LGRP_INSERT_FAILED 27 719 #define SMB_LGRP_DELETE_FAILED 28 720 #define SMB_LGRP_UPDATE_FAILED 29 721 #define SMB_LGRP_LOOKUP_FAILED 30 722 #define SMB_LGRP_NOT_SUPPORTED 31 723 724 #define SMB_LGRP_NAME_CHAR_MAX 32 725 #define SMB_LGRP_COMMENT_MAX 256 726 #define SMB_LGRP_NAME_MAX (SMB_LGRP_NAME_CHAR_MAX * MTS_MB_CHAR_MAX + 1) 727 728 /* 729 * values for smb_nic_t.smbflags 730 */ 731 #define SMB_NICF_NBEXCL 0x01 /* Excluded from Netbios activities */ 732 #define SMB_NICF_ALIAS 0x02 /* This is an alias */ 733 734 /* 735 * smb_nic_t 736 * nic_host actual host name 737 * nic_nbname 16-byte NetBIOS host name 738 */ 739 typedef struct { 740 char nic_host[MAXHOSTNAMELEN]; 741 char nic_nbname[NETBIOS_NAME_SZ]; 742 char nic_cmnt[SMB_PI_MAX_COMMENT]; 743 char nic_ifname[LIFNAMSIZ]; 744 smb_inaddr_t nic_ip; 745 uint32_t nic_mask; 746 uint32_t nic_bcast; 747 uint32_t nic_smbflags; 748 uint64_t nic_sysflags; 749 } smb_nic_t; 750 751 typedef struct smb_niciter { 752 smb_nic_t ni_nic; 753 int ni_cookie; 754 int ni_seqnum; 755 } smb_niciter_t; 756 757 /* NIC config functions */ 758 int smb_nic_init(void); 759 void smb_nic_fini(void); 760 int smb_nic_getnum(char *); 761 int smb_nic_addhost(const char *, const char *, int, const char **); 762 int smb_nic_delhost(const char *); 763 int smb_nic_getfirst(smb_niciter_t *); 764 int smb_nic_getnext(smb_niciter_t *); 765 boolean_t smb_nic_is_local(smb_inaddr_t *); 766 boolean_t smb_nic_is_same_subnet(smb_inaddr_t *); 767 768 /* NIC Monitoring functions */ 769 int smb_nicmon_start(const char *); 770 void smb_nicmon_stop(void); 771 772 /* 773 * Well-known account structure 774 * 775 * A security identifier (SID) is a unique value of variable length that 776 * is used to identify a security principal or security group in 777 * Windows. Well-known SIDs are a group of SIDs that identify generic 778 * users or generic groups. Their values remain constant across all 779 * operating systems. 780 * 781 * This structure is defined to store these SIDs and other related 782 * information about them (e.g. account and domain names) in a 783 * predefined table. 784 */ 785 typedef struct smb_wka { 786 uint8_t wka_domidx; 787 char *wka_sid; 788 char *wka_name; 789 uint16_t wka_type; 790 uint16_t wka_flags; 791 char *wka_desc; 792 smb_sid_t *wka_binsid; 793 } smb_wka_t; 794 795 /* 796 * Defined values for smb_wka.wka_flags 797 * 798 * SMB_WKAFLG_LGRP_ENABLE Can be added as local group 799 */ 800 #define SMB_WKAFLG_LGRP_ENABLE 0x1 801 802 /* 803 * Well-known account interfaces 804 */ 805 int smb_wka_init(void); 806 void smb_wka_fini(void); 807 smb_wka_t *smb_wka_lookup_name(char *); 808 smb_wka_t *smb_wka_lookup_sid(smb_sid_t *); 809 smb_sid_t *smb_wka_get_sid(char *); 810 char *smb_wka_get_domain(int); 811 uint32_t smb_wka_token_groups(uint32_t, smb_ids_t *); 812 813 /* 814 * In memory account representation 815 */ 816 typedef struct smb_account { 817 char *a_name; 818 char *a_domain; 819 uint16_t a_type; 820 smb_sid_t *a_sid; 821 smb_sid_t *a_domsid; 822 uint32_t a_rid; 823 } smb_account_t; 824 825 uint32_t smb_sam_lookup_name(char *, char *, uint16_t, smb_account_t *); 826 uint32_t smb_sam_lookup_sid(smb_sid_t *, smb_account_t *); 827 int smb_sam_usr_cnt(void); 828 uint32_t smb_sam_usr_groups(smb_sid_t *, smb_ids_t *); 829 int smb_sam_grp_cnt(nt_domain_type_t); 830 void smb_account_free(smb_account_t *); 831 boolean_t smb_account_validate(smb_account_t *); 832 833 /* 834 * Security Descriptor functions. 835 */ 836 uint32_t smb_sd_read(char *path, smb_sd_t *, uint32_t); 837 uint32_t smb_sd_write(char *path, smb_sd_t *, uint32_t); 838 839 /* Kernel Module Interface */ 840 int smb_kmod_bind(void); 841 int smb_kmod_setcfg(smb_kmod_cfg_t *); 842 int smb_kmod_setgmtoff(int32_t); 843 int smb_kmod_start(int, int, int); 844 int smb_kmod_tcplisten(int); 845 int smb_kmod_nbtlisten(int); 846 int smb_kmod_tcpreceive(void); 847 int smb_kmod_nbtreceive(void); 848 void smb_kmod_unbind(void); 849 int smb_kmod_share(char *, char *); 850 int smb_kmod_unshare(char *, char *); 851 int smb_kmod_get_usernum(uint32_t *); 852 int smb_kmod_get_userlist(smb_ulist_t *); 853 854 #ifdef __cplusplus 855 } 856 #endif 857 858 #endif /* _LIBSMB_H */ 859