summaryrefslogtreecommitdiff
path: root/libcli/auth
diff options
context:
space:
mode:
Diffstat (limited to 'libcli/auth')
-rw-r--r--libcli/auth/kerberos_pac.c358
-rw-r--r--libcli/auth/krb5_wrap.c49
-rw-r--r--libcli/auth/krb5_wrap.h10
-rw-r--r--libcli/auth/msrpc_parse.c6
-rw-r--r--libcli/auth/msrpc_parse.h21
-rw-r--r--libcli/auth/schannel_state_tdb.c8
-rw-r--r--libcli/auth/smbencrypt.c14
-rw-r--r--libcli/auth/wscript_build6
8 files changed, 89 insertions, 383 deletions
diff --git a/libcli/auth/kerberos_pac.c b/libcli/auth/kerberos_pac.c
deleted file mode 100644
index 6a41eb1ace..0000000000
--- a/libcli/auth/kerberos_pac.c
+++ /dev/null
@@ -1,358 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- kerberos authorization data (PAC) utility library
- Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
- Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
- Copyright (C) Andrew Tridgell 2001
- Copyright (C) Luke Howard 2002-2003
- Copyright (C) Stefan Metzmacher 2004-2005
- Copyright (C) Guenther Deschner 2005,2007,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 <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#ifdef HAVE_KRB5
-
-#include "librpc/gen_ndr/ndr_krb5pac.h"
-#include "libcli/auth/krb5_wrap.h"
-
-krb5_error_code check_pac_checksum(TALLOC_CTX *mem_ctx,
- DATA_BLOB pac_data,
- struct PAC_SIGNATURE_DATA *sig,
- krb5_context context,
- const krb5_keyblock *keyblock)
-{
- krb5_error_code ret;
- krb5_checksum cksum;
- krb5_keyusage usage = 0;
-
- smb_krb5_checksum_from_pac_sig(&cksum, sig);
-
-#ifdef HAVE_KRB5_KU_OTHER_CKSUM /* Heimdal */
- usage = KRB5_KU_OTHER_CKSUM;
-#elif defined(HAVE_KRB5_KEYUSAGE_APP_DATA_CKSUM) /* MIT */
- usage = KRB5_KEYUSAGE_APP_DATA_CKSUM;
-#else
-#error UNKNOWN_KRB5_KEYUSAGE
-#endif
-
- ret = smb_krb5_verify_checksum(context,
- keyblock,
- usage,
- &cksum,
- pac_data.data,
- pac_data.length);
-
- if (ret) {
- DEBUG(2,("check_pac_checksum: PAC Verification failed: %s (%d)\n",
- error_message(ret), ret));
- return ret;
- }
-
- return ret;
-}
-
-/**
-* @brief Decode a blob containing a NDR envoded PAC structure
-*
-* @param mem_ctx - The memory context
-* @param pac_data_blob - The data blob containing the NDR encoded data
-* @param context - The Kerberos Context
-* @param service_keyblock - The Service Key used to verify the checksum
-* @param client_principal - The client principal
-* @param tgs_authtime - The ticket timestamp
-* @param pac_data_out - [out] The decoded PAC
-*
-* @return - A NTSTATUS error code
-*/
-NTSTATUS kerberos_decode_pac(TALLOC_CTX *mem_ctx,
- DATA_BLOB pac_data_blob,
- krb5_context context,
- const krb5_keyblock *krbtgt_keyblock,
- const krb5_keyblock *service_keyblock,
- krb5_const_principal client_principal,
- time_t tgs_authtime,
- struct PAC_DATA **pac_data_out)
-{
- NTSTATUS status;
- enum ndr_err_code ndr_err;
- krb5_error_code ret;
- DATA_BLOB modified_pac_blob;
-
- NTTIME tgs_authtime_nttime;
- krb5_principal client_principal_pac = NULL;
- int i;
-
- struct PAC_SIGNATURE_DATA *srv_sig_ptr = NULL;
- struct PAC_SIGNATURE_DATA *kdc_sig_ptr = NULL;
- struct PAC_SIGNATURE_DATA *srv_sig_wipe = NULL;
- struct PAC_SIGNATURE_DATA *kdc_sig_wipe = NULL;
- struct PAC_LOGON_NAME *logon_name = NULL;
- struct PAC_LOGON_INFO *logon_info = NULL;
- struct PAC_DATA *pac_data = NULL;
- struct PAC_DATA_RAW *pac_data_raw = NULL;
-
- DATA_BLOB *srv_sig_blob = NULL;
- DATA_BLOB *kdc_sig_blob = NULL;
-
- bool bool_ret;
-
- *pac_data_out = NULL;
-
- pac_data = talloc(mem_ctx, struct PAC_DATA);
- pac_data_raw = talloc(mem_ctx, struct PAC_DATA_RAW);
- kdc_sig_wipe = talloc(mem_ctx, struct PAC_SIGNATURE_DATA);
- srv_sig_wipe = talloc(mem_ctx, struct PAC_SIGNATURE_DATA);
- if (!pac_data_raw || !pac_data || !kdc_sig_wipe || !srv_sig_wipe) {
- return NT_STATUS_NO_MEMORY;
- }
-
- ndr_err = ndr_pull_struct_blob(&pac_data_blob, pac_data, pac_data,
- (ndr_pull_flags_fn_t)ndr_pull_PAC_DATA);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- status = ndr_map_error2ntstatus(ndr_err);
- DEBUG(0,("can't parse the PAC: %s\n",
- nt_errstr(status)));
- return status;
- }
-
- if (pac_data->num_buffers < 4) {
- /* we need logon_ingo, service_key and kdc_key */
- DEBUG(0,("less than 4 PAC buffers\n"));
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- ndr_err = ndr_pull_struct_blob(
- &pac_data_blob, pac_data_raw, pac_data_raw,
- (ndr_pull_flags_fn_t)ndr_pull_PAC_DATA_RAW);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- status = ndr_map_error2ntstatus(ndr_err);
- DEBUG(0,("can't parse the PAC: %s\n",
- nt_errstr(status)));
- return status;
- }
-
- if (pac_data_raw->num_buffers < 4) {
- /* we need logon_ingo, service_key and kdc_key */
- DEBUG(0,("less than 4 PAC buffers\n"));
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- if (pac_data->num_buffers != pac_data_raw->num_buffers) {
- /* we need logon_ingo, service_key and kdc_key */
- DEBUG(0, ("misparse! PAC_DATA has %d buffers while "
- "PAC_DATA_RAW has %d\n", pac_data->num_buffers,
- pac_data_raw->num_buffers));
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- for (i=0; i < pac_data->num_buffers; i++) {
- struct PAC_BUFFER *data_buf = &pac_data->buffers[i];
- struct PAC_BUFFER_RAW *raw_buf = &pac_data_raw->buffers[i];
-
- if (data_buf->type != raw_buf->type) {
- DEBUG(0, ("misparse! PAC_DATA buffer %d has type "
- "%d while PAC_DATA_RAW has %d\n", i,
- data_buf->type, raw_buf->type));
- return NT_STATUS_INVALID_PARAMETER;
- }
- switch (data_buf->type) {
- case PAC_TYPE_LOGON_INFO:
- if (!data_buf->info) {
- break;
- }
- logon_info = data_buf->info->logon_info.info;
- break;
- case PAC_TYPE_SRV_CHECKSUM:
- if (!data_buf->info) {
- break;
- }
- srv_sig_ptr = &data_buf->info->srv_cksum;
- srv_sig_blob = &raw_buf->info->remaining;
- break;
- case PAC_TYPE_KDC_CHECKSUM:
- if (!data_buf->info) {
- break;
- }
- kdc_sig_ptr = &data_buf->info->kdc_cksum;
- kdc_sig_blob = &raw_buf->info->remaining;
- break;
- case PAC_TYPE_LOGON_NAME:
- logon_name = &data_buf->info->logon_name;
- break;
- default:
- break;
- }
- }
-
- if (!logon_info) {
- DEBUG(0,("PAC no logon_info\n"));
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- if (!logon_name) {
- DEBUG(0,("PAC no logon_name\n"));
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- if (!srv_sig_ptr || !srv_sig_blob) {
- DEBUG(0,("PAC no srv_key\n"));
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- if (!kdc_sig_ptr || !kdc_sig_blob) {
- DEBUG(0,("PAC no kdc_key\n"));
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- /* Find and zero out the signatures,
- * as required by the signing algorithm */
-
- /* We find the data blobs above,
- * now we parse them to get at the exact portion we should zero */
- ndr_err = ndr_pull_struct_blob(
- kdc_sig_blob, kdc_sig_wipe, kdc_sig_wipe,
- (ndr_pull_flags_fn_t)ndr_pull_PAC_SIGNATURE_DATA);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- status = ndr_map_error2ntstatus(ndr_err);
- DEBUG(0,("can't parse the KDC signature: %s\n",
- nt_errstr(status)));
- return status;
- }
-
- ndr_err = ndr_pull_struct_blob(
- srv_sig_blob, srv_sig_wipe, srv_sig_wipe,
- (ndr_pull_flags_fn_t)ndr_pull_PAC_SIGNATURE_DATA);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- status = ndr_map_error2ntstatus(ndr_err);
- DEBUG(0,("can't parse the SRV signature: %s\n",
- nt_errstr(status)));
- return status;
- }
-
- /* Now zero the decoded structure */
- memset(kdc_sig_wipe->signature.data,
- '\0', kdc_sig_wipe->signature.length);
- memset(srv_sig_wipe->signature.data,
- '\0', srv_sig_wipe->signature.length);
-
- /* and reencode, back into the same place it came from */
- ndr_err = ndr_push_struct_blob(
- kdc_sig_blob, pac_data_raw, kdc_sig_wipe,
- (ndr_push_flags_fn_t)ndr_push_PAC_SIGNATURE_DATA);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- status = ndr_map_error2ntstatus(ndr_err);
- DEBUG(0,("can't repack the KDC signature: %s\n",
- nt_errstr(status)));
- return status;
- }
- ndr_err = ndr_push_struct_blob(
- srv_sig_blob, pac_data_raw, srv_sig_wipe,
- (ndr_push_flags_fn_t)ndr_push_PAC_SIGNATURE_DATA);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- status = ndr_map_error2ntstatus(ndr_err);
- DEBUG(0,("can't repack the SRV signature: %s\n",
- nt_errstr(status)));
- return status;
- }
-
- /* push out the whole structure, but now with zero'ed signatures */
- ndr_err = ndr_push_struct_blob(
- &modified_pac_blob, pac_data_raw, pac_data_raw,
- (ndr_push_flags_fn_t)ndr_push_PAC_DATA_RAW);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- status = ndr_map_error2ntstatus(ndr_err);
- DEBUG(0,("can't repack the RAW PAC: %s\n",
- nt_errstr(status)));
- return status;
- }
-
- /* verify by service_key */
- ret = check_pac_checksum(mem_ctx,
- modified_pac_blob, srv_sig_ptr,
- context,
- service_keyblock);
- if (ret) {
- DEBUG(1, ("PAC Decode: Failed to verify the service "
- "signature: %s\n", error_message(ret)));
- return NT_STATUS_ACCESS_DENIED;
- }
-
- if (krbtgt_keyblock) {
- /* verify the service key checksum by krbtgt_key */
- ret = check_pac_checksum(mem_ctx,
- srv_sig_ptr->signature, kdc_sig_ptr,
- context, krbtgt_keyblock);
- if (ret) {
- DEBUG(1, ("PAC Decode: Failed to verify the KDC signature: %s\n",
- smb_get_krb5_error_message(context, ret, mem_ctx)));
- return NT_STATUS_ACCESS_DENIED;
- }
- }
-
- /* Convert to NT time, so as not to loose accuracy in comparison */
- unix_to_nt_time(&tgs_authtime_nttime, tgs_authtime);
-
- if (tgs_authtime_nttime != logon_name->logon_time) {
- DEBUG(2, ("PAC Decode: "
- "Logon time mismatch between ticket and PAC!\n"));
- DEBUG(2, ("PAC Decode: PAC: %s\n",
- nt_time_string(mem_ctx, logon_name->logon_time)));
- DEBUG(2, ("PAC Decode: Ticket: %s\n",
- nt_time_string(mem_ctx, tgs_authtime_nttime)));
- return NT_STATUS_ACCESS_DENIED;
- }
-
- ret = smb_krb5_parse_name_norealm(context,
- logon_name->account_name,
- &client_principal_pac);
- if (ret) {
- DEBUG(2, ("Could not parse name from PAC: [%s]:%s\n",
- logon_name->account_name, error_message(ret)));
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- bool_ret = smb_krb5_principal_compare_any_realm(context,
- client_principal,
- client_principal_pac);
-
- krb5_free_principal(context, client_principal_pac);
-
- if (!bool_ret) {
- DEBUG(2, ("Name in PAC [%s] does not match principal name "
- "in ticket\n", logon_name->account_name));
- return NT_STATUS_ACCESS_DENIED;
- }
-
- DEBUG(3,("Found account name from PAC: %s [%s]\n",
- logon_info->info3.base.account_name.string,
- logon_info->info3.base.full_name.string));
-
- DEBUG(10,("Successfully validated Kerberos PAC\n"));
-
- if (DEBUGLEVEL >= 10) {
- const char *s;
- s = NDR_PRINT_STRUCT_STRING(mem_ctx, PAC_DATA, pac_data);
- if (s) {
- DEBUGADD(10,("%s\n", s));
- }
- }
-
- *pac_data_out = pac_data;
-
- return NT_STATUS_OK;
-}
-
-#endif
diff --git a/libcli/auth/krb5_wrap.c b/libcli/auth/krb5_wrap.c
index c69e3946c6..e7e071d484 100644
--- a/libcli/auth/krb5_wrap.c
+++ b/libcli/auth/krb5_wrap.c
@@ -5,6 +5,7 @@
Copyright (C) Luke Howard 2002-2003
Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005-2011
Copyright (C) Guenther Deschner 2005-2009
+ Copyright (C) Simo Sorce 2010.
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
@@ -119,13 +120,15 @@ int create_kerberos_key_from_string_direct(krb5_context context,
krb5_error_code ret;
char *utf8_name;
size_t converted_size;
+ TALLOC_CTX *frame = talloc_stackframe();
- if (!push_utf8_talloc(talloc_tos(), &utf8_name, name, &converted_size)) {
+ if (!push_utf8_talloc(frame, &utf8_name, name, &converted_size)) {
+ talloc_free(frame);
return ENOMEM;
}
ret = krb5_parse_name(context, utf8_name, principal);
- TALLOC_FREE(utf8_name);
+ TALLOC_FREE(frame);
return ret;
}
@@ -202,8 +205,8 @@ krb5_error_code smb_krb5_unparse_name(TALLOC_CTX *mem_ctx,
for (i = 0; i < len1; i++) {
- p1 = krb5_princ_component(context, CONST_DISCARD(krb5_principal, princ1), i);
- p2 = krb5_princ_component(context, CONST_DISCARD(krb5_principal, princ2), i);
+ p1 = krb5_princ_component(context, (krb5_principal)discard_const(princ1), i);
+ p2 = krb5_princ_component(context, (krb5_principal)discard_const(princ2), i);
if (p1->length != p2->length || memcmp(p1->data, p2->data, p1->length))
return False;
@@ -307,6 +310,44 @@ krb5_error_code smb_krb5_unparse_name(TALLOC_CTX *mem_ctx,
return ret;
}
+char *gssapi_error_string(TALLOC_CTX *mem_ctx,
+ OM_uint32 maj_stat, OM_uint32 min_stat,
+ const gss_OID mech)
+{
+ OM_uint32 disp_min_stat, disp_maj_stat;
+ gss_buffer_desc maj_error_message;
+ gss_buffer_desc min_error_message;
+ char *maj_error_string, *min_error_string;
+ OM_uint32 msg_ctx = 0;
+
+ char *ret;
+
+ maj_error_message.value = NULL;
+ min_error_message.value = NULL;
+ maj_error_message.length = 0;
+ min_error_message.length = 0;
+
+ disp_maj_stat = gss_display_status(&disp_min_stat, maj_stat, GSS_C_GSS_CODE,
+ mech, &msg_ctx, &maj_error_message);
+ disp_maj_stat = gss_display_status(&disp_min_stat, min_stat, GSS_C_MECH_CODE,
+ mech, &msg_ctx, &min_error_message);
+
+ maj_error_string = talloc_strndup(mem_ctx, (char *)maj_error_message.value, maj_error_message.length);
+
+ min_error_string = talloc_strndup(mem_ctx, (char *)min_error_message.value, min_error_message.length);
+
+ ret = talloc_asprintf(mem_ctx, "%s: %s", maj_error_string, min_error_string);
+
+ talloc_free(maj_error_string);
+ talloc_free(min_error_string);
+
+ gss_release_buffer(&disp_min_stat, &maj_error_message);
+ gss_release_buffer(&disp_min_stat, &min_error_message);
+
+ return ret;
+}
+
+
char *smb_get_krb5_error_message(krb5_context context, krb5_error_code code, TALLOC_CTX *mem_ctx)
{
char *ret;
diff --git a/libcli/auth/krb5_wrap.h b/libcli/auth/krb5_wrap.h
index 4f333cc4b0..82769aede9 100644
--- a/libcli/auth/krb5_wrap.h
+++ b/libcli/auth/krb5_wrap.h
@@ -31,7 +31,6 @@ int create_kerberos_key_from_string_direct(krb5_context context,
krb5_enctype enctype);
void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
-char *smb_get_krb5_error_message(krb5_context context, krb5_error_code code, TALLOC_CTX *mem_ctx);
krb5_error_code smb_krb5_parse_name(krb5_context context,
const char *name, /* in unix charset */
@@ -54,6 +53,10 @@ krb5_error_code smb_krb5_unparse_name(TALLOC_CTX *mem_ctx,
krb5_checksum *cksum,
uint8_t *data,
size_t length);
+char *gssapi_error_string(TALLOC_CTX *mem_ctx,
+ OM_uint32 maj_stat, OM_uint32 min_stat,
+ const gss_OID mech);
+char *smb_get_krb5_error_message(krb5_context context, krb5_error_code code, TALLOC_CTX *mem_ctx);
krb5_error_code check_pac_checksum(TALLOC_CTX *mem_ctx,
DATA_BLOB pac_data,
@@ -69,3 +72,8 @@ NTSTATUS kerberos_decode_pac(TALLOC_CTX *mem_ctx,
krb5_const_principal client_principal,
time_t tgs_authtime,
struct PAC_DATA **pac_data_out);
+
+NTSTATUS gssapi_obtain_pac_blob(TALLOC_CTX *mem_ctx,
+ gss_ctx_id_t gssapi_context,
+ gss_name_t gss_client_name,
+ DATA_BLOB *pac_data);
diff --git a/libcli/auth/msrpc_parse.c b/libcli/auth/msrpc_parse.c
index bdbba3d76c..8b64e98feb 100644
--- a/libcli/auth/msrpc_parse.c
+++ b/libcli/auth/msrpc_parse.c
@@ -78,7 +78,7 @@ NTSTATUS msrpc_gen(TALLOC_CTX *mem_ctx,
s, &n);
if (!ret) {
va_end(ap);
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
pointers[i].length = n;
pointers[i].length -= 2;
@@ -92,7 +92,7 @@ NTSTATUS msrpc_gen(TALLOC_CTX *mem_ctx,
s, &n);
if (!ret) {
va_end(ap);
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
pointers[i].length = n;
pointers[i].length -= 1;
@@ -108,7 +108,7 @@ NTSTATUS msrpc_gen(TALLOC_CTX *mem_ctx,
s, &n);
if (!ret) {
va_end(ap);
- return map_nt_error_from_unix(errno);
+ return map_nt_error_from_unix_common(errno);
}
pointers[i].length = n;
pointers[i].length -= 2;
diff --git a/libcli/auth/msrpc_parse.h b/libcli/auth/msrpc_parse.h
index d976a95b73..47529f24a9 100644
--- a/libcli/auth/msrpc_parse.h
+++ b/libcli/auth/msrpc_parse.h
@@ -1,3 +1,24 @@
+/*
+ Unix SMB/CIFS implementation.
+ simple kerberos5/SPNEGO routines
+ Copyright (C) Andrew Tridgell 2001
+ Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
+ Copyright (C) Andrew Bartlett 2002-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/>.
+*/
+
#ifndef _LIBCLI_AUTH_MSRPC_PARSE_H__
#define _LIBCLI_AUTH_MSRPC_PARSE_H__
diff --git a/libcli/auth/schannel_state_tdb.c b/libcli/auth/schannel_state_tdb.c
index c332bae8ba..76110b89ef 100644
--- a/libcli/auth/schannel_state_tdb.c
+++ b/libcli/auth/schannel_state_tdb.c
@@ -23,13 +23,11 @@
#include "includes.h"
#include "system/filesys.h"
-#include <tdb.h>
+#include "../lib/tdb_compat/tdb_compat.h"
#include "../lib/util/util_tdb.h"
#include "../libcli/auth/schannel.h"
#include "../librpc/gen_ndr/ndr_schannel.h"
-#if _SAMBA_BUILD_ == 4
-#include "tdb_wrap.h"
-#endif
+#include "lib/util/tdb_wrap.h"
#define SECRETS_SCHANNEL_STATE "SECRETS/SCHANNEL"
@@ -102,7 +100,7 @@ NTSTATUS schannel_store_session_key_tdb(struct tdb_wrap *tdb_sc,
ret = tdb_store_bystring(tdb_sc->tdb, keystr, value, TDB_REPLACE);
if (ret != TDB_SUCCESS) {
DEBUG(0,("Unable to add %s to session key db - %s\n",
- keystr, tdb_errorstr(tdb_sc->tdb)));
+ keystr, tdb_errorstr_compat(tdb_sc->tdb)));
talloc_free(keystr);
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
diff --git a/libcli/auth/smbencrypt.c b/libcli/auth/smbencrypt.c
index 366f6df3ad..66fdbd25a8 100644
--- a/libcli/auth/smbencrypt.c
+++ b/libcli/auth/smbencrypt.c
@@ -118,7 +118,7 @@ bool E_deshash(const char *passwd, uint8_t p16[16])
{
bool ret;
uint8_t dospwd[14];
- TALLOC_CTX *mem_ctx;
+ TALLOC_CTX *frame = talloc_stackframe();
size_t converted_size;
@@ -126,23 +126,19 @@ bool E_deshash(const char *passwd, uint8_t p16[16])
ZERO_STRUCT(dospwd);
-#if _SAMBA_BUILD_ == 3
- mem_ctx = talloc_tos();
-#else
- mem_ctx = NULL;
-#endif
- tmpbuf = strupper_talloc(mem_ctx, passwd);
+ tmpbuf = strupper_talloc(frame, passwd);
if (tmpbuf == NULL) {
/* Too many callers don't check this result, we need to fill in the buffer with something */
- safe_strcpy((char *)dospwd, passwd, sizeof(dospwd)-1);
+ strlcpy((char *)dospwd, passwd ? passwd : "", sizeof(dospwd));
E_P16(dospwd, p16);
+ talloc_free(frame);
return false;
}
ZERO_STRUCT(dospwd);
ret = convert_string_error(CH_UNIX, CH_DOS, tmpbuf, strlen(tmpbuf), dospwd, sizeof(dospwd), &converted_size);
- talloc_free(tmpbuf);
+ talloc_free(frame);
/* Only the first 14 chars are considered, password need not
* be null terminated. We do this in the error and success
diff --git a/libcli/auth/wscript_build b/libcli/auth/wscript_build
index bdf52d0399..acb1ce38f0 100644
--- a/libcli/auth/wscript_build
+++ b/libcli/auth/wscript_build
@@ -2,7 +2,7 @@
bld.SAMBA_LIBRARY('cliauth',
source='',
- deps='NTLMSSP_COMMON MSRPC_PARSE LIBCLI_AUTH COMMON_SCHANNEL PAM_ERRORS SPNEGO_PARSE KRB5_WRAP',
+ deps='NTLMSSP_COMMON MSRPC_PARSE LIBCLI_AUTH COMMON_SCHANNEL PAM_ERRORS SPNEGO_PARSE KRB5_WRAP errors',
private_library=True,
grouping_library=True)
@@ -40,5 +40,5 @@ bld.SAMBA_SUBSYSTEM('SPNEGO_PARSE',
deps='asn1util')
bld.SAMBA_SUBSYSTEM('KRB5_WRAP',
- source='krb5_wrap.c kerberos_pac.c',
- deps='krb5 ndr-krb5pac com_err')
+ source='krb5_wrap.c',
+ deps='gssapi_krb5 krb5 ndr-krb5pac com_err KRB5_PAC')