summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/clifile.c9
-rw-r--r--source3/libsmb/clikrb5.c14
-rw-r--r--source3/libsmb/credentials.c88
-rw-r--r--source3/libsmb/samlogon_cache.c217
-rw-r--r--source3/libsmb/trusts_util.c27
5 files changed, 173 insertions, 182 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 9b4c380d40..10c35a30cc 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -38,8 +38,15 @@ static bool cli_link_internal(struct cli_state *cli, const char *oldname, const
size_t newlen = 2*(strlen(newname)+1);
param = SMB_MALLOC_ARRAY(char, 6+newlen+2);
+
+ if (!param) {
+ return false;
+ }
+
data = SMB_MALLOC_ARRAY(char, oldlen+2);
- if (!param || !data) {
+
+ if (!data) {
+ SAFE_FREE(param);
return false;
}
diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c
index 844a3b35c0..c289740ab2 100644
--- a/source3/libsmb/clikrb5.c
+++ b/source3/libsmb/clikrb5.c
@@ -835,22 +835,22 @@ failed:
#endif
}
- void smb_krb5_checksum_from_pac_sig(krb5_checksum *cksum,
- PAC_SIGNATURE_DATA *sig)
+ void smb_krb5_checksum_from_pac_sig(krb5_checksum *cksum,
+ struct PAC_SIGNATURE_DATA *sig)
{
#ifdef HAVE_CHECKSUM_IN_KRB5_CHECKSUM
cksum->cksumtype = (krb5_cksumtype)sig->type;
- cksum->checksum.length = sig->signature.buf_len;
- cksum->checksum.data = sig->signature.buffer;
+ cksum->checksum.length = sig->signature.length;
+ cksum->checksum.data = sig->signature.data;
#else
cksum->checksum_type = (krb5_cksumtype)sig->type;
- cksum->length = sig->signature.buf_len;
- cksum->contents = sig->signature.buffer;
+ cksum->length = sig->signature.length;
+ cksum->contents = sig->signature.data;
#endif
}
krb5_error_code smb_krb5_verify_checksum(krb5_context context,
- krb5_keyblock *keyblock,
+ const krb5_keyblock *keyblock,
krb5_keyusage usage,
krb5_checksum *cksum,
uint8 *data,
diff --git a/source3/libsmb/credentials.c b/source3/libsmb/credentials.c
index 0043f4e6a9..9d33e6d93d 100644
--- a/source3/libsmb/credentials.c
+++ b/source3/libsmb/credentials.c
@@ -42,9 +42,9 @@ char *credstr(const unsigned char *cred)
****************************************************************************/
static void creds_init_128(struct dcinfo *dc,
- const DOM_CHAL *clnt_chal_in,
- const DOM_CHAL *srv_chal_in,
- const unsigned char mach_pw[16])
+ const struct netr_Credential *clnt_chal_in,
+ const struct netr_Credential *srv_chal_in,
+ const unsigned char mach_pw[16])
{
unsigned char zero[4], tmp[16];
HMACMD5Context ctx;
@@ -94,9 +94,9 @@ static void creds_init_128(struct dcinfo *dc,
****************************************************************************/
static void creds_init_64(struct dcinfo *dc,
- const DOM_CHAL *clnt_chal_in,
- const DOM_CHAL *srv_chal_in,
- const unsigned char mach_pw[16])
+ const struct netr_Credential *clnt_chal_in,
+ const struct netr_Credential *srv_chal_in,
+ const unsigned char mach_pw[16])
{
uint32 sum[2];
unsigned char sum2[8];
@@ -177,10 +177,10 @@ static void creds_step(struct dcinfo *dc)
void creds_server_init(uint32 neg_flags,
struct dcinfo *dc,
- DOM_CHAL *clnt_chal,
- DOM_CHAL *srv_chal,
+ struct netr_Credential *clnt_chal,
+ struct netr_Credential *srv_chal,
const unsigned char mach_pw[16],
- DOM_CHAL *init_chal_out)
+ struct netr_Credential *init_chal_out)
{
DEBUG(10,("creds_server_init: neg_flags : %x\n", (unsigned int)neg_flags));
DEBUG(10,("creds_server_init: client chal : %s\n", credstr(clnt_chal->data) ));
@@ -213,18 +213,6 @@ void creds_server_init(uint32 neg_flags,
Check a credential sent by the client.
****************************************************************************/
-bool creds_server_check(const struct dcinfo *dc, const DOM_CHAL *rcv_cli_chal_in)
-{
- if (memcmp(dc->clnt_chal.data, rcv_cli_chal_in->data, 8)) {
- DEBUG(5,("creds_server_check: challenge : %s\n", credstr(rcv_cli_chal_in->data)));
- DEBUG(5,("calculated: %s\n", credstr(dc->clnt_chal.data)));
- DEBUG(2,("creds_server_check: credentials check failed.\n"));
- return False;
- }
- DEBUG(10,("creds_server_check: credentials check OK.\n"));
- return True;
-}
-
bool netlogon_creds_server_check(const struct dcinfo *dc,
const struct netr_Credential *rcv_cli_chal_in)
{
@@ -246,7 +234,7 @@ bool netlogon_creds_server_check(const struct dcinfo *dc,
static void creds_reseed(struct dcinfo *dc)
{
- DOM_CHAL time_chal;
+ struct netr_Credential time_chal;
SIVAL(time_chal.data, 0, IVAL(dc->seed_chal.data, 0) + dc->sequence + 1);
SIVAL(time_chal.data, 4, IVAL(dc->seed_chal.data, 4));
@@ -260,34 +248,6 @@ static void creds_reseed(struct dcinfo *dc)
Step the server credential chain one forward.
****************************************************************************/
-bool creds_server_step(struct dcinfo *dc, const DOM_CRED *received_cred, DOM_CRED *cred_out)
-{
- bool ret;
- struct dcinfo tmp_dc = *dc;
-
- /* Do all operations on a temporary copy of the dc,
- which we throw away if the checks fail. */
-
- tmp_dc.sequence = received_cred->timestamp.time;
-
- creds_step(&tmp_dc);
-
- /* Create the outgoing credentials */
- cred_out->timestamp.time = tmp_dc.sequence + 1;
- cred_out->challenge = tmp_dc.srv_chal;
-
- creds_reseed(&tmp_dc);
-
- ret = creds_server_check(&tmp_dc, &received_cred->challenge);
- if (!ret) {
- return False;
- }
-
- /* creds step succeeded - replace the current creds. */
- *dc = tmp_dc;
- return True;
-}
-
bool netlogon_creds_server_step(struct dcinfo *dc,
const struct netr_Authenticator *received_cred,
struct netr_Authenticator *cred_out)
@@ -324,10 +284,10 @@ bool netlogon_creds_server_step(struct dcinfo *dc,
void creds_client_init(uint32 neg_flags,
struct dcinfo *dc,
- DOM_CHAL *clnt_chal,
- DOM_CHAL *srv_chal,
+ struct netr_Credential *clnt_chal,
+ struct netr_Credential *srv_chal,
const unsigned char mach_pw[16],
- DOM_CHAL *init_chal_out)
+ struct netr_Credential *init_chal_out)
{
dc->sequence = time(NULL);
@@ -362,18 +322,6 @@ void creds_client_init(uint32 neg_flags,
Check a credential returned by the server.
****************************************************************************/
-bool creds_client_check(const struct dcinfo *dc, const DOM_CHAL *rcv_srv_chal_in)
-{
- if (memcmp(dc->srv_chal.data, rcv_srv_chal_in->data, 8)) {
- DEBUG(5,("creds_client_check: challenge : %s\n", credstr(rcv_srv_chal_in->data)));
- DEBUG(5,("calculated: %s\n", credstr(dc->srv_chal.data)));
- DEBUG(0,("creds_client_check: credentials check failed.\n"));
- return False;
- }
- DEBUG(10,("creds_client_check: credentials check OK.\n"));
- return True;
-}
-
bool netlogon_creds_client_check(const struct dcinfo *dc,
const struct netr_Credential *rcv_srv_chal_in)
{
@@ -400,16 +348,6 @@ bool netlogon_creds_client_check(const struct dcinfo *dc,
the server
****************************************************************************/
-void creds_client_step(struct dcinfo *dc, DOM_CRED *next_cred_out)
-{
- dc->sequence += 2;
- creds_step(dc);
- creds_reseed(dc);
-
- next_cred_out->challenge = dc->clnt_chal;
- next_cred_out->timestamp.time = dc->sequence;
-}
-
void netlogon_creds_client_step(struct dcinfo *dc,
struct netr_Authenticator *next_cred_out)
{
diff --git a/source3/libsmb/samlogon_cache.c b/source3/libsmb/samlogon_cache.c
index 4f791f66f6..e2a4b3898f 100644
--- a/source3/libsmb/samlogon_cache.c
+++ b/source3/libsmb/samlogon_cache.c
@@ -1,21 +1,21 @@
-/*
+/*
Unix SMB/CIFS implementation.
Net_sam_logon info3 helpers
Copyright (C) Alexander Bokovoy 2002.
Copyright (C) Andrew Bartlett 2002.
Copyright (C) Gerald Carter 2003.
Copyright (C) Tim Potter 2003.
-
+
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 <http://www.gnu.org/licenses/>.
*/
@@ -29,12 +29,12 @@ static TDB_CONTEXT *netsamlogon_tdb = NULL;
/***********************************************************************
open the tdb
***********************************************************************/
-
+
bool netsamlogon_cache_init(void)
{
if (!netsamlogon_tdb) {
netsamlogon_tdb = tdb_open_log(lock_path(NETSAMLOGON_TDB), 0,
- TDB_DEFAULT, O_RDWR | O_CREAT, 0600);
+ TDB_DEFAULT, O_RDWR | O_CREAT, 0600);
}
return (netsamlogon_tdb != NULL);
@@ -47,37 +47,39 @@ bool netsamlogon_cache_init(void)
bool netsamlogon_cache_shutdown(void)
{
- if(netsamlogon_tdb)
+ if (netsamlogon_tdb) {
return (tdb_close(netsamlogon_tdb) == 0);
-
- return True;
+ }
+
+ return true;
}
/***********************************************************************
Clear cache getpwnam and getgroups entries from the winbindd cache
***********************************************************************/
-void netsamlogon_clear_cached_user(TDB_CONTEXT *tdb, NET_USER_INFO_3 *user)
+
+void netsamlogon_clear_cached_user(TDB_CONTEXT *tdb, struct netr_SamInfo3 *info3)
{
- bool got_tdb = False;
+ bool got_tdb = false;
DOM_SID sid;
fstring key_str, sid_string;
/* We may need to call this function from smbd which will not have
- winbindd_cache.tdb open. Open the tdb if a NULL is passed. */
+ winbindd_cache.tdb open. Open the tdb if a NULL is passed. */
if (!tdb) {
- tdb = tdb_open_log(lock_path("winbindd_cache.tdb"),
+ tdb = tdb_open_log(lock_path("winbindd_cache.tdb"),
WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
TDB_DEFAULT, O_RDWR, 0600);
if (!tdb) {
DEBUG(5, ("netsamlogon_clear_cached_user: failed to open cache\n"));
return;
}
- got_tdb = True;
+ got_tdb = true;
}
- sid_copy(&sid, &user->dom_sid.sid);
- sid_append_rid(&sid, user->user_rid);
+ sid_copy(&sid, info3->base.domain_sid);
+ sid_append_rid(&sid, info3->base.rid);
/* Clear U/SID cache entry */
@@ -95,157 +97,176 @@ void netsamlogon_clear_cached_user(TDB_CONTEXT *tdb, NET_USER_INFO_3 *user)
tdb_delete(tdb, string_tdb_data(key_str));
- if (got_tdb)
+ if (got_tdb) {
tdb_close(tdb);
+ }
}
/***********************************************************************
- Store a NET_USER_INFO_3 structure in a tdb for later user
+ Store a netr_SamInfo3 structure in a tdb for later user
username should be in UTF-8 format
***********************************************************************/
-bool netsamlogon_cache_store( const char *username, NET_USER_INFO_3 *user )
+bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
{
- TDB_DATA data;
- fstring keystr, tmp;
- prs_struct ps;
- bool result = False;
- DOM_SID user_sid;
- time_t t = time(NULL);
- TALLOC_CTX *mem_ctx;
-
+ TDB_DATA data;
+ fstring keystr, tmp;
+ bool result = false;
+ DOM_SID user_sid;
+ time_t t = time(NULL);
+ TALLOC_CTX *mem_ctx;
+ DATA_BLOB blob;
+ enum ndr_err_code ndr_err;
+ struct netsamlogoncache_entry r;
+
+ if (!info3) {
+ return false;
+ }
if (!netsamlogon_cache_init()) {
- DEBUG(0,("netsamlogon_cache_store: cannot open %s for write!\n", NETSAMLOGON_TDB));
- return False;
+ DEBUG(0,("netsamlogon_cache_store: cannot open %s for write!\n",
+ NETSAMLOGON_TDB));
+ return false;
}
- sid_copy( &user_sid, &user->dom_sid.sid );
- sid_append_rid( &user_sid, user->user_rid );
+ sid_copy(&user_sid, info3->base.domain_sid);
+ sid_append_rid(&user_sid, info3->base.rid);
/* Prepare key as DOMAIN-SID/USER-RID string */
slprintf(keystr, sizeof(keystr), "%s", sid_to_fstring(tmp, &user_sid));
DEBUG(10,("netsamlogon_cache_store: SID [%s]\n", keystr));
-
+
+ /* Prepare data */
+
+ if (!(mem_ctx = TALLOC_P( NULL, int))) {
+ DEBUG(0,("netsamlogon_cache_store: talloc() failed!\n"));
+ return false;
+ }
+
/* only Samba fills in the username, not sure why NT doesn't */
/* so we fill it in since winbindd_getpwnam() makes use of it */
-
- if ( !user->uni_user_name.buffer ) {
- init_unistr2( &user->uni_user_name, username, UNI_STR_TERMINATE );
- init_uni_hdr( &user->hdr_user_name, &user->uni_user_name );
+
+ if (!info3->base.account_name.string) {
+ info3->base.account_name.string = talloc_strdup(mem_ctx, username);
}
-
- /* Prepare data */
-
- if ( !(mem_ctx = TALLOC_P( NULL, int )) ) {
- DEBUG(0,("netsamlogon_cache_store: talloc() failed!\n"));
- return False;
+
+ r.timestamp = t;
+ r.info3 = *info3;
+
+ if (DEBUGLEVEL >= 10) {
+ NDR_PRINT_DEBUG(netsamlogoncache_entry, &r);
}
- prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-
- {
- uint32 ts = (uint32)t;
- if ( !prs_uint32( "timestamp", &ps, 0, &ts ) )
- return False;
+ ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &r,
+ (ndr_push_flags_fn_t)ndr_push_netsamlogoncache_entry);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ DEBUG(0,("netsamlogon_cache_store: failed to push entry to cache\n"));
+ TALLOC_FREE(mem_ctx);
+ return false;
}
-
- if ( net_io_user_info3("", user, &ps, 0, 3, 0) )
- {
- data.dsize = prs_offset( &ps );
- data.dptr = (uint8 *)prs_data_p( &ps );
- if (tdb_store_bystring(netsamlogon_tdb, keystr, data, TDB_REPLACE) != -1)
- result = True;
-
- prs_mem_free( &ps );
+ data.dsize = blob.length;
+ data.dptr = blob.data;
+
+ if (tdb_store_bystring(netsamlogon_tdb, keystr, data, TDB_REPLACE) != -1) {
+ result = true;
}
- TALLOC_FREE( mem_ctx );
-
+ TALLOC_FREE(mem_ctx);
+
return result;
}
/***********************************************************************
- Retrieves a NET_USER_INFO_3 structure from a tdb. Caller must
+ Retrieves a netr_SamInfo3 structure from a tdb. Caller must
free the user_info struct (malloc()'d memory)
***********************************************************************/
-NET_USER_INFO_3* netsamlogon_cache_get( TALLOC_CTX *mem_ctx, const DOM_SID *user_sid)
+struct netr_SamInfo3 *netsamlogon_cache_get(TALLOC_CTX *mem_ctx, const DOM_SID *user_sid)
{
- NET_USER_INFO_3 *user = NULL;
- TDB_DATA data;
- prs_struct ps;
- fstring keystr, tmp;
- uint32 t;
-
+ struct netr_SamInfo3 *info3 = NULL;
+ TDB_DATA data;
+ fstring keystr, tmp;
+ enum ndr_err_code ndr_err;
+ DATA_BLOB blob;
+ struct netsamlogoncache_entry r;
+
if (!netsamlogon_cache_init()) {
- DEBUG(0,("netsamlogon_cache_get: cannot open %s for write!\n", NETSAMLOGON_TDB));
- return False;
+ DEBUG(0,("netsamlogon_cache_get: cannot open %s for write!\n",
+ NETSAMLOGON_TDB));
+ return false;
}
/* Prepare key as DOMAIN-SID/USER-RID string */
slprintf(keystr, sizeof(keystr), "%s", sid_to_fstring(tmp, user_sid));
DEBUG(10,("netsamlogon_cache_get: SID [%s]\n", keystr));
data = tdb_fetch_bystring( netsamlogon_tdb, keystr );
-
- if ( data.dptr ) {
- user = TALLOC_ZERO_P(mem_ctx, NET_USER_INFO_3);
- if (user == NULL) {
- return NULL;
- }
+ if (!data.dptr) {
+ return NULL;
+ }
- prs_init( &ps, 0, mem_ctx, UNMARSHALL );
- prs_give_memory( &ps, (char *)data.dptr, data.dsize, True );
-
- if ( !prs_uint32( "timestamp", &ps, 0, &t ) ) {
- prs_mem_free( &ps );
- TALLOC_FREE(user);
- return False;
- }
-
- if ( !net_io_user_info3("", user, &ps, 0, 3, 0) ) {
- TALLOC_FREE( user );
- }
-
- prs_mem_free( &ps );
+ info3 = TALLOC_ZERO_P(mem_ctx, struct netr_SamInfo3);
+ if (!info3) {
+ goto done;
+ }
+
+ blob.data = (uint8 *)data.dptr;
+ blob.length = data.dsize;
+
+ ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r,
+ (ndr_pull_flags_fn_t)ndr_pull_netsamlogoncache_entry);
-#if 0 /* The netsamlogon cache needs to hang around. Something about
+ if (DEBUGLEVEL >= 10) {
+ NDR_PRINT_DEBUG(netsamlogoncache_entry, &r);
+ }
+
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ DEBUG(0,("netsamlogon_cache_get: failed to pull entry from cache\n"));
+ tdb_delete(netsamlogon_tdb, data);
+ goto done;
+ }
+
+ info3 = talloc_memdup(mem_ctx, &r.info3, sizeof(r.info3));
+
+ done:
+ SAFE_FREE(data.dptr);
+
+ return info3;
+
+#if 0 /* The netsamlogon cache needs to hang around. Something about
this feels wrong, but it is the only way we can get all of the
groups. The old universal groups cache didn't expire either.
--jerry */
{
time_t now = time(NULL);
uint32 time_diff;
-
+
/* is the entry expired? */
time_diff = now - t;
-
+
if ( (time_diff < 0 ) || (time_diff > lp_winbind_cache_time()) ) {
DEBUG(10,("netsamlogon_cache_get: cache entry expired \n"));
tdb_delete( netsamlogon_tdb, key );
TALLOC_FREE( user );
}
-#endif
}
-
- return user;
+#endif
}
bool netsamlogon_cache_have(const DOM_SID *user_sid)
{
TALLOC_CTX *mem_ctx = talloc_init("netsamlogon_cache_have");
- NET_USER_INFO_3 *user = NULL;
+ struct netr_SamInfo3 *info3 = NULL;
bool result;
if (!mem_ctx)
return False;
- user = netsamlogon_cache_get(mem_ctx, user_sid);
+ info3 = netsamlogon_cache_get(mem_ctx, user_sid);
- result = (user != NULL);
+ result = (info3 != NULL);
talloc_destroy(mem_ctx);
diff --git a/source3/libsmb/trusts_util.c b/source3/libsmb/trusts_util.c
index 11f691bee6..1e92bf21de 100644
--- a/source3/libsmb/trusts_util.c
+++ b/source3/libsmb/trusts_util.c
@@ -58,7 +58,32 @@ static NTSTATUS just_change_the_password(struct rpc_pipe_client *cli, TALLOC_CTX
}
}
- result = rpccli_net_srv_pwset(cli, mem_ctx, global_myname(), new_trust_passwd_hash);
+ {
+ struct netr_Authenticator clnt_creds, srv_cred;
+ struct samr_Password new_password;
+
+ netlogon_creds_client_step(cli->dc, &clnt_creds);
+
+ cred_hash3(new_password.hash,
+ new_trust_passwd_hash,
+ cli->dc->sess_key, 1);
+
+ result = rpccli_netr_ServerPasswordSet(cli, mem_ctx,
+ cli->dc->remote_machine,
+ cli->dc->mach_acct,
+ sec_channel_type,
+ global_myname(),
+ &clnt_creds,
+ &srv_cred,
+ &new_password);
+
+ /* Always check returned credentials. */
+ if (!netlogon_creds_client_check(cli->dc, &srv_cred.cred)) {
+ DEBUG(0,("rpccli_netr_ServerPasswordSet: "
+ "credentials chain check failed\n"));
+ return NT_STATUS_ACCESS_DENIED;
+ }
+ }
if (!NT_STATUS_IS_OK(result)) {
DEBUG(0,("just_change_the_password: unable to change password (%s)!\n",