xref: /illumos-gate/usr/src/lib/smbsrv/libmlsvc/common/libmlsvc.h (revision ce8560eeb961d528e27685fcdd2ffb03e9478dbf)
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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2020 Tintri by DDN, Inc. All rights reserved.
24  */
25 
26 #ifndef	_LIBMLSVC_H
27 #define	_LIBMLSVC_H
28 
29 #include <sys/param.h>
30 #include <sys/types.h>
31 #include <sys/uio.h>
32 #include <sys/ksynch.h>
33 #include <uuid/uuid.h>
34 
35 #include <time.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <syslog.h>
39 #include <netdb.h>
40 #include <libuutil.h>
41 
42 #include <smb/wintypes.h>
43 #include <libmlrpc/libmlrpc.h>
44 
45 #include <smbsrv/hash_table.h>
46 #include <smbsrv/smb_token.h>
47 #include <smbsrv/smb_privilege.h>
48 #include <smbsrv/smb_share.h>
49 #include <smbsrv/smb_xdr.h>
50 #include <smbsrv/smb_dfs.h>
51 #include <smbsrv/libsmb.h>
52 
53 /*
54  * XXX: Some temporary left-overs from the old ntstatus.h
55  * Should eliminate uses of these macros when convenient.
56  */
57 /* This used to OR in the severity bits. */
58 #define	NT_SC_ERROR(S)		(S)
59 /* This used to mask off the severity bits. */
60 #define	NT_SC_VALUE(S)		(S)
61 /* XXX end of temporary left-overs. */
62 
63 #ifdef	__cplusplus
64 extern "C" {
65 #endif
66 
67 uint32_t lsa_lookup_name(char *, uint16_t, smb_account_t *);
68 uint32_t lsa_lookup_lname(char *, uint16_t, smb_account_t *);
69 uint32_t lsa_lookup_sid(smb_sid_t *, smb_account_t *);
70 uint32_t lsa_lookup_lsid(smb_sid_t *, smb_account_t *);
71 
72 /*
73  * SMB domain API to discover a domain controller and obtain domain
74  * information.
75  */
76 
77 extern boolean_t smb_locate_dc(char *, smb_domainex_t *);
78 uint32_t smb_ddiscover_dns(char *, smb_domainex_t *);
79 extern void smb_ddiscover_bad_dc(char *);
80 extern void smb_ddiscover_refresh(void);
81 
82 extern int dssetup_check_service(void);
83 extern void dssetup_clear_domain_info(void);
84 extern void mlsvc_disconnect(const char *);
85 extern int mlsvc_init(void);
86 extern void mlsvc_fini(void);
87 extern DWORD mlsvc_netlogon(char *, char *);
88 extern void mlsvc_join(smb_joininfo_t *, smb_joinres_t *);
89 
90 extern void smb_logon_domain(smb_logon_t *, smb_token_t *);
91 extern uint32_t smb_decode_krb5_pac(smb_token_t *, char *, uint_t);
92 extern boolean_t smb_token_setup_common(smb_token_t *);
93 
94 
95 /*
96  * The maximum number of domains (NT limit).
97  */
98 #define	MLSVC_DOMAIN_MAX		32
99 
100 #define	MLSVC_ANON_USER			"IPC$"
101 
102 char *mlsvc_ipc_name(int ipc_type, char *username);
103 
104 /*
105  * Passthrough negotiation and authentication interface.
106  *
107  * NT supports two forms of password: a Lanman (case-insensitive)
108  * password and an NT (case-sensitive) password. If either of the
109  * passwords is not available its pointer and length should be set
110  * to zero. The session key and vc number are required to validate
111  * the encrypted passwords.
112  */
113 
114 void mlsvc_nt_password_hash(char *result, char *password);
115 int mlsvc_encrypt_nt_password(char *password, char *key, int keylen, char *out,
116     int outmax);
117 
118 #define	SMB_AUTOHOME_FILE	"smbautohome"
119 #define	SMB_AUTOHOME_PATH	"/etc"
120 
121 typedef struct smb_autohome {
122 	struct smb_autohome *ah_next;
123 	uint32_t ah_hits;
124 	time_t ah_timestamp;
125 	char *ah_name;		/* User account name */
126 	char *ah_path;		/* Home directory path */
127 	char *ah_container;	/* ADS container distinguished name */
128 } smb_autohome_t;
129 
130 extern void smb_autohome_add(const smb_token_t *);
131 extern void smb_autohome_remove(const char *);
132 
133 /*
134  * A local unique id (LUID) is an opaque id used by servers to identify
135  * local resources, such as privileges.  A client will use lookup
136  * functions to translate the LUID to a more general, machine independent
137  * form; such as a string.
138  */
139 typedef struct ms_luid {
140 	uint32_t low_part;
141 	uint32_t high_part;
142 } ms_luid_t;
143 
144 /*
145  * A client_t is created while binding a client connection to hold the
146  * context for calls made using that connection.
147  *
148  * Handles are RPC call specific and we use an inheritance mechanism to
149  * ensure that each handle has a pointer to the client_t.  When the top
150  * level (bind) handle is released, we close the connection.
151  */
152 typedef struct mlrpc_handle mlsvc_handle_t;
153 
154 /* mlsvc_client.c */
155 void ndr_rpc_init(void);
156 void ndr_rpc_fini(void);
157 uint32_t ndr_rpc_bind(mlsvc_handle_t *, char *, char *, char *, const char *);
158 uint32_t ndr_rpc_bind_secure(mlsvc_handle_t *, char *, char *, char *,
159     const char *, ndr_auth_ctx_t *);
160 void ndr_rpc_unbind(mlsvc_handle_t *);
161 void ndr_rpc_status(mlsvc_handle_t *, int, uint32_t);
162 
163 /* These three get info about the connected client. */
164 boolean_t ndr_is_admin(ndr_xa_t *);
165 boolean_t ndr_is_poweruser(ndr_xa_t *);
166 int32_t ndr_native_os(ndr_xa_t *);
167 
168 /* SRVSVC */
169 int srvsvc_net_remote_tod(char *, char *, struct timeval *, struct tm *);
170 
171 /* SVCCTL service */
172 /*
173  * Calculate the wide-char equivalent string length required to
174  * store a string - including the terminating null wide-char.
175  */
176 #define	SVCCTL_WNSTRLEN(S)	((strlen((S)) + 1) * sizeof (smb_wchar_t))
177 
178 /* An AVL-storable node representing each service in the SCM database. */
179 typedef struct svcctl_svc_node {
180 	uu_avl_node_t		sn_node;
181 	char			*sn_name;	/* Service Name (Key) */
182 	char			*sn_fmri;	/* Display Name (FMRI) */
183 	char			*sn_desc;	/* Description */
184 	char			*sn_state;	/* State */
185 } svcctl_svc_node_t;
186 
187 /* This structure provides context for each svcctl_s_OpenManager call. */
188 typedef struct svcctl_manager_context {
189 	scf_handle_t		*mc_scf_hdl;	  /* SCF handle */
190 	scf_propertygroup_t	*mc_scf_gpg;	  /* Property group */
191 	scf_property_t		*mc_scf_gprop;	  /* Property */
192 	scf_value_t		*mc_scf_gval;	  /* Value */
193 	uint32_t		mc_scf_numsvcs;   /* Number of SMF services */
194 	ssize_t			mc_scf_max_fmri_len;  /* Max FMRI length */
195 	ssize_t			mc_scf_max_value_len; /* Max Value length */
196 	uint32_t		mc_bytes_needed;  /* Number of bytes needed */
197 	uu_avl_pool_t		*mc_svcs_pool;	  /* AVL pool */
198 	uu_avl_t		*mc_svcs;	  /* AVL tree of SMF services */
199 } svcctl_manager_context_t;
200 
201 /* This structure provides context for each svcctl_s_OpenService call. */
202 typedef struct svcctl_service_context {
203 	ndr_hdid_t		*sc_mgrid;	/* Manager ID */
204 	char			*sc_svcname;    /* Service Name */
205 } svcctl_service_context_t;
206 
207 typedef enum {
208 	SVCCTL_MANAGER_CONTEXT = 0,
209 	SVCCTL_SERVICE_CONTEXT
210 } svcctl_context_type_t;
211 
212 /* This structure provides abstraction for service and manager context call. */
213 typedef struct svcctl_context {
214 	svcctl_context_type_t	c_type;
215 	union {
216 		svcctl_manager_context_t *uc_mgr;
217 		svcctl_service_context_t *uc_svc;
218 		void *uc_cp;
219 	} c_ctx;
220 } svcctl_context_t;
221 
222 /* Service Control Manager (SCM) functions */
223 void svcctl_init(void);
224 void svcctl_fini(void);
225 int svcctl_scm_init(svcctl_manager_context_t *);
226 void svcctl_scm_fini(svcctl_manager_context_t *);
227 int svcctl_scm_scf_handle_init(svcctl_manager_context_t *);
228 void svcctl_scm_scf_handle_fini(svcctl_manager_context_t *);
229 int svcctl_scm_refresh(svcctl_manager_context_t *);
230 uint32_t svcctl_scm_enum_services(svcctl_manager_context_t *, uint8_t *,
231     size_t, uint32_t *, boolean_t);
232 uint32_t svcctl_scm_validate_service(svcctl_manager_context_t *, char *);
233 svcctl_svc_node_t *svcctl_scm_find_service(svcctl_manager_context_t *, char *);
234 uint32_t svcctl_scm_map_status(const char *);
235 
236 /* LOGR service */
237 #define	LOGR_APPLICATION_LOG		"Application"
238 #define	LOGR_SECURITY_LOG		"Security"
239 #define	LOGR_SYSTEM_LOG			"System"
240 #define	LOGR_NMSGMASK			1023
241 #define	LOGR_MAXMSGLEN			800
242 
243 typedef struct logr_entry {
244 	struct timeval	le_timestamp;			/* Time of log entry */
245 	int		le_pri;				/* Message priority */
246 	char		le_hostname[MAXHOSTNAMELEN];	/* Log hostname */
247 	char		le_msg[LOGR_MAXMSGLEN];		/* Log message text */
248 } logr_entry_t;
249 
250 typedef struct logr_info {
251 	logr_entry_t	li_entry[LOGR_NMSGMASK+1];	/* Array of log entry */
252 	int		li_idx;				/* Index */
253 } logr_info_t;
254 
255 typedef struct logr_read_data {
256 	int		rd_tot_recnum;		/* Total no. of record read */
257 	int		rd_last_sentrec;	/* Last sentence read */
258 	char		rd_first_read;		/* First sentence read */
259 	logr_info_t	*rd_log;		/* Log information read */
260 } logr_read_data_t;
261 
262 /* This structure provides the context for eventlog calls from clients. */
263 typedef struct logr_context {
264 	logr_read_data_t *lc_cached_read_data;
265 	char *lc_source_name;
266 } logr_context_t;
267 
268 void logr_init(void);
269 void logr_fini(void);
270 boolean_t logr_is_supported(char *);
271 int logr_get_snapshot(logr_context_t *);
272 
273 /* User and Group quotas */
274 uint32_t smb_quota_query(smb_quota_query_t *, smb_quota_response_t *);
275 uint32_t smb_quota_set(smb_quota_set_t *);
276 void smb_quota_free(smb_quota_response_t *);
277 
278 uint32_t dfs_get_referrals(const char *, dfs_reftype_t, dfs_info_t *);
279 void dfs_info_free(dfs_info_t *);
280 
281 /*
282  * The spoolss installable copyfile API.
283  */
284 typedef void (*spoolss_copyfile_t)(smb_inaddr_t *, char *, char *, char *);
285 void spoolss_register_copyfile(spoolss_copyfile_t);
286 
287 #ifdef	__cplusplus
288 }
289 #endif
290 
291 #endif	/* _LIBMLSVC_H */
292