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