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 2008 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 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #include <sys/types.h> 36 #include <sys/list.h> 37 #include <arpa/inet.h> 38 #include <net/if.h> 39 #include <netdb.h> 40 41 #include <stdlib.h> 42 #include <libscf.h> 43 #include <libshare.h> 44 #include <sqlite/sqlite.h> 45 46 #include <smbsrv/string.h> 47 #include <smbsrv/smb_idmap.h> 48 #include <smbsrv/netbios.h> 49 50 /* 51 * XXX - These header files are here, only because other libraries 52 * can compile. Move the header files in to the internal header files 53 * of other libraries, once the restructure is complete. libsmb.h does not 54 * need these header files. 55 */ 56 #include <smbsrv/lmshare.h> 57 #include <smbsrv/lmshare_door.h> 58 #include <smbsrv/ntstatus.h> 59 #include <smbsrv/smb_door_svc.h> 60 #include <smbsrv/alloc.h> 61 #include <smbsrv/codepage.h> 62 #include <smbsrv/crypt.h> 63 #include <smbsrv/ctype.h> 64 #include <smbsrv/hash_table.h> 65 #include <smbsrv/msgbuf.h> 66 #include <smbsrv/oem.h> 67 #include <smbsrv/string.h> 68 #include <smbsrv/smb_i18n.h> 69 #include <smbsrv/wintypes.h> 70 #include <smbsrv/smb_xdr.h> 71 #include <smbsrv/smbinfo.h> 72 /* End of header files to be removed. */ 73 74 /* Max value length of all SMB properties */ 75 #define MAX_VALUE_BUFLEN 512 76 77 #define SMBD_FMRI_PREFIX "network/smb/server" 78 #define SMBD_DEFAULT_INSTANCE_FMRI "svc:/network/smb/server:default" 79 #define SMBD_PG_NAME "smbd" 80 #define SMBD_PROTECTED_PG_NAME "read" 81 82 #define SMBD_SMF_OK 0 83 #define SMBD_SMF_NO_MEMORY 1 /* no memory for data structures */ 84 #define SMBD_SMF_SYSTEM_ERR 2 /* system error, use errno */ 85 #define SMBD_SMF_NO_PERMISSION 3 /* no permission for operation */ 86 #define SMBD_SMF_INVALID_ARG 4 87 88 #define SCH_STATE_UNINIT 0 89 #define SCH_STATE_INITIALIZING 1 90 #define SCH_STATE_INIT 2 91 92 typedef struct smb_scfhandle { 93 scf_handle_t *scf_handle; 94 int scf_state; 95 scf_service_t *scf_service; 96 scf_scope_t *scf_scope; 97 scf_transaction_t *scf_trans; 98 scf_transaction_entry_t *scf_entry; 99 scf_propertygroup_t *scf_pg; 100 scf_instance_t *scf_instance; 101 scf_iter_t *scf_inst_iter; 102 scf_iter_t *scf_pg_iter; 103 } smb_scfhandle_t; 104 105 /* 106 * CIFS Configuration Management 107 */ 108 typedef enum { 109 SMB_CI_OPLOCK_ENABLE = 0, 110 SMB_CI_OPLOCK_TIMEOUT, 111 112 SMB_CI_AUTOHOME_MAP, 113 114 SMB_CI_DOMAIN_SID, 115 SMB_CI_DOMAIN_MEMB, 116 SMB_CI_DOMAIN_NAME, 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_SRVSVC_SHRSET_ENABLE, 124 SMB_CI_MLRPC_KALIVE, 125 126 SMB_CI_MAX_BUFSIZE, 127 SMB_CI_MAX_WORKERS, 128 SMB_CI_MAX_CONNECTIONS, 129 SMB_CI_KEEPALIVE, 130 SMB_CI_RESTRICT_ANON, 131 132 SMB_CI_SIGNING_ENABLE, 133 SMB_CI_SIGNING_REQD, 134 SMB_CI_SIGNING_CHECK, 135 136 SMB_CI_FLUSH_REQUIRED, 137 SMB_CI_SYNC_ENABLE, 138 SMB_CI_DIRSYMLINK_DISABLE, 139 SMB_CI_ANNONCE_QUOTA, 140 141 SMB_CI_SECURITY, 142 SMB_CI_NBSCOPE, 143 SMB_CI_SYS_CMNT, 144 SMB_CI_LM_LEVEL, 145 146 SMB_CI_ADS_SITE, 147 148 SMB_CI_DYNDNS_ENABLE, 149 150 SMB_CI_MACHINE_PASSWD, 151 SMB_CI_MAX 152 } smb_cfg_id_t; 153 154 /* SMF helper functions */ 155 extern smb_scfhandle_t *smb_smf_scf_init(char *); 156 extern void smb_smf_scf_fini(smb_scfhandle_t *); 157 extern int smb_smf_start_transaction(smb_scfhandle_t *); 158 extern int smb_smf_end_transaction(smb_scfhandle_t *); 159 extern int smb_smf_set_string_property(smb_scfhandle_t *, char *, char *); 160 extern int smb_smf_get_string_property(smb_scfhandle_t *, char *, 161 char *, size_t); 162 extern int smb_smf_set_integer_property(smb_scfhandle_t *, char *, int64_t); 163 extern int smb_smf_get_integer_property(smb_scfhandle_t *, char *, int64_t *); 164 extern int smb_smf_set_boolean_property(smb_scfhandle_t *, char *, uint8_t); 165 extern int smb_smf_get_boolean_property(smb_scfhandle_t *, char *, uint8_t *); 166 extern int smb_smf_set_opaque_property(smb_scfhandle_t *, char *, 167 void *, size_t); 168 extern int smb_smf_get_opaque_property(smb_scfhandle_t *, char *, 169 void *, size_t); 170 extern int smb_smf_create_service_pgroup(smb_scfhandle_t *, char *); 171 172 /* Configuration management functions */ 173 extern int smb_config_get(smb_cfg_id_t, char *, int); 174 extern char *smb_config_getname(smb_cfg_id_t); 175 extern int smb_config_getstr(smb_cfg_id_t, char *, int); 176 extern int smb_config_getnum(smb_cfg_id_t, int64_t *); 177 extern boolean_t smb_config_getbool(smb_cfg_id_t); 178 179 extern int smb_config_set(smb_cfg_id_t, char *); 180 extern int smb_config_setstr(smb_cfg_id_t, char *); 181 extern int smb_config_setnum(smb_cfg_id_t, int64_t); 182 extern int smb_config_setbool(smb_cfg_id_t, boolean_t); 183 184 extern uint8_t smb_config_get_fg_flag(void); 185 extern char *smb_config_get_localsid(void); 186 extern int smb_config_secmode_fromstr(char *secmode); 187 extern char *smb_config_secmode_tostr(int secmode); 188 extern int smb_config_get_secmode(void); 189 extern int smb_config_set_secmode(int secmode); 190 extern int smb_config_set_idmap_domain(char *value); 191 extern int smb_config_set_idmap_gc(char *value); 192 extern int smb_config_refresh_idmap(void); 193 extern int smb_config_refresh(void); 194 195 /* smb_door_client.c */ 196 typedef struct smb_joininfo { 197 char domain_name[MAXHOSTNAMELEN]; 198 char domain_username[BUF_LEN + 1]; 199 char domain_passwd[BUF_LEN + 1]; 200 uint32_t mode; 201 } smb_joininfo_t; 202 203 /* APIs to communicate with SMB daemon via door calls */ 204 extern int smbd_set_param(smb_cfg_id_t, char *); 205 extern int smbd_get_param(smb_cfg_id_t, char *); 206 extern int smbd_get_security_mode(int *); 207 extern int smbd_netbios_reconfig(void); 208 extern uint32_t smb_join(smb_joininfo_t *info); 209 210 211 #define SMB_DOMAIN_NOMACHINE_SID -1 212 #define SMB_DOMAIN_NODOMAIN_SID -2 213 214 extern int nt_domain_init(char *resource_domain, uint32_t secmode); 215 216 /* Following set of functions, manipulate WINS server configuration */ 217 extern int smb_wins_allow_list(char *config_list, char *allow_list); 218 extern int smb_wins_exclude_list(char *config_list, char *exclude_list); 219 extern boolean_t smb_wins_is_excluded(in_addr_t ipaddr, 220 ipaddr_t *exclude_list, int nexclude); 221 extern void smb_wins_build_list(char *buf, uint32_t iplist[], int max_naddr); 222 extern int smb_wins_iplist(char *list, uint32_t iplist[], int max_naddr); 223 224 /* 225 * Information on a particular domain: the domain name, the 226 * name of a controller (PDC or BDC) and it's ip address. 227 */ 228 typedef struct smb_ntdomain { 229 char domain[SMB_PI_MAX_DOMAIN]; 230 char server[SMB_PI_MAX_DOMAIN]; 231 uint32_t ipaddr; 232 } smb_ntdomain_t; 233 234 /* SMB domain information management functions */ 235 extern smb_ntdomain_t *smb_getdomaininfo(uint32_t timeout); 236 extern void smb_setdomaininfo(char *domain, char *server, uint32_t ipaddr); 237 extern void smb_logdomaininfo(smb_ntdomain_t *di); 238 239 /* 240 * Following set of function, handle calls to SMB Kernel driver, via 241 * Kernel doors interface. 242 */ 243 extern uint64_t smb_dwncall_user_num(void); 244 extern int smb_dwncall_share(int, char *, char *); 245 246 /* 247 * buffer context structure. This is used to keep track of the buffer 248 * context. 249 * 250 * basep: points to the beginning of the buffer 251 * curp: points to the current offset 252 * endp: points to the limit of the buffer 253 */ 254 typedef struct { 255 unsigned char *basep; 256 unsigned char *curp; 257 unsigned char *endp; 258 } smb_ctxbuf_t; 259 260 extern int smb_ctxbuf_init(smb_ctxbuf_t *ctx, unsigned char *buf, 261 size_t buflen); 262 extern int smb_ctxbuf_len(smb_ctxbuf_t *ctx); 263 extern int smb_ctxbuf_printf(smb_ctxbuf_t *ctx, const char *fmt, ...); 264 265 /* Functions to handle SMB daemon communications with idmap service */ 266 extern int smb_idmap_start(void); 267 extern void smb_idmap_stop(void); 268 extern int smb_idmap_restart(void); 269 270 /* Miscellaneous functions */ 271 extern void hexdump(unsigned char *, int); 272 extern size_t bintohex(const char *, size_t, char *, size_t); 273 extern size_t hextobin(const char *, size_t, char *, size_t); 274 extern char *trim_whitespace(char *buf); 275 extern void randomize(char *, unsigned); 276 extern void rand_hash(unsigned char *, size_t, unsigned char *, size_t); 277 278 extern int smb_resolve_netbiosname(char *, char *, size_t); 279 extern int smb_resolve_fqdn(char *, char *, size_t); 280 extern int smb_getdomainname(char *, size_t); 281 extern int smb_getfqdomainname(char *, size_t); 282 extern int smb_gethostname(char *, size_t, int); 283 extern int smb_getfqhostname(char *, size_t); 284 extern int smb_getnetbiosname(char *, size_t); 285 286 extern int smb_get_nameservers(struct in_addr *, int); 287 extern void smb_tonetbiosname(char *, char *, char); 288 289 290 void smb_trace(const char *s); 291 void smb_tracef(const char *fmt, ...); 292 293 /* 294 * Authentication 295 */ 296 297 #define SMBAUTH_LM_MAGIC_STR "KGS!@#$%" 298 299 #define SMBAUTH_HASH_SZ 16 /* also LM/NTLM/NTLMv2 Hash size */ 300 #define SMBAUTH_LM_RESP_SZ 24 /* also NTLM Response size */ 301 #define SMBAUTH_LM_PWD_SZ 14 /* LM password size */ 302 #define SMBAUTH_V2_CLNT_CHALLENGE_SZ 8 /* both LMv2 and NTLMv2 */ 303 #define SMBAUTH_SESSION_KEY_SZ SMBAUTH_HASH_SZ 304 #define SMBAUTH_HEXHASH_SZ (SMBAUTH_HASH_SZ * 2) 305 306 #define SMBAUTH_FAILURE 1 307 #define SMBAUTH_SUCCESS 0 308 #define MD_DIGEST_LEN 16 309 310 /* 311 * Name Types 312 * 313 * The list of names near the end of the data blob (i.e. the ndb_names 314 * field of the smb_auth_data_blob_t data structure) can be classify into 315 * the following types: 316 * 317 * 0x0000 Indicates the end of the list. 318 * 0x0001 The name is a NetBIOS machine name (e.g. server name) 319 * 0x0002 The name is an NT Domain NetBIOS name. 320 * 0x0003 The name is the server's DNS hostname. 321 * 0x0004 The name is a W2K Domain name (a DNS name). 322 */ 323 #define SMBAUTH_NAME_TYPE_LIST_END 0x0000 324 #define SMBAUTH_NAME_TYPE_SERVER_NETBIOS 0x0001 325 #define SMBAUTH_NAME_TYPE_DOMAIN_NETBIOS 0x0002 326 #define SMBAUTH_NAME_TYPE_SERVER_DNS 0x0003 327 #define SMBAUTH_NAME_TYPE_DOMAIN_DNS 0x0004 328 329 /* 330 * smb_auth_name_entry_t 331 * 332 * Each name entry in the data blob consists of the following 3 fields: 333 * 334 * nne_type - name type 335 * nne_len - the length of the name 336 * nne_name - the name, in uppercase UCS-2LE Unicode format 337 */ 338 typedef struct smb_auth_name_entry { 339 unsigned short nne_type; 340 unsigned short nne_len; 341 mts_wchar_t nne_name[SMB_PI_MAX_DOMAIN * 2]; 342 } smb_auth_name_entry_t; 343 344 /* 345 * smb_auth_data_blob 346 * 347 * The format of this NTLMv2 data blob structure is as follow: 348 * 349 * - Blob Signature 0x01010000 (4 bytes) 350 * - Reserved (0x00000000) (4 bytes) 351 * - Timestamp Little-endian, 64-bit signed value representing 352 * the number of tenths of a microsecond since January 1, 1601. 353 * (8 bytes) 354 * - Client Challenge (8 bytes) 355 * - Unknown1 (4 bytes) 356 * - List of Target Information (variable length) 357 * - Unknown2 (4 bytes) 358 */ 359 typedef struct smb_auth_data_blob { 360 unsigned char ndb_signature[4]; 361 unsigned char ndb_reserved[4]; 362 uint64_t ndb_timestamp; 363 unsigned char ndb_clnt_challenge[SMBAUTH_V2_CLNT_CHALLENGE_SZ]; 364 unsigned char ndb_unknown[4]; 365 smb_auth_name_entry_t ndb_names[2]; 366 unsigned char ndb_unknown2[4]; 367 } smb_auth_data_blob_t; 368 369 #define SMBAUTH_BLOB_MAXLEN (sizeof (smb_auth_data_blob_t)) 370 #define SMBAUTH_CI_MAXLEN SMBAUTH_LM_RESP_SZ 371 #define SMBAUTH_CS_MAXLEN (SMBAUTH_BLOB_MAXLEN + SMBAUTH_HASH_SZ) 372 373 /* 374 * smb_auth_info_t 375 * 376 * The structure contains all the authentication information 377 * needed for the preparaton of the SMBSessionSetupAndx request 378 * and the user session key. 379 * 380 * hash - NTLM hash 381 * hash_v2 - NTLMv2 hash 382 * ci_len - the length of the case-insensitive password 383 * ci - case-insensitive password 384 * (If NTLMv2 authentication mechanism is used, it 385 * represents the LMv2 response. Otherwise, it 386 * is empty.) 387 * cs_len - the length of the case-sensitive password 388 * cs - case-sensitive password 389 * (If NTLMv2 authentication mechanism is used, it 390 * represents the NTLMv2 response. Otherwise, it 391 * represents the NTLM response.) 392 * data_blob - NTLMv2 data blob 393 */ 394 typedef struct smb_auth_info { 395 unsigned char hash[SMBAUTH_HASH_SZ]; 396 unsigned char hash_v2[SMBAUTH_HASH_SZ]; 397 unsigned short ci_len; 398 unsigned char ci[SMBAUTH_CI_MAXLEN]; 399 unsigned short cs_len; 400 unsigned char cs[SMBAUTH_CS_MAXLEN]; 401 int lmcompatibility_lvl; 402 smb_auth_data_blob_t data_blob; 403 } smb_auth_info_t; 404 405 /* 406 * SMB password management 407 */ 408 409 #define SMB_PWF_LM 0x01 /* LM hash is present */ 410 #define SMB_PWF_NT 0x02 /* NT hash is present */ 411 #define SMB_PWF_DISABLE 0x04 /* Account is disabled */ 412 413 typedef struct smb_passwd { 414 uid_t pw_uid; 415 uint32_t pw_flags; 416 unsigned char pw_lmhash[SMBAUTH_HASH_SZ]; 417 unsigned char pw_nthash[SMBAUTH_HASH_SZ]; 418 } smb_passwd_t; 419 420 /* 421 * Control flags passed to smb_pwd_setcntl 422 */ 423 #define SMB_PWC_DISABLE 0x01 424 #define SMB_PWC_ENABLE 0x02 425 #define SMB_PWC_NOLM 0x04 426 427 #define SMB_PWE_SUCCESS 0 428 #define SMB_PWE_USER_UNKNOWN 1 429 #define SMB_PWE_USER_DISABLE 2 430 #define SMB_PWE_CLOSE_FAILED 3 431 #define SMB_PWE_OPEN_FAILED 4 432 #define SMB_PWE_WRITE_FAILED 6 433 #define SMB_PWE_UPDATE_FAILED 7 434 #define SMB_PWE_STAT_FAILED 8 435 #define SMB_PWE_BUSY 9 436 #define SMB_PWE_DENIED 10 437 #define SMB_PWE_SYSTEM_ERROR 11 438 #define SMB_PWE_MAX 12 439 440 extern void smb_pwd_init(void); 441 extern void smb_pwd_fini(void); 442 extern smb_passwd_t *smb_pwd_getpasswd(const char *, smb_passwd_t *); 443 extern int smb_pwd_setpasswd(const char *, const char *); 444 extern int smb_pwd_setcntl(const char *, int); 445 446 extern int smb_auth_qnd_unicode(mts_wchar_t *dst, char *src, int length); 447 extern int smb_auth_hmac_md5(unsigned char *data, int data_len, 448 unsigned char *key, int key_len, unsigned char *digest); 449 450 /* 451 * A variation on HMAC-MD5 known as HMACT64 is used by Windows systems. 452 * The HMACT64() function is the same as the HMAC-MD5() except that 453 * it truncates the input key to 64 bytes rather than hashing it down 454 * to 16 bytes using the MD5() function. 455 */ 456 #define SMBAUTH_HMACT64(D, Ds, K, Ks, digest) \ 457 smb_auth_hmac_md5(D, Ds, K, (Ks > 64) ? 64 : Ks, digest) 458 459 extern int smb_auth_DES(unsigned char *, int, unsigned char *, int, 460 unsigned char *, int); 461 462 extern int smb_auth_md4(unsigned char *, unsigned char *, int); 463 extern int smb_auth_lm_hash(char *, unsigned char *); 464 extern int smb_auth_ntlm_hash(char *, unsigned char *); 465 466 extern int smb_auth_set_info(char *, char *, 467 unsigned char *, char *, unsigned char *, 468 int, int, smb_auth_info_t *); 469 470 extern int smb_auth_gen_session_key(smb_auth_info_t *, unsigned char *); 471 472 boolean_t smb_auth_validate_lm(unsigned char *, uint32_t, smb_passwd_t *, 473 unsigned char *, int, char *, char *); 474 boolean_t smb_auth_validate_nt(unsigned char *, uint32_t, smb_passwd_t *, 475 unsigned char *, int, char *, char *); 476 477 /* 478 * SMB MAC Signing 479 */ 480 481 #define SMB_MAC_KEY_SZ (SMBAUTH_SESSION_KEY_SZ + SMBAUTH_CS_MAXLEN) 482 #define SMB_SIG_OFFS 14 /* signature field offset within header */ 483 #define SMB_SIG_SIZE 8 /* SMB signature size */ 484 485 /* 486 * Signing flags: 487 * 488 * SMB_SCF_ENABLE Signing is enabled. 489 * 490 * SMB_SCF_REQUIRED Signing is enabled and required. 491 * This flag shouldn't be set if 492 * SMB_SCF_ENABLE isn't set. 493 * 494 * SMB_SCF_STARTED Signing will start after receiving 495 * the first non-anonymous SessionSetup 496 * request. 497 * 498 * SMB_SCF_KEY_ISSET_THIS_LOGON Indicates whether the MAC key has just 499 * been set for this logon. (prior to 500 * sending the SMBSessionSetup request) 501 * 502 */ 503 #define SMB_SCF_ENABLE 0x01 504 #define SMB_SCF_REQUIRED 0x02 505 #define SMB_SCF_STARTED 0x04 506 #define SMB_SCF_KEY_ISSET_THIS_LOGON 0x08 507 508 /* 509 * smb_sign_ctx 510 * 511 * SMB signing context. 512 * 513 * ssc_seqnum sequence number 514 * ssc_keylen mac key length 515 * ssc_mid multiplex id - reserved 516 * ssc_flags flags 517 * ssc_mackey mac key 518 * ssc_sign mac signature 519 * 520 */ 521 typedef struct smb_sign_ctx { 522 unsigned int ssc_seqnum; 523 unsigned short ssc_keylen; 524 unsigned short ssc_mid; 525 unsigned int ssc_flags; 526 unsigned char ssc_mackey[SMB_MAC_KEY_SZ]; 527 unsigned char ssc_sign[SMB_SIG_SIZE]; 528 } smb_sign_ctx_t; 529 530 extern int smb_mac_init(smb_sign_ctx_t *sign_ctx, smb_auth_info_t *auth); 531 extern int smb_mac_calc(smb_sign_ctx_t *sign_ctx, 532 const unsigned char *buf, size_t buf_len, unsigned char *mac_sign); 533 extern int smb_mac_chk(smb_sign_ctx_t *sign_ctx, 534 const unsigned char *buf, size_t buf_len); 535 extern int smb_mac_sign(smb_sign_ctx_t *sign_ctx, 536 unsigned char *buf, size_t buf_len); 537 extern void smb_mac_inc_seqnum(smb_sign_ctx_t *sign_ctx); 538 extern void smb_mac_dec_seqnum(smb_sign_ctx_t *sign_ctx); 539 540 /* 541 * Each domain is categorized using the enum values below. 542 * The local domain refers to the local machine and is named 543 * after the local hostname. The primary domain is the domain 544 * that the system joined. All other domains are either 545 * trusted or untrusted, as defined by the primary domain PDC. 546 * 547 * This enum must be kept in step with the table of strings 548 * in ntdomain.c. 549 */ 550 typedef enum nt_domain_type { 551 NT_DOMAIN_NULL, 552 NT_DOMAIN_BUILTIN, 553 NT_DOMAIN_LOCAL, 554 NT_DOMAIN_PRIMARY, 555 NT_DOMAIN_ACCOUNT, 556 NT_DOMAIN_TRUSTED, 557 NT_DOMAIN_UNTRUSTED, 558 NT_DOMAIN_NUM_TYPES 559 } nt_domain_type_t; 560 561 562 /* 563 * This is the information that is held about each domain. The database 564 * is a linked list that is threaded through the domain structures. As 565 * the number of domains in the database should be small (32 max), this 566 * should be sufficient. 567 */ 568 typedef struct nt_domain { 569 struct nt_domain *next; 570 nt_domain_type_t type; 571 char *name; 572 nt_sid_t *sid; 573 } nt_domain_t; 574 575 nt_domain_t *nt_domain_new(nt_domain_type_t type, char *name, nt_sid_t *sid); 576 void nt_domain_delete(nt_domain_t *domain); 577 nt_domain_t *nt_domain_add(nt_domain_t *new_domain); 578 void nt_domain_remove(nt_domain_t *domain); 579 void nt_domain_flush(nt_domain_type_t domain_type); 580 void nt_domain_sync(void); 581 char *nt_domain_xlat_type(nt_domain_type_t domain_type); 582 nt_domain_type_t nt_domain_xlat_type_name(char *type_name); 583 nt_domain_t *nt_domain_lookup_name(char *domain_name); 584 nt_domain_t *nt_domain_lookup_sid(nt_sid_t *domain_sid); 585 nt_domain_t *nt_domain_lookupbytype(nt_domain_type_t type); 586 nt_sid_t *nt_domain_local_sid(void); 587 588 typedef enum { 589 SMB_LGRP_BUILTIN = 1, 590 SMB_LGRP_LOCAL 591 } smb_gdomain_t; 592 593 typedef struct smb_gsid { 594 nt_sid_t *gs_sid; 595 uint16_t gs_type; 596 } smb_gsid_t; 597 598 typedef struct smb_giter { 599 sqlite_vm *sgi_vm; 600 sqlite *sgi_db; 601 } smb_giter_t; 602 603 typedef struct smb_group { 604 char *sg_name; 605 char *sg_cmnt; 606 uint32_t sg_attr; 607 uint32_t sg_rid; 608 smb_gsid_t sg_id; 609 smb_gdomain_t sg_domain; 610 smb_privset_t *sg_privs; 611 uint32_t sg_nmembers; 612 smb_gsid_t *sg_members; 613 } smb_group_t; 614 615 int smb_lgrp_start(void); 616 void smb_lgrp_stop(void); 617 int smb_lgrp_add(char *, char *); 618 int smb_lgrp_rename(char *, char *); 619 int smb_lgrp_delete(char *); 620 int smb_lgrp_setcmnt(char *, char *); 621 int smb_lgrp_getcmnt(char *, char **); 622 int smb_lgrp_getpriv(char *, uint8_t, boolean_t *); 623 int smb_lgrp_setpriv(char *, uint8_t, boolean_t); 624 int smb_lgrp_add_member(char *, nt_sid_t *, uint16_t); 625 int smb_lgrp_del_member(char *, nt_sid_t *, uint16_t); 626 int smb_lgrp_getbyname(char *, smb_group_t *); 627 int smb_lgrp_getbyrid(uint32_t, smb_gdomain_t, smb_group_t *); 628 int smb_lgrp_numbydomain(smb_gdomain_t, int *); 629 int smb_lgrp_numbymember(nt_sid_t *, int *); 630 void smb_lgrp_free(smb_group_t *); 631 boolean_t smb_lgrp_is_member(smb_group_t *, nt_sid_t *); 632 char *smb_lgrp_strerror(int); 633 int smb_lgrp_iteropen(smb_giter_t *); 634 void smb_lgrp_iterclose(smb_giter_t *); 635 int smb_lgrp_iterate(smb_giter_t *, smb_group_t *); 636 637 int smb_lookup_sid(nt_sid_t *, char *buf, int buflen); 638 int smb_lookup_name(char *, smb_gsid_t *); 639 640 #define SMB_LGRP_SUCCESS 0 641 #define SMB_LGRP_INVALID_ARG 1 642 #define SMB_LGRP_INVALID_MEMBER 2 643 #define SMB_LGRP_INVALID_NAME 3 644 #define SMB_LGRP_NOT_FOUND 4 645 #define SMB_LGRP_EXISTS 5 646 #define SMB_LGRP_NO_SID 6 647 #define SMB_LGRP_NO_LOCAL_SID 7 648 #define SMB_LGRP_SID_NOTLOCAL 8 649 #define SMB_LGRP_WKSID 9 650 #define SMB_LGRP_NO_MEMORY 10 651 #define SMB_LGRP_DB_ERROR 11 652 #define SMB_LGRP_DBINIT_ERROR 12 653 #define SMB_LGRP_INTERNAL_ERROR 13 654 #define SMB_LGRP_MEMBER_IN_GROUP 14 655 #define SMB_LGRP_MEMBER_NOT_IN_GROUP 15 656 #define SMB_LGRP_NO_SUCH_PRIV 16 657 #define SMB_LGRP_NO_SUCH_DOMAIN 17 658 #define SMB_LGRP_PRIV_HELD 18 659 #define SMB_LGRP_PRIV_NOT_HELD 19 660 #define SMB_LGRP_BAD_DATA 20 661 #define SMB_LGRP_NO_MORE 21 662 #define SMB_LGRP_DBOPEN_FAILED 22 663 #define SMB_LGRP_DBEXEC_FAILED 23 664 #define SMB_LGRP_DBINIT_FAILED 24 665 #define SMB_LGRP_DOMLKP_FAILED 25 666 #define SMB_LGRP_DOMINS_FAILED 26 667 #define SMB_LGRP_INSERT_FAILED 27 668 #define SMB_LGRP_DELETE_FAILED 28 669 #define SMB_LGRP_UPDATE_FAILED 29 670 #define SMB_LGRP_LOOKUP_FAILED 30 671 #define SMB_LGRP_NOT_SUPPORTED 31 672 673 #define SMB_LGRP_NAME_CHAR_MAX 32 674 #define SMB_LGRP_COMMENT_MAX 256 675 #define SMB_LGRP_NAME_MAX (SMB_LGRP_NAME_CHAR_MAX * MTS_MB_CHAR_MAX + 1) 676 677 /* 678 * values for smb_nic_t.smbflags 679 */ 680 #define SMB_NICF_NBEXCL 0x01 /* Excluded from Netbios activities */ 681 #define SMB_NICF_ALIAS 0x02 /* This is an alias */ 682 683 /* 684 * smb_nic_t 685 * nic_host actual host name 686 * nic_nbname 16-byte NetBIOS host name 687 */ 688 typedef struct { 689 char nic_host[MAXHOSTNAMELEN]; 690 char nic_nbname[NETBIOS_NAME_SZ]; 691 char nic_cmnt[SMB_PI_MAX_COMMENT]; 692 char nic_ifname[LIFNAMSIZ]; 693 uint32_t nic_ip; 694 uint32_t nic_mask; 695 uint32_t nic_bcast; 696 uint32_t nic_smbflags; 697 uint64_t nic_sysflags; 698 } smb_nic_t; 699 700 typedef struct smb_niciter { 701 smb_nic_t ni_nic; 702 int ni_cookie; 703 int ni_seqnum; 704 } smb_niciter_t; 705 706 /* NIC config functions */ 707 int smb_nic_init(void); 708 void smb_nic_fini(void); 709 int smb_nic_getnum(char *); 710 int smb_nic_addhost(const char *, const char *, int, const char **); 711 int smb_nic_delhost(const char *); 712 int smb_nic_getfirst(smb_niciter_t *); 713 int smb_nic_getnext(smb_niciter_t *); 714 boolean_t smb_nic_exists(uint32_t, boolean_t); 715 716 #ifdef __cplusplus 717 } 718 #endif 719 720 #endif /* _LIBSMB_H */ 721