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