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