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*ce8560eeSMatt Barden  * Copyright 2020 Tintri by DDN, Inc. All rights reserved.
24da6c28aaSamw  */
25da6c28aaSamw 
26da6c28aaSamw #ifndef	_LIBMLSVC_H
27da6c28aaSamw #define	_LIBMLSVC_H
28da6c28aaSamw 
298d7e4166Sjose borrego #include <sys/param.h>
30da6c28aaSamw #include <sys/types.h>
318d7e4166Sjose borrego #include <sys/uio.h>
328d7e4166Sjose borrego #include <sys/ksynch.h>
333299f39fSGordon Ross #include <uuid/uuid.h>
343299f39fSGordon Ross 
359fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <time.h>
368d7e4166Sjose borrego #include <stdio.h>
378d7e4166Sjose borrego #include <string.h>
383299f39fSGordon Ross #include <syslog.h>
391fcced4cSJordan Brown #include <netdb.h>
401fcced4cSJordan Brown #include <libuutil.h>
413299f39fSGordon Ross 
423299f39fSGordon Ross #include <smb/wintypes.h>
433299f39fSGordon Ross #include <libmlrpc/libmlrpc.h>
443299f39fSGordon Ross 
45da6c28aaSamw #include <smbsrv/hash_table.h>
46da6c28aaSamw #include <smbsrv/smb_token.h>
47da6c28aaSamw #include <smbsrv/smb_privilege.h>
483db3f65cSamw #include <smbsrv/smb_share.h>
498d96b23eSAlan Wright #include <smbsrv/smb_xdr.h>
509fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States #include <smbsrv/smb_dfs.h>
518d7e4166Sjose borrego #include <smbsrv/libsmb.h>
52da6c28aaSamw 
53d6390ef7SGordon Ross /*
54d6390ef7SGordon Ross  * XXX: Some temporary left-overs from the old ntstatus.h
55d6390ef7SGordon Ross  * Should eliminate uses of these macros when convenient.
56d6390ef7SGordon Ross  */
57d6390ef7SGordon Ross /* This used to OR in the severity bits. */
58d6390ef7SGordon Ross #define	NT_SC_ERROR(S)		(S)
59d6390ef7SGordon Ross /* This used to mask off the severity bits. */
60d6390ef7SGordon Ross #define	NT_SC_VALUE(S)		(S)
61d6390ef7SGordon Ross /* XXX end of temporary left-overs. */
62d6390ef7SGordon Ross 
63da6c28aaSamw #ifdef	__cplusplus
64da6c28aaSamw extern "C" {
65da6c28aaSamw #endif
66da6c28aaSamw 
67fe1c642dSBill Krier uint32_t lsa_lookup_name(char *, uint16_t, smb_account_t *);
68dafb549fSGordon Ross uint32_t lsa_lookup_lname(char *, uint16_t, smb_account_t *);
69fe1c642dSBill Krier uint32_t lsa_lookup_sid(smb_sid_t *, smb_account_t *);
70dafb549fSGordon Ross uint32_t lsa_lookup_lsid(smb_sid_t *, smb_account_t *);
718d7e4166Sjose borrego 
728d7e4166Sjose borrego /*
738d7e4166Sjose borrego  * SMB domain API to discover a domain controller and obtain domain
748d7e4166Sjose borrego  * information.
758d7e4166Sjose borrego  */
768d7e4166Sjose borrego 
77b3700b07SGordon Ross extern boolean_t smb_locate_dc(char *, smb_domainex_t *);
78b3700b07SGordon Ross uint32_t smb_ddiscover_dns(char *, smb_domainex_t *);
79b3700b07SGordon Ross extern void smb_ddiscover_bad_dc(char *);
80b3700b07SGordon Ross extern void smb_ddiscover_refresh(void);
818d7e4166Sjose borrego 
821fdeec65Sjoyce mcintosh extern int dssetup_check_service(void);
832c1b14e5Sjose borrego extern void dssetup_clear_domain_info(void);
84a0aa776eSAlan Wright extern void mlsvc_disconnect(const char *);
85da6c28aaSamw extern int mlsvc_init(void);
8629bd2886SAlan Wright extern void mlsvc_fini(void);
87faa1795aSjb extern DWORD mlsvc_netlogon(char *, char *);
88b3700b07SGordon Ross extern void mlsvc_join(smb_joininfo_t *, smb_joinres_t *);
898d7e4166Sjose borrego 
9012b65585SGordon Ross extern void smb_logon_domain(smb_logon_t *, smb_token_t *);
9112b65585SGordon Ross extern uint32_t smb_decode_krb5_pac(smb_token_t *, char *, uint_t);
9212b65585SGordon Ross extern boolean_t smb_token_setup_common(smb_token_t *);
9312b65585SGordon Ross 
948d7e4166Sjose borrego 
958d7e4166Sjose borrego /*
968d7e4166Sjose borrego  * The maximum number of domains (NT limit).
978d7e4166Sjose borrego  */
988d7e4166Sjose borrego #define	MLSVC_DOMAIN_MAX		32
998d7e4166Sjose borrego 
1008d7e4166Sjose borrego #define	MLSVC_ANON_USER			"IPC$"
1018d7e4166Sjose borrego 
1028d7e4166Sjose borrego char *mlsvc_ipc_name(int ipc_type, char *username);
1038d7e4166Sjose borrego 
1048d7e4166Sjose borrego /*
1058d7e4166Sjose borrego  * Passthrough negotiation and authentication interface.
1068d7e4166Sjose borrego  *
1078d7e4166Sjose borrego  * NT supports two forms of password: a Lanman (case-insensitive)
1088d7e4166Sjose borrego  * password and an NT (case-sensitive) password. If either of the
1098d7e4166Sjose borrego  * passwords is not available its pointer and length should be set
1108d7e4166Sjose borrego  * to zero. The session key and vc number are required to validate
1118d7e4166Sjose borrego  * the encrypted passwords.
1128d7e4166Sjose borrego  */
113da6c28aaSamw 
1148d7e4166Sjose borrego void mlsvc_nt_password_hash(char *result, char *password);
1158d7e4166Sjose borrego int mlsvc_encrypt_nt_password(char *password, char *key, int keylen, char *out,
1168d7e4166Sjose borrego     int outmax);
117da6c28aaSamw 
118da6c28aaSamw #define	SMB_AUTOHOME_FILE	"smbautohome"
119da6c28aaSamw #define	SMB_AUTOHOME_PATH	"/etc"
120da6c28aaSamw 
121da6c28aaSamw typedef struct smb_autohome {
122da6c28aaSamw 	struct smb_autohome *ah_next;
123da6c28aaSamw 	uint32_t ah_hits;
124da6c28aaSamw 	time_t ah_timestamp;
125da6c28aaSamw 	char *ah_name;		/* User account name */
126da6c28aaSamw 	char *ah_path;		/* Home directory path */
127da6c28aaSamw 	char *ah_container;	/* ADS container distinguished name */
128da6c28aaSamw } smb_autohome_t;
129da6c28aaSamw 
130fe1c642dSBill Krier extern void smb_autohome_add(const smb_token_t *);
1313ad684d6Sjb extern void smb_autohome_remove(const char *);
132da6c28aaSamw 
1338d7e4166Sjose borrego /*
1348d7e4166Sjose borrego  * A local unique id (LUID) is an opaque id used by servers to identify
1358d7e4166Sjose borrego  * local resources, such as privileges.  A client will use lookup
1368d7e4166Sjose borrego  * functions to translate the LUID to a more general, machine independent
1378d7e4166Sjose borrego  * form; such as a string.
1388d7e4166Sjose borrego  */
1398d7e4166Sjose borrego typedef struct ms_luid {
1408d7e4166Sjose borrego 	uint32_t low_part;
1418d7e4166Sjose borrego 	uint32_t high_part;
1428d7e4166Sjose borrego } ms_luid_t;
1438d7e4166Sjose borrego 
1448d7e4166Sjose borrego /*
1458d7e4166Sjose borrego  * A client_t is created while binding a client connection to hold the
1468d7e4166Sjose borrego  * context for calls made using that connection.
1478d7e4166Sjose borrego  *
1488d7e4166Sjose borrego  * Handles are RPC call specific and we use an inheritance mechanism to
1498d7e4166Sjose borrego  * ensure that each handle has a pointer to the client_t.  When the top
1508d7e4166Sjose borrego  * level (bind) handle is released, we close the connection.
1518d7e4166Sjose borrego  */
1523299f39fSGordon Ross typedef struct mlrpc_handle mlsvc_handle_t;
1538d7e4166Sjose borrego 
1543299f39fSGordon Ross /* mlsvc_client.c */
155a0aa776eSAlan Wright void ndr_rpc_init(void);
156a0aa776eSAlan Wright void ndr_rpc_fini(void);
157b3700b07SGordon Ross uint32_t ndr_rpc_bind(mlsvc_handle_t *, char *, char *, char *, const char *);
158*ce8560eeSMatt Barden uint32_t ndr_rpc_bind_secure(mlsvc_handle_t *, char *, char *, char *,
159*ce8560eeSMatt Barden     const char *, ndr_auth_ctx_t *);
1608d7e4166Sjose borrego void ndr_rpc_unbind(mlsvc_handle_t *);
1618d7e4166Sjose borrego void ndr_rpc_status(mlsvc_handle_t *, int, uint32_t);
1628d7e4166Sjose borrego 
1633299f39fSGordon Ross /* These three get info about the connected client. */
1643299f39fSGordon Ross boolean_t ndr_is_admin(ndr_xa_t *);
1653299f39fSGordon Ross boolean_t ndr_is_poweruser(ndr_xa_t *);
1663299f39fSGordon Ross int32_t ndr_native_os(ndr_xa_t *);
1673299f39fSGordon Ross 
1683299f39fSGordon Ross /* SRVSVC */
1693299f39fSGordon Ross int srvsvc_net_remote_tod(char *, char *, struct timeval *, struct tm *);
1703299f39fSGordon Ross 
1711fcced4cSJordan Brown /* SVCCTL service */
1721fcced4cSJordan Brown /*
1731fcced4cSJordan Brown  * Calculate the wide-char equivalent string length required to
1741fcced4cSJordan Brown  * store a string - including the terminating null wide-char.
1751fcced4cSJordan Brown  */
176bbf6f00cSJordan Brown #define	SVCCTL_WNSTRLEN(S)	((strlen((S)) + 1) * sizeof (smb_wchar_t))
1771fcced4cSJordan Brown 
1781fcced4cSJordan Brown /* An AVL-storable node representing each service in the SCM database. */
1791fcced4cSJordan Brown typedef struct svcctl_svc_node {
1801fcced4cSJordan Brown 	uu_avl_node_t		sn_node;
1811fcced4cSJordan Brown 	char			*sn_name;	/* Service Name (Key) */
1821fcced4cSJordan Brown 	char			*sn_fmri;	/* Display Name (FMRI) */
1831fcced4cSJordan Brown 	char			*sn_desc;	/* Description */
1841fcced4cSJordan Brown 	char			*sn_state;	/* State */
1851fcced4cSJordan Brown } svcctl_svc_node_t;
1861fcced4cSJordan Brown 
1871fcced4cSJordan Brown /* This structure provides context for each svcctl_s_OpenManager call. */
1881fcced4cSJordan Brown typedef struct svcctl_manager_context {
1891fcced4cSJordan Brown 	scf_handle_t		*mc_scf_hdl;	  /* SCF handle */
1901fcced4cSJordan Brown 	scf_propertygroup_t	*mc_scf_gpg;	  /* Property group */
1911fcced4cSJordan Brown 	scf_property_t		*mc_scf_gprop;	  /* Property */
1921fcced4cSJordan Brown 	scf_value_t		*mc_scf_gval;	  /* Value */
1931fcced4cSJordan Brown 	uint32_t		mc_scf_numsvcs;   /* Number of SMF services */
1941fcced4cSJordan Brown 	ssize_t			mc_scf_max_fmri_len;  /* Max FMRI length */
1951fcced4cSJordan Brown 	ssize_t			mc_scf_max_value_len; /* Max Value length */
1961fcced4cSJordan Brown 	uint32_t		mc_bytes_needed;  /* Number of bytes needed */
1971fcced4cSJordan Brown 	uu_avl_pool_t		*mc_svcs_pool;	  /* AVL pool */
1981fcced4cSJordan Brown 	uu_avl_t		*mc_svcs;	  /* AVL tree of SMF services */
1991fcced4cSJordan Brown } svcctl_manager_context_t;
2001fcced4cSJordan Brown 
2011fcced4cSJordan Brown /* This structure provides context for each svcctl_s_OpenService call. */
2021fcced4cSJordan Brown typedef struct svcctl_service_context {
2031fcced4cSJordan Brown 	ndr_hdid_t		*sc_mgrid;	/* Manager ID */
2041fcced4cSJordan Brown 	char			*sc_svcname;    /* Service Name */
2051fcced4cSJordan Brown } svcctl_service_context_t;
2061fcced4cSJordan Brown 
2071fcced4cSJordan Brown typedef enum {
2081fcced4cSJordan Brown 	SVCCTL_MANAGER_CONTEXT = 0,
2091fcced4cSJordan Brown 	SVCCTL_SERVICE_CONTEXT
2101fcced4cSJordan Brown } svcctl_context_type_t;
2111fcced4cSJordan Brown 
2121fcced4cSJordan Brown /* This structure provides abstraction for service and manager context call. */
2131fcced4cSJordan Brown typedef struct svcctl_context {
2141fcced4cSJordan Brown 	svcctl_context_type_t	c_type;
2151fcced4cSJordan Brown 	union {
2161fcced4cSJordan Brown 		svcctl_manager_context_t *uc_mgr;
2171fcced4cSJordan Brown 		svcctl_service_context_t *uc_svc;
2181fcced4cSJordan Brown 		void *uc_cp;
2191fcced4cSJordan Brown 	} c_ctx;
2201fcced4cSJordan Brown } svcctl_context_t;
2211fcced4cSJordan Brown 
2221fcced4cSJordan Brown /* Service Control Manager (SCM) functions */
2231fcced4cSJordan Brown void svcctl_init(void);
2241fcced4cSJordan Brown void svcctl_fini(void);
2251fcced4cSJordan Brown int svcctl_scm_init(svcctl_manager_context_t *);
2261fcced4cSJordan Brown void svcctl_scm_fini(svcctl_manager_context_t *);
2271fcced4cSJordan Brown int svcctl_scm_scf_handle_init(svcctl_manager_context_t *);
2281fcced4cSJordan Brown void svcctl_scm_scf_handle_fini(svcctl_manager_context_t *);
2291fcced4cSJordan Brown int svcctl_scm_refresh(svcctl_manager_context_t *);
2301fcced4cSJordan Brown uint32_t svcctl_scm_enum_services(svcctl_manager_context_t *, uint8_t *,
2311fcced4cSJordan Brown     size_t, uint32_t *, boolean_t);
2321fcced4cSJordan Brown uint32_t svcctl_scm_validate_service(svcctl_manager_context_t *, char *);
2331fcced4cSJordan Brown svcctl_svc_node_t *svcctl_scm_find_service(svcctl_manager_context_t *, char *);
2341fcced4cSJordan Brown uint32_t svcctl_scm_map_status(const char *);
2351fcced4cSJordan Brown 
2361fcced4cSJordan Brown /* LOGR service */
2371fcced4cSJordan Brown #define	LOGR_APPLICATION_LOG		"Application"
2381fcced4cSJordan Brown #define	LOGR_SECURITY_LOG		"Security"
2391fcced4cSJordan Brown #define	LOGR_SYSTEM_LOG			"System"
2401fcced4cSJordan Brown #define	LOGR_NMSGMASK			1023
2411fcced4cSJordan Brown #define	LOGR_MAXMSGLEN			800
2421fcced4cSJordan Brown 
2431fcced4cSJordan Brown typedef struct logr_entry {
2441fcced4cSJordan Brown 	struct timeval	le_timestamp;			/* Time of log entry */
2451fcced4cSJordan Brown 	int		le_pri;				/* Message priority */
2461fcced4cSJordan Brown 	char		le_hostname[MAXHOSTNAMELEN];	/* Log hostname */
2471fcced4cSJordan Brown 	char		le_msg[LOGR_MAXMSGLEN];		/* Log message text */
2481fcced4cSJordan Brown } logr_entry_t;
2491fcced4cSJordan Brown 
2501fcced4cSJordan Brown typedef struct logr_info {
2511fcced4cSJordan Brown 	logr_entry_t	li_entry[LOGR_NMSGMASK+1];	/* Array of log entry */
2521fcced4cSJordan Brown 	int		li_idx;				/* Index */
2531fcced4cSJordan Brown } logr_info_t;
2541fcced4cSJordan Brown 
2551fcced4cSJordan Brown typedef struct logr_read_data {
2561fcced4cSJordan Brown 	int		rd_tot_recnum;		/* Total no. of record read */
2571fcced4cSJordan Brown 	int		rd_last_sentrec;	/* Last sentence read */
2581fcced4cSJordan Brown 	char		rd_first_read;		/* First sentence read */
2591fcced4cSJordan Brown 	logr_info_t	*rd_log;		/* Log information read */
2601fcced4cSJordan Brown } logr_read_data_t;
2611fcced4cSJordan Brown 
2621fcced4cSJordan Brown /* This structure provides the context for eventlog calls from clients. */
2631fcced4cSJordan Brown typedef struct logr_context {
2641fcced4cSJordan Brown 	logr_read_data_t *lc_cached_read_data;
2651fcced4cSJordan Brown 	char *lc_source_name;
2661fcced4cSJordan Brown } logr_context_t;
2671fcced4cSJordan Brown 
2681fcced4cSJordan Brown void logr_init(void);
2691fcced4cSJordan Brown void logr_fini(void);
2701fcced4cSJordan Brown boolean_t logr_is_supported(char *);
2711fcced4cSJordan Brown int logr_get_snapshot(logr_context_t *);
2721fcced4cSJordan Brown 
2739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* User and Group quotas */
2749fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t smb_quota_query(smb_quota_query_t *, smb_quota_response_t *);
2759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t smb_quota_set(smb_quota_set_t *);
2769fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void smb_quota_free(smb_quota_response_t *);
2779fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
2789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States uint32_t dfs_get_referrals(const char *, dfs_reftype_t, dfs_info_t *);
2799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States void dfs_info_free(dfs_info_t *);
2809fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 
281fd9ee8b5Sjoyce mcintosh /*
282fd9ee8b5Sjoyce mcintosh  * The spoolss installable copyfile API.
283fd9ee8b5Sjoyce mcintosh  */
284fd9ee8b5Sjoyce mcintosh typedef void (*spoolss_copyfile_t)(smb_inaddr_t *, char *, char *, char *);
285fd9ee8b5Sjoyce mcintosh void spoolss_register_copyfile(spoolss_copyfile_t);
286cb174861Sjoyce mcintosh 
287da6c28aaSamw #ifdef	__cplusplus
288da6c28aaSamw }
289da6c28aaSamw #endif
290da6c28aaSamw 
291da6c28aaSamw #endif	/* _LIBMLSVC_H */
292