2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) James Myers 2003 <myersjj@samba.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 this file implements functions for manipulating the 'struct smbcli_request' structure in libsmb
27 #include "libcli/raw/libcliraw.h"
28 #include "dlinklist.h"
29 #include "lib/events/events.h"
31 /* we over allocate the data buffer to prevent too many realloc calls */
32 #define REQ_OVER_ALLOCATION 0
34 /* assume that a character will not consume more than 3 bytes per char */
35 #define MAX_BYTES_PER_CHAR 3
37 /* destroy a request structure and return final status */
38 NTSTATUS smbcli_request_destroy(struct smbcli_request *req)
42 /* this is the error code we give the application for when a
43 _send() call fails completely */
44 if (!req) return NT_STATUS_UNSUCCESSFUL;
47 /* remove it from the list of pending requests (a null op if
48 its not in the list) */
49 DLIST_REMOVE(req->transport->pending_recv, req);
52 if (req->state == SMBCLI_REQUEST_ERROR &&
53 NT_STATUS_IS_OK(req->status)) {
54 req->status = NT_STATUS_INTERNAL_ERROR;
64 low-level function to setup a request buffer for a non-SMB packet
65 at the transport level
67 struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *transport, uint_t size)
69 struct smbcli_request *req;
71 req = talloc(transport, struct smbcli_request);
77 /* setup the request context */
78 req->state = SMBCLI_REQUEST_INIT;
79 req->transport = transport;
84 /* over allocate by a small amount */
85 req->out.allocated = req->out.size + REQ_OVER_ALLOCATION;
87 req->out.buffer = talloc_size(req, req->out.allocated);
88 if (!req->out.buffer) {
92 SIVAL(req->out.buffer, 0, 0);
99 setup a SMB packet at transport level
101 struct smbcli_request *smbcli_request_setup_transport(struct smbcli_transport *transport,
102 uint8_t command, uint_t wct, uint_t buflen)
104 struct smbcli_request *req;
106 req = smbcli_request_setup_nonsmb(transport, NBT_HDR_SIZE + MIN_SMB_SIZE + wct*2 + buflen);
108 if (!req) return NULL;
110 req->out.hdr = req->out.buffer + NBT_HDR_SIZE;
111 req->out.vwv = req->out.hdr + HDR_VWV;
113 req->out.data = req->out.vwv + VWV(wct) + 2;
114 req->out.data_size = buflen;
115 req->out.ptr = req->out.data;
117 SCVAL(req->out.hdr, HDR_WCT, wct);
118 SSVAL(req->out.vwv, VWV(wct), buflen);
120 memcpy(req->out.hdr, "\377SMB", 4);
121 SCVAL(req->out.hdr,HDR_COM,command);
123 SCVAL(req->out.hdr,HDR_FLG, FLAG_CASELESS_PATHNAMES);
124 SSVAL(req->out.hdr,HDR_FLG2, 0);
126 if (command != SMBtranss && command != SMBtranss2) {
128 req->mid = smbcli_transport_next_mid(transport);
131 /* copy the pid, uid and mid to the request */
132 SSVAL(req->out.hdr, HDR_PID, 0);
133 SSVAL(req->out.hdr, HDR_UID, 0);
134 SSVAL(req->out.hdr, HDR_MID, req->mid);
135 SSVAL(req->out.hdr, HDR_TID,0);
136 SSVAL(req->out.hdr, HDR_PIDHIGH,0);
137 SIVAL(req->out.hdr, HDR_RCLS, 0);
138 memset(req->out.hdr+HDR_SS_FIELD, 0, 10);
144 setup a reply in req->out with the given word count and initial data
145 buffer size. the caller will then fill in the command words and
146 data before calling smbcli_request_send() to send the reply on its
147 way. This interface is used before a session is setup.
149 struct smbcli_request *smbcli_request_setup_session(struct smbcli_session *session,
150 uint8_t command, uint_t wct, uint_t buflen)
152 struct smbcli_request *req;
154 req = smbcli_request_setup_transport(session->transport, command, wct, buflen);
156 if (!req) return NULL;
158 req->session = session;
160 SSVAL(req->out.hdr, HDR_FLG2, session->flags2);
161 SSVAL(req->out.hdr, HDR_PID, session->pid & 0xFFFF);
162 SSVAL(req->out.hdr, HDR_PIDHIGH, session->pid >> 16);
163 SSVAL(req->out.hdr, HDR_UID, session->vuid);
169 setup a request for tree based commands
171 struct smbcli_request *smbcli_request_setup(struct smbcli_tree *tree,
173 uint_t wct, uint_t buflen)
175 struct smbcli_request *req;
177 req = smbcli_request_setup_session(tree->session, command, wct, buflen);
180 SSVAL(req->out.hdr,HDR_TID,tree->tid);
187 grow the allocation of the data buffer portion of a reply
188 packet. Note that as this can reallocate the packet buffer this
189 invalidates any local pointers into the packet.
191 To cope with this req->out.ptr is supplied. This will be updated to
192 point at the same offset into the packet as before this call
194 static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_size)
199 delta = new_size - req->out.data_size;
200 if (delta + req->out.size <= req->out.allocated) {
201 /* it fits in the preallocation */
205 /* we need to realloc */
206 req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION;
207 buf2 = talloc_realloc(req, req->out.buffer, uint8_t, req->out.allocated);
209 smb_panic("out of memory in req_grow_allocation");
212 if (buf2 == req->out.buffer) {
213 /* the malloc library gave us the same pointer */
217 /* update the pointers into the packet */
218 req->out.data = buf2 + PTR_DIFF(req->out.data, req->out.buffer);
219 req->out.ptr = buf2 + PTR_DIFF(req->out.ptr, req->out.buffer);
220 req->out.vwv = buf2 + PTR_DIFF(req->out.vwv, req->out.buffer);
221 req->out.hdr = buf2 + PTR_DIFF(req->out.hdr, req->out.buffer);
223 req->out.buffer = buf2;
228 grow the data buffer portion of a reply packet. Note that as this
229 can reallocate the packet buffer this invalidates any local pointers
232 To cope with this req->out.ptr is supplied. This will be updated to
233 point at the same offset into the packet as before this call
235 static void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size)
239 smbcli_req_grow_allocation(req, new_size);
241 delta = new_size - req->out.data_size;
243 req->out.size += delta;
244 req->out.data_size += delta;
246 /* set the BCC to the new data size */
247 SSVAL(req->out.vwv, VWV(req->out.wct), new_size);
252 setup a chained reply in req->out with the given word count and
253 initial data buffer size.
255 NTSTATUS smbcli_chained_request_setup(struct smbcli_request *req,
257 uint_t wct, uint_t buflen)
259 uint_t new_size = 1 + (wct*2) + 2 + buflen;
261 SSVAL(req->out.vwv, VWV(0), command);
262 SSVAL(req->out.vwv, VWV(1), req->out.size - NBT_HDR_SIZE);
264 smbcli_req_grow_allocation(req, req->out.data_size + new_size);
266 req->out.vwv = req->out.buffer + req->out.size + 1;
267 SCVAL(req->out.vwv, -1, wct);
268 SSVAL(req->out.vwv, VWV(wct), buflen);
270 req->out.size += new_size;
276 aadvance to the next chained reply in a request
278 NTSTATUS smbcli_chained_advance(struct smbcli_request *req)
282 if (CVAL(req->in.vwv, VWV(0)) == SMB_CHAIN_NONE) {
283 return NT_STATUS_NOT_FOUND;
286 buffer = req->in.hdr + SVAL(req->in.vwv, VWV(1));
288 if (buffer + 3 > req->in.buffer + req->in.size) {
289 return NT_STATUS_BUFFER_TOO_SMALL;
292 req->in.vwv = buffer + 1;
293 req->in.wct = CVAL(buffer, 0);
294 if (buffer + 3 + req->in.wct*2 > req->in.buffer + req->in.size) {
295 return NT_STATUS_BUFFER_TOO_SMALL;
297 req->in.data = req->in.vwv + 2 + req->in.wct * 2;
298 req->in.data_size = SVAL(req->in.vwv, VWV(req->in.wct));
300 if (buffer + 3 + req->in.wct*2 + req->in.data_size >
301 req->in.buffer + req->in.size) {
302 return NT_STATUS_BUFFER_TOO_SMALL;
312 BOOL smbcli_request_send(struct smbcli_request *req)
314 if (IVAL(req->out.buffer, 0) == 0) {
315 _smb_setlen(req->out.buffer, req->out.size - NBT_HDR_SIZE);
318 smbcli_request_calculate_sign_mac(req);
320 smbcli_transport_send(req);
327 receive a response to a packet
329 BOOL smbcli_request_receive(struct smbcli_request *req)
331 /* req can be NULL when a send has failed. This eliminates lots of NULL
332 checks in each module */
333 if (!req) return False;
335 /* keep receiving packets until this one is replied to */
336 while (req->state <= SMBCLI_REQUEST_RECV) {
337 if (event_loop_once(req->transport->socket->event.ctx) != 0) {
342 return req->state == SMBCLI_REQUEST_DONE;
347 receive another reply to a request - this is used for requests that
348 have multi-part replies (such as SMBtrans2)
350 BOOL smbcli_request_receive_more(struct smbcli_request *req)
352 req->state = SMBCLI_REQUEST_RECV;
353 DLIST_ADD(req->transport->pending_recv, req);
355 return smbcli_request_receive(req);
360 handle oplock break requests from the server - return True if the request was
363 BOOL smbcli_handle_oplock_break(struct smbcli_transport *transport, uint_t len, const uint8_t *hdr, const uint8_t *vwv)
365 /* we must be very fussy about what we consider an oplock break to avoid
366 matching readbraw replies */
367 if (len != MIN_SMB_SIZE + VWV(8) + NBT_HDR_SIZE ||
368 (CVAL(hdr, HDR_FLG) & FLAG_REPLY) ||
369 CVAL(hdr,HDR_COM) != SMBlockingX ||
370 SVAL(hdr, HDR_MID) != 0xFFFF ||
371 SVAL(vwv,VWV(6)) != 0 ||
372 SVAL(vwv,VWV(7)) != 0) {
376 if (transport->oplock.handler) {
377 uint16_t tid = SVAL(hdr, HDR_TID);
378 uint16_t fnum = SVAL(vwv,VWV(2));
379 uint8_t level = CVAL(vwv,VWV(3)+1);
380 transport->oplock.handler(transport, tid, fnum, level, transport->oplock.private);
387 wait for a reply to be received for a packet that just returns an error
388 code and nothing more
390 NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req)
392 (void) smbcli_request_receive(req);
393 return smbcli_request_destroy(req);
397 /* Return true if the last packet was in error */
398 BOOL smbcli_request_is_error(struct smbcli_request *req)
400 return NT_STATUS_IS_ERR(req->status);
404 append a string into the data portion of the request packet
406 return the number of bytes added to the packet
408 size_t smbcli_req_append_string(struct smbcli_request *req, const char *str, uint_t flags)
412 /* determine string type to use */
413 if (!(flags & (STR_ASCII|STR_UNICODE))) {
414 flags |= (req->transport->negotiate.capabilities & CAP_UNICODE) ? STR_UNICODE : STR_ASCII;
417 len = (strlen(str)+2) * MAX_BYTES_PER_CHAR;
419 smbcli_req_grow_allocation(req, len + req->out.data_size);
421 len = push_string(req->out.data + req->out.data_size, str, len, flags);
423 smbcli_req_grow_data(req, len + req->out.data_size);
430 this is like smbcli_req_append_string but it also return the
431 non-terminated string byte length, which can be less than the number
432 of bytes consumed in the packet for 2 reasons:
434 1) the string in the packet may be null terminated
435 2) the string in the packet may need a 1 byte UCS2 alignment
437 this is used in places where the non-terminated string byte length is
438 placed in the packet as a separate field
440 size_t smbcli_req_append_string_len(struct smbcli_request *req, const char *str, uint_t flags, int *len)
445 /* determine string type to use */
446 if (!(flags & (STR_ASCII|STR_UNICODE))) {
447 flags |= (req->transport->negotiate.capabilities & CAP_UNICODE) ? STR_UNICODE : STR_ASCII;
450 /* see if an alignment byte will be used */
451 if ((flags & STR_UNICODE) && !(flags & STR_NOALIGN)) {
452 diff = ucs2_align(NULL, req->out.data + req->out.data_size, flags);
455 /* do the hard work */
456 ret = smbcli_req_append_string(req, str, flags);
458 /* see if we need to subtract the termination */
459 if (flags & STR_TERMINATE) {
460 diff += (flags & STR_UNICODE) ? 2 : 1;
474 push a string into the data portion of the request packet, growing it if necessary
475 this gets quite tricky - please be very careful to cover all cases when modifying this
477 if dest is NULL, then put the string at the end of the data portion of the packet
479 if dest_len is -1 then no limit applies
481 size_t smbcli_req_append_ascii4(struct smbcli_request *req, const char *str, uint_t flags)
484 smbcli_req_append_bytes(req, (const uint8_t *)"\4", 1);
485 size = smbcli_req_append_string(req, str, flags);
491 push a blob into the data portion of the request packet, growing it if necessary
492 this gets quite tricky - please be very careful to cover all cases when modifying this
494 if dest is NULL, then put the blob at the end of the data portion of the packet
496 size_t smbcli_req_append_blob(struct smbcli_request *req, const DATA_BLOB *blob)
498 smbcli_req_grow_allocation(req, req->out.data_size + blob->length);
499 memcpy(req->out.data + req->out.data_size, blob->data, blob->length);
500 smbcli_req_grow_data(req, req->out.data_size + blob->length);
505 append raw bytes into the data portion of the request packet
506 return the number of bytes added
508 size_t smbcli_req_append_bytes(struct smbcli_request *req, const uint8_t *bytes, size_t byte_len)
510 smbcli_req_grow_allocation(req, byte_len + req->out.data_size);
511 memcpy(req->out.data + req->out.data_size, bytes, byte_len);
512 smbcli_req_grow_data(req, byte_len + req->out.data_size);
517 append variable block (type 5 buffer) into the data portion of the request packet
518 return the number of bytes added
520 size_t smbcli_req_append_var_block(struct smbcli_request *req, const uint8_t *bytes, uint16_t byte_len)
522 smbcli_req_grow_allocation(req, byte_len + 3 + req->out.data_size);
523 SCVAL(req->out.data + req->out.data_size, 0, 5);
524 SSVAL(req->out.data + req->out.data_size, 1, byte_len); /* add field length */
526 memcpy(req->out.data + req->out.data_size + 3, bytes, byte_len);
528 smbcli_req_grow_data(req, byte_len + 3 + req->out.data_size);
534 pull a UCS2 string from a request packet, returning a talloced unix string
536 the string length is limited by the 3 things:
537 - the data size in the request (end of packet)
538 - the passed 'byte_len' if it is not -1
539 - the end of string (null termination)
541 Note that 'byte_len' is the number of bytes in the packet
543 on failure zero is returned and *dest is set to NULL, otherwise the number
544 of bytes consumed in the packet is returned
546 static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_ctx,
547 char **dest, const uint8_t *src, int byte_len, uint_t flags)
549 int src_len, src_len2, alignment=0;
552 if (!(flags & STR_NOALIGN) && ucs2_align(req->in.buffer, src, flags)) {
555 if (byte_len != -1) {
560 src_len = req->in.data_size - PTR_DIFF(src, req->in.data);
565 if (byte_len != -1 && src_len > byte_len) {
569 src_len2 = utf16_len_n(src, src_len);
571 /* ucs2 strings must be at least 2 bytes long */
577 ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)dest);
583 return src_len2 + alignment;
587 pull a ascii string from a request packet, returning a talloced string
589 the string length is limited by the 3 things:
590 - the data size in the request (end of packet)
591 - the passed 'byte_len' if it is not -1
592 - the end of string (null termination)
594 Note that 'byte_len' is the number of bytes in the packet
596 on failure zero is returned and *dest is set to NULL, otherwise the number
597 of bytes consumed in the packet is returned
599 size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx,
600 char **dest, const uint8_t *src, int byte_len, uint_t flags)
602 int src_len, src_len2;
605 src_len = req->in.data_size - PTR_DIFF(src, req->in.data);
610 if (byte_len != -1 && src_len > byte_len) {
613 src_len2 = strnlen((const char *)src, src_len);
614 if (src_len2 < src_len - 1) {
615 /* include the termination if we didn't reach the end of the packet */
619 ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)dest);
630 pull a string from a request packet, returning a talloced string
632 the string length is limited by the 3 things:
633 - the data size in the request (end of packet)
634 - the passed 'byte_len' if it is not -1
635 - the end of string (null termination)
637 Note that 'byte_len' is the number of bytes in the packet
639 on failure zero is returned and *dest is set to NULL, otherwise the number
640 of bytes consumed in the packet is returned
642 size_t smbcli_req_pull_string(struct smbcli_request *req, TALLOC_CTX *mem_ctx,
643 char **dest, const uint8_t *src, int byte_len, uint_t flags)
645 if (!(flags & STR_ASCII) &&
646 (((flags & STR_UNICODE) || (req->flags2 & FLAGS2_UNICODE_STRINGS)))) {
647 return smbcli_req_pull_ucs2(req, mem_ctx, dest, src, byte_len, flags);
650 return smbcli_req_pull_ascii(req, mem_ctx, dest, src, byte_len, flags);
655 pull a DATA_BLOB from a reply packet, returning a talloced blob
656 make sure we don't go past end of packet
658 if byte_len is -1 then limit the blob only by packet size
660 DATA_BLOB smbcli_req_pull_blob(struct smbcli_request *req, TALLOC_CTX *mem_ctx, const uint8_t *src, int byte_len)
664 src_len = req->in.data_size - PTR_DIFF(src, req->in.data);
667 return data_blob(NULL, 0);
670 if (byte_len != -1 && src_len > byte_len) {
674 return data_blob_talloc(mem_ctx, src, src_len);
677 /* check that a lump of data in a request is within the bounds of the data section of
679 static BOOL smbcli_req_data_oob(struct smbcli_request *req, const uint8_t *ptr, uint32_t count)
681 /* be careful with wraparound! */
682 if (ptr < req->in.data ||
683 ptr >= req->in.data + req->in.data_size ||
684 count > req->in.data_size ||
685 ptr + count > req->in.data + req->in.data_size) {
692 pull a lump of data from a request packet
694 return False if any part is outside the data portion of the packet
696 BOOL smbcli_raw_pull_data(struct smbcli_request *req, const uint8_t *src, int len, uint8_t *dest)
698 if (len == 0) return True;
700 if (smbcli_req_data_oob(req, src, len)) {
704 memcpy(dest, src, len);
710 put a NTTIME into a packet
712 void smbcli_push_nttime(void *base, uint16_t offset, NTTIME t)
714 SBVAL(base, offset, t);
718 pull a NTTIME from a packet
720 NTTIME smbcli_pull_nttime(void *base, uint16_t offset)
722 NTTIME ret = BVAL(base, offset);
727 pull a UCS2 string from a blob, returning a talloced unix string
729 the string length is limited by the 3 things:
730 - the data size in the blob
731 - the passed 'byte_len' if it is not -1
732 - the end of string (null termination)
734 Note that 'byte_len' is the number of bytes in the packet
736 on failure zero is returned and *dest is set to NULL, otherwise the number
737 of bytes consumed in the blob is returned
739 static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx,
740 const DATA_BLOB *blob, const char **dest,
741 const uint8_t *src, int byte_len, uint_t flags)
743 int src_len, src_len2, alignment=0;
747 if (src < blob->data ||
748 src >= (blob->data + blob->length)) {
753 src_len = blob->length - PTR_DIFF(src, blob->data);
755 if (byte_len != -1 && src_len > byte_len) {
759 if (!(flags & STR_NOALIGN) && ucs2_align(blob->data, src, flags)) {
770 src_len2 = utf16_len_n(src, src_len);
772 ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2);
779 return src_len2 + alignment;
783 pull a ascii string from a blob, returning a talloced string
785 the string length is limited by the 3 things:
786 - the data size in the blob
787 - the passed 'byte_len' if it is not -1
788 - the end of string (null termination)
790 Note that 'byte_len' is the number of bytes in the blob
792 on failure zero is returned and *dest is set to NULL, otherwise the number
793 of bytes consumed in the blob is returned
795 static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx,
796 const DATA_BLOB *blob, const char **dest,
797 const uint8_t *src, int byte_len, uint_t flags)
799 int src_len, src_len2;
803 src_len = blob->length - PTR_DIFF(src, blob->data);
808 if (byte_len != -1 && src_len > byte_len) {
811 src_len2 = strnlen((const char *)src, src_len);
813 if (src_len2 < src_len - 1) {
814 /* include the termination if we didn't reach the end of the packet */
818 ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2);
830 pull a string from a blob, returning a talloced WIRE_STRING
832 the string length is limited by the 3 things:
833 - the data size in the blob
834 - length field on the wire
835 - the end of string (null termination)
837 if STR_LEN8BIT is set in the flags then assume the length field is
838 8 bits, instead of 32
840 on failure zero is returned and dest->s is set to NULL, otherwise the number
841 of bytes consumed in the blob is returned
843 size_t smbcli_blob_pull_string(struct smbcli_session *session,
845 const DATA_BLOB *blob,
847 uint16_t len_offset, uint16_t str_offset,
853 if (flags & STR_LEN8BIT) {
854 if (len_offset > blob->length-1) {
857 dest->private_length = CVAL(blob->data, len_offset);
859 if (len_offset > blob->length-4) {
862 dest->private_length = IVAL(blob->data, len_offset);
866 if (!(flags & STR_ASCII) &&
867 ((flags & STR_UNICODE) ||
868 (session->transport->negotiate.capabilities & CAP_UNICODE))) {
870 if ((str_offset&1) && !(flags & STR_NOALIGN)) {
873 if (flags & STR_LEN_NOTERM) {
876 return align + extra + smbcli_blob_pull_ucs2(mem_ctx, blob, &dest->s,
877 blob->data+str_offset+align,
878 dest->private_length, flags);
881 if (flags & STR_LEN_NOTERM) {
885 return extra + smbcli_blob_pull_ascii(mem_ctx, blob, &dest->s,
886 blob->data+str_offset, dest->private_length, flags);
890 pull a string from a blob, returning a talloced char *
892 Currently only used by the UNIX search info level.
894 the string length is limited by 2 things:
895 - the data size in the blob
896 - the end of string (null termination)
898 on failure zero is returned and dest->s is set to NULL, otherwise the number
899 of bytes consumed in the blob is returned
901 size_t smbcli_blob_pull_unix_string(struct smbcli_session *session,
911 if (!(flags & STR_ASCII) &&
912 ((flags & STR_UNICODE) ||
913 (session->transport->negotiate.capabilities & CAP_UNICODE))) {
915 if ((str_offset&1) && !(flags & STR_NOALIGN)) {
918 if (flags & STR_LEN_NOTERM) {
921 return align + extra + smbcli_blob_pull_ucs2(mem_ctx, blob, dest,
922 blob->data+str_offset+align,
926 if (flags & STR_LEN_NOTERM) {
930 return extra + smbcli_blob_pull_ascii(mem_ctx, blob, dest,
931 blob->data+str_offset, -1, flags);
936 append a string into a blob
938 size_t smbcli_blob_append_string(struct smbcli_session *session,
939 TALLOC_CTX *mem_ctx, DATA_BLOB *blob,
940 const char *str, uint_t flags)
947 /* determine string type to use */
948 if (!(flags & (STR_ASCII|STR_UNICODE))) {
949 flags |= (session->transport->negotiate.capabilities & CAP_UNICODE) ? STR_UNICODE : STR_ASCII;
952 max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR;
954 blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, blob->length + max_len);
959 len = push_string(blob->data + blob->length, str, max_len, flags);