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