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