From 61b68fc43cda3fbee8b0c4fa8fbc9bd56fb98924 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 13 Jun 2008 11:57:09 +0200 Subject: samsync: add samsync_fix_delta_array() This code is vastly based on samba4 code. Guenther (cherry picked from commit 5b68be96996a710988b1fd1c176cd5dff0f2c6af) (This used to be commit 2c53d87de4ecc5ac9c43bc7488a03bceecf35140) --- source3/libnet/libnet_samsync.c | 188 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 source3/libnet/libnet_samsync.c (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c new file mode 100644 index 0000000000..e45a84568c --- /dev/null +++ b/source3/libnet/libnet_samsync.c @@ -0,0 +1,188 @@ +/* + Unix SMB/CIFS implementation. + + Extract the user/system database from a remote SamSync server + + Copyright (C) Andrew Bartlett 2004-2005 + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#include "includes.h" + +/** + * Decrypt and extract the user's passwords. + * + * The writes decrypted (no longer 'RID encrypted' or arcfour encrypted) + * passwords back into the structure + */ + +static NTSTATUS fix_user(TALLOC_CTX *mem_ctx, + DATA_BLOB *session_key, + bool rid_crypt, + enum netr_SamDatabaseID database_id, + struct netr_DELTA_ENUM *delta) +{ + + uint32_t rid = delta->delta_id_union.rid; + struct netr_DELTA_USER *user = delta->delta_union.user; + struct samr_Password lm_hash; + struct samr_Password nt_hash; + const char *username = user->account_name.string; + + if (rid_crypt) { + if (user->lm_password_present) { + sam_pwd_hash(rid, user->lmpassword.hash, lm_hash.hash, 0); + user->lmpassword = lm_hash; + } + + if (user->nt_password_present) { + sam_pwd_hash(rid, user->ntpassword.hash, nt_hash.hash, 0); + user->ntpassword = nt_hash; + } + } + + if (user->user_private_info.SensitiveData) { + DATA_BLOB data; + struct netr_USER_KEYS keys; + enum ndr_err_code ndr_err; + data.data = user->user_private_info.SensitiveData; + data.length = user->user_private_info.DataLength; + SamOEMhashBlob(data.data, data.length, session_key); + user->user_private_info.SensitiveData = data.data; + user->user_private_info.DataLength = data.length; + + ndr_err = ndr_pull_struct_blob(&data, mem_ctx, &keys, + (ndr_pull_flags_fn_t)ndr_pull_netr_USER_KEYS); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + dump_data(10, data.data, data.length); + return ndr_map_error2ntstatus(ndr_err); + } + + if (keys.keys.keys2.lmpassword.length == 16) { + if (rid_crypt) { + sam_pwd_hash(rid, + keys.keys.keys2.lmpassword.pwd.hash, + lm_hash.hash, 0); + user->lmpassword = lm_hash; + } else { + user->lmpassword = keys.keys.keys2.lmpassword.pwd; + } + user->lm_password_present = true; + } + if (keys.keys.keys2.ntpassword.length == 16) { + if (rid_crypt) { + sam_pwd_hash(rid, + keys.keys.keys2.ntpassword.pwd.hash, + nt_hash.hash, 0); + user->ntpassword = nt_hash; + } else { + user->ntpassword = keys.keys.keys2.ntpassword.pwd; + } + user->nt_password_present = true; + } + /* TODO: rid decrypt history fields */ + } + return NT_STATUS_OK; +} + +/** + * Decrypt and extract the secrets + * + * The writes decrypted secrets back into the structure + */ +static NTSTATUS fix_secret(TALLOC_CTX *mem_ctx, + DATA_BLOB *session_key, + enum netr_SamDatabaseID database_id, + struct netr_DELTA_ENUM *delta) +{ + struct netr_DELTA_SECRET *secret = delta->delta_union.secret; + + SamOEMhashBlob(secret->current_cipher.cipher_data, + secret->current_cipher.maxlen, + session_key); + + SamOEMhashBlob(secret->old_cipher.cipher_data, + secret->old_cipher.maxlen, + session_key); + + return NT_STATUS_OK; +} + +/** + * Fix up the delta, dealing with encryption issues so that the final + * callback need only do the printing or application logic + */ + +static NTSTATUS samsync_fix_delta(TALLOC_CTX *mem_ctx, + DATA_BLOB *session_key, + bool rid_crypt, + enum netr_SamDatabaseID database_id, + struct netr_DELTA_ENUM *delta) +{ + NTSTATUS status = NT_STATUS_OK; + + switch (delta->delta_type) { + case NETR_DELTA_USER: + + status = fix_user(mem_ctx, + session_key, + rid_crypt, + database_id, + delta); + break; + case NETR_DELTA_SECRET: + + status = fix_secret(mem_ctx, + session_key, + database_id, + delta); + break; + default: + break; + } + + return status; +} + +/** + * Fix up the delta, dealing with encryption issues so that the final + * callback need only do the printing or application logic + */ + +NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx, + DATA_BLOB *session_key, + bool rid_crypt, + enum netr_SamDatabaseID database_id, + struct netr_DELTA_ENUM_ARRAY *r) +{ + NTSTATUS status; + int i; + + for (i = 0; i < r->num_deltas; i++) { + + status = samsync_fix_delta(mem_ctx, + session_key, + rid_crypt, + database_id, + &r->delta_enum[i]); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + } + + return NT_STATUS_OK; +} -- cgit From ccdcbc2efe86cde991a1cafdb2b098db41b163fd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 16 Jun 2008 12:09:08 +0200 Subject: net_vampire: move some samsync functions to libnet. Guenther (This used to be commit b3b6af0a3e25fab0a14c9c802dbabd3d03448ebe) --- source3/libnet/libnet_samsync.c | 164 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index e45a84568c..d6331fd08c 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -22,6 +22,7 @@ #include "includes.h" +#include "libnet/libnet_samsync.h" /** * Decrypt and extract the user's passwords. @@ -186,3 +187,166 @@ NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } + +/** + * samsync_init_context + */ + +NTSTATUS samsync_init_context(TALLOC_CTX *mem_ctx, + const struct dom_sid *domain_sid, + enum net_samsync_mode mode, + struct samsync_context **ctx_p) +{ + struct samsync_context *ctx; + + *ctx_p = NULL; + + ctx = TALLOC_ZERO_P(mem_ctx, struct samsync_context); + NT_STATUS_HAVE_NO_MEMORY(ctx); + + ctx->mode = mode; + + if (domain_sid) { + ctx->domain_sid = sid_dup_talloc(mem_ctx, domain_sid); + NT_STATUS_HAVE_NO_MEMORY(ctx->domain_sid); + + ctx->domain_sid_str = sid_string_talloc(mem_ctx, ctx->domain_sid); + NT_STATUS_HAVE_NO_MEMORY(ctx->domain_sid_str); + } + + *ctx_p = ctx; + + return NT_STATUS_OK; +} + +/** + * samsync_debug_str + */ + +static const char *samsync_debug_str(TALLOC_CTX *mem_ctx, + enum net_samsync_mode mode, + enum netr_SamDatabaseID database_id) +{ + const char *action = NULL; + const char *str = NULL; + + switch (mode) { + case NET_SAMSYNC_MODE_DUMP: + action = "Dumping (to stdout)"; + break; + case NET_SAMSYNC_MODE_FETCH_PASSDB: + action = "Fetching (to passdb)"; + break; + case NET_SAMSYNC_MODE_FETCH_LDIF: + action = "Fetching (to ldif)"; + break; + default: + action = "Unknown"; + break; + } + + switch (database_id) { + case SAM_DATABASE_DOMAIN: + str = talloc_asprintf(mem_ctx, "%s DOMAIN database", + action); + break; + case SAM_DATABASE_BUILTIN: + str = talloc_asprintf(mem_ctx, "%s BUILTIN database", + action); + break; + case SAM_DATABASE_PRIVS: + str = talloc_asprintf(mem_ctx, "%s PRIVS database", + action); + break; + default: + str = talloc_asprintf(mem_ctx, "%s unknown database type %u", + action, database_id); + break; + } + + return str; +} + +/** + * samsync_process_database + */ + +NTSTATUS samsync_process_database(struct rpc_pipe_client *pipe_hnd, + enum netr_SamDatabaseID database_id, + samsync_fn_t callback_fn, + struct samsync_context *ctx) +{ + NTSTATUS result; + TALLOC_CTX *mem_ctx; + const char *logon_server = pipe_hnd->desthost; + const char *computername = global_myname(); + struct netr_Authenticator credential; + struct netr_Authenticator return_authenticator; + uint16_t restart_state = 0; + uint32_t sync_context = 0; + const char *debug_str; + DATA_BLOB session_key; + + ZERO_STRUCT(return_authenticator); + + if (!(mem_ctx = talloc_init("samsync_process_database"))) { + return NT_STATUS_NO_MEMORY; + } + + debug_str = samsync_debug_str(mem_ctx, ctx->mode, database_id); + if (debug_str) { + d_fprintf(stderr, "%s\n", debug_str); + } + + do { + struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL; + + netlogon_creds_client_step(pipe_hnd->dc, &credential); + + result = rpccli_netr_DatabaseSync2(pipe_hnd, mem_ctx, + logon_server, + computername, + &credential, + &return_authenticator, + database_id, + restart_state, + &sync_context, + &delta_enum_array, + 0xffff); + if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED)) { + return result; + } + + /* Check returned credentials. */ + if (!netlogon_creds_client_check(pipe_hnd->dc, + &return_authenticator.cred)) { + DEBUG(0,("credentials chain check failed\n")); + return NT_STATUS_ACCESS_DENIED; + } + + if (NT_STATUS_IS_ERR(result)) { + break; + } + + session_key = data_blob_const(pipe_hnd->dc->sess_key, 16); + + samsync_fix_delta_array(mem_ctx, + &session_key, + true, + database_id, + delta_enum_array); + + /* Process results */ + callback_fn(mem_ctx, database_id, delta_enum_array, result, ctx); + + TALLOC_FREE(delta_enum_array); + + /* Increment sync_context */ + sync_context += 1; + + } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)); + + talloc_destroy(mem_ctx); + + return result; +} -- cgit From 0d0043697d203f89f80e8bf61cff775fc435f8f9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 17 Jun 2008 10:36:53 +0200 Subject: net_vampire: fix build warning. Guenther (This used to be commit eb4232fec05cd87ea85a781b84a3fbe85f469703) --- source3/libnet/libnet_samsync.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index d6331fd08c..ce95dcad5c 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -42,7 +42,6 @@ static NTSTATUS fix_user(TALLOC_CTX *mem_ctx, struct netr_DELTA_USER *user = delta->delta_union.user; struct samr_Password lm_hash; struct samr_Password nt_hash; - const char *username = user->account_name.string; if (rid_crypt) { if (user->lm_password_present) { -- cgit From 45bce6e50597c32265321ae608c5564ccab10382 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 17 Jun 2008 10:38:07 +0200 Subject: net_vampire: fix samsync_process_database(). Turns out the password hashes are not rid encrypted in the samsync reply. Guenther (This used to be commit 7d8d60bcbae79f3cdd55b27217145ffbd19f161d) --- source3/libnet/libnet_samsync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index ce95dcad5c..3c6a87a495 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -331,7 +331,7 @@ NTSTATUS samsync_process_database(struct rpc_pipe_client *pipe_hnd, samsync_fix_delta_array(mem_ctx, &session_key, - true, + false, database_id, delta_enum_array); -- cgit From 49b269f50fc2fc2817bdee97e9670b8579113060 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 17 Jun 2008 18:02:03 +0200 Subject: net_vampire: add domain_name to samsync_context. Guenther (This used to be commit 7e7f07ec59d23e909809ed32adc8fc399826310d) --- source3/libnet/libnet_samsync.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index 3c6a87a495..b5632aed69 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -193,6 +193,7 @@ NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx, NTSTATUS samsync_init_context(TALLOC_CTX *mem_ctx, const struct dom_sid *domain_sid, + const char *domain_name, enum net_samsync_mode mode, struct samsync_context **ctx_p) { @@ -205,6 +206,9 @@ NTSTATUS samsync_init_context(TALLOC_CTX *mem_ctx, ctx->mode = mode; + ctx->domain_name = talloc_strdup(mem_ctx, domain_name); + NT_STATUS_HAVE_NO_MEMORY(ctx->domain_name); + if (domain_sid) { ctx->domain_sid = sid_dup_talloc(mem_ctx, domain_sid); NT_STATUS_HAVE_NO_MEMORY(ctx->domain_sid); -- cgit From fefcb70f870cae351d29a937df674db8c4ee9abe Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 17 Jun 2008 19:49:58 +0200 Subject: net_vampire: add error and result_message to samsync_context. Guenther (This used to be commit e0b117200441f842fbc11cc817ab2cde4d63a22e) --- source3/libnet/libnet_samsync.c | 66 +++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index b5632aed69..c86c5c12e1 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -222,6 +222,25 @@ NTSTATUS samsync_init_context(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } +/** + * samsync_database_str + */ + +static const char *samsync_database_str(enum netr_SamDatabaseID database_id) +{ + + switch (database_id) { + case SAM_DATABASE_DOMAIN: + return "DOMAIN"; + case SAM_DATABASE_BUILTIN: + return "BUILTIN"; + case SAM_DATABASE_PRIVS: + return "PRIVS"; + default: + return "unknown"; + } +} + /** * samsync_debug_str */ @@ -231,7 +250,6 @@ static const char *samsync_debug_str(TALLOC_CTX *mem_ctx, enum netr_SamDatabaseID database_id) { const char *action = NULL; - const char *str = NULL; switch (mode) { case NET_SAMSYNC_MODE_DUMP: @@ -248,26 +266,8 @@ static const char *samsync_debug_str(TALLOC_CTX *mem_ctx, break; } - switch (database_id) { - case SAM_DATABASE_DOMAIN: - str = talloc_asprintf(mem_ctx, "%s DOMAIN database", - action); - break; - case SAM_DATABASE_BUILTIN: - str = talloc_asprintf(mem_ctx, "%s BUILTIN database", - action); - break; - case SAM_DATABASE_PRIVS: - str = talloc_asprintf(mem_ctx, "%s PRIVS database", - action); - break; - default: - str = talloc_asprintf(mem_ctx, "%s unknown database type %u", - action, database_id); - break; - } - - return str; + return talloc_asprintf(mem_ctx, "%s %s database", + action, samsync_database_str(database_id)); } /** @@ -303,6 +303,7 @@ NTSTATUS samsync_process_database(struct rpc_pipe_client *pipe_hnd, do { struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL; + NTSTATUS callback_status; netlogon_creds_client_step(pipe_hnd->dc, &credential); @@ -340,7 +341,11 @@ NTSTATUS samsync_process_database(struct rpc_pipe_client *pipe_hnd, delta_enum_array); /* Process results */ - callback_fn(mem_ctx, database_id, delta_enum_array, result, ctx); + callback_status = callback_fn(mem_ctx, database_id, delta_enum_array, result, ctx); + if (!NT_STATUS_IS_OK(callback_status)) { + result = callback_status; + goto out; + } TALLOC_FREE(delta_enum_array); @@ -349,6 +354,23 @@ NTSTATUS samsync_process_database(struct rpc_pipe_client *pipe_hnd, } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)); + out: + if (NT_STATUS_IS_ERR(result) && !ctx->error_message) { + + ctx->error_message = talloc_asprintf(ctx, + "Failed to fetch %s database: %s", + samsync_database_str(database_id), + nt_errstr(result)); + + if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED)) { + + ctx->error_message = + talloc_asprintf_append(ctx->error_message, + "\nPerhaps %s is a Windows native mode domain?", + ctx->domain_name); + } + } + talloc_destroy(mem_ctx); return result; -- cgit From ddf6e73b1fcbc4faae938815e7c7840d04d84150 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 17 Jun 2008 21:22:06 +0200 Subject: net_vampire: move pull_netr_AcctLockStr() to libnet. Guenther (This used to be commit 8ec64a96e43d2e55e81f725fe693178ecdc65e88) --- source3/libnet/libnet_samsync.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index c86c5c12e1..fab77e8398 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -375,3 +375,41 @@ NTSTATUS samsync_process_database(struct rpc_pipe_client *pipe_hnd, return result; } + +/** + * pull_netr_AcctLockStr + */ + +NTSTATUS pull_netr_AcctLockStr(TALLOC_CTX *mem_ctx, + struct lsa_BinaryString *r, + struct netr_AcctLockStr **str_p) +{ + struct netr_AcctLockStr *str; + enum ndr_err_code ndr_err; + DATA_BLOB blob; + + if (!mem_ctx || !r || !str_p) { + return NT_STATUS_INVALID_PARAMETER; + } + + *str_p = NULL; + + str = TALLOC_ZERO_P(mem_ctx, struct netr_AcctLockStr); + if (!str) { + return NT_STATUS_NO_MEMORY; + } + + blob = data_blob_const(r->array, r->length); + + ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, str, + (ndr_pull_flags_fn_t)ndr_pull_netr_AcctLockStr); + + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + return ndr_map_error2ntstatus(ndr_err); + } + + *str_p = str; + + return NT_STATUS_OK; +} + -- cgit From 8725626ec8b2b2a11b2c0bb5e7010f229d552b5e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 23 Jun 2008 17:03:53 +0200 Subject: net_vampire: prepend libnet_ to the public samsync functions. Guenther (This used to be commit f020c947cfb1482176af8827ed9c361d7c21e26f) --- source3/libnet/libnet_samsync.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index fab77e8398..7dd47b6399 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -163,11 +163,11 @@ static NTSTATUS samsync_fix_delta(TALLOC_CTX *mem_ctx, * callback need only do the printing or application logic */ -NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx, - DATA_BLOB *session_key, - bool rid_crypt, - enum netr_SamDatabaseID database_id, - struct netr_DELTA_ENUM_ARRAY *r) +static NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx, + DATA_BLOB *session_key, + bool rid_crypt, + enum netr_SamDatabaseID database_id, + struct netr_DELTA_ENUM_ARRAY *r) { NTSTATUS status; int i; @@ -188,14 +188,14 @@ NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx, } /** - * samsync_init_context + * libnet_samsync_init_context */ -NTSTATUS samsync_init_context(TALLOC_CTX *mem_ctx, - const struct dom_sid *domain_sid, - const char *domain_name, - enum net_samsync_mode mode, - struct samsync_context **ctx_p) +NTSTATUS libnet_samsync_init_context(TALLOC_CTX *mem_ctx, + const struct dom_sid *domain_sid, + const char *domain_name, + enum net_samsync_mode mode, + struct samsync_context **ctx_p) { struct samsync_context *ctx; @@ -271,13 +271,13 @@ static const char *samsync_debug_str(TALLOC_CTX *mem_ctx, } /** - * samsync_process_database + * libnet_samsync */ -NTSTATUS samsync_process_database(struct rpc_pipe_client *pipe_hnd, - enum netr_SamDatabaseID database_id, - samsync_fn_t callback_fn, - struct samsync_context *ctx) +NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd, + enum netr_SamDatabaseID database_id, + samsync_fn_t callback_fn, + struct samsync_context *ctx) { NTSTATUS result; TALLOC_CTX *mem_ctx; @@ -292,7 +292,7 @@ NTSTATUS samsync_process_database(struct rpc_pipe_client *pipe_hnd, ZERO_STRUCT(return_authenticator); - if (!(mem_ctx = talloc_init("samsync_process_database"))) { + if (!(mem_ctx = talloc_init("libnet_samsync"))) { return NT_STATUS_NO_MEMORY; } -- cgit From 48a680ecf2a00169066c6e6c84ec3fecc3245dbd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 23 Jun 2008 17:29:01 +0200 Subject: net_vampire: more libnet_samsync restructuring. Guenther (This used to be commit 3bcda522f025aff249678a8a086218679fc19c6b) --- source3/libnet/libnet_samsync.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index 7dd47b6399..e170acc560 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -193,8 +193,6 @@ static NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx, NTSTATUS libnet_samsync_init_context(TALLOC_CTX *mem_ctx, const struct dom_sid *domain_sid, - const char *domain_name, - enum net_samsync_mode mode, struct samsync_context **ctx_p) { struct samsync_context *ctx; @@ -204,11 +202,6 @@ NTSTATUS libnet_samsync_init_context(TALLOC_CTX *mem_ctx, ctx = TALLOC_ZERO_P(mem_ctx, struct samsync_context); NT_STATUS_HAVE_NO_MEMORY(ctx); - ctx->mode = mode; - - ctx->domain_name = talloc_strdup(mem_ctx, domain_name); - NT_STATUS_HAVE_NO_MEMORY(ctx->domain_name); - if (domain_sid) { ctx->domain_sid = sid_dup_talloc(mem_ctx, domain_sid); NT_STATUS_HAVE_NO_MEMORY(ctx->domain_sid); @@ -274,14 +267,12 @@ static const char *samsync_debug_str(TALLOC_CTX *mem_ctx, * libnet_samsync */ -NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd, - enum netr_SamDatabaseID database_id, - samsync_fn_t callback_fn, +NTSTATUS libnet_samsync(enum netr_SamDatabaseID database_id, struct samsync_context *ctx) { NTSTATUS result; TALLOC_CTX *mem_ctx; - const char *logon_server = pipe_hnd->desthost; + const char *logon_server = ctx->cli->desthost; const char *computername = global_myname(); struct netr_Authenticator credential; struct netr_Authenticator return_authenticator; @@ -305,9 +296,9 @@ NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd, struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL; NTSTATUS callback_status; - netlogon_creds_client_step(pipe_hnd->dc, &credential); + netlogon_creds_client_step(ctx->cli->dc, &credential); - result = rpccli_netr_DatabaseSync2(pipe_hnd, mem_ctx, + result = rpccli_netr_DatabaseSync2(ctx->cli, mem_ctx, logon_server, computername, &credential, @@ -322,7 +313,7 @@ NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd, } /* Check returned credentials. */ - if (!netlogon_creds_client_check(pipe_hnd->dc, + if (!netlogon_creds_client_check(ctx->cli->dc, &return_authenticator.cred)) { DEBUG(0,("credentials chain check failed\n")); return NT_STATUS_ACCESS_DENIED; @@ -332,7 +323,7 @@ NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd, break; } - session_key = data_blob_const(pipe_hnd->dc->sess_key, 16); + session_key = data_blob_const(ctx->cli->dc->sess_key, 16); samsync_fix_delta_array(mem_ctx, &session_key, @@ -341,7 +332,8 @@ NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd, delta_enum_array); /* Process results */ - callback_status = callback_fn(mem_ctx, database_id, delta_enum_array, result, ctx); + callback_status = ctx->delta_fn(mem_ctx, database_id, + delta_enum_array, result, ctx); if (!NT_STATUS_IS_OK(callback_status)) { result = callback_status; goto out; -- cgit From adef1b004bde0d88f7cf2f46b62312e49a1ad2e6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 18 Jun 2008 12:52:00 +0200 Subject: net_vampire: add code to vampire a SAM database to a keytab file. Guenther (This used to be commit ee6e422c0e035aa4779fa718bb6f142827cc2de0) --- source3/libnet/libnet_samsync.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index e170acc560..dcf5f9c39f 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -254,6 +254,9 @@ static const char *samsync_debug_str(TALLOC_CTX *mem_ctx, case NET_SAMSYNC_MODE_FETCH_LDIF: action = "Fetching (to ldif)"; break; + case NET_SAMSYNC_MODE_FETCH_KEYTAB: + action = "Fetching (to keytab)"; + break; default: action = "Unknown"; break; -- cgit From 92df9ae39329a2c442c55d20ba9015fe23b071e3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 27 Jun 2008 00:46:38 +0200 Subject: net_vampire: use bool for last_query information in samsync. Guenther (This used to be commit fa1976e23a33bd3fab17c3f6ab5573ee1fdf9e31) --- source3/libnet/libnet_samsync.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index dcf5f9c39f..4f2a8f9222 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -336,7 +336,8 @@ NTSTATUS libnet_samsync(enum netr_SamDatabaseID database_id, /* Process results */ callback_status = ctx->delta_fn(mem_ctx, database_id, - delta_enum_array, result, ctx); + delta_enum_array, + NT_STATUS_IS_OK(result), ctx); if (!NT_STATUS_IS_OK(callback_status)) { result = callback_status; goto out; -- cgit From 3ea5c185ad7b59c069e05f7712bea945d35b47dd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 30 Jul 2008 17:47:40 +0200 Subject: build: fix some no previous prototype warnings. Guenther (This used to be commit 51062534fd58d7a914a6bbac2e52bb44e71363b7) --- source3/libnet/libnet_samsync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libnet/libnet_samsync.c') diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index 4f2a8f9222..daf27ffb51 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -22,7 +22,7 @@ #include "includes.h" -#include "libnet/libnet_samsync.h" +#include "libnet/libnet.h" /** * Decrypt and extract the user's passwords. -- cgit