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 3 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, see <http://www.gnu.org/licenses/>.
22 this file implements functions for manipulating the 'struct smbcli_request' structure in libsmb
26 #include "libcli/raw/libcliraw.h"
27 #include "lib/util/dlinklist.h"
28 #include "lib/events/events.h"
30 /* we over allocate the data buffer to prevent too many realloc calls */
31 #define REQ_OVER_ALLOCATION 0
33 /* assume that a character will not consume more than 3 bytes per char */
34 #define MAX_BYTES_PER_CHAR 3
36 /* destroy a request structure and return final status */
37 NTSTATUS smbcli_request_destroy(struct smbcli_request *req)
41 /* this is the error code we give the application for when a
42 _send() call fails completely */
43 if (!req) return NT_STATUS_UNSUCCESSFUL;
46 /* remove it from the list of pending requests (a null op if
47 its not in the list) */
48 DLIST_REMOVE(req->transport->pending_recv, req);
51 if (req->state == SMBCLI_REQUEST_ERROR &&
52 NT_STATUS_IS_OK(req->status)) {
53 req->status = NT_STATUS_INTERNAL_ERROR;
63 low-level function to setup a request buffer for a non-SMB packet
64 at the transport level
66 struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *transport, size_t size)
68 struct smbcli_request *req;
70 req = talloc(transport, struct smbcli_request);
76 /* setup the request context */
77 req->state = SMBCLI_REQUEST_INIT;
78 req->transport = transport;
83 /* over allocate by a small amount */
84 req->out.allocated = req->out.size + REQ_OVER_ALLOCATION;
86 req->out.buffer = talloc_size(req, req->out.allocated);
87 if (!req->out.buffer) {
91 SIVAL(req->out.buffer, 0, 0);
98 setup a SMB packet at transport level
100 struct smbcli_request *smbcli_request_setup_transport(struct smbcli_transport *transport,
101 uint8_t command, uint_t wct, uint_t buflen)
103 struct smbcli_request *req;
105 req = smbcli_request_setup_nonsmb(transport, NBT_HDR_SIZE + MIN_SMB_SIZE + wct*2 + buflen);
107 if (!req) return NULL;
109 req->out.hdr = req->out.buffer + NBT_HDR_SIZE;
110 req->out.vwv = req->out.hdr + HDR_VWV;
112 req->out.data = req->out.vwv + VWV(wct) + 2;
113 req->out.data_size = buflen;
114 req->out.ptr = req->out.data;
116 SCVAL(req->out.hdr, HDR_WCT, wct);
117 SSVAL(req->out.vwv, VWV(wct), buflen);
119 memcpy(req->out.hdr, "\377SMB", 4);
120 SCVAL(req->out.hdr,HDR_COM,command);
122 SCVAL(req->out.hdr,HDR_FLG, FLAG_CASELESS_PATHNAMES);
123 SSVAL(req->out.hdr,HDR_FLG2, 0);
125 if (command != SMBtranss && command != SMBtranss2) {
127 req->mid = smbcli_transport_next_mid(transport);
130 /* copy the pid, uid and mid to the request */
131 SSVAL(req->out.hdr, HDR_PID, 0);
132 SSVAL(req->out.hdr, HDR_UID, 0);
133 SSVAL(req->out.hdr, HDR_MID, req->mid);
134 SSVAL(req->out.hdr, HDR_TID,0);
135 SSVAL(req->out.hdr, HDR_PIDHIGH,0);
136 SIVAL(req->out.hdr, HDR_RCLS, 0);
137 memset(req->out.hdr+HDR_SS_FIELD, 0, 10);
143 setup a reply in req->out with the given word count and initial data
144 buffer size. the caller will then fill in the command words and
145 data before calling smbcli_request_send() to send the reply on its
146 way. This interface is used before a session is setup.
148 struct smbcli_request *smbcli_request_setup_session(struct smbcli_session *session,
149 uint8_t command, uint_t wct, size_t buflen)
151 struct smbcli_request *req;
153 req = smbcli_request_setup_transport(session->transport, command, wct, buflen);
155 if (!req) return NULL;
157 req->session = session;
159 SSVAL(req->out.hdr, HDR_FLG2, session->flags2);
160 SSVAL(req->out.hdr, HDR_PID, session->pid & 0xFFFF);
161 SSVAL(req->out.hdr, HDR_PIDHIGH, session->pid >> 16);
162 SSVAL(req->out.hdr, HDR_UID, session->vuid);
168 setup a request for tree based commands
170 struct smbcli_request *smbcli_request_setup(struct smbcli_tree *tree,
172 uint_t wct, uint_t buflen)
174 struct smbcli_request *req;
176 req = smbcli_request_setup_session(tree->session, command, wct, buflen);
179 SSVAL(req->out.hdr,HDR_TID,tree->tid);
186 grow the allocation of the data buffer portion of a reply
187 packet. Note that as this can reallocate the packet buffer this
188 invalidates any local pointers into the packet.
190 To cope with this req->out.ptr is supplied. This will be updated to
191 point at the same offset into the packet as before this call
193 static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_size)
198 delta = new_size - req->out.data_size;
199 if (delta + req->out.size <= req->out.allocated) {
200 /* it fits in the preallocation */
204 /* we need to realloc */
205 req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION;
206 buf2 = talloc_realloc(req, req->out.buffer, uint8_t, req->out.allocated);
208 smb_panic("out of memory in req_grow_allocation");
211 if (buf2 == req->out.buffer) {
212 /* the malloc library gave us the same pointer */
216 /* update the pointers into the packet */
217 req->out.data = buf2 + PTR_DIFF(req->out.data, req->out.buffer);
218 req->out.ptr = buf2 + PTR_DIFF(req->out.ptr, req->out.buffer);
219 req->out.vwv = buf2 + PTR_DIFF(req->out.vwv, req->out.buffer);
220 req->out.hdr = buf2 + PTR_DIFF(req->out.hdr, req->out.buffer);
222 req->out.buffer = buf2;
227 grow the data buffer portion of a reply packet. Note that as this
228 can reallocate the packet buffer this invalidates any local pointers
231 To cope with this req->out.ptr is supplied. This will be updated to
232 point at the same offset into the packet as before this call
234 static void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size)
238 smbcli_req_grow_allocation(req, new_size);
240 delta = new_size - req->out.data_size;
242 req->out.size += delta;
243 req->out.data_size += delta;
245 /* set the BCC to the new data size */
246 SSVAL(req->out.vwv, VWV(req->out.wct), new_size);
251 setup a chained reply in req->out with the given word count and
252 initial data buffer size.
254 NTSTATUS smbcli_chained_request_setup(struct smbcli_request *req,
256 uint_t wct, size_t buflen)
258 uint_t new_size = 1 + (wct*2) + 2 + buflen;
260 SSVAL(req->out.vwv, VWV(0), command);
261 SSVAL(req->out.vwv, VWV(1), req->out.size - NBT_HDR_SIZE);
263 smbcli_req_grow_allocation(req, req->out.data_size + new_size);
265 req->out.vwv = req->out.buffer + req->out.size + 1;
266 SCVAL(req->out.vwv, -1, wct);
267 SSVAL(req->out.vwv, VWV(wct), buflen);
269 req->out.size += new_size;
270 req->out.data_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 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 struct smb_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,
846 struct smb_wire_string *dest,
847 uint16_t len_offset, uint16_t str_offset,
853 if (!(flags & STR_ASCII)) {
854 /* this is here to cope with SMB2 calls using the SMB
855 parsers. SMB2 will pass smbcli_session==NULL, which forces
856 unicode on (as used by SMB2) */
857 if (session == NULL) {
858 flags |= STR_UNICODE;
859 } else if (session->transport->negotiate.capabilities & CAP_UNICODE) {
860 flags |= STR_UNICODE;
864 if (flags & STR_LEN8BIT) {
865 if (len_offset > blob->length-1) {
868 dest->private_length = CVAL(blob->data, len_offset);
870 if (len_offset > blob->length-4) {
873 dest->private_length = IVAL(blob->data, len_offset);
877 if (!(flags & STR_ASCII) && (flags & STR_UNICODE)) {
879 if ((str_offset&1) && !(flags & STR_NOALIGN)) {
882 if (flags & STR_LEN_NOTERM) {
885 return align + extra + smbcli_blob_pull_ucs2(mem_ctx, blob, &dest->s,
886 blob->data+str_offset+align,
887 dest->private_length, flags);
890 if (flags & STR_LEN_NOTERM) {
894 return extra + smbcli_blob_pull_ascii(mem_ctx, blob, &dest->s,
895 blob->data+str_offset, dest->private_length, flags);
899 pull a string from a blob, returning a talloced char *
901 Currently only used by the UNIX search info level.
903 the string length is limited by 2 things:
904 - the data size in the blob
905 - the end of string (null termination)
907 on failure zero is returned and dest->s is set to NULL, otherwise the number
908 of bytes consumed in the blob is returned
910 size_t smbcli_blob_pull_unix_string(struct smbcli_session *session,
920 if (!(flags & STR_ASCII) &&
921 ((flags & STR_UNICODE) ||
922 (session->transport->negotiate.capabilities & CAP_UNICODE))) {
924 if ((str_offset&1) && !(flags & STR_NOALIGN)) {
927 if (flags & STR_LEN_NOTERM) {
930 return align + extra + smbcli_blob_pull_ucs2(mem_ctx, blob, dest,
931 blob->data+str_offset+align,
935 if (flags & STR_LEN_NOTERM) {
939 return extra + smbcli_blob_pull_ascii(mem_ctx, blob, dest,
940 blob->data+str_offset, -1, flags);
945 append a string into a blob
947 size_t smbcli_blob_append_string(struct smbcli_session *session,
948 TALLOC_CTX *mem_ctx, DATA_BLOB *blob,
949 const char *str, uint_t flags)
956 /* determine string type to use */
957 if (!(flags & (STR_ASCII|STR_UNICODE))) {
958 flags |= (session->transport->negotiate.capabilities & CAP_UNICODE) ? STR_UNICODE : STR_ASCII;
961 max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR;
963 blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, blob->length + max_len);
968 len = push_string(blob->data + blob->length, str, max_len, flags);