CVE-2020-25718 tests/krb5: Fix indentation
[Samba.git] / source3 / libsmb / clifsinfo.c
blobc4e2a01bc45bba81e12f86c981ecf9e476c49734
1 /*
2 Unix SMB/CIFS implementation.
3 FS info functions
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/>.
22 #include "includes.h"
23 #include "libsmb/libsmb.h"
24 #include "../lib/util/tevent_ntstatus.h"
25 #include "async_smb.h"
26 #include "trans2.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;
39 uint16_t setup[1];
40 uint8_t param[2];
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);
56 if (req == NULL) {
57 return NULL;
59 state->cli = cli;
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,
64 NULL, 0, 0, 0,
65 state->setup, 1, 0,
66 state->param, 2, 0,
67 NULL, 0, 560);
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);
72 return 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);
81 uint8_t *data;
82 uint32_t num_data;
83 NTSTATUS status;
85 status = cli_trans_recv(subreq, state, NULL, NULL, 0, NULL,
86 NULL, 0, NULL, &data, 12, &num_data);
87 TALLOC_FREE(subreq);
88 if (!NT_STATUS_IS_OK(status)) {
89 tevent_req_nterror(req, status);
90 return;
93 state->major = SVAL(data, 0);
94 state->minor = SVAL(data, 2);
95 state->caplow = IVAL(data, 4);
96 state->caphigh = IVAL(data, 8);
97 TALLOC_FREE(data);
98 tevent_req_done(req);
101 NTSTATUS cli_unix_extensions_version_recv(struct tevent_req *req,
102 uint16_t *pmajor, uint16_t *pminor,
103 uint32_t *pcaplow,
104 uint32_t *pcaphigh)
106 struct cli_unix_extensions_version_state *state = tevent_req_data(
107 req, struct cli_unix_extensions_version_state);
108 NTSTATUS status;
110 if (tevent_req_is_nterror(req, &status)) {
111 return status;
113 *pmajor = state->major;
114 *pminor = state->minor;
115 *pcaplow = state->caplow;
116 *pcaphigh = state->caphigh;
117 state->cli->server_posix_capabilities = *pcaplow;
118 return NT_STATUS_OK;
121 NTSTATUS cli_unix_extensions_version(struct cli_state *cli, uint16_t *pmajor,
122 uint16_t *pminor, uint32_t *pcaplow,
123 uint32_t *pcaphigh)
125 TALLOC_CTX *frame = talloc_stackframe();
126 struct tevent_context *ev;
127 struct tevent_req *req;
128 NTSTATUS status = NT_STATUS_OK;
130 if (smbXcli_conn_has_async_calls(cli->conn)) {
132 * Can't use sync call while an async call is in flight
134 status = NT_STATUS_INVALID_PARAMETER;
135 goto fail;
138 ev = samba_tevent_context_init(frame);
139 if (ev == NULL) {
140 status = NT_STATUS_NO_MEMORY;
141 goto fail;
144 req = cli_unix_extensions_version_send(frame, ev, cli);
145 if (req == NULL) {
146 status = NT_STATUS_NO_MEMORY;
147 goto fail;
150 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
151 goto fail;
154 status = cli_unix_extensions_version_recv(req, pmajor, pminor, pcaplow,
155 pcaphigh);
156 fail:
157 TALLOC_FREE(frame);
158 return status;
161 /****************************************************************************
162 Set UNIX extensions capabilities.
163 ****************************************************************************/
165 struct cli_set_unix_extensions_capabilities_state {
166 struct cli_state *cli;
167 uint16_t setup[1];
168 uint8_t param[4];
169 uint8_t data[12];
172 static void cli_set_unix_extensions_capabilities_done(
173 struct tevent_req *subreq);
175 struct tevent_req *cli_set_unix_extensions_capabilities_send(
176 TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct cli_state *cli,
177 uint16_t major, uint16_t minor, uint32_t caplow, uint32_t caphigh)
179 struct tevent_req *req, *subreq;
180 struct cli_set_unix_extensions_capabilities_state *state;
182 req = tevent_req_create(
183 mem_ctx, &state,
184 struct cli_set_unix_extensions_capabilities_state);
185 if (req == NULL) {
186 return NULL;
189 state->cli = cli;
190 SSVAL(state->setup+0, 0, TRANSACT2_SETFSINFO);
192 SSVAL(state->param, 0, 0);
193 SSVAL(state->param, 2, SMB_SET_CIFS_UNIX_INFO);
195 SSVAL(state->data, 0, major);
196 SSVAL(state->data, 2, minor);
197 SIVAL(state->data, 4, caplow);
198 SIVAL(state->data, 8, caphigh);
200 subreq = cli_trans_send(state, ev, cli, 0, SMBtrans2,
201 NULL, 0, 0, 0,
202 state->setup, 1, 0,
203 state->param, 4, 0,
204 state->data, 12, 560);
205 if (tevent_req_nomem(subreq, req)) {
206 return tevent_req_post(req, ev);
208 tevent_req_set_callback(
209 subreq, cli_set_unix_extensions_capabilities_done, req);
210 return req;
213 static void cli_set_unix_extensions_capabilities_done(
214 struct tevent_req *subreq)
216 struct tevent_req *req = tevent_req_callback_data(
217 subreq, struct tevent_req);
218 struct cli_set_unix_extensions_capabilities_state *state = tevent_req_data(
219 req, struct cli_set_unix_extensions_capabilities_state);
221 NTSTATUS status = cli_trans_recv(subreq, NULL, NULL, NULL, 0, NULL,
222 NULL, 0, NULL, NULL, 0, NULL);
223 if (NT_STATUS_IS_OK(status)) {
224 state->cli->requested_posix_capabilities = IVAL(state->data, 4);
226 tevent_req_simple_finish_ntstatus(subreq, status);
229 NTSTATUS cli_set_unix_extensions_capabilities_recv(struct tevent_req *req)
231 return tevent_req_simple_recv_ntstatus(req);
234 NTSTATUS cli_set_unix_extensions_capabilities(struct cli_state *cli,
235 uint16_t major, uint16_t minor,
236 uint32_t caplow, uint32_t caphigh)
238 struct tevent_context *ev;
239 struct tevent_req *req;
240 NTSTATUS status = NT_STATUS_NO_MEMORY;
242 if (smbXcli_conn_has_async_calls(cli->conn)) {
243 return NT_STATUS_INVALID_PARAMETER;
245 ev = samba_tevent_context_init(talloc_tos());
246 if (ev == NULL) {
247 goto fail;
249 req = cli_set_unix_extensions_capabilities_send(
250 ev, ev, cli, major, minor, caplow, caphigh);
251 if (req == NULL) {
252 goto fail;
254 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
255 goto fail;
257 status = cli_set_unix_extensions_capabilities_recv(req);
258 fail:
259 TALLOC_FREE(ev);
260 return status;
263 struct cli_get_fs_attr_info_state {
264 uint16_t setup[1];
265 uint8_t param[2];
266 uint32_t fs_attr;
269 static void cli_get_fs_attr_info_done(struct tevent_req *subreq);
271 struct tevent_req *cli_get_fs_attr_info_send(TALLOC_CTX *mem_ctx,
272 struct tevent_context *ev,
273 struct cli_state *cli)
275 struct tevent_req *subreq, *req;
276 struct cli_get_fs_attr_info_state *state;
278 req = tevent_req_create(mem_ctx, &state,
279 struct cli_get_fs_attr_info_state);
280 if (req == NULL) {
281 return NULL;
283 SSVAL(state->setup+0, 0, TRANSACT2_QFSINFO);
284 SSVAL(state->param+0, 0, SMB_QUERY_FS_ATTRIBUTE_INFO);
286 subreq = cli_trans_send(state, ev, cli, 0, SMBtrans2,
287 NULL, 0, 0, 0,
288 state->setup, 1, 0,
289 state->param, 2, 0,
290 NULL, 0, 560);
291 if (tevent_req_nomem(subreq, req)) {
292 return tevent_req_post(req, ev);
294 tevent_req_set_callback(subreq, cli_get_fs_attr_info_done, req);
295 return req;
298 static void cli_get_fs_attr_info_done(struct tevent_req *subreq)
300 struct tevent_req *req = tevent_req_callback_data(
301 subreq, struct tevent_req);
302 struct cli_get_fs_attr_info_state *state = tevent_req_data(
303 req, struct cli_get_fs_attr_info_state);
304 uint8_t *data;
305 uint32_t num_data;
306 NTSTATUS status;
308 status = cli_trans_recv(subreq, talloc_tos(), NULL, NULL, 0, NULL,
309 NULL, 0, NULL, &data, 12, &num_data);
310 TALLOC_FREE(subreq);
311 if (!NT_STATUS_IS_OK(status)) {
312 tevent_req_nterror(req, status);
313 return;
315 state->fs_attr = IVAL(data, 0);
316 TALLOC_FREE(data);
317 tevent_req_done(req);
320 NTSTATUS cli_get_fs_attr_info_recv(struct tevent_req *req, uint32_t *fs_attr)
322 struct cli_get_fs_attr_info_state *state = tevent_req_data(
323 req, struct cli_get_fs_attr_info_state);
324 NTSTATUS status;
326 if (tevent_req_is_nterror(req, &status)) {
327 return status;
329 *fs_attr = state->fs_attr;
330 return NT_STATUS_OK;
333 NTSTATUS cli_get_fs_attr_info(struct cli_state *cli, uint32_t *fs_attr)
335 struct tevent_context *ev;
336 struct tevent_req *req;
337 NTSTATUS status = NT_STATUS_NO_MEMORY;
339 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
340 return cli_smb2_get_fs_attr_info(cli, fs_attr);
343 if (smbXcli_conn_has_async_calls(cli->conn)) {
344 return NT_STATUS_INVALID_PARAMETER;
346 ev = samba_tevent_context_init(talloc_tos());
347 if (ev == NULL) {
348 goto fail;
350 req = cli_get_fs_attr_info_send(ev, ev, cli);
351 if (req == NULL) {
352 goto fail;
354 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
355 goto fail;
357 status = cli_get_fs_attr_info_recv(req, fs_attr);
358 fail:
359 TALLOC_FREE(ev);
360 return status;
363 NTSTATUS cli_get_fs_volume_info(struct cli_state *cli,
364 TALLOC_CTX *mem_ctx,
365 char **_volume_name,
366 uint32_t *pserial_number,
367 time_t *pdate)
369 NTSTATUS status;
370 uint16_t recv_flags2;
371 uint16_t setup[1];
372 uint8_t param[2];
373 uint8_t *rdata;
374 uint32_t rdata_count;
375 unsigned int nlen;
376 char *volume_name = NULL;
378 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
379 return cli_smb2_get_fs_volume_info(cli,
380 mem_ctx,
381 _volume_name,
382 pserial_number,
383 pdate);
386 SSVAL(setup, 0, TRANSACT2_QFSINFO);
387 SSVAL(param,0,SMB_QUERY_FS_VOLUME_INFO);
389 status = cli_trans(talloc_tos(), cli, SMBtrans2,
390 NULL, 0, 0, 0,
391 setup, 1, 0,
392 param, 2, 0,
393 NULL, 0, 560,
394 &recv_flags2,
395 NULL, 0, NULL,
396 NULL, 0, NULL,
397 &rdata, 18, &rdata_count);
398 if (!NT_STATUS_IS_OK(status)) {
399 return status;
402 if (pdate) {
403 struct timespec ts;
404 ts = interpret_long_date((char *)rdata);
405 *pdate = ts.tv_sec;
407 if (pserial_number) {
408 *pserial_number = IVAL(rdata,8);
410 nlen = IVAL(rdata,12);
411 if (nlen > (rdata_count - 18)) {
412 TALLOC_FREE(rdata);
413 return NT_STATUS_INVALID_NETWORK_RESPONSE;
416 pull_string_talloc(mem_ctx,
417 (const char *)rdata,
418 recv_flags2,
419 &volume_name,
420 rdata + 18,
421 nlen, STR_UNICODE);
422 if (volume_name == NULL) {
423 status = map_nt_error_from_unix(errno);
424 TALLOC_FREE(rdata);
425 return status;
428 /* todo: but not yet needed
429 * return the other stuff
432 *_volume_name = volume_name;
433 TALLOC_FREE(rdata);
434 return NT_STATUS_OK;
437 NTSTATUS cli_get_fs_full_size_info(struct cli_state *cli,
438 uint64_t *total_allocation_units,
439 uint64_t *caller_allocation_units,
440 uint64_t *actual_allocation_units,
441 uint64_t *sectors_per_allocation_unit,
442 uint64_t *bytes_per_sector)
444 uint16_t setup[1];
445 uint8_t param[2];
446 uint8_t *rdata = NULL;
447 uint32_t rdata_count;
448 NTSTATUS status;
450 if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
451 return cli_smb2_get_fs_full_size_info(cli,
452 total_allocation_units,
453 caller_allocation_units,
454 actual_allocation_units,
455 sectors_per_allocation_unit,
456 bytes_per_sector);
459 SSVAL(setup, 0, TRANSACT2_QFSINFO);
460 SSVAL(param, 0, SMB_FS_FULL_SIZE_INFORMATION);
462 status = cli_trans(talloc_tos(), cli, SMBtrans2,
463 NULL, 0, 0, 0,
464 setup, 1, 0, /* setup */
465 param, 2, 0, /* param */
466 NULL, 0, 560, /* data */
467 NULL,
468 NULL, 0, NULL, /* rsetup */
469 NULL, 0, NULL, /* rparam */
470 &rdata, 32, &rdata_count); /* rdata */
471 if (!NT_STATUS_IS_OK(status)) {
472 goto fail;
475 if (total_allocation_units) {
476 *total_allocation_units = BIG_UINT(rdata, 0);
478 if (caller_allocation_units) {
479 *caller_allocation_units = BIG_UINT(rdata,8);
481 if (actual_allocation_units) {
482 *actual_allocation_units = BIG_UINT(rdata,16);
484 if (sectors_per_allocation_unit) {
485 *sectors_per_allocation_unit = IVAL(rdata,24);
487 if (bytes_per_sector) {
488 *bytes_per_sector = IVAL(rdata,28);
491 fail:
492 TALLOC_FREE(rdata);
493 return status;
496 NTSTATUS cli_get_posix_fs_info(struct cli_state *cli,
497 uint32_t *optimal_transfer_size,
498 uint32_t *block_size,
499 uint64_t *total_blocks,
500 uint64_t *blocks_available,
501 uint64_t *user_blocks_available,
502 uint64_t *total_file_nodes,
503 uint64_t *free_file_nodes,
504 uint64_t *fs_identifier)
506 uint16_t setup[1];
507 uint8_t param[2];
508 uint8_t *rdata = NULL;
509 uint32_t rdata_count;
510 NTSTATUS status;
512 SSVAL(setup, 0, TRANSACT2_QFSINFO);
513 SSVAL(param,0,SMB_QUERY_POSIX_FS_INFO);
515 status = cli_trans(talloc_tos(), cli, SMBtrans2, NULL, 0, 0, 0,
516 setup, 1, 0,
517 param, 2, 0,
518 NULL, 0, 560,
519 NULL,
520 NULL, 0, NULL, /* rsetup */
521 NULL, 0, NULL, /* rparam */
522 &rdata, 56, &rdata_count);
523 if (!NT_STATUS_IS_OK(status)) {
524 return status;
527 if (optimal_transfer_size) {
528 *optimal_transfer_size = IVAL(rdata, 0);
530 if (block_size) {
531 *block_size = IVAL(rdata,4);
533 if (total_blocks) {
534 *total_blocks = BIG_UINT(rdata,8);
536 if (blocks_available) {
537 *blocks_available = BIG_UINT(rdata,16);
539 if (user_blocks_available) {
540 *user_blocks_available = BIG_UINT(rdata,24);
542 if (total_file_nodes) {
543 *total_file_nodes = BIG_UINT(rdata,32);
545 if (free_file_nodes) {
546 *free_file_nodes = BIG_UINT(rdata,40);
548 if (fs_identifier) {
549 *fs_identifier = BIG_UINT(rdata,48);
551 return NT_STATUS_OK;
554 /****************************************************************************
555 Do a UNIX extensions SMB_QUERY_POSIX_WHOAMI call.
556 ****************************************************************************/
558 struct posix_whoami_state {
559 uint16_t setup[1];
560 uint8_t param[2];
561 uint32_t max_rdata;
562 bool guest;
563 uint64_t uid;
564 uint64_t gid;
565 uint32_t num_gids;
566 uint64_t *gids;
567 uint32_t num_sids;
568 struct dom_sid *sids;
571 static void cli_posix_whoami_done(struct tevent_req *subreq);
573 static const uint32_t posix_whoami_max_rdata = 62*1024;
575 struct tevent_req *cli_posix_whoami_send(TALLOC_CTX *mem_ctx,
576 struct tevent_context *ev,
577 struct cli_state *cli)
579 struct tevent_req *req = NULL, *subreq = NULL;
580 struct posix_whoami_state *state = NULL;
582 req = tevent_req_create(mem_ctx, &state, struct posix_whoami_state);
583 if (req == NULL) {
584 return NULL;
587 /* Setup setup word. */
588 SSVAL(state->setup, 0, TRANSACT2_QFSINFO);
589 SSVAL(state->param, 0, SMB_QUERY_POSIX_WHOAMI);
591 state->max_rdata = posix_whoami_max_rdata;
593 subreq = cli_trans_send(state, /* mem ctx. */
594 ev, /* event ctx. */
595 cli, /* cli_state. */
596 0, /* additional_flags2 */
597 SMBtrans2, /* cmd. */
598 NULL, /* pipe name. */
599 -1, /* fid. */
600 0, /* function. */
601 0, /* flags. */
602 state->setup, /* setup. */
603 1, /* num setup uint16_t words. */
604 0, /* max returned setup. */
605 state->param, /* param. */
606 2, /* num param. */
607 0, /* max returned param. */
608 NULL, /* data. */
609 0, /* num data. */
610 state->max_rdata); /* max returned data. */
612 if (tevent_req_nomem(subreq, req)) {
613 return tevent_req_post(req, ev);
615 tevent_req_set_callback(subreq, cli_posix_whoami_done, req);
616 return req;
619 static void cli_posix_whoami_done(struct tevent_req *subreq)
621 struct tevent_req *req = tevent_req_callback_data(
622 subreq, struct tevent_req);
623 struct posix_whoami_state *state = tevent_req_data(
624 req, struct posix_whoami_state);
625 uint8_t *rdata = NULL;
626 uint8_t *p = NULL;
627 uint32_t num_rdata = 0;
628 uint32_t i;
629 NTSTATUS status;
631 status = cli_trans_recv(subreq,
632 state,
633 NULL,
634 NULL,
636 NULL,
637 NULL,
639 NULL,
640 &rdata,
642 &num_rdata);
643 TALLOC_FREE(subreq);
644 if (tevent_req_nterror(req, status)) {
645 return;
649 * Not strictly needed - cli_trans_recv()
650 * will ensure at least 40 bytes here. Added
651 * as more of a reminder to be careful when
652 * parsing network packets in C.
655 if (num_rdata < 40 || num_rdata > posix_whoami_max_rdata) {
656 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
657 return;
660 state->guest = (IVAL(rdata, 0) & SMB_WHOAMI_GUEST);
661 state->uid = BVAL(rdata, 8);
662 state->gid = BVAL(rdata, 16);
663 state->num_gids = IVAL(rdata, 24);
664 state->num_sids = IVAL(rdata, 28);
666 /* Ensure the gid array doesn't overflow */
667 if (state->num_gids > (num_rdata - 40) / sizeof(uint64_t)) {
668 tevent_req_nterror(req,
669 NT_STATUS_INVALID_NETWORK_RESPONSE);
670 return;
673 state->gids = talloc_array(state, uint64_t, state->num_gids);
674 if (tevent_req_nomem(state->gids, req)) {
675 return;
677 state->sids = talloc_array(state, struct dom_sid, state->num_sids);
678 if (tevent_req_nomem(state->sids, req)) {
679 return;
682 p = rdata + 40;
684 for (i = 0; i < state->num_gids; i++) {
685 state->gids[i] = BVAL(p, 0);
686 p += 8;
689 num_rdata -= (p - rdata);
691 for (i = 0; i < state->num_sids; i++) {
692 size_t sid_size;
693 DATA_BLOB in = data_blob_const(p, num_rdata);
694 enum ndr_err_code ndr_err;
696 ndr_err = ndr_pull_struct_blob(&in,
697 state,
698 &state->sids[i],
699 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
700 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
701 tevent_req_nterror(req,
702 NT_STATUS_INVALID_NETWORK_RESPONSE);
703 return;
706 sid_size = ndr_size_dom_sid(&state->sids[i], 0);
708 if (sid_size > num_rdata) {
709 tevent_req_nterror(req,
710 NT_STATUS_INVALID_NETWORK_RESPONSE);
711 return;
714 p += sid_size;
715 num_rdata -= sid_size;
718 if (num_rdata != 0) {
719 tevent_req_nterror(req,
720 NT_STATUS_INVALID_NETWORK_RESPONSE);
721 return;
724 tevent_req_done(req);
727 NTSTATUS cli_posix_whoami_recv(struct tevent_req *req,
728 TALLOC_CTX *mem_ctx,
729 uint64_t *puid,
730 uint64_t *pgid,
731 uint32_t *pnum_gids,
732 uint64_t **pgids,
733 uint32_t *pnum_sids,
734 struct dom_sid **psids,
735 bool *pguest)
737 NTSTATUS status;
738 struct posix_whoami_state *state = tevent_req_data(
739 req, struct posix_whoami_state);
741 if (tevent_req_is_nterror(req, &status)) {
742 return status;
745 if (puid) {
746 *puid = state->uid;
748 if (pgid) {
749 *pgid = state->gid;
751 if (pnum_gids) {
752 *pnum_gids = state->num_gids;
754 if (pgids) {
755 *pgids = talloc_move(mem_ctx, &state->gids);
757 if (pnum_sids) {
758 *pnum_sids = state->num_sids;
760 if (psids) {
761 *psids = talloc_move(mem_ctx, &state->sids);
763 if (pguest) {
764 *pguest = state->guest;
766 return NT_STATUS_OK;
769 NTSTATUS cli_posix_whoami(struct cli_state *cli,
770 TALLOC_CTX *mem_ctx,
771 uint64_t *puid,
772 uint64_t *pgid,
773 uint32_t *num_gids,
774 uint64_t **gids,
775 uint32_t *num_sids,
776 struct dom_sid **sids,
777 bool *pguest)
779 TALLOC_CTX *frame = talloc_stackframe();
780 struct tevent_context *ev = NULL;
781 struct tevent_req *req = NULL;
782 NTSTATUS status = NT_STATUS_OK;
784 if (smbXcli_conn_has_async_calls(cli->conn)) {
786 * Can't use sync call while an async call is in flight
788 status = NT_STATUS_INVALID_PARAMETER;
789 goto fail;
792 ev = samba_tevent_context_init(frame);
793 if (ev == NULL) {
794 status = NT_STATUS_NO_MEMORY;
795 goto fail;
798 req = cli_posix_whoami_send(frame,
800 cli);
801 if (req == NULL) {
802 status = NT_STATUS_NO_MEMORY;
803 goto fail;
806 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
807 goto fail;
810 status = cli_posix_whoami_recv(req,
811 mem_ctx,
812 puid,
813 pgid,
814 num_gids,
815 gids,
816 num_sids,
817 sids,
818 pguest);
820 fail:
821 TALLOC_FREE(frame);
822 return status;