2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan (metze) Metzmacher 2003
5 Copyright (C) Jeremy Allison 2007
6 Copyright (C) Andrew Bartlett 2011
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libsmb/libsmb.h"
24 #include "../lib/util/tevent_ntstatus.h"
25 #include "async_smb.h"
27 #include "auth_generic.h"
28 #include "auth/gensec/gensec.h"
29 #include "../libcli/smb/smbXcli_base.h"
30 #include "auth/credentials/credentials.h"
31 #include "../librpc/gen_ndr/ndr_security.h"
33 /****************************************************************************
34 Get UNIX extensions version info.
35 ****************************************************************************/
37 struct cli_unix_extensions_version_state
{
38 struct cli_state
*cli
;
41 uint16_t major
, minor
;
42 uint32_t caplow
, caphigh
;
45 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
);
47 struct tevent_req
*cli_unix_extensions_version_send(TALLOC_CTX
*mem_ctx
,
48 struct tevent_context
*ev
,
49 struct cli_state
*cli
)
51 struct tevent_req
*req
, *subreq
;
52 struct cli_unix_extensions_version_state
*state
;
54 req
= tevent_req_create(mem_ctx
, &state
,
55 struct cli_unix_extensions_version_state
);
60 SSVAL(state
->setup
, 0, TRANSACT2_QFSINFO
);
61 SSVAL(state
->param
, 0, SMB_QUERY_CIFS_UNIX_INFO
);
63 subreq
= cli_trans_send(state
, ev
, cli
, 0, SMBtrans2
,
68 if (tevent_req_nomem(subreq
, req
)) {
69 return tevent_req_post(req
, ev
);
71 tevent_req_set_callback(subreq
, cli_unix_extensions_version_done
, req
);
75 static void cli_unix_extensions_version_done(struct tevent_req
*subreq
)
77 struct tevent_req
*req
= tevent_req_callback_data(
78 subreq
, struct tevent_req
);
79 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
80 req
, struct cli_unix_extensions_version_state
);
85 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
86 NULL
, 0, NULL
, &data
, 12, &num_data
);
88 if (tevent_req_nterror(req
, status
)) {
92 state
->major
= SVAL(data
, 0);
93 state
->minor
= SVAL(data
, 2);
94 state
->caplow
= IVAL(data
, 4);
95 state
->caphigh
= IVAL(data
, 8);
100 NTSTATUS
cli_unix_extensions_version_recv(struct tevent_req
*req
,
101 uint16_t *pmajor
, uint16_t *pminor
,
105 struct cli_unix_extensions_version_state
*state
= tevent_req_data(
106 req
, struct cli_unix_extensions_version_state
);
109 if (tevent_req_is_nterror(req
, &status
)) {
112 *pmajor
= state
->major
;
113 *pminor
= state
->minor
;
114 *pcaplow
= state
->caplow
;
115 *pcaphigh
= state
->caphigh
;
116 state
->cli
->server_posix_capabilities
= *pcaplow
;
120 NTSTATUS
cli_unix_extensions_version(struct cli_state
*cli
, uint16_t *pmajor
,
121 uint16_t *pminor
, uint32_t *pcaplow
,
124 TALLOC_CTX
*frame
= talloc_stackframe();
125 struct tevent_context
*ev
;
126 struct tevent_req
*req
;
127 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
129 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
131 * Can't use sync call while an async call is in flight
133 status
= NT_STATUS_INVALID_PARAMETER
;
136 ev
= samba_tevent_context_init(frame
);
140 req
= cli_unix_extensions_version_send(frame
, ev
, cli
);
144 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
147 status
= cli_unix_extensions_version_recv(req
, pmajor
, pminor
, pcaplow
,
154 /****************************************************************************
155 Set UNIX extensions capabilities.
156 ****************************************************************************/
158 struct cli_set_unix_extensions_capabilities_state
{
159 struct cli_state
*cli
;
165 static void cli_set_unix_extensions_capabilities_done(
166 struct tevent_req
*subreq
);
168 struct tevent_req
*cli_set_unix_extensions_capabilities_send(
169 TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
, struct cli_state
*cli
,
170 uint16_t major
, uint16_t minor
, uint32_t caplow
, uint32_t caphigh
)
172 struct tevent_req
*req
, *subreq
;
173 struct cli_set_unix_extensions_capabilities_state
*state
;
175 req
= tevent_req_create(
177 struct cli_set_unix_extensions_capabilities_state
);
183 SSVAL(state
->setup
+0, 0, TRANSACT2_SETFSINFO
);
185 SSVAL(state
->param
, 0, 0);
186 SSVAL(state
->param
, 2, SMB_SET_CIFS_UNIX_INFO
);
188 SSVAL(state
->data
, 0, major
);
189 SSVAL(state
->data
, 2, minor
);
190 SIVAL(state
->data
, 4, caplow
);
191 SIVAL(state
->data
, 8, caphigh
);
193 subreq
= cli_trans_send(state
, ev
, cli
, 0, SMBtrans2
,
197 state
->data
, 12, 560);
198 if (tevent_req_nomem(subreq
, req
)) {
199 return tevent_req_post(req
, ev
);
201 tevent_req_set_callback(
202 subreq
, cli_set_unix_extensions_capabilities_done
, req
);
206 static void cli_set_unix_extensions_capabilities_done(
207 struct tevent_req
*subreq
)
209 struct tevent_req
*req
= tevent_req_callback_data(
210 subreq
, struct tevent_req
);
211 struct cli_set_unix_extensions_capabilities_state
*state
= tevent_req_data(
212 req
, struct cli_set_unix_extensions_capabilities_state
);
214 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
215 NULL
, 0, NULL
, NULL
, 0, NULL
);
216 if (NT_STATUS_IS_OK(status
)) {
217 state
->cli
->requested_posix_capabilities
= IVAL(state
->data
, 4);
219 tevent_req_simple_finish_ntstatus(subreq
, status
);
222 NTSTATUS
cli_set_unix_extensions_capabilities_recv(struct tevent_req
*req
)
224 return tevent_req_simple_recv_ntstatus(req
);
227 NTSTATUS
cli_set_unix_extensions_capabilities(struct cli_state
*cli
,
228 uint16_t major
, uint16_t minor
,
229 uint32_t caplow
, uint32_t caphigh
)
231 struct tevent_context
*ev
;
232 struct tevent_req
*req
;
233 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
235 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
236 return NT_STATUS_INVALID_PARAMETER
;
238 ev
= samba_tevent_context_init(talloc_tos());
242 req
= cli_set_unix_extensions_capabilities_send(
243 ev
, ev
, cli
, major
, minor
, caplow
, caphigh
);
247 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
250 status
= cli_set_unix_extensions_capabilities_recv(req
);
256 struct cli_get_fs_attr_info_state
{
262 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
);
264 struct tevent_req
*cli_get_fs_attr_info_send(TALLOC_CTX
*mem_ctx
,
265 struct tevent_context
*ev
,
266 struct cli_state
*cli
)
268 struct tevent_req
*subreq
, *req
;
269 struct cli_get_fs_attr_info_state
*state
;
271 req
= tevent_req_create(mem_ctx
, &state
,
272 struct cli_get_fs_attr_info_state
);
276 SSVAL(state
->setup
+0, 0, TRANSACT2_QFSINFO
);
277 SSVAL(state
->param
+0, 0, SMB_QUERY_FS_ATTRIBUTE_INFO
);
279 subreq
= cli_trans_send(state
, ev
, cli
, 0, SMBtrans2
,
284 if (tevent_req_nomem(subreq
, req
)) {
285 return tevent_req_post(req
, ev
);
287 tevent_req_set_callback(subreq
, cli_get_fs_attr_info_done
, req
);
291 static void cli_get_fs_attr_info_done(struct tevent_req
*subreq
)
293 struct tevent_req
*req
= tevent_req_callback_data(
294 subreq
, struct tevent_req
);
295 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
296 req
, struct cli_get_fs_attr_info_state
);
301 status
= cli_trans_recv(subreq
, talloc_tos(), NULL
, NULL
, 0, NULL
,
302 NULL
, 0, NULL
, &data
, 12, &num_data
);
304 if (tevent_req_nterror(req
, status
)) {
307 state
->fs_attr
= IVAL(data
, 0);
309 tevent_req_done(req
);
312 NTSTATUS
cli_get_fs_attr_info_recv(struct tevent_req
*req
, uint32_t *fs_attr
)
314 struct cli_get_fs_attr_info_state
*state
= tevent_req_data(
315 req
, struct cli_get_fs_attr_info_state
);
318 if (tevent_req_is_nterror(req
, &status
)) {
321 *fs_attr
= state
->fs_attr
;
325 NTSTATUS
cli_get_fs_attr_info(struct cli_state
*cli
, uint32_t *fs_attr
)
327 struct tevent_context
*ev
;
328 struct tevent_req
*req
;
329 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
331 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
332 return cli_smb2_get_fs_attr_info(cli
, fs_attr
);
335 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
336 return NT_STATUS_INVALID_PARAMETER
;
338 ev
= samba_tevent_context_init(talloc_tos());
342 req
= cli_get_fs_attr_info_send(ev
, ev
, cli
);
346 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
349 status
= cli_get_fs_attr_info_recv(req
, fs_attr
);
355 NTSTATUS
cli_get_fs_volume_info(struct cli_state
*cli
,
358 uint32_t *pserial_number
,
362 uint16_t recv_flags2
;
366 uint32_t rdata_count
;
368 char *volume_name
= NULL
;
370 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
371 return cli_smb2_get_fs_volume_info(cli
,
378 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
379 SSVAL(param
,0,SMB_QUERY_FS_VOLUME_INFO
);
381 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
389 &rdata
, 18, &rdata_count
);
390 if (!NT_STATUS_IS_OK(status
)) {
396 ts
= interpret_long_date(BVAL(rdata
, 0));
399 if (pserial_number
) {
400 *pserial_number
= IVAL(rdata
,8);
402 nlen
= IVAL(rdata
,12);
403 if (nlen
> (rdata_count
- 18)) {
405 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
408 pull_string_talloc(mem_ctx
,
414 if (volume_name
== NULL
) {
415 status
= map_nt_error_from_unix(errno
);
420 /* todo: but not yet needed
421 * return the other stuff
424 *_volume_name
= volume_name
;
429 NTSTATUS
cli_get_fs_full_size_info(struct cli_state
*cli
,
430 uint64_t *total_allocation_units
,
431 uint64_t *caller_allocation_units
,
432 uint64_t *actual_allocation_units
,
433 uint64_t *sectors_per_allocation_unit
,
434 uint64_t *bytes_per_sector
)
438 uint8_t *rdata
= NULL
;
439 uint32_t rdata_count
;
442 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
443 return cli_smb2_get_fs_full_size_info(cli
,
444 total_allocation_units
,
445 caller_allocation_units
,
446 actual_allocation_units
,
447 sectors_per_allocation_unit
,
451 SSVAL(setup
, 0, TRANSACT2_QFSINFO
);
452 SSVAL(param
, 0, SMB_FS_FULL_SIZE_INFORMATION
);
454 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
456 setup
, 1, 0, /* setup */
457 param
, 2, 0, /* param */
458 NULL
, 0, 560, /* data */
460 NULL
, 0, NULL
, /* rsetup */
461 NULL
, 0, NULL
, /* rparam */
462 &rdata
, 32, &rdata_count
); /* rdata */
463 if (!NT_STATUS_IS_OK(status
)) {
467 if (total_allocation_units
) {
468 *total_allocation_units
= BIG_UINT(rdata
, 0);
470 if (caller_allocation_units
) {
471 *caller_allocation_units
= BIG_UINT(rdata
,8);
473 if (actual_allocation_units
) {
474 *actual_allocation_units
= BIG_UINT(rdata
,16);
476 if (sectors_per_allocation_unit
) {
477 *sectors_per_allocation_unit
= IVAL(rdata
,24);
479 if (bytes_per_sector
) {
480 *bytes_per_sector
= IVAL(rdata
,28);
488 struct cli_get_posix_fs_info_state
{
491 uint32_t optimal_transfer_size
;
493 uint64_t total_blocks
;
494 uint64_t blocks_available
;
495 uint64_t user_blocks_available
;
496 uint64_t total_file_nodes
;
497 uint64_t free_file_nodes
;
498 uint64_t fs_identifier
;
501 static void cli_get_posix_fs_info_done(struct tevent_req
*subreq
);
502 static void cli_get_posix_fs_info_done2(struct tevent_req
*subreq
);
504 struct tevent_req
*cli_get_posix_fs_info_send(TALLOC_CTX
*mem_ctx
,
505 struct tevent_context
*ev
,
506 struct cli_state
*cli
)
508 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
509 struct cli_get_posix_fs_info_state
*state
= NULL
;
511 req
= tevent_req_create(mem_ctx
, &state
,
512 struct cli_get_posix_fs_info_state
);
516 SSVAL(state
->setup
, 0, TRANSACT2_QFSINFO
);
517 SSVAL(state
->param
, 0, SMB_QUERY_POSIX_FS_INFO
);
519 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
520 subreq
= cli_smb2_get_posix_fs_info_send(mem_ctx
, ev
, cli
);
521 if (tevent_req_nomem(subreq
, req
)) {
522 return tevent_req_post(req
, ev
);
524 tevent_req_set_callback(subreq
, cli_get_posix_fs_info_done2
, req
);
528 subreq
= cli_trans_send(talloc_tos(), /* mem ctx. */
530 cli
, /* cli_state. */
531 0, /* additional_flags2 */
532 SMBtrans2
, /* cmd. */
533 NULL
, /* pipe name. */
537 state
->setup
, /* setup. */
538 1, /* num setup uint16_t words. */
539 0, /* max returned setup. */
540 state
->param
, /* param. */
542 0, /* max returned param. */
545 560); /* max returned data. */
547 if (tevent_req_nomem(subreq
, req
)) {
548 return tevent_req_post(req
, ev
);
550 tevent_req_set_callback(subreq
, cli_get_posix_fs_info_done
, req
);
554 static void cli_get_posix_fs_info_done(struct tevent_req
*subreq
)
556 struct tevent_req
*req
= tevent_req_callback_data(
557 subreq
, struct tevent_req
);
558 struct cli_get_posix_fs_info_state
*state
= tevent_req_data(
559 req
, struct cli_get_posix_fs_info_state
);
560 uint8_t *data
= NULL
;
564 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
565 NULL
, 0, NULL
, &data
, 56, &num_data
);
567 if (tevent_req_nterror(req
, status
)) {
571 state
->optimal_transfer_size
= IVAL(data
, 0);
572 state
->block_size
= IVAL(data
,4);
573 state
->total_blocks
= BIG_UINT(data
,8);
574 state
->blocks_available
= BIG_UINT(data
,16);
575 state
->user_blocks_available
= BIG_UINT(data
,24);
576 state
->total_file_nodes
= BIG_UINT(data
,32);
577 state
->free_file_nodes
= BIG_UINT(data
,40);
578 state
->fs_identifier
= BIG_UINT(data
,48);
580 tevent_req_done(req
);
583 static void cli_get_posix_fs_info_done2(struct tevent_req
*subreq
)
585 struct tevent_req
*req
= tevent_req_callback_data(
586 subreq
, struct tevent_req
);
587 struct cli_get_posix_fs_info_state
*state
= tevent_req_data(
588 req
, struct cli_get_posix_fs_info_state
);
590 status
= cli_smb2_get_posix_fs_info_recv(subreq
,
591 &state
->optimal_transfer_size
,
593 &state
->total_blocks
,
594 &state
->blocks_available
,
595 &state
->user_blocks_available
,
596 &state
->total_file_nodes
,
597 &state
->free_file_nodes
,
598 &state
->fs_identifier
);
600 if (tevent_req_nterror(req
, status
)) {
604 tevent_req_done(req
);
607 NTSTATUS
cli_get_posix_fs_info_recv(struct tevent_req
*req
,
608 uint32_t *optimal_transfer_size
,
609 uint32_t *block_size
,
610 uint64_t *total_blocks
,
611 uint64_t *blocks_available
,
612 uint64_t *user_blocks_available
,
613 uint64_t *total_file_nodes
,
614 uint64_t *free_file_nodes
,
615 uint64_t *fs_identifier
)
617 struct cli_get_posix_fs_info_state
*state
= tevent_req_data(
618 req
, struct cli_get_posix_fs_info_state
);
621 if (tevent_req_is_nterror(req
, &status
)) {
622 tevent_req_received(req
);
626 if (optimal_transfer_size
) {
627 *optimal_transfer_size
= state
->optimal_transfer_size
;
630 *block_size
= state
->block_size
;
633 *total_blocks
= state
->total_blocks
;
635 if (blocks_available
) {
636 *blocks_available
= state
->blocks_available
;
638 if (user_blocks_available
) {
639 *user_blocks_available
= state
->user_blocks_available
;
641 if (total_file_nodes
) {
642 *total_file_nodes
= state
->total_file_nodes
;
644 if (free_file_nodes
) {
645 *free_file_nodes
= state
->free_file_nodes
;
648 *fs_identifier
= state
->fs_identifier
;
650 tevent_req_received(req
);
654 NTSTATUS
cli_get_posix_fs_info(struct cli_state
*cli
,
655 uint32_t *optimal_transfer_size
,
656 uint32_t *block_size
,
657 uint64_t *total_blocks
,
658 uint64_t *blocks_available
,
659 uint64_t *user_blocks_available
,
660 uint64_t *total_file_nodes
,
661 uint64_t *free_file_nodes
,
662 uint64_t *fs_identifier
)
664 TALLOC_CTX
*frame
= talloc_stackframe();
665 struct tevent_context
*ev
= NULL
;
666 struct tevent_req
*req
= NULL
;
667 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
669 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
671 * Can't use sync call while an async call is in flight
673 status
= NT_STATUS_INVALID_PARAMETER
;
677 ev
= samba_tevent_context_init(frame
);
682 req
= cli_get_posix_fs_info_send(frame
, ev
, cli
);
686 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
690 status
= cli_get_posix_fs_info_recv(req
,
691 optimal_transfer_size
,
695 user_blocks_available
,
705 /****************************************************************************
706 Do a UNIX extensions SMB_QUERY_POSIX_WHOAMI call.
707 ****************************************************************************/
709 struct posix_whoami_state
{
719 struct dom_sid
*sids
;
722 static void cli_posix_whoami_done(struct tevent_req
*subreq
);
724 static const uint32_t posix_whoami_max_rdata
= 62*1024;
726 struct tevent_req
*cli_posix_whoami_send(TALLOC_CTX
*mem_ctx
,
727 struct tevent_context
*ev
,
728 struct cli_state
*cli
)
730 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
731 struct posix_whoami_state
*state
= NULL
;
733 req
= tevent_req_create(mem_ctx
, &state
, struct posix_whoami_state
);
738 /* Setup setup word. */
739 SSVAL(state
->setup
, 0, TRANSACT2_QFSINFO
);
740 SSVAL(state
->param
, 0, SMB_QUERY_POSIX_WHOAMI
);
742 state
->max_rdata
= posix_whoami_max_rdata
;
744 subreq
= cli_trans_send(state
, /* mem ctx. */
746 cli
, /* cli_state. */
747 0, /* additional_flags2 */
748 SMBtrans2
, /* cmd. */
749 NULL
, /* pipe name. */
753 state
->setup
, /* setup. */
754 1, /* num setup uint16_t words. */
755 0, /* max returned setup. */
756 state
->param
, /* param. */
758 0, /* max returned param. */
761 state
->max_rdata
); /* max returned data. */
763 if (tevent_req_nomem(subreq
, req
)) {
764 return tevent_req_post(req
, ev
);
766 tevent_req_set_callback(subreq
, cli_posix_whoami_done
, req
);
770 static void cli_posix_whoami_done(struct tevent_req
*subreq
)
772 struct tevent_req
*req
= tevent_req_callback_data(
773 subreq
, struct tevent_req
);
774 struct posix_whoami_state
*state
= tevent_req_data(
775 req
, struct posix_whoami_state
);
776 uint8_t *rdata
= NULL
;
778 uint32_t num_rdata
= 0;
782 status
= cli_trans_recv(subreq
,
795 if (tevent_req_nterror(req
, status
)) {
800 * Not strictly needed - cli_trans_recv()
801 * will ensure at least 40 bytes here. Added
802 * as more of a reminder to be careful when
803 * parsing network packets in C.
806 if (num_rdata
< 40 || num_rdata
> posix_whoami_max_rdata
) {
807 tevent_req_nterror(req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
811 state
->guest
= (IVAL(rdata
, 0) & SMB_WHOAMI_GUEST
);
812 state
->uid
= BVAL(rdata
, 8);
813 state
->gid
= BVAL(rdata
, 16);
814 state
->num_gids
= IVAL(rdata
, 24);
815 state
->num_sids
= IVAL(rdata
, 28);
817 /* Ensure the gid array doesn't overflow */
818 if (state
->num_gids
> (num_rdata
- 40) / sizeof(uint64_t)) {
819 tevent_req_nterror(req
,
820 NT_STATUS_INVALID_NETWORK_RESPONSE
);
824 state
->gids
= talloc_array(state
, uint64_t, state
->num_gids
);
825 if (tevent_req_nomem(state
->gids
, req
)) {
828 state
->sids
= talloc_array(state
, struct dom_sid
, state
->num_sids
);
829 if (tevent_req_nomem(state
->sids
, req
)) {
835 for (i
= 0; i
< state
->num_gids
; i
++) {
836 state
->gids
[i
] = BVAL(p
, 0);
840 num_rdata
-= (p
- rdata
);
842 for (i
= 0; i
< state
->num_sids
; i
++) {
844 DATA_BLOB in
= data_blob_const(p
, num_rdata
);
845 enum ndr_err_code ndr_err
;
847 ndr_err
= ndr_pull_struct_blob(&in
,
850 (ndr_pull_flags_fn_t
)ndr_pull_dom_sid
);
851 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
852 tevent_req_nterror(req
,
853 NT_STATUS_INVALID_NETWORK_RESPONSE
);
857 sid_size
= ndr_size_dom_sid(&state
->sids
[i
], 0);
859 if (sid_size
> num_rdata
) {
860 tevent_req_nterror(req
,
861 NT_STATUS_INVALID_NETWORK_RESPONSE
);
866 num_rdata
-= sid_size
;
869 if (num_rdata
!= 0) {
870 tevent_req_nterror(req
,
871 NT_STATUS_INVALID_NETWORK_RESPONSE
);
875 tevent_req_done(req
);
878 NTSTATUS
cli_posix_whoami_recv(struct tevent_req
*req
,
885 struct dom_sid
**psids
,
889 struct posix_whoami_state
*state
= tevent_req_data(
890 req
, struct posix_whoami_state
);
892 if (tevent_req_is_nterror(req
, &status
)) {
903 *pnum_gids
= state
->num_gids
;
906 *pgids
= talloc_move(mem_ctx
, &state
->gids
);
909 *pnum_sids
= state
->num_sids
;
912 *psids
= talloc_move(mem_ctx
, &state
->sids
);
915 *pguest
= state
->guest
;
920 NTSTATUS
cli_posix_whoami(struct cli_state
*cli
,
927 struct dom_sid
**sids
,
930 TALLOC_CTX
*frame
= talloc_stackframe();
931 struct tevent_context
*ev
= NULL
;
932 struct tevent_req
*req
= NULL
;
933 NTSTATUS status
= NT_STATUS_OK
;
935 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
937 * Can't use sync call while an async call is in flight
939 status
= NT_STATUS_INVALID_PARAMETER
;
943 ev
= samba_tevent_context_init(frame
);
945 status
= NT_STATUS_NO_MEMORY
;
949 req
= cli_posix_whoami_send(frame
,
953 status
= NT_STATUS_NO_MEMORY
;
957 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
961 status
= cli_posix_whoami_recv(req
,