s3-rpcclient: fix netr_LogonGetCapabilities command.
[ira/wip.git] / source3 / rpcclient / cmd_netlogon.c
index cdcc0ec28dbccf32b201cc9ec9d185866b9f2393..ae76652113a7da9c28faed319e69a5f3862bead0 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 #include "rpcclient.h"
+#include "../libcli/auth/libcli_auth.h"
 
 static WERROR cmd_netlogon_logon_ctrl2(struct rpc_pipe_client *cli,
                                       TALLOC_CTX *mem_ctx, int argc,
@@ -221,7 +222,7 @@ static WERROR cmd_netlogon_dsr_getdcname(struct rpc_pipe_client *cli,
        }
 
        printf("rpccli_netlogon_dsr_getdcname returned %s\n",
-              dos_errstr(werr));
+              win_errstr(werr));
 
        return werr;
 }
@@ -584,7 +585,7 @@ static NTSTATUS cmd_netlogon_sam_sync(struct rpc_pipe_client *cli,
        do {
                struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
 
-               netlogon_creds_client_step(cli->dc, &credential);
+               netlogon_creds_client_authenticator(cli->dc, &credential);
 
                result = rpccli_netr_DatabaseSync2(cli, mem_ctx,
                                                   logon_server,
@@ -647,7 +648,7 @@ static NTSTATUS cmd_netlogon_sam_deltas(struct rpc_pipe_client *cli,
        do {
                struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
 
-               netlogon_creds_client_step(cli->dc, &credential);
+               netlogon_creds_client_authenticator(cli->dc, &credential);
 
                result = rpccli_netr_DatabaseDeltas(cli, mem_ctx,
                                                    logon_server,
@@ -1003,6 +1004,151 @@ static WERROR cmd_netlogon_enumtrusteddomainsex(struct rpc_pipe_client *cli,
        return werr;
 }
 
+static WERROR cmd_netlogon_getdcsitecoverage(struct rpc_pipe_client *cli,
+                                            TALLOC_CTX *mem_ctx, int argc,
+                                            const char **argv)
+{
+       NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       WERROR werr = WERR_GENERAL_FAILURE;
+       const char *server_name = cli->desthost;
+       struct DcSitesCtr *ctr = NULL;
+
+       if (argc < 1 || argc > 3) {
+               fprintf(stderr, "Usage: %s <server_name>\n", argv[0]);
+               return WERR_OK;
+       }
+
+       if (argc >= 2) {
+               server_name = argv[1];
+       }
+
+       status = rpccli_netr_DsrGetDcSiteCoverageW(cli, mem_ctx,
+                                                  server_name,
+                                                  &ctr,
+                                                  &werr);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+       if (W_ERROR_IS_OK(werr) && ctr->num_sites) {
+               int i;
+               printf("sites covered by this DC: %d\n", ctr->num_sites);
+               for (i=0; i<ctr->num_sites; i++) {
+                       printf("%s\n", ctr->sites[i].string);
+               }
+       }
+ done:
+       return werr;
+}
+
+static NTSTATUS cmd_netlogon_database_redo(struct rpc_pipe_client *cli,
+                                          TALLOC_CTX *mem_ctx, int argc,
+                                          const char **argv)
+{
+       NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       const char *server_name = cli->desthost;
+       uint32_t neg_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS;
+       struct netr_Authenticator clnt_creds, srv_cred;
+       struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
+       unsigned char trust_passwd_hash[16];
+       uint32_t sec_channel_type = 0;
+       struct netr_ChangeLogEntry e;
+       uint32_t rid = 500;
+
+       if (argc > 2) {
+               fprintf(stderr, "Usage: %s <user rid>\n", argv[0]);
+               return NT_STATUS_OK;
+       }
+
+       if (argc == 2) {
+               sscanf(argv[1], "%d", &rid);
+       }
+
+       if (!secrets_fetch_trust_account_password(lp_workgroup(),
+                                                 trust_passwd_hash,
+                                                 NULL, &sec_channel_type)) {
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       status = rpccli_netlogon_setup_creds(cli,
+                                            server_name, /* server name */
+                                            lp_workgroup(), /* domain */
+                                            global_myname(), /* client name */
+                                            global_myname(), /* machine account name */
+                                            trust_passwd_hash,
+                                            sec_channel_type,
+                                            &neg_flags);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       netlogon_creds_client_authenticator(cli->dc, &clnt_creds);
+
+       ZERO_STRUCT(e);
+
+       e.object_rid            = rid;
+       e.db_index              = SAM_DATABASE_DOMAIN;
+       e.delta_type            = NETR_DELTA_USER;
+
+       status = rpccli_netr_DatabaseRedo(cli, mem_ctx,
+                                         server_name,
+                                         global_myname(),
+                                         &clnt_creds,
+                                         &srv_cred,
+                                         e,
+                                         0, /* is calculated automatically */
+                                         &delta_enum_array);
+
+       if (!netlogon_creds_client_check(cli->dc, &srv_cred.cred)) {
+               DEBUG(0,("credentials chain check failed\n"));
+               return NT_STATUS_ACCESS_DENIED;
+       }
+
+       return status;
+}
+
+static NTSTATUS cmd_netlogon_capabilities(struct rpc_pipe_client *cli,
+                                         TALLOC_CTX *mem_ctx, int argc,
+                                         const char **argv)
+{
+       NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       struct netr_Authenticator credential;
+       struct netr_Authenticator return_authenticator;
+       union netr_Capabilities capabilities;
+       uint32_t level = 1;
+
+       if (argc > 2) {
+               fprintf(stderr, "Usage: %s <level>\n", argv[0]);
+               return NT_STATUS_OK;
+       }
+
+       if (argc == 2) {
+               level = atoi(argv[1]);
+       }
+
+       ZERO_STRUCT(return_authenticator);
+
+       netlogon_creds_client_authenticator(cli->dc, &credential);
+
+       status = rpccli_netr_LogonGetCapabilities(cli, mem_ctx,
+                                                 cli->desthost,
+                                                 global_myname(),
+                                                 &credential,
+                                                 &return_authenticator,
+                                                 level,
+                                                 &capabilities);
+
+       if (!netlogon_creds_client_check(cli->dc,
+                                        &return_authenticator.cred)) {
+               DEBUG(0,("credentials chain check failed\n"));
+               return NT_STATUS_ACCESS_DENIED;
+       }
+
+       printf("capabilities: 0x%08x\n", capabilities.server_capabilities);
+
+       return status;
+}
 
 /* List of commands exported by this module */
 
@@ -1029,6 +1175,9 @@ struct cmd_set netlogon_commands[] = {
        { "deregisterdnsrecords", RPC_RTYPE_WERROR, NULL, cmd_netlogon_deregisterdnsrecords, &ndr_table_netlogon.syntax_id, NULL, "Deregister DNS records",     "" },
        { "netrenumtrusteddomains", RPC_RTYPE_WERROR, NULL, cmd_netlogon_enumtrusteddomains, &ndr_table_netlogon.syntax_id, NULL, "Enumerate trusted domains",     "" },
        { "netrenumtrusteddomainsex", RPC_RTYPE_WERROR, NULL, cmd_netlogon_enumtrusteddomainsex, &ndr_table_netlogon.syntax_id, NULL, "Enumerate trusted domains",     "" },
+       { "getdcsitecoverage", RPC_RTYPE_WERROR, NULL, cmd_netlogon_getdcsitecoverage, &ndr_table_netlogon.syntax_id, NULL, "Get the Site-Coverage from a DC",     "" },
+       { "database_redo", RPC_RTYPE_NTSTATUS, cmd_netlogon_database_redo, NULL, &ndr_table_netlogon.syntax_id, NULL, "Replicate single object from a DC",     "" },
+       { "capabilities", RPC_RTYPE_NTSTATUS, cmd_netlogon_capabilities, NULL, &ndr_table_netlogon.syntax_id, NULL, "Return Capabilities",     "" },
 
        { NULL }
 };