[SCM] Samba Shared Repository - branch master updated -
439086099ad97a49c93102af1e6edafabea64b6f
Volker Lendecke
vlendec at samba.org
Mon Oct 6 07:57:06 GMT 2008
The branch, master has been updated
via 439086099ad97a49c93102af1e6edafabea64b6f (commit)
via 2f6026248ec9a84f6a263622f1753e98c89eb543 (commit)
via f3ba7fc0b973ea66ee57fe0e1be73b3bcefc07fb (commit)
from bb4e9d72dd7de46ae4635ff5fbe5427b2a93e7cc (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 439086099ad97a49c93102af1e6edafabea64b6f
Author: Volker Lendecke <vl at samba.org>
Date: Mon Sep 22 19:29:05 2008 +0200
Add netlogond auth method
This authenticates against a local running samba4 using SamLogonEx. We retrieve
the machine password using samba4's mymachinepwd script and store the schannel
key for re-use in secrets.tdb.
commit 2f6026248ec9a84f6a263622f1753e98c89eb543
Author: Volker Lendecke <vl at samba.org>
Date: Mon Sep 22 19:24:59 2008 +0200
Add dyn_NCALRPCDIR
commit f3ba7fc0b973ea66ee57fe0e1be73b3bcefc07fb
Author: Volker Lendecke <vl at samba.org>
Date: Mon Sep 22 19:23:21 2008 +0200
Store a local schannel key in secrets.tdb
-----------------------------------------------------------------------
Summary of changes:
source3/Makefile.in | 7 +
source3/auth/auth_netlogond.c | 321 +++++++++++++++++++++++++++++++++++++++++
source3/configure.in | 3 +-
source3/dynconfig.c | 1 +
source3/include/dynconfig.h | 4 +
source3/include/proto.h | 4 +
source3/include/secrets.h | 2 +
source3/m4/check_path.m4 | 19 +++
source3/passdb/secrets.c | 25 ++++
9 files changed, 385 insertions(+), 1 deletions(-)
create mode 100644 source3/auth/auth_netlogond.c
Changeset truncated at 500 lines:
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 61e946e..eb6a05c 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -127,6 +127,7 @@ LOGFILEBASE = @logfilebase@
CONFIGFILE = $(CONFIGDIR)/smb.conf
LMHOSTSFILE = $(CONFIGDIR)/lmhosts
CTDBDIR = @ctdbdir@
+NCALRPCDIR = @ncalrpcdir@
# This is where smbpasswd et al go
PRIVATEDIR = @privatedir@
@@ -166,6 +167,7 @@ PATH_FLAGS = -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" \
-DLOGFILEBASE=\"$(LOGFILEBASE)\" \
-DSHLIBEXT=\"@SHLIBEXT@\" \
-DCTDBDIR=\"$(CTDBDIR)\" \
+ -DNCALRPCDIR=\"$(NCALRPCDIR)\" \
-DCONFIGDIR=\"$(CONFIGDIR)\" \
-DCODEPAGEDIR=\"$(CODEPAGEDIR)\" \
-DCACHEDIR=\"$(CACHEDIR)\" \
@@ -636,6 +638,7 @@ AUTH_SERVER_OBJ = auth/auth_server.o
AUTH_UNIX_OBJ = auth/auth_unix.o
AUTH_WINBIND_OBJ = auth/auth_winbind.o
AUTH_SCRIPT_OBJ = auth/auth_script.o
+AUTH_NETLOGOND_OBJ = auth/auth_netlogond.o
AUTH_OBJ = auth/auth.o @AUTH_STATIC@ auth/auth_util.o auth/token_util.o \
auth/auth_compat.o auth/auth_ntlmssp.o \
@@ -2195,6 +2198,10 @@ bin/script. at SHLIBEXT@: $(BINARY_PREREQS) $(AUTH_SCRIPT_OBJ)
@echo "Building plugin $@"
@$(SHLD_MODULE) $(AUTH_SCRIPT_OBJ)
+bin/netlogond. at SHLIBEXT@: $(BINARY_PREREQS) $(AUTH_NETLOGOND_OBJ)
+ @echo "Building plugin $@"
+ @$(SHLD_MODULE) $(AUTH_NETLOGOND_OBJ)
+
bin/smbserver. at SHLIBEXT@: $(BINARY_PREREQS) $(AUTH_SERVER_OBJ)
@echo "Building plugin $@"
@$(SHLD_MODULE) $(AUTH_SERVER_OBJ)
diff --git a/source3/auth/auth_netlogond.c b/source3/auth/auth_netlogond.c
new file mode 100644
index 0000000..a57f3b7
--- /dev/null
+++ b/source3/auth/auth_netlogond.c
@@ -0,0 +1,321 @@
+/*
+ Unix SMB/CIFS implementation.
+ Authenticate against a netlogon pipe listening on a unix domain socket
+ Copyright (C) Volker Lendecke 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"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_AUTH
+
+static NTSTATUS netlogond_validate(TALLOC_CTX *mem_ctx,
+ const struct auth_context *auth_context,
+ const char *ncalrpc_sockname,
+ uint8_t schannel_key[16],
+ const auth_usersupplied_info *user_info,
+ struct netr_SamInfo3 **pinfo3,
+ NTSTATUS *schannel_bind_result)
+{
+ struct rpc_pipe_client *p;
+ struct cli_pipe_auth_data *auth;
+ struct netr_SamInfo3 *info3 = NULL;
+ NTSTATUS status;
+
+ *schannel_bind_result = NT_STATUS_OK;
+
+ status = rpc_pipe_open_ncalrpc(talloc_tos(), ncalrpc_sockname,
+ &ndr_table_netlogon.syntax_id, &p);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("rpc_pipe_open_ncalrpc failed: %s\n",
+ nt_errstr(status)));
+ return status;
+ }
+
+ status = rpccli_schannel_bind_data(p, lp_workgroup(),
+ PIPE_AUTH_LEVEL_PRIVACY,
+ schannel_key, &auth);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("rpccli_schannel_bind_data failed: %s\n",
+ nt_errstr(status)));
+ TALLOC_FREE(p);
+ return status;
+ }
+
+ status = rpc_pipe_bind(p, auth);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("rpc_pipe_bind failed: %s\n", nt_errstr(status)));
+ TALLOC_FREE(p);
+ *schannel_bind_result = status;
+ return status;
+ }
+
+ /*
+ * We have to fake a struct dcinfo, so that
+ * rpccli_netlogon_sam_network_logon_ex can decrypt the session keys.
+ */
+
+ p->dc = talloc(p, struct dcinfo);
+ if (p->dc == NULL) {
+ DEBUG(0, ("talloc failed\n"));
+ TALLOC_FREE(p);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ memcpy(p->dc->sess_key, schannel_key, 16);
+
+ status = rpccli_netlogon_sam_network_logon_ex(
+ p, p,
+ user_info->logon_parameters,/* flags such as 'allow
+ * workstation logon' */
+ global_myname(), /* server name */
+ user_info->smb_name, /* user name logging on. */
+ user_info->client_domain, /* domain name */
+ user_info->wksta_name, /* workstation name */
+ (uchar *)auth_context->challenge.data, /* 8 byte challenge. */
+ user_info->lm_resp, /* lanman 24 byte response */
+ user_info->nt_resp, /* nt 24 byte response */
+ &info3); /* info3 out */
+
+ DEBUG(10, ("rpccli_netlogon_sam_network_logon_ex returned %s\n",
+ nt_errstr(status)));
+
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(p);
+ return status;
+ }
+
+ *pinfo3 = talloc_move(mem_ctx, &info3);
+
+ TALLOC_FREE(p);
+ return NT_STATUS_OK;
+}
+
+static char *mymachinepw(TALLOC_CTX *mem_ctx)
+{
+ fstring pwd;
+ const char *script;
+ char *to_free = NULL;
+ ssize_t nread;
+ int ret, fd;
+
+ script = lp_parm_const_string(
+ GLOBAL_SECTION_SNUM, "auth_netlogond", "machinepwscript",
+ NULL);
+
+ if (script == NULL) {
+ to_free = talloc_asprintf(talloc_tos(), "%s/%s",
+ get_dyn_SBINDIR(), "mymachinepw");
+ script = to_free;
+ }
+ if (script == NULL) {
+ return NULL;
+ }
+
+ ret = smbrun(script, &fd);
+ DEBUG(ret ? 0 : 3, ("mymachinepw: Running the command `%s' gave %d\n",
+ script, ret));
+ TALLOC_FREE(to_free);
+
+ if (ret != 0) {
+ return NULL;
+ }
+
+ pwd[sizeof(pwd)-1] = '\0';
+
+ nread = read(fd, pwd, sizeof(pwd)-1);
+ close(fd);
+
+ if (nread <= 0) {
+ DEBUG(3, ("mymachinepwd: Could not read password\n"));
+ return NULL;
+ }
+
+ DEBUG(0, ("pwd: %d [%s]\n", (int)nread, pwd));
+
+ if (pwd[nread-1] == '\n') {
+ pwd[nread-1] = '\0';
+ }
+
+ return talloc_strdup(mem_ctx, pwd);
+}
+
+static NTSTATUS check_netlogond_security(const struct auth_context *auth_context,
+ void *my_private_data,
+ TALLOC_CTX *mem_ctx,
+ const auth_usersupplied_info *user_info,
+ auth_serversupplied_info **server_info)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct netr_SamInfo3 *info3 = NULL;
+ struct rpc_pipe_client *p;
+ struct cli_pipe_auth_data *auth;
+ uint32_t neg_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS;
+ char *plaintext_machinepw;
+ uint8_t machine_password[16];
+ uint8_t schannel_key[16];
+ NTSTATUS schannel_bind_result, status;
+ struct named_mutex *mutex;
+ const char *ncalrpcsock;
+
+ ncalrpcsock = lp_parm_const_string(
+ GLOBAL_SECTION_SNUM, "auth_netlogond", "socket", NULL);
+
+ if (ncalrpcsock == NULL) {
+ ncalrpcsock = talloc_asprintf(talloc_tos(), "%s/%s",
+ get_dyn_NCALRPCDIR(), "DEFAULT");
+ }
+
+ if (ncalrpcsock == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ if (!secrets_fetch_local_schannel_key(schannel_key)) {
+ goto new_key;
+ }
+
+ status = netlogond_validate(talloc_tos(), auth_context, ncalrpcsock,
+ schannel_key, user_info, &info3,
+ &schannel_bind_result);
+
+ DEBUG(10, ("netlogond_validate returned %s\n", nt_errstr(status)));
+
+ if (NT_STATUS_IS_OK(status)) {
+ goto okay;
+ }
+
+ if (NT_STATUS_IS_OK(schannel_bind_result)) {
+ /*
+ * This is a real failure from the DC
+ */
+ goto done;
+ }
+
+ new_key:
+
+ mutex = grab_named_mutex(talloc_tos(), "LOCAL_SCHANNEL_KEY", 60);
+ if (mutex == NULL) {
+ DEBUG(10, ("Could not get mutex LOCAL_SCHANNEL_KEY\n"));
+ status = NT_STATUS_ACCESS_DENIED;
+ goto done;
+ }
+
+ DEBUG(10, ("schannel bind failed, setting up new key\n"));
+
+ status = rpc_pipe_open_ncalrpc(talloc_tos(), ncalrpcsock,
+ &ndr_table_netlogon.syntax_id, &p);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("rpc_pipe_open_ncalrpc failed: %s\n",
+ nt_errstr(status)));
+ goto done;
+ }
+
+ status = rpccli_anon_bind_data(p, &auth);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("rpccli_anon_bind_data failed: %s\n",
+ nt_errstr(status)));
+ goto done;
+ }
+
+ status = rpc_pipe_bind(p, auth);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("rpc_pipe_bind failed: %s\n", nt_errstr(status)));
+ goto done;
+ }
+
+ TALLOC_FREE(auth);
+
+ plaintext_machinepw = mymachinepw(talloc_tos());
+ if (plaintext_machinepw == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ E_md4hash(plaintext_machinepw, machine_password);
+
+ TALLOC_FREE(plaintext_machinepw);
+
+ status = rpccli_netlogon_setup_creds(
+ p, global_myname(), lp_workgroup(), global_myname(),
+ global_myname(), machine_password, SEC_CHAN_BDC, &neg_flags);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("rpccli_netlogon_setup_creds failed: %s\n",
+ nt_errstr(status)));
+ goto done;
+ }
+
+ memcpy(schannel_key, p->dc->sess_key, 16);
+ secrets_store_local_schannel_key(schannel_key);
+
+ TALLOC_FREE(p);
+
+ /*
+ * Retry the authentication with the mutex held. This way nobody else
+ * can step on our toes.
+ */
+
+ status = netlogond_validate(talloc_tos(), auth_context, ncalrpcsock,
+ schannel_key, user_info, &info3,
+ &schannel_bind_result);
+
+ DEBUG(10, ("netlogond_validate returned %s\n", nt_errstr(status)));
+
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ okay:
+
+ status = make_server_info_info3(mem_ctx, user_info->smb_name,
+ user_info->domain, server_info,
+ info3);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("make_server_info_info3 failed: %s\n",
+ nt_errstr(status)));
+ TALLOC_FREE(frame);
+ return status;
+ }
+
+ status = NT_STATUS_OK;
+
+ done:
+ TALLOC_FREE(frame);
+ return status;
+}
+
+/* module initialisation */
+static NTSTATUS auth_init_netlogond(struct auth_context *auth_context,
+ const char *param,
+ auth_methods **auth_method)
+{
+ if (!make_auth_methods(auth_context, auth_method)) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ (*auth_method)->name = "netlogond";
+ (*auth_method)->auth = check_netlogond_security;
+ return NT_STATUS_OK;
+}
+
+NTSTATUS auth_netlogond_init(void)
+{
+ smb_register_auth(AUTH_INTERFACE_VERSION, "netlogond",
+ auth_init_netlogond);
+ return NT_STATUS_OK;
+}
diff --git a/source3/configure.in b/source3/configure.in
index 545a565..1eba4a0 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -404,7 +404,7 @@ AC_SUBST(DYNEXP)
dnl Add modules that have to be built by default here
dnl These have to be built static:
-default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsarpc rpc_samr rpc_winreg rpc_initshutdown rpc_dssetup rpc_wkssvc rpc_svcctl2 rpc_ntsvcs2 rpc_netlogon rpc_netdfs rpc_srvsvc rpc_spoolss rpc_eventlog2 auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin vfs_default nss_info_template"
+default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsarpc rpc_samr rpc_winreg rpc_initshutdown rpc_dssetup rpc_wkssvc rpc_svcctl2 rpc_ntsvcs2 rpc_netlogon rpc_netdfs rpc_srvsvc rpc_spoolss rpc_eventlog2 auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin auth_netlogond vfs_default nss_info_template"
dnl These are preferably build shared, and static if dlopen() is not available
default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 charset_CP850 charset_CP437 auth_script vfs_readahead vfs_xattr_tdb vfs_streams_xattr vfs_acl_xattr vfs_smb_traffic_analyzer"
@@ -6077,6 +6077,7 @@ SMB_MODULE(auth_server, \$(AUTH_SERVER_OBJ), "bin/smbserver.$SHLIBEXT", AUTH)
SMB_MODULE(auth_domain, \$(AUTH_DOMAIN_OBJ), "bin/domain.$SHLIBEXT", AUTH)
SMB_MODULE(auth_builtin, \$(AUTH_BUILTIN_OBJ), "bin/builtin.$SHLIBEXT", AUTH)
SMB_MODULE(auth_script, \$(AUTH_SCRIPT_OBJ), "bin/script.$SHLIBEXT", AUTH)
+SMB_MODULE(auth_netlogond, \$(AUTH_NETLOGOND_OBJ), "bin/netlogond.$SHLIBEXT", AUTH)
SMB_SUBSYSTEM(AUTH,auth/auth.o)
SMB_MODULE(vfs_default, \$(VFS_DEFAULT_OBJ), "bin/default.$SHLIBEXT", VFS)
diff --git a/source3/dynconfig.c b/source3/dynconfig.c
index 3a54507..6125f99 100644
--- a/source3/dynconfig.c
+++ b/source3/dynconfig.c
@@ -77,6 +77,7 @@ DEFINE_DYN_CONFIG_PARAM(MODULESDIR)
DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
DEFINE_DYN_CONFIG_PARAM(PIDDIR)
+DEFINE_DYN_CONFIG_PARAM(NCALRPCDIR)
DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
diff --git a/source3/include/dynconfig.h b/source3/include/dynconfig.h
index 758bde3..8267064 100644
--- a/source3/include/dynconfig.h
+++ b/source3/include/dynconfig.h
@@ -71,6 +71,10 @@ const char *get_dyn_PIDDIR(void);
const char *set_dyn_PIDDIR(const char *newpath);
bool is_default_dyn_PIDDIR(void);
+const char *get_dyn_NCALRPCDIR(void);
+const char *set_dyn_NCALRPCDIR(const char *newpath);
+bool is_default_dyn_NCALRPCDIR(void);
+
const char *get_dyn_SMB_PASSWD_FILE(void);
const char *set_dyn_SMB_PASSWD_FILE(const char *newpath);
bool is_default_dyn_SMB_PASSWD_FILE(void);
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 7cdcba1..30e309c 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -46,6 +46,8 @@ bool password_ok(const char *smb_name, DATA_BLOB password_blob);
void attempt_machine_password_change(void);
NTSTATUS auth_domain_init(void);
+NTSTATUS auth_netlogond_init(void);
+
/* The following definitions come from auth/auth_ntlmssp.c */
NTSTATUS auth_ntlmssp_start(AUTH_NTLMSSP_STATE **auth_ntlmssp_state);
@@ -6421,6 +6423,8 @@ bool secrets_restore_schannel_session_info(TALLOC_CTX *mem_ctx,
struct dcinfo **ppdc);
bool secrets_store_generic(const char *owner, const char *key, const char *secret);
char *secrets_fetch_generic(const char *owner, const char *key);
+bool secrets_store_local_schannel_key(uint8_t schannel_key[16]);
+bool secrets_fetch_local_schannel_key(uint8_t schannel_key[16]);
/* The following definitions come from passdb/util_builtin.c */
diff --git a/source3/include/secrets.h b/source3/include/secrets.h
index d9f4575..3c8e2cc 100644
--- a/source3/include/secrets.h
+++ b/source3/include/secrets.h
@@ -45,6 +45,8 @@
#define SECRETS_LDAP_BIND_PW "SECRETS/LDAP_BIND_PW"
+#define SECRETS_LOCAL_SCHANNEL_KEY "SECRETS/LOCAL_SCHANNEL_KEY"
+
/* Authenticated user info is stored in secrets.tdb under these keys */
#define SECRETS_AUTH_USER "SECRETS/AUTH_USER"
diff --git a/source3/m4/check_path.m4 b/source3/m4/check_path.m4
index 7aa8c21..40a97d3 100644
--- a/source3/m4/check_path.m4
+++ b/source3/m4/check_path.m4
@@ -18,6 +18,7 @@ AC_PREFIX_DEFAULT(/usr/local/samba)
rootsbindir="\${SBINDIR}"
lockdir="\${VARDIR}/locks"
piddir="\${VARDIR}/locks"
+ncalrpcdir="\${VARDIR}/ncalrpc"
test "${mandir}" || mandir="\${prefix}/man"
logfilebase="\${VARDIR}"
privatedir="\${prefix}/private"
@@ -46,6 +47,7 @@ AC_ARG_WITH(fhs,
codepagedir="\${MODULESDIR}"
statedir="\${VARDIR}/lib/samba"
cachedir="\${VARDIR}/lib/samba"
+ ncalrpcdir="\${VARDIR}/ncalrpc"
AC_DEFINE(FHS_COMPATIBLE, 1, [Whether to use fully FHS-compatible paths])
;;
esac])
@@ -115,6 +117,22 @@ AC_ARG_WITH(piddir,
esac])
#################################################
+# set ncalrpc directory location
+AC_ARG_WITH(ncalprcdir,
+[AS_HELP_STRING([--with-ncalprcdir=DIR], [Where to put ncalrpc sockets ($ac_default_prefix/var/ncalrpc)])],
+[ case "$withval" in
+ yes|no)
+ #
+ # Just in case anybody calls it without argument
+ #
+ AC_MSG_WARN([--with-ncalrpcdir called without argument - will use default])
+ ;;
+ * )
+ ncalrpcdir="$withval"
+ ;;
+ esac])
+
+#################################################
# set SWAT directory location
AC_ARG_WITH(swatdir,
[AS_HELP_STRING([--with-swatdir=DIR], [Where to put SWAT files ($ac_default_prefix/swat)])],
@@ -227,6 +245,7 @@ AC_ARG_WITH(mandir,
AC_SUBST(configdir)
AC_SUBST(lockdir)
AC_SUBST(piddir)
+AC_SUBST(ncalrpcdir)
AC_SUBST(logfilebase)
AC_SUBST(ctdbdir)
AC_SUBST(privatedir)
--
Samba Shared Repository
More information about the samba-cvs
mailing list