Print this page
1575 untangle libmlrpc ... (smbsrv)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/common/smbsrv/smb_door_legacy.c
+++ new/usr/src/common/smbsrv/smb_door_legacy.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 *
25 25 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
26 26 */
27 27
28 28 /*
29 29 * Legacy encode/decode routines for door clients and servers.
30 30 */
31 31
↓ open down ↓ |
31 lines elided |
↑ open up ↑ |
32 32 #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
33 33 #include <errno.h>
34 34 #include <string.h>
35 35 #include <strings.h>
36 36 #else
37 37 #include <sys/types.h>
38 38 #include <sys/sunddi.h>
39 39 #include <sys/errno.h>
40 40 #endif
41 41
42 -#include <smbsrv/wintypes.h>
42 +#include <smb/wintypes.h>
43 43 #include <smbsrv/smb_share.h>
44 44 #include <smbsrv/smb_door.h>
45 45 #include <smbsrv/alloc.h>
46 46 #include <smbsrv/smbinfo.h>
47 47
48 48 smb_dr_ctx_t *
49 49 smb_dr_decode_start(char *ptr, int size)
50 50 {
51 51 smb_dr_ctx_t *ctx = MEM_MALLOC("CommonDoor", sizeof (smb_dr_ctx_t));
52 52 if (ctx) {
53 53 ctx->start_ptr = ctx->ptr = ptr;
54 54 ctx->end_ptr = ptr + size;
55 55 ctx->status = 0;
56 56 }
57 57 return (ctx);
58 58 }
59 59
60 60 int
61 61 smb_dr_decode_finish(smb_dr_ctx_t *ctx)
62 62 {
63 63 int status = ctx->status;
64 64 if (status == 0 && ctx->ptr != ctx->end_ptr)
65 65 status = ENOTEMPTY;
66 66
67 67 MEM_FREE("CommonDoor", ctx);
68 68 return (status);
69 69 }
70 70
71 71 smb_dr_ctx_t *
72 72 smb_dr_encode_start(char *ptr, int size)
73 73 {
74 74 smb_dr_ctx_t *ctx = MEM_MALLOC("CommonDoor", sizeof (smb_dr_ctx_t));
75 75 if (ctx) {
76 76 ctx->start_ptr = ctx->ptr = ptr;
77 77 ctx->end_ptr = ptr + size;
78 78 ctx->status = 0;
79 79 }
80 80 return (ctx);
81 81 }
82 82
83 83 int
84 84 smb_dr_encode_finish(smb_dr_ctx_t *ctx, unsigned int *used)
85 85 {
86 86 int status = ctx->status;
87 87 if (status == 0) {
88 88 if (ctx->ptr < ctx->end_ptr) {
89 89 /*LINTED E_PTRDIFF_OVERFLOW*/
90 90 *used = ctx->ptr - ctx->start_ptr;
91 91 } else {
92 92 status = ENOSPC;
93 93 }
94 94 }
95 95
96 96 MEM_FREE("CommonDoor", ctx);
97 97 return (status);
98 98 }
99 99
100 100 DWORD
101 101 smb_dr_get_dword(smb_dr_ctx_t *ctx)
102 102 {
103 103 DWORD num = 0;
104 104 if (ctx->status == 0) {
105 105 if (ctx->ptr + sizeof (DWORD) <= ctx->end_ptr) {
106 106 (void) memcpy(&num, ctx->ptr, sizeof (DWORD));
107 107 ctx->ptr += sizeof (DWORD);
108 108 } else {
109 109 ctx->status = ENOSPC;
110 110 }
111 111 }
112 112 return (num);
113 113 }
114 114
115 115 int32_t
116 116 smb_dr_get_int32(smb_dr_ctx_t *ctx)
117 117 {
118 118 int32_t num = 0;
119 119 if (ctx->status == 0) {
120 120 if (ctx->ptr + sizeof (int32_t) <= ctx->end_ptr) {
121 121 (void) memcpy(&num, ctx->ptr, sizeof (int32_t));
122 122 ctx->ptr += sizeof (int32_t);
123 123 } else {
124 124 ctx->status = ENOSPC;
125 125 }
126 126 }
127 127 return (num);
128 128 }
129 129
130 130 uint32_t
131 131 smb_dr_get_uint32(smb_dr_ctx_t *ctx)
132 132 {
133 133 return ((uint32_t)smb_dr_get_int32(ctx));
134 134 }
135 135
136 136 char *
137 137 smb_dr_get_string(smb_dr_ctx_t *ctx)
138 138 {
139 139 char *buf = NULL;
140 140 int len = smb_dr_get_int32(ctx);
141 141
142 142 if (ctx->status == 0) {
143 143 if (len == -1)
144 144 return (buf);
145 145
146 146 if (ctx->ptr + len <= ctx->end_ptr) {
147 147 buf = MEM_MALLOC("CommonDoor", len +1);
148 148 if (buf) {
149 149 if (len == 0) {
150 150 (void) strcpy(buf, "");
151 151 } else {
152 152 (void) memcpy(buf, ctx->ptr, len);
153 153 ctx->ptr += len;
154 154 *(buf + len) = '\0';
155 155 }
156 156 } else {
157 157 #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
158 158 ctx->status = errno;
159 159 #else
160 160 ctx->status = ENOMEM;
161 161 #endif
162 162 }
163 163 } else {
164 164 ctx->status = ENOSPC;
165 165 }
166 166 }
167 167 return (buf);
168 168 }
169 169
170 170 void
171 171 smb_dr_put_dword(smb_dr_ctx_t *ctx, DWORD num)
172 172 {
173 173 if (ctx->status == 0) {
174 174 if (ctx->ptr + sizeof (DWORD) <= ctx->end_ptr) {
175 175 (void) memcpy(ctx->ptr, &num, sizeof (DWORD));
176 176 ctx->ptr += sizeof (DWORD);
177 177 } else {
178 178 ctx->status = ENOSPC;
179 179 }
180 180 }
181 181 }
182 182
183 183 void
184 184 smb_dr_put_int32(smb_dr_ctx_t *ctx, int32_t num)
185 185 {
186 186 if (ctx->status == 0) {
187 187 if (ctx->ptr + sizeof (int32_t) <= ctx->end_ptr) {
188 188 (void) memcpy(ctx->ptr, &num, sizeof (int32_t));
189 189 ctx->ptr += sizeof (int32_t);
190 190 } else {
191 191 ctx->status = ENOSPC;
192 192 }
193 193 }
194 194 }
195 195
196 196 void
197 197 smb_dr_put_uint32(smb_dr_ctx_t *ctx, uint32_t num)
198 198 {
199 199 smb_dr_put_int32(ctx, (int32_t)num);
200 200 }
201 201
202 202 void
203 203 smb_dr_put_string(smb_dr_ctx_t *ctx, const char *buf)
204 204 {
205 205 int len;
206 206
207 207 if (!buf)
208 208 len = -1;
209 209 else
210 210 len = strlen(buf);
211 211
212 212 if (ctx->status == 0) {
213 213 smb_dr_put_int32(ctx, len);
214 214 if (len <= 0)
215 215 return;
216 216
217 217 if (ctx->ptr + len <= ctx->end_ptr) {
218 218 (void) memcpy(ctx->ptr, buf, len);
219 219 ctx->ptr += len;
220 220 } else {
221 221 ctx->status = ENOSPC;
222 222 }
223 223 }
224 224 }
225 225
226 226 void
227 227 smb_dr_free_string(char *buf)
228 228 {
229 229 if (buf)
230 230 MEM_FREE("CommonDoor", buf);
231 231 }
232 232
233 233 int64_t
234 234 smb_dr_get_int64(smb_dr_ctx_t *ctx)
235 235 {
236 236 int64_t num = 0;
237 237 if (ctx->status == 0) {
238 238 if (ctx->ptr + sizeof (int64_t) <= ctx->end_ptr) {
239 239 (void) memcpy(&num, ctx->ptr, sizeof (int64_t));
240 240 ctx->ptr += sizeof (int64_t);
241 241 } else {
242 242 ctx->status = ENOSPC;
243 243 }
244 244 }
245 245 return (num);
246 246 }
247 247
248 248 uint64_t
249 249 smb_dr_get_uint64(smb_dr_ctx_t *ctx)
250 250 {
251 251 return ((uint64_t)smb_dr_get_int64(ctx));
252 252 }
253 253
254 254
255 255 void
256 256 smb_dr_put_int64(smb_dr_ctx_t *ctx, int64_t num)
257 257 {
258 258 if (ctx->status == 0) {
259 259 if (ctx->ptr + sizeof (int64_t) <= ctx->end_ptr) {
260 260 (void) memcpy(ctx->ptr, &num, sizeof (int64_t));
261 261 ctx->ptr += sizeof (int64_t);
262 262 } else {
263 263 ctx->status = ENOSPC;
264 264 }
265 265 }
266 266 }
267 267
268 268 void
269 269 smb_dr_put_uint64(smb_dr_ctx_t *ctx, uint64_t num)
270 270 {
271 271 smb_dr_put_int64(ctx, (int64_t)num);
272 272 }
273 273
274 274 void
275 275 smb_dr_put_short(smb_dr_ctx_t *ctx, short num)
276 276 {
277 277 if (ctx->status == 0) {
278 278 if (ctx->ptr + sizeof (short) <= ctx->end_ptr) {
279 279 (void) memcpy(ctx->ptr, &num, sizeof (short));
280 280 ctx->ptr += sizeof (short);
281 281 } else {
282 282 ctx->status = ENOSPC;
283 283 }
284 284 }
285 285 }
286 286
287 287 short
288 288 smb_dr_get_short(smb_dr_ctx_t *ctx)
289 289 {
290 290 short num = 0;
291 291 if (ctx->status == 0) {
292 292 if (ctx->ptr + sizeof (short) <= ctx->end_ptr) {
293 293 (void) memcpy(&num, ctx->ptr, sizeof (short));
294 294 ctx->ptr += sizeof (short);
295 295 } else {
296 296 ctx->status = ENOSPC;
297 297 }
298 298 }
299 299 return (num);
300 300 }
301 301
302 302 void
303 303 smb_dr_put_ushort(smb_dr_ctx_t *ctx, unsigned short num)
304 304 {
305 305 smb_dr_put_short(ctx, (short)num);
306 306 }
307 307
308 308 unsigned short
309 309 smb_dr_get_ushort(smb_dr_ctx_t *ctx)
310 310 {
311 311 return ((unsigned short)smb_dr_get_short(ctx));
312 312 }
313 313
314 314 void
315 315 smb_dr_put_word(smb_dr_ctx_t *ctx, WORD num)
316 316 {
317 317 smb_dr_put_ushort(ctx, num);
318 318 }
319 319
320 320 WORD
321 321 smb_dr_get_word(smb_dr_ctx_t *ctx)
322 322 {
323 323 return (smb_dr_get_ushort(ctx));
324 324 }
325 325
326 326 void
327 327 smb_dr_put_BYTE(smb_dr_ctx_t *ctx, BYTE byte)
328 328 {
329 329 if (ctx->status == 0) {
330 330 if (ctx->ptr + sizeof (BYTE) <= ctx->end_ptr) {
331 331 (void) memcpy(ctx->ptr, &byte, sizeof (BYTE));
332 332 ctx->ptr += sizeof (BYTE);
333 333 } else {
334 334 ctx->status = ENOSPC;
335 335 }
336 336 }
337 337 }
338 338
339 339 BYTE
340 340 smb_dr_get_BYTE(smb_dr_ctx_t *ctx)
341 341 {
342 342 BYTE byte = 0;
343 343 if (ctx->status == 0) {
344 344 if (ctx->ptr + sizeof (BYTE) <= ctx->end_ptr) {
345 345 (void) memcpy(&byte, ctx->ptr, sizeof (BYTE));
346 346 ctx->ptr += sizeof (BYTE);
347 347 } else {
348 348 ctx->status = ENOSPC;
349 349 }
350 350 }
351 351 return (byte);
352 352 }
353 353
354 354 void
355 355 smb_dr_put_buf(smb_dr_ctx_t *ctx, unsigned char *start, int len)
356 356 {
357 357 smb_dr_put_int32(ctx, len);
358 358 if (ctx->status == 0) {
359 359 if (ctx->ptr + len <= ctx->end_ptr) {
360 360 (void) memcpy(ctx->ptr, start, len);
361 361 ctx->ptr += len;
362 362 } else {
363 363 ctx->status = ENOSPC;
364 364 }
365 365 }
366 366 }
367 367
368 368 int
369 369 smb_dr_get_buf(smb_dr_ctx_t *ctx, unsigned char *buf, int bufsize)
370 370 {
371 371 int len = -1;
372 372
373 373 if (!buf)
374 374 return (-1);
375 375
376 376 len = smb_dr_get_int32(ctx);
377 377 if (ctx->status == 0) {
378 378 if (bufsize < len) {
379 379 ctx->status = ENOSPC;
380 380 return (-2);
381 381 }
382 382
383 383 if (ctx->ptr + len <= ctx->end_ptr) {
384 384 (void) memcpy(buf, ctx->ptr, len);
385 385 ctx->ptr += len;
386 386 } else {
387 387 ctx->status = ENOSPC;
388 388 return (-3);
389 389 }
390 390 }
391 391
392 392 return (len);
393 393 }
394 394
395 395 void
396 396 smb_dr_get_share(smb_dr_ctx_t *ctx, smb_share_t *si)
397 397 {
398 398 if (ctx->status == 0) {
399 399 if (smb_dr_get_int32(ctx)) {
400 400 (void) memcpy(si, ctx->ptr, sizeof (smb_share_t));
401 401 ctx->ptr += sizeof (smb_share_t);
402 402 } else {
403 403 bzero(si, sizeof (smb_share_t));
404 404 }
405 405 } else {
406 406 bzero(si, sizeof (smb_share_t));
407 407 }
408 408 }
409 409
410 410 void
411 411 smb_dr_put_share(smb_dr_ctx_t *ctx, smb_share_t *si)
412 412 {
413 413 if (si) {
414 414 smb_dr_put_int32(ctx, 1);
415 415 if (ctx->ptr + sizeof (smb_share_t) <= ctx->end_ptr) {
416 416 (void) memcpy(ctx->ptr, si, sizeof (smb_share_t));
417 417 ctx->ptr += sizeof (smb_share_t);
418 418 } else {
419 419 ctx->status = ENOSPC;
420 420 }
421 421 } else {
422 422 smb_dr_put_int32(ctx, 0);
423 423 }
424 424 }
↓ open down ↓ |
372 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX