From 418e92d06da0638d92c48ffd310a409c89e2fa48 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Sep 2005 23:58:14 +0000 Subject: r10234: Add new auth module "auth_script" to allow valid users to be provisioned on demand - calls script with domain, username, challenge and LM and NT responses - passing the info through a pipe. Jeremy. (This used to be commit 67be4ee41cd244bcc0445cac7c9e1e2d40e93c9b) --- source3/auth/auth_script.c | 155 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 source3/auth/auth_script.c (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c new file mode 100644 index 0000000000..1a715fca31 --- /dev/null +++ b/source3/auth/auth_script.c @@ -0,0 +1,155 @@ +/* + Unix SMB/CIFS implementation. + + Call out to a shell script for an authentication check. + + Copyright (C) Jeremy Allison 2005. + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#undef malloc + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_AUTH + +/* Create a string containing the supplied : + * domain\n + * user\n + * ascii hex challenge\n + * ascii hex LM response\n + * ascii hex NT response\n\0 + * and execute a shell script to check this. + * Allows external programs to create users on demand. + * Script returns zero on success, non-zero on fail. + */ + +static NTSTATUS script_check_user_credentials(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) +{ + const char *script = lp_parm_const_string( GLOBAL_SECTION_SNUM, "auth_script", "script", NULL); + char *secret_str; + size_t secret_str_len; + char hex_str[49]; + int ret, i; + + if (!script) { + return NT_STATUS_INVALID_PARAMETER; + } + + if (!user_info) { + return NT_STATUS_INVALID_PARAMETER; + } + + if (!auth_context) { + DEBUG(3,("script_check_user_credentials: no auth_info !\n")); + return NT_STATUS_INVALID_PARAMETER; + } + + secret_str_len = strlen(user_info->domain.str) + 1 + + strlen(user_info->smb_name.str) + 1 + + 16 + 1 + /* 8 bytes of challenge going to 16 */ + 48 + 1 + /* 24 bytes of challenge going to 48 */ + 48 + 1; + + secret_str = malloc(secret_str_len); + if (!secret_str) { + return NT_STATUS_NO_MEMORY; + } + + safe_strcpy( secret_str, user_info->domain.str, secret_str_len - 1); + safe_strcat( secret_str, "\n", secret_str_len - 1); + safe_strcat( secret_str, user_info->smb_name.str, secret_str_len - 1); + safe_strcat( secret_str, "\n", secret_str_len - 1); + + for (i = 0; i < 8; i++) { + slprintf(&hex_str[i*2], 3, "%02X", auth_context->challenge.data[i]); + } + safe_strcat( secret_str, hex_str, secret_str_len - 1); + safe_strcat( secret_str, "\n", secret_str_len - 1); + + if (user_info->lm_resp.data) { + for (i = 0; i < 24; i++) { + slprintf(&hex_str[i*2], 3, "%02X", user_info->lm_resp.data[i]); + } + safe_strcat( secret_str, hex_str, secret_str_len - 1); + } + safe_strcat( secret_str, "\n", secret_str_len - 1); + + if (user_info->nt_resp.data) { + for (i = 0; i < 24; i++) { + slprintf(&hex_str[i*2], 3, "%02X", user_info->nt_resp.data[i]); + } + safe_strcat( secret_str, hex_str, secret_str_len - 1); + } + safe_strcat( secret_str, "\n", secret_str_len - 1); + + DEBUG(10,("script_check_user_credentials: running %s with parameters:\n%s\n", + script, secret_str )); + + ret = smbrunsecret( script, secret_str); + + SAFE_FREE(secret_str); + + if (ret) { + DEBUG(1,("script_check_user_credentials: failed to authenticate %s\\%s\n", + user_info->domain.str, user_info->smb_name.str )); + /* auth failed. */ + return NT_STATUS_NO_SUCH_USER; + } + + /* Cause the auth system to keep going.... */ + return NT_STATUS_NOT_IMPLEMENTED; +} + +/* module initialisation */ +static NTSTATUS auth_init_script(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 = "script"; + (*auth_method)->auth = script_check_user_credentials; + + if (param && *param) { + /* we load the 'fallback' module - if script isn't here, call this + module */ + if (!load_auth_module(auth_context, param, (auth_methods **)&(*auth_method)->private_data)) { + return NT_STATUS_UNSUCCESSFUL; + } + + } + return NT_STATUS_OK; +} + +#if 0 +/* Define this to build static. */ +NTSTATUS auth_script_init(void) +{ + return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script); +} +#else +/* Define this to build shared. */ +NTSTATUS init_module(void) +{ + return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script); +} +#endif -- cgit From 0af1500fc0bafe61019f1b2ab1d9e1d369221240 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Feb 2006 22:19:41 +0000 Subject: r13316: Let the carnage begin.... Sync with trunk as off r13315 (This used to be commit 17e63ac4ed8325c0d44fe62b2442449f3298559f) --- source3/auth/auth_script.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c index 1a715fca31..1bc33ec59e 100644 --- a/source3/auth/auth_script.c +++ b/source3/auth/auth_script.c @@ -63,8 +63,8 @@ static NTSTATUS script_check_user_credentials(const struct auth_context *auth_co return NT_STATUS_INVALID_PARAMETER; } - secret_str_len = strlen(user_info->domain.str) + 1 + - strlen(user_info->smb_name.str) + 1 + + secret_str_len = strlen(user_info->domain) + 1 + + strlen(user_info->smb_name) + 1 + 16 + 1 + /* 8 bytes of challenge going to 16 */ 48 + 1 + /* 24 bytes of challenge going to 48 */ 48 + 1; @@ -74,9 +74,9 @@ static NTSTATUS script_check_user_credentials(const struct auth_context *auth_co return NT_STATUS_NO_MEMORY; } - safe_strcpy( secret_str, user_info->domain.str, secret_str_len - 1); + safe_strcpy( secret_str, user_info->domain, secret_str_len - 1); safe_strcat( secret_str, "\n", secret_str_len - 1); - safe_strcat( secret_str, user_info->smb_name.str, secret_str_len - 1); + safe_strcat( secret_str, user_info->smb_name, secret_str_len - 1); safe_strcat( secret_str, "\n", secret_str_len - 1); for (i = 0; i < 8; i++) { @@ -110,7 +110,7 @@ static NTSTATUS script_check_user_credentials(const struct auth_context *auth_co if (ret) { DEBUG(1,("script_check_user_credentials: failed to authenticate %s\\%s\n", - user_info->domain.str, user_info->smb_name.str )); + user_info->domain, user_info->smb_name )); /* auth failed. */ return NT_STATUS_NO_SUCH_USER; } -- cgit From 31693197bee0d71e83418c0fb72685fd848e358f Mon Sep 17 00:00:00 2001 From: Paul Green Date: Wed, 26 Apr 2006 15:41:25 +0000 Subject: r15283: Oh yeah. The build farm doesn't do much with head. OK, here is the patch to SAMBA_3_0 to declare prototypes for the initialization functions. These are the same changes I just made to head. --paulg (This used to be commit 17774387ad879b6a72dd1cf406326318add31b04) --- source3/auth/auth_script.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c index 1bc33ec59e..05bae44865 100644 --- a/source3/auth/auth_script.c +++ b/source3/auth/auth_script.c @@ -140,16 +140,14 @@ static NTSTATUS auth_init_script(struct auth_context *auth_context, const char * return NT_STATUS_OK; } -#if 0 /* Define this to build static. */ NTSTATUS auth_script_init(void) { return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script); } -#else + /* Define this to build shared. */ NTSTATUS init_module(void) { return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script); } -#endif -- cgit From 0ec947bf1a661ac275fd6bd0aa96b6982f50dab3 Mon Sep 17 00:00:00 2001 From: Paul Green Date: Wed, 26 Apr 2006 16:18:02 +0000 Subject: r15285: Fix the build. (This used to be commit 2270a5196db071bbf15aed92637a24f81d179cd5) --- source3/auth/auth_script.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c index 05bae44865..722abe3d04 100644 --- a/source3/auth/auth_script.c +++ b/source3/auth/auth_script.c @@ -145,9 +145,10 @@ NTSTATUS auth_script_init(void) { return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script); } - +#if 0 /* Define this to build shared. */ NTSTATUS init_module(void) { return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script); } +#endif -- cgit From 567e8fa6ca61e136f94d06e858ee30577c8f36e3 Mon Sep 17 00:00:00 2001 From: Paul Green Date: Sun, 30 Apr 2006 23:49:39 +0000 Subject: r15368: Remove some dead code. -- paulg (This used to be commit e1bd357fe87a66861d092fcdbdde1ff6ffcc8cf2) --- source3/auth/auth_script.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c index 722abe3d04..ec7264924c 100644 --- a/source3/auth/auth_script.c +++ b/source3/auth/auth_script.c @@ -140,15 +140,7 @@ static NTSTATUS auth_init_script(struct auth_context *auth_context, const char * return NT_STATUS_OK; } -/* Define this to build static. */ NTSTATUS auth_script_init(void) { return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script); } -#if 0 -/* Define this to build shared. */ -NTSTATUS init_module(void) -{ - return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script); -} -#endif -- cgit From 0691ed55cade8093213db38555edb536ee0c557d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 17 Aug 2006 11:54:23 +0000 Subject: r17584: Some C++ Warnings (This used to be commit f6194cf4b263454bbdf180a7d014ffc3498df497) --- source3/auth/auth_script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c index ec7264924c..70c906d942 100644 --- a/source3/auth/auth_script.c +++ b/source3/auth/auth_script.c @@ -69,7 +69,7 @@ static NTSTATUS script_check_user_credentials(const struct auth_context *auth_co 48 + 1 + /* 24 bytes of challenge going to 48 */ 48 + 1; - secret_str = malloc(secret_str_len); + secret_str = (char *)malloc(secret_str_len); if (!secret_str) { return NT_STATUS_NO_MEMORY; } -- cgit From 72e9a5d9e658514568586fb6e7ec4a8e479bf8ad Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 19 Sep 2006 01:25:52 +0000 Subject: r18665: Remove two type-punned warnings (This used to be commit 157b2c0c262dc9b9ae2a8a3133479e66e6c8db07) --- source3/auth/auth_script.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c index 70c906d942..3d007b7730 100644 --- a/source3/auth/auth_script.c +++ b/source3/auth/auth_script.c @@ -132,10 +132,11 @@ static NTSTATUS auth_init_script(struct auth_context *auth_context, const char * if (param && *param) { /* we load the 'fallback' module - if script isn't here, call this module */ - if (!load_auth_module(auth_context, param, (auth_methods **)&(*auth_method)->private_data)) { + auth_methods *priv; + if (!load_auth_module(auth_context, param, &priv)) { return NT_STATUS_UNSUCCESSFUL; } - + (*auth_method)->private_data = (void *)priv; } return NT_STATUS_OK; } -- cgit From 84cd4d05e0a6e04c2a9fd1f4608a73ee1086a7af Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 20 Dec 2006 01:07:21 +0000 Subject: r20268: merge -r 20261:20263 from samba_3_0_24 get rid of previous prototype warnings (This used to be commit 90265c83ff1c7f11672694ff005d8ecc5d4a867f) --- source3/auth/auth_script.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c index 3d007b7730..bdcd7533f9 100644 --- a/source3/auth/auth_script.c +++ b/source3/auth/auth_script.c @@ -141,6 +141,7 @@ static NTSTATUS auth_init_script(struct auth_context *auth_context, const char * return NT_STATUS_OK; } +NTSTATUS auth_script_init(void); NTSTATUS auth_script_init(void) { return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script); -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/auth/auth_script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c index bdcd7533f9..4d65269b89 100644 --- a/source3/auth/auth_script.c +++ b/source3/auth/auth_script.c @@ -7,7 +7,7 @@ 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 2 of the License, or + 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, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/auth/auth_script.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/auth/auth_script.c') diff --git a/source3/auth/auth_script.c b/source3/auth/auth_script.c index 4d65269b89..6cbace71e8 100644 --- a/source3/auth/auth_script.c +++ b/source3/auth/auth_script.c @@ -16,8 +16,7 @@ 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit