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