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 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SMBSRV_MLSVC_H 27 #define _SMBSRV_MLSVC_H 28 29 #pragma ident "@(#)mlsvc.h 1.3 08/01/04 SMI" 30 31 /* 32 * MLSVC RPC layer public interface definitions. 33 */ 34 35 #include <sys/param.h> 36 #include <sys/uio.h> 37 #include <sys/ksynch.h> 38 39 #include <smbsrv/wintypes.h> 40 #include <smbsrv/ntsid.h> 41 42 #include <smbsrv/smb_winpipe.h> 43 #include <smbsrv/smb_xdr.h> 44 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /* 51 * RPC strings 52 * 53 * DCE RPC strings (CAE section 14.3.4) are represented as varying or 54 * varying and conformant one-dimensional arrays. Characters can be 55 * single-byte or multi-byte as long as all characters conform to a 56 * fixed element size, i.e. UCS-2 is okay but UTF-8 is not a valid 57 * DCE RPC string format. The string is terminated by a null character 58 * of the appropriate element size. 59 * 60 * MSRPC strings are always varying and conformant format and not null 61 * terminated. This format uses the size_is, first_is and length_is 62 * attributes (CAE section 4.2.18). 63 * 64 * typedef struct mlrpc_string { 65 * DWORD size_is; 66 * DWORD first_is; 67 * DWORD length_is; 68 * wchar_t string[ANY_SIZE_ARRAY]; 69 * } mlrpc_string_t; 70 * 71 * The size_is attribute is used to specify the number of data elements 72 * in each dimension of an array. 73 * 74 * The first_is attribute is used to define the lower bound for 75 * significant elements in each dimension of an array. For strings 76 * this is always 0. 77 * 78 * The length_is attribute is used to define the number of significant 79 * elements in each dimension of an array. For strings this is typically 80 * the same as size_is. Although it might be (size_is - 1) if the string 81 * is null terminated. 82 * 83 * In MSRPC, Unicode strings are not null terminated. This means 84 * that the recipient has to manually null-terminate the string after 85 * it has been unmarshalled. Note that there is often a wide-char pad 86 * following a string. Although the padding sometimes contains zero, 87 * it's not guaranteed. 88 * 89 * 4 bytes 4 bytes 4 bytes 2bytes 2bytes 2bytes 2bytes 90 * +---------+---------+---------+------+------+------+------+ 91 * |size_is |first_is |length_is| char | char | char | char | 92 * +---------+---------+---------+------+------+------+------+ 93 * 94 * The problem is that some strings are null terminated. This seems 95 * to conflict with the statement above that Unicode strings are not 96 * null terminated, which may be a historical thing from earlier 97 * implementations or it may be that different services do different 98 * things. So there is an additional string wrapper with two more 99 * fields used in some RPC structures as shown below (LPTSTR is 100 * automatically converted to mlrpc_string by the NDR marshalling). 101 * 102 * typedef struct ms_string { 103 * WORD length; 104 * WORD maxlen; 105 * LPTSTR str; 106 * } ms_string_t; 107 * 108 * Here, length is the array length in bytes excluding any terminating 109 * null bytes and maxlen is the array length in bytes including null 110 * terminator bytes. 111 */ 112 typedef struct mlsvc_string { 113 WORD length; 114 WORD maxlen; 115 LPTSTR str; 116 } mlsvc_string_t; 117 118 /* 119 * The maximum number of domains (NT limit). 120 */ 121 #define MLSVC_DOMAIN_MAX 32 122 123 /* 124 * Some buffer size limits. I don't know if these are definitive 125 * limits for NT but these numbers appear in various places. 126 */ 127 #define MLSVC_DOMAIN_NAME_MAX 32 128 #define MLSVC_ACCOUNT_NAME_MAX 32 129 #define MLSVC_CLIENT_NAME_MAX 48 130 131 /* 32-byte machine account password (null-terminated) */ 132 #define MLSVC_MACHINE_ACCT_PASSWD_MAX 32 + 1 133 134 /* 135 * Status code returned from enumeration RPCs to indicate 136 * that the server has no more data. Normally returned at 137 * severity level ERROR_SEVERITY_WARNING. 138 */ 139 #define MLSVC_NO_MORE_DATA 0x1A 140 141 #define MLSVC_ANON_USER "IPC$" 142 143 char *mlsvc_ipc_name(int ipc_type, char *username); 144 145 /* 146 * Passthrough negotiation and authentication interface. 147 * 148 * NT supports two forms of password: a Lanman (case-insensitive) 149 * password and an NT (case-sensitive) password. If either of the 150 * passwords is not available its pointer and length should be set 151 * to zero. The session key and vc number are required to validate 152 * the encrypted passwords. 153 */ 154 155 void mlsvc_nt_password_hash(char *result, char *password); 156 int mlsvc_encrypt_nt_password(char *password, char *key, int keylen, char *out, 157 int outmax); 158 DWORD mlsvc_join(char *server, char *domain, char *username, char *password); 159 160 /* 161 * RPC request processing interface (mlsvc_server.c). 162 */ 163 #define MLSVC_MAX_IOVEC 512 164 165 typedef struct mlrpc_frag { 166 struct mlrpc_frag *next; 167 struct mbuf *mhead; 168 uint32_t length; 169 } mlrpc_frag_t; 170 171 typedef struct mlsvc_stream { 172 mlrpc_frag_t *head; 173 mlrpc_frag_t *tail; 174 mlrpc_frag_t *pending; 175 unsigned int nfrag; 176 struct uio uio; 177 struct iovec iovec[MLSVC_MAX_IOVEC]; 178 } mlsvc_stream_t; 179 180 typedef struct mlsvc_pipe { 181 kmutex_t mutex; 182 kcondvar_t cv; 183 uint32_t busy; 184 uint32_t fid; 185 char *pipe_name; 186 mlsvc_stream_t input; 187 uchar_t *output; 188 int32_t outlen; 189 } mlsvc_pipe_t; 190 191 struct mlsvc_rpc_context *mlrpc_process(int, smb_dr_user_ctx_t *); 192 struct mlsvc_rpc_context *mlrpc_lookup(int fid); 193 void mlrpc_release(int); 194 void mlsvc_rpc_report_status(int opnum, DWORD status); 195 196 #ifdef __cplusplus 197 } 198 #endif 199 200 201 #endif /* _SMBSRV_MLSVC_H */ 202