1da6c28aamw/*
2da6c28aamw * CDDL HEADER START
3da6c28aamw *
4da6c28aamw * The contents of this file are subject to the terms of the
5da6c28aamw * Common Development and Distribution License (the "License").
6da6c28aamw * You may not use this file except in compliance with the License.
7da6c28aamw *
8da6c28aamw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aamw * or http://www.opensolaris.org/os/licensing.
10da6c28aamw * See the License for the specific language governing permissions
11da6c28aamw * and limitations under the License.
12da6c28aamw *
13da6c28aamw * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aamw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aamw * If applicable, add the following below this CDDL HEADER, with the
16da6c28aamw * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aamw * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aamw *
19da6c28aamw * CDDL HEADER END
20da6c28aamw */
21da6c28aamw/*
22c586600Keyur Desai * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
2368b2bbfGordon Ross * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
24da6c28aamw */
25da6c28aamw
26da6c28aamw#ifndef	_SMBSRV_SMB_XDR_H
27da6c28aamw#define	_SMBSRV_SMB_XDR_H
28da6c28aamw
29da6c28aamw#ifdef	__cplusplus
30da6c28aamwextern "C" {
31da6c28aamw#endif
32da6c28aamw
33da6c28aamw#include <rpc/xdr.h>
34da6c28aamw#include <sys/param.h>
359fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States#include <sys/avl.h>
36b819ceaGordon Ross#include <sys/list.h>
373299f39Gordon Ross#include <smb/wintypes.h>
38fe1c642Bill Krier#include <smbsrv/smb_sid.h>
397f667e7jose borrego#include <smbsrv/smbinfo.h>
401fcced4Jordan Brown#include <smbsrv/smb_ioctl.h>
419fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States#include <smbsrv/smb_sid.h>
42148c5f4Alan Wright#include <smbsrv/smb_share.h>
439fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States#include <smbsrv/smb_dfs.h>
44da6c28aamw
45b819ceaGordon Ross#if defined(_KERNEL) || defined(_FAKE_KERNEL)
46b819ceaGordon Ross#include <sys/sysmacros.h>
47da6c28aamw#define	xdr_int8_t	xdr_char
48da6c28aamw#define	xdr_uint8_t	xdr_u_char
49da6c28aamw#define	xdr_int16_t	xdr_short
50da6c28aamw#define	xdr_uint16_t	xdr_u_short
51b819ceaGordon Ross#else /* _KERNEL */
52b819ceaGordon Ross#include <stddef.h>	/* offsetof */
53da6c28aamw#endif /* _KERNEL */
54da6c28aamw
55a90cf9fGordon Ross/*
56a90cf9fGordon Ross * null-terminated string
57a90cf9fGordon Ross * See also: smb_string_xdr()
58a90cf9fGordon Ross */
599fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statestypedef struct smb_string {
60da6c28aamw	char *buf;
619fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States} smb_string_t;
62da6c28aamw
63b819ceaGordon Rossstruct smb_buf32;
64da6c28aamw
6568b2bbfGordon Ross/*
6668b2bbfGordon Ross * Initial message on server named pipes.
6768b2bbfGordon Ross * Followed by smb_netuserinfo
6868b2bbfGordon Ross */
6968b2bbfGordon Rosstypedef struct smb_pipehdr {
7068b2bbfGordon Ross	uint32_t ph_magic;
7168b2bbfGordon Ross	uint32_t ph_uilen;
7268b2bbfGordon Ross} smb_pipehdr_t;
7368b2bbfGordon Ross
7468b2bbfGordon Ross#define	SMB_PIPE_HDR_MAGIC	0x50495045	/* PIPE */
7568b2bbfGordon Ross
7668b2bbfGordon Ross/*
7768b2bbfGordon Ross * Maximum message size for SMB named pipes.
7868b2bbfGordon Ross * Should be less than PIPE_BUF (5120).
7968b2bbfGordon Ross * Use the same value Windows does.
8068b2bbfGordon Ross */
8168b2bbfGordon Ross#define	SMB_PIPE_MAX_MSGSIZE	4280
823db3f65amw
83da6c28aamw/*
8468b2bbfGordon Ross * Door up-call stuff shared with smbd
85da6c28aamw */
863db3f65amw
879fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States#define	SMB_DOOR_HDR_MAGIC	0x444F4F52	/* DOOR */
889fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States
899fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States/*
909fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * Door header flags.
919fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States */
929fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States#define	SMB_DF_ASYNC		0x00000001	/* Asynchronous call */
939fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States#define	SMB_DF_SYSSPACE		0x00000002	/* Called from the kernel */
949fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States#define	SMB_DF_USERSPACE	0x00000004	/* Called from user space */
95b819ceaGordon Ross#define	SMB_DF_FAKE_KERNEL	0x00000008	/* Called from fake kernel */
969fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States
979fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States/*
989fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * Header for door calls.  The op codes and return codes are defined
999fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * in smb_door.h.  The header is here to make it available to XDR.
1009fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States *
1019fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * fid		For opipe: the pipe identifier.
1029fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * op		The door operation being invoked.
1039fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * txid		Unique transaction id for the current door call.
1049fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * datalen	Bytes of data following the header (excludes the header).
1059fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * resid	For opipe: the number of bytes remaining in the server.
1069fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * door_rc	Return code provided by the door server.
1079fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * status	A pass-through status provided by the door operation.
108a90cf9fGordon Ross *
109a90cf9fGordon Ross * See also: smb_doorhdr_xdr()
1109fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States */
1119fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statestypedef struct smb_doorhdr {
1129fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t dh_magic;
1139fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t dh_flags;
1149fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t dh_fid;
1159fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t dh_op;
1169fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t dh_txid;
1179fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t dh_datalen;
1189fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t dh_resid;
1199fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t dh_door_rc;
1209fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t dh_status;
1219fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States} smb_doorhdr_t;
1223db3f65amw
123a90cf9fGordon Ross/*
124a90cf9fGordon Ross * Information about the client of a named pipe, provided by smbsrv
125a90cf9fGordon Ross * to the server side of the named pipe (the RPC service).
126a90cf9fGordon Ross * See also: smb_netuserinfo_xdr()
127a90cf9fGordon Ross */
1281fcced4Jordan Browntypedef struct smb_netuserinfo {
1291fcced4Jordan Brown	uint64_t	ui_session_id;
1301fcced4Jordan Brown	uint16_t	ui_domain_len;
1311fcced4Jordan Brown	char		*ui_domain;
1321fcced4Jordan Brown	uint16_t	ui_account_len;
1331fcced4Jordan Brown	char		*ui_account;
134c586600Keyur Desai	uid_t		ui_posix_uid;
1351fcced4Jordan Brown	uint16_t	ui_workstation_len;
1361fcced4Jordan Brown	char		*ui_workstation;
1371fcced4Jordan Brown	smb_inaddr_t	ui_ipaddr;
1381fcced4Jordan Brown	int32_t		ui_native_os;
1391fcced4Jordan Brown	int64_t		ui_logon_time;
1401fcced4Jordan Brown	uint32_t	ui_numopens;
1411fcced4Jordan Brown	uint32_t	ui_flags;
1421fcced4Jordan Brown} smb_netuserinfo_t;
1431fcced4Jordan Brown
1441fcced4Jordan Browntypedef struct smb_opennum {
1451fcced4Jordan Brown	uint32_t	open_users;
1461fcced4Jordan Brown	uint32_t	open_trees;
1471fcced4Jordan Brown	uint32_t	open_files;
1481fcced4Jordan Brown	uint32_t	qualtype;
1491fcced4Jordan Brown	char		qualifier[MAXNAMELEN];
1501fcced4Jordan Brown} smb_opennum_t;
1511fcced4Jordan Brown
152a90cf9fGordon Ross/*
153a90cf9fGordon Ross * SMB (internal) representation of a tree connection (etc.)
154a90cf9fGordon Ross * See also: smb_netconnectinfo_xdr()
155a90cf9fGordon Ross */
1561fcced4Jordan Browntypedef struct smb_netconnectinfo {
1571fcced4Jordan Brown	uint32_t	ci_id;
1581fcced4Jordan Brown	uint32_t	ci_type;
1591fcced4Jordan Brown	uint32_t	ci_numopens;
1601fcced4Jordan Brown	uint32_t	ci_numusers;
1611fcced4Jordan Brown	uint32_t	ci_time;
1621fcced4Jordan Brown	uint32_t	ci_namelen;
1631fcced4Jordan Brown	uint32_t	ci_sharelen;
1641fcced4Jordan Brown	char		*ci_username;
1651fcced4Jordan Brown	char		*ci_share;
1661fcced4Jordan Brown} smb_netconnectinfo_t;
1671fcced4Jordan Brown
168a90cf9fGordon Ross/*
169a90cf9fGordon Ross * SMB (internal) representation of an open file.
170a90cf9fGordon Ross * See also: smb_netfileinfo_xdr()
171a90cf9fGordon Ross */
1721fcced4Jordan Browntypedef struct smb_netfileinfo {
1731fcced4Jordan Brown	uint16_t	fi_fid;
1741fcced4Jordan Brown	uint32_t	fi_uniqid;
1751fcced4Jordan Brown	uint32_t	fi_permissions;
1761fcced4Jordan Brown	uint32_t	fi_numlocks;
1771fcced4Jordan Brown	uint32_t	fi_pathlen;
1781fcced4Jordan Brown	uint32_t	fi_namelen;
1791fcced4Jordan Brown	char		*fi_path;
1801fcced4Jordan Brown	char		*fi_username;
1811fcced4Jordan Brown} smb_netfileinfo_t;
1821fcced4Jordan Brown
1831fcced4Jordan Browntypedef struct smb_netsvcitem {
1841fcced4Jordan Brown	list_node_t	nsi_lnd;
1851fcced4Jordan Brown	union {
1861fcced4Jordan Brown		smb_netuserinfo_t	nsi_user;
1871fcced4Jordan Brown		smb_netconnectinfo_t	nsi_tree;
1881fcced4Jordan Brown		smb_netfileinfo_t	nsi_ofile;
1891fcced4Jordan Brown	} nsi_un;
1901fcced4Jordan Brown} smb_netsvcitem_t;
1911fcced4Jordan Brown
1921fcced4Jordan Browntypedef struct smb_netsvc {
1931fcced4Jordan Brown	list_t			ns_list;
1941fcced4Jordan Brown	smb_netsvcitem_t	*ns_items;
1951fcced4Jordan Brown	smb_ioc_svcenum_t	*ns_ioc;
1961fcced4Jordan Brown	uint32_t		ns_ioclen;
1971fcced4Jordan Brown} smb_netsvc_t;
198da6c28aamw
199da6c28aamw
200b819ceaGordon Rossbool_t smb_buf32_xdr(XDR *, struct smb_buf32 *);
2019fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statesbool_t smb_string_xdr(XDR *, smb_string_t *);
2029fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statesbool_t smb_inaddr_xdr(XDR *, smb_inaddr_t *);
2039fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States
2049fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statesconst char *smb_doorhdr_opname(uint32_t);
2059fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statesint smb_doorhdr_encode(smb_doorhdr_t *, uint8_t *, uint32_t);
2069fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statesint smb_doorhdr_decode(smb_doorhdr_t *, uint8_t *, uint32_t);
2079fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statesbool_t smb_doorhdr_xdr(XDR *xdrs, smb_doorhdr_t *objp);
2081fcced4Jordan Brownint smb_netuserinfo_encode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
2091fcced4Jordan Brownint smb_netuserinfo_decode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
2101fcced4Jordan Brownbool_t smb_netuserinfo_xdr(XDR *, smb_netuserinfo_t *);
2111fcced4Jordan Brownint smb_netconnectinfo_encode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
21229bd288Alan Wright    uint_t *);
2131fcced4Jordan Brownint smb_netconnectinfo_decode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
21429bd288Alan Wright    uint_t *);
2151fcced4Jordan Brownbool_t smb_netconnectinfo_xdr(XDR *, smb_netconnectinfo_t *);
2161fcced4Jordan Brownint smb_netfileinfo_encode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
2171fcced4Jordan Brownint smb_netfileinfo_decode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
2181fcced4Jordan Brownbool_t smb_netfileinfo_xdr(XDR *, smb_netfileinfo_t *);
2191fcced4Jordan Brown
220fe1c642Bill Kriertypedef uint16_t sid_type_t;
221fe1c642Bill Krier
222fe1c642Bill Kriertypedef struct lsa_account {
223fe1c642Bill Krier	ntstatus_t	a_status;
224fe1c642Bill Krier	sid_type_t	a_sidtype;
225fe1c642Bill Krier	char		a_domain[MAXNAMELEN];
226fe1c642Bill Krier	char		a_name[MAXNAMELEN];
227fe1c642Bill Krier	char		a_sid[SMB_SID_STRSZ];
228fe1c642Bill Krier} lsa_account_t;
229fe1c642Bill Krier
230fe1c642Bill Krierint lsa_account_encode(lsa_account_t *, uint8_t *, uint32_t);
231fe1c642Bill Krierint lsa_account_decode(lsa_account_t *, uint8_t *, uint32_t);
232fe1c642Bill Krierbool_t lsa_account_xdr(XDR *, lsa_account_t *);
233fe1c642Bill Krier
23489dc44cjose borrego/*
23589dc44cjose borrego * VSS Door Structures
23689dc44cjose borrego */
23789dc44cjose borrego#define	SMB_VSS_GMT_SIZE sizeof ("@GMT-yyyy.mm.dd-hh.mm.ss")
23889dc44cjose borrego
239a90cf9fGordon Ross/*
240a90cf9fGordon Ross * Args for enumerating "previous versions".
241a90cf9fGordon Ross * See also: smb_gmttoken_query_xdr()
242a90cf9fGordon Ross */
2439fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statestypedef struct smb_gmttoken_query {
2449fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t	gtq_count;
2459fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	char		*gtq_path;
2469fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States} smb_gmttoken_query_t;
24789dc44cjose borrego
248a90cf9fGordon Ross/*
249a90cf9fGordon Ross * Part of response for enumerating "previous versions".
250a90cf9fGordon Ross * See also: smb_gmttoken_xdr()
251a90cf9fGordon Ross */
2529fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statestypedef char *smb_gmttoken_t;
25389dc44cjose borrego
254a90cf9fGordon Ross/*
255a90cf9fGordon Ross * Response for enumerating "previous versions".
256a90cf9fGordon Ross * See also: smb_gmttoken_response_xdr()
257a90cf9fGordon Ross */
2589fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statestypedef struct smb_gmttoken_response {
2599fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	uint32_t gtr_count;
26089dc44cjose borrego	struct {
2619fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States		uint_t		gtr_gmttokens_len;
2629fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States		smb_gmttoken_t	*gtr_gmttokens_val;
2639fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	} gtr_gmttokens;
2649fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States} smb_gmttoken_response_t;
2659fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States
266a90cf9fGordon Ross/*
267a90cf9fGordon Ross * Args to lookup "previous versions" during open.
268a90cf9fGordon Ross * See also: smb_gmttoken_snapname_xdr()
269a90cf9fGordon Ross */
2709fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statestypedef struct smb_gmttoken_snapname {
2719fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	char	*gts_path;
2729fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	char	*gts_gmttoken;
273a90cf9fGordon Ross	uint64_t gts_toktime; /* seconds */
2749fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States} smb_gmttoken_snapname_t;
2759fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States
2769fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statesbool_t smb_gmttoken_query_xdr(XDR *, smb_gmttoken_query_t *);
2779fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statesbool_t smb_gmttoken_response_xdr(XDR *, smb_gmttoken_response_t *);
2789fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statesbool_t smb_gmttoken_snapname_xdr(XDR *, smb_gmttoken_snapname_t *);
2799fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States
2809fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States/*
2819fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * User and Group Quotas
2829fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States *
2839fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * SMB User and Group quota values of SMB_QUOTA_UNLIMITED mean
2849fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States * No Limit. This maps to 0 (none) on ZFS.
2859fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States */
2869fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States#define	SMB_QUOTA_UNLIMITED		0xFFFFFFFFFFFFFFFF
2879fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States
288a90cf9fGordon Ross/*
289a90cf9fGordon Ross * SMB (internal) representation of a quota response
290a90cf9fGordon Ross * See also: smb_quota_xdr()
291a90cf9fGordon Ross */
2929fb67eaafshin salek ardakani - Sun Microsystems - Irvine United Statestypedef struct smb_quota {
2939fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	list_node_t q_list_node;
2949fb67eaafshin salek ardakani - Sun Microsystems - Irvine United States	char q_sidstr[SMB_SID_STRSZ];
295