| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | RPC pipe client
|
|---|
| 4 | Copyright (C) Gerald Carter 2002,
|
|---|
| 5 | Copyright (C) Jeremy Allison 2005.
|
|---|
| 6 |
|
|---|
| 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.
|
|---|
| 11 |
|
|---|
| 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.
|
|---|
| 16 |
|
|---|
| 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.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 23 |
|
|---|
| 24 | /* implementations of client side DsXXX() functions */
|
|---|
| 25 |
|
|---|
| 26 | /********************************************************************
|
|---|
| 27 | Get information about the server and directory services
|
|---|
| 28 | ********************************************************************/
|
|---|
| 29 |
|
|---|
| 30 | NTSTATUS rpccli_ds_getprimarydominfo(struct rpc_pipe_client *cli,
|
|---|
| 31 | TALLOC_CTX *mem_ctx,
|
|---|
| 32 | uint16 level, DS_DOMINFO_CTR *ctr)
|
|---|
| 33 | {
|
|---|
| 34 | prs_struct qbuf, rbuf;
|
|---|
| 35 | DS_Q_GETPRIMDOMINFO q;
|
|---|
| 36 | DS_R_GETPRIMDOMINFO r;
|
|---|
| 37 | NTSTATUS result;
|
|---|
| 38 |
|
|---|
| 39 | ZERO_STRUCT(q);
|
|---|
| 40 | ZERO_STRUCT(r);
|
|---|
| 41 |
|
|---|
| 42 | q.level = level;
|
|---|
| 43 |
|
|---|
| 44 | CLI_DO_RPC( cli, mem_ctx, PI_LSARPC_DS, DS_GETPRIMDOMINFO,
|
|---|
| 45 | q, r,
|
|---|
| 46 | qbuf, rbuf,
|
|---|
| 47 | ds_io_q_getprimdominfo,
|
|---|
| 48 | ds_io_r_getprimdominfo,
|
|---|
| 49 | NT_STATUS_UNSUCCESSFUL);
|
|---|
| 50 |
|
|---|
| 51 | /* Return basic info - if we are requesting at info != 1 then
|
|---|
| 52 | there could be trouble. */
|
|---|
| 53 |
|
|---|
| 54 | result = r.status;
|
|---|
| 55 |
|
|---|
| 56 | if ( r.ptr && ctr ) {
|
|---|
| 57 | ctr->basic = TALLOC_P(mem_ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC);
|
|---|
| 58 | if (!ctr->basic)
|
|---|
| 59 | goto done;
|
|---|
| 60 | memcpy(ctr->basic, r.info.basic, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | done:
|
|---|
| 64 |
|
|---|
| 65 | return result;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | /********************************************************************
|
|---|
| 69 | Enumerate trusted domains in an AD forest
|
|---|
| 70 | ********************************************************************/
|
|---|
| 71 |
|
|---|
| 72 | NTSTATUS rpccli_ds_enum_domain_trusts(struct rpc_pipe_client *cli,
|
|---|
| 73 | TALLOC_CTX *mem_ctx,
|
|---|
| 74 | const char *server, uint32 flags,
|
|---|
| 75 | struct ds_domain_trust **trusts,
|
|---|
| 76 | uint32 *num_domains)
|
|---|
| 77 | {
|
|---|
| 78 | prs_struct qbuf, rbuf;
|
|---|
| 79 | DS_Q_ENUM_DOM_TRUSTS q;
|
|---|
| 80 | DS_R_ENUM_DOM_TRUSTS r;
|
|---|
| 81 | NTSTATUS result;
|
|---|
| 82 |
|
|---|
| 83 | ZERO_STRUCT(q);
|
|---|
| 84 | ZERO_STRUCT(r);
|
|---|
| 85 |
|
|---|
| 86 | init_q_ds_enum_domain_trusts( &q, server, flags );
|
|---|
| 87 |
|
|---|
| 88 | CLI_DO_RPC( cli, mem_ctx, PI_NETLOGON, DS_ENUM_DOM_TRUSTS,
|
|---|
| 89 | q, r,
|
|---|
| 90 | qbuf, rbuf,
|
|---|
| 91 | ds_io_q_enum_domain_trusts,
|
|---|
| 92 | ds_io_r_enum_domain_trusts,
|
|---|
| 93 | NT_STATUS_UNSUCCESSFUL);
|
|---|
| 94 |
|
|---|
| 95 | result = r.status;
|
|---|
| 96 |
|
|---|
| 97 | if ( NT_STATUS_IS_OK(result) ) {
|
|---|
| 98 | int i;
|
|---|
| 99 |
|
|---|
| 100 | *num_domains = r.num_domains;
|
|---|
| 101 | if (r.num_domains) {
|
|---|
| 102 | *trusts = TALLOC_ARRAY(mem_ctx, struct ds_domain_trust, r.num_domains);
|
|---|
| 103 |
|
|---|
| 104 | if (*trusts == NULL) {
|
|---|
| 105 | return NT_STATUS_NO_MEMORY;
|
|---|
| 106 | }
|
|---|
| 107 | } else {
|
|---|
| 108 | *trusts = NULL;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | for ( i=0; i< *num_domains; i++ ) {
|
|---|
| 112 | (*trusts)[i].flags = r.domains.trusts[i].flags;
|
|---|
| 113 | (*trusts)[i].parent_index = r.domains.trusts[i].parent_index;
|
|---|
| 114 | (*trusts)[i].trust_type = r.domains.trusts[i].trust_type;
|
|---|
| 115 | (*trusts)[i].trust_attributes = r.domains.trusts[i].trust_attributes;
|
|---|
| 116 | (*trusts)[i].guid = r.domains.trusts[i].guid;
|
|---|
| 117 |
|
|---|
| 118 | if (r.domains.trusts[i].sid_ptr) {
|
|---|
| 119 | sid_copy(&(*trusts)[i].sid, &r.domains.trusts[i].sid.sid);
|
|---|
| 120 | } else {
|
|---|
| 121 | ZERO_STRUCT((*trusts)[i].sid);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | if (r.domains.trusts[i].netbios_ptr) {
|
|---|
| 125 | (*trusts)[i].netbios_domain = unistr2_tdup( mem_ctx, &r.domains.trusts[i].netbios_domain );
|
|---|
| 126 | } else {
|
|---|
| 127 | (*trusts)[i].netbios_domain = NULL;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | if (r.domains.trusts[i].dns_ptr) {
|
|---|
| 131 | (*trusts)[i].dns_domain = unistr2_tdup( mem_ctx, &r.domains.trusts[i].dns_domain );
|
|---|
| 132 | } else {
|
|---|
| 133 | (*trusts)[i].dns_domain = NULL;
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | return result;
|
|---|
| 139 | }
|
|---|