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