xref: /titanic_51/usr/src/lib/smbsrv/libmlsvc/common/libmlsvc.h (revision b3700b074e637f8c6991b70754c88a2cfffb246b)
1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21da6c28aaSamw /*
22148c5f43SAlan Wright  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23*b3700b07SGordon Ross  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
24da6c28aaSamw  */
25da6c28aaSamw 
26da6c28aaSamw #ifndef	_LIBMLSVC_H
27da6c28aaSamw #define	_LIBMLSVC_H
28da6c28aaSamw 
291fcced4cSJordan Brown #include <uuid/uuid.h>
308d7e4166Sjose borrego #include <sys/param.h>
31da6c28aaSamw #include <sys/types.h>
328d7e4166Sjose borrego #include <sys/uio.h>
338d7e4166Sjose borrego #include <sys/ksynch.h>
349fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <time.h>
358d7e4166Sjose borrego #include <stdio.h>
368d7e4166Sjose borrego #include <string.h>
371fcced4cSJordan Brown #include <netdb.h>
381fcced4cSJordan Brown #include <libuutil.h>
398d7e4166Sjose borrego #include <smbsrv/wintypes.h>
40da6c28aaSamw #include <smbsrv/hash_table.h>
41da6c28aaSamw #include <smbsrv/smb_token.h>
42da6c28aaSamw #include <smbsrv/smb_privilege.h>
433db3f65cSamw #include <smbsrv/smb_share.h>
448d96b23eSAlan Wright #include <smbsrv/smb_xdr.h>
459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <smbsrv/smb_dfs.h>
468d7e4166Sjose borrego #include <smbsrv/libsmb.h>
478d7e4166Sjose borrego #include <smbsrv/libmlrpc.h>
488d7e4166Sjose borrego #include <smbsrv/ndl/lsarpc.ndl>
49da6c28aaSamw 
50da6c28aaSamw #ifdef	__cplusplus
51da6c28aaSamw extern "C" {
52da6c28aaSamw #endif
53da6c28aaSamw 
54fe1c642dSBill Krier uint32_t lsa_lookup_name(char *, uint16_t, smb_account_t *);
55fe1c642dSBill Krier uint32_t lsa_lookup_sid(smb_sid_t *, smb_account_t *);
568d7e4166Sjose borrego 
578d7e4166Sjose borrego /*
588d7e4166Sjose borrego  * SMB domain API to discover a domain controller and obtain domain
598d7e4166Sjose borrego  * information.
608d7e4166Sjose borrego  */
618d7e4166Sjose borrego 
62*b3700b07SGordon Ross extern boolean_t smb_locate_dc(char *, smb_domainex_t *);
63*b3700b07SGordon Ross uint32_t smb_ddiscover_dns(char *, smb_domainex_t *);
64*b3700b07SGordon Ross extern void smb_ddiscover_bad_dc(char *);
65*b3700b07SGordon Ross extern void smb_ddiscover_refresh(void);
66380acbbeSGordon Ross extern int smb_ddiscover_wait(void);
678d7e4166Sjose borrego 
681fdeec65Sjoyce mcintosh extern int dssetup_check_service(void);
692c1b14e5Sjose borrego extern void dssetup_clear_domain_info(void);
70a0aa776eSAlan Wright extern void mlsvc_disconnect(const char *);
71da6c28aaSamw extern int mlsvc_init(void);
7229bd2886SAlan Wright extern void mlsvc_fini(void);
73faa1795aSjb150015 extern DWORD mlsvc_netlogon(char *, char *);
74*b3700b07SGordon Ross extern void mlsvc_join(smb_joininfo_t *, smb_joinres_t *);
75da6c28aaSamw 
7612b65585SGordon Ross extern void smb_logon_domain(smb_logon_t *, smb_token_t *);
7712b65585SGordon Ross extern uint32_t smb_decode_krb5_pac(smb_token_t *, char *, uint_t);
7812b65585SGordon Ross extern boolean_t smb_token_setup_common(smb_token_t *);
7912b65585SGordon Ross 
808d7e4166Sjose borrego 
818d7e4166Sjose borrego /*
828d7e4166Sjose borrego  * The maximum number of domains (NT limit).
838d7e4166Sjose borrego  */
848d7e4166Sjose borrego #define	MLSVC_DOMAIN_MAX		32
858d7e4166Sjose borrego 
868d7e4166Sjose borrego #define	MLSVC_ANON_USER			"IPC$"
878d7e4166Sjose borrego 
888d7e4166Sjose borrego char *mlsvc_ipc_name(int ipc_type, char *username);
898d7e4166Sjose borrego 
908d7e4166Sjose borrego /*
918d7e4166Sjose borrego  * Passthrough negotiation and authentication interface.
928d7e4166Sjose borrego  *
938d7e4166Sjose borrego  * NT supports two forms of password: a Lanman (case-insensitive)
948d7e4166Sjose borrego  * password and an NT (case-sensitive) password. If either of the
958d7e4166Sjose borrego  * passwords is not available its pointer and length should be set
968d7e4166Sjose borrego  * to zero. The session key and vc number are required to validate
978d7e4166Sjose borrego  * the encrypted passwords.
988d7e4166Sjose borrego  */
998d7e4166Sjose borrego 
1008d7e4166Sjose borrego void mlsvc_nt_password_hash(char *result, char *password);
1018d7e4166Sjose borrego int mlsvc_encrypt_nt_password(char *password, char *key, int keylen, char *out,
1028d7e4166Sjose borrego     int outmax);
103da6c28aaSamw 
104da6c28aaSamw #define	SMB_AUTOHOME_FILE	"smbautohome"
105da6c28aaSamw #define	SMB_AUTOHOME_PATH	"/etc"
106da6c28aaSamw 
107da6c28aaSamw typedef struct smb_autohome {
108da6c28aaSamw 	struct smb_autohome *ah_next;
109da6c28aaSamw 	uint32_t ah_hits;
110da6c28aaSamw 	time_t ah_timestamp;
111da6c28aaSamw 	char *ah_name;		/* User account name */
112da6c28aaSamw 	char *ah_path;		/* Home directory path */
113da6c28aaSamw 	char *ah_container;	/* ADS container distinguished name */
114da6c28aaSamw } smb_autohome_t;
115da6c28aaSamw 
116fe1c642dSBill Krier extern void smb_autohome_add(const smb_token_t *);
1173ad684d6Sjb150015 extern void smb_autohome_remove(const char *);
118da6c28aaSamw 
1198d7e4166Sjose borrego /*
1208d7e4166Sjose borrego  * A local unique id (LUID) is an opaque id used by servers to identify
1218d7e4166Sjose borrego  * local resources, such as privileges.  A client will use lookup
1228d7e4166Sjose borrego  * functions to translate the LUID to a more general, machine independent
1238d7e4166Sjose borrego  * form; such as a string.
1248d7e4166Sjose borrego  */
1258d7e4166Sjose borrego typedef struct ms_luid {
1268d7e4166Sjose borrego 	uint32_t low_part;
1278d7e4166Sjose borrego 	uint32_t high_part;
1288d7e4166Sjose borrego } ms_luid_t;
1298d7e4166Sjose borrego 
1308d7e4166Sjose borrego /*
1311fcced4cSJordan Brown  * Information about a server as reported by NetServerGetInfo.
1321fcced4cSJordan Brown  * The SV_PLATFORM and SV_TYPE definitions are in srvsvc.ndl.
1331fcced4cSJordan Brown  */
1341fcced4cSJordan Brown typedef struct srvsvc_server_info {
1351fcced4cSJordan Brown 	uint32_t	sv_platform_id;
1361fcced4cSJordan Brown 	char		*sv_name;
1371fcced4cSJordan Brown 	uint32_t	sv_version_major;
1381fcced4cSJordan Brown 	uint32_t	sv_version_minor;
1391fcced4cSJordan Brown 	uint32_t	sv_type;
1401fcced4cSJordan Brown 	char		*sv_comment;
141a0aa776eSAlan Wright 	uint32_t	sv_os;
1421fcced4cSJordan Brown } srvsvc_server_info_t;
1431fcced4cSJordan Brown 
1441fcced4cSJordan Brown int srvsvc_net_server_getinfo(char *, char *, srvsvc_server_info_t *);
1459fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States int srvsvc_net_remote_tod(char *, char *, struct timeval *, struct tm *);
1469fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
1471fcced4cSJordan Brown 
1481fcced4cSJordan Brown /*
1498d7e4166Sjose borrego  * A client_t is created while binding a client connection to hold the
1508d7e4166Sjose borrego  * context for calls made using that connection.
1518d7e4166Sjose borrego  *
1528d7e4166Sjose borrego  * Handles are RPC call specific and we use an inheritance mechanism to
1538d7e4166Sjose borrego  * ensure that each handle has a pointer to the client_t.  When the top
1548d7e4166Sjose borrego  * level (bind) handle is released, we close the connection.
1558d7e4166Sjose borrego  */
1568d7e4166Sjose borrego typedef struct mlsvc_handle {
1578d7e4166Sjose borrego 	ndr_hdid_t			handle;
1588d7e4166Sjose borrego 	ndr_client_t			*clnt;
1591fcced4cSJordan Brown 	srvsvc_server_info_t		svinfo;
1608d7e4166Sjose borrego } mlsvc_handle_t;
1618d7e4166Sjose borrego 
162a0aa776eSAlan Wright void ndr_rpc_init(void);
163a0aa776eSAlan Wright void ndr_rpc_fini(void);
164*b3700b07SGordon Ross uint32_t ndr_rpc_bind(mlsvc_handle_t *, char *, char *, char *, const char *);
1658d7e4166Sjose borrego void ndr_rpc_unbind(mlsvc_handle_t *);
1668d7e4166Sjose borrego int ndr_rpc_call(mlsvc_handle_t *, int, void *);
167fe1c642dSBill Krier void ndr_rpc_set_nonull(mlsvc_handle_t *);
168fe1c642dSBill Krier const srvsvc_server_info_t *ndr_rpc_server_info(mlsvc_handle_t *);
169a0aa776eSAlan Wright uint32_t ndr_rpc_server_os(mlsvc_handle_t *);
170e3f2c991SKeyur Desai int ndr_rpc_get_ssnkey(mlsvc_handle_t *, unsigned char *, size_t);
1718d7e4166Sjose borrego void *ndr_rpc_malloc(mlsvc_handle_t *, size_t);
1728d7e4166Sjose borrego ndr_heap_t *ndr_rpc_get_heap(mlsvc_handle_t *);
1738d7e4166Sjose borrego void ndr_rpc_release(mlsvc_handle_t *);
1748d7e4166Sjose borrego boolean_t ndr_is_null_handle(mlsvc_handle_t *);
1758d7e4166Sjose borrego boolean_t ndr_is_bind_handle(mlsvc_handle_t *);
1768d7e4166Sjose borrego void ndr_inherit_handle(mlsvc_handle_t *, mlsvc_handle_t *);
1778d7e4166Sjose borrego void ndr_rpc_status(mlsvc_handle_t *, int, uint32_t);
1788d7e4166Sjose borrego 
1791fcced4cSJordan Brown /* SVCCTL service */
1801fcced4cSJordan Brown /*
1811fcced4cSJordan Brown  * Calculate the wide-char equivalent string length required to
1821fcced4cSJordan Brown  * store a string - including the terminating null wide-char.
1831fcced4cSJordan Brown  */
184bbf6f00cSJordan Brown #define	SVCCTL_WNSTRLEN(S)	((strlen((S)) + 1) * sizeof (smb_wchar_t))
1851fcced4cSJordan Brown 
1861fcced4cSJordan Brown /* An AVL-storable node representing each service in the SCM database. */
1871fcced4cSJordan Brown typedef struct svcctl_svc_node {
1881fcced4cSJordan Brown 	uu_avl_node_t		sn_node;
1891fcced4cSJordan Brown 	char			*sn_name;	/* Service Name (Key) */
1901fcced4cSJordan Brown 	char			*sn_fmri;	/* Display Name (FMRI) */
1911fcced4cSJordan Brown 	char			*sn_desc;	/* Description */
1921fcced4cSJordan Brown 	char			*sn_state;	/* State */
1931fcced4cSJordan Brown } svcctl_svc_node_t;
1941fcced4cSJordan Brown 
1951fcced4cSJordan Brown /* This structure provides context for each svcctl_s_OpenManager call. */
1961fcced4cSJordan Brown typedef struct svcctl_manager_context {
1971fcced4cSJordan Brown 	scf_handle_t		*mc_scf_hdl;	  /* SCF handle */
1981fcced4cSJordan Brown 	scf_propertygroup_t	*mc_scf_gpg;	  /* Property group */
1991fcced4cSJordan Brown 	scf_property_t		*mc_scf_gprop;	  /* Property */
2001fcced4cSJordan Brown 	scf_value_t		*mc_scf_gval;	  /* Value */
2011fcced4cSJordan Brown 	uint32_t		mc_scf_numsvcs;   /* Number of SMF services */
2021fcced4cSJordan Brown 	ssize_t			mc_scf_max_fmri_len;  /* Max FMRI length */
2031fcced4cSJordan Brown 	ssize_t			mc_scf_max_value_len; /* Max Value length */
2041fcced4cSJordan Brown 	uint32_t		mc_bytes_needed;  /* Number of bytes needed */
2051fcced4cSJordan Brown 	uu_avl_pool_t		*mc_svcs_pool;	  /* AVL pool */
2061fcced4cSJordan Brown 	uu_avl_t		*mc_svcs;	  /* AVL tree of SMF services */
2071fcced4cSJordan Brown } svcctl_manager_context_t;
2081fcced4cSJordan Brown 
2091fcced4cSJordan Brown /* This structure provides context for each svcctl_s_OpenService call. */
2101fcced4cSJordan Brown typedef struct svcctl_service_context {
2111fcced4cSJordan Brown 	ndr_hdid_t		*sc_mgrid;	/* Manager ID */
2121fcced4cSJordan Brown 	char			*sc_svcname;    /* Service Name */
2131fcced4cSJordan Brown } svcctl_service_context_t;
2141fcced4cSJordan Brown 
2151fcced4cSJordan Brown typedef enum {
2161fcced4cSJordan Brown 	SVCCTL_MANAGER_CONTEXT = 0,
2171fcced4cSJordan Brown 	SVCCTL_SERVICE_CONTEXT
2181fcced4cSJordan Brown } svcctl_context_type_t;
2191fcced4cSJordan Brown 
2201fcced4cSJordan Brown /* This structure provides abstraction for service and manager context call. */
2211fcced4cSJordan Brown typedef struct svcctl_context {
2221fcced4cSJordan Brown 	svcctl_context_type_t	c_type;
2231fcced4cSJordan Brown 	union {
2241fcced4cSJordan Brown 		svcctl_manager_context_t *uc_mgr;
2251fcced4cSJordan Brown 		svcctl_service_context_t *uc_svc;
2261fcced4cSJordan Brown 		void *uc_cp;
2271fcced4cSJordan Brown 	} c_ctx;
2281fcced4cSJordan Brown } svcctl_context_t;
2291fcced4cSJordan Brown 
2301fcced4cSJordan Brown /* Service Control Manager (SCM) functions */
2311fcced4cSJordan Brown void svcctl_init(void);
2321fcced4cSJordan Brown void svcctl_fini(void);
2331fcced4cSJordan Brown int svcctl_scm_init(svcctl_manager_context_t *);
2341fcced4cSJordan Brown void svcctl_scm_fini(svcctl_manager_context_t *);
2351fcced4cSJordan Brown int svcctl_scm_scf_handle_init(svcctl_manager_context_t *);
2361fcced4cSJordan Brown void svcctl_scm_scf_handle_fini(svcctl_manager_context_t *);
2371fcced4cSJordan Brown int svcctl_scm_refresh(svcctl_manager_context_t *);
2381fcced4cSJordan Brown uint32_t svcctl_scm_enum_services(svcctl_manager_context_t *, uint8_t *,
2391fcced4cSJordan Brown     size_t, uint32_t *, boolean_t);
2401fcced4cSJordan Brown uint32_t svcctl_scm_validate_service(svcctl_manager_context_t *, char *);
2411fcced4cSJordan Brown svcctl_svc_node_t *svcctl_scm_find_service(svcctl_manager_context_t *, char *);
2421fcced4cSJordan Brown uint32_t svcctl_scm_map_status(const char *);
2431fcced4cSJordan Brown 
2441fcced4cSJordan Brown /* LOGR service */
2451fcced4cSJordan Brown #define	LOGR_APPLICATION_LOG		"Application"
2461fcced4cSJordan Brown #define	LOGR_SECURITY_LOG		"Security"
2471fcced4cSJordan Brown #define	LOGR_SYSTEM_LOG			"System"
2481fcced4cSJordan Brown #define	LOGR_NMSGMASK			1023
2491fcced4cSJordan Brown #define	LOGR_MAXMSGLEN			800
2501fcced4cSJordan Brown 
2511fcced4cSJordan Brown typedef struct logr_entry {
2521fcced4cSJordan Brown 	struct timeval	le_timestamp;			/* Time of log entry */
2531fcced4cSJordan Brown 	int		le_pri;				/* Message priority */
2541fcced4cSJordan Brown 	char		le_hostname[MAXHOSTNAMELEN];	/* Log hostname */
2551fcced4cSJordan Brown 	char		le_msg[LOGR_MAXMSGLEN];		/* Log message text */
2561fcced4cSJordan Brown } logr_entry_t;
2571fcced4cSJordan Brown 
2581fcced4cSJordan Brown typedef struct logr_info {
2591fcced4cSJordan Brown 	logr_entry_t	li_entry[LOGR_NMSGMASK+1];	/* Array of log entry */
2601fcced4cSJordan Brown 	int		li_idx;				/* Index */
2611fcced4cSJordan Brown } logr_info_t;
2621fcced4cSJordan Brown 
2631fcced4cSJordan Brown typedef struct logr_read_data {
2641fcced4cSJordan Brown 	int		rd_tot_recnum;		/* Total no. of record read */
2651fcced4cSJordan Brown 	int		rd_last_sentrec;	/* Last sentence read */
2661fcced4cSJordan Brown 	char		rd_first_read;		/* First sentence read */
2671fcced4cSJordan Brown 	logr_info_t	*rd_log;		/* Log information read */
2681fcced4cSJordan Brown } logr_read_data_t;
2691fcced4cSJordan Brown 
2701fcced4cSJordan Brown /* This structure provides the context for eventlog calls from clients. */
2711fcced4cSJordan Brown typedef struct logr_context {
2721fcced4cSJordan Brown 	logr_read_data_t *lc_cached_read_data;
2731fcced4cSJordan Brown 	char *lc_source_name;
2741fcced4cSJordan Brown } logr_context_t;
2751fcced4cSJordan Brown 
2761fcced4cSJordan Brown void logr_init(void);
2771fcced4cSJordan Brown void logr_fini(void);
2781fcced4cSJordan Brown boolean_t logr_is_supported(char *);
2791fcced4cSJordan Brown int logr_get_snapshot(logr_context_t *);
2801fcced4cSJordan Brown 
2819fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* User and Group quotas */
2829fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t smb_quota_query(smb_quota_query_t *, smb_quota_response_t *);
2839fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t smb_quota_set(smb_quota_set_t *);
2849fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void smb_quota_free(smb_quota_response_t *);
2859fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
2869fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t dfs_get_referrals(const char *, dfs_reftype_t, dfs_info_t *);
2879fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void dfs_info_free(dfs_info_t *);
2889fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
289fd9ee8b5Sjoyce mcintosh /*
290fd9ee8b5Sjoyce mcintosh  * The spoolss installable copyfile API.
291fd9ee8b5Sjoyce mcintosh  */
292fd9ee8b5Sjoyce mcintosh typedef void (*spoolss_copyfile_t)(smb_inaddr_t *, char *, char *, char *);
293fd9ee8b5Sjoyce mcintosh void spoolss_register_copyfile(spoolss_copyfile_t);
294cb174861Sjoyce mcintosh 
295da6c28aaSamw #ifdef	__cplusplus
296da6c28aaSamw }
297da6c28aaSamw #endif
298da6c28aaSamw 
299da6c28aaSamw #endif	/* _LIBMLSVC_H */
300