summaryrefslogtreecommitdiff
path: root/source3/rpcclient/cmd_netlogon.c
diff options
context:
space:
mode:
authorKarolin Seeger <kseeger@samba.org>2008-02-29 10:44:38 +0100
committerKarolin Seeger <kseeger@samba.org>2008-02-29 10:44:38 +0100
commitc4fbe2846231a6b322c1094c6a1dbf93b7305768 (patch)
tree09eb77a294f4acda131b41fe4c9bec4ed175eb16 /source3/rpcclient/cmd_netlogon.c
parent1a6415fc77c708b87c8e2ce6e7828f486ffc87ac (diff)
parent695b6662abe64a40061bfa05ede12173fc4b1945 (diff)
downloadsamba-c4fbe2846231a6b322c1094c6a1dbf93b7305768.tar.gz
samba-c4fbe2846231a6b322c1094c6a1dbf93b7305768.tar.bz2
samba-c4fbe2846231a6b322c1094c6a1dbf93b7305768.zip
Merge commit 'origin/v3-2-test' into v3-2-stable
Conflicts: WHATSNEW.txt (This used to be commit a390bcf9403df4cf4d5eef42b35ebccbe253882e)
Diffstat (limited to 'source3/rpcclient/cmd_netlogon.c')
-rw-r--r--source3/rpcclient/cmd_netlogon.c871
1 files changed, 670 insertions, 201 deletions
diff --git a/source3/rpcclient/cmd_netlogon.c b/source3/rpcclient/cmd_netlogon.c
index 2c1f7e0f11..95d79b5825 100644
--- a/source3/rpcclient/cmd_netlogon.c
+++ b/source3/rpcclient/cmd_netlogon.c
@@ -3,6 +3,7 @@
RPC pipe client
Copyright (C) Tim Potter 2000
+ Copyright (C) Guenther Deschner 2008
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,35 +22,77 @@
#include "includes.h"
#include "rpcclient.h"
-static NTSTATUS cmd_netlogon_logon_ctrl2(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx, int argc,
- const char **argv)
+static WERROR cmd_netlogon_logon_ctrl2(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ const char **argv)
{
- uint32 query_level = 1;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ WERROR werr;
+ const char *logon_server = cli->cli->desthost;
+ enum netr_LogonControlCode function_code = NETLOGON_CONTROL_REDISCOVER;
+ uint32_t level = 1;
+ union netr_CONTROL_DATA_INFORMATION data;
+ union netr_CONTROL_QUERY_INFORMATION query;
+ const char *domain = lp_workgroup();
+
+ if (argc > 5) {
+ fprintf(stderr, "Usage: %s <logon_server> <function_code> "
+ "<level> <domain>\n", argv[0]);
+ return WERR_OK;
+ }
- if (argc > 1) {
- fprintf(stderr, "Usage: %s\n", argv[0]);
- return NT_STATUS_OK;
+ if (argc >= 2) {
+ logon_server = argv[1];
}
- result = rpccli_netlogon_logon_ctrl2(cli, mem_ctx, query_level);
+ if (argc >= 3) {
+ function_code = atoi(argv[2]);
+ }
- if (!NT_STATUS_IS_OK(result))
- goto done;
+ if (argc >= 4) {
+ level = atoi(argv[3]);
+ }
+
+ if (argc >= 5) {
+ domain = argv[4];
+ }
+
+ switch (function_code) {
+ case NETLOGON_CONTROL_REDISCOVER:
+ case NETLOGON_CONTROL_TC_QUERY:
+ data.domain = domain;
+ break;
+ default:
+ break;
+ }
+
+ status = rpccli_netr_LogonControl2(cli, mem_ctx,
+ logon_server,
+ function_code,
+ level,
+ &data,
+ &query,
+ &werr);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ntstatus_to_werror(status);
+ }
+
+ if (!W_ERROR_IS_OK(werr)) {
+ return werr;
+ }
/* Display results */
- done:
- return result;
+ return werr;
}
static WERROR cmd_netlogon_getanydcname(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
- char *dcname = NULL;
- WERROR result = WERR_GENERAL_FAILURE;
+ const char *dcname = NULL;
+ WERROR werr;
+ NTSTATUS status;
int old_timeout;
if (argc != 2) {
@@ -60,27 +103,35 @@ static WERROR cmd_netlogon_getanydcname(struct rpc_pipe_client *cli,
/* Make sure to wait for our DC's reply */
old_timeout = cli_set_timeout(cli->cli, MAX(cli->cli->timeout,30000)); /* 30 seconds. */
- result = rpccli_netlogon_getanydcname(cli, mem_ctx, cli->cli->desthost, argv[1], &dcname);
-
+ status = rpccli_netr_GetAnyDCName(cli, mem_ctx,
+ cli->cli->desthost,
+ argv[1],
+ &dcname,
+ &werr);
cli_set_timeout(cli->cli, old_timeout);
- if (!W_ERROR_IS_OK(result))
- goto done;
+ if (!NT_STATUS_IS_OK(status)) {
+ return ntstatus_to_werror(status);
+ }
+
+ if (!W_ERROR_IS_OK(werr)) {
+ return werr;
+ }
/* Display results */
printf("%s\n", dcname);
- done:
- return result;
+ return werr;
}
-static WERROR cmd_netlogon_getdcname(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx, int argc,
+static WERROR cmd_netlogon_getdcname(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
- char *dcname = NULL;
- WERROR result = WERR_GENERAL_FAILURE;
+ const char *dcname = NULL;
+ NTSTATUS status;
+ WERROR werr;
int old_timeout;
if (argc != 2) {
@@ -91,32 +142,40 @@ static WERROR cmd_netlogon_getdcname(struct rpc_pipe_client *cli,
/* Make sure to wait for our DC's reply */
old_timeout = cli_set_timeout(cli->cli, MAX(cli->cli->timeout,30000)); /* 30 seconds. */
- result = rpccli_netlogon_getdcname(cli, mem_ctx, cli->cli->desthost, argv[1], &dcname);
-
+ status = rpccli_netr_GetDcName(cli, mem_ctx,
+ cli->cli->desthost,
+ argv[1],
+ &dcname,
+ &werr);
cli_set_timeout(cli->cli, old_timeout);
- if (!W_ERROR_IS_OK(result))
- goto done;
+ if (!NT_STATUS_IS_OK(status)) {
+ return ntstatus_to_werror(status);
+ }
+
+ if (!W_ERROR_IS_OK(werr)) {
+ return werr;
+ }
/* Display results */
printf("%s\n", dcname);
- done:
- return result;
+ return werr;
}
static WERROR cmd_netlogon_dsr_getdcname(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
- WERROR result;
+ NTSTATUS result;
+ WERROR werr = WERR_OK;
uint32 flags = DS_RETURN_DNS_NAME;
const char *server_name = cli->cli->desthost;
const char *domain_name;
struct GUID domain_guid = GUID_zero();
struct GUID site_guid = GUID_zero();
- struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+ struct netr_DsRGetDCNameInfo *info = NULL;
if (argc < 2) {
fprintf(stderr, "Usage: %s [domain_name] [domain_guid] "
@@ -144,20 +203,25 @@ static WERROR cmd_netlogon_dsr_getdcname(struct rpc_pipe_client *cli,
debug_dsdcinfo_flags(1,flags);
- result = rpccli_netlogon_dsr_getdcname(cli, mem_ctx, server_name, domain_name,
- &domain_guid, &site_guid, flags,
- &info);
-
- if (W_ERROR_IS_OK(result)) {
- d_printf("DsGetDcName gave\n");
- display_ds_domain_controller_info(mem_ctx, info);
+ result = rpccli_netr_DsRGetDCName(cli, mem_ctx,
+ server_name,
+ domain_name,
+ &domain_guid,
+ &site_guid,
+ flags,
+ &info,
+ &werr);
+
+ if (W_ERROR_IS_OK(werr)) {
+ d_printf("DsGetDcName gave: %s\n",
+ NDR_PRINT_STRUCT_STRING(mem_ctx, netr_DsRGetDCNameInfo, info));
return WERR_OK;
}
printf("rpccli_netlogon_dsr_getdcname returned %s\n",
- dos_errstr(result));
+ dos_errstr(werr));
- return result;
+ return werr;
}
static WERROR cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client *cli,
@@ -165,12 +229,13 @@ static WERROR cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client *cli,
const char **argv)
{
WERROR result;
- uint32 flags = DS_RETURN_DNS_NAME;
+ NTSTATUS status;
+ uint32_t flags = DS_RETURN_DNS_NAME;
const char *server_name = cli->cli->desthost;
const char *domain_name;
const char *site_name = NULL;
struct GUID domain_guid = GUID_zero();
- struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+ struct netr_DsRGetDCNameInfo *info = NULL;
if (argc < 2) {
fprintf(stderr, "Usage: %s [domain_name] [domain_guid] "
@@ -178,8 +243,7 @@ static WERROR cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client *cli,
return WERR_OK;
}
- if (argc >= 2)
- domain_name = argv[1];
+ domain_name = argv[1];
if (argc >= 3) {
if (!NT_STATUS_IS_OK(GUID_from_string(argv[2], &domain_guid))) {
@@ -187,26 +251,34 @@ static WERROR cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client *cli,
}
}
- if (argc >= 4)
+ if (argc >= 4) {
site_name = argv[3];
+ }
- if (argc >= 5)
+ if (argc >= 5) {
sscanf(argv[4], "%x", &flags);
+ }
debug_dsdcinfo_flags(1,flags);
- result = rpccli_netlogon_dsr_getdcnameex(cli, mem_ctx, server_name, domain_name,
- &domain_guid, site_name, flags,
- &info);
+ status = rpccli_netr_DsRGetDCNameEx(cli, mem_ctx,
+ server_name,
+ domain_name,
+ &domain_guid,
+ site_name,
+ flags,
+ &info,
+ &result);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ntstatus_to_werror(status);
+ }
- if (W_ERROR_IS_OK(result)) {
- d_printf("DsGetDcNameEx gave\n");
- display_ds_domain_controller_info(mem_ctx, info);
- return WERR_OK;
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
}
- printf("rpccli_netlogon_dsr_getdcnameex returned %s\n",
- dos_errstr(result));
+ d_printf("DsRGetDCNameEx gave %s\n",
+ NDR_PRINT_STRUCT_STRING(mem_ctx, netr_DsRGetDCNameInfo, info));
return result;
}
@@ -216,14 +288,15 @@ static WERROR cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client *cli,
const char **argv)
{
WERROR result;
- uint32 flags = DS_RETURN_DNS_NAME;
+ NTSTATUS status;
+ uint32_t flags = DS_RETURN_DNS_NAME;
const char *server_name = cli->cli->desthost;
const char *domain_name = NULL;
const char *client_account = NULL;
- uint32 mask = 0;
+ uint32_t mask = 0;
const char *site_name = NULL;
struct GUID domain_guid = GUID_zero();
- struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+ struct netr_DsRGetDCNameInfo *info = NULL;
if (argc < 2) {
fprintf(stderr, "Usage: %s [client_account] [acb_mask] "
@@ -232,14 +305,17 @@ static WERROR cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client *cli,
return WERR_OK;
}
- if (argc >= 2)
+ if (argc >= 2) {
client_account = argv[1];
+ }
- if (argc >= 3)
+ if (argc >= 3) {
mask = atoi(argv[2]);
+ }
- if (argc >= 4)
+ if (argc >= 4) {
domain_name = argv[3];
+ }
if (argc >= 5) {
if (!NT_STATUS_IS_OK(GUID_from_string(argv[4], &domain_guid))) {
@@ -247,28 +323,36 @@ static WERROR cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client *cli,
}
}
- if (argc >= 6)
+ if (argc >= 6) {
site_name = argv[5];
+ }
- if (argc >= 7)
+ if (argc >= 7) {
sscanf(argv[6], "%x", &flags);
+ }
debug_dsdcinfo_flags(1,flags);
- result = rpccli_netlogon_dsr_getdcnameex2(cli, mem_ctx, server_name,
- client_account, mask,
- domain_name, &domain_guid,
- site_name, flags,
- &info);
+ status = rpccli_netr_DsRGetDCNameEx2(cli, mem_ctx,
+ server_name,
+ client_account,
+ mask,
+ domain_name,
+ &domain_guid,
+ site_name,
+ flags,
+ &info,
+ &result);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ntstatus_to_werror(status);
+ }
- if (W_ERROR_IS_OK(result)) {
- d_printf("DsGetDcNameEx2 gave\n");
- display_ds_domain_controller_info(mem_ctx, info);
- return WERR_OK;
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
}
- printf("rpccli_netlogon_dsr_getdcnameex2 returned %s\n",
- dos_errstr(result));
+ d_printf("DsRGetDCNameEx2 gave %s\n",
+ NDR_PRINT_STRUCT_STRING(mem_ctx, netr_DsRGetDCNameInfo, info));
return result;
}
@@ -278,20 +362,27 @@ static WERROR cmd_netlogon_dsr_getsitename(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
- WERROR result;
- char *sitename;
+ WERROR werr;
+ NTSTATUS status;
+ const char *sitename = NULL;
if (argc != 2) {
fprintf(stderr, "Usage: %s computername\n", argv[0]);
return WERR_OK;
}
- result = rpccli_netlogon_dsr_getsitename(cli, mem_ctx, argv[1], &sitename);
+ status = rpccli_netr_DsRGetSiteName(cli, mem_ctx,
+ argv[1],
+ &sitename,
+ &werr);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ntstatus_to_werror(status);
+ }
- if (!W_ERROR_IS_OK(result)) {
+ if (!W_ERROR_IS_OK(werr)) {
printf("rpccli_netlogon_dsr_gesitename returned %s\n",
- nt_errstr(werror_to_ntstatus(result)));
- return result;
+ nt_errstr(werror_to_ntstatus(werr)));
+ return werr;
}
printf("Computer %s is on Site: %s\n", argv[1], sitename);
@@ -299,169 +390,292 @@ static WERROR cmd_netlogon_dsr_getsitename(struct rpc_pipe_client *cli,
return WERR_OK;
}
-static NTSTATUS cmd_netlogon_logon_ctrl(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx, int argc,
- const char **argv)
+static WERROR cmd_netlogon_logon_ctrl(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ const char **argv)
{
-#if 0
- uint32 query_level = 1;
-#endif
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ WERROR werr;
+ const char *logon_server = cli->cli->desthost;
+ enum netr_LogonControlCode function_code = 1;
+ uint32_t level = 1;
+ union netr_CONTROL_QUERY_INFORMATION info;
+
+ if (argc > 4) {
+ fprintf(stderr, "Usage: %s <logon_server> <function_code> "
+ "<level>\n", argv[0]);
+ return WERR_OK;
+ }
- if (argc > 1) {
- fprintf(stderr, "Usage: %s\n", argv[0]);
- return NT_STATUS_OK;
+ if (argc >= 2) {
+ logon_server = argv[1];
}
-#if 0
- result = cli_netlogon_logon_ctrl(cli, mem_ctx, query_level);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
+ if (argc >= 3) {
+ function_code = atoi(argv[2]);
+ }
+
+ if (argc >= 4) {
+ level = atoi(argv[3]);
+ }
+
+ status = rpccli_netr_LogonControl(cli, mem_ctx,
+ logon_server,
+ function_code,
+ level,
+ &info,
+ &werr);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ntstatus_to_werror(status);
+ }
+
+ if (!W_ERROR_IS_OK(werr)) {
+ return werr;
}
-#endif
/* Display results */
- return result;
+ return werr;
}
/* Display sam synchronisation information */
-static void display_sam_sync(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas,
- SAM_DELTA_CTR *deltas)
+static void display_sam_sync(struct netr_DELTA_ENUM_ARRAY *r)
{
- fstring name;
- uint32 i, j;
-
- for (i = 0; i < num_deltas; i++) {
- switch (hdr_deltas[i].type) {
- case SAM_DELTA_DOMAIN_INFO:
- unistr2_to_ascii(name,
- &deltas[i].domain_info.uni_dom_name,
- sizeof(name));
- printf("Domain: %s\n", name);
- break;
- case SAM_DELTA_GROUP_INFO:
- unistr2_to_ascii(name,
- &deltas[i].group_info.uni_grp_name,
- sizeof(name));
- printf("Group: %s\n", name);
- break;
- case SAM_DELTA_ACCOUNT_INFO:
- unistr2_to_ascii(name,
- &deltas[i].account_info.uni_acct_name,
- sizeof(name));
- printf("Account: %s\n", name);
- break;
- case SAM_DELTA_ALIAS_INFO:
- unistr2_to_ascii(name,
- &deltas[i].alias_info.uni_als_name,
- sizeof(name));
- printf("Alias: %s\n", name);
- break;
- case SAM_DELTA_ALIAS_MEM: {
- SAM_ALIAS_MEM_INFO *alias = &deltas[i].als_mem_info;
-
- for (j = 0; j < alias->num_members; j++) {
- fstring sid_str;
-
- sid_to_fstring(sid_str, &alias->sids[j].sid);
-
- printf("%s\n", sid_str);
- }
- break;
- }
- case SAM_DELTA_GROUP_MEM: {
- SAM_GROUP_MEM_INFO *group = &deltas[i].grp_mem_info;
-
- for (j = 0; j < group->num_members; j++)
- printf("rid 0x%x, attrib 0x%08x\n",
- group->rids[j], group->attribs[j]);
- break;
- }
- case SAM_DELTA_MODIFIED_COUNT: {
- SAM_DELTA_MOD_COUNT *mc = &deltas[i].mod_count;
-
- printf("sam sequence update: 0x%04x\n", mc->seqnum);
- break;
- }
- default:
- printf("unknown delta type 0x%02x\n",
- hdr_deltas[i].type);
- break;
- }
- }
+ uint32_t i, j;
+
+ for (i=0; i < r->num_deltas; i++) {
+
+ union netr_DELTA_UNION u = r->delta_enum[i].delta_union;
+ union netr_DELTA_ID_UNION id = r->delta_enum[i].delta_id_union;
+
+ switch (r->delta_enum[i].delta_type) {
+ case NETR_DELTA_DOMAIN:
+ printf("Domain: %s\n",
+ u.domain->domain_name.string);
+ break;
+ case NETR_DELTA_GROUP:
+ printf("Group: %s\n",
+ u.group->group_name.string);
+ break;
+ case NETR_DELTA_DELETE_GROUP:
+ printf("Delete Group: %d\n",
+ u.delete_account.unknown);
+ break;
+ case NETR_DELTA_RENAME_GROUP:
+ printf("Rename Group: %s -> %s\n",
+ u.rename_group->OldName.string,
+ u.rename_group->NewName.string);
+ break;
+ case NETR_DELTA_USER:
+ printf("Account: %s\n",
+ u.user->account_name.string);
+ break;
+ case NETR_DELTA_DELETE_USER:
+ printf("Delete User: %d\n",
+ id.rid);
+ break;
+ case NETR_DELTA_RENAME_USER:
+ printf("Rename user: %s -> %s\n",
+ u.rename_user->OldName.string,
+ u.rename_user->NewName.string);
+ break;
+ case NETR_DELTA_GROUP_MEMBER:
+ for (j=0; j < u.group_member->num_rids; j++) {
+ printf("rid 0x%x, attrib 0x%08x\n",
+ u.group_member->rids[j],
+ u.group_member->attribs[j]);
+ }
+ break;
+ case NETR_DELTA_ALIAS:
+ printf("Alias: %s\n",
+ u.alias->alias_name.string);
+ break;
+ case NETR_DELTA_DELETE_ALIAS:
+ printf("Delete Alias: %d\n",
+ r->delta_enum[i].delta_id_union.rid);
+ break;
+ case NETR_DELTA_RENAME_ALIAS:
+ printf("Rename alias: %s -> %s\n",
+ u.rename_alias->OldName.string,
+ u.rename_alias->NewName.string);
+ break;
+ case NETR_DELTA_ALIAS_MEMBER:
+ for (j=0; j < u.alias_member->sids.num_sids; j++) {
+ fstring sid_str;
+ sid_to_fstring(sid_str,
+ u.alias_member->sids.sids[j].sid);
+ printf("%s\n", sid_str);
+ }
+ break;
+ case NETR_DELTA_POLICY:
+ printf("Policy\n");
+ break;
+ case NETR_DELTA_TRUSTED_DOMAIN:
+ printf("Trusted Domain: %s\n",
+ u.trusted_domain->domain_name.string);
+ break;
+ case NETR_DELTA_DELETE_TRUST:
+ printf("Delete Trust: %d\n",
+ u.delete_trust.unknown);
+ break;
+ case NETR_DELTA_ACCOUNT:
+ printf("Account\n");
+ break;
+ case NETR_DELTA_DELETE_ACCOUNT:
+ printf("Delete Account: %d\n",
+ u.delete_account.unknown);
+ break;
+ case NETR_DELTA_SECRET:
+ printf("Secret\n");
+ break;
+ case NETR_DELTA_DELETE_SECRET:
+ printf("Delete Secret: %d\n",
+ u.delete_secret.unknown);
+ break;
+ case NETR_DELTA_DELETE_GROUP2:
+ printf("Delete Group2: %s\n",
+ u.delete_group->account_name);
+ break;
+ case NETR_DELTA_DELETE_USER2:
+ printf("Delete User2: %s\n",
+ u.delete_user->account_name);
+ break;
+ case NETR_DELTA_MODIFY_COUNT:
+ printf("sam sequence update: 0x%016llx\n",
+ (unsigned long long) *u.modified_count);
+ break;
+ default:
+ printf("unknown delta type 0x%02x\n",
+ r->delta_enum[i].delta_type);
+ break;
+ }
+ }
}
/* Perform sam synchronisation */
-static NTSTATUS cmd_netlogon_sam_sync(struct rpc_pipe_client *cli,
+static NTSTATUS cmd_netlogon_sam_sync(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 database_id = 0, num_deltas;
- SAM_DELTA_HDR *hdr_deltas;
- SAM_DELTA_CTR *deltas;
+ const char *logon_server = cli->cli->desthost;
+ const char *computername = global_myname();
+ struct netr_Authenticator credential;
+ struct netr_Authenticator return_authenticator;
+ enum netr_SamDatabaseID database_id = SAM_DATABASE_DOMAIN;
+ uint16_t restart_state = 0;
+ uint32_t sync_context = 0;
if (argc > 2) {
fprintf(stderr, "Usage: %s [database_id]\n", argv[0]);
return NT_STATUS_OK;
}
- if (argc == 2)
- database_id = atoi(argv[1]);
+ if (argc == 2) {
+ database_id = atoi(argv[1]);
+ }
- /* Synchronise sam database */
+ /* Synchronise sam database */
+
+ do {
+ struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
+
+ netlogon_creds_client_step(cli->dc, &credential);
+
+ result = rpccli_netr_DatabaseSync2(cli, mem_ctx,
+ logon_server,
+ computername,
+ &credential,
+ &return_authenticator,
+ database_id,
+ restart_state,
+ &sync_context,
+ &delta_enum_array,
+ 0xffff);
+
+ /* Check returned credentials. */
+ if (!netlogon_creds_client_check(cli->dc,
+ &return_authenticator.cred)) {
+ DEBUG(0,("credentials chain check failed\n"));
+ return NT_STATUS_ACCESS_DENIED;
+ }
- result = rpccli_netlogon_sam_sync(cli, mem_ctx, database_id,
- 0, &num_deltas, &hdr_deltas, &deltas);
+ if (NT_STATUS_IS_ERR(result)) {
+ break;
+ }
- if (!NT_STATUS_IS_OK(result))
- goto done;
+ /* Display results */
- /* Display results */
+ display_sam_sync(delta_enum_array);
- display_sam_sync(num_deltas, hdr_deltas, deltas);
+ TALLOC_FREE(delta_enum_array);
- done:
- return result;
+ } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
+
+ return result;
}
/* Perform sam delta synchronisation */
-static NTSTATUS cmd_netlogon_sam_deltas(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx, int argc,
- const char **argv)
+static NTSTATUS cmd_netlogon_sam_deltas(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ const char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 database_id, num_deltas, tmp;
- SAM_DELTA_HDR *hdr_deltas;
- SAM_DELTA_CTR *deltas;
- uint64 seqnum;
+ uint32_t tmp;
+ const char *logon_server = cli->cli->desthost;
+ const char *computername = global_myname();
+ struct netr_Authenticator credential;
+ struct netr_Authenticator return_authenticator;
+ enum netr_SamDatabaseID database_id = SAM_DATABASE_DOMAIN;
+ uint64_t sequence_num;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
+ return NT_STATUS_OK;
+ }
- if (argc != 3) {
- fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
- return NT_STATUS_OK;
- }
+ database_id = atoi(argv[1]);
+ tmp = atoi(argv[2]);
- database_id = atoi(argv[1]);
- tmp = atoi(argv[2]);
+ sequence_num = tmp & 0xffff;
- seqnum = tmp & 0xffff;
+ do {
+ struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
- result = rpccli_netlogon_sam_deltas(cli, mem_ctx, database_id,
- seqnum, &num_deltas,
- &hdr_deltas, &deltas);
+ netlogon_creds_client_step(cli->dc, &credential);
- if (!NT_STATUS_IS_OK(result))
- goto done;
+ result = rpccli_netr_DatabaseDeltas(cli, mem_ctx,
+ logon_server,
+ computername,
+ &credential,
+ &return_authenticator,
+ database_id,
+ &sequence_num,
+ &delta_enum_array,
+ 0xffff);
- /* Display results */
+ /* Check returned credentials. */
+ if (!netlogon_creds_client_check(cli->dc,
+ &return_authenticator.cred)) {
+ DEBUG(0,("credentials chain check failed\n"));
+ return NT_STATUS_ACCESS_DENIED;
+ }
+
+ if (NT_STATUS_IS_ERR(result)) {
+ break;
+ }
+
+ /* Display results */
+
+ display_sam_sync(delta_enum_array);
+
+ TALLOC_FREE(delta_enum_array);
+
+ } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
- display_sam_sync(num_deltas, hdr_deltas, deltas);
-
- done:
return result;
}
@@ -539,6 +753,254 @@ static NTSTATUS cmd_netlogon_change_trust_pw(struct rpc_pipe_client *cli,
return result;
}
+static WERROR cmd_netlogon_gettrustrid(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->cli->desthost;
+ const char *domain_name = lp_workgroup();
+ uint32_t rid = 0;
+
+ if (argc < 1 || argc > 3) {
+ fprintf(stderr, "Usage: %s <server_name> <domain_name>\n",
+ argv[0]);
+ return WERR_OK;
+ }
+
+ if (argc >= 2) {
+ server_name = argv[1];
+ }
+
+ if (argc >= 3) {
+ domain_name = argv[2];
+ }
+
+ status = rpccli_netr_LogonGetTrustRid(cli, mem_ctx,
+ server_name,
+ domain_name,
+ &rid,
+ &werr);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ if (W_ERROR_IS_OK(werr)) {
+ printf("Rid: %d\n", rid);
+ }
+ done:
+ return werr;
+}
+
+static WERROR cmd_netlogon_dsr_enumtrustdom(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->cli->desthost;
+ uint32_t trust_flags = NETR_TRUST_FLAG_IN_FOREST;
+ struct netr_DomainTrustList trusts;
+
+ if (argc < 1 || argc > 3) {
+ fprintf(stderr, "Usage: %s <server_name> <trust_flags>\n",
+ argv[0]);
+ return WERR_OK;
+ }
+
+ if (argc >= 2) {
+ server_name = argv[1];
+ }
+
+ if (argc >= 3) {
+ sscanf(argv[2], "%x", &trust_flags);
+ }
+
+ status = rpccli_netr_DsrEnumerateDomainTrusts(cli, mem_ctx,
+ server_name,
+ trust_flags,
+ &trusts,
+ &werr);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ if (W_ERROR_IS_OK(werr)) {
+ int i;
+
+ printf("%d domains returned\n", trusts.count);
+
+ for (i=0; i<trusts.count; i++ ) {
+ printf("%s (%s)\n",
+ trusts.array[i].dns_name,
+ trusts.array[i].netbios_name);
+ }
+ }
+ done:
+ return werr;
+}
+
+static WERROR cmd_netlogon_deregisterdnsrecords(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->cli->desthost;
+ const char *domain = lp_workgroup();
+ const char *dns_host = NULL;
+
+ if (argc < 1 || argc > 4) {
+ fprintf(stderr, "Usage: %s <server_name> <domain_name> "
+ "<dns_host>\n", argv[0]);
+ return WERR_OK;
+ }
+
+ if (argc >= 2) {
+ server_name = argv[1];
+ }
+
+ if (argc >= 3) {
+ domain = argv[2];
+ }
+
+ if (argc >= 4) {
+ dns_host = argv[3];
+ }
+
+ status = rpccli_netr_DsrDeregisterDNSHostRecords(cli, mem_ctx,
+ server_name,
+ domain,
+ NULL,
+ NULL,
+ dns_host,
+ &werr);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ if (W_ERROR_IS_OK(werr)) {
+ printf("success\n");
+ }
+ done:
+ return werr;
+}
+
+static WERROR cmd_netlogon_dsr_getforesttrustinfo(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->cli->desthost;
+ const char *trusted_domain_name = NULL;
+ struct lsa_ForestTrustInformation *info = NULL;
+ uint32_t flags = 0;
+
+ if (argc < 1 || argc > 4) {
+ fprintf(stderr, "Usage: %s <server_name> <trusted_domain_name> "
+ "<flags>\n", argv[0]);
+ return WERR_OK;
+ }
+
+ if (argc >= 2) {
+ server_name = argv[1];
+ }
+
+ if (argc >= 3) {
+ trusted_domain_name = argv[2];
+ }
+
+ if (argc >= 4) {
+ sscanf(argv[3], "%x", &flags);
+ }
+
+ status = rpccli_netr_DsRGetForestTrustInformation(cli, mem_ctx,
+ server_name,
+ trusted_domain_name,
+ flags,
+ &info,
+ &werr);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ if (W_ERROR_IS_OK(werr)) {
+ printf("success\n");
+ }
+ done:
+ return werr;
+}
+
+static WERROR cmd_netlogon_enumtrusteddomains(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->cli->desthost;
+ struct netr_Blob blob;
+
+
+ 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_NetrEnumerateTrustedDomains(cli, mem_ctx,
+ server_name,
+ &blob,
+ &werr);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ if (W_ERROR_IS_OK(werr)) {
+ printf("success\n");
+ dump_data(1, blob.data, blob.length);
+ }
+ done:
+ return werr;
+}
+
+static WERROR cmd_netlogon_enumtrusteddomainsex(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->cli->desthost;
+ struct netr_DomainTrustList list;
+
+ 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_NetrEnumerateTrustedDomainsEx(cli, mem_ctx,
+ server_name,
+ &list,
+ &werr);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ if (W_ERROR_IS_OK(werr)) {
+ printf("success\n");
+ }
+ done:
+ return werr;
+}
+
/* List of commands exported by this module */
@@ -546,18 +1008,25 @@ struct cmd_set netlogon_commands[] = {
{ "NETLOGON" },
- { "logonctrl2", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl2, NULL, PI_NETLOGON, NULL, "Logon Control 2", "" },
+ { "logonctrl2", RPC_RTYPE_WERROR, NULL, cmd_netlogon_logon_ctrl2, PI_NETLOGON, NULL, "Logon Control 2", "" },
{ "getanydcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_getanydcname, PI_NETLOGON, NULL, "Get trusted DC name", "" },
{ "getdcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_getdcname, PI_NETLOGON, NULL, "Get trusted PDC name", "" },
{ "dsr_getdcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcname, PI_NETLOGON, NULL, "Get trusted DC name", "" },
{ "dsr_getdcnameex", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcnameex, PI_NETLOGON, NULL, "Get trusted DC name", "" },
{ "dsr_getdcnameex2", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcnameex2, PI_NETLOGON, NULL, "Get trusted DC name", "" },
{ "dsr_getsitename", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getsitename, PI_NETLOGON, NULL, "Get sitename", "" },
- { "logonctrl", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl, NULL, PI_NETLOGON, NULL, "Logon Control", "" },
+ { "dsr_getforesttrustinfo", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getforesttrustinfo, PI_NETLOGON, NULL, "Get Forest Trust Info", "" },
+ { "logonctrl", RPC_RTYPE_WERROR, NULL, cmd_netlogon_logon_ctrl, PI_NETLOGON, NULL, "Logon Control", "" },
{ "samsync", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync, NULL, PI_NETLOGON, NULL, "Sam Synchronisation", "" },
{ "samdeltas", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas, NULL, PI_NETLOGON, NULL, "Query Sam Deltas", "" },
{ "samlogon", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_logon, NULL, PI_NETLOGON, NULL, "Sam Logon", "" },
{ "change_trust_pw", RPC_RTYPE_NTSTATUS, cmd_netlogon_change_trust_pw, NULL, PI_NETLOGON, NULL, "Change Trust Account Password", "" },
+ { "gettrustrid", RPC_RTYPE_WERROR, NULL, cmd_netlogon_gettrustrid, PI_NETLOGON, NULL, "Get trust rid", "" },
+ { "dsr_enumtrustdom", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_enumtrustdom, PI_NETLOGON, NULL, "Enumerate trusted domains", "" },
+ { "dsenumdomtrusts", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_enumtrustdom, PI_NETLOGON, NULL, "Enumerate all trusted domains in an AD forest", "" },
+ { "deregisterdnsrecords", RPC_RTYPE_WERROR, NULL, cmd_netlogon_deregisterdnsrecords, PI_NETLOGON, NULL, "Deregister DNS records", "" },
+ { "netrenumtrusteddomains", RPC_RTYPE_WERROR, NULL, cmd_netlogon_enumtrusteddomains, PI_NETLOGON, NULL, "Enumerate trusted domains", "" },
+ { "netrenumtrusteddomainsex", RPC_RTYPE_WERROR, NULL, cmd_netlogon_enumtrusteddomainsex, PI_NETLOGON, NULL, "Enumerate trusted domains", "" },
{ NULL }
};