summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/smbsrv/mlsvc.h
blob: a85066fc9ff70e8090d9f49f035efdba5d0bd8ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _SMBSRV_MLSVC_H
#define	_SMBSRV_MLSVC_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

/*
 * MLSVC RPC layer public interface definitions.
 */

#include <sys/param.h>
#include <sys/uio.h>
#include <sys/ksynch.h>

#include <smbsrv/wintypes.h>
#include <smbsrv/ntsid.h>

#include <smbsrv/smb_winpipe.h>
#include <smbsrv/smb_xdr.h>


#ifdef __cplusplus
extern "C" {
#endif

/*
 * RPC strings
 *
 * DCE RPC strings (CAE section 14.3.4) are represented as varying or
 * varying and conformant one-dimensional arrays. Characters can be
 * single-byte or multi-byte as long as all characters conform to a
 * fixed element size, i.e. UCS-2 is okay but UTF-8 is not a valid
 * DCE RPC string format. The string is terminated by a null character
 * of the appropriate element size.
 *
 * MSRPC strings are always varying and conformant format and not null
 * terminated. This format uses the size_is, first_is and length_is
 * attributes (CAE section 4.2.18).
 *
 *	typedef struct mlrpc_string {
 *		DWORD size_is;
 *		DWORD first_is;
 *		DWORD length_is;
 *		wchar_t string[ANY_SIZE_ARRAY];
 *  } mlrpc_string_t;
 *
 * The size_is attribute is used to specify the number of data elements
 * in each dimension of an array.
 *
 * The first_is attribute is used to define the lower bound for
 * significant elements in each dimension of an array. For strings
 * this is always 0.
 *
 * The length_is attribute is used to define the number of significant
 * elements in each dimension of an array. For strings this is typically
 * the same as size_is. Although it might be (size_is - 1) if the string
 * is null terminated.
 *
 * In MSRPC, Unicode strings are not null terminated. This means
 * that the recipient has to manually null-terminate the string after
 * it has been unmarshalled. Note that there is often a wide-char pad
 * following a string. Although the padding sometimes contains zero,
 * it's not guaranteed.
 *
 *   4 bytes   4 bytes   4 bytes  2bytes 2bytes 2bytes 2bytes
 * +---------+---------+---------+------+------+------+------+
 * |size_is  |first_is |length_is| char | char | char | char |
 * +---------+---------+---------+------+------+------+------+
 *
 * The problem is that some strings are null terminated. This seems
 * to conflict with the statement above that Unicode strings are not
 * null terminated, which may be a historical thing from earlier
 * implementations or it may be that different services do different
 * things. So there is an additional string wrapper with two more
 * fields used in some RPC structures as shown below (LPTSTR is
 * automatically converted to mlrpc_string by the NDR marshalling).
 *
 * typedef struct ms_string {
 *		WORD length;
 *		WORD maxlen;
 *		LPTSTR str;
 * } ms_string_t;
 *
 * Here, length is the array length in bytes excluding any terminating
 * null bytes and maxlen is the array length in bytes including null
 * terminator bytes.
 */
typedef struct mlsvc_string {
	WORD length;
	WORD maxlen;
	LPTSTR str;
} mlsvc_string_t;

/*
 * The maximum number of domains (NT limit).
 */
#define	MLSVC_DOMAIN_MAX		32

/*
 * Some buffer size limits. I don't know if these are definitive
 * limits for NT but these numbers appear in various places.
 */
#define	MLSVC_DOMAIN_NAME_MAX		32
#define	MLSVC_ACCOUNT_NAME_MAX		32
#define	MLSVC_CLIENT_NAME_MAX		48

/* 32-byte machine account password (null-terminated) */
#define	MLSVC_MACHINE_ACCT_PASSWD_MAX	32 + 1

/*
 * Status code returned from enumeration RPCs to indicate
 * that the server has no more data. Normally returned at
 * severity level ERROR_SEVERITY_WARNING.
 */
#define	MLSVC_NO_MORE_DATA		0x1A

#define	MLSVC_ANON_USER			"IPC$"

char *mlsvc_ipc_name(int ipc_type, char *username);

/*
 * Passthrough negotiation and authentication interface.
 *
 * NT supports two forms of password: a Lanman (case-insensitive)
 * password and an NT (case-sensitive) password. If either of the
 * passwords is not available its pointer and length should be set
 * to zero. The session key and vc number are required to validate
 * the encrypted passwords.
 */

void mlsvc_nt_password_hash(char *result, char *password);
int mlsvc_encrypt_nt_password(char *password, char *key, int keylen, char *out,
    int outmax);
DWORD mlsvc_join(char *server, char *domain, char *username, char *password);

/*
 * RPC request processing interface (mlsvc_server.c).
 */
#define	MLSVC_MAX_IOVEC			512

typedef struct mlrpc_frag {
	struct mlrpc_frag *next;
	struct mbuf *mhead;
	uint32_t length;
} mlrpc_frag_t;

typedef struct mlsvc_stream {
	mlrpc_frag_t *head;
	mlrpc_frag_t *tail;
	mlrpc_frag_t *pending;
	unsigned int nfrag;
	struct uio uio;
	struct iovec iovec[MLSVC_MAX_IOVEC];
} mlsvc_stream_t;

typedef struct mlsvc_pipe {
	kmutex_t mutex;
	kcondvar_t cv;
	uint32_t busy;
	uint32_t fid;
	char *pipe_name;
	mlsvc_stream_t input;
	uchar_t *output;
	int32_t outlen;
} mlsvc_pipe_t;

struct mlsvc_rpc_context *mlrpc_process(int, smb_dr_user_ctx_t *);
struct mlsvc_rpc_context *mlrpc_lookup(int fid);
void mlrpc_release(int);
void mlsvc_rpc_report_status(int opnum, DWORD status);

#ifdef __cplusplus
}
#endif


#endif /* _SMBSRV_MLSVC_H */