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