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