r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[Samba/bb.git] / source / rpcclient / cmd_ds.c
blob1f36dc3b457006f96222b335f8ba14e27f225b64
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Gerald Carter 2002
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/>.
21 #include "includes.h"
22 #include "rpcclient.h"
24 /* Look up domain related information on a remote host */
26 static NTSTATUS cmd_ds_dsrole_getprimarydominfo(struct rpc_pipe_client *cli,
27 TALLOC_CTX *mem_ctx, int argc,
28 const char **argv)
30 NTSTATUS result;
31 DS_DOMINFO_CTR ctr;
33 result = rpccli_ds_getprimarydominfo( cli, mem_ctx, DsRolePrimaryDomainInfoBasic, &ctr );
34 if ( NT_STATUS_IS_OK(result) )
36 printf ("Machine Role = [%d]\n", ctr.basic->machine_role);
38 if ( ctr.basic->flags & DSROLE_PRIMARY_DS_RUNNING ) {
39 printf( "Directory Service is running.\n");
40 printf( "Domain is in %s mode.\n", (ctr.basic->flags & DSROLE_PRIMARY_DS_MIXED_MODE) ? "mixed" : "native" );
42 else
43 printf( "Directory Service not running on server\n");
46 return result;
49 static NTSTATUS cmd_ds_enum_domain_trusts(struct rpc_pipe_client *cli,
50 TALLOC_CTX *mem_ctx, int argc,
51 const char **argv)
53 NTSTATUS result;
54 uint32 flags = DS_DOMAIN_IN_FOREST;
55 struct ds_domain_trust *trusts = NULL;
56 unsigned int num_domains = 0;
57 int i;
59 if (argc > 1) {
60 flags = atoi(argv[1]);
63 result = rpccli_ds_enum_domain_trusts( cli, mem_ctx, cli->cli->desthost, flags,
64 &trusts, &num_domains );
66 printf( "%d domains returned\n", num_domains );
68 for (i=0; i<num_domains; i++ )
69 printf("%s (%s)\n", trusts[i].dns_domain, trusts[i].netbios_domain);
71 return result;
74 /* List of commands exported by this module */
76 struct cmd_set ds_commands[] = {
78 { "LSARPC-DS" },
80 { "dsroledominfo", RPC_RTYPE_NTSTATUS, cmd_ds_dsrole_getprimarydominfo, NULL, PI_LSARPC_DS, NULL, "Get Primary Domain Information", "" },
81 { "dsenumdomtrusts", RPC_RTYPE_NTSTATUS, cmd_ds_enum_domain_trusts, NULL, PI_NETLOGON, NULL, "Enumerate all trusted domains in an AD forest", "" },
83 { NULL }