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