From 27439c53c54f1821e90c4db383abe512a2f3db6b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 22 Feb 2002 02:57:49 +0000 Subject: Also add the matching example pdb module. (This used to be commit fbfb7ee896469e79043fab02481bacd2621a302d) --- examples/pdb/Makefile | 31 +++++++++++++ examples/pdb/README | 9 ++++ examples/pdb/pdb_test.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 examples/pdb/Makefile create mode 100644 examples/pdb/README create mode 100644 examples/pdb/pdb_test.c (limited to 'examples/pdb') diff --git a/examples/pdb/Makefile b/examples/pdb/Makefile new file mode 100644 index 0000000000..115fd3c87e --- /dev/null +++ b/examples/pdb/Makefile @@ -0,0 +1,31 @@ +# Makefile for samba-pdb examples +# Variables + +CC = gcc +LIBTOOL = libtool + +SAMBA_SRC = ../../source +SAMBA_INCL = ../../source/include +UBIQX_SRC = ../../source/ubiqx +SMBWR_SRC = ../../source/smbwrapper +CFLAGS = -I$(SAMBA_SRC) -I$(SAMBA_INCL) -I$(UBIQX_SRC) -I$(SMBWR_SRC) -Wall -g +PDB_OBJS = pdb_test.so + +# Default target + +default: $(PDB_OBJS) + +# Pattern rules + +%.so: %.lo + $(LIBTOOL) $(CC) -shared -o $@ $< $(LDFLAGS) + +%.lo: %.c + $(LIBTOOL) $(CC) $(CPPFLAGS) $(CFLAGS) -c $< + +# Misc targets + +clean: + rm -rf .libs + rm -f core *~ *% *.bak \ + $(PDB_OBJS) $(PDB_OBJS:.so=.o) $(PDB_OBJS:.so=.lo) diff --git a/examples/pdb/README b/examples/pdb/README new file mode 100644 index 0000000000..ccc39248aa --- /dev/null +++ b/examples/pdb/README @@ -0,0 +1,9 @@ +README for Samba Password Database (PDB) examples +==================================================== +15-2-2002 Jelmer Vernooij + +The pdb_test.c file in this directory contains a very basic example of +a pdb plugin. It just prints the name of the function that is executed using +DEBUG. Maybe it's nice to include some of the arguments to the function in the +future too.. + diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c new file mode 100644 index 0000000000..4b4189e9d5 --- /dev/null +++ b/examples/pdb/pdb_test.c @@ -0,0 +1,121 @@ +/* + * Test password backend for samba + * Copyright (C) Jelmer Vernooij 2002 + * + * 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" + +static BOOL testsam_setsampwent(struct pdb_context *context, BOOL update) +{ + DEBUG(0, ("testsam_setsampwent called\n")); + return True; +} + +/*************************************************************** + End enumeration of the passwd list. +****************************************************************/ + +static void testsam_endsampwent(struct pdb_context *context) +{ + DEBUG(0, ("testsam_endsampwent called\n")); +} + +/***************************************************************** + Get one SAM_ACCOUNT from the list (next in line) +*****************************************************************/ + +static BOOL testsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user) +{ + DEBUG(0, ("testsam_getsampwent called\n")); + return False; +} + +/****************************************************************** + Lookup a name in the SAM database +******************************************************************/ + +static BOOL testsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, const char *sname) +{ + DEBUG(0, ("testsam_getsampwnam called\n")); + return False; +} + +/*************************************************************************** + Search by rid + **************************************************************************/ + +static BOOL testsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, uint32 rid) +{ + DEBUG(0, ("testsam_getsampwrid called\n")); + return False; +} + +/*************************************************************************** + Delete a SAM_ACCOUNT +****************************************************************************/ + +static BOOL testsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sam_pass) +{ + DEBUG(0, ("testsam_delete_sam_account called\n")); + return False; +} + +/*************************************************************************** + Modifies an existing SAM_ACCOUNT +****************************************************************************/ + +static BOOL testsam_update_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) +{ + DEBUG(0, ("testsam_update_sam_account called\n")); + return False; +} + +/*************************************************************************** + Adds an existing SAM_ACCOUNT +****************************************************************************/ + +static BOOL testsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) +{ + DEBUG(0, ("testsam_add_sam_account called\n")); + return False; +} + +NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +{ + NTSTATUS nt_status; + + if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { + return nt_status; + } + + (*pdb_method)->name = "testsam"; + + (*pdb_method)->setsampwent = testsam_setsampwent; + (*pdb_method)->endsampwent = testsam_endsampwent; + (*pdb_method)->getsampwent = testsam_getsampwent; + (*pdb_method)->getsampwnam = testsam_getsampwnam; + (*pdb_method)->getsampwrid = testsam_getsampwrid; + (*pdb_method)->add_sam_account = testsam_add_sam_account; + (*pdb_method)->update_sam_account = testsam_update_sam_account; + (*pdb_method)->delete_sam_account = testsam_delete_sam_account; + + DEBUG(0, ("Initializing testsam\n")); + if (location) + DEBUG(0, ("Location: %s\n", location)); + + return NT_STATUS_OK; +} -- cgit From cc60b069836cbc355e828675e6f089b6ef22b32e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 13 Apr 2002 08:16:41 +0000 Subject: This is the 'multiple pdb backends' patch from ctrlsoft, aka Jelmer Vernooij . This patch also includes major rework of pdbedit to use popt, and the addition of -i paramter (allowing the user to specify which PDBs is being operated on) and -e to export a pdb - useful for backup and testing etc. Use of -i and -e gets us pdb2pdb functionality for transition between backends, much like the sam2sam in TNG. Andrew Bartlett (This used to be commit c10def37f506d3f2bab442418ac08fdb62659b02) --- examples/pdb/README | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'examples/pdb') diff --git a/examples/pdb/README b/examples/pdb/README index ccc39248aa..9ca03bf593 100644 --- a/examples/pdb/README +++ b/examples/pdb/README @@ -7,3 +7,9 @@ a pdb plugin. It just prints the name of the function that is executed using DEBUG. Maybe it's nice to include some of the arguments to the function in the future too.. +To debug passdb backends, try to run gdb on the 'pdbedit' executable. That's really much easier than restarting smbd constantly and attaching with your debugger. + +New passdb plugins should go into the samba lib directory, (/usr/lib/samba/ for +most distributions) and should be prefixed with 'pdb_'. An example would be: +/usr/lib/samba/pdb_test.so + -- cgit From 98d5699d28c687f8af5671c9a29aa55dd5a01bfd Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 24 May 2002 09:57:48 +0000 Subject: Some of the updates from ctrlsoft's 'Various' patch: - convert net to popt - convert status to popt - adapt examples/pdb/ to multiple passdb system - add dynamic debug class example to examples/pdb/ and some reformatting to better match the samba coding style. Andrew Bartlett (This used to be commit 2498bc69d4e5c38ec385f640489daa94c508c726) --- examples/pdb/pdb_test.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index 4b4189e9d5..983a995d85 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -17,11 +17,15 @@ * Mass Ave, Cambridge, MA 02139, USA. */ + #include "includes.h" +static int testsam_debug_level = DBGC_ALL; +#undef DBGC_CLASS +#define DBGC_CLASS testsam_debug_level -static BOOL testsam_setsampwent(struct pdb_context *context, BOOL update) +static BOOL testsam_setsampwent(struct pdb_methods *methods, BOOL update) { - DEBUG(0, ("testsam_setsampwent called\n")); + DEBUG(10, ("testsam_setsampwent called\n")); return True; } @@ -29,18 +33,18 @@ static BOOL testsam_setsampwent(struct pdb_context *context, BOOL update) End enumeration of the passwd list. ****************************************************************/ -static void testsam_endsampwent(struct pdb_context *context) +static void testsam_endsampwent(struct pdb_methods *methods) { - DEBUG(0, ("testsam_endsampwent called\n")); + DEBUG(10, ("testsam_endsampwent called\n")); } /***************************************************************** Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL testsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user) +static BOOL testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) { - DEBUG(0, ("testsam_getsampwent called\n")); + DEBUG(10, ("testsam_getsampwent called\n")); return False; } @@ -48,9 +52,9 @@ static BOOL testsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user) Lookup a name in the SAM database ******************************************************************/ -static BOOL testsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, const char *sname) +static BOOL testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) { - DEBUG(0, ("testsam_getsampwnam called\n")); + DEBUG(10, ("testsam_getsampwnam called\n")); return False; } @@ -58,9 +62,9 @@ static BOOL testsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, Search by rid **************************************************************************/ -static BOOL testsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, uint32 rid) +static BOOL testsam_getsampwrid (struct pdb_methods *methods, SAM_ACCOUNT *user, uint32 rid) { - DEBUG(0, ("testsam_getsampwrid called\n")); + DEBUG(10, ("testsam_getsampwrid called\n")); return False; } @@ -68,9 +72,9 @@ static BOOL testsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sam_pass) +static BOOL testsam_delete_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT *sam_pass) { - DEBUG(0, ("testsam_delete_sam_account called\n")); + DEBUG(10, ("testsam_delete_sam_account called\n")); return False; } @@ -78,9 +82,9 @@ static BOOL testsam_delete_sam_account(struct pdb_context *context, const SAM_AC Modifies an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_update_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) +static BOOL testsam_update_sam_account (struct pdb_methods *methods, const SAM_ACCOUNT *newpwd) { - DEBUG(0, ("testsam_update_sam_account called\n")); + DEBUG(10, ("testsam_update_sam_account called\n")); return False; } @@ -88,9 +92,9 @@ static BOOL testsam_update_sam_account (struct pdb_context *context, const SAM_A Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) +static BOOL testsam_add_sam_account (struct pdb_methods *methods, const SAM_ACCOUNT *newpwd) { - DEBUG(0, ("testsam_add_sam_account called\n")); + DEBUG(10, ("testsam_add_sam_account called\n")); return False; } @@ -112,10 +116,16 @@ NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char (*pdb_method)->add_sam_account = testsam_add_sam_account; (*pdb_method)->update_sam_account = testsam_update_sam_account; (*pdb_method)->delete_sam_account = testsam_delete_sam_account; + + testsam_debug_level = debug_add_class("testsam"); + if (testsam_debug_level == -1) { + testsam_debug_level = DBGC_ALL; + DEBUG(0, ("testsam: Couldn't register custom debugging class!\n")); + } else DEBUG(0, ("testsam: Debug class number of 'testsam': %d\n", testsam_debug_level)); DEBUG(0, ("Initializing testsam\n")); if (location) - DEBUG(0, ("Location: %s\n", location)); + DEBUG(10, ("Location: %s\n", location)); return NT_STATUS_OK; } -- cgit From a770dd49a4d7df1d58912250358f523a12342982 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 14 Jun 2002 02:58:43 +0000 Subject: Add some comments on writing new pdb modules. (from ctrlsoft) Andrew Bartlett (This used to be commit 0a64ff4c9984c751ed6bd9e9bc8d16c70abec02d) --- examples/pdb/pdb_test.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'examples/pdb') diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index 983a995d85..c932c6128b 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -23,6 +23,10 @@ static int testsam_debug_level = DBGC_ALL; #undef DBGC_CLASS #define DBGC_CLASS testsam_debug_level +/*************************************************************** + Start enumeration of the passwd list. +****************************************************************/ + static BOOL testsam_setsampwent(struct pdb_methods *methods, BOOL update) { DEBUG(10, ("testsam_setsampwent called\n")); @@ -108,6 +112,9 @@ NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char (*pdb_method)->name = "testsam"; + /* Functions your pdb module doesn't provide should be set + * to NULL */ + (*pdb_method)->setsampwent = testsam_setsampwent; (*pdb_method)->endsampwent = testsam_endsampwent; (*pdb_method)->getsampwent = testsam_getsampwent; -- cgit From ea7cdc4de060181b11779d726ba2aecf0a09b72b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Jun 2002 12:19:35 +0000 Subject: Add module versioning to the passdb module system All passdb modules need to include a 'magic' macro that creates simple 'return my version number' function. (from metze and jelmer) Also fix up the dir_drive autosubsitute code to correctly use lp_logon_drive(). (from metze) Andrew Bartlett (This used to be commit 4a57c445dd4354034fc41b132a484afe6ab66e16) --- examples/pdb/README | 36 ++++++++++++++++++++++++++++++++++++ examples/pdb/pdb_test.c | 13 +++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/README b/examples/pdb/README index 9ca03bf593..a212604792 100644 --- a/examples/pdb/README +++ b/examples/pdb/README @@ -1,5 +1,41 @@ README for Samba Password Database (PDB) examples ==================================================== +21-6-2002 Stefan (metze) Metzmacher + +I have added an interface versioning. + +Every module MUST have a pdb_version() function. + +this is defined in include/passdb.h: +#define PDB_MODULE_VERSIONING_MAGIC \ +int pdb_version(void)\ +{\ + return PASSDB_INTERFACE_VERSION;\ +} + +You MUST add this line inside a module: +PDB_MODULE_VERSIONING_MAGIC + +21-6-2002 Stefan (metze) Metzmacher + +The pdb_interface was changed: + +this function are deleted: +static BOOL testsam_getsampwrid (struct pdb_methods *methods, SAM_ACCOUNT *user, uint32 rid) + +this function are added: +static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, DOM_SID sid) + +In the SAM_ACCOUNT struct: + +this fields are deleted: +uint32 user_rid; +uint32 group_rid; + +this fields are added: +DOM_SID user_sid; +DOM_SID group_sid; + 15-2-2002 Jelmer Vernooij The pdb_test.c file in this directory contains a very basic example of diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index c932c6128b..d2722d2e03 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -19,10 +19,15 @@ #include "includes.h" + static int testsam_debug_level = DBGC_ALL; + #undef DBGC_CLASS #define DBGC_CLASS testsam_debug_level +/* define the version of the passdb interface */ +PDB_MODULE_VERSIONING_MAGIC + /*************************************************************** Start enumeration of the passwd list. ****************************************************************/ @@ -63,12 +68,12 @@ static BOOL testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, } /*************************************************************************** - Search by rid + Search by sid **************************************************************************/ -static BOOL testsam_getsampwrid (struct pdb_methods *methods, SAM_ACCOUNT *user, uint32 rid) +static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, DOM_SID sid) { - DEBUG(10, ("testsam_getsampwrid called\n")); + DEBUG(10, ("testsam_getsampwsid called\n")); return False; } @@ -119,7 +124,7 @@ NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char (*pdb_method)->endsampwent = testsam_endsampwent; (*pdb_method)->getsampwent = testsam_getsampwent; (*pdb_method)->getsampwnam = testsam_getsampwnam; - (*pdb_method)->getsampwrid = testsam_getsampwrid; + (*pdb_method)->getsampwsid = testsam_getsampwsid; (*pdb_method)->add_sam_account = testsam_add_sam_account; (*pdb_method)->update_sam_account = testsam_update_sam_account; (*pdb_method)->delete_sam_account = testsam_delete_sam_account; -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- examples/pdb/README | 42 ++++++++++++++++++++++++++++++++++ examples/pdb/pdb_test.c | 60 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 83 insertions(+), 19 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/README b/examples/pdb/README index ccc39248aa..a212604792 100644 --- a/examples/pdb/README +++ b/examples/pdb/README @@ -1,5 +1,41 @@ README for Samba Password Database (PDB) examples ==================================================== +21-6-2002 Stefan (metze) Metzmacher + +I have added an interface versioning. + +Every module MUST have a pdb_version() function. + +this is defined in include/passdb.h: +#define PDB_MODULE_VERSIONING_MAGIC \ +int pdb_version(void)\ +{\ + return PASSDB_INTERFACE_VERSION;\ +} + +You MUST add this line inside a module: +PDB_MODULE_VERSIONING_MAGIC + +21-6-2002 Stefan (metze) Metzmacher + +The pdb_interface was changed: + +this function are deleted: +static BOOL testsam_getsampwrid (struct pdb_methods *methods, SAM_ACCOUNT *user, uint32 rid) + +this function are added: +static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, DOM_SID sid) + +In the SAM_ACCOUNT struct: + +this fields are deleted: +uint32 user_rid; +uint32 group_rid; + +this fields are added: +DOM_SID user_sid; +DOM_SID group_sid; + 15-2-2002 Jelmer Vernooij The pdb_test.c file in this directory contains a very basic example of @@ -7,3 +43,9 @@ a pdb plugin. It just prints the name of the function that is executed using DEBUG. Maybe it's nice to include some of the arguments to the function in the future too.. +To debug passdb backends, try to run gdb on the 'pdbedit' executable. That's really much easier than restarting smbd constantly and attaching with your debugger. + +New passdb plugins should go into the samba lib directory, (/usr/lib/samba/ for +most distributions) and should be prefixed with 'pdb_'. An example would be: +/usr/lib/samba/pdb_test.so + diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index 4b4189e9d5..d2722d2e03 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -17,11 +17,24 @@ * Mass Ave, Cambridge, MA 02139, USA. */ + #include "includes.h" -static BOOL testsam_setsampwent(struct pdb_context *context, BOOL update) +static int testsam_debug_level = DBGC_ALL; + +#undef DBGC_CLASS +#define DBGC_CLASS testsam_debug_level + +/* define the version of the passdb interface */ +PDB_MODULE_VERSIONING_MAGIC + +/*************************************************************** + Start enumeration of the passwd list. +****************************************************************/ + +static BOOL testsam_setsampwent(struct pdb_methods *methods, BOOL update) { - DEBUG(0, ("testsam_setsampwent called\n")); + DEBUG(10, ("testsam_setsampwent called\n")); return True; } @@ -29,18 +42,18 @@ static BOOL testsam_setsampwent(struct pdb_context *context, BOOL update) End enumeration of the passwd list. ****************************************************************/ -static void testsam_endsampwent(struct pdb_context *context) +static void testsam_endsampwent(struct pdb_methods *methods) { - DEBUG(0, ("testsam_endsampwent called\n")); + DEBUG(10, ("testsam_endsampwent called\n")); } /***************************************************************** Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL testsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user) +static BOOL testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) { - DEBUG(0, ("testsam_getsampwent called\n")); + DEBUG(10, ("testsam_getsampwent called\n")); return False; } @@ -48,19 +61,19 @@ static BOOL testsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user) Lookup a name in the SAM database ******************************************************************/ -static BOOL testsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, const char *sname) +static BOOL testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) { - DEBUG(0, ("testsam_getsampwnam called\n")); + DEBUG(10, ("testsam_getsampwnam called\n")); return False; } /*************************************************************************** - Search by rid + Search by sid **************************************************************************/ -static BOOL testsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, uint32 rid) +static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, DOM_SID sid) { - DEBUG(0, ("testsam_getsampwrid called\n")); + DEBUG(10, ("testsam_getsampwsid called\n")); return False; } @@ -68,9 +81,9 @@ static BOOL testsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sam_pass) +static BOOL testsam_delete_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT *sam_pass) { - DEBUG(0, ("testsam_delete_sam_account called\n")); + DEBUG(10, ("testsam_delete_sam_account called\n")); return False; } @@ -78,9 +91,9 @@ static BOOL testsam_delete_sam_account(struct pdb_context *context, const SAM_AC Modifies an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_update_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) +static BOOL testsam_update_sam_account (struct pdb_methods *methods, const SAM_ACCOUNT *newpwd) { - DEBUG(0, ("testsam_update_sam_account called\n")); + DEBUG(10, ("testsam_update_sam_account called\n")); return False; } @@ -88,9 +101,9 @@ static BOOL testsam_update_sam_account (struct pdb_context *context, const SAM_A Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd) +static BOOL testsam_add_sam_account (struct pdb_methods *methods, const SAM_ACCOUNT *newpwd) { - DEBUG(0, ("testsam_add_sam_account called\n")); + DEBUG(10, ("testsam_add_sam_account called\n")); return False; } @@ -104,18 +117,27 @@ NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char (*pdb_method)->name = "testsam"; + /* Functions your pdb module doesn't provide should be set + * to NULL */ + (*pdb_method)->setsampwent = testsam_setsampwent; (*pdb_method)->endsampwent = testsam_endsampwent; (*pdb_method)->getsampwent = testsam_getsampwent; (*pdb_method)->getsampwnam = testsam_getsampwnam; - (*pdb_method)->getsampwrid = testsam_getsampwrid; + (*pdb_method)->getsampwsid = testsam_getsampwsid; (*pdb_method)->add_sam_account = testsam_add_sam_account; (*pdb_method)->update_sam_account = testsam_update_sam_account; (*pdb_method)->delete_sam_account = testsam_delete_sam_account; + + testsam_debug_level = debug_add_class("testsam"); + if (testsam_debug_level == -1) { + testsam_debug_level = DBGC_ALL; + DEBUG(0, ("testsam: Couldn't register custom debugging class!\n")); + } else DEBUG(0, ("testsam: Debug class number of 'testsam': %d\n", testsam_debug_level)); DEBUG(0, ("Initializing testsam\n")); if (location) - DEBUG(0, ("Location: %s\n", location)); + DEBUG(10, ("Location: %s\n", location)); return NT_STATUS_OK; } -- cgit From 3fce46ac7d790fbe9fcdd2426277857612bb252a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 10 Aug 2002 20:14:32 +0000 Subject: Adding pdb_xml and pdb_mysql passdb modules. Added some consts to pdb_test to follow pdb_methods struct more strictly (This used to be commit bb1c4501992650a5e26b4bc743aeae551852becc) --- examples/pdb/README | 4 + examples/pdb/mysql/ChangeLog | 41 ++ examples/pdb/mysql/Makefile.in | 33 ++ examples/pdb/mysql/README | 92 ++++ examples/pdb/mysql/pdb_mysql.c | 983 +++++++++++++++++++++++++++++++++++++++++ examples/pdb/pdb_test.c | 8 +- examples/pdb/xml/ChangeLog | 13 + examples/pdb/xml/Makefile.in | 33 ++ examples/pdb/xml/README | 14 + examples/pdb/xml/TODO | 6 + examples/pdb/xml/pdb_xml.c | 561 +++++++++++++++++++++++ 11 files changed, 1784 insertions(+), 4 deletions(-) create mode 100644 examples/pdb/mysql/ChangeLog create mode 100644 examples/pdb/mysql/Makefile.in create mode 100644 examples/pdb/mysql/README create mode 100644 examples/pdb/mysql/pdb_mysql.c create mode 100644 examples/pdb/xml/ChangeLog create mode 100644 examples/pdb/xml/Makefile.in create mode 100644 examples/pdb/xml/README create mode 100644 examples/pdb/xml/TODO create mode 100644 examples/pdb/xml/pdb_xml.c (limited to 'examples/pdb') diff --git a/examples/pdb/README b/examples/pdb/README index a212604792..561473129b 100644 --- a/examples/pdb/README +++ b/examples/pdb/README @@ -1,5 +1,9 @@ README for Samba Password Database (PDB) examples ==================================================== +8-8-2002 Jelmer Vernooij + +Added mysql and xml modules. See README in xml/ and mysql/ for details. + 21-6-2002 Stefan (metze) Metzmacher I have added an interface versioning. diff --git a/examples/pdb/mysql/ChangeLog b/examples/pdb/mysql/ChangeLog new file mode 100644 index 0000000000..5aeeb66268 --- /dev/null +++ b/examples/pdb/mysql/ChangeLog @@ -0,0 +1,41 @@ +** This file is now deprecated, use CVS' log featues ** + +2002-06-13 Jelmer Vernooij + * Converted to using SID's like samba HEAD does now + * Fixed some FIXME's + +2002-05-28 Jelmer Vernooij + * Updated docs, after some testing by Vance Lankhaar + +2002-05-25 Jelmer Vernooij + * Added support for dynamic debug classes + * Fixed nt/lanman password support + * Released 1.2 + +2002-05-06 Jelmer Vernooij + * Added support for multiple instances of pdb_mysql + * Added identifiers + * Updated documentation + * Released 1.1 + +2002-04-27 Jelmer Vernooij + * Updated documentation + * Released 1.0! + +2002-04-27 Jelmer Vernooij + * Added update/add sam account support + * Released 0.4 + +2002-04-13 Jelmer Vernooij + * Support for multiple instances of pdb_mysql + * Released 0.3 + +2002-04-12 Jelmer Vernooij + * Now using lp_parm_string to retrieve configuration values (instead of + our configuration files) + * Updated documentation + * Released 0.2 + +2002-04-10 Jelmer Vernooij + * Released 0.1 + * Initial release. Not supporting adding and updating data of users diff --git a/examples/pdb/mysql/Makefile.in b/examples/pdb/mysql/Makefile.in new file mode 100644 index 0000000000..1da6ea789e --- /dev/null +++ b/examples/pdb/mysql/Makefile.in @@ -0,0 +1,33 @@ +PDB_OBJS = pdb_mysql.so +PDB_LDFLAGS = -lmysqlclient +MAKEFILE = Makefile.pdb + +include $(MAKEFILE) + +CC = @CC@ +LIBTOOL = libtool +CFLAGS = @CFLAGS@ $(PDB_CFLAGS) +CPPFLAGS = @CPPFLAGS@ $(PDB_CPPFLAGS) +LDFLAGS = @LDFLAGS@ $(PDB_LDFLAGS) +LDSHFLAGS = -shared +srcdir = @builddir@ +FLAGS = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper -I. $(CPPFLAGS) -I$(srcdir) + +# Default target + +default: $(PDB_OBJS) + +# Pattern rules + +%.so: %.lo + $(LIBTOOL) $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< + +%.lo: %.c + $(LIBTOOL) $(CC) $(FLAGS) -c $< + +# Misc targets + +clean: + rm -rf .libs + rm -f core *~ *% *.bak \ + $(PDB_OBJS) $(PDB_OBJS:.so=.o) $(PDB_OBJS:.so=.lo) diff --git a/examples/pdb/mysql/README b/examples/pdb/mysql/README new file mode 100644 index 0000000000..e3cbcab8cf --- /dev/null +++ b/examples/pdb/mysql/README @@ -0,0 +1,92 @@ +PDB MySQL plugin for samba v1.1 +-- + +Building +========= +Before you can build the plugin, set the variable SAMBA_SRC in Makefile to the +path containing the samba sources. This is usually the 'source' directory in +the samba tarball or CVS. + +Next, type make, and then copy pdb_mysql.so to any location you want. I +strongly recommend installing it in $PREFIX/lib or /usr/lib/samba/ + +Configuring +============ +This plugin lacks some good documentation, but here is some short info: + +Add a the following to the 'passdb backend' variable in your smb.conf: + +passdb backend = [other-plugins] plugin:/location/to/pdb_mysql.so:identifier [other-plugins] + +The identifier can be any string you like, as long as it doesn't collide with +the identifiers of other plugins or other instances of pdb_mysql. If you +specify multiple pdb_mysql.so entries in 'passdb backend', you also need to +use different identifiers! + +Additional options can be given thru the smb.conf file in the [global] section. + +identifier:mysql host - host name, defaults to 'localhost' +identifier:mysql password +identifier:mysql user - defaults to 'samba' +identifier:mysql database - defaults to 'samba' +identifier:mysql port - defaults to 3306 +identifier:table - Name of the table containing users + +Names of the columns in this table(I've added column types those columns + should have first): +identifier:logon time column - int(9) +identifier:logoff time column - int(9) +identifier:kickoff time column - int(9) +identifier:pass last set time column - int(9) +identifier:pass can change time column - int(9) +identifier:pass must change time column - int(9) +identifier:username column - varchar(255) - unix username +identifier:domain column - varchar(255) - NT domain user is part of +identifier:nt username column - varchar(255) - NT username +identifier:fullname column - varchar(255) - Full name of user +identifier:home dir column - varchar(255) - Unix homedir path +identifier:dir drive column - varchar(2) - Directory drive path (eg: 'H:') +identifier:logon script column - varchar(255) - Batch file to run on client side when logging on +identifier:profile path column - varchar(255) - Path of profile +identifier:acct desc column - varchar(255) - Some ASCII NT user data +identifier:workstations column - varchar(255) - Workstations user can logon to (or NULL for all) +identifier:unknown string column - varchar(255) - unknown string +identifier:munged dial column - varchar(255) - ? +identifier:uid column - int(9) - Unix user ID (uid) +identifier:gid column - int(9) - Unix user group (gid) +identifier:user sid column - varchar(255) - NT user SID +identifier:group sid column - varchar(255) - NT group ID +identifier:lanman pass column - varchar(255) - encrypted lanman password +identifier:nt pass column - varchar(255) - encrypted nt passwd +identifier:plaintext pass column - varchar(255) - plaintext password +identifier:acct control column - int(9) - nt user data +identifier:unknown 3 column - int(9) - unknown +identifier:logon divs column - int(9) - ? +identifier:hours len column - int(9) - ? +identifier:unknown 5 column - int(9) - unknown +identifier:unknown 6 column - int(9) - unknown + +Eventually, you can put a colon (:) after the name of each column, which +should specify the column to update when updating the table. You can also +specify nothing behind the colon - then the data from the field will not be +updated. + +Using plaintext passwords or encrypted password +=============================================== +I strongly discourage the use of plaintext passwords, however, you can use them: + +If you would like to use plaintext passwords, set 'identifier:lanman pass column' and 'identifier:nt pass column' to 'NULL' (without the quotes) and 'identifier:plaintext pass column' to the name of the column containing the plaintext passwords. + +If you use encrypted passwords, set the 'identifier:plaintext pass column' to 'NULL' (without the quotes). This is the default. + +Getting non-column data from the table +====================================== +It is possible to have not all data in the database and making some 'constant'. + +For example, you can set 'identifier:fullname column' to : + CONCAT(First_name,' ',Sur_name) + +Or, set 'identifier:workstations column' to : + NULL + +See the MySQL documentation for more language constructs. diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c new file mode 100644 index 0000000000..c7e9e781c3 --- /dev/null +++ b/examples/pdb/mysql/pdb_mysql.c @@ -0,0 +1,983 @@ + +/* + * MySQL password backend for samba + * Copyright (C) Jelmer Vernooij 2002 + * + * 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" +#include + +#define CONFIG_TABLE_DEFAULT "user" +#define CONFIG_LOGON_TIME_DEFAULT "logon_time" +#define CONFIG_LOGOFF_TIME_DEFAULT "logoff_time" +#define CONFIG_KICKOFF_TIME_DEFAULT "kickoff_time" +#define CONFIG_PASS_LAST_SET_TIME_DEFAULT "pass_last_set_time" +#define CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT "pass_can_change_time" +#define CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT "pass_must_change_time" +#define CONFIG_USERNAME_DEFAULT "username" +#define CONFIG_DOMAIN_DEFAULT "domain" +#define CONFIG_NT_USERNAME_DEFAULT "nt_username" +#define CONFIG_FULLNAME_DEFAULT "nt_fullname" +#define CONFIG_HOME_DIR_DEFAULT "home_dir" +#define CONFIG_DIR_DRIVE_DEFAULT "dir_drive" +#define CONFIG_LOGON_SCRIPT_DEFAULT "logon_script" +#define CONFIG_PROFILE_PATH_DEFAULT "profile_path" +#define CONFIG_ACCT_DESC_DEFAULT "acct_desc" +#define CONFIG_WORKSTATIONS_DEFAULT "workstations" +#define CONFIG_UNKNOWN_STR_DEFAULT "unknown_str" +#define CONFIG_MUNGED_DIAL_DEFAULT "munged_dial" +#define CONFIG_UID_DEFAULT "uid" +#define CONFIG_GID_DEFAULT "gid" +#define CONFIG_USER_SID_DEFAULT "user_sid" +#define CONFIG_GROUP_SID_DEFAULT "group_sid" +#define CONFIG_LM_PW_DEFAULT "lm_pw" +#define CONFIG_NT_PW_DEFAULT "nt_pw" +#define CONFIG_PLAIN_PW_DEFAULT "NULL" +#define CONFIG_ACCT_CTRL_DEFAULT "acct_ctrl" +#define CONFIG_UNKNOWN_3_DEFAULT "unknown_3" +#define CONFIG_LOGON_DIVS_DEFAULT "logon_divs" +#define CONFIG_HOURS_LEN_DEFAULT "hours_len" +#define CONFIG_UNKNOWN_5_DEFAULT "unknown_5" +#define CONFIG_UNKNOWN_6_DEFAULT "unknown_6" +#define CONFIG_HOST_DEFAULT "localhost" +#define CONFIG_USER_DEFAULT "samba" +#define CONFIG_PASS_DEFAULT "" +#define CONFIG_PORT_DEFAULT "3306" +#define CONFIG_DB_DEFAULT "samba" + +static int mysqlsam_debug_level = DBGC_ALL; + +#undef DBGC_CLASS +#define DBGC_CLASS mysqlsam_debug_level + +PDB_MODULE_VERSIONING_MAGIC + +typedef struct pdb_mysql_data { + MYSQL *handle; + MYSQL_RES *pwent; + char *location; +} pdb_mysql_data; + +/* Used to construct insert and update queries */ + +typedef struct pdb_mysql_query { + char update; + TALLOC_CTX *mem_ctx; + char *part1; + char *part2; +} pdb_mysql_query; + +#define SET_DATA(data,methods) { \ + if(!methods){ \ + DEBUG(0, ("invalid methods!\n")); \ + return False; \ + } \ + data = (struct pdb_mysql_data *)methods->private_data; \ + if(!data || !(data->handle)){ \ + DEBUG(0, ("invalid handle!\n")); \ + return False; \ + } \ +} +void +pdb_mysql_int_field(struct pdb_methods *m, + struct pdb_mysql_query *q, char *name, int value) +{ + if (!name || strchr(name, '\'')) + return; /* This field shouldn't be set by us */ + + if (q->update) { + q->part1 = + talloc_asprintf_append(q->mem_ctx, q->part1, + "%s = %d,", name, value); + } else { + q->part1 = + talloc_asprintf_append(q->mem_ctx, q->part1, "%s,", name); + q->part2 = + talloc_asprintf_append(q->mem_ctx, q->part2, "%d,", value); + } +} + +static BOOL +pdb_mysql_string_field(struct pdb_methods *methods, + struct pdb_mysql_query *q, + char *name, const char *value) +{ + char *esc_value; + struct pdb_mysql_data *data; + + SET_DATA(data, methods); + + if (!name || !value || !strcmp(value, "") || strchr(name, '\'')) + return False; /* This field shouldn't be set by module */ + + esc_value = malloc(strlen(value) * 2 + 1); + mysql_real_escape_string(data->handle, esc_value, (char *) value, + strlen(value)); + + if (q->update) { + q->part1 = + talloc_asprintf_append(q->mem_ctx, q->part1, + "%s = '%s',", name, esc_value); + } else { + q->part1 = + talloc_asprintf_append(q->mem_ctx, q->part1, "%s,", name); + q->part2 = + talloc_asprintf_append(q->mem_ctx, q->part2, "'%s',", + esc_value); + } + + SAFE_FREE(esc_value); + + return True; +} + +static char * +config_value(pdb_mysql_data * data, char *name, char *default_value) +{ + if (lp_parm_string(NULL, data->location, name)) + return lp_parm_string(NULL, data->location, name); + + return default_value; +} + +static char * +config_value_write(pdb_mysql_data * data, char *name, char *default_value) +{ + char *v = config_value(data, name, NULL); + char *write; + + if (!v) + return default_value; + + write = strchr(v, ':'); + + /* Default to the same field as read field */ + if (!write) + return v; + + write++; + + /* If the field is 0 chars long, we shouldn't write to it */ + if (!strlen(write) || !strcmp(write, "NULL")) + return NULL; + + /* Otherwise, use the additionally specified */ + return write; +} + +static const char * +config_value_read(pdb_mysql_data * data, char *name, char *default_value) +{ + char *v = config_value(data, name, NULL); + char *write; + + if (!v) + return default_value; + + write = strchr(v, ':'); + + /* If no write is specified, there are no problems */ + if (!write) { + if (strlen(v) == 0) + return "NULL"; + return v; + } + + /* Otherwise, we have to cut the ':write_part' */ + *write = '\0'; + if (strlen(v) == 0) + return "NULL"; + + return v; +} + +/* Wrapper for atol that returns 0 if 'a' points to NULL */ +static long +xatol(char *a) +{ + long ret = 0; + + if (a != NULL) + ret = atol(a); + + return ret; +} + +static BOOL +row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) +{ + MYSQL_ROW row; + pstring temp; + unsigned int num_fields; + unsigned long *lengths; + DOM_SID sid; + + num_fields = mysql_num_fields(r); + row = mysql_fetch_row(r); + if (!row) + return False; + + pdb_set_logon_time(u, xatol(row[0]), FALSE); + pdb_set_logoff_time(u, xatol(row[1]), FALSE); + pdb_set_kickoff_time(u, xatol(row[2]), FALSE); + pdb_set_pass_last_set_time(u, xatol(row[3])); + pdb_set_pass_can_change_time(u, xatol(row[4]), FALSE); + pdb_set_pass_must_change_time(u, xatol(row[5]), FALSE); + pdb_set_username(u, row[6]); + pdb_set_domain(u, row[7]); + pdb_set_nt_username(u, row[8]); + pdb_set_fullname(u, row[9]); + pdb_set_homedir(u, row[10], True); + pdb_set_dir_drive(u, row[11], True); + pdb_set_logon_script(u, row[12], True); + pdb_set_profile_path(u, row[13], True); + pdb_set_acct_desc(u, row[14]); + pdb_set_workstations(u, row[15]); + pdb_set_unknown_str(u, row[16]); + pdb_set_munged_dial(u, row[17]); + + if (row[18]) + pdb_set_uid(u, xatol(row[18])); + if (row[19]) + pdb_set_gid(u, xatol(row[19])); + + string_to_sid(&sid, row[20]); + pdb_set_user_sid(u, &sid); + string_to_sid(&sid, row[21]); + pdb_set_group_sid(u, &sid); + + if (pdb_gethexpwd(row[22], temp)) + pdb_set_lanman_passwd(u, temp); + if (pdb_gethexpwd(row[23], temp)) + pdb_set_nt_passwd(u, temp); + + /* Only use plaintext password storage when lanman and nt are + * NOT used */ + if (!row[22] || !row[23]) + pdb_set_plaintext_passwd(u, row[24]); + + pdb_set_acct_ctrl(u, xatol(row[25])); + pdb_set_unknown_3(u, xatol(row[26])); + pdb_set_logon_divs(u, xatol(row[27])); + pdb_set_hours_len(u, xatol(row[28])); + pdb_set_unknown_5(u, xatol(row[29])); + pdb_set_unknown_6(u, xatol(row[30])); + + return True; +} + +static BOOL +mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) +{ + struct pdb_mysql_data *data = + (struct pdb_mysql_data *) methods->private_data; + char *query; + int ret; + + if (!data || !(data->handle)) { + DEBUG(0, ("invalid handle!\n")); + return False; + } + + asprintf(&query, + "SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s", + config_value_read(data, "logon time column", + CONFIG_LOGON_TIME_DEFAULT), + config_value_read(data, "logoff time column", + CONFIG_LOGOFF_TIME_DEFAULT), + config_value_read(data, "kickoff time column", + CONFIG_KICKOFF_TIME_DEFAULT), + config_value_read(data, "pass last set time column", + CONFIG_PASS_LAST_SET_TIME_DEFAULT), + config_value_read(data, "pass can change time column", + CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT), + config_value_read(data, "pass must change time column", + CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT), + config_value_read(data, "username column", + CONFIG_USERNAME_DEFAULT), + config_value_read(data, "domain column", + CONFIG_DOMAIN_DEFAULT), + config_value_read(data, "nt username column", + CONFIG_NT_USERNAME_DEFAULT), + config_value_read(data, "fullname column", + CONFIG_FULLNAME_DEFAULT), + config_value_read(data, "home dir column", + CONFIG_HOME_DIR_DEFAULT), + config_value_read(data, "dir drive column", + CONFIG_DIR_DRIVE_DEFAULT), + config_value_read(data, "logon script column", + CONFIG_LOGON_SCRIPT_DEFAULT), + config_value_read(data, "profile path column", + CONFIG_PROFILE_PATH_DEFAULT), + config_value_read(data, "acct desc column", + CONFIG_ACCT_DESC_DEFAULT), + config_value_read(data, "workstations column", + CONFIG_WORKSTATIONS_DEFAULT), + config_value_read(data, "unknown string column", + CONFIG_UNKNOWN_STR_DEFAULT), + config_value_read(data, "munged dial column", + CONFIG_MUNGED_DIAL_DEFAULT), + config_value_read(data, "uid column", CONFIG_UID_DEFAULT), + config_value_read(data, "gid column", CONFIG_GID_DEFAULT), + config_value_read(data, "user sid column", + CONFIG_USER_SID_DEFAULT), + config_value_read(data, "group sid column", + CONFIG_GROUP_SID_DEFAULT), + config_value_read(data, "lanman pass column", + CONFIG_LM_PW_DEFAULT), + config_value_read(data, "nt pass column", + CONFIG_NT_PW_DEFAULT), + config_value_read(data, "plain pass column", + CONFIG_PLAIN_PW_DEFAULT), + config_value_read(data, "acct ctrl column", + CONFIG_ACCT_CTRL_DEFAULT), + config_value_read(data, "unknown 3 column", + CONFIG_UNKNOWN_3_DEFAULT), + config_value_read(data, "logon divs column", + CONFIG_LOGON_DIVS_DEFAULT), + config_value_read(data, "hours len column", + CONFIG_HOURS_LEN_DEFAULT), + config_value_read(data, "unknown 5 column", + CONFIG_UNKNOWN_5_DEFAULT), + config_value_read(data, "unknown 6 column", + CONFIG_UNKNOWN_6_DEFAULT), + config_value(data, "table", CONFIG_TABLE_DEFAULT) + ); + + ret = mysql_query(data->handle, query); + SAFE_FREE(query); + + if (ret) { + DEBUG(0, + ("Error executing query: %s\n", mysql_error(data->handle))); + return False; + } + + data->pwent = mysql_store_result(data->handle); + + if (data->pwent == NULL) { + DEBUG(0, + ("Error storing results: %s\n", mysql_error(data->handle))); + return False; + } + + DEBUG(5, + ("mysqlsam_setsampwent succeeded(%d results)!\n", + mysql_num_fields(data->pwent))); + + return True; +} + +/*************************************************************** + End enumeration of the passwd list. + ****************************************************************/ + +static void +mysqlsam_endsampwent(struct pdb_methods *methods) +{ + struct pdb_mysql_data *data = + (struct pdb_mysql_data *) methods->private_data; + + if (data == NULL) { + DEBUG(0, ("invalid handle!\n")); + return; + } + + if (data->pwent != NULL) + mysql_free_result(data->pwent); + + data->pwent = NULL; + + DEBUG(5, ("mysql_endsampwent called\n")); +} + +/***************************************************************** + Get one SAM_ACCOUNT from the list (next in line) + *****************************************************************/ + +static BOOL +mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +{ + struct pdb_mysql_data *data; + + SET_DATA(data, methods); + + if (data->pwent == NULL) { + DEBUG(0, ("invalid pwent\n")); + return False; + } + + return row_to_sam_account(data->pwent, user); +} + +BOOL +mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, + const char *field, const char *sname) +{ + char *esc_sname; + char *query; + int ret; + MYSQL_RES *res; + struct pdb_mysql_data *data; + + SET_DATA(data, methods); + + esc_sname = malloc(strlen(sname) * 2 + 1); + if (!esc_sname) { + DEBUG(0, ("Not enough memory available!\n")); + return False; + } + + DEBUG(5, + ("mysqlsam_select_by_field: getting data where %s = %s(nonescaped)\n", + field, sname)); + + /* Escape sname */ + mysql_real_escape_string(data->handle, esc_sname, (char *) sname, + strlen(sname)); + + if (user == NULL) { + DEBUG(0, ("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); + SAFE_FREE(esc_sname); + return False; + } + + asprintf(&query, + "SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s WHERE %s = '%s'", + config_value_read(data, "logon time column", + CONFIG_LOGON_TIME_DEFAULT), + config_value_read(data, "logoff time column", + CONFIG_LOGOFF_TIME_DEFAULT), + config_value_read(data, "kickoff time column", + CONFIG_KICKOFF_TIME_DEFAULT), + config_value_read(data, "pass last set time column", + CONFIG_PASS_LAST_SET_TIME_DEFAULT), + config_value_read(data, "pass can change time column", + CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT), + config_value_read(data, "pass must change time column", + CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT), + config_value_read(data, "username column", + CONFIG_USERNAME_DEFAULT), + config_value_read(data, "domain column", + CONFIG_DOMAIN_DEFAULT), + config_value_read(data, "nt username column", + CONFIG_NT_USERNAME_DEFAULT), + config_value_read(data, "fullname column", + CONFIG_FULLNAME_DEFAULT), + config_value_read(data, "home dir column", + CONFIG_HOME_DIR_DEFAULT), + config_value_read(data, "dir drive column", + CONFIG_DIR_DRIVE_DEFAULT), + config_value_read(data, "logon script column", + CONFIG_LOGON_SCRIPT_DEFAULT), + config_value_read(data, "profile path column", + CONFIG_PROFILE_PATH_DEFAULT), + config_value_read(data, "acct desc column", + CONFIG_ACCT_DESC_DEFAULT), + config_value_read(data, "workstations column", + CONFIG_WORKSTATIONS_DEFAULT), + config_value_read(data, "unknown string column", + CONFIG_UNKNOWN_STR_DEFAULT), + config_value_read(data, "munged dial column", + CONFIG_MUNGED_DIAL_DEFAULT), + config_value_read(data, "uid column", CONFIG_UID_DEFAULT), + config_value_read(data, "gid column", CONFIG_GID_DEFAULT), + config_value_read(data, "user sid column", + CONFIG_USER_SID_DEFAULT), + config_value_read(data, "group sid column", + CONFIG_GROUP_SID_DEFAULT), + config_value_read(data, "lanman pass column", + CONFIG_LM_PW_DEFAULT), + config_value_read(data, "nt pass column", + CONFIG_NT_PW_DEFAULT), + config_value_read(data, "plain pass column", + CONFIG_PLAIN_PW_DEFAULT), + config_value_read(data, "acct ctrl column", + CONFIG_ACCT_CTRL_DEFAULT), + config_value_read(data, "unknown 3 column", + CONFIG_UNKNOWN_3_DEFAULT), + config_value_read(data, "logon divs column", + CONFIG_LOGON_DIVS_DEFAULT), + config_value_read(data, "hours len column", + CONFIG_HOURS_LEN_DEFAULT), + config_value_read(data, "unknown 5 column", + CONFIG_UNKNOWN_5_DEFAULT), + config_value_read(data, "unknown 6 column", + CONFIG_UNKNOWN_6_DEFAULT), + config_value(data, "table", CONFIG_TABLE_DEFAULT), field, + esc_sname); + + SAFE_FREE(esc_sname); + + ret = mysql_query(data->handle, query); + + SAFE_FREE(query); + + if (ret) { + DEBUG(0, + ("Error while executing MySQL query: %s\n", + mysql_error(data->handle))); + return False; + } + + res = mysql_store_result(data->handle); + if (res == NULL) { + DEBUG(0, + ("Error storing results: %s\n", mysql_error(data->handle))); + return False; + } + + ret = row_to_sam_account(res, user); + mysql_free_result(res); + + return ret; +} + +/****************************************************************** + Lookup a name in the SAM database + ******************************************************************/ + +static BOOL +mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, + const char *sname) +{ + struct pdb_mysql_data *data; + + SET_DATA(data, methods); + + if (!sname) { + DEBUG(0, ("invalid name specified")); + return False; + } + return mysqlsam_select_by_field(methods, user, + config_value_read(data, "username column", + CONFIG_USERNAME_DEFAULT), sname); +} + + +/*************************************************************************** + Search by sid + **************************************************************************/ + +static BOOL +mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, + const DOM_SID * sid) +{ + BOOL ret = False; + struct pdb_mysql_data *data; + fstring sid_str; + + SET_DATA(data, methods); + + sid_to_string(sid_str, sid); + + ret = + mysqlsam_select_by_field(methods, user, + config_value_read(data, "user sid column", + CONFIG_USER_SID_DEFAULT), sid_str); + + return ret; +} + +/*************************************************************************** + Delete a SAM_ACCOUNT + ****************************************************************************/ + +static BOOL +mysqlsam_delete_sam_account(struct pdb_methods *methods, + SAM_ACCOUNT * sam_pass) +{ + const char *sname = pdb_get_username(sam_pass); + char *esc; + char *query; + int ret; + struct pdb_mysql_data *data; + + SET_DATA(data, methods); + + if (!methods) { + DEBUG(0, ("invalid methods!\n")); + return False; + } + + data = (struct pdb_mysql_data *) methods->private_data; + if (!data || !(data->handle)) { + DEBUG(0, ("invalid handle!\n")); + return False; + } + + if (!sname) { + DEBUG(0, ("invalid name specified\n")); + return False; + } + + /* Escape sname */ + esc = malloc(strlen(sname) * 2 + 1); + if (!esc) { + DEBUG(0, ("Can't allocate memory to store escaped name\n")); + return False; + } + mysql_real_escape_string(data->handle, esc, (char *) sname, + strlen(sname)); + + asprintf(&query, "DELETE FROM %s WHERE %s = '%s'", + config_value(data, "table", CONFIG_TABLE_DEFAULT), + config_value_read(data, "username column", + CONFIG_USERNAME_DEFAULT), esc); + + SAFE_FREE(esc); + + ret = mysql_query(data->handle, query); + + SAFE_FREE(query); + + if (ret) { + DEBUG(0, + ("Error while executing query: %s\n", + mysql_error(data->handle))); + return False; + } + + DEBUG(5, ("User '%s' deleted\n", sname)); + return True; +} + +static BOOL +mysqlsam_replace_sam_account(struct pdb_methods *methods, + const SAM_ACCOUNT * newpwd, char isupdate) +{ + pstring temp; + uint32 store = pdb_get_init_flag(newpwd); + struct pdb_mysql_data *data; + pdb_mysql_query query; + fstring sid_str; + + if (!methods) { + DEBUG(0, ("invalid methods!\n")); + return False; + } + + data = (struct pdb_mysql_data *) methods->private_data; + if (data == NULL || data->handle == NULL) { + DEBUG(0, ("invalid handle!\n")); + return False; + } + query.update = isupdate; + + /* I know this is somewhat overkill but only the talloc + * functions have asprint_append and the 'normal' asprintf + * is a GNU extension */ + query.mem_ctx = talloc_init(); + query.part2 = talloc_asprintf(query.mem_ctx, "%s", ""); + if (query.update) { + query.part1 = + talloc_asprintf(query.mem_ctx, "UPDATE %s SET ", + config_value(data, "table", + CONFIG_TABLE_DEFAULT)); + } else { + query.part1 = + talloc_asprintf(query.mem_ctx, "INSERT INTO %s (", + config_value(data, "table", + CONFIG_TABLE_DEFAULT)); + } + + pdb_mysql_int_field(methods, &query, + config_value_write(data, "acct ctrl column", + CONFIG_ACCT_CTRL_DEFAULT), + pdb_get_acct_ctrl(newpwd)); + + if (store & FLAG_SAM_LOGONTIME) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, + "logon time column", + CONFIG_LOGON_TIME_DEFAULT), + pdb_get_logon_time(newpwd)); + } + + if (store & FLAG_SAM_LOGOFFTIME) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, + "logoff time column", + CONFIG_LOGOFF_TIME_DEFAULT), + pdb_get_logoff_time(newpwd)); + } + + if (store & FLAG_SAM_KICKOFFTIME) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, + "kickoff time column", + CONFIG_KICKOFF_TIME_DEFAULT), + pdb_get_kickoff_time(newpwd)); + } + + if (store & FLAG_SAM_CANCHANGETIME) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, + "pass can change time column", + CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT), + pdb_get_pass_can_change_time(newpwd)); + } + + if (store & FLAG_SAM_MUSTCHANGETIME) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, + "pass must change time column", + CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT), + pdb_get_pass_must_change_time(newpwd)); + } + + if (pdb_get_pass_last_set_time(newpwd)) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, + "pass must change time column", + CONFIG_PASS_LAST_SET_TIME_DEFAULT), + pdb_get_pass_last_set_time(newpwd)); + } + + if (pdb_get_hours_len(newpwd)) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, + "hours len column", + CONFIG_HOURS_LEN_DEFAULT), + pdb_get_hours_len(newpwd)); + } + + if (pdb_get_logon_divs(newpwd)) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, + "logon divs column", + CONFIG_LOGON_DIVS_DEFAULT), + pdb_get_logon_divs(newpwd)); + } + + if (store & FLAG_SAM_UID) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, "uid column", + CONFIG_UID_DEFAULT), + pdb_get_uid(newpwd)); + } + + if (store & FLAG_SAM_GID) { + pdb_mysql_int_field(methods, &query, + config_value_write(data, "gid column", + CONFIG_GID_DEFAULT), + pdb_get_gid(newpwd)); + } + + pdb_mysql_string_field(methods, &query, + config_value_write(data, "user sid column", + CONFIG_USER_SID_DEFAULT), + sid_to_string(sid_str, (DOM_SID *) + pdb_get_user_sid(newpwd))); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, "group sid column", + CONFIG_GROUP_SID_DEFAULT), + sid_to_string(sid_str, (DOM_SID *) + pdb_get_group_sid(newpwd))); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, "username column", + CONFIG_USERNAME_DEFAULT), + pdb_get_username(newpwd)); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, "domain column", + CONFIG_DOMAIN_DEFAULT), + pdb_get_domain(newpwd)); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, + "nt username column", + CONFIG_NT_USERNAME_DEFAULT), + pdb_get_nt_username(newpwd)); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, "fullname column", + CONFIG_FULLNAME_DEFAULT), + pdb_get_fullname(newpwd)); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, + "logon script column", + CONFIG_LOGON_SCRIPT_DEFAULT), + pdb_get_logon_script(newpwd)); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, + "profile path column", + CONFIG_PROFILE_PATH_DEFAULT), + pdb_get_profile_path(newpwd)); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, "dir drive column", + CONFIG_DIR_DRIVE_DEFAULT), + pdb_get_dir_drive(newpwd)); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, "home dir column", + CONFIG_HOME_DIR_DEFAULT), + pdb_get_homedir(newpwd)); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, + "workstations column", + CONFIG_WORKSTATIONS_DEFAULT), + pdb_get_workstations(newpwd)); + + pdb_mysql_string_field(methods, &query, + config_value_write(data, + "unknown string column", + CONFIG_UNKNOWN_STR_DEFAULT), + pdb_get_workstations(newpwd)); + + pdb_sethexpwd(temp, pdb_get_lanman_passwd(newpwd), + pdb_get_acct_ctrl(newpwd)); + pdb_mysql_string_field(methods, &query, + config_value_write(data, + "lanman pass column", + CONFIG_LM_PW_DEFAULT), temp); + + pdb_sethexpwd(temp, pdb_get_nt_passwd(newpwd), + pdb_get_acct_ctrl(newpwd)); + pdb_mysql_string_field(methods, &query, + config_value_write(data, "nt pass column", + CONFIG_NT_PW_DEFAULT), temp); + + if (query.update) { + query.part1[strlen(query.part1) - 1] = '\0'; + query.part1 = + talloc_asprintf_append(query.mem_ctx, query.part1, + " WHERE %s = '%s'", + config_value_read(data, + "user sid column", + CONFIG_USER_SID_DEFAULT), + sid_to_string(sid_str, (DOM_SID *) + pdb_get_user_sid + (newpwd))); + } else { + query.part2[strlen(query.part2) - 1] = ')'; + query.part1[strlen(query.part1) - 1] = ')'; + query.part1 = + talloc_asprintf_append(query.mem_ctx, query.part1, + " VALUES (%s", query.part2); + } + + DEBUG(0, ("%s\n", query.part1)); + /* Execute the query */ + if (mysql_query(data->handle, query.part1)) { + DEBUG(0, + ("Error executing %s, %s\n", query.part1, + mysql_error(data->handle))); + return False; + } + talloc_destroy(query.mem_ctx); + return True; +} + +static BOOL +mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) +{ + return mysqlsam_replace_sam_account(methods, newpwd, 0); +} + +static BOOL +mysqlsam_update_sam_account(struct pdb_methods *methods, + SAM_ACCOUNT * newpwd) +{ + return mysqlsam_replace_sam_account(methods, newpwd, 1); +} + +NTSTATUS +pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, + char *location) +{ + NTSTATUS nt_status; + struct pdb_mysql_data *data; + + mysqlsam_debug_level = debug_add_class("mysqlsam"); + if (mysqlsam_debug_level == -1) { + mysqlsam_debug_level = DBGC_ALL; + DEBUG(0, + ("mysqlsam: Couldn't register custom debugging class!\n")); + } + + if (!pdb_context) { + DEBUG(0, ("invalid pdb_methods specified\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + if (!NT_STATUS_IS_OK + (nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { + return nt_status; + } + + (*pdb_method)->name = "mysqlsam"; + + (*pdb_method)->setsampwent = mysqlsam_setsampwent; + (*pdb_method)->endsampwent = mysqlsam_endsampwent; + (*pdb_method)->getsampwent = mysqlsam_getsampwent; + (*pdb_method)->getsampwnam = mysqlsam_getsampwnam; + (*pdb_method)->getsampwsid = mysqlsam_getsampwsid; + (*pdb_method)->add_sam_account = mysqlsam_add_sam_account; + (*pdb_method)->update_sam_account = mysqlsam_update_sam_account; + (*pdb_method)->delete_sam_account = mysqlsam_delete_sam_account; + + data = talloc(pdb_context->mem_ctx, sizeof(struct pdb_mysql_data)); + (*pdb_method)->private_data = data; + data->handle = NULL; + data->pwent = NULL; + + if (!location) { + DEBUG(0, ("No identifier specified. See README for details\n")); + return NT_STATUS_INVALID_PARAMETER; + } + + data->location = smb_xstrdup(location); + + DEBUG(1, + ("Connecting to database server, host: %s, user: %s, password: %s, database: %s, port: %d\n", + config_value(data, "mysql host", CONFIG_HOST_DEFAULT), + config_value(data, "mysql user", CONFIG_USER_DEFAULT), + config_value(data, "mysql password", CONFIG_PASS_DEFAULT), + config_value(data, "mysql database", CONFIG_DB_DEFAULT), + xatol(config_value(data, "mysql port", CONFIG_PORT_DEFAULT)))); + + /* Do the mysql initialization */ + data->handle = mysql_init(NULL); + if (!data->handle) { + DEBUG(0, ("Failed to connect to server\n")); + return NT_STATUS_UNSUCCESSFUL; + } + /* Process correct entry in $HOME/.my.conf */ + if (!mysql_real_connect(data->handle, + config_value(data, "mysql host", CONFIG_HOST_DEFAULT), + config_value(data, "mysql user", CONFIG_USER_DEFAULT), + config_value(data, "mysql password", CONFIG_PASS_DEFAULT), + config_value(data, "mysql database", CONFIG_DB_DEFAULT), + xatol(config_value (data, "mysql port", CONFIG_PORT_DEFAULT)), + NULL, 0)) { + DEBUG(0, + ("Failed to connect to mysql database: error: %s\n", + mysql_error(data->handle))); + return NT_STATUS_UNSUCCESSFUL; + } + + DEBUG(5, ("Connected to mysql db\n")); + + return NT_STATUS_OK; +} diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index d2722d2e03..b46fe24bd6 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -71,7 +71,7 @@ static BOOL testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, Search by sid **************************************************************************/ -static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, DOM_SID sid) +static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, const DOM_SID *sid) { DEBUG(10, ("testsam_getsampwsid called\n")); return False; @@ -81,7 +81,7 @@ static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_delete_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT *sam_pass) +static BOOL testsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT *sam_pass) { DEBUG(10, ("testsam_delete_sam_account called\n")); return False; @@ -91,7 +91,7 @@ static BOOL testsam_delete_sam_account(struct pdb_methods *methods, const SAM_AC Modifies an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_update_sam_account (struct pdb_methods *methods, const SAM_ACCOUNT *newpwd) +static BOOL testsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) { DEBUG(10, ("testsam_update_sam_account called\n")); return False; @@ -101,7 +101,7 @@ static BOOL testsam_update_sam_account (struct pdb_methods *methods, const SAM_A Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_add_sam_account (struct pdb_methods *methods, const SAM_ACCOUNT *newpwd) +static BOOL testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) { DEBUG(10, ("testsam_add_sam_account called\n")); return False; diff --git a/examples/pdb/xml/ChangeLog b/examples/pdb/xml/ChangeLog new file mode 100644 index 0000000000..e44fa3bd30 --- /dev/null +++ b/examples/pdb/xml/ChangeLog @@ -0,0 +1,13 @@ +** This file is now deprecated - use CVS' log features ** + +2002-06-13 Jelmer Vernooij + * Use SID's instead of RID's (just like samba-HEAD CVS) + * Released 1.1 + +2002-05-26 Jelmer Vernooij + * Update read support (didn't support all elements yet) + * Released 1.0 + +2002-05-26 Jelmer Vernooij + * Initial release + * Released 0.5 diff --git a/examples/pdb/xml/Makefile.in b/examples/pdb/xml/Makefile.in new file mode 100644 index 0000000000..87d4546972 --- /dev/null +++ b/examples/pdb/xml/Makefile.in @@ -0,0 +1,33 @@ +PDB_OBJS = pdb_xml.so +PDB_CFLAGS = `xml2-config --cflags` +PDB_LDFLAGS = `xml2-config --libs` + +include $(MAKEFILE) + +CC = @CC@ +LIBTOOL = libtool +CFLAGS = @CFLAGS@ $(PDB_CFLAGS) +CPPFLAGS = @CPPFLAGS@ $(PDB_CPPFLAGS) +LDFLAGS = @LDFLAGS@ $(PDB_LDFLAGS) +LDSHFLAGS = -shared +srcdir = @builddir@ +FLAGS = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper -I. $(CPPFLAGS) -I$(srcdir) + +# Default target + +default: $(PDB_OBJS) + +# Pattern rules + +%.so: %.lo + $(LIBTOOL) $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< + +%.lo: %.c + $(LIBTOOL) $(CC) $(FLAGS) -c $< + +# Misc targets + +clean: + rm -rf .libs + rm -f core *~ *% *.bak \ + $(PDB_OBJS) $(PDB_OBJS:.so=.o) $(PDB_OBJS:.so=.lo) diff --git a/examples/pdb/xml/README b/examples/pdb/xml/README new file mode 100644 index 0000000000..afb08fdb4f --- /dev/null +++ b/examples/pdb/xml/README @@ -0,0 +1,14 @@ +Readme for samba pdb xml 0.5 +-- +This module requires libxml2 to be installed. + +The usage of pdb_xml is pretty straightforward. To export data, use: + +pdbedit -e plugin:/usr/lib/samba/pdb_xml.so:filename + +(where filename is the name of the file to put the data in) +To import data, use: + +pdbedit -i plugin:/usr/lib/samba/pdb_xml.so:filename -e + +Where filename is the name to read the data from and to put it in. diff --git a/examples/pdb/xml/TODO b/examples/pdb/xml/TODO new file mode 100644 index 0000000000..3947bb68be --- /dev/null +++ b/examples/pdb/xml/TODO @@ -0,0 +1,6 @@ +- Be faster. Don't rewrite the whole file when adding a user, but store + it in the memory and save it when exiting. Requires changes to samba source. + Gives the ability to read/write to standard input/output +- Do locking! +- Better names! +- Support stdin ? diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c new file mode 100644 index 0000000000..f237a7da9d --- /dev/null +++ b/examples/pdb/xml/pdb_xml.c @@ -0,0 +1,561 @@ + +/* + * XML password backend for samba + * Copyright (C) Jelmer Vernooij 2002 + * Some parts based on the libxml gjobread example by Daniel Veillard + * + * 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. + */ + +/* FIXME: Support stdin input by using '-' */ + +#define XML_URL "http://www.samba.org/ns" + +#include "includes.h" + +#include +#include + +static int xmlsam_debug_level = DBGC_ALL; + +#undef DBGC_CLASS +#define DBGC_CLASS xmlsam_debug_level + +PDB_MODULE_VERSIONING_MAGIC + +static char * iota(int a) { + static char tmp[10]; + + snprintf(tmp, 9, "%d", a); + return tmp; +} + +BOOL +parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) +{ + pstring temp; + + cur = cur->xmlChildrenNode; + while (cur != NULL) { + if (strcmp(cur->name, "crypt")) + DEBUG(0, ("Unknown element %s\n", cur->name)); + else { + if (!strcmp(xmlGetProp(cur, "type"), "nt") + && + pdb_gethexpwd(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1), temp)) + pdb_set_nt_passwd(u, temp); + else if (!strcmp(xmlGetProp(cur, "type"), "lanman") + && + pdb_gethexpwd(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1), temp)) + pdb_set_lanman_passwd(u, temp); + else + DEBUG(0, + ("Unknown crypt type: %s\n", + xmlGetProp(cur, "type"))); + } + cur = cur->next; + } + return True; +} + +BOOL +parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) +{ + char *tmp; + DOM_SID sid; + + tmp = xmlGetProp(cur, "sid"); + if (tmp){ + string_to_sid(&sid, tmp); + pdb_set_user_sid(u, &sid); + } + tmp = xmlGetProp(cur, "uid"); + if (tmp) + pdb_set_uid(u, atol(tmp)); + pdb_set_username(u, xmlGetProp(cur, "name")); + /* We don't care what the top level element name is */ + cur = cur->xmlChildrenNode; + while (cur != NULL) { + if ((!strcmp(cur->name, "group")) && (cur->ns == ns)) { + tmp = xmlGetProp(cur, "gid"); + if (tmp) + pdb_set_gid(u, atol(tmp)); + tmp = xmlGetProp(cur, "sid"); + if (tmp){ + string_to_sid(&sid, tmp); + pdb_set_group_sid(u, &sid); + } + } + + else if ((!strcmp(cur->name, "domain")) && (cur->ns == ns)) + pdb_set_domain(u, + xmlNodeListGetString(doc, cur->xmlChildrenNode, + 1)); + + else if (!strcmp(cur->name, "fullname") && cur->ns == ns) + pdb_set_fullname(u, + xmlNodeListGetString(doc, + cur->xmlChildrenNode, + 1)); + + else if (!strcmp(cur->name, "nt_username") && cur->ns == ns) + pdb_set_nt_username(u, + xmlNodeListGetString(doc, + cur->xmlChildrenNode, + 1)); + + else if (!strcmp(cur->name, "logon_script") && cur->ns == ns) + pdb_set_logon_script(u, + xmlNodeListGetString(doc, + cur->xmlChildrenNode, + 1), True); + + else if (!strcmp(cur->name, "profile_path") && cur->ns == ns) + pdb_set_profile_path(u, + xmlNodeListGetString(doc, + cur->xmlChildrenNode, + 1), True); + + else if (!strcmp(cur->name, "logon_time") && cur->ns == ns) + pdb_set_logon_time(u, + atol(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1)), True); + + else if (!strcmp(cur->name, "logoff_time") && cur->ns == ns) + pdb_set_logoff_time(u, + atol(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1)), + True); + + else if (!strcmp(cur->name, "kickoff_time") && cur->ns == ns) + pdb_set_kickoff_time(u, + atol(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1)), + True); + + else if (!strcmp(cur->name, "logon_divs") && cur->ns == ns) + pdb_set_logon_divs(u, + atol(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1))); + + else if (!strcmp(cur->name, "hours_len") && cur->ns == ns) + pdb_set_hours_len(u, + atol(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1))); + + else if (!strcmp(cur->name, "unknown_3") && cur->ns == ns) + pdb_set_unknown_3(u, + atol(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1))); + + else if (!strcmp(cur->name, "unknown_5") && cur->ns == ns) + pdb_set_unknown_5(u, + atol(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1))); + + else if (!strcmp(cur->name, "unknown_6") && cur->ns == ns) + pdb_set_unknown_6(u, + atol(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1))); + + else if (!strcmp(cur->name, "homedir") && cur->ns == ns) + pdb_set_homedir(u, + xmlNodeListGetString(doc, cur->xmlChildrenNode, + 1), True); + + else if (!strcmp(cur->name, "unknown_str") && cur->ns == ns) + pdb_set_unknown_str(u, + xmlNodeListGetString(doc, + cur->xmlChildrenNode, + 1)); + + else if (!strcmp(cur->name, "dir_drive") && cur->ns == ns) + pdb_set_dir_drive(u, + xmlNodeListGetString(doc, + cur->xmlChildrenNode, + 1), True); + + else if (!strcmp(cur->name, "munged_dial") && cur->ns == ns) + pdb_set_munged_dial(u, + xmlNodeListGetString(doc, + cur->xmlChildrenNode, + 1)); + + else if (!strcmp(cur->name, "acct_desc") && cur->ns == ns) + pdb_set_acct_desc(u, + xmlNodeListGetString(doc, + cur->xmlChildrenNode, + 1)); + + else if (!strcmp(cur->name, "acct_ctrl") && cur->ns == ns) + pdb_set_acct_ctrl(u, + atol(xmlNodeListGetString + (doc, cur->xmlChildrenNode, 1))); + + else if (!strcmp(cur->name, "workstations") && cur->ns == ns) + pdb_set_workstations(u, + xmlNodeListGetString(doc, + cur->xmlChildrenNode, + 1)); + + else if ((!strcmp(cur->name, "password")) && (cur->ns == ns)) { + tmp = xmlGetProp(cur, "last_set"); + if (tmp) + pdb_set_pass_last_set_time(u, atol(tmp)); + tmp = xmlGetProp(cur, "must_change"); + if (tmp) + pdb_set_pass_must_change_time(u, atol(tmp), True); + tmp = xmlGetProp(cur, "can_change"); + if (tmp) + pdb_set_pass_can_change_time(u, atol(tmp), True); + parsePass(doc, ns, cur, u); + } + + else + DEBUG(0, ("Unknown element %s\n", cur->name)); + cur = cur->next; + } + + return True; +} + +typedef struct pdb_xml { + char *location; + char written; + xmlDocPtr doc; + xmlNodePtr users; + xmlNodePtr pwent; + xmlNsPtr ns; +} pdb_xml; + +xmlNodePtr +parseSambaXMLFile(struct pdb_xml *data) +{ + xmlNodePtr cur; + + data->doc = xmlParseFile(data->location); + if (data->doc == NULL) + return NULL; + + cur = xmlDocGetRootElement(data->doc); + if (!cur) { + DEBUG(0, ("empty document\n")); + xmlFreeDoc(data->doc); + return NULL; + } + data->ns = xmlSearchNsByHref(data->doc, cur, XML_URL); + if (!data->ns) { + DEBUG(0, + ("document of the wrong type, samba user namespace not found\n")); + xmlFreeDoc(data->doc); + return NULL; + } + if (strcmp(cur->name, "samba")) { + DEBUG(0, ("document of the wrong type, root node != samba")); + xmlFreeDoc(data->doc); + return NULL; + } + + cur = cur->xmlChildrenNode; + while (cur && xmlIsBlankNode(cur)) { + cur = cur->next; + } + if (!cur) + return NULL; + if ((strcmp(cur->name, "users")) || (cur->ns != data->ns)) { + DEBUG(0, ("document of the wrong type, was '%s', users expected", + cur->name)); + DEBUG(0, ("xmlDocDump follows\n")); + xmlDocDump(stderr, data->doc); + DEBUG(0, ("xmlDocDump finished\n")); + xmlFreeDoc(data->doc); + return NULL; + } + data->users = cur; + cur = cur->xmlChildrenNode; + return cur; +} + +static BOOL +xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) +{ + pdb_xml *data; + + if (!methods) { + DEBUG(0, ("Invalid methods\n")); + return False; + } + data = (pdb_xml *) methods->private_data; + if (!data) { + DEBUG(0, ("Invalid pdb_xml_data\n")); + return False; + } + data->pwent = parseSambaXMLFile(data); + if (!data->pwent) + return False; + return True; +} + +/*************************************************************** + End enumeration of the passwd list. + ****************************************************************/ + +static void +xmlsam_endsampwent(struct pdb_methods *methods) +{ + pdb_xml *data; + + if (!methods) { + DEBUG(0, ("Invalid methods\n")); + return; + } + + data = (pdb_xml *) methods->private_data; + + if (!data) { + DEBUG(0, ("Invalid pdb_xml_data\n")); + return; + } + + xmlFreeDoc(data->doc); + data->doc = NULL; + data->pwent = NULL; +} + +/***************************************************************** + Get one SAM_ACCOUNT from the list (next in line) + *****************************************************************/ + +static BOOL +xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +{ + pdb_xml *data; + + if (!methods) { + DEBUG(0, ("Invalid methods\n")); + return False; + } + data = (pdb_xml *) methods->private_data; + + if (!data) { + DEBUG(0, ("Invalid pdb_xml_data\n")); + return False; + } + + while (data->pwent) { + if ((!strcmp(data->pwent->name, "user")) && + (data->pwent->ns == data->ns)) { + + parseUser(data->doc, data->ns, data->pwent, user); + data->pwent = data->pwent->next; + return True; + } + data->pwent = data->pwent->next; + } + return False; +} + +/*************************************************************************** + Adds an existing SAM_ACCOUNT + ****************************************************************************/ + +static BOOL +xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) +{ + pstring temp; + fstring sid_str; + xmlNodePtr cur, user, pass, root; + pdb_xml *data; + uint32 store = pdb_get_init_flag(u); + + DEBUG(10, ("xmlsam_add_sam_account called!\n")); + + if (!methods) { + DEBUG(0, ("Invalid methods\n")); + return False; + } + + data = (pdb_xml *) methods->private_data; + if (!data) { + DEBUG(0, ("Invalid pdb_xml_data\n")); + return False; + } + + /* Create a new document if we can't open the current one */ + if (!parseSambaXMLFile(data)) { + DEBUG(0, ("Can't load current XML file, creating a new one\n")); + data->doc = xmlNewDoc(XML_DEFAULT_VERSION); + root = xmlNewDocNode(data->doc, NULL, "samba", NULL); + cur = xmlDocSetRootElement(data->doc, root); + data->ns = xmlNewNs(root, XML_URL, "samba"); + data->users = xmlNewChild(root, data->ns, "users", NULL); + } + + user = xmlNewChild(data->users, data->ns, "user", NULL); + xmlNewProp(user, "sid", + sid_to_string(sid_str, pdb_get_user_sid(u))); + if (store & FLAG_SAM_UID) + xmlNewProp(user, "uid", iota(pdb_get_uid(u))); + + if (pdb_get_username(u) && strcmp(pdb_get_username(u), "")) + xmlNewProp(user, "name", pdb_get_username(u)); + + cur = xmlNewChild(user, data->ns, "group", NULL); + + xmlNewProp(cur, "sid", + sid_to_string(sid_str, pdb_get_group_sid(u))); + if (store & FLAG_SAM_GID) + xmlNewProp(cur, "gid", iota(pdb_get_gid(u))); + + if (store & FLAG_SAM_LOGONTIME) + xmlNewChild(user, data->ns, "login_time", + iota(pdb_get_logon_time(u))); + + if (store & FLAG_SAM_LOGOFFTIME) + xmlNewChild(user, data->ns, "logoff_time", + iota(pdb_get_logoff_time(u))); + + if (store & FLAG_SAM_KICKOFFTIME) + xmlNewChild(user, data->ns, "kickoff_time", + iota(pdb_get_kickoff_time(u))); + + if (pdb_get_domain(u) && strcmp(pdb_get_domain(u), "")) + xmlNewChild(user, data->ns, "domain", pdb_get_domain(u)); + + if (pdb_get_nt_username(u) && strcmp(pdb_get_nt_username(u), "")) + xmlNewChild(user, data->ns, "nt_username", pdb_get_nt_username(u)); + + if (pdb_get_fullname(u) && strcmp(pdb_get_fullname(u), "")) + xmlNewChild(user, data->ns, "fullname", pdb_get_fullname(u)); + + if (pdb_get_homedir(u) && strcmp(pdb_get_homedir(u), "")) + xmlNewChild(user, data->ns, "homedir", pdb_get_homedir(u)); + + if (pdb_get_dir_drive(u) && strcmp(pdb_get_dir_drive(u), "")) + xmlNewChild(user, data->ns, "dir_drive", pdb_get_dir_drive(u)); + + if (pdb_get_logon_script(u) && strcmp(pdb_get_logon_script(u), "")) + xmlNewChild(user, data->ns, "logon_script", + pdb_get_logon_script(u)); + + if (pdb_get_profile_path(u) && strcmp(pdb_get_profile_path(u), "")) + xmlNewChild(user, data->ns, "profile_path", + pdb_get_profile_path(u)); + + if (pdb_get_acct_desc(u) && strcmp(pdb_get_acct_desc(u), "")) + xmlNewChild(user, data->ns, "acct_desc", pdb_get_acct_desc(u)); + + if (pdb_get_workstations(u) && strcmp(pdb_get_workstations(u), "")) + xmlNewChild(user, data->ns, "workstations", + pdb_get_workstations(u)); + + if (pdb_get_unknown_str(u) && strcmp(pdb_get_unknown_str(u), "")) + xmlNewChild(user, data->ns, "unknown_str", pdb_get_unknown_str(u)); + + if (pdb_get_munged_dial(u) && strcmp(pdb_get_munged_dial(u), "")) + xmlNewChild(user, data->ns, "munged_dial", pdb_get_munged_dial(u)); + + + /* Password stuff */ + pass = xmlNewChild(user, data->ns, "password", NULL); + if (pdb_get_pass_last_set_time(u)) + xmlNewProp(pass, "last_set", iota(pdb_get_pass_last_set_time(u))); + if (store & FLAG_SAM_CANCHANGETIME) + xmlNewProp(pass, "can_change", + iota(pdb_get_pass_can_change_time(u))); + + if (store & FLAG_SAM_MUSTCHANGETIME) + xmlNewProp(pass, "must_change", + iota(pdb_get_pass_must_change_time(u))); + + + if (pdb_get_lanman_passwd(u)) { + pdb_sethexpwd(temp, pdb_get_lanman_passwd(u), + pdb_get_acct_ctrl(u)); + cur = xmlNewChild(pass, data->ns, "crypt", temp); + xmlNewProp(cur, "type", "lanman"); + } + + if (pdb_get_nt_passwd(u)) { + pdb_sethexpwd(temp, pdb_get_nt_passwd(u), pdb_get_acct_ctrl(u)); + cur = xmlNewChild(pass, data->ns, "crypt", temp); + xmlNewProp(cur, "type", "nt"); + } + + xmlNewChild(user, data->ns, "acct_ctrl", iota(pdb_get_acct_ctrl(u))); + xmlNewChild(user, data->ns, "unknown_3", iota(pdb_get_unknown3(u))); + + if (pdb_get_logon_divs(u)) + xmlNewChild(user, data->ns, "logon_divs", + iota(pdb_get_logon_divs(u))); + + if (pdb_get_hours_len(u)) + xmlNewChild(user, data->ns, "hours_len", + iota(pdb_get_hours_len(u))); + + xmlNewChild(user, data->ns, "unknown_5", iota(pdb_get_unknown5(u))); + xmlNewChild(user, data->ns, "unknown_6", iota(pdb_get_unknown6(u))); + xmlSaveFile(data->location, data->doc); + + return True; +} + +NTSTATUS +pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, + const char *location) +{ + NTSTATUS nt_status; + pdb_xml *data; + + xmlsam_debug_level = debug_add_class("xmlsam"); + if (xmlsam_debug_level == -1) { + xmlsam_debug_level = DBGC_ALL; + DEBUG(0, ("xmlsam: Couldn't register custom debugging class!\n")); + } + + if (!pdb_context) { + DEBUG(0, ("invalid pdb_methods specified\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + if (!NT_STATUS_IS_OK + (nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { + return nt_status; + } + + (*pdb_method)->name = "xmlsam"; + + (*pdb_method)->setsampwent = xmlsam_setsampwent; + (*pdb_method)->endsampwent = xmlsam_endsampwent; + (*pdb_method)->getsampwent = xmlsam_getsampwent; + (*pdb_method)->add_sam_account = xmlsam_add_sam_account; + (*pdb_method)->getsampwnam = NULL; + (*pdb_method)->getsampwsid = NULL; + (*pdb_method)->update_sam_account = NULL; + (*pdb_method)->delete_sam_account = NULL; + + data = talloc(pdb_context->mem_ctx, sizeof(pdb_xml)); + data->location = + (location ? talloc_strdup(pdb_context->mem_ctx, location) : "-"); + data->pwent = NULL; + data->written = 0; + (*pdb_method)->private_data = data; + + LIBXML_TEST_VERSION xmlKeepBlanksDefault(0); + + return NT_STATUS_OK; +} -- cgit From 21d26afb2af6ae34219a4286eb7a8896d7e04a3a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 14:15:33 +0000 Subject: sync 3_0 branch with HEAD (This used to be commit 19ab776bf9c91cf4e56887fd7a63d3253b7e36ef) --- examples/pdb/README | 4 ++++ examples/pdb/pdb_test.c | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/README b/examples/pdb/README index a212604792..561473129b 100644 --- a/examples/pdb/README +++ b/examples/pdb/README @@ -1,5 +1,9 @@ README for Samba Password Database (PDB) examples ==================================================== +8-8-2002 Jelmer Vernooij + +Added mysql and xml modules. See README in xml/ and mysql/ for details. + 21-6-2002 Stefan (metze) Metzmacher I have added an interface versioning. diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index d2722d2e03..b46fe24bd6 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -71,7 +71,7 @@ static BOOL testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, Search by sid **************************************************************************/ -static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, DOM_SID sid) +static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, const DOM_SID *sid) { DEBUG(10, ("testsam_getsampwsid called\n")); return False; @@ -81,7 +81,7 @@ static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_delete_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT *sam_pass) +static BOOL testsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT *sam_pass) { DEBUG(10, ("testsam_delete_sam_account called\n")); return False; @@ -91,7 +91,7 @@ static BOOL testsam_delete_sam_account(struct pdb_methods *methods, const SAM_AC Modifies an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_update_sam_account (struct pdb_methods *methods, const SAM_ACCOUNT *newpwd) +static BOOL testsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) { DEBUG(10, ("testsam_update_sam_account called\n")); return False; @@ -101,7 +101,7 @@ static BOOL testsam_update_sam_account (struct pdb_methods *methods, const SAM_A Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_add_sam_account (struct pdb_methods *methods, const SAM_ACCOUNT *newpwd) +static BOOL testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) { DEBUG(10, ("testsam_add_sam_account called\n")); return False; -- cgit From 3312086d7a2b1e2adb75c323e882f1cd4ea52e2e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 16:25:39 +0000 Subject: Better coding style Move out last Makefile.pdb dependencies (This used to be commit 2dc8b48632b0f14834db79f851a06469d2c0c00b) --- examples/pdb/xml/Makefile.in | 2 -- examples/pdb/xml/pdb_xml.c | 24 ++++++++---------------- 2 files changed, 8 insertions(+), 18 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/xml/Makefile.in b/examples/pdb/xml/Makefile.in index 87d4546972..252641da6d 100644 --- a/examples/pdb/xml/Makefile.in +++ b/examples/pdb/xml/Makefile.in @@ -2,8 +2,6 @@ PDB_OBJS = pdb_xml.so PDB_CFLAGS = `xml2-config --cflags` PDB_LDFLAGS = `xml2-config --libs` -include $(MAKEFILE) - CC = @CC@ LIBTOOL = libtool CFLAGS = @CFLAGS@ $(PDB_CFLAGS) diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c index f237a7da9d..17261873cd 100644 --- a/examples/pdb/xml/pdb_xml.c +++ b/examples/pdb/xml/pdb_xml.c @@ -42,8 +42,7 @@ static char * iota(int a) { return tmp; } -BOOL -parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) +BOOL parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) { pstring temp; @@ -72,8 +71,7 @@ parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) return True; } -BOOL -parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) +BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) { char *tmp; DOM_SID sid; @@ -242,8 +240,7 @@ typedef struct pdb_xml { xmlNsPtr ns; } pdb_xml; -xmlNodePtr -parseSambaXMLFile(struct pdb_xml *data) +xmlNodePtr parseSambaXMLFile(struct pdb_xml *data) { xmlNodePtr cur; @@ -290,8 +287,7 @@ parseSambaXMLFile(struct pdb_xml *data) return cur; } -static BOOL -xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static BOOL xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) { pdb_xml *data; @@ -314,8 +310,7 @@ xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) End enumeration of the passwd list. ****************************************************************/ -static void -xmlsam_endsampwent(struct pdb_methods *methods) +static void xmlsam_endsampwent(struct pdb_methods *methods) { pdb_xml *data; @@ -340,8 +335,7 @@ xmlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL -xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static BOOL xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { pdb_xml *data; @@ -373,8 +367,7 @@ xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL -xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) +static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) { pstring temp; fstring sid_str; @@ -514,8 +507,7 @@ xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) return True; } -NTSTATUS -pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, +NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, const char *location) { NTSTATUS nt_status; -- cgit From 36e9005cc2fb37b6c005ab537209618a3a26191b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 16:27:27 +0000 Subject: Better coding style (This used to be commit 09cb706dd1347ff29893ef33214332990be86b43) --- examples/pdb/mysql/Makefile.in | 2 -- examples/pdb/mysql/pdb_mysql.c | 57 ++++++++++++++---------------------------- 2 files changed, 19 insertions(+), 40 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/Makefile.in b/examples/pdb/mysql/Makefile.in index 1da6ea789e..3ebecad762 100644 --- a/examples/pdb/mysql/Makefile.in +++ b/examples/pdb/mysql/Makefile.in @@ -2,8 +2,6 @@ PDB_OBJS = pdb_mysql.so PDB_LDFLAGS = -lmysqlclient MAKEFILE = Makefile.pdb -include $(MAKEFILE) - CC = @CC@ LIBTOOL = libtool CFLAGS = @CFLAGS@ $(PDB_CFLAGS) diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c index c7e9e781c3..0cc1de6aaf 100644 --- a/examples/pdb/mysql/pdb_mysql.c +++ b/examples/pdb/mysql/pdb_mysql.c @@ -80,7 +80,6 @@ typedef struct pdb_mysql_query { char *part1; char *part2; } pdb_mysql_query; - #define SET_DATA(data,methods) { \ if(!methods){ \ DEBUG(0, ("invalid methods!\n")); \ @@ -92,8 +91,8 @@ typedef struct pdb_mysql_query { return False; \ } \ } -void -pdb_mysql_int_field(struct pdb_methods *m, + +void pdb_mysql_int_field(struct pdb_methods *m, struct pdb_mysql_query *q, char *name, int value) { if (!name || strchr(name, '\'')) @@ -111,8 +110,7 @@ pdb_mysql_int_field(struct pdb_methods *m, } } -static BOOL -pdb_mysql_string_field(struct pdb_methods *methods, +static BOOL pdb_mysql_string_field(struct pdb_methods *methods, struct pdb_mysql_query *q, char *name, const char *value) { @@ -145,8 +143,7 @@ pdb_mysql_string_field(struct pdb_methods *methods, return True; } -static char * -config_value(pdb_mysql_data * data, char *name, char *default_value) +static char * config_value(pdb_mysql_data * data, char *name, char *default_value) { if (lp_parm_string(NULL, data->location, name)) return lp_parm_string(NULL, data->location, name); @@ -154,9 +151,7 @@ config_value(pdb_mysql_data * data, char *name, char *default_value) return default_value; } -static char * -config_value_write(pdb_mysql_data * data, char *name, char *default_value) -{ +static char * config_value_write(pdb_mysql_data * data, char *name, char *default_value) { char *v = config_value(data, name, NULL); char *write; @@ -179,8 +174,7 @@ config_value_write(pdb_mysql_data * data, char *name, char *default_value) return write; } -static const char * -config_value_read(pdb_mysql_data * data, char *name, char *default_value) +static const char * config_value_read(pdb_mysql_data * data, char *name, char *default_value) { char *v = config_value(data, name, NULL); char *write; @@ -206,8 +200,7 @@ config_value_read(pdb_mysql_data * data, char *name, char *default_value) } /* Wrapper for atol that returns 0 if 'a' points to NULL */ -static long -xatol(char *a) +static long xatol(char *a) { long ret = 0; @@ -217,8 +210,7 @@ xatol(char *a) return ret; } -static BOOL -row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) +static BOOL row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) { MYSQL_ROW row; pstring temp; @@ -280,8 +272,7 @@ row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) return True; } -static BOOL -mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) { struct pdb_mysql_data *data = (struct pdb_mysql_data *) methods->private_data; @@ -386,8 +377,7 @@ mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) End enumeration of the passwd list. ****************************************************************/ -static void -mysqlsam_endsampwent(struct pdb_methods *methods) +static void mysqlsam_endsampwent(struct pdb_methods *methods) { struct pdb_mysql_data *data = (struct pdb_mysql_data *) methods->private_data; @@ -409,8 +399,7 @@ mysqlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL -mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static BOOL mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { struct pdb_mysql_data *data; @@ -424,8 +413,7 @@ mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) return row_to_sam_account(data->pwent, user); } -BOOL -mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, +BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, const char *field, const char *sname) { char *esc_sname; @@ -551,8 +539,7 @@ mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, Lookup a name in the SAM database ******************************************************************/ -static BOOL -mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, +static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, const char *sname) { struct pdb_mysql_data *data; @@ -573,8 +560,7 @@ mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, Search by sid **************************************************************************/ -static BOOL -mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, +static BOOL mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, const DOM_SID * sid) { BOOL ret = False; @@ -597,8 +583,7 @@ mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL -mysqlsam_delete_sam_account(struct pdb_methods *methods, +static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * sam_pass) { const char *sname = pdb_get_username(sam_pass); @@ -656,8 +641,7 @@ mysqlsam_delete_sam_account(struct pdb_methods *methods, return True; } -static BOOL -mysqlsam_replace_sam_account(struct pdb_methods *methods, +static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT * newpwd, char isupdate) { pstring temp; @@ -889,21 +873,18 @@ mysqlsam_replace_sam_account(struct pdb_methods *methods, return True; } -static BOOL -mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) +static BOOL mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 0); } -static BOOL -mysqlsam_update_sam_account(struct pdb_methods *methods, +static BOOL mysqlsam_update_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 1); } -NTSTATUS -pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, +NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, char *location) { NTSTATUS nt_status; -- cgit From ec0b8aa70454cab4a918ab09e8ed52d60b4b3256 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:05:17 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 803715d96016767c55202362b17096fc80786c59) --- examples/pdb/mysql/Makefile.in | 2 -- examples/pdb/mysql/pdb_mysql.c | 57 ++++++++++++++---------------------------- examples/pdb/xml/Makefile.in | 2 -- examples/pdb/xml/pdb_xml.c | 24 ++++++------------ 4 files changed, 27 insertions(+), 58 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/Makefile.in b/examples/pdb/mysql/Makefile.in index 1da6ea789e..3ebecad762 100644 --- a/examples/pdb/mysql/Makefile.in +++ b/examples/pdb/mysql/Makefile.in @@ -2,8 +2,6 @@ PDB_OBJS = pdb_mysql.so PDB_LDFLAGS = -lmysqlclient MAKEFILE = Makefile.pdb -include $(MAKEFILE) - CC = @CC@ LIBTOOL = libtool CFLAGS = @CFLAGS@ $(PDB_CFLAGS) diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c index c7e9e781c3..0cc1de6aaf 100644 --- a/examples/pdb/mysql/pdb_mysql.c +++ b/examples/pdb/mysql/pdb_mysql.c @@ -80,7 +80,6 @@ typedef struct pdb_mysql_query { char *part1; char *part2; } pdb_mysql_query; - #define SET_DATA(data,methods) { \ if(!methods){ \ DEBUG(0, ("invalid methods!\n")); \ @@ -92,8 +91,8 @@ typedef struct pdb_mysql_query { return False; \ } \ } -void -pdb_mysql_int_field(struct pdb_methods *m, + +void pdb_mysql_int_field(struct pdb_methods *m, struct pdb_mysql_query *q, char *name, int value) { if (!name || strchr(name, '\'')) @@ -111,8 +110,7 @@ pdb_mysql_int_field(struct pdb_methods *m, } } -static BOOL -pdb_mysql_string_field(struct pdb_methods *methods, +static BOOL pdb_mysql_string_field(struct pdb_methods *methods, struct pdb_mysql_query *q, char *name, const char *value) { @@ -145,8 +143,7 @@ pdb_mysql_string_field(struct pdb_methods *methods, return True; } -static char * -config_value(pdb_mysql_data * data, char *name, char *default_value) +static char * config_value(pdb_mysql_data * data, char *name, char *default_value) { if (lp_parm_string(NULL, data->location, name)) return lp_parm_string(NULL, data->location, name); @@ -154,9 +151,7 @@ config_value(pdb_mysql_data * data, char *name, char *default_value) return default_value; } -static char * -config_value_write(pdb_mysql_data * data, char *name, char *default_value) -{ +static char * config_value_write(pdb_mysql_data * data, char *name, char *default_value) { char *v = config_value(data, name, NULL); char *write; @@ -179,8 +174,7 @@ config_value_write(pdb_mysql_data * data, char *name, char *default_value) return write; } -static const char * -config_value_read(pdb_mysql_data * data, char *name, char *default_value) +static const char * config_value_read(pdb_mysql_data * data, char *name, char *default_value) { char *v = config_value(data, name, NULL); char *write; @@ -206,8 +200,7 @@ config_value_read(pdb_mysql_data * data, char *name, char *default_value) } /* Wrapper for atol that returns 0 if 'a' points to NULL */ -static long -xatol(char *a) +static long xatol(char *a) { long ret = 0; @@ -217,8 +210,7 @@ xatol(char *a) return ret; } -static BOOL -row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) +static BOOL row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) { MYSQL_ROW row; pstring temp; @@ -280,8 +272,7 @@ row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) return True; } -static BOOL -mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) { struct pdb_mysql_data *data = (struct pdb_mysql_data *) methods->private_data; @@ -386,8 +377,7 @@ mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) End enumeration of the passwd list. ****************************************************************/ -static void -mysqlsam_endsampwent(struct pdb_methods *methods) +static void mysqlsam_endsampwent(struct pdb_methods *methods) { struct pdb_mysql_data *data = (struct pdb_mysql_data *) methods->private_data; @@ -409,8 +399,7 @@ mysqlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL -mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static BOOL mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { struct pdb_mysql_data *data; @@ -424,8 +413,7 @@ mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) return row_to_sam_account(data->pwent, user); } -BOOL -mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, +BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, const char *field, const char *sname) { char *esc_sname; @@ -551,8 +539,7 @@ mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, Lookup a name in the SAM database ******************************************************************/ -static BOOL -mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, +static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, const char *sname) { struct pdb_mysql_data *data; @@ -573,8 +560,7 @@ mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, Search by sid **************************************************************************/ -static BOOL -mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, +static BOOL mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, const DOM_SID * sid) { BOOL ret = False; @@ -597,8 +583,7 @@ mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL -mysqlsam_delete_sam_account(struct pdb_methods *methods, +static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * sam_pass) { const char *sname = pdb_get_username(sam_pass); @@ -656,8 +641,7 @@ mysqlsam_delete_sam_account(struct pdb_methods *methods, return True; } -static BOOL -mysqlsam_replace_sam_account(struct pdb_methods *methods, +static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT * newpwd, char isupdate) { pstring temp; @@ -889,21 +873,18 @@ mysqlsam_replace_sam_account(struct pdb_methods *methods, return True; } -static BOOL -mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) +static BOOL mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 0); } -static BOOL -mysqlsam_update_sam_account(struct pdb_methods *methods, +static BOOL mysqlsam_update_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 1); } -NTSTATUS -pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, +NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, char *location) { NTSTATUS nt_status; diff --git a/examples/pdb/xml/Makefile.in b/examples/pdb/xml/Makefile.in index 87d4546972..252641da6d 100644 --- a/examples/pdb/xml/Makefile.in +++ b/examples/pdb/xml/Makefile.in @@ -2,8 +2,6 @@ PDB_OBJS = pdb_xml.so PDB_CFLAGS = `xml2-config --cflags` PDB_LDFLAGS = `xml2-config --libs` -include $(MAKEFILE) - CC = @CC@ LIBTOOL = libtool CFLAGS = @CFLAGS@ $(PDB_CFLAGS) diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c index f237a7da9d..17261873cd 100644 --- a/examples/pdb/xml/pdb_xml.c +++ b/examples/pdb/xml/pdb_xml.c @@ -42,8 +42,7 @@ static char * iota(int a) { return tmp; } -BOOL -parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) +BOOL parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) { pstring temp; @@ -72,8 +71,7 @@ parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) return True; } -BOOL -parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) +BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) { char *tmp; DOM_SID sid; @@ -242,8 +240,7 @@ typedef struct pdb_xml { xmlNsPtr ns; } pdb_xml; -xmlNodePtr -parseSambaXMLFile(struct pdb_xml *data) +xmlNodePtr parseSambaXMLFile(struct pdb_xml *data) { xmlNodePtr cur; @@ -290,8 +287,7 @@ parseSambaXMLFile(struct pdb_xml *data) return cur; } -static BOOL -xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static BOOL xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) { pdb_xml *data; @@ -314,8 +310,7 @@ xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) End enumeration of the passwd list. ****************************************************************/ -static void -xmlsam_endsampwent(struct pdb_methods *methods) +static void xmlsam_endsampwent(struct pdb_methods *methods) { pdb_xml *data; @@ -340,8 +335,7 @@ xmlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL -xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static BOOL xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { pdb_xml *data; @@ -373,8 +367,7 @@ xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL -xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) +static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) { pstring temp; fstring sid_str; @@ -514,8 +507,7 @@ xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) return True; } -NTSTATUS -pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, +NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, const char *location) { NTSTATUS nt_status; -- cgit From 2ef81d751768ed1d17dfa5726af1ab8093af7810 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 26 Sep 2002 14:29:09 +0000 Subject: Make functions return NTSTATUS instead of BOOL (This used to be commit 6347d40eff03ad780446bdae0f1dfe0bc9edf824) --- examples/pdb/pdb_test.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index b46fe24bd6..c5ba094e42 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -32,10 +32,10 @@ PDB_MODULE_VERSIONING_MAGIC Start enumeration of the passwd list. ****************************************************************/ -static BOOL testsam_setsampwent(struct pdb_methods *methods, BOOL update) +static NTSTATUS testsam_setsampwent(struct pdb_methods *methods, BOOL update) { DEBUG(10, ("testsam_setsampwent called\n")); - return True; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************** @@ -51,60 +51,60 @@ static void testsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) +static NTSTATUS testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) { DEBUG(10, ("testsam_getsampwent called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /****************************************************************** Lookup a name in the SAM database ******************************************************************/ -static BOOL testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) +static NTSTATUS testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) { DEBUG(10, ("testsam_getsampwnam called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** Search by sid **************************************************************************/ -static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, const DOM_SID *sid) +static NTSTATUS testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, const DOM_SID *sid) { DEBUG(10, ("testsam_getsampwsid called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT *sam_pass) +static NTSTATUS testsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT *sam_pass) { DEBUG(10, ("testsam_delete_sam_account called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** Modifies an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +static NTSTATUS testsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) { DEBUG(10, ("testsam_update_sam_account called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +static NTSTATUS testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) { DEBUG(10, ("testsam_add_sam_account called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) -- cgit From f90e9ae2443fe3c1e72a8a8e751937a324c6dc87 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 26 Sep 2002 14:52:54 +0000 Subject: Change pdb_mysql function to return NTSTATUS (This used to be commit fa056769a08c93f086f05baf9095ee93217f92f1) --- examples/pdb/mysql/pdb_mysql.c | 141 ++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 65 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c index 0cc1de6aaf..c73d3716fe 100644 --- a/examples/pdb/mysql/pdb_mysql.c +++ b/examples/pdb/mysql/pdb_mysql.c @@ -83,16 +83,16 @@ typedef struct pdb_mysql_query { #define SET_DATA(data,methods) { \ if(!methods){ \ DEBUG(0, ("invalid methods!\n")); \ - return False; \ + return NT_STATUS_INVALID_PARAMETER; \ } \ data = (struct pdb_mysql_data *)methods->private_data; \ if(!data || !(data->handle)){ \ DEBUG(0, ("invalid handle!\n")); \ - return False; \ + return NT_STATUS_INVALID_HANDLE; \ } \ } -void pdb_mysql_int_field(struct pdb_methods *m, +static void pdb_mysql_int_field(struct pdb_methods *m, struct pdb_mysql_query *q, char *name, int value) { if (!name || strchr(name, '\'')) @@ -110,21 +110,25 @@ void pdb_mysql_int_field(struct pdb_methods *m, } } -static BOOL pdb_mysql_string_field(struct pdb_methods *methods, +static NTSTATUS pdb_mysql_string_field(struct pdb_methods *methods, struct pdb_mysql_query *q, char *name, const char *value) { char *esc_value; struct pdb_mysql_data *data; + char *tmp_value; SET_DATA(data, methods); if (!name || !value || !strcmp(value, "") || strchr(name, '\'')) - return False; /* This field shouldn't be set by module */ + return NT_STATUS_INVALID_PARAMETER; /* This field shouldn't be set by module */ esc_value = malloc(strlen(value) * 2 + 1); - mysql_real_escape_string(data->handle, esc_value, (char *) value, - strlen(value)); + + tmp_value = smb_xstrdup(value); + mysql_real_escape_string(data->handle, esc_value, tmp_value, + strlen(tmp_value)); + SAFE_FREE(tmp_value); if (q->update) { q->part1 = @@ -140,7 +144,7 @@ static BOOL pdb_mysql_string_field(struct pdb_methods *methods, SAFE_FREE(esc_value); - return True; + return NT_STATUS_OK; } static char * config_value(pdb_mysql_data * data, char *name, char *default_value) @@ -153,46 +157,46 @@ static char * config_value(pdb_mysql_data * data, char *name, char *default_valu static char * config_value_write(pdb_mysql_data * data, char *name, char *default_value) { char *v = config_value(data, name, NULL); - char *write; + char *swrite; if (!v) return default_value; - write = strchr(v, ':'); + swrite = strchr(v, ':'); /* Default to the same field as read field */ - if (!write) + if (!swrite) return v; - write++; + swrite++; /* If the field is 0 chars long, we shouldn't write to it */ - if (!strlen(write) || !strcmp(write, "NULL")) + if (!strlen(swrite) || !strcmp(swrite, "NULL")) return NULL; /* Otherwise, use the additionally specified */ - return write; + return swrite; } static const char * config_value_read(pdb_mysql_data * data, char *name, char *default_value) { char *v = config_value(data, name, NULL); - char *write; + char *swrite; if (!v) return default_value; - write = strchr(v, ':'); + swrite = strchr(v, ':'); /* If no write is specified, there are no problems */ - if (!write) { + if (!swrite) { if (strlen(v) == 0) return "NULL"; return v; } /* Otherwise, we have to cut the ':write_part' */ - *write = '\0'; + *swrite = '\0'; if (strlen(v) == 0) return "NULL"; @@ -210,18 +214,17 @@ static long xatol(char *a) return ret; } -static BOOL row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) +static NTSTATUS row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) { MYSQL_ROW row; pstring temp; unsigned int num_fields; - unsigned long *lengths; DOM_SID sid; num_fields = mysql_num_fields(r); row = mysql_fetch_row(r); if (!row) - return False; + return NT_STATUS_INVALID_PARAMETER; pdb_set_logon_time(u, xatol(row[0]), FALSE); pdb_set_logoff_time(u, xatol(row[1]), FALSE); @@ -269,10 +272,10 @@ static BOOL row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) pdb_set_unknown_5(u, xatol(row[29])); pdb_set_unknown_6(u, xatol(row[30])); - return True; + return NT_STATUS_OK; } -static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static NTSTATUS mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) { struct pdb_mysql_data *data = (struct pdb_mysql_data *) methods->private_data; @@ -281,7 +284,7 @@ static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) if (!data || !(data->handle)) { DEBUG(0, ("invalid handle!\n")); - return False; + return NT_STATUS_INVALID_HANDLE; } asprintf(&query, @@ -355,7 +358,7 @@ static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) if (ret) { DEBUG(0, ("Error executing query: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } data->pwent = mysql_store_result(data->handle); @@ -363,14 +366,14 @@ static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) if (data->pwent == NULL) { DEBUG(0, ("Error storing results: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } DEBUG(5, ("mysqlsam_setsampwent succeeded(%d results)!\n", mysql_num_fields(data->pwent))); - return True; + return NT_STATUS_OK; } /*************************************************************** @@ -399,7 +402,7 @@ static void mysqlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static NTSTATUS mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { struct pdb_mysql_data *data; @@ -407,41 +410,46 @@ static BOOL mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user if (data->pwent == NULL) { DEBUG(0, ("invalid pwent\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } return row_to_sam_account(data->pwent, user); } -BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, +static NTSTATUS mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, const char *field, const char *sname) { char *esc_sname; char *query; - int ret; + NTSTATUS ret; MYSQL_RES *res; + int mysql_ret; struct pdb_mysql_data *data; + char *tmp_sname; SET_DATA(data, methods); esc_sname = malloc(strlen(sname) * 2 + 1); if (!esc_sname) { - DEBUG(0, ("Not enough memory available!\n")); - return False; + return NT_STATUS_NO_MEMORY; } DEBUG(5, ("mysqlsam_select_by_field: getting data where %s = %s(nonescaped)\n", field, sname)); + tmp_sname = smb_xstrdup(sname); + /* Escape sname */ - mysql_real_escape_string(data->handle, esc_sname, (char *) sname, - strlen(sname)); + mysql_real_escape_string(data->handle, esc_sname, tmp_sname, + strlen(tmp_sname)); + + SAFE_FREE(tmp_sname); if (user == NULL) { DEBUG(0, ("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); SAFE_FREE(esc_sname); - return False; + return NT_STATUS_INVALID_PARAMETER; } asprintf(&query, @@ -511,22 +519,22 @@ BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, SAFE_FREE(esc_sname); - ret = mysql_query(data->handle, query); + mysql_ret = mysql_query(data->handle, query); SAFE_FREE(query); - if (ret) { + if (mysql_ret) { DEBUG(0, ("Error while executing MySQL query: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } res = mysql_store_result(data->handle); if (res == NULL) { DEBUG(0, ("Error storing results: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } ret = row_to_sam_account(res, user); @@ -539,7 +547,7 @@ BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, Lookup a name in the SAM database ******************************************************************/ -static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, +static NTSTATUS mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, const char *sname) { struct pdb_mysql_data *data; @@ -548,8 +556,9 @@ static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user if (!sname) { DEBUG(0, ("invalid name specified")); - return False; + return NT_STATUS_INVALID_PARAMETER; } + return mysqlsam_select_by_field(methods, user, config_value_read(data, "username column", CONFIG_USERNAME_DEFAULT), sname); @@ -560,10 +569,9 @@ static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user Search by sid **************************************************************************/ -static BOOL mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, +static NTSTATUS mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, const DOM_SID * sid) { - BOOL ret = False; struct pdb_mysql_data *data; fstring sid_str; @@ -571,19 +579,16 @@ static BOOL mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user sid_to_string(sid_str, sid); - ret = - mysqlsam_select_by_field(methods, user, + return mysqlsam_select_by_field(methods, user, config_value_read(data, "user sid column", CONFIG_USER_SID_DEFAULT), sid_str); - - return ret; } /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, +static NTSTATUS mysqlsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * sam_pass) { const char *sname = pdb_get_username(sam_pass); @@ -591,33 +596,39 @@ static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, char *query; int ret; struct pdb_mysql_data *data; + char *tmp_sname; SET_DATA(data, methods); if (!methods) { DEBUG(0, ("invalid methods!\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (struct pdb_mysql_data *) methods->private_data; if (!data || !(data->handle)) { DEBUG(0, ("invalid handle!\n")); - return False; + return NT_STATUS_INVALID_HANDLE; } if (!sname) { DEBUG(0, ("invalid name specified\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } /* Escape sname */ esc = malloc(strlen(sname) * 2 + 1); if (!esc) { DEBUG(0, ("Can't allocate memory to store escaped name\n")); - return False; + return NT_STATUS_NO_MEMORY; } - mysql_real_escape_string(data->handle, esc, (char *) sname, - strlen(sname)); + + tmp_sname = smb_xstrdup(sname); + + mysql_real_escape_string(data->handle, esc, tmp_sname, + strlen(tmp_sname)); + + SAFE_FREE(tmp_sname); asprintf(&query, "DELETE FROM %s WHERE %s = '%s'", config_value(data, "table", CONFIG_TABLE_DEFAULT), @@ -634,14 +645,14 @@ static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, DEBUG(0, ("Error while executing query: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } DEBUG(5, ("User '%s' deleted\n", sname)); - return True; + return NT_STATUS_OK; } -static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, +static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT * newpwd, char isupdate) { pstring temp; @@ -652,13 +663,13 @@ static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, if (!methods) { DEBUG(0, ("invalid methods!\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (struct pdb_mysql_data *) methods->private_data; if (data == NULL || data->handle == NULL) { DEBUG(0, ("invalid handle!\n")); - return False; + return NT_STATUS_INVALID_HANDLE; } query.update = isupdate; @@ -867,18 +878,18 @@ static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, DEBUG(0, ("Error executing %s, %s\n", query.part1, mysql_error(data->handle))); - return False; + return NT_STATUS_INVALID_PARAMETER; } talloc_destroy(query.mem_ctx); - return True; + return NT_STATUS_OK; } -static BOOL mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) +static NTSTATUS mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 0); } -static BOOL mysqlsam_update_sam_account(struct pdb_methods *methods, +static NTSTATUS mysqlsam_update_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 1); @@ -931,7 +942,7 @@ NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, data->location = smb_xstrdup(location); DEBUG(1, - ("Connecting to database server, host: %s, user: %s, password: %s, database: %s, port: %d\n", + ("Connecting to database server, host: %s, user: %s, password: %s, database: %s, port: %ld\n", config_value(data, "mysql host", CONFIG_HOST_DEFAULT), config_value(data, "mysql user", CONFIG_USER_DEFAULT), config_value(data, "mysql password", CONFIG_PASS_DEFAULT), -- cgit From 791d9e8facb221d0532922a39f83ca06f84e99f2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 26 Sep 2002 15:03:26 +0000 Subject: Change pdb_xml functions to return NTSTATUS (This used to be commit 834fcd23959ed202a84069bf19390103f563540c) --- examples/pdb/xml/pdb_xml.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c index 17261873cd..5de27bc6e2 100644 --- a/examples/pdb/xml/pdb_xml.c +++ b/examples/pdb/xml/pdb_xml.c @@ -287,23 +287,24 @@ xmlNodePtr parseSambaXMLFile(struct pdb_xml *data) return cur; } -static BOOL xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static NTSTATUS xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) { pdb_xml *data; if (!methods) { DEBUG(0, ("Invalid methods\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (pdb_xml *) methods->private_data; if (!data) { DEBUG(0, ("Invalid pdb_xml_data\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data->pwent = parseSambaXMLFile(data); if (!data->pwent) - return False; - return True; + return NT_STATUS_UNSUCCESSFUL; + + return NT_STATUS_OK; } /*************************************************************** @@ -335,19 +336,19 @@ static void xmlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static NTSTATUS xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { pdb_xml *data; if (!methods) { DEBUG(0, ("Invalid methods\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (pdb_xml *) methods->private_data; if (!data) { DEBUG(0, ("Invalid pdb_xml_data\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } while (data->pwent) { @@ -356,18 +357,18 @@ static BOOL xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) parseUser(data->doc, data->ns, data->pwent, user); data->pwent = data->pwent->next; - return True; + return NT_STATUS_OK; } data->pwent = data->pwent->next; } - return False; + return NT_STATUS_UNSUCCESSFUL; } /*************************************************************************** Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) +static NTSTATUS xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) { pstring temp; fstring sid_str; @@ -379,13 +380,13 @@ static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) if (!methods) { DEBUG(0, ("Invalid methods\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (pdb_xml *) methods->private_data; if (!data) { DEBUG(0, ("Invalid pdb_xml_data\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } /* Create a new document if we can't open the current one */ @@ -504,7 +505,7 @@ static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) xmlNewChild(user, data->ns, "unknown_6", iota(pdb_get_unknown6(u))); xmlSaveFile(data->location, data->doc); - return True; + return NT_STATUS_OK; } NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, -- cgit From d9729d81a993234db850fa733fd4591e1a5ae56e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 26 Sep 2002 18:37:55 +0000 Subject: syncing up with HEAD again.... (This used to be commit e026b84815ad1a5fa981c24fff197fefa73b4928) --- examples/pdb/mysql/pdb_mysql.c | 141 ++++++++++++++++++++++------------------- examples/pdb/pdb_test.c | 28 ++++---- examples/pdb/xml/pdb_xml.c | 29 +++++---- 3 files changed, 105 insertions(+), 93 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c index 0cc1de6aaf..c73d3716fe 100644 --- a/examples/pdb/mysql/pdb_mysql.c +++ b/examples/pdb/mysql/pdb_mysql.c @@ -83,16 +83,16 @@ typedef struct pdb_mysql_query { #define SET_DATA(data,methods) { \ if(!methods){ \ DEBUG(0, ("invalid methods!\n")); \ - return False; \ + return NT_STATUS_INVALID_PARAMETER; \ } \ data = (struct pdb_mysql_data *)methods->private_data; \ if(!data || !(data->handle)){ \ DEBUG(0, ("invalid handle!\n")); \ - return False; \ + return NT_STATUS_INVALID_HANDLE; \ } \ } -void pdb_mysql_int_field(struct pdb_methods *m, +static void pdb_mysql_int_field(struct pdb_methods *m, struct pdb_mysql_query *q, char *name, int value) { if (!name || strchr(name, '\'')) @@ -110,21 +110,25 @@ void pdb_mysql_int_field(struct pdb_methods *m, } } -static BOOL pdb_mysql_string_field(struct pdb_methods *methods, +static NTSTATUS pdb_mysql_string_field(struct pdb_methods *methods, struct pdb_mysql_query *q, char *name, const char *value) { char *esc_value; struct pdb_mysql_data *data; + char *tmp_value; SET_DATA(data, methods); if (!name || !value || !strcmp(value, "") || strchr(name, '\'')) - return False; /* This field shouldn't be set by module */ + return NT_STATUS_INVALID_PARAMETER; /* This field shouldn't be set by module */ esc_value = malloc(strlen(value) * 2 + 1); - mysql_real_escape_string(data->handle, esc_value, (char *) value, - strlen(value)); + + tmp_value = smb_xstrdup(value); + mysql_real_escape_string(data->handle, esc_value, tmp_value, + strlen(tmp_value)); + SAFE_FREE(tmp_value); if (q->update) { q->part1 = @@ -140,7 +144,7 @@ static BOOL pdb_mysql_string_field(struct pdb_methods *methods, SAFE_FREE(esc_value); - return True; + return NT_STATUS_OK; } static char * config_value(pdb_mysql_data * data, char *name, char *default_value) @@ -153,46 +157,46 @@ static char * config_value(pdb_mysql_data * data, char *name, char *default_valu static char * config_value_write(pdb_mysql_data * data, char *name, char *default_value) { char *v = config_value(data, name, NULL); - char *write; + char *swrite; if (!v) return default_value; - write = strchr(v, ':'); + swrite = strchr(v, ':'); /* Default to the same field as read field */ - if (!write) + if (!swrite) return v; - write++; + swrite++; /* If the field is 0 chars long, we shouldn't write to it */ - if (!strlen(write) || !strcmp(write, "NULL")) + if (!strlen(swrite) || !strcmp(swrite, "NULL")) return NULL; /* Otherwise, use the additionally specified */ - return write; + return swrite; } static const char * config_value_read(pdb_mysql_data * data, char *name, char *default_value) { char *v = config_value(data, name, NULL); - char *write; + char *swrite; if (!v) return default_value; - write = strchr(v, ':'); + swrite = strchr(v, ':'); /* If no write is specified, there are no problems */ - if (!write) { + if (!swrite) { if (strlen(v) == 0) return "NULL"; return v; } /* Otherwise, we have to cut the ':write_part' */ - *write = '\0'; + *swrite = '\0'; if (strlen(v) == 0) return "NULL"; @@ -210,18 +214,17 @@ static long xatol(char *a) return ret; } -static BOOL row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) +static NTSTATUS row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) { MYSQL_ROW row; pstring temp; unsigned int num_fields; - unsigned long *lengths; DOM_SID sid; num_fields = mysql_num_fields(r); row = mysql_fetch_row(r); if (!row) - return False; + return NT_STATUS_INVALID_PARAMETER; pdb_set_logon_time(u, xatol(row[0]), FALSE); pdb_set_logoff_time(u, xatol(row[1]), FALSE); @@ -269,10 +272,10 @@ static BOOL row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) pdb_set_unknown_5(u, xatol(row[29])); pdb_set_unknown_6(u, xatol(row[30])); - return True; + return NT_STATUS_OK; } -static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static NTSTATUS mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) { struct pdb_mysql_data *data = (struct pdb_mysql_data *) methods->private_data; @@ -281,7 +284,7 @@ static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) if (!data || !(data->handle)) { DEBUG(0, ("invalid handle!\n")); - return False; + return NT_STATUS_INVALID_HANDLE; } asprintf(&query, @@ -355,7 +358,7 @@ static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) if (ret) { DEBUG(0, ("Error executing query: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } data->pwent = mysql_store_result(data->handle); @@ -363,14 +366,14 @@ static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) if (data->pwent == NULL) { DEBUG(0, ("Error storing results: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } DEBUG(5, ("mysqlsam_setsampwent succeeded(%d results)!\n", mysql_num_fields(data->pwent))); - return True; + return NT_STATUS_OK; } /*************************************************************** @@ -399,7 +402,7 @@ static void mysqlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static NTSTATUS mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { struct pdb_mysql_data *data; @@ -407,41 +410,46 @@ static BOOL mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user if (data->pwent == NULL) { DEBUG(0, ("invalid pwent\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } return row_to_sam_account(data->pwent, user); } -BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, +static NTSTATUS mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, const char *field, const char *sname) { char *esc_sname; char *query; - int ret; + NTSTATUS ret; MYSQL_RES *res; + int mysql_ret; struct pdb_mysql_data *data; + char *tmp_sname; SET_DATA(data, methods); esc_sname = malloc(strlen(sname) * 2 + 1); if (!esc_sname) { - DEBUG(0, ("Not enough memory available!\n")); - return False; + return NT_STATUS_NO_MEMORY; } DEBUG(5, ("mysqlsam_select_by_field: getting data where %s = %s(nonescaped)\n", field, sname)); + tmp_sname = smb_xstrdup(sname); + /* Escape sname */ - mysql_real_escape_string(data->handle, esc_sname, (char *) sname, - strlen(sname)); + mysql_real_escape_string(data->handle, esc_sname, tmp_sname, + strlen(tmp_sname)); + + SAFE_FREE(tmp_sname); if (user == NULL) { DEBUG(0, ("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); SAFE_FREE(esc_sname); - return False; + return NT_STATUS_INVALID_PARAMETER; } asprintf(&query, @@ -511,22 +519,22 @@ BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, SAFE_FREE(esc_sname); - ret = mysql_query(data->handle, query); + mysql_ret = mysql_query(data->handle, query); SAFE_FREE(query); - if (ret) { + if (mysql_ret) { DEBUG(0, ("Error while executing MySQL query: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } res = mysql_store_result(data->handle); if (res == NULL) { DEBUG(0, ("Error storing results: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } ret = row_to_sam_account(res, user); @@ -539,7 +547,7 @@ BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, Lookup a name in the SAM database ******************************************************************/ -static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, +static NTSTATUS mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, const char *sname) { struct pdb_mysql_data *data; @@ -548,8 +556,9 @@ static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user if (!sname) { DEBUG(0, ("invalid name specified")); - return False; + return NT_STATUS_INVALID_PARAMETER; } + return mysqlsam_select_by_field(methods, user, config_value_read(data, "username column", CONFIG_USERNAME_DEFAULT), sname); @@ -560,10 +569,9 @@ static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user Search by sid **************************************************************************/ -static BOOL mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, +static NTSTATUS mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, const DOM_SID * sid) { - BOOL ret = False; struct pdb_mysql_data *data; fstring sid_str; @@ -571,19 +579,16 @@ static BOOL mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user sid_to_string(sid_str, sid); - ret = - mysqlsam_select_by_field(methods, user, + return mysqlsam_select_by_field(methods, user, config_value_read(data, "user sid column", CONFIG_USER_SID_DEFAULT), sid_str); - - return ret; } /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, +static NTSTATUS mysqlsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * sam_pass) { const char *sname = pdb_get_username(sam_pass); @@ -591,33 +596,39 @@ static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, char *query; int ret; struct pdb_mysql_data *data; + char *tmp_sname; SET_DATA(data, methods); if (!methods) { DEBUG(0, ("invalid methods!\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (struct pdb_mysql_data *) methods->private_data; if (!data || !(data->handle)) { DEBUG(0, ("invalid handle!\n")); - return False; + return NT_STATUS_INVALID_HANDLE; } if (!sname) { DEBUG(0, ("invalid name specified\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } /* Escape sname */ esc = malloc(strlen(sname) * 2 + 1); if (!esc) { DEBUG(0, ("Can't allocate memory to store escaped name\n")); - return False; + return NT_STATUS_NO_MEMORY; } - mysql_real_escape_string(data->handle, esc, (char *) sname, - strlen(sname)); + + tmp_sname = smb_xstrdup(sname); + + mysql_real_escape_string(data->handle, esc, tmp_sname, + strlen(tmp_sname)); + + SAFE_FREE(tmp_sname); asprintf(&query, "DELETE FROM %s WHERE %s = '%s'", config_value(data, "table", CONFIG_TABLE_DEFAULT), @@ -634,14 +645,14 @@ static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, DEBUG(0, ("Error while executing query: %s\n", mysql_error(data->handle))); - return False; + return NT_STATUS_UNSUCCESSFUL; } DEBUG(5, ("User '%s' deleted\n", sname)); - return True; + return NT_STATUS_OK; } -static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, +static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT * newpwd, char isupdate) { pstring temp; @@ -652,13 +663,13 @@ static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, if (!methods) { DEBUG(0, ("invalid methods!\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (struct pdb_mysql_data *) methods->private_data; if (data == NULL || data->handle == NULL) { DEBUG(0, ("invalid handle!\n")); - return False; + return NT_STATUS_INVALID_HANDLE; } query.update = isupdate; @@ -867,18 +878,18 @@ static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, DEBUG(0, ("Error executing %s, %s\n", query.part1, mysql_error(data->handle))); - return False; + return NT_STATUS_INVALID_PARAMETER; } talloc_destroy(query.mem_ctx); - return True; + return NT_STATUS_OK; } -static BOOL mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) +static NTSTATUS mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 0); } -static BOOL mysqlsam_update_sam_account(struct pdb_methods *methods, +static NTSTATUS mysqlsam_update_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 1); @@ -931,7 +942,7 @@ NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, data->location = smb_xstrdup(location); DEBUG(1, - ("Connecting to database server, host: %s, user: %s, password: %s, database: %s, port: %d\n", + ("Connecting to database server, host: %s, user: %s, password: %s, database: %s, port: %ld\n", config_value(data, "mysql host", CONFIG_HOST_DEFAULT), config_value(data, "mysql user", CONFIG_USER_DEFAULT), config_value(data, "mysql password", CONFIG_PASS_DEFAULT), diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index b46fe24bd6..c5ba094e42 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -32,10 +32,10 @@ PDB_MODULE_VERSIONING_MAGIC Start enumeration of the passwd list. ****************************************************************/ -static BOOL testsam_setsampwent(struct pdb_methods *methods, BOOL update) +static NTSTATUS testsam_setsampwent(struct pdb_methods *methods, BOOL update) { DEBUG(10, ("testsam_setsampwent called\n")); - return True; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************** @@ -51,60 +51,60 @@ static void testsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) +static NTSTATUS testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) { DEBUG(10, ("testsam_getsampwent called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /****************************************************************** Lookup a name in the SAM database ******************************************************************/ -static BOOL testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) +static NTSTATUS testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) { DEBUG(10, ("testsam_getsampwnam called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** Search by sid **************************************************************************/ -static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, const DOM_SID *sid) +static NTSTATUS testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, const DOM_SID *sid) { DEBUG(10, ("testsam_getsampwsid called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT *sam_pass) +static NTSTATUS testsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT *sam_pass) { DEBUG(10, ("testsam_delete_sam_account called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** Modifies an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +static NTSTATUS testsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) { DEBUG(10, ("testsam_update_sam_account called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +static NTSTATUS testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) { DEBUG(10, ("testsam_add_sam_account called\n")); - return False; + return NT_STATUS_NOT_IMPLEMENTED; } NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c index 17261873cd..5de27bc6e2 100644 --- a/examples/pdb/xml/pdb_xml.c +++ b/examples/pdb/xml/pdb_xml.c @@ -287,23 +287,24 @@ xmlNodePtr parseSambaXMLFile(struct pdb_xml *data) return cur; } -static BOOL xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static NTSTATUS xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) { pdb_xml *data; if (!methods) { DEBUG(0, ("Invalid methods\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (pdb_xml *) methods->private_data; if (!data) { DEBUG(0, ("Invalid pdb_xml_data\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data->pwent = parseSambaXMLFile(data); if (!data->pwent) - return False; - return True; + return NT_STATUS_UNSUCCESSFUL; + + return NT_STATUS_OK; } /*************************************************************** @@ -335,19 +336,19 @@ static void xmlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static NTSTATUS xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { pdb_xml *data; if (!methods) { DEBUG(0, ("Invalid methods\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (pdb_xml *) methods->private_data; if (!data) { DEBUG(0, ("Invalid pdb_xml_data\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } while (data->pwent) { @@ -356,18 +357,18 @@ static BOOL xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) parseUser(data->doc, data->ns, data->pwent, user); data->pwent = data->pwent->next; - return True; + return NT_STATUS_OK; } data->pwent = data->pwent->next; } - return False; + return NT_STATUS_UNSUCCESSFUL; } /*************************************************************************** Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) +static NTSTATUS xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) { pstring temp; fstring sid_str; @@ -379,13 +380,13 @@ static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) if (!methods) { DEBUG(0, ("Invalid methods\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } data = (pdb_xml *) methods->private_data; if (!data) { DEBUG(0, ("Invalid pdb_xml_data\n")); - return False; + return NT_STATUS_INVALID_PARAMETER; } /* Create a new document if we can't open the current one */ @@ -504,7 +505,7 @@ static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) xmlNewChild(user, data->ns, "unknown_6", iota(pdb_get_unknown6(u))); xmlSaveFile(data->location, data->doc); - return True; + return NT_STATUS_OK; } NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, -- cgit From 366da1ee377e279d57e247667f02818aca935b30 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 4 Nov 2002 14:36:34 +0000 Subject: Adapt to metze's PDB_SET patch (This used to be commit 33c7a296b3bdfab276ed91ea77077eedbeed3757) --- examples/pdb/mysql/pdb_mysql.c | 60 +++++++++++++++++++++--------------------- examples/pdb/xml/pdb_xml.c | 56 +++++++++++++++++++-------------------- 2 files changed, 58 insertions(+), 58 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c index c73d3716fe..207c3d124e 100644 --- a/examples/pdb/mysql/pdb_mysql.c +++ b/examples/pdb/mysql/pdb_mysql.c @@ -229,48 +229,48 @@ static NTSTATUS row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) pdb_set_logon_time(u, xatol(row[0]), FALSE); pdb_set_logoff_time(u, xatol(row[1]), FALSE); pdb_set_kickoff_time(u, xatol(row[2]), FALSE); - pdb_set_pass_last_set_time(u, xatol(row[3])); + pdb_set_pass_last_set_time(u, xatol(row[3]), PDB_SET); pdb_set_pass_can_change_time(u, xatol(row[4]), FALSE); pdb_set_pass_must_change_time(u, xatol(row[5]), FALSE); - pdb_set_username(u, row[6]); - pdb_set_domain(u, row[7]); - pdb_set_nt_username(u, row[8]); - pdb_set_fullname(u, row[9]); + pdb_set_username(u, row[6], PDB_SET); + pdb_set_domain(u, row[7], PDB_SET); + pdb_set_nt_username(u, row[8], PDB_SET); + pdb_set_fullname(u, row[9], PDB_SET); pdb_set_homedir(u, row[10], True); pdb_set_dir_drive(u, row[11], True); pdb_set_logon_script(u, row[12], True); pdb_set_profile_path(u, row[13], True); - pdb_set_acct_desc(u, row[14]); - pdb_set_workstations(u, row[15]); - pdb_set_unknown_str(u, row[16]); - pdb_set_munged_dial(u, row[17]); + pdb_set_acct_desc(u, row[14], PDB_SET); + pdb_set_workstations(u, row[15], PDB_SET); + pdb_set_unknown_str(u, row[16], PDB_SET); + pdb_set_munged_dial(u, row[17], PDB_SET); if (row[18]) - pdb_set_uid(u, xatol(row[18])); + pdb_set_uid(u, xatol(row[18]), PDB_SET); if (row[19]) - pdb_set_gid(u, xatol(row[19])); + pdb_set_gid(u, xatol(row[19]), PDB_SET); string_to_sid(&sid, row[20]); - pdb_set_user_sid(u, &sid); + pdb_set_user_sid(u, &sid, PDB_SET); string_to_sid(&sid, row[21]); - pdb_set_group_sid(u, &sid); + pdb_set_group_sid(u, &sid, PDB_SET); - if (pdb_gethexpwd(row[22], temp)) - pdb_set_lanman_passwd(u, temp); - if (pdb_gethexpwd(row[23], temp)) - pdb_set_nt_passwd(u, temp); + if (pdb_gethexpwd(row[22], temp), PDB_SET) + pdb_set_lanman_passwd(u, temp, PDB_SET); + if (pdb_gethexpwd(row[23], temp), PDB_SET) + pdb_set_nt_passwd(u, temp, PDB_SET); /* Only use plaintext password storage when lanman and nt are * NOT used */ if (!row[22] || !row[23]) pdb_set_plaintext_passwd(u, row[24]); - pdb_set_acct_ctrl(u, xatol(row[25])); - pdb_set_unknown_3(u, xatol(row[26])); - pdb_set_logon_divs(u, xatol(row[27])); - pdb_set_hours_len(u, xatol(row[28])); - pdb_set_unknown_5(u, xatol(row[29])); - pdb_set_unknown_6(u, xatol(row[30])); + pdb_set_acct_ctrl(u, xatol(row[25]), PDB_SET); + pdb_set_unknown_3(u, xatol(row[26]), PDB_SET); + pdb_set_logon_divs(u, xatol(row[27]), PDB_SET); + pdb_set_hours_len(u, xatol(row[28]), PDB_SET); + pdb_set_unknown_5(u, xatol(row[29]), PDB_SET); + pdb_set_unknown_6(u, xatol(row[30]), PDB_SET); return NT_STATUS_OK; } @@ -695,7 +695,7 @@ static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, CONFIG_ACCT_CTRL_DEFAULT), pdb_get_acct_ctrl(newpwd)); - if (store & FLAG_SAM_LOGONTIME) { + if (store & PDB_LOGONTIME) { pdb_mysql_int_field(methods, &query, config_value_write(data, "logon time column", @@ -703,7 +703,7 @@ static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, pdb_get_logon_time(newpwd)); } - if (store & FLAG_SAM_LOGOFFTIME) { + if (store & PDB_LOGOFFTIME) { pdb_mysql_int_field(methods, &query, config_value_write(data, "logoff time column", @@ -711,7 +711,7 @@ static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, pdb_get_logoff_time(newpwd)); } - if (store & FLAG_SAM_KICKOFFTIME) { + if (store & PDB_KICKOFFTIME) { pdb_mysql_int_field(methods, &query, config_value_write(data, "kickoff time column", @@ -719,7 +719,7 @@ static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, pdb_get_kickoff_time(newpwd)); } - if (store & FLAG_SAM_CANCHANGETIME) { + if (store & PDB_CANCHANGETIME) { pdb_mysql_int_field(methods, &query, config_value_write(data, "pass can change time column", @@ -727,7 +727,7 @@ static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, pdb_get_pass_can_change_time(newpwd)); } - if (store & FLAG_SAM_MUSTCHANGETIME) { + if (store & PDB_MUSTCHANGETIME) { pdb_mysql_int_field(methods, &query, config_value_write(data, "pass must change time column", @@ -759,14 +759,14 @@ static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, pdb_get_logon_divs(newpwd)); } - if (store & FLAG_SAM_UID) { + if (store & PDB_UID) { pdb_mysql_int_field(methods, &query, config_value_write(data, "uid column", CONFIG_UID_DEFAULT), pdb_get_uid(newpwd)); } - if (store & FLAG_SAM_GID) { + if (store & PDB_GID) { pdb_mysql_int_field(methods, &query, config_value_write(data, "gid column", CONFIG_GID_DEFAULT), diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c index 5de27bc6e2..be074fca03 100644 --- a/examples/pdb/xml/pdb_xml.c +++ b/examples/pdb/xml/pdb_xml.c @@ -55,12 +55,12 @@ BOOL parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) && pdb_gethexpwd(xmlNodeListGetString (doc, cur->xmlChildrenNode, 1), temp)) - pdb_set_nt_passwd(u, temp); + pdb_set_nt_passwd(u, temp, PDB_SET); else if (!strcmp(xmlGetProp(cur, "type"), "lanman") && pdb_gethexpwd(xmlNodeListGetString (doc, cur->xmlChildrenNode, 1), temp)) - pdb_set_lanman_passwd(u, temp); + pdb_set_lanman_passwd(u, temp, PDB_SET); else DEBUG(0, ("Unknown crypt type: %s\n", @@ -79,42 +79,42 @@ BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) tmp = xmlGetProp(cur, "sid"); if (tmp){ string_to_sid(&sid, tmp); - pdb_set_user_sid(u, &sid); + pdb_set_user_sid(u, &sid, PDB_SET); } tmp = xmlGetProp(cur, "uid"); if (tmp) - pdb_set_uid(u, atol(tmp)); - pdb_set_username(u, xmlGetProp(cur, "name")); + pdb_set_uid(u, atol(tmp), PDB_SET); + pdb_set_username(u, xmlGetProp(cur, "name"), PDB_SET); /* We don't care what the top level element name is */ cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!strcmp(cur->name, "group")) && (cur->ns == ns)) { tmp = xmlGetProp(cur, "gid"); if (tmp) - pdb_set_gid(u, atol(tmp)); + pdb_set_gid(u, atol(tmp), PDB_SET); tmp = xmlGetProp(cur, "sid"); if (tmp){ string_to_sid(&sid, tmp); - pdb_set_group_sid(u, &sid); + pdb_set_group_sid(u, &sid, PDB_SET); } } else if ((!strcmp(cur->name, "domain")) && (cur->ns == ns)) pdb_set_domain(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1)); + 1), PDB_SET); else if (!strcmp(cur->name, "fullname") && cur->ns == ns) pdb_set_fullname(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1)); + 1), PDB_SET); else if (!strcmp(cur->name, "nt_username") && cur->ns == ns) pdb_set_nt_username(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1)); + 1), PDB_SET); else if (!strcmp(cur->name, "logon_script") && cur->ns == ns) pdb_set_logon_script(u, @@ -148,27 +148,27 @@ BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) else if (!strcmp(cur->name, "logon_divs") && cur->ns == ns) pdb_set_logon_divs(u, atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); + (doc, cur->xmlChildrenNode, 1)), PDB_SET); else if (!strcmp(cur->name, "hours_len") && cur->ns == ns) pdb_set_hours_len(u, atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); + (doc, cur->xmlChildrenNode, 1)), PDB_SET); else if (!strcmp(cur->name, "unknown_3") && cur->ns == ns) pdb_set_unknown_3(u, atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); + (doc, cur->xmlChildrenNode, 1)), PDB_SET); else if (!strcmp(cur->name, "unknown_5") && cur->ns == ns) pdb_set_unknown_5(u, atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); + (doc, cur->xmlChildrenNode, 1)), PDB_SET); else if (!strcmp(cur->name, "unknown_6") && cur->ns == ns) pdb_set_unknown_6(u, atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); + (doc, cur->xmlChildrenNode, 1)), PDB_SET); else if (!strcmp(cur->name, "homedir") && cur->ns == ns) pdb_set_homedir(u, @@ -179,7 +179,7 @@ BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) pdb_set_unknown_str(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1)); + 1), PDB_SET); else if (!strcmp(cur->name, "dir_drive") && cur->ns == ns) pdb_set_dir_drive(u, @@ -191,29 +191,29 @@ BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) pdb_set_munged_dial(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1)); + 1), PDB_SET); else if (!strcmp(cur->name, "acct_desc") && cur->ns == ns) pdb_set_acct_desc(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1)); + 1), PDB_SET); else if (!strcmp(cur->name, "acct_ctrl") && cur->ns == ns) pdb_set_acct_ctrl(u, atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); + (doc, cur->xmlChildrenNode, 1)), PDB_SET); else if (!strcmp(cur->name, "workstations") && cur->ns == ns) pdb_set_workstations(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1)); + 1), PDB_SET); else if ((!strcmp(cur->name, "password")) && (cur->ns == ns)) { tmp = xmlGetProp(cur, "last_set"); if (tmp) - pdb_set_pass_last_set_time(u, atol(tmp)); + pdb_set_pass_last_set_time(u, atol(tmp), PDB_SET); tmp = xmlGetProp(cur, "must_change"); if (tmp) pdb_set_pass_must_change_time(u, atol(tmp), True); @@ -402,7 +402,7 @@ static NTSTATUS xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT user = xmlNewChild(data->users, data->ns, "user", NULL); xmlNewProp(user, "sid", sid_to_string(sid_str, pdb_get_user_sid(u))); - if (store & FLAG_SAM_UID) + if (store & PDB_UID) xmlNewProp(user, "uid", iota(pdb_get_uid(u))); if (pdb_get_username(u) && strcmp(pdb_get_username(u), "")) @@ -412,18 +412,18 @@ static NTSTATUS xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT xmlNewProp(cur, "sid", sid_to_string(sid_str, pdb_get_group_sid(u))); - if (store & FLAG_SAM_GID) + if (store & PDB_GID) xmlNewProp(cur, "gid", iota(pdb_get_gid(u))); - if (store & FLAG_SAM_LOGONTIME) + if (store & PDB_LOGONTIME) xmlNewChild(user, data->ns, "login_time", iota(pdb_get_logon_time(u))); - if (store & FLAG_SAM_LOGOFFTIME) + if (store & PDB_LOGOFFTIME) xmlNewChild(user, data->ns, "logoff_time", iota(pdb_get_logoff_time(u))); - if (store & FLAG_SAM_KICKOFFTIME) + if (store & PDB_KICKOFFTIME) xmlNewChild(user, data->ns, "kickoff_time", iota(pdb_get_kickoff_time(u))); @@ -468,11 +468,11 @@ static NTSTATUS xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT pass = xmlNewChild(user, data->ns, "password", NULL); if (pdb_get_pass_last_set_time(u)) xmlNewProp(pass, "last_set", iota(pdb_get_pass_last_set_time(u))); - if (store & FLAG_SAM_CANCHANGETIME) + if (store & PDB_CANCHANGETIME) xmlNewProp(pass, "can_change", iota(pdb_get_pass_can_change_time(u))); - if (store & FLAG_SAM_MUSTCHANGETIME) + if (store & PDB_MUSTCHANGETIME) xmlNewProp(pass, "must_change", iota(pdb_get_pass_must_change_time(u))); -- cgit From 0a0cee218a8fb5646bcf662aba6fc4f39bae5db2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 4 Nov 2002 15:03:58 +0000 Subject: Don't pass true to pdb_set_* functions (This used to be commit e803bfde3d0b199155a87975e8af65f13babe692) --- examples/pdb/mysql/pdb_mysql.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c index 207c3d124e..15b091589c 100644 --- a/examples/pdb/mysql/pdb_mysql.c +++ b/examples/pdb/mysql/pdb_mysql.c @@ -226,20 +226,20 @@ static NTSTATUS row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) if (!row) return NT_STATUS_INVALID_PARAMETER; - pdb_set_logon_time(u, xatol(row[0]), FALSE); - pdb_set_logoff_time(u, xatol(row[1]), FALSE); - pdb_set_kickoff_time(u, xatol(row[2]), FALSE); + pdb_set_logon_time(u, xatol(row[0]), PDB_SET); + pdb_set_logoff_time(u, xatol(row[1]), PDB_SET); + pdb_set_kickoff_time(u, xatol(row[2]), PDB_SET); pdb_set_pass_last_set_time(u, xatol(row[3]), PDB_SET); - pdb_set_pass_can_change_time(u, xatol(row[4]), FALSE); - pdb_set_pass_must_change_time(u, xatol(row[5]), FALSE); + pdb_set_pass_can_change_time(u, xatol(row[4]), PDB_SET); + pdb_set_pass_must_change_time(u, xatol(row[5]), PDB_SET); pdb_set_username(u, row[6], PDB_SET); pdb_set_domain(u, row[7], PDB_SET); pdb_set_nt_username(u, row[8], PDB_SET); pdb_set_fullname(u, row[9], PDB_SET); - pdb_set_homedir(u, row[10], True); - pdb_set_dir_drive(u, row[11], True); - pdb_set_logon_script(u, row[12], True); - pdb_set_profile_path(u, row[13], True); + pdb_set_homedir(u, row[10], PDB_SET); + pdb_set_dir_drive(u, row[11], PDB_SET); + pdb_set_logon_script(u, row[12], PDB_SET); + pdb_set_profile_path(u, row[13], PDB_SET); pdb_set_acct_desc(u, row[14], PDB_SET); pdb_set_workstations(u, row[15], PDB_SET); pdb_set_unknown_str(u, row[16], PDB_SET); -- cgit From d4a93bd8f04f938ae3a33f4ff77229125e3aa850 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 4 Nov 2002 15:04:26 +0000 Subject: Don't pass any booleans to pdb_set_* functions (This used to be commit 91f9c9e1d8b490eb384198ff012f65e22f834c39) --- examples/pdb/xml/pdb_xml.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c index be074fca03..a8b26d6f5f 100644 --- a/examples/pdb/xml/pdb_xml.c +++ b/examples/pdb/xml/pdb_xml.c @@ -120,30 +120,30 @@ BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) pdb_set_logon_script(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1), True); + 1), PDB_SET); else if (!strcmp(cur->name, "profile_path") && cur->ns == ns) pdb_set_profile_path(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1), True); + 1), PDB_SET); else if (!strcmp(cur->name, "logon_time") && cur->ns == ns) pdb_set_logon_time(u, atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), True); + (doc, cur->xmlChildrenNode, 1)), PDB_SET); else if (!strcmp(cur->name, "logoff_time") && cur->ns == ns) pdb_set_logoff_time(u, atol(xmlNodeListGetString (doc, cur->xmlChildrenNode, 1)), - True); + PDB_SET); else if (!strcmp(cur->name, "kickoff_time") && cur->ns == ns) pdb_set_kickoff_time(u, atol(xmlNodeListGetString (doc, cur->xmlChildrenNode, 1)), - True); + PDB_SET); else if (!strcmp(cur->name, "logon_divs") && cur->ns == ns) pdb_set_logon_divs(u, @@ -173,7 +173,7 @@ BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) else if (!strcmp(cur->name, "homedir") && cur->ns == ns) pdb_set_homedir(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1), True); + 1), PDB_SET); else if (!strcmp(cur->name, "unknown_str") && cur->ns == ns) pdb_set_unknown_str(u, @@ -185,7 +185,7 @@ BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) pdb_set_dir_drive(u, xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1), True); + 1), PDB_SET); else if (!strcmp(cur->name, "munged_dial") && cur->ns == ns) pdb_set_munged_dial(u, @@ -216,10 +216,10 @@ BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) pdb_set_pass_last_set_time(u, atol(tmp), PDB_SET); tmp = xmlGetProp(cur, "must_change"); if (tmp) - pdb_set_pass_must_change_time(u, atol(tmp), True); + pdb_set_pass_must_change_time(u, atol(tmp), PDB_SET); tmp = xmlGetProp(cur, "can_change"); if (tmp) - pdb_set_pass_can_change_time(u, atol(tmp), True); + pdb_set_pass_can_change_time(u, atol(tmp), PDB_SET); parsePass(doc, ns, cur, u); } -- cgit From 42f569f06cfb2d3c7f951594fdb28f2c030764b8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 5 Nov 2002 16:48:23 +0000 Subject: Move pdb_mysql to source/passdb (This used to be commit 1d742e14ad18070aee654071d159b8b7410d6f86) --- examples/pdb/mysql/ChangeLog | 41 -- examples/pdb/mysql/Makefile.in | 31 -- examples/pdb/mysql/pdb_mysql.c | 975 ----------------------------------------- 3 files changed, 1047 deletions(-) delete mode 100644 examples/pdb/mysql/ChangeLog delete mode 100644 examples/pdb/mysql/Makefile.in delete mode 100644 examples/pdb/mysql/pdb_mysql.c (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/ChangeLog b/examples/pdb/mysql/ChangeLog deleted file mode 100644 index 5aeeb66268..0000000000 --- a/examples/pdb/mysql/ChangeLog +++ /dev/null @@ -1,41 +0,0 @@ -** This file is now deprecated, use CVS' log featues ** - -2002-06-13 Jelmer Vernooij - * Converted to using SID's like samba HEAD does now - * Fixed some FIXME's - -2002-05-28 Jelmer Vernooij - * Updated docs, after some testing by Vance Lankhaar - -2002-05-25 Jelmer Vernooij - * Added support for dynamic debug classes - * Fixed nt/lanman password support - * Released 1.2 - -2002-05-06 Jelmer Vernooij - * Added support for multiple instances of pdb_mysql - * Added identifiers - * Updated documentation - * Released 1.1 - -2002-04-27 Jelmer Vernooij - * Updated documentation - * Released 1.0! - -2002-04-27 Jelmer Vernooij - * Added update/add sam account support - * Released 0.4 - -2002-04-13 Jelmer Vernooij - * Support for multiple instances of pdb_mysql - * Released 0.3 - -2002-04-12 Jelmer Vernooij - * Now using lp_parm_string to retrieve configuration values (instead of - our configuration files) - * Updated documentation - * Released 0.2 - -2002-04-10 Jelmer Vernooij - * Released 0.1 - * Initial release. Not supporting adding and updating data of users diff --git a/examples/pdb/mysql/Makefile.in b/examples/pdb/mysql/Makefile.in deleted file mode 100644 index 3ebecad762..0000000000 --- a/examples/pdb/mysql/Makefile.in +++ /dev/null @@ -1,31 +0,0 @@ -PDB_OBJS = pdb_mysql.so -PDB_LDFLAGS = -lmysqlclient -MAKEFILE = Makefile.pdb - -CC = @CC@ -LIBTOOL = libtool -CFLAGS = @CFLAGS@ $(PDB_CFLAGS) -CPPFLAGS = @CPPFLAGS@ $(PDB_CPPFLAGS) -LDFLAGS = @LDFLAGS@ $(PDB_LDFLAGS) -LDSHFLAGS = -shared -srcdir = @builddir@ -FLAGS = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper -I. $(CPPFLAGS) -I$(srcdir) - -# Default target - -default: $(PDB_OBJS) - -# Pattern rules - -%.so: %.lo - $(LIBTOOL) $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< - -%.lo: %.c - $(LIBTOOL) $(CC) $(FLAGS) -c $< - -# Misc targets - -clean: - rm -rf .libs - rm -f core *~ *% *.bak \ - $(PDB_OBJS) $(PDB_OBJS:.so=.o) $(PDB_OBJS:.so=.lo) diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c deleted file mode 100644 index 15b091589c..0000000000 --- a/examples/pdb/mysql/pdb_mysql.c +++ /dev/null @@ -1,975 +0,0 @@ - -/* - * MySQL password backend for samba - * Copyright (C) Jelmer Vernooij 2002 - * - * 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" -#include - -#define CONFIG_TABLE_DEFAULT "user" -#define CONFIG_LOGON_TIME_DEFAULT "logon_time" -#define CONFIG_LOGOFF_TIME_DEFAULT "logoff_time" -#define CONFIG_KICKOFF_TIME_DEFAULT "kickoff_time" -#define CONFIG_PASS_LAST_SET_TIME_DEFAULT "pass_last_set_time" -#define CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT "pass_can_change_time" -#define CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT "pass_must_change_time" -#define CONFIG_USERNAME_DEFAULT "username" -#define CONFIG_DOMAIN_DEFAULT "domain" -#define CONFIG_NT_USERNAME_DEFAULT "nt_username" -#define CONFIG_FULLNAME_DEFAULT "nt_fullname" -#define CONFIG_HOME_DIR_DEFAULT "home_dir" -#define CONFIG_DIR_DRIVE_DEFAULT "dir_drive" -#define CONFIG_LOGON_SCRIPT_DEFAULT "logon_script" -#define CONFIG_PROFILE_PATH_DEFAULT "profile_path" -#define CONFIG_ACCT_DESC_DEFAULT "acct_desc" -#define CONFIG_WORKSTATIONS_DEFAULT "workstations" -#define CONFIG_UNKNOWN_STR_DEFAULT "unknown_str" -#define CONFIG_MUNGED_DIAL_DEFAULT "munged_dial" -#define CONFIG_UID_DEFAULT "uid" -#define CONFIG_GID_DEFAULT "gid" -#define CONFIG_USER_SID_DEFAULT "user_sid" -#define CONFIG_GROUP_SID_DEFAULT "group_sid" -#define CONFIG_LM_PW_DEFAULT "lm_pw" -#define CONFIG_NT_PW_DEFAULT "nt_pw" -#define CONFIG_PLAIN_PW_DEFAULT "NULL" -#define CONFIG_ACCT_CTRL_DEFAULT "acct_ctrl" -#define CONFIG_UNKNOWN_3_DEFAULT "unknown_3" -#define CONFIG_LOGON_DIVS_DEFAULT "logon_divs" -#define CONFIG_HOURS_LEN_DEFAULT "hours_len" -#define CONFIG_UNKNOWN_5_DEFAULT "unknown_5" -#define CONFIG_UNKNOWN_6_DEFAULT "unknown_6" -#define CONFIG_HOST_DEFAULT "localhost" -#define CONFIG_USER_DEFAULT "samba" -#define CONFIG_PASS_DEFAULT "" -#define CONFIG_PORT_DEFAULT "3306" -#define CONFIG_DB_DEFAULT "samba" - -static int mysqlsam_debug_level = DBGC_ALL; - -#undef DBGC_CLASS -#define DBGC_CLASS mysqlsam_debug_level - -PDB_MODULE_VERSIONING_MAGIC - -typedef struct pdb_mysql_data { - MYSQL *handle; - MYSQL_RES *pwent; - char *location; -} pdb_mysql_data; - -/* Used to construct insert and update queries */ - -typedef struct pdb_mysql_query { - char update; - TALLOC_CTX *mem_ctx; - char *part1; - char *part2; -} pdb_mysql_query; -#define SET_DATA(data,methods) { \ - if(!methods){ \ - DEBUG(0, ("invalid methods!\n")); \ - return NT_STATUS_INVALID_PARAMETER; \ - } \ - data = (struct pdb_mysql_data *)methods->private_data; \ - if(!data || !(data->handle)){ \ - DEBUG(0, ("invalid handle!\n")); \ - return NT_STATUS_INVALID_HANDLE; \ - } \ -} - -static void pdb_mysql_int_field(struct pdb_methods *m, - struct pdb_mysql_query *q, char *name, int value) -{ - if (!name || strchr(name, '\'')) - return; /* This field shouldn't be set by us */ - - if (q->update) { - q->part1 = - talloc_asprintf_append(q->mem_ctx, q->part1, - "%s = %d,", name, value); - } else { - q->part1 = - talloc_asprintf_append(q->mem_ctx, q->part1, "%s,", name); - q->part2 = - talloc_asprintf_append(q->mem_ctx, q->part2, "%d,", value); - } -} - -static NTSTATUS pdb_mysql_string_field(struct pdb_methods *methods, - struct pdb_mysql_query *q, - char *name, const char *value) -{ - char *esc_value; - struct pdb_mysql_data *data; - char *tmp_value; - - SET_DATA(data, methods); - - if (!name || !value || !strcmp(value, "") || strchr(name, '\'')) - return NT_STATUS_INVALID_PARAMETER; /* This field shouldn't be set by module */ - - esc_value = malloc(strlen(value) * 2 + 1); - - tmp_value = smb_xstrdup(value); - mysql_real_escape_string(data->handle, esc_value, tmp_value, - strlen(tmp_value)); - SAFE_FREE(tmp_value); - - if (q->update) { - q->part1 = - talloc_asprintf_append(q->mem_ctx, q->part1, - "%s = '%s',", name, esc_value); - } else { - q->part1 = - talloc_asprintf_append(q->mem_ctx, q->part1, "%s,", name); - q->part2 = - talloc_asprintf_append(q->mem_ctx, q->part2, "'%s',", - esc_value); - } - - SAFE_FREE(esc_value); - - return NT_STATUS_OK; -} - -static char * config_value(pdb_mysql_data * data, char *name, char *default_value) -{ - if (lp_parm_string(NULL, data->location, name)) - return lp_parm_string(NULL, data->location, name); - - return default_value; -} - -static char * config_value_write(pdb_mysql_data * data, char *name, char *default_value) { - char *v = config_value(data, name, NULL); - char *swrite; - - if (!v) - return default_value; - - swrite = strchr(v, ':'); - - /* Default to the same field as read field */ - if (!swrite) - return v; - - swrite++; - - /* If the field is 0 chars long, we shouldn't write to it */ - if (!strlen(swrite) || !strcmp(swrite, "NULL")) - return NULL; - - /* Otherwise, use the additionally specified */ - return swrite; -} - -static const char * config_value_read(pdb_mysql_data * data, char *name, char *default_value) -{ - char *v = config_value(data, name, NULL); - char *swrite; - - if (!v) - return default_value; - - swrite = strchr(v, ':'); - - /* If no write is specified, there are no problems */ - if (!swrite) { - if (strlen(v) == 0) - return "NULL"; - return v; - } - - /* Otherwise, we have to cut the ':write_part' */ - *swrite = '\0'; - if (strlen(v) == 0) - return "NULL"; - - return v; -} - -/* Wrapper for atol that returns 0 if 'a' points to NULL */ -static long xatol(char *a) -{ - long ret = 0; - - if (a != NULL) - ret = atol(a); - - return ret; -} - -static NTSTATUS row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) -{ - MYSQL_ROW row; - pstring temp; - unsigned int num_fields; - DOM_SID sid; - - num_fields = mysql_num_fields(r); - row = mysql_fetch_row(r); - if (!row) - return NT_STATUS_INVALID_PARAMETER; - - pdb_set_logon_time(u, xatol(row[0]), PDB_SET); - pdb_set_logoff_time(u, xatol(row[1]), PDB_SET); - pdb_set_kickoff_time(u, xatol(row[2]), PDB_SET); - pdb_set_pass_last_set_time(u, xatol(row[3]), PDB_SET); - pdb_set_pass_can_change_time(u, xatol(row[4]), PDB_SET); - pdb_set_pass_must_change_time(u, xatol(row[5]), PDB_SET); - pdb_set_username(u, row[6], PDB_SET); - pdb_set_domain(u, row[7], PDB_SET); - pdb_set_nt_username(u, row[8], PDB_SET); - pdb_set_fullname(u, row[9], PDB_SET); - pdb_set_homedir(u, row[10], PDB_SET); - pdb_set_dir_drive(u, row[11], PDB_SET); - pdb_set_logon_script(u, row[12], PDB_SET); - pdb_set_profile_path(u, row[13], PDB_SET); - pdb_set_acct_desc(u, row[14], PDB_SET); - pdb_set_workstations(u, row[15], PDB_SET); - pdb_set_unknown_str(u, row[16], PDB_SET); - pdb_set_munged_dial(u, row[17], PDB_SET); - - if (row[18]) - pdb_set_uid(u, xatol(row[18]), PDB_SET); - if (row[19]) - pdb_set_gid(u, xatol(row[19]), PDB_SET); - - string_to_sid(&sid, row[20]); - pdb_set_user_sid(u, &sid, PDB_SET); - string_to_sid(&sid, row[21]); - pdb_set_group_sid(u, &sid, PDB_SET); - - if (pdb_gethexpwd(row[22], temp), PDB_SET) - pdb_set_lanman_passwd(u, temp, PDB_SET); - if (pdb_gethexpwd(row[23], temp), PDB_SET) - pdb_set_nt_passwd(u, temp, PDB_SET); - - /* Only use plaintext password storage when lanman and nt are - * NOT used */ - if (!row[22] || !row[23]) - pdb_set_plaintext_passwd(u, row[24]); - - pdb_set_acct_ctrl(u, xatol(row[25]), PDB_SET); - pdb_set_unknown_3(u, xatol(row[26]), PDB_SET); - pdb_set_logon_divs(u, xatol(row[27]), PDB_SET); - pdb_set_hours_len(u, xatol(row[28]), PDB_SET); - pdb_set_unknown_5(u, xatol(row[29]), PDB_SET); - pdb_set_unknown_6(u, xatol(row[30]), PDB_SET); - - return NT_STATUS_OK; -} - -static NTSTATUS mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) -{ - struct pdb_mysql_data *data = - (struct pdb_mysql_data *) methods->private_data; - char *query; - int ret; - - if (!data || !(data->handle)) { - DEBUG(0, ("invalid handle!\n")); - return NT_STATUS_INVALID_HANDLE; - } - - asprintf(&query, - "SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s", - config_value_read(data, "logon time column", - CONFIG_LOGON_TIME_DEFAULT), - config_value_read(data, "logoff time column", - CONFIG_LOGOFF_TIME_DEFAULT), - config_value_read(data, "kickoff time column", - CONFIG_KICKOFF_TIME_DEFAULT), - config_value_read(data, "pass last set time column", - CONFIG_PASS_LAST_SET_TIME_DEFAULT), - config_value_read(data, "pass can change time column", - CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT), - config_value_read(data, "pass must change time column", - CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT), - config_value_read(data, "username column", - CONFIG_USERNAME_DEFAULT), - config_value_read(data, "domain column", - CONFIG_DOMAIN_DEFAULT), - config_value_read(data, "nt username column", - CONFIG_NT_USERNAME_DEFAULT), - config_value_read(data, "fullname column", - CONFIG_FULLNAME_DEFAULT), - config_value_read(data, "home dir column", - CONFIG_HOME_DIR_DEFAULT), - config_value_read(data, "dir drive column", - CONFIG_DIR_DRIVE_DEFAULT), - config_value_read(data, "logon script column", - CONFIG_LOGON_SCRIPT_DEFAULT), - config_value_read(data, "profile path column", - CONFIG_PROFILE_PATH_DEFAULT), - config_value_read(data, "acct desc column", - CONFIG_ACCT_DESC_DEFAULT), - config_value_read(data, "workstations column", - CONFIG_WORKSTATIONS_DEFAULT), - config_value_read(data, "unknown string column", - CONFIG_UNKNOWN_STR_DEFAULT), - config_value_read(data, "munged dial column", - CONFIG_MUNGED_DIAL_DEFAULT), - config_value_read(data, "uid column", CONFIG_UID_DEFAULT), - config_value_read(data, "gid column", CONFIG_GID_DEFAULT), - config_value_read(data, "user sid column", - CONFIG_USER_SID_DEFAULT), - config_value_read(data, "group sid column", - CONFIG_GROUP_SID_DEFAULT), - config_value_read(data, "lanman pass column", - CONFIG_LM_PW_DEFAULT), - config_value_read(data, "nt pass column", - CONFIG_NT_PW_DEFAULT), - config_value_read(data, "plain pass column", - CONFIG_PLAIN_PW_DEFAULT), - config_value_read(data, "acct ctrl column", - CONFIG_ACCT_CTRL_DEFAULT), - config_value_read(data, "unknown 3 column", - CONFIG_UNKNOWN_3_DEFAULT), - config_value_read(data, "logon divs column", - CONFIG_LOGON_DIVS_DEFAULT), - config_value_read(data, "hours len column", - CONFIG_HOURS_LEN_DEFAULT), - config_value_read(data, "unknown 5 column", - CONFIG_UNKNOWN_5_DEFAULT), - config_value_read(data, "unknown 6 column", - CONFIG_UNKNOWN_6_DEFAULT), - config_value(data, "table", CONFIG_TABLE_DEFAULT) - ); - - ret = mysql_query(data->handle, query); - SAFE_FREE(query); - - if (ret) { - DEBUG(0, - ("Error executing query: %s\n", mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - data->pwent = mysql_store_result(data->handle); - - if (data->pwent == NULL) { - DEBUG(0, - ("Error storing results: %s\n", mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - DEBUG(5, - ("mysqlsam_setsampwent succeeded(%d results)!\n", - mysql_num_fields(data->pwent))); - - return NT_STATUS_OK; -} - -/*************************************************************** - End enumeration of the passwd list. - ****************************************************************/ - -static void mysqlsam_endsampwent(struct pdb_methods *methods) -{ - struct pdb_mysql_data *data = - (struct pdb_mysql_data *) methods->private_data; - - if (data == NULL) { - DEBUG(0, ("invalid handle!\n")); - return; - } - - if (data->pwent != NULL) - mysql_free_result(data->pwent); - - data->pwent = NULL; - - DEBUG(5, ("mysql_endsampwent called\n")); -} - -/***************************************************************** - Get one SAM_ACCOUNT from the list (next in line) - *****************************************************************/ - -static NTSTATUS mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) -{ - struct pdb_mysql_data *data; - - SET_DATA(data, methods); - - if (data->pwent == NULL) { - DEBUG(0, ("invalid pwent\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - return row_to_sam_account(data->pwent, user); -} - -static NTSTATUS mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, - const char *field, const char *sname) -{ - char *esc_sname; - char *query; - NTSTATUS ret; - MYSQL_RES *res; - int mysql_ret; - struct pdb_mysql_data *data; - char *tmp_sname; - - SET_DATA(data, methods); - - esc_sname = malloc(strlen(sname) * 2 + 1); - if (!esc_sname) { - return NT_STATUS_NO_MEMORY; - } - - DEBUG(5, - ("mysqlsam_select_by_field: getting data where %s = %s(nonescaped)\n", - field, sname)); - - tmp_sname = smb_xstrdup(sname); - - /* Escape sname */ - mysql_real_escape_string(data->handle, esc_sname, tmp_sname, - strlen(tmp_sname)); - - SAFE_FREE(tmp_sname); - - if (user == NULL) { - DEBUG(0, ("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); - SAFE_FREE(esc_sname); - return NT_STATUS_INVALID_PARAMETER; - } - - asprintf(&query, - "SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s WHERE %s = '%s'", - config_value_read(data, "logon time column", - CONFIG_LOGON_TIME_DEFAULT), - config_value_read(data, "logoff time column", - CONFIG_LOGOFF_TIME_DEFAULT), - config_value_read(data, "kickoff time column", - CONFIG_KICKOFF_TIME_DEFAULT), - config_value_read(data, "pass last set time column", - CONFIG_PASS_LAST_SET_TIME_DEFAULT), - config_value_read(data, "pass can change time column", - CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT), - config_value_read(data, "pass must change time column", - CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT), - config_value_read(data, "username column", - CONFIG_USERNAME_DEFAULT), - config_value_read(data, "domain column", - CONFIG_DOMAIN_DEFAULT), - config_value_read(data, "nt username column", - CONFIG_NT_USERNAME_DEFAULT), - config_value_read(data, "fullname column", - CONFIG_FULLNAME_DEFAULT), - config_value_read(data, "home dir column", - CONFIG_HOME_DIR_DEFAULT), - config_value_read(data, "dir drive column", - CONFIG_DIR_DRIVE_DEFAULT), - config_value_read(data, "logon script column", - CONFIG_LOGON_SCRIPT_DEFAULT), - config_value_read(data, "profile path column", - CONFIG_PROFILE_PATH_DEFAULT), - config_value_read(data, "acct desc column", - CONFIG_ACCT_DESC_DEFAULT), - config_value_read(data, "workstations column", - CONFIG_WORKSTATIONS_DEFAULT), - config_value_read(data, "unknown string column", - CONFIG_UNKNOWN_STR_DEFAULT), - config_value_read(data, "munged dial column", - CONFIG_MUNGED_DIAL_DEFAULT), - config_value_read(data, "uid column", CONFIG_UID_DEFAULT), - config_value_read(data, "gid column", CONFIG_GID_DEFAULT), - config_value_read(data, "user sid column", - CONFIG_USER_SID_DEFAULT), - config_value_read(data, "group sid column", - CONFIG_GROUP_SID_DEFAULT), - config_value_read(data, "lanman pass column", - CONFIG_LM_PW_DEFAULT), - config_value_read(data, "nt pass column", - CONFIG_NT_PW_DEFAULT), - config_value_read(data, "plain pass column", - CONFIG_PLAIN_PW_DEFAULT), - config_value_read(data, "acct ctrl column", - CONFIG_ACCT_CTRL_DEFAULT), - config_value_read(data, "unknown 3 column", - CONFIG_UNKNOWN_3_DEFAULT), - config_value_read(data, "logon divs column", - CONFIG_LOGON_DIVS_DEFAULT), - config_value_read(data, "hours len column", - CONFIG_HOURS_LEN_DEFAULT), - config_value_read(data, "unknown 5 column", - CONFIG_UNKNOWN_5_DEFAULT), - config_value_read(data, "unknown 6 column", - CONFIG_UNKNOWN_6_DEFAULT), - config_value(data, "table", CONFIG_TABLE_DEFAULT), field, - esc_sname); - - SAFE_FREE(esc_sname); - - mysql_ret = mysql_query(data->handle, query); - - SAFE_FREE(query); - - if (mysql_ret) { - DEBUG(0, - ("Error while executing MySQL query: %s\n", - mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - res = mysql_store_result(data->handle); - if (res == NULL) { - DEBUG(0, - ("Error storing results: %s\n", mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - ret = row_to_sam_account(res, user); - mysql_free_result(res); - - return ret; -} - -/****************************************************************** - Lookup a name in the SAM database - ******************************************************************/ - -static NTSTATUS mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, - const char *sname) -{ - struct pdb_mysql_data *data; - - SET_DATA(data, methods); - - if (!sname) { - DEBUG(0, ("invalid name specified")); - return NT_STATUS_INVALID_PARAMETER; - } - - return mysqlsam_select_by_field(methods, user, - config_value_read(data, "username column", - CONFIG_USERNAME_DEFAULT), sname); -} - - -/*************************************************************************** - Search by sid - **************************************************************************/ - -static NTSTATUS mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, - const DOM_SID * sid) -{ - struct pdb_mysql_data *data; - fstring sid_str; - - SET_DATA(data, methods); - - sid_to_string(sid_str, sid); - - return mysqlsam_select_by_field(methods, user, - config_value_read(data, "user sid column", - CONFIG_USER_SID_DEFAULT), sid_str); -} - -/*************************************************************************** - Delete a SAM_ACCOUNT - ****************************************************************************/ - -static NTSTATUS mysqlsam_delete_sam_account(struct pdb_methods *methods, - SAM_ACCOUNT * sam_pass) -{ - const char *sname = pdb_get_username(sam_pass); - char *esc; - char *query; - int ret; - struct pdb_mysql_data *data; - char *tmp_sname; - - SET_DATA(data, methods); - - if (!methods) { - DEBUG(0, ("invalid methods!\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - data = (struct pdb_mysql_data *) methods->private_data; - if (!data || !(data->handle)) { - DEBUG(0, ("invalid handle!\n")); - return NT_STATUS_INVALID_HANDLE; - } - - if (!sname) { - DEBUG(0, ("invalid name specified\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - /* Escape sname */ - esc = malloc(strlen(sname) * 2 + 1); - if (!esc) { - DEBUG(0, ("Can't allocate memory to store escaped name\n")); - return NT_STATUS_NO_MEMORY; - } - - tmp_sname = smb_xstrdup(sname); - - mysql_real_escape_string(data->handle, esc, tmp_sname, - strlen(tmp_sname)); - - SAFE_FREE(tmp_sname); - - asprintf(&query, "DELETE FROM %s WHERE %s = '%s'", - config_value(data, "table", CONFIG_TABLE_DEFAULT), - config_value_read(data, "username column", - CONFIG_USERNAME_DEFAULT), esc); - - SAFE_FREE(esc); - - ret = mysql_query(data->handle, query); - - SAFE_FREE(query); - - if (ret) { - DEBUG(0, - ("Error while executing query: %s\n", - mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - DEBUG(5, ("User '%s' deleted\n", sname)); - return NT_STATUS_OK; -} - -static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, - const SAM_ACCOUNT * newpwd, char isupdate) -{ - pstring temp; - uint32 store = pdb_get_init_flag(newpwd); - struct pdb_mysql_data *data; - pdb_mysql_query query; - fstring sid_str; - - if (!methods) { - DEBUG(0, ("invalid methods!\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - data = (struct pdb_mysql_data *) methods->private_data; - if (data == NULL || data->handle == NULL) { - DEBUG(0, ("invalid handle!\n")); - return NT_STATUS_INVALID_HANDLE; - } - query.update = isupdate; - - /* I know this is somewhat overkill but only the talloc - * functions have asprint_append and the 'normal' asprintf - * is a GNU extension */ - query.mem_ctx = talloc_init(); - query.part2 = talloc_asprintf(query.mem_ctx, "%s", ""); - if (query.update) { - query.part1 = - talloc_asprintf(query.mem_ctx, "UPDATE %s SET ", - config_value(data, "table", - CONFIG_TABLE_DEFAULT)); - } else { - query.part1 = - talloc_asprintf(query.mem_ctx, "INSERT INTO %s (", - config_value(data, "table", - CONFIG_TABLE_DEFAULT)); - } - - pdb_mysql_int_field(methods, &query, - config_value_write(data, "acct ctrl column", - CONFIG_ACCT_CTRL_DEFAULT), - pdb_get_acct_ctrl(newpwd)); - - if (store & PDB_LOGONTIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "logon time column", - CONFIG_LOGON_TIME_DEFAULT), - pdb_get_logon_time(newpwd)); - } - - if (store & PDB_LOGOFFTIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "logoff time column", - CONFIG_LOGOFF_TIME_DEFAULT), - pdb_get_logoff_time(newpwd)); - } - - if (store & PDB_KICKOFFTIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "kickoff time column", - CONFIG_KICKOFF_TIME_DEFAULT), - pdb_get_kickoff_time(newpwd)); - } - - if (store & PDB_CANCHANGETIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "pass can change time column", - CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT), - pdb_get_pass_can_change_time(newpwd)); - } - - if (store & PDB_MUSTCHANGETIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "pass must change time column", - CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT), - pdb_get_pass_must_change_time(newpwd)); - } - - if (pdb_get_pass_last_set_time(newpwd)) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "pass must change time column", - CONFIG_PASS_LAST_SET_TIME_DEFAULT), - pdb_get_pass_last_set_time(newpwd)); - } - - if (pdb_get_hours_len(newpwd)) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "hours len column", - CONFIG_HOURS_LEN_DEFAULT), - pdb_get_hours_len(newpwd)); - } - - if (pdb_get_logon_divs(newpwd)) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "logon divs column", - CONFIG_LOGON_DIVS_DEFAULT), - pdb_get_logon_divs(newpwd)); - } - - if (store & PDB_UID) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, "uid column", - CONFIG_UID_DEFAULT), - pdb_get_uid(newpwd)); - } - - if (store & PDB_GID) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, "gid column", - CONFIG_GID_DEFAULT), - pdb_get_gid(newpwd)); - } - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "user sid column", - CONFIG_USER_SID_DEFAULT), - sid_to_string(sid_str, (DOM_SID *) - pdb_get_user_sid(newpwd))); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "group sid column", - CONFIG_GROUP_SID_DEFAULT), - sid_to_string(sid_str, (DOM_SID *) - pdb_get_group_sid(newpwd))); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "username column", - CONFIG_USERNAME_DEFAULT), - pdb_get_username(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "domain column", - CONFIG_DOMAIN_DEFAULT), - pdb_get_domain(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "nt username column", - CONFIG_NT_USERNAME_DEFAULT), - pdb_get_nt_username(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "fullname column", - CONFIG_FULLNAME_DEFAULT), - pdb_get_fullname(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "logon script column", - CONFIG_LOGON_SCRIPT_DEFAULT), - pdb_get_logon_script(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "profile path column", - CONFIG_PROFILE_PATH_DEFAULT), - pdb_get_profile_path(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "dir drive column", - CONFIG_DIR_DRIVE_DEFAULT), - pdb_get_dir_drive(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "home dir column", - CONFIG_HOME_DIR_DEFAULT), - pdb_get_homedir(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "workstations column", - CONFIG_WORKSTATIONS_DEFAULT), - pdb_get_workstations(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "unknown string column", - CONFIG_UNKNOWN_STR_DEFAULT), - pdb_get_workstations(newpwd)); - - pdb_sethexpwd(temp, pdb_get_lanman_passwd(newpwd), - pdb_get_acct_ctrl(newpwd)); - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "lanman pass column", - CONFIG_LM_PW_DEFAULT), temp); - - pdb_sethexpwd(temp, pdb_get_nt_passwd(newpwd), - pdb_get_acct_ctrl(newpwd)); - pdb_mysql_string_field(methods, &query, - config_value_write(data, "nt pass column", - CONFIG_NT_PW_DEFAULT), temp); - - if (query.update) { - query.part1[strlen(query.part1) - 1] = '\0'; - query.part1 = - talloc_asprintf_append(query.mem_ctx, query.part1, - " WHERE %s = '%s'", - config_value_read(data, - "user sid column", - CONFIG_USER_SID_DEFAULT), - sid_to_string(sid_str, (DOM_SID *) - pdb_get_user_sid - (newpwd))); - } else { - query.part2[strlen(query.part2) - 1] = ')'; - query.part1[strlen(query.part1) - 1] = ')'; - query.part1 = - talloc_asprintf_append(query.mem_ctx, query.part1, - " VALUES (%s", query.part2); - } - - DEBUG(0, ("%s\n", query.part1)); - /* Execute the query */ - if (mysql_query(data->handle, query.part1)) { - DEBUG(0, - ("Error executing %s, %s\n", query.part1, - mysql_error(data->handle))); - return NT_STATUS_INVALID_PARAMETER; - } - talloc_destroy(query.mem_ctx); - return NT_STATUS_OK; -} - -static NTSTATUS mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) -{ - return mysqlsam_replace_sam_account(methods, newpwd, 0); -} - -static NTSTATUS mysqlsam_update_sam_account(struct pdb_methods *methods, - SAM_ACCOUNT * newpwd) -{ - return mysqlsam_replace_sam_account(methods, newpwd, 1); -} - -NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, - char *location) -{ - NTSTATUS nt_status; - struct pdb_mysql_data *data; - - mysqlsam_debug_level = debug_add_class("mysqlsam"); - if (mysqlsam_debug_level == -1) { - mysqlsam_debug_level = DBGC_ALL; - DEBUG(0, - ("mysqlsam: Couldn't register custom debugging class!\n")); - } - - if (!pdb_context) { - DEBUG(0, ("invalid pdb_methods specified\n")); - return NT_STATUS_UNSUCCESSFUL; - } - - if (!NT_STATUS_IS_OK - (nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { - return nt_status; - } - - (*pdb_method)->name = "mysqlsam"; - - (*pdb_method)->setsampwent = mysqlsam_setsampwent; - (*pdb_method)->endsampwent = mysqlsam_endsampwent; - (*pdb_method)->getsampwent = mysqlsam_getsampwent; - (*pdb_method)->getsampwnam = mysqlsam_getsampwnam; - (*pdb_method)->getsampwsid = mysqlsam_getsampwsid; - (*pdb_method)->add_sam_account = mysqlsam_add_sam_account; - (*pdb_method)->update_sam_account = mysqlsam_update_sam_account; - (*pdb_method)->delete_sam_account = mysqlsam_delete_sam_account; - - data = talloc(pdb_context->mem_ctx, sizeof(struct pdb_mysql_data)); - (*pdb_method)->private_data = data; - data->handle = NULL; - data->pwent = NULL; - - if (!location) { - DEBUG(0, ("No identifier specified. See README for details\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - data->location = smb_xstrdup(location); - - DEBUG(1, - ("Connecting to database server, host: %s, user: %s, password: %s, database: %s, port: %ld\n", - config_value(data, "mysql host", CONFIG_HOST_DEFAULT), - config_value(data, "mysql user", CONFIG_USER_DEFAULT), - config_value(data, "mysql password", CONFIG_PASS_DEFAULT), - config_value(data, "mysql database", CONFIG_DB_DEFAULT), - xatol(config_value(data, "mysql port", CONFIG_PORT_DEFAULT)))); - - /* Do the mysql initialization */ - data->handle = mysql_init(NULL); - if (!data->handle) { - DEBUG(0, ("Failed to connect to server\n")); - return NT_STATUS_UNSUCCESSFUL; - } - /* Process correct entry in $HOME/.my.conf */ - if (!mysql_real_connect(data->handle, - config_value(data, "mysql host", CONFIG_HOST_DEFAULT), - config_value(data, "mysql user", CONFIG_USER_DEFAULT), - config_value(data, "mysql password", CONFIG_PASS_DEFAULT), - config_value(data, "mysql database", CONFIG_DB_DEFAULT), - xatol(config_value (data, "mysql port", CONFIG_PORT_DEFAULT)), - NULL, 0)) { - DEBUG(0, - ("Failed to connect to mysql database: error: %s\n", - mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - DEBUG(5, ("Connected to mysql db\n")); - - return NT_STATUS_OK; -} -- cgit From 7dba784b5ed7fd4b0c9bc62c08be0b1a4a84ad14 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 5 Nov 2002 16:55:21 +0000 Subject: Convert pdb_mysql docs to sgml (This used to be commit 6642f6c5a9d6fa52a41a382850ed8bb3e1ebf701) --- examples/pdb/mysql/README | 92 ----------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 examples/pdb/mysql/README (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/README b/examples/pdb/mysql/README deleted file mode 100644 index e3cbcab8cf..0000000000 --- a/examples/pdb/mysql/README +++ /dev/null @@ -1,92 +0,0 @@ -PDB MySQL plugin for samba v1.1 --- - -Building -========= -Before you can build the plugin, set the variable SAMBA_SRC in Makefile to the -path containing the samba sources. This is usually the 'source' directory in -the samba tarball or CVS. - -Next, type make, and then copy pdb_mysql.so to any location you want. I -strongly recommend installing it in $PREFIX/lib or /usr/lib/samba/ - -Configuring -============ -This plugin lacks some good documentation, but here is some short info: - -Add a the following to the 'passdb backend' variable in your smb.conf: - -passdb backend = [other-plugins] plugin:/location/to/pdb_mysql.so:identifier [other-plugins] - -The identifier can be any string you like, as long as it doesn't collide with -the identifiers of other plugins or other instances of pdb_mysql. If you -specify multiple pdb_mysql.so entries in 'passdb backend', you also need to -use different identifiers! - -Additional options can be given thru the smb.conf file in the [global] section. - -identifier:mysql host - host name, defaults to 'localhost' -identifier:mysql password -identifier:mysql user - defaults to 'samba' -identifier:mysql database - defaults to 'samba' -identifier:mysql port - defaults to 3306 -identifier:table - Name of the table containing users - -Names of the columns in this table(I've added column types those columns - should have first): -identifier:logon time column - int(9) -identifier:logoff time column - int(9) -identifier:kickoff time column - int(9) -identifier:pass last set time column - int(9) -identifier:pass can change time column - int(9) -identifier:pass must change time column - int(9) -identifier:username column - varchar(255) - unix username -identifier:domain column - varchar(255) - NT domain user is part of -identifier:nt username column - varchar(255) - NT username -identifier:fullname column - varchar(255) - Full name of user -identifier:home dir column - varchar(255) - Unix homedir path -identifier:dir drive column - varchar(2) - Directory drive path (eg: 'H:') -identifier:logon script column - varchar(255) - Batch file to run on client side when logging on -identifier:profile path column - varchar(255) - Path of profile -identifier:acct desc column - varchar(255) - Some ASCII NT user data -identifier:workstations column - varchar(255) - Workstations user can logon to (or NULL for all) -identifier:unknown string column - varchar(255) - unknown string -identifier:munged dial column - varchar(255) - ? -identifier:uid column - int(9) - Unix user ID (uid) -identifier:gid column - int(9) - Unix user group (gid) -identifier:user sid column - varchar(255) - NT user SID -identifier:group sid column - varchar(255) - NT group ID -identifier:lanman pass column - varchar(255) - encrypted lanman password -identifier:nt pass column - varchar(255) - encrypted nt passwd -identifier:plaintext pass column - varchar(255) - plaintext password -identifier:acct control column - int(9) - nt user data -identifier:unknown 3 column - int(9) - unknown -identifier:logon divs column - int(9) - ? -identifier:hours len column - int(9) - ? -identifier:unknown 5 column - int(9) - unknown -identifier:unknown 6 column - int(9) - unknown - -Eventually, you can put a colon (:) after the name of each column, which -should specify the column to update when updating the table. You can also -specify nothing behind the colon - then the data from the field will not be -updated. - -Using plaintext passwords or encrypted password -=============================================== -I strongly discourage the use of plaintext passwords, however, you can use them: - -If you would like to use plaintext passwords, set 'identifier:lanman pass column' and 'identifier:nt pass column' to 'NULL' (without the quotes) and 'identifier:plaintext pass column' to the name of the column containing the plaintext passwords. - -If you use encrypted passwords, set the 'identifier:plaintext pass column' to 'NULL' (without the quotes). This is the default. - -Getting non-column data from the table -====================================== -It is possible to have not all data in the database and making some 'constant'. - -For example, you can set 'identifier:fullname column' to : - CONCAT(First_name,' ',Sur_name) - -Or, set 'identifier:workstations column' to : - NULL - -See the MySQL documentation for more language constructs. -- cgit From 82c714569d8fb01f40d343c3330467e65636be33 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 5 Nov 2002 17:08:32 +0000 Subject: Move pdb_xml to source/ (This used to be commit b68106a79e4536fa82d75dd330d07dba51bfeaf4) --- examples/pdb/xml/ChangeLog | 13 - examples/pdb/xml/Makefile.in | 31 --- examples/pdb/xml/README | 14 -- examples/pdb/xml/TODO | 6 - examples/pdb/xml/pdb_xml.c | 554 ------------------------------------------- 5 files changed, 618 deletions(-) delete mode 100644 examples/pdb/xml/ChangeLog delete mode 100644 examples/pdb/xml/Makefile.in delete mode 100644 examples/pdb/xml/README delete mode 100644 examples/pdb/xml/TODO delete mode 100644 examples/pdb/xml/pdb_xml.c (limited to 'examples/pdb') diff --git a/examples/pdb/xml/ChangeLog b/examples/pdb/xml/ChangeLog deleted file mode 100644 index e44fa3bd30..0000000000 --- a/examples/pdb/xml/ChangeLog +++ /dev/null @@ -1,13 +0,0 @@ -** This file is now deprecated - use CVS' log features ** - -2002-06-13 Jelmer Vernooij - * Use SID's instead of RID's (just like samba-HEAD CVS) - * Released 1.1 - -2002-05-26 Jelmer Vernooij - * Update read support (didn't support all elements yet) - * Released 1.0 - -2002-05-26 Jelmer Vernooij - * Initial release - * Released 0.5 diff --git a/examples/pdb/xml/Makefile.in b/examples/pdb/xml/Makefile.in deleted file mode 100644 index 252641da6d..0000000000 --- a/examples/pdb/xml/Makefile.in +++ /dev/null @@ -1,31 +0,0 @@ -PDB_OBJS = pdb_xml.so -PDB_CFLAGS = `xml2-config --cflags` -PDB_LDFLAGS = `xml2-config --libs` - -CC = @CC@ -LIBTOOL = libtool -CFLAGS = @CFLAGS@ $(PDB_CFLAGS) -CPPFLAGS = @CPPFLAGS@ $(PDB_CPPFLAGS) -LDFLAGS = @LDFLAGS@ $(PDB_LDFLAGS) -LDSHFLAGS = -shared -srcdir = @builddir@ -FLAGS = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper -I. $(CPPFLAGS) -I$(srcdir) - -# Default target - -default: $(PDB_OBJS) - -# Pattern rules - -%.so: %.lo - $(LIBTOOL) $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< - -%.lo: %.c - $(LIBTOOL) $(CC) $(FLAGS) -c $< - -# Misc targets - -clean: - rm -rf .libs - rm -f core *~ *% *.bak \ - $(PDB_OBJS) $(PDB_OBJS:.so=.o) $(PDB_OBJS:.so=.lo) diff --git a/examples/pdb/xml/README b/examples/pdb/xml/README deleted file mode 100644 index afb08fdb4f..0000000000 --- a/examples/pdb/xml/README +++ /dev/null @@ -1,14 +0,0 @@ -Readme for samba pdb xml 0.5 --- -This module requires libxml2 to be installed. - -The usage of pdb_xml is pretty straightforward. To export data, use: - -pdbedit -e plugin:/usr/lib/samba/pdb_xml.so:filename - -(where filename is the name of the file to put the data in) -To import data, use: - -pdbedit -i plugin:/usr/lib/samba/pdb_xml.so:filename -e - -Where filename is the name to read the data from and to put it in. diff --git a/examples/pdb/xml/TODO b/examples/pdb/xml/TODO deleted file mode 100644 index 3947bb68be..0000000000 --- a/examples/pdb/xml/TODO +++ /dev/null @@ -1,6 +0,0 @@ -- Be faster. Don't rewrite the whole file when adding a user, but store - it in the memory and save it when exiting. Requires changes to samba source. - Gives the ability to read/write to standard input/output -- Do locking! -- Better names! -- Support stdin ? diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c deleted file mode 100644 index a8b26d6f5f..0000000000 --- a/examples/pdb/xml/pdb_xml.c +++ /dev/null @@ -1,554 +0,0 @@ - -/* - * XML password backend for samba - * Copyright (C) Jelmer Vernooij 2002 - * Some parts based on the libxml gjobread example by Daniel Veillard - * - * 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. - */ - -/* FIXME: Support stdin input by using '-' */ - -#define XML_URL "http://www.samba.org/ns" - -#include "includes.h" - -#include -#include - -static int xmlsam_debug_level = DBGC_ALL; - -#undef DBGC_CLASS -#define DBGC_CLASS xmlsam_debug_level - -PDB_MODULE_VERSIONING_MAGIC - -static char * iota(int a) { - static char tmp[10]; - - snprintf(tmp, 9, "%d", a); - return tmp; -} - -BOOL parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) -{ - pstring temp; - - cur = cur->xmlChildrenNode; - while (cur != NULL) { - if (strcmp(cur->name, "crypt")) - DEBUG(0, ("Unknown element %s\n", cur->name)); - else { - if (!strcmp(xmlGetProp(cur, "type"), "nt") - && - pdb_gethexpwd(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1), temp)) - pdb_set_nt_passwd(u, temp, PDB_SET); - else if (!strcmp(xmlGetProp(cur, "type"), "lanman") - && - pdb_gethexpwd(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1), temp)) - pdb_set_lanman_passwd(u, temp, PDB_SET); - else - DEBUG(0, - ("Unknown crypt type: %s\n", - xmlGetProp(cur, "type"))); - } - cur = cur->next; - } - return True; -} - -BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) -{ - char *tmp; - DOM_SID sid; - - tmp = xmlGetProp(cur, "sid"); - if (tmp){ - string_to_sid(&sid, tmp); - pdb_set_user_sid(u, &sid, PDB_SET); - } - tmp = xmlGetProp(cur, "uid"); - if (tmp) - pdb_set_uid(u, atol(tmp), PDB_SET); - pdb_set_username(u, xmlGetProp(cur, "name"), PDB_SET); - /* We don't care what the top level element name is */ - cur = cur->xmlChildrenNode; - while (cur != NULL) { - if ((!strcmp(cur->name, "group")) && (cur->ns == ns)) { - tmp = xmlGetProp(cur, "gid"); - if (tmp) - pdb_set_gid(u, atol(tmp), PDB_SET); - tmp = xmlGetProp(cur, "sid"); - if (tmp){ - string_to_sid(&sid, tmp); - pdb_set_group_sid(u, &sid, PDB_SET); - } - } - - else if ((!strcmp(cur->name, "domain")) && (cur->ns == ns)) - pdb_set_domain(u, - xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "fullname") && cur->ns == ns) - pdb_set_fullname(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "nt_username") && cur->ns == ns) - pdb_set_nt_username(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "logon_script") && cur->ns == ns) - pdb_set_logon_script(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "profile_path") && cur->ns == ns) - pdb_set_profile_path(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "logon_time") && cur->ns == ns) - pdb_set_logon_time(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), PDB_SET); - - else if (!strcmp(cur->name, "logoff_time") && cur->ns == ns) - pdb_set_logoff_time(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), - PDB_SET); - - else if (!strcmp(cur->name, "kickoff_time") && cur->ns == ns) - pdb_set_kickoff_time(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), - PDB_SET); - - else if (!strcmp(cur->name, "logon_divs") && cur->ns == ns) - pdb_set_logon_divs(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), PDB_SET); - - else if (!strcmp(cur->name, "hours_len") && cur->ns == ns) - pdb_set_hours_len(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), PDB_SET); - - else if (!strcmp(cur->name, "unknown_3") && cur->ns == ns) - pdb_set_unknown_3(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), PDB_SET); - - else if (!strcmp(cur->name, "unknown_5") && cur->ns == ns) - pdb_set_unknown_5(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), PDB_SET); - - else if (!strcmp(cur->name, "unknown_6") && cur->ns == ns) - pdb_set_unknown_6(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), PDB_SET); - - else if (!strcmp(cur->name, "homedir") && cur->ns == ns) - pdb_set_homedir(u, - xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "unknown_str") && cur->ns == ns) - pdb_set_unknown_str(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "dir_drive") && cur->ns == ns) - pdb_set_dir_drive(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "munged_dial") && cur->ns == ns) - pdb_set_munged_dial(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "acct_desc") && cur->ns == ns) - pdb_set_acct_desc(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), PDB_SET); - - else if (!strcmp(cur->name, "acct_ctrl") && cur->ns == ns) - pdb_set_acct_ctrl(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), PDB_SET); - - else if (!strcmp(cur->name, "workstations") && cur->ns == ns) - pdb_set_workstations(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), PDB_SET); - - else if ((!strcmp(cur->name, "password")) && (cur->ns == ns)) { - tmp = xmlGetProp(cur, "last_set"); - if (tmp) - pdb_set_pass_last_set_time(u, atol(tmp), PDB_SET); - tmp = xmlGetProp(cur, "must_change"); - if (tmp) - pdb_set_pass_must_change_time(u, atol(tmp), PDB_SET); - tmp = xmlGetProp(cur, "can_change"); - if (tmp) - pdb_set_pass_can_change_time(u, atol(tmp), PDB_SET); - parsePass(doc, ns, cur, u); - } - - else - DEBUG(0, ("Unknown element %s\n", cur->name)); - cur = cur->next; - } - - return True; -} - -typedef struct pdb_xml { - char *location; - char written; - xmlDocPtr doc; - xmlNodePtr users; - xmlNodePtr pwent; - xmlNsPtr ns; -} pdb_xml; - -xmlNodePtr parseSambaXMLFile(struct pdb_xml *data) -{ - xmlNodePtr cur; - - data->doc = xmlParseFile(data->location); - if (data->doc == NULL) - return NULL; - - cur = xmlDocGetRootElement(data->doc); - if (!cur) { - DEBUG(0, ("empty document\n")); - xmlFreeDoc(data->doc); - return NULL; - } - data->ns = xmlSearchNsByHref(data->doc, cur, XML_URL); - if (!data->ns) { - DEBUG(0, - ("document of the wrong type, samba user namespace not found\n")); - xmlFreeDoc(data->doc); - return NULL; - } - if (strcmp(cur->name, "samba")) { - DEBUG(0, ("document of the wrong type, root node != samba")); - xmlFreeDoc(data->doc); - return NULL; - } - - cur = cur->xmlChildrenNode; - while (cur && xmlIsBlankNode(cur)) { - cur = cur->next; - } - if (!cur) - return NULL; - if ((strcmp(cur->name, "users")) || (cur->ns != data->ns)) { - DEBUG(0, ("document of the wrong type, was '%s', users expected", - cur->name)); - DEBUG(0, ("xmlDocDump follows\n")); - xmlDocDump(stderr, data->doc); - DEBUG(0, ("xmlDocDump finished\n")); - xmlFreeDoc(data->doc); - return NULL; - } - data->users = cur; - cur = cur->xmlChildrenNode; - return cur; -} - -static NTSTATUS xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) -{ - pdb_xml *data; - - if (!methods) { - DEBUG(0, ("Invalid methods\n")); - return NT_STATUS_INVALID_PARAMETER; - } - data = (pdb_xml *) methods->private_data; - if (!data) { - DEBUG(0, ("Invalid pdb_xml_data\n")); - return NT_STATUS_INVALID_PARAMETER; - } - data->pwent = parseSambaXMLFile(data); - if (!data->pwent) - return NT_STATUS_UNSUCCESSFUL; - - return NT_STATUS_OK; -} - -/*************************************************************** - End enumeration of the passwd list. - ****************************************************************/ - -static void xmlsam_endsampwent(struct pdb_methods *methods) -{ - pdb_xml *data; - - if (!methods) { - DEBUG(0, ("Invalid methods\n")); - return; - } - - data = (pdb_xml *) methods->private_data; - - if (!data) { - DEBUG(0, ("Invalid pdb_xml_data\n")); - return; - } - - xmlFreeDoc(data->doc); - data->doc = NULL; - data->pwent = NULL; -} - -/***************************************************************** - Get one SAM_ACCOUNT from the list (next in line) - *****************************************************************/ - -static NTSTATUS xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) -{ - pdb_xml *data; - - if (!methods) { - DEBUG(0, ("Invalid methods\n")); - return NT_STATUS_INVALID_PARAMETER; - } - data = (pdb_xml *) methods->private_data; - - if (!data) { - DEBUG(0, ("Invalid pdb_xml_data\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - while (data->pwent) { - if ((!strcmp(data->pwent->name, "user")) && - (data->pwent->ns == data->ns)) { - - parseUser(data->doc, data->ns, data->pwent, user); - data->pwent = data->pwent->next; - return NT_STATUS_OK; - } - data->pwent = data->pwent->next; - } - return NT_STATUS_UNSUCCESSFUL; -} - -/*************************************************************************** - Adds an existing SAM_ACCOUNT - ****************************************************************************/ - -static NTSTATUS xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) -{ - pstring temp; - fstring sid_str; - xmlNodePtr cur, user, pass, root; - pdb_xml *data; - uint32 store = pdb_get_init_flag(u); - - DEBUG(10, ("xmlsam_add_sam_account called!\n")); - - if (!methods) { - DEBUG(0, ("Invalid methods\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - data = (pdb_xml *) methods->private_data; - if (!data) { - DEBUG(0, ("Invalid pdb_xml_data\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - /* Create a new document if we can't open the current one */ - if (!parseSambaXMLFile(data)) { - DEBUG(0, ("Can't load current XML file, creating a new one\n")); - data->doc = xmlNewDoc(XML_DEFAULT_VERSION); - root = xmlNewDocNode(data->doc, NULL, "samba", NULL); - cur = xmlDocSetRootElement(data->doc, root); - data->ns = xmlNewNs(root, XML_URL, "samba"); - data->users = xmlNewChild(root, data->ns, "users", NULL); - } - - user = xmlNewChild(data->users, data->ns, "user", NULL); - xmlNewProp(user, "sid", - sid_to_string(sid_str, pdb_get_user_sid(u))); - if (store & PDB_UID) - xmlNewProp(user, "uid", iota(pdb_get_uid(u))); - - if (pdb_get_username(u) && strcmp(pdb_get_username(u), "")) - xmlNewProp(user, "name", pdb_get_username(u)); - - cur = xmlNewChild(user, data->ns, "group", NULL); - - xmlNewProp(cur, "sid", - sid_to_string(sid_str, pdb_get_group_sid(u))); - if (store & PDB_GID) - xmlNewProp(cur, "gid", iota(pdb_get_gid(u))); - - if (store & PDB_LOGONTIME) - xmlNewChild(user, data->ns, "login_time", - iota(pdb_get_logon_time(u))); - - if (store & PDB_LOGOFFTIME) - xmlNewChild(user, data->ns, "logoff_time", - iota(pdb_get_logoff_time(u))); - - if (store & PDB_KICKOFFTIME) - xmlNewChild(user, data->ns, "kickoff_time", - iota(pdb_get_kickoff_time(u))); - - if (pdb_get_domain(u) && strcmp(pdb_get_domain(u), "")) - xmlNewChild(user, data->ns, "domain", pdb_get_domain(u)); - - if (pdb_get_nt_username(u) && strcmp(pdb_get_nt_username(u), "")) - xmlNewChild(user, data->ns, "nt_username", pdb_get_nt_username(u)); - - if (pdb_get_fullname(u) && strcmp(pdb_get_fullname(u), "")) - xmlNewChild(user, data->ns, "fullname", pdb_get_fullname(u)); - - if (pdb_get_homedir(u) && strcmp(pdb_get_homedir(u), "")) - xmlNewChild(user, data->ns, "homedir", pdb_get_homedir(u)); - - if (pdb_get_dir_drive(u) && strcmp(pdb_get_dir_drive(u), "")) - xmlNewChild(user, data->ns, "dir_drive", pdb_get_dir_drive(u)); - - if (pdb_get_logon_script(u) && strcmp(pdb_get_logon_script(u), "")) - xmlNewChild(user, data->ns, "logon_script", - pdb_get_logon_script(u)); - - if (pdb_get_profile_path(u) && strcmp(pdb_get_profile_path(u), "")) - xmlNewChild(user, data->ns, "profile_path", - pdb_get_profile_path(u)); - - if (pdb_get_acct_desc(u) && strcmp(pdb_get_acct_desc(u), "")) - xmlNewChild(user, data->ns, "acct_desc", pdb_get_acct_desc(u)); - - if (pdb_get_workstations(u) && strcmp(pdb_get_workstations(u), "")) - xmlNewChild(user, data->ns, "workstations", - pdb_get_workstations(u)); - - if (pdb_get_unknown_str(u) && strcmp(pdb_get_unknown_str(u), "")) - xmlNewChild(user, data->ns, "unknown_str", pdb_get_unknown_str(u)); - - if (pdb_get_munged_dial(u) && strcmp(pdb_get_munged_dial(u), "")) - xmlNewChild(user, data->ns, "munged_dial", pdb_get_munged_dial(u)); - - - /* Password stuff */ - pass = xmlNewChild(user, data->ns, "password", NULL); - if (pdb_get_pass_last_set_time(u)) - xmlNewProp(pass, "last_set", iota(pdb_get_pass_last_set_time(u))); - if (store & PDB_CANCHANGETIME) - xmlNewProp(pass, "can_change", - iota(pdb_get_pass_can_change_time(u))); - - if (store & PDB_MUSTCHANGETIME) - xmlNewProp(pass, "must_change", - iota(pdb_get_pass_must_change_time(u))); - - - if (pdb_get_lanman_passwd(u)) { - pdb_sethexpwd(temp, pdb_get_lanman_passwd(u), - pdb_get_acct_ctrl(u)); - cur = xmlNewChild(pass, data->ns, "crypt", temp); - xmlNewProp(cur, "type", "lanman"); - } - - if (pdb_get_nt_passwd(u)) { - pdb_sethexpwd(temp, pdb_get_nt_passwd(u), pdb_get_acct_ctrl(u)); - cur = xmlNewChild(pass, data->ns, "crypt", temp); - xmlNewProp(cur, "type", "nt"); - } - - xmlNewChild(user, data->ns, "acct_ctrl", iota(pdb_get_acct_ctrl(u))); - xmlNewChild(user, data->ns, "unknown_3", iota(pdb_get_unknown3(u))); - - if (pdb_get_logon_divs(u)) - xmlNewChild(user, data->ns, "logon_divs", - iota(pdb_get_logon_divs(u))); - - if (pdb_get_hours_len(u)) - xmlNewChild(user, data->ns, "hours_len", - iota(pdb_get_hours_len(u))); - - xmlNewChild(user, data->ns, "unknown_5", iota(pdb_get_unknown5(u))); - xmlNewChild(user, data->ns, "unknown_6", iota(pdb_get_unknown6(u))); - xmlSaveFile(data->location, data->doc); - - return NT_STATUS_OK; -} - -NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, - const char *location) -{ - NTSTATUS nt_status; - pdb_xml *data; - - xmlsam_debug_level = debug_add_class("xmlsam"); - if (xmlsam_debug_level == -1) { - xmlsam_debug_level = DBGC_ALL; - DEBUG(0, ("xmlsam: Couldn't register custom debugging class!\n")); - } - - if (!pdb_context) { - DEBUG(0, ("invalid pdb_methods specified\n")); - return NT_STATUS_UNSUCCESSFUL; - } - - if (!NT_STATUS_IS_OK - (nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { - return nt_status; - } - - (*pdb_method)->name = "xmlsam"; - - (*pdb_method)->setsampwent = xmlsam_setsampwent; - (*pdb_method)->endsampwent = xmlsam_endsampwent; - (*pdb_method)->getsampwent = xmlsam_getsampwent; - (*pdb_method)->add_sam_account = xmlsam_add_sam_account; - (*pdb_method)->getsampwnam = NULL; - (*pdb_method)->getsampwsid = NULL; - (*pdb_method)->update_sam_account = NULL; - (*pdb_method)->delete_sam_account = NULL; - - data = talloc(pdb_context->mem_ctx, sizeof(pdb_xml)); - data->location = - (location ? talloc_strdup(pdb_context->mem_ctx, location) : "-"); - data->pwent = NULL; - data->written = 0; - (*pdb_method)->private_data = data; - - LIBXML_TEST_VERSION xmlKeepBlanksDefault(0); - - return NT_STATUS_OK; -} -- cgit From c9bd108a81c2419ae5a5750d3eb1c253a7294fd9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 10 Nov 2002 12:07:54 +0000 Subject: Add example for MySQL (This used to be commit de136d294fce59bdc4d0a65d35071c2837ef92a5) --- examples/pdb/mysql/mysql.dump | 35 +++++++++++++++++++++++++++++++++++ examples/pdb/mysql/smb.conf | 11 +++++++++++ 2 files changed, 46 insertions(+) create mode 100644 examples/pdb/mysql/mysql.dump create mode 100644 examples/pdb/mysql/smb.conf (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/mysql.dump b/examples/pdb/mysql/mysql.dump new file mode 100644 index 0000000000..12eac6cdc7 --- /dev/null +++ b/examples/pdb/mysql/mysql.dump @@ -0,0 +1,35 @@ +# Put this in your MySQL database by running +# mysql -u -p -h < mysql.dump + +CREATE TABEL user ( + logon_time int(9), + logoff_time int(9), + kickoff_time int(9), + pass_last_set_time int(9), + pass_can_change_time int(9), + pass_must_change_time int(9), + username varchar(255), + domain varchar(255), + nt_username varchar(255), + nt_fullname varchar(255), + home_dir varchar(255), + dir_drive varchar(4), + logon_script varchar(255), + profile_path varchar(255), + acct_desc varchar(255), + workstations varchar(255), + unknown_str varchar(255), + munged_dial varchar(255), + uid int(9) NOT NULL DEFAULT "0" PRIMARY KEY auto_increment, + gid int(9), + user_sid varchar(255), + group_sid varchar(255), + lm_pw varchar(255), + nt_pw varchar(255), + acct_ctrl int(9), + unknown_3 int(9), + logon_divs int(9), + hours_len int(9), + unknown_5 int(9), + unknown_6 int(9) +); diff --git a/examples/pdb/mysql/smb.conf b/examples/pdb/mysql/smb.conf new file mode 100644 index 0000000000..61a3f19816 --- /dev/null +++ b/examples/pdb/mysql/smb.conf @@ -0,0 +1,11 @@ +[global] +netbios name = FOOBAR +workgroup = TESTGROUP +security = domain +domain logons = yes +domain master = yes +passdb backend = plugin:/usr/local/samba/lib/pdb_mysql.so:mysql +mysql:mysql host = rhonwyn +mysql:mysql user = samba +mysql:mysql password = ambas +mysql:mysql database = samba -- cgit From 289fe8557cf3300be42b30d44c88426fb16c0c1a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 10 Nov 2002 12:10:39 +0000 Subject: Sync with HEAD (This used to be commit b6359c585a563f9694d8afacd43329dece6af500) --- examples/pdb/mysql/ChangeLog | 41 -- examples/pdb/mysql/Makefile.in | 31 -- examples/pdb/mysql/README | 92 ---- examples/pdb/mysql/pdb_mysql.c | 975 ----------------------------------------- examples/pdb/xml/ChangeLog | 13 - examples/pdb/xml/Makefile.in | 31 -- examples/pdb/xml/README | 14 - examples/pdb/xml/TODO | 6 - examples/pdb/xml/pdb_xml.c | 554 ----------------------- 9 files changed, 1757 deletions(-) delete mode 100644 examples/pdb/mysql/ChangeLog delete mode 100644 examples/pdb/mysql/Makefile.in delete mode 100644 examples/pdb/mysql/README delete mode 100644 examples/pdb/mysql/pdb_mysql.c delete mode 100644 examples/pdb/xml/ChangeLog delete mode 100644 examples/pdb/xml/Makefile.in delete mode 100644 examples/pdb/xml/README delete mode 100644 examples/pdb/xml/TODO delete mode 100644 examples/pdb/xml/pdb_xml.c (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/ChangeLog b/examples/pdb/mysql/ChangeLog deleted file mode 100644 index 5aeeb66268..0000000000 --- a/examples/pdb/mysql/ChangeLog +++ /dev/null @@ -1,41 +0,0 @@ -** This file is now deprecated, use CVS' log featues ** - -2002-06-13 Jelmer Vernooij - * Converted to using SID's like samba HEAD does now - * Fixed some FIXME's - -2002-05-28 Jelmer Vernooij - * Updated docs, after some testing by Vance Lankhaar - -2002-05-25 Jelmer Vernooij - * Added support for dynamic debug classes - * Fixed nt/lanman password support - * Released 1.2 - -2002-05-06 Jelmer Vernooij - * Added support for multiple instances of pdb_mysql - * Added identifiers - * Updated documentation - * Released 1.1 - -2002-04-27 Jelmer Vernooij - * Updated documentation - * Released 1.0! - -2002-04-27 Jelmer Vernooij - * Added update/add sam account support - * Released 0.4 - -2002-04-13 Jelmer Vernooij - * Support for multiple instances of pdb_mysql - * Released 0.3 - -2002-04-12 Jelmer Vernooij - * Now using lp_parm_string to retrieve configuration values (instead of - our configuration files) - * Updated documentation - * Released 0.2 - -2002-04-10 Jelmer Vernooij - * Released 0.1 - * Initial release. Not supporting adding and updating data of users diff --git a/examples/pdb/mysql/Makefile.in b/examples/pdb/mysql/Makefile.in deleted file mode 100644 index 3ebecad762..0000000000 --- a/examples/pdb/mysql/Makefile.in +++ /dev/null @@ -1,31 +0,0 @@ -PDB_OBJS = pdb_mysql.so -PDB_LDFLAGS = -lmysqlclient -MAKEFILE = Makefile.pdb - -CC = @CC@ -LIBTOOL = libtool -CFLAGS = @CFLAGS@ $(PDB_CFLAGS) -CPPFLAGS = @CPPFLAGS@ $(PDB_CPPFLAGS) -LDFLAGS = @LDFLAGS@ $(PDB_LDFLAGS) -LDSHFLAGS = -shared -srcdir = @builddir@ -FLAGS = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper -I. $(CPPFLAGS) -I$(srcdir) - -# Default target - -default: $(PDB_OBJS) - -# Pattern rules - -%.so: %.lo - $(LIBTOOL) $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< - -%.lo: %.c - $(LIBTOOL) $(CC) $(FLAGS) -c $< - -# Misc targets - -clean: - rm -rf .libs - rm -f core *~ *% *.bak \ - $(PDB_OBJS) $(PDB_OBJS:.so=.o) $(PDB_OBJS:.so=.lo) diff --git a/examples/pdb/mysql/README b/examples/pdb/mysql/README deleted file mode 100644 index e3cbcab8cf..0000000000 --- a/examples/pdb/mysql/README +++ /dev/null @@ -1,92 +0,0 @@ -PDB MySQL plugin for samba v1.1 --- - -Building -========= -Before you can build the plugin, set the variable SAMBA_SRC in Makefile to the -path containing the samba sources. This is usually the 'source' directory in -the samba tarball or CVS. - -Next, type make, and then copy pdb_mysql.so to any location you want. I -strongly recommend installing it in $PREFIX/lib or /usr/lib/samba/ - -Configuring -============ -This plugin lacks some good documentation, but here is some short info: - -Add a the following to the 'passdb backend' variable in your smb.conf: - -passdb backend = [other-plugins] plugin:/location/to/pdb_mysql.so:identifier [other-plugins] - -The identifier can be any string you like, as long as it doesn't collide with -the identifiers of other plugins or other instances of pdb_mysql. If you -specify multiple pdb_mysql.so entries in 'passdb backend', you also need to -use different identifiers! - -Additional options can be given thru the smb.conf file in the [global] section. - -identifier:mysql host - host name, defaults to 'localhost' -identifier:mysql password -identifier:mysql user - defaults to 'samba' -identifier:mysql database - defaults to 'samba' -identifier:mysql port - defaults to 3306 -identifier:table - Name of the table containing users - -Names of the columns in this table(I've added column types those columns - should have first): -identifier:logon time column - int(9) -identifier:logoff time column - int(9) -identifier:kickoff time column - int(9) -identifier:pass last set time column - int(9) -identifier:pass can change time column - int(9) -identifier:pass must change time column - int(9) -identifier:username column - varchar(255) - unix username -identifier:domain column - varchar(255) - NT domain user is part of -identifier:nt username column - varchar(255) - NT username -identifier:fullname column - varchar(255) - Full name of user -identifier:home dir column - varchar(255) - Unix homedir path -identifier:dir drive column - varchar(2) - Directory drive path (eg: 'H:') -identifier:logon script column - varchar(255) - Batch file to run on client side when logging on -identifier:profile path column - varchar(255) - Path of profile -identifier:acct desc column - varchar(255) - Some ASCII NT user data -identifier:workstations column - varchar(255) - Workstations user can logon to (or NULL for all) -identifier:unknown string column - varchar(255) - unknown string -identifier:munged dial column - varchar(255) - ? -identifier:uid column - int(9) - Unix user ID (uid) -identifier:gid column - int(9) - Unix user group (gid) -identifier:user sid column - varchar(255) - NT user SID -identifier:group sid column - varchar(255) - NT group ID -identifier:lanman pass column - varchar(255) - encrypted lanman password -identifier:nt pass column - varchar(255) - encrypted nt passwd -identifier:plaintext pass column - varchar(255) - plaintext password -identifier:acct control column - int(9) - nt user data -identifier:unknown 3 column - int(9) - unknown -identifier:logon divs column - int(9) - ? -identifier:hours len column - int(9) - ? -identifier:unknown 5 column - int(9) - unknown -identifier:unknown 6 column - int(9) - unknown - -Eventually, you can put a colon (:) after the name of each column, which -should specify the column to update when updating the table. You can also -specify nothing behind the colon - then the data from the field will not be -updated. - -Using plaintext passwords or encrypted password -=============================================== -I strongly discourage the use of plaintext passwords, however, you can use them: - -If you would like to use plaintext passwords, set 'identifier:lanman pass column' and 'identifier:nt pass column' to 'NULL' (without the quotes) and 'identifier:plaintext pass column' to the name of the column containing the plaintext passwords. - -If you use encrypted passwords, set the 'identifier:plaintext pass column' to 'NULL' (without the quotes). This is the default. - -Getting non-column data from the table -====================================== -It is possible to have not all data in the database and making some 'constant'. - -For example, you can set 'identifier:fullname column' to : - CONCAT(First_name,' ',Sur_name) - -Or, set 'identifier:workstations column' to : - NULL - -See the MySQL documentation for more language constructs. diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c deleted file mode 100644 index c73d3716fe..0000000000 --- a/examples/pdb/mysql/pdb_mysql.c +++ /dev/null @@ -1,975 +0,0 @@ - -/* - * MySQL password backend for samba - * Copyright (C) Jelmer Vernooij 2002 - * - * 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" -#include - -#define CONFIG_TABLE_DEFAULT "user" -#define CONFIG_LOGON_TIME_DEFAULT "logon_time" -#define CONFIG_LOGOFF_TIME_DEFAULT "logoff_time" -#define CONFIG_KICKOFF_TIME_DEFAULT "kickoff_time" -#define CONFIG_PASS_LAST_SET_TIME_DEFAULT "pass_last_set_time" -#define CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT "pass_can_change_time" -#define CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT "pass_must_change_time" -#define CONFIG_USERNAME_DEFAULT "username" -#define CONFIG_DOMAIN_DEFAULT "domain" -#define CONFIG_NT_USERNAME_DEFAULT "nt_username" -#define CONFIG_FULLNAME_DEFAULT "nt_fullname" -#define CONFIG_HOME_DIR_DEFAULT "home_dir" -#define CONFIG_DIR_DRIVE_DEFAULT "dir_drive" -#define CONFIG_LOGON_SCRIPT_DEFAULT "logon_script" -#define CONFIG_PROFILE_PATH_DEFAULT "profile_path" -#define CONFIG_ACCT_DESC_DEFAULT "acct_desc" -#define CONFIG_WORKSTATIONS_DEFAULT "workstations" -#define CONFIG_UNKNOWN_STR_DEFAULT "unknown_str" -#define CONFIG_MUNGED_DIAL_DEFAULT "munged_dial" -#define CONFIG_UID_DEFAULT "uid" -#define CONFIG_GID_DEFAULT "gid" -#define CONFIG_USER_SID_DEFAULT "user_sid" -#define CONFIG_GROUP_SID_DEFAULT "group_sid" -#define CONFIG_LM_PW_DEFAULT "lm_pw" -#define CONFIG_NT_PW_DEFAULT "nt_pw" -#define CONFIG_PLAIN_PW_DEFAULT "NULL" -#define CONFIG_ACCT_CTRL_DEFAULT "acct_ctrl" -#define CONFIG_UNKNOWN_3_DEFAULT "unknown_3" -#define CONFIG_LOGON_DIVS_DEFAULT "logon_divs" -#define CONFIG_HOURS_LEN_DEFAULT "hours_len" -#define CONFIG_UNKNOWN_5_DEFAULT "unknown_5" -#define CONFIG_UNKNOWN_6_DEFAULT "unknown_6" -#define CONFIG_HOST_DEFAULT "localhost" -#define CONFIG_USER_DEFAULT "samba" -#define CONFIG_PASS_DEFAULT "" -#define CONFIG_PORT_DEFAULT "3306" -#define CONFIG_DB_DEFAULT "samba" - -static int mysqlsam_debug_level = DBGC_ALL; - -#undef DBGC_CLASS -#define DBGC_CLASS mysqlsam_debug_level - -PDB_MODULE_VERSIONING_MAGIC - -typedef struct pdb_mysql_data { - MYSQL *handle; - MYSQL_RES *pwent; - char *location; -} pdb_mysql_data; - -/* Used to construct insert and update queries */ - -typedef struct pdb_mysql_query { - char update; - TALLOC_CTX *mem_ctx; - char *part1; - char *part2; -} pdb_mysql_query; -#define SET_DATA(data,methods) { \ - if(!methods){ \ - DEBUG(0, ("invalid methods!\n")); \ - return NT_STATUS_INVALID_PARAMETER; \ - } \ - data = (struct pdb_mysql_data *)methods->private_data; \ - if(!data || !(data->handle)){ \ - DEBUG(0, ("invalid handle!\n")); \ - return NT_STATUS_INVALID_HANDLE; \ - } \ -} - -static void pdb_mysql_int_field(struct pdb_methods *m, - struct pdb_mysql_query *q, char *name, int value) -{ - if (!name || strchr(name, '\'')) - return; /* This field shouldn't be set by us */ - - if (q->update) { - q->part1 = - talloc_asprintf_append(q->mem_ctx, q->part1, - "%s = %d,", name, value); - } else { - q->part1 = - talloc_asprintf_append(q->mem_ctx, q->part1, "%s,", name); - q->part2 = - talloc_asprintf_append(q->mem_ctx, q->part2, "%d,", value); - } -} - -static NTSTATUS pdb_mysql_string_field(struct pdb_methods *methods, - struct pdb_mysql_query *q, - char *name, const char *value) -{ - char *esc_value; - struct pdb_mysql_data *data; - char *tmp_value; - - SET_DATA(data, methods); - - if (!name || !value || !strcmp(value, "") || strchr(name, '\'')) - return NT_STATUS_INVALID_PARAMETER; /* This field shouldn't be set by module */ - - esc_value = malloc(strlen(value) * 2 + 1); - - tmp_value = smb_xstrdup(value); - mysql_real_escape_string(data->handle, esc_value, tmp_value, - strlen(tmp_value)); - SAFE_FREE(tmp_value); - - if (q->update) { - q->part1 = - talloc_asprintf_append(q->mem_ctx, q->part1, - "%s = '%s',", name, esc_value); - } else { - q->part1 = - talloc_asprintf_append(q->mem_ctx, q->part1, "%s,", name); - q->part2 = - talloc_asprintf_append(q->mem_ctx, q->part2, "'%s',", - esc_value); - } - - SAFE_FREE(esc_value); - - return NT_STATUS_OK; -} - -static char * config_value(pdb_mysql_data * data, char *name, char *default_value) -{ - if (lp_parm_string(NULL, data->location, name)) - return lp_parm_string(NULL, data->location, name); - - return default_value; -} - -static char * config_value_write(pdb_mysql_data * data, char *name, char *default_value) { - char *v = config_value(data, name, NULL); - char *swrite; - - if (!v) - return default_value; - - swrite = strchr(v, ':'); - - /* Default to the same field as read field */ - if (!swrite) - return v; - - swrite++; - - /* If the field is 0 chars long, we shouldn't write to it */ - if (!strlen(swrite) || !strcmp(swrite, "NULL")) - return NULL; - - /* Otherwise, use the additionally specified */ - return swrite; -} - -static const char * config_value_read(pdb_mysql_data * data, char *name, char *default_value) -{ - char *v = config_value(data, name, NULL); - char *swrite; - - if (!v) - return default_value; - - swrite = strchr(v, ':'); - - /* If no write is specified, there are no problems */ - if (!swrite) { - if (strlen(v) == 0) - return "NULL"; - return v; - } - - /* Otherwise, we have to cut the ':write_part' */ - *swrite = '\0'; - if (strlen(v) == 0) - return "NULL"; - - return v; -} - -/* Wrapper for atol that returns 0 if 'a' points to NULL */ -static long xatol(char *a) -{ - long ret = 0; - - if (a != NULL) - ret = atol(a); - - return ret; -} - -static NTSTATUS row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) -{ - MYSQL_ROW row; - pstring temp; - unsigned int num_fields; - DOM_SID sid; - - num_fields = mysql_num_fields(r); - row = mysql_fetch_row(r); - if (!row) - return NT_STATUS_INVALID_PARAMETER; - - pdb_set_logon_time(u, xatol(row[0]), FALSE); - pdb_set_logoff_time(u, xatol(row[1]), FALSE); - pdb_set_kickoff_time(u, xatol(row[2]), FALSE); - pdb_set_pass_last_set_time(u, xatol(row[3])); - pdb_set_pass_can_change_time(u, xatol(row[4]), FALSE); - pdb_set_pass_must_change_time(u, xatol(row[5]), FALSE); - pdb_set_username(u, row[6]); - pdb_set_domain(u, row[7]); - pdb_set_nt_username(u, row[8]); - pdb_set_fullname(u, row[9]); - pdb_set_homedir(u, row[10], True); - pdb_set_dir_drive(u, row[11], True); - pdb_set_logon_script(u, row[12], True); - pdb_set_profile_path(u, row[13], True); - pdb_set_acct_desc(u, row[14]); - pdb_set_workstations(u, row[15]); - pdb_set_unknown_str(u, row[16]); - pdb_set_munged_dial(u, row[17]); - - if (row[18]) - pdb_set_uid(u, xatol(row[18])); - if (row[19]) - pdb_set_gid(u, xatol(row[19])); - - string_to_sid(&sid, row[20]); - pdb_set_user_sid(u, &sid); - string_to_sid(&sid, row[21]); - pdb_set_group_sid(u, &sid); - - if (pdb_gethexpwd(row[22], temp)) - pdb_set_lanman_passwd(u, temp); - if (pdb_gethexpwd(row[23], temp)) - pdb_set_nt_passwd(u, temp); - - /* Only use plaintext password storage when lanman and nt are - * NOT used */ - if (!row[22] || !row[23]) - pdb_set_plaintext_passwd(u, row[24]); - - pdb_set_acct_ctrl(u, xatol(row[25])); - pdb_set_unknown_3(u, xatol(row[26])); - pdb_set_logon_divs(u, xatol(row[27])); - pdb_set_hours_len(u, xatol(row[28])); - pdb_set_unknown_5(u, xatol(row[29])); - pdb_set_unknown_6(u, xatol(row[30])); - - return NT_STATUS_OK; -} - -static NTSTATUS mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) -{ - struct pdb_mysql_data *data = - (struct pdb_mysql_data *) methods->private_data; - char *query; - int ret; - - if (!data || !(data->handle)) { - DEBUG(0, ("invalid handle!\n")); - return NT_STATUS_INVALID_HANDLE; - } - - asprintf(&query, - "SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s", - config_value_read(data, "logon time column", - CONFIG_LOGON_TIME_DEFAULT), - config_value_read(data, "logoff time column", - CONFIG_LOGOFF_TIME_DEFAULT), - config_value_read(data, "kickoff time column", - CONFIG_KICKOFF_TIME_DEFAULT), - config_value_read(data, "pass last set time column", - CONFIG_PASS_LAST_SET_TIME_DEFAULT), - config_value_read(data, "pass can change time column", - CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT), - config_value_read(data, "pass must change time column", - CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT), - config_value_read(data, "username column", - CONFIG_USERNAME_DEFAULT), - config_value_read(data, "domain column", - CONFIG_DOMAIN_DEFAULT), - config_value_read(data, "nt username column", - CONFIG_NT_USERNAME_DEFAULT), - config_value_read(data, "fullname column", - CONFIG_FULLNAME_DEFAULT), - config_value_read(data, "home dir column", - CONFIG_HOME_DIR_DEFAULT), - config_value_read(data, "dir drive column", - CONFIG_DIR_DRIVE_DEFAULT), - config_value_read(data, "logon script column", - CONFIG_LOGON_SCRIPT_DEFAULT), - config_value_read(data, "profile path column", - CONFIG_PROFILE_PATH_DEFAULT), - config_value_read(data, "acct desc column", - CONFIG_ACCT_DESC_DEFAULT), - config_value_read(data, "workstations column", - CONFIG_WORKSTATIONS_DEFAULT), - config_value_read(data, "unknown string column", - CONFIG_UNKNOWN_STR_DEFAULT), - config_value_read(data, "munged dial column", - CONFIG_MUNGED_DIAL_DEFAULT), - config_value_read(data, "uid column", CONFIG_UID_DEFAULT), - config_value_read(data, "gid column", CONFIG_GID_DEFAULT), - config_value_read(data, "user sid column", - CONFIG_USER_SID_DEFAULT), - config_value_read(data, "group sid column", - CONFIG_GROUP_SID_DEFAULT), - config_value_read(data, "lanman pass column", - CONFIG_LM_PW_DEFAULT), - config_value_read(data, "nt pass column", - CONFIG_NT_PW_DEFAULT), - config_value_read(data, "plain pass column", - CONFIG_PLAIN_PW_DEFAULT), - config_value_read(data, "acct ctrl column", - CONFIG_ACCT_CTRL_DEFAULT), - config_value_read(data, "unknown 3 column", - CONFIG_UNKNOWN_3_DEFAULT), - config_value_read(data, "logon divs column", - CONFIG_LOGON_DIVS_DEFAULT), - config_value_read(data, "hours len column", - CONFIG_HOURS_LEN_DEFAULT), - config_value_read(data, "unknown 5 column", - CONFIG_UNKNOWN_5_DEFAULT), - config_value_read(data, "unknown 6 column", - CONFIG_UNKNOWN_6_DEFAULT), - config_value(data, "table", CONFIG_TABLE_DEFAULT) - ); - - ret = mysql_query(data->handle, query); - SAFE_FREE(query); - - if (ret) { - DEBUG(0, - ("Error executing query: %s\n", mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - data->pwent = mysql_store_result(data->handle); - - if (data->pwent == NULL) { - DEBUG(0, - ("Error storing results: %s\n", mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - DEBUG(5, - ("mysqlsam_setsampwent succeeded(%d results)!\n", - mysql_num_fields(data->pwent))); - - return NT_STATUS_OK; -} - -/*************************************************************** - End enumeration of the passwd list. - ****************************************************************/ - -static void mysqlsam_endsampwent(struct pdb_methods *methods) -{ - struct pdb_mysql_data *data = - (struct pdb_mysql_data *) methods->private_data; - - if (data == NULL) { - DEBUG(0, ("invalid handle!\n")); - return; - } - - if (data->pwent != NULL) - mysql_free_result(data->pwent); - - data->pwent = NULL; - - DEBUG(5, ("mysql_endsampwent called\n")); -} - -/***************************************************************** - Get one SAM_ACCOUNT from the list (next in line) - *****************************************************************/ - -static NTSTATUS mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) -{ - struct pdb_mysql_data *data; - - SET_DATA(data, methods); - - if (data->pwent == NULL) { - DEBUG(0, ("invalid pwent\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - return row_to_sam_account(data->pwent, user); -} - -static NTSTATUS mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, - const char *field, const char *sname) -{ - char *esc_sname; - char *query; - NTSTATUS ret; - MYSQL_RES *res; - int mysql_ret; - struct pdb_mysql_data *data; - char *tmp_sname; - - SET_DATA(data, methods); - - esc_sname = malloc(strlen(sname) * 2 + 1); - if (!esc_sname) { - return NT_STATUS_NO_MEMORY; - } - - DEBUG(5, - ("mysqlsam_select_by_field: getting data where %s = %s(nonescaped)\n", - field, sname)); - - tmp_sname = smb_xstrdup(sname); - - /* Escape sname */ - mysql_real_escape_string(data->handle, esc_sname, tmp_sname, - strlen(tmp_sname)); - - SAFE_FREE(tmp_sname); - - if (user == NULL) { - DEBUG(0, ("pdb_getsampwnam: SAM_ACCOUNT is NULL.\n")); - SAFE_FREE(esc_sname); - return NT_STATUS_INVALID_PARAMETER; - } - - asprintf(&query, - "SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s WHERE %s = '%s'", - config_value_read(data, "logon time column", - CONFIG_LOGON_TIME_DEFAULT), - config_value_read(data, "logoff time column", - CONFIG_LOGOFF_TIME_DEFAULT), - config_value_read(data, "kickoff time column", - CONFIG_KICKOFF_TIME_DEFAULT), - config_value_read(data, "pass last set time column", - CONFIG_PASS_LAST_SET_TIME_DEFAULT), - config_value_read(data, "pass can change time column", - CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT), - config_value_read(data, "pass must change time column", - CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT), - config_value_read(data, "username column", - CONFIG_USERNAME_DEFAULT), - config_value_read(data, "domain column", - CONFIG_DOMAIN_DEFAULT), - config_value_read(data, "nt username column", - CONFIG_NT_USERNAME_DEFAULT), - config_value_read(data, "fullname column", - CONFIG_FULLNAME_DEFAULT), - config_value_read(data, "home dir column", - CONFIG_HOME_DIR_DEFAULT), - config_value_read(data, "dir drive column", - CONFIG_DIR_DRIVE_DEFAULT), - config_value_read(data, "logon script column", - CONFIG_LOGON_SCRIPT_DEFAULT), - config_value_read(data, "profile path column", - CONFIG_PROFILE_PATH_DEFAULT), - config_value_read(data, "acct desc column", - CONFIG_ACCT_DESC_DEFAULT), - config_value_read(data, "workstations column", - CONFIG_WORKSTATIONS_DEFAULT), - config_value_read(data, "unknown string column", - CONFIG_UNKNOWN_STR_DEFAULT), - config_value_read(data, "munged dial column", - CONFIG_MUNGED_DIAL_DEFAULT), - config_value_read(data, "uid column", CONFIG_UID_DEFAULT), - config_value_read(data, "gid column", CONFIG_GID_DEFAULT), - config_value_read(data, "user sid column", - CONFIG_USER_SID_DEFAULT), - config_value_read(data, "group sid column", - CONFIG_GROUP_SID_DEFAULT), - config_value_read(data, "lanman pass column", - CONFIG_LM_PW_DEFAULT), - config_value_read(data, "nt pass column", - CONFIG_NT_PW_DEFAULT), - config_value_read(data, "plain pass column", - CONFIG_PLAIN_PW_DEFAULT), - config_value_read(data, "acct ctrl column", - CONFIG_ACCT_CTRL_DEFAULT), - config_value_read(data, "unknown 3 column", - CONFIG_UNKNOWN_3_DEFAULT), - config_value_read(data, "logon divs column", - CONFIG_LOGON_DIVS_DEFAULT), - config_value_read(data, "hours len column", - CONFIG_HOURS_LEN_DEFAULT), - config_value_read(data, "unknown 5 column", - CONFIG_UNKNOWN_5_DEFAULT), - config_value_read(data, "unknown 6 column", - CONFIG_UNKNOWN_6_DEFAULT), - config_value(data, "table", CONFIG_TABLE_DEFAULT), field, - esc_sname); - - SAFE_FREE(esc_sname); - - mysql_ret = mysql_query(data->handle, query); - - SAFE_FREE(query); - - if (mysql_ret) { - DEBUG(0, - ("Error while executing MySQL query: %s\n", - mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - res = mysql_store_result(data->handle); - if (res == NULL) { - DEBUG(0, - ("Error storing results: %s\n", mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - ret = row_to_sam_account(res, user); - mysql_free_result(res); - - return ret; -} - -/****************************************************************** - Lookup a name in the SAM database - ******************************************************************/ - -static NTSTATUS mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, - const char *sname) -{ - struct pdb_mysql_data *data; - - SET_DATA(data, methods); - - if (!sname) { - DEBUG(0, ("invalid name specified")); - return NT_STATUS_INVALID_PARAMETER; - } - - return mysqlsam_select_by_field(methods, user, - config_value_read(data, "username column", - CONFIG_USERNAME_DEFAULT), sname); -} - - -/*************************************************************************** - Search by sid - **************************************************************************/ - -static NTSTATUS mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, - const DOM_SID * sid) -{ - struct pdb_mysql_data *data; - fstring sid_str; - - SET_DATA(data, methods); - - sid_to_string(sid_str, sid); - - return mysqlsam_select_by_field(methods, user, - config_value_read(data, "user sid column", - CONFIG_USER_SID_DEFAULT), sid_str); -} - -/*************************************************************************** - Delete a SAM_ACCOUNT - ****************************************************************************/ - -static NTSTATUS mysqlsam_delete_sam_account(struct pdb_methods *methods, - SAM_ACCOUNT * sam_pass) -{ - const char *sname = pdb_get_username(sam_pass); - char *esc; - char *query; - int ret; - struct pdb_mysql_data *data; - char *tmp_sname; - - SET_DATA(data, methods); - - if (!methods) { - DEBUG(0, ("invalid methods!\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - data = (struct pdb_mysql_data *) methods->private_data; - if (!data || !(data->handle)) { - DEBUG(0, ("invalid handle!\n")); - return NT_STATUS_INVALID_HANDLE; - } - - if (!sname) { - DEBUG(0, ("invalid name specified\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - /* Escape sname */ - esc = malloc(strlen(sname) * 2 + 1); - if (!esc) { - DEBUG(0, ("Can't allocate memory to store escaped name\n")); - return NT_STATUS_NO_MEMORY; - } - - tmp_sname = smb_xstrdup(sname); - - mysql_real_escape_string(data->handle, esc, tmp_sname, - strlen(tmp_sname)); - - SAFE_FREE(tmp_sname); - - asprintf(&query, "DELETE FROM %s WHERE %s = '%s'", - config_value(data, "table", CONFIG_TABLE_DEFAULT), - config_value_read(data, "username column", - CONFIG_USERNAME_DEFAULT), esc); - - SAFE_FREE(esc); - - ret = mysql_query(data->handle, query); - - SAFE_FREE(query); - - if (ret) { - DEBUG(0, - ("Error while executing query: %s\n", - mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - DEBUG(5, ("User '%s' deleted\n", sname)); - return NT_STATUS_OK; -} - -static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods, - const SAM_ACCOUNT * newpwd, char isupdate) -{ - pstring temp; - uint32 store = pdb_get_init_flag(newpwd); - struct pdb_mysql_data *data; - pdb_mysql_query query; - fstring sid_str; - - if (!methods) { - DEBUG(0, ("invalid methods!\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - data = (struct pdb_mysql_data *) methods->private_data; - if (data == NULL || data->handle == NULL) { - DEBUG(0, ("invalid handle!\n")); - return NT_STATUS_INVALID_HANDLE; - } - query.update = isupdate; - - /* I know this is somewhat overkill but only the talloc - * functions have asprint_append and the 'normal' asprintf - * is a GNU extension */ - query.mem_ctx = talloc_init(); - query.part2 = talloc_asprintf(query.mem_ctx, "%s", ""); - if (query.update) { - query.part1 = - talloc_asprintf(query.mem_ctx, "UPDATE %s SET ", - config_value(data, "table", - CONFIG_TABLE_DEFAULT)); - } else { - query.part1 = - talloc_asprintf(query.mem_ctx, "INSERT INTO %s (", - config_value(data, "table", - CONFIG_TABLE_DEFAULT)); - } - - pdb_mysql_int_field(methods, &query, - config_value_write(data, "acct ctrl column", - CONFIG_ACCT_CTRL_DEFAULT), - pdb_get_acct_ctrl(newpwd)); - - if (store & FLAG_SAM_LOGONTIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "logon time column", - CONFIG_LOGON_TIME_DEFAULT), - pdb_get_logon_time(newpwd)); - } - - if (store & FLAG_SAM_LOGOFFTIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "logoff time column", - CONFIG_LOGOFF_TIME_DEFAULT), - pdb_get_logoff_time(newpwd)); - } - - if (store & FLAG_SAM_KICKOFFTIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "kickoff time column", - CONFIG_KICKOFF_TIME_DEFAULT), - pdb_get_kickoff_time(newpwd)); - } - - if (store & FLAG_SAM_CANCHANGETIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "pass can change time column", - CONFIG_PASS_CAN_CHANGE_TIME_DEFAULT), - pdb_get_pass_can_change_time(newpwd)); - } - - if (store & FLAG_SAM_MUSTCHANGETIME) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "pass must change time column", - CONFIG_PASS_MUST_CHANGE_TIME_DEFAULT), - pdb_get_pass_must_change_time(newpwd)); - } - - if (pdb_get_pass_last_set_time(newpwd)) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "pass must change time column", - CONFIG_PASS_LAST_SET_TIME_DEFAULT), - pdb_get_pass_last_set_time(newpwd)); - } - - if (pdb_get_hours_len(newpwd)) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "hours len column", - CONFIG_HOURS_LEN_DEFAULT), - pdb_get_hours_len(newpwd)); - } - - if (pdb_get_logon_divs(newpwd)) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, - "logon divs column", - CONFIG_LOGON_DIVS_DEFAULT), - pdb_get_logon_divs(newpwd)); - } - - if (store & FLAG_SAM_UID) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, "uid column", - CONFIG_UID_DEFAULT), - pdb_get_uid(newpwd)); - } - - if (store & FLAG_SAM_GID) { - pdb_mysql_int_field(methods, &query, - config_value_write(data, "gid column", - CONFIG_GID_DEFAULT), - pdb_get_gid(newpwd)); - } - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "user sid column", - CONFIG_USER_SID_DEFAULT), - sid_to_string(sid_str, (DOM_SID *) - pdb_get_user_sid(newpwd))); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "group sid column", - CONFIG_GROUP_SID_DEFAULT), - sid_to_string(sid_str, (DOM_SID *) - pdb_get_group_sid(newpwd))); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "username column", - CONFIG_USERNAME_DEFAULT), - pdb_get_username(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "domain column", - CONFIG_DOMAIN_DEFAULT), - pdb_get_domain(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "nt username column", - CONFIG_NT_USERNAME_DEFAULT), - pdb_get_nt_username(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "fullname column", - CONFIG_FULLNAME_DEFAULT), - pdb_get_fullname(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "logon script column", - CONFIG_LOGON_SCRIPT_DEFAULT), - pdb_get_logon_script(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "profile path column", - CONFIG_PROFILE_PATH_DEFAULT), - pdb_get_profile_path(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "dir drive column", - CONFIG_DIR_DRIVE_DEFAULT), - pdb_get_dir_drive(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, "home dir column", - CONFIG_HOME_DIR_DEFAULT), - pdb_get_homedir(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "workstations column", - CONFIG_WORKSTATIONS_DEFAULT), - pdb_get_workstations(newpwd)); - - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "unknown string column", - CONFIG_UNKNOWN_STR_DEFAULT), - pdb_get_workstations(newpwd)); - - pdb_sethexpwd(temp, pdb_get_lanman_passwd(newpwd), - pdb_get_acct_ctrl(newpwd)); - pdb_mysql_string_field(methods, &query, - config_value_write(data, - "lanman pass column", - CONFIG_LM_PW_DEFAULT), temp); - - pdb_sethexpwd(temp, pdb_get_nt_passwd(newpwd), - pdb_get_acct_ctrl(newpwd)); - pdb_mysql_string_field(methods, &query, - config_value_write(data, "nt pass column", - CONFIG_NT_PW_DEFAULT), temp); - - if (query.update) { - query.part1[strlen(query.part1) - 1] = '\0'; - query.part1 = - talloc_asprintf_append(query.mem_ctx, query.part1, - " WHERE %s = '%s'", - config_value_read(data, - "user sid column", - CONFIG_USER_SID_DEFAULT), - sid_to_string(sid_str, (DOM_SID *) - pdb_get_user_sid - (newpwd))); - } else { - query.part2[strlen(query.part2) - 1] = ')'; - query.part1[strlen(query.part1) - 1] = ')'; - query.part1 = - talloc_asprintf_append(query.mem_ctx, query.part1, - " VALUES (%s", query.part2); - } - - DEBUG(0, ("%s\n", query.part1)); - /* Execute the query */ - if (mysql_query(data->handle, query.part1)) { - DEBUG(0, - ("Error executing %s, %s\n", query.part1, - mysql_error(data->handle))); - return NT_STATUS_INVALID_PARAMETER; - } - talloc_destroy(query.mem_ctx); - return NT_STATUS_OK; -} - -static NTSTATUS mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) -{ - return mysqlsam_replace_sam_account(methods, newpwd, 0); -} - -static NTSTATUS mysqlsam_update_sam_account(struct pdb_methods *methods, - SAM_ACCOUNT * newpwd) -{ - return mysqlsam_replace_sam_account(methods, newpwd, 1); -} - -NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, - char *location) -{ - NTSTATUS nt_status; - struct pdb_mysql_data *data; - - mysqlsam_debug_level = debug_add_class("mysqlsam"); - if (mysqlsam_debug_level == -1) { - mysqlsam_debug_level = DBGC_ALL; - DEBUG(0, - ("mysqlsam: Couldn't register custom debugging class!\n")); - } - - if (!pdb_context) { - DEBUG(0, ("invalid pdb_methods specified\n")); - return NT_STATUS_UNSUCCESSFUL; - } - - if (!NT_STATUS_IS_OK - (nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { - return nt_status; - } - - (*pdb_method)->name = "mysqlsam"; - - (*pdb_method)->setsampwent = mysqlsam_setsampwent; - (*pdb_method)->endsampwent = mysqlsam_endsampwent; - (*pdb_method)->getsampwent = mysqlsam_getsampwent; - (*pdb_method)->getsampwnam = mysqlsam_getsampwnam; - (*pdb_method)->getsampwsid = mysqlsam_getsampwsid; - (*pdb_method)->add_sam_account = mysqlsam_add_sam_account; - (*pdb_method)->update_sam_account = mysqlsam_update_sam_account; - (*pdb_method)->delete_sam_account = mysqlsam_delete_sam_account; - - data = talloc(pdb_context->mem_ctx, sizeof(struct pdb_mysql_data)); - (*pdb_method)->private_data = data; - data->handle = NULL; - data->pwent = NULL; - - if (!location) { - DEBUG(0, ("No identifier specified. See README for details\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - data->location = smb_xstrdup(location); - - DEBUG(1, - ("Connecting to database server, host: %s, user: %s, password: %s, database: %s, port: %ld\n", - config_value(data, "mysql host", CONFIG_HOST_DEFAULT), - config_value(data, "mysql user", CONFIG_USER_DEFAULT), - config_value(data, "mysql password", CONFIG_PASS_DEFAULT), - config_value(data, "mysql database", CONFIG_DB_DEFAULT), - xatol(config_value(data, "mysql port", CONFIG_PORT_DEFAULT)))); - - /* Do the mysql initialization */ - data->handle = mysql_init(NULL); - if (!data->handle) { - DEBUG(0, ("Failed to connect to server\n")); - return NT_STATUS_UNSUCCESSFUL; - } - /* Process correct entry in $HOME/.my.conf */ - if (!mysql_real_connect(data->handle, - config_value(data, "mysql host", CONFIG_HOST_DEFAULT), - config_value(data, "mysql user", CONFIG_USER_DEFAULT), - config_value(data, "mysql password", CONFIG_PASS_DEFAULT), - config_value(data, "mysql database", CONFIG_DB_DEFAULT), - xatol(config_value (data, "mysql port", CONFIG_PORT_DEFAULT)), - NULL, 0)) { - DEBUG(0, - ("Failed to connect to mysql database: error: %s\n", - mysql_error(data->handle))); - return NT_STATUS_UNSUCCESSFUL; - } - - DEBUG(5, ("Connected to mysql db\n")); - - return NT_STATUS_OK; -} diff --git a/examples/pdb/xml/ChangeLog b/examples/pdb/xml/ChangeLog deleted file mode 100644 index e44fa3bd30..0000000000 --- a/examples/pdb/xml/ChangeLog +++ /dev/null @@ -1,13 +0,0 @@ -** This file is now deprecated - use CVS' log features ** - -2002-06-13 Jelmer Vernooij - * Use SID's instead of RID's (just like samba-HEAD CVS) - * Released 1.1 - -2002-05-26 Jelmer Vernooij - * Update read support (didn't support all elements yet) - * Released 1.0 - -2002-05-26 Jelmer Vernooij - * Initial release - * Released 0.5 diff --git a/examples/pdb/xml/Makefile.in b/examples/pdb/xml/Makefile.in deleted file mode 100644 index 252641da6d..0000000000 --- a/examples/pdb/xml/Makefile.in +++ /dev/null @@ -1,31 +0,0 @@ -PDB_OBJS = pdb_xml.so -PDB_CFLAGS = `xml2-config --cflags` -PDB_LDFLAGS = `xml2-config --libs` - -CC = @CC@ -LIBTOOL = libtool -CFLAGS = @CFLAGS@ $(PDB_CFLAGS) -CPPFLAGS = @CPPFLAGS@ $(PDB_CPPFLAGS) -LDFLAGS = @LDFLAGS@ $(PDB_LDFLAGS) -LDSHFLAGS = -shared -srcdir = @builddir@ -FLAGS = $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper -I. $(CPPFLAGS) -I$(srcdir) - -# Default target - -default: $(PDB_OBJS) - -# Pattern rules - -%.so: %.lo - $(LIBTOOL) $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< - -%.lo: %.c - $(LIBTOOL) $(CC) $(FLAGS) -c $< - -# Misc targets - -clean: - rm -rf .libs - rm -f core *~ *% *.bak \ - $(PDB_OBJS) $(PDB_OBJS:.so=.o) $(PDB_OBJS:.so=.lo) diff --git a/examples/pdb/xml/README b/examples/pdb/xml/README deleted file mode 100644 index afb08fdb4f..0000000000 --- a/examples/pdb/xml/README +++ /dev/null @@ -1,14 +0,0 @@ -Readme for samba pdb xml 0.5 --- -This module requires libxml2 to be installed. - -The usage of pdb_xml is pretty straightforward. To export data, use: - -pdbedit -e plugin:/usr/lib/samba/pdb_xml.so:filename - -(where filename is the name of the file to put the data in) -To import data, use: - -pdbedit -i plugin:/usr/lib/samba/pdb_xml.so:filename -e - -Where filename is the name to read the data from and to put it in. diff --git a/examples/pdb/xml/TODO b/examples/pdb/xml/TODO deleted file mode 100644 index 3947bb68be..0000000000 --- a/examples/pdb/xml/TODO +++ /dev/null @@ -1,6 +0,0 @@ -- Be faster. Don't rewrite the whole file when adding a user, but store - it in the memory and save it when exiting. Requires changes to samba source. - Gives the ability to read/write to standard input/output -- Do locking! -- Better names! -- Support stdin ? diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c deleted file mode 100644 index 5de27bc6e2..0000000000 --- a/examples/pdb/xml/pdb_xml.c +++ /dev/null @@ -1,554 +0,0 @@ - -/* - * XML password backend for samba - * Copyright (C) Jelmer Vernooij 2002 - * Some parts based on the libxml gjobread example by Daniel Veillard - * - * 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. - */ - -/* FIXME: Support stdin input by using '-' */ - -#define XML_URL "http://www.samba.org/ns" - -#include "includes.h" - -#include -#include - -static int xmlsam_debug_level = DBGC_ALL; - -#undef DBGC_CLASS -#define DBGC_CLASS xmlsam_debug_level - -PDB_MODULE_VERSIONING_MAGIC - -static char * iota(int a) { - static char tmp[10]; - - snprintf(tmp, 9, "%d", a); - return tmp; -} - -BOOL parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) -{ - pstring temp; - - cur = cur->xmlChildrenNode; - while (cur != NULL) { - if (strcmp(cur->name, "crypt")) - DEBUG(0, ("Unknown element %s\n", cur->name)); - else { - if (!strcmp(xmlGetProp(cur, "type"), "nt") - && - pdb_gethexpwd(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1), temp)) - pdb_set_nt_passwd(u, temp); - else if (!strcmp(xmlGetProp(cur, "type"), "lanman") - && - pdb_gethexpwd(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1), temp)) - pdb_set_lanman_passwd(u, temp); - else - DEBUG(0, - ("Unknown crypt type: %s\n", - xmlGetProp(cur, "type"))); - } - cur = cur->next; - } - return True; -} - -BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) -{ - char *tmp; - DOM_SID sid; - - tmp = xmlGetProp(cur, "sid"); - if (tmp){ - string_to_sid(&sid, tmp); - pdb_set_user_sid(u, &sid); - } - tmp = xmlGetProp(cur, "uid"); - if (tmp) - pdb_set_uid(u, atol(tmp)); - pdb_set_username(u, xmlGetProp(cur, "name")); - /* We don't care what the top level element name is */ - cur = cur->xmlChildrenNode; - while (cur != NULL) { - if ((!strcmp(cur->name, "group")) && (cur->ns == ns)) { - tmp = xmlGetProp(cur, "gid"); - if (tmp) - pdb_set_gid(u, atol(tmp)); - tmp = xmlGetProp(cur, "sid"); - if (tmp){ - string_to_sid(&sid, tmp); - pdb_set_group_sid(u, &sid); - } - } - - else if ((!strcmp(cur->name, "domain")) && (cur->ns == ns)) - pdb_set_domain(u, - xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1)); - - else if (!strcmp(cur->name, "fullname") && cur->ns == ns) - pdb_set_fullname(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1)); - - else if (!strcmp(cur->name, "nt_username") && cur->ns == ns) - pdb_set_nt_username(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1)); - - else if (!strcmp(cur->name, "logon_script") && cur->ns == ns) - pdb_set_logon_script(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), True); - - else if (!strcmp(cur->name, "profile_path") && cur->ns == ns) - pdb_set_profile_path(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), True); - - else if (!strcmp(cur->name, "logon_time") && cur->ns == ns) - pdb_set_logon_time(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), True); - - else if (!strcmp(cur->name, "logoff_time") && cur->ns == ns) - pdb_set_logoff_time(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), - True); - - else if (!strcmp(cur->name, "kickoff_time") && cur->ns == ns) - pdb_set_kickoff_time(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1)), - True); - - else if (!strcmp(cur->name, "logon_divs") && cur->ns == ns) - pdb_set_logon_divs(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); - - else if (!strcmp(cur->name, "hours_len") && cur->ns == ns) - pdb_set_hours_len(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); - - else if (!strcmp(cur->name, "unknown_3") && cur->ns == ns) - pdb_set_unknown_3(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); - - else if (!strcmp(cur->name, "unknown_5") && cur->ns == ns) - pdb_set_unknown_5(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); - - else if (!strcmp(cur->name, "unknown_6") && cur->ns == ns) - pdb_set_unknown_6(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); - - else if (!strcmp(cur->name, "homedir") && cur->ns == ns) - pdb_set_homedir(u, - xmlNodeListGetString(doc, cur->xmlChildrenNode, - 1), True); - - else if (!strcmp(cur->name, "unknown_str") && cur->ns == ns) - pdb_set_unknown_str(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1)); - - else if (!strcmp(cur->name, "dir_drive") && cur->ns == ns) - pdb_set_dir_drive(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1), True); - - else if (!strcmp(cur->name, "munged_dial") && cur->ns == ns) - pdb_set_munged_dial(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1)); - - else if (!strcmp(cur->name, "acct_desc") && cur->ns == ns) - pdb_set_acct_desc(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1)); - - else if (!strcmp(cur->name, "acct_ctrl") && cur->ns == ns) - pdb_set_acct_ctrl(u, - atol(xmlNodeListGetString - (doc, cur->xmlChildrenNode, 1))); - - else if (!strcmp(cur->name, "workstations") && cur->ns == ns) - pdb_set_workstations(u, - xmlNodeListGetString(doc, - cur->xmlChildrenNode, - 1)); - - else if ((!strcmp(cur->name, "password")) && (cur->ns == ns)) { - tmp = xmlGetProp(cur, "last_set"); - if (tmp) - pdb_set_pass_last_set_time(u, atol(tmp)); - tmp = xmlGetProp(cur, "must_change"); - if (tmp) - pdb_set_pass_must_change_time(u, atol(tmp), True); - tmp = xmlGetProp(cur, "can_change"); - if (tmp) - pdb_set_pass_can_change_time(u, atol(tmp), True); - parsePass(doc, ns, cur, u); - } - - else - DEBUG(0, ("Unknown element %s\n", cur->name)); - cur = cur->next; - } - - return True; -} - -typedef struct pdb_xml { - char *location; - char written; - xmlDocPtr doc; - xmlNodePtr users; - xmlNodePtr pwent; - xmlNsPtr ns; -} pdb_xml; - -xmlNodePtr parseSambaXMLFile(struct pdb_xml *data) -{ - xmlNodePtr cur; - - data->doc = xmlParseFile(data->location); - if (data->doc == NULL) - return NULL; - - cur = xmlDocGetRootElement(data->doc); - if (!cur) { - DEBUG(0, ("empty document\n")); - xmlFreeDoc(data->doc); - return NULL; - } - data->ns = xmlSearchNsByHref(data->doc, cur, XML_URL); - if (!data->ns) { - DEBUG(0, - ("document of the wrong type, samba user namespace not found\n")); - xmlFreeDoc(data->doc); - return NULL; - } - if (strcmp(cur->name, "samba")) { - DEBUG(0, ("document of the wrong type, root node != samba")); - xmlFreeDoc(data->doc); - return NULL; - } - - cur = cur->xmlChildrenNode; - while (cur && xmlIsBlankNode(cur)) { - cur = cur->next; - } - if (!cur) - return NULL; - if ((strcmp(cur->name, "users")) || (cur->ns != data->ns)) { - DEBUG(0, ("document of the wrong type, was '%s', users expected", - cur->name)); - DEBUG(0, ("xmlDocDump follows\n")); - xmlDocDump(stderr, data->doc); - DEBUG(0, ("xmlDocDump finished\n")); - xmlFreeDoc(data->doc); - return NULL; - } - data->users = cur; - cur = cur->xmlChildrenNode; - return cur; -} - -static NTSTATUS xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) -{ - pdb_xml *data; - - if (!methods) { - DEBUG(0, ("Invalid methods\n")); - return NT_STATUS_INVALID_PARAMETER; - } - data = (pdb_xml *) methods->private_data; - if (!data) { - DEBUG(0, ("Invalid pdb_xml_data\n")); - return NT_STATUS_INVALID_PARAMETER; - } - data->pwent = parseSambaXMLFile(data); - if (!data->pwent) - return NT_STATUS_UNSUCCESSFUL; - - return NT_STATUS_OK; -} - -/*************************************************************** - End enumeration of the passwd list. - ****************************************************************/ - -static void xmlsam_endsampwent(struct pdb_methods *methods) -{ - pdb_xml *data; - - if (!methods) { - DEBUG(0, ("Invalid methods\n")); - return; - } - - data = (pdb_xml *) methods->private_data; - - if (!data) { - DEBUG(0, ("Invalid pdb_xml_data\n")); - return; - } - - xmlFreeDoc(data->doc); - data->doc = NULL; - data->pwent = NULL; -} - -/***************************************************************** - Get one SAM_ACCOUNT from the list (next in line) - *****************************************************************/ - -static NTSTATUS xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) -{ - pdb_xml *data; - - if (!methods) { - DEBUG(0, ("Invalid methods\n")); - return NT_STATUS_INVALID_PARAMETER; - } - data = (pdb_xml *) methods->private_data; - - if (!data) { - DEBUG(0, ("Invalid pdb_xml_data\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - while (data->pwent) { - if ((!strcmp(data->pwent->name, "user")) && - (data->pwent->ns == data->ns)) { - - parseUser(data->doc, data->ns, data->pwent, user); - data->pwent = data->pwent->next; - return NT_STATUS_OK; - } - data->pwent = data->pwent->next; - } - return NT_STATUS_UNSUCCESSFUL; -} - -/*************************************************************************** - Adds an existing SAM_ACCOUNT - ****************************************************************************/ - -static NTSTATUS xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) -{ - pstring temp; - fstring sid_str; - xmlNodePtr cur, user, pass, root; - pdb_xml *data; - uint32 store = pdb_get_init_flag(u); - - DEBUG(10, ("xmlsam_add_sam_account called!\n")); - - if (!methods) { - DEBUG(0, ("Invalid methods\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - data = (pdb_xml *) methods->private_data; - if (!data) { - DEBUG(0, ("Invalid pdb_xml_data\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - /* Create a new document if we can't open the current one */ - if (!parseSambaXMLFile(data)) { - DEBUG(0, ("Can't load current XML file, creating a new one\n")); - data->doc = xmlNewDoc(XML_DEFAULT_VERSION); - root = xmlNewDocNode(data->doc, NULL, "samba", NULL); - cur = xmlDocSetRootElement(data->doc, root); - data->ns = xmlNewNs(root, XML_URL, "samba"); - data->users = xmlNewChild(root, data->ns, "users", NULL); - } - - user = xmlNewChild(data->users, data->ns, "user", NULL); - xmlNewProp(user, "sid", - sid_to_string(sid_str, pdb_get_user_sid(u))); - if (store & FLAG_SAM_UID) - xmlNewProp(user, "uid", iota(pdb_get_uid(u))); - - if (pdb_get_username(u) && strcmp(pdb_get_username(u), "")) - xmlNewProp(user, "name", pdb_get_username(u)); - - cur = xmlNewChild(user, data->ns, "group", NULL); - - xmlNewProp(cur, "sid", - sid_to_string(sid_str, pdb_get_group_sid(u))); - if (store & FLAG_SAM_GID) - xmlNewProp(cur, "gid", iota(pdb_get_gid(u))); - - if (store & FLAG_SAM_LOGONTIME) - xmlNewChild(user, data->ns, "login_time", - iota(pdb_get_logon_time(u))); - - if (store & FLAG_SAM_LOGOFFTIME) - xmlNewChild(user, data->ns, "logoff_time", - iota(pdb_get_logoff_time(u))); - - if (store & FLAG_SAM_KICKOFFTIME) - xmlNewChild(user, data->ns, "kickoff_time", - iota(pdb_get_kickoff_time(u))); - - if (pdb_get_domain(u) && strcmp(pdb_get_domain(u), "")) - xmlNewChild(user, data->ns, "domain", pdb_get_domain(u)); - - if (pdb_get_nt_username(u) && strcmp(pdb_get_nt_username(u), "")) - xmlNewChild(user, data->ns, "nt_username", pdb_get_nt_username(u)); - - if (pdb_get_fullname(u) && strcmp(pdb_get_fullname(u), "")) - xmlNewChild(user, data->ns, "fullname", pdb_get_fullname(u)); - - if (pdb_get_homedir(u) && strcmp(pdb_get_homedir(u), "")) - xmlNewChild(user, data->ns, "homedir", pdb_get_homedir(u)); - - if (pdb_get_dir_drive(u) && strcmp(pdb_get_dir_drive(u), "")) - xmlNewChild(user, data->ns, "dir_drive", pdb_get_dir_drive(u)); - - if (pdb_get_logon_script(u) && strcmp(pdb_get_logon_script(u), "")) - xmlNewChild(user, data->ns, "logon_script", - pdb_get_logon_script(u)); - - if (pdb_get_profile_path(u) && strcmp(pdb_get_profile_path(u), "")) - xmlNewChild(user, data->ns, "profile_path", - pdb_get_profile_path(u)); - - if (pdb_get_acct_desc(u) && strcmp(pdb_get_acct_desc(u), "")) - xmlNewChild(user, data->ns, "acct_desc", pdb_get_acct_desc(u)); - - if (pdb_get_workstations(u) && strcmp(pdb_get_workstations(u), "")) - xmlNewChild(user, data->ns, "workstations", - pdb_get_workstations(u)); - - if (pdb_get_unknown_str(u) && strcmp(pdb_get_unknown_str(u), "")) - xmlNewChild(user, data->ns, "unknown_str", pdb_get_unknown_str(u)); - - if (pdb_get_munged_dial(u) && strcmp(pdb_get_munged_dial(u), "")) - xmlNewChild(user, data->ns, "munged_dial", pdb_get_munged_dial(u)); - - - /* Password stuff */ - pass = xmlNewChild(user, data->ns, "password", NULL); - if (pdb_get_pass_last_set_time(u)) - xmlNewProp(pass, "last_set", iota(pdb_get_pass_last_set_time(u))); - if (store & FLAG_SAM_CANCHANGETIME) - xmlNewProp(pass, "can_change", - iota(pdb_get_pass_can_change_time(u))); - - if (store & FLAG_SAM_MUSTCHANGETIME) - xmlNewProp(pass, "must_change", - iota(pdb_get_pass_must_change_time(u))); - - - if (pdb_get_lanman_passwd(u)) { - pdb_sethexpwd(temp, pdb_get_lanman_passwd(u), - pdb_get_acct_ctrl(u)); - cur = xmlNewChild(pass, data->ns, "crypt", temp); - xmlNewProp(cur, "type", "lanman"); - } - - if (pdb_get_nt_passwd(u)) { - pdb_sethexpwd(temp, pdb_get_nt_passwd(u), pdb_get_acct_ctrl(u)); - cur = xmlNewChild(pass, data->ns, "crypt", temp); - xmlNewProp(cur, "type", "nt"); - } - - xmlNewChild(user, data->ns, "acct_ctrl", iota(pdb_get_acct_ctrl(u))); - xmlNewChild(user, data->ns, "unknown_3", iota(pdb_get_unknown3(u))); - - if (pdb_get_logon_divs(u)) - xmlNewChild(user, data->ns, "logon_divs", - iota(pdb_get_logon_divs(u))); - - if (pdb_get_hours_len(u)) - xmlNewChild(user, data->ns, "hours_len", - iota(pdb_get_hours_len(u))); - - xmlNewChild(user, data->ns, "unknown_5", iota(pdb_get_unknown5(u))); - xmlNewChild(user, data->ns, "unknown_6", iota(pdb_get_unknown6(u))); - xmlSaveFile(data->location, data->doc); - - return NT_STATUS_OK; -} - -NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, - const char *location) -{ - NTSTATUS nt_status; - pdb_xml *data; - - xmlsam_debug_level = debug_add_class("xmlsam"); - if (xmlsam_debug_level == -1) { - xmlsam_debug_level = DBGC_ALL; - DEBUG(0, ("xmlsam: Couldn't register custom debugging class!\n")); - } - - if (!pdb_context) { - DEBUG(0, ("invalid pdb_methods specified\n")); - return NT_STATUS_UNSUCCESSFUL; - } - - if (!NT_STATUS_IS_OK - (nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { - return nt_status; - } - - (*pdb_method)->name = "xmlsam"; - - (*pdb_method)->setsampwent = xmlsam_setsampwent; - (*pdb_method)->endsampwent = xmlsam_endsampwent; - (*pdb_method)->getsampwent = xmlsam_getsampwent; - (*pdb_method)->add_sam_account = xmlsam_add_sam_account; - (*pdb_method)->getsampwnam = NULL; - (*pdb_method)->getsampwsid = NULL; - (*pdb_method)->update_sam_account = NULL; - (*pdb_method)->delete_sam_account = NULL; - - data = talloc(pdb_context->mem_ctx, sizeof(pdb_xml)); - data->location = - (location ? talloc_strdup(pdb_context->mem_ctx, location) : "-"); - data->pwent = NULL; - data->written = 0; - (*pdb_method)->private_data = data; - - LIBXML_TEST_VERSION xmlKeepBlanksDefault(0); - - return NT_STATUS_OK; -} -- cgit From b8766e74c6eae8d4025b88043d57fe2653c14352 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 11 Nov 2002 13:49:39 +0000 Subject: Fix typo (This used to be commit ad5cb338a1e5e60116757a1c8f2fb844ad062401) --- examples/pdb/mysql/mysql.dump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/mysql.dump b/examples/pdb/mysql/mysql.dump index 12eac6cdc7..3bd6d19800 100644 --- a/examples/pdb/mysql/mysql.dump +++ b/examples/pdb/mysql/mysql.dump @@ -1,7 +1,7 @@ # Put this in your MySQL database by running # mysql -u -p -h < mysql.dump -CREATE TABEL user ( +CREATE TABLE user ( logon_time int(9), logoff_time int(9), kickoff_time int(9), -- cgit From 4a6eb741f0e065f85c1d49ef63e6bd98a34e10a1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 28 Apr 2003 01:21:59 +0000 Subject: Update for new modules system (This used to be commit bd2444322956cd34a95159114547b5ddc804df9e) --- examples/pdb/README | 53 +++++++---------------------------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/README b/examples/pdb/README index 561473129b..c18e128e78 100644 --- a/examples/pdb/README +++ b/examples/pdb/README @@ -1,55 +1,16 @@ README for Samba Password Database (PDB) examples ==================================================== -8-8-2002 Jelmer Vernooij - -Added mysql and xml modules. See README in xml/ and mysql/ for details. - -21-6-2002 Stefan (metze) Metzmacher - -I have added an interface versioning. - -Every module MUST have a pdb_version() function. - -this is defined in include/passdb.h: -#define PDB_MODULE_VERSIONING_MAGIC \ -int pdb_version(void)\ -{\ - return PASSDB_INTERFACE_VERSION;\ -} - -You MUST add this line inside a module: -PDB_MODULE_VERSIONING_MAGIC - -21-6-2002 Stefan (metze) Metzmacher - -The pdb_interface was changed: - -this function are deleted: -static BOOL testsam_getsampwrid (struct pdb_methods *methods, SAM_ACCOUNT *user, uint32 rid) - -this function are added: -static BOOL testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, DOM_SID sid) - -In the SAM_ACCOUNT struct: - -this fields are deleted: -uint32 user_rid; -uint32 group_rid; - -this fields are added: -DOM_SID user_sid; -DOM_SID group_sid; - -15-2-2002 Jelmer Vernooij +Jelmer Vernooij +Stefan (metze) Metzmacher The pdb_test.c file in this directory contains a very basic example of a pdb plugin. It just prints the name of the function that is executed using DEBUG. Maybe it's nice to include some of the arguments to the function in the future too.. -To debug passdb backends, try to run gdb on the 'pdbedit' executable. That's really much easier than restarting smbd constantly and attaching with your debugger. - -New passdb plugins should go into the samba lib directory, (/usr/lib/samba/ for -most distributions) and should be prefixed with 'pdb_'. An example would be: -/usr/lib/samba/pdb_test.so +To debug passdb backends, try to run gdb on the 'pdbedit' executable. That's +really much easier than restarting smbd constantly and attaching with your +debugger. +New passdb plugins should go into the samba lib directory, (/usr/lib/samba/pdb/ +for most distributions). An example would be: /usr/lib/samba/pdb/test.so -- cgit From 37865338804e76b36f3bb53fef58398f44cbf0a3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 28 Apr 2003 01:24:26 +0000 Subject: Update for the new modules system (This used to be commit 528c56176b186d9fa43f6a0c9831562c123ec25d) --- examples/pdb/pdb_test.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index c5ba094e42..f5fb57ddb2 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -25,9 +25,6 @@ static int testsam_debug_level = DBGC_ALL; #undef DBGC_CLASS #define DBGC_CLASS testsam_debug_level -/* define the version of the passdb interface */ -PDB_MODULE_VERSIONING_MAGIC - /*************************************************************** Start enumeration of the passwd list. ****************************************************************/ @@ -107,7 +104,7 @@ static NTSTATUS testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUN return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +NTSTATUS testsam_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) { NTSTATUS nt_status; @@ -141,3 +138,12 @@ NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char return NT_STATUS_OK; } + +int init_module(void); + +int init_module() { + if(smb_register_passdb("testsam", testsam_init, PASSDB_INTERFACE_VERSION)) + return 0; + + return 1; +} -- cgit From 540e3f889c4a50440880214d2a88561b0d2c0323 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 16 Jun 2003 21:33:46 +0000 Subject: Add DTD used by XML passdb backend (This used to be commit f3fd321b61dbf53b1dc33a42afe8a943c94c1135) --- examples/pdb/sambapdb.dtd | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/pdb/sambapdb.dtd (limited to 'examples/pdb') diff --git a/examples/pdb/sambapdb.dtd b/examples/pdb/sambapdb.dtd new file mode 100644 index 0000000000..1f4054ddec --- /dev/null +++ b/examples/pdb/sambapdb.dtd @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit From 9da5e6a4da67578b6d64011dce04a4eb9361e1b3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 9 Nov 2003 14:09:27 +0000 Subject: Add new fields bad_password_count and logon_count (This used to be commit 58c21bc0d1e9a39e64ce7b9efd637dc776c06029) --- examples/pdb/mysql/mysql.dump | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/mysql.dump b/examples/pdb/mysql/mysql.dump index 3bd6d19800..5da75f5745 100644 --- a/examples/pdb/mysql/mysql.dump +++ b/examples/pdb/mysql/mysql.dump @@ -31,5 +31,7 @@ CREATE TABLE user ( logon_divs int(9), hours_len int(9), unknown_5 int(9), - unknown_6 int(9) + unknown_6 int(9), + bad_password_count int(9), + logon_count(9) ); -- cgit From 2abf5f928fc974f0f03443f4bf3b8a8e97738aa1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 30 Dec 2003 21:12:36 +0000 Subject: Another little one: Make pdb_test.c at least compile, although its way out of date. Volker (This used to be commit 5d7a14166af3daf04b570fd5f66469d5db5a3500) --- examples/pdb/Makefile | 2 +- examples/pdb/pdb_test.c | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/Makefile b/examples/pdb/Makefile index 115fd3c87e..a53cd5d5e2 100644 --- a/examples/pdb/Makefile +++ b/examples/pdb/Makefile @@ -8,7 +8,7 @@ SAMBA_SRC = ../../source SAMBA_INCL = ../../source/include UBIQX_SRC = ../../source/ubiqx SMBWR_SRC = ../../source/smbwrapper -CFLAGS = -I$(SAMBA_SRC) -I$(SAMBA_INCL) -I$(UBIQX_SRC) -I$(SMBWR_SRC) -Wall -g +CFLAGS = -I$(SAMBA_SRC) -I$(SAMBA_INCL) -I$(UBIQX_SRC) -I$(SMBWR_SRC) -Wall -g -I/usr/include/heimdal -fPIC PDB_OBJS = pdb_test.so # Default target diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index f5fb57ddb2..e46c621d48 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -139,11 +139,7 @@ NTSTATUS testsam_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const return NT_STATUS_OK; } -int init_module(void); - -int init_module() { - if(smb_register_passdb("testsam", testsam_init, PASSDB_INTERFACE_VERSION)) - return 0; - - return 1; +NTSTATUS init_module(void) { + return smb_register_passdb(PASSDB_INTERFACE_VERSION, "testsam", + testsam_init); } -- cgit From 7d7b6190b0d07441ded54f096e7f95f51dc31024 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 24 Mar 2004 13:41:06 +0000 Subject: change my email address to the samba.org one metze (This used to be commit 5bf8f1b31b7b37317e78bbb9fbf3cd25290027b5) --- examples/pdb/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/pdb') diff --git a/examples/pdb/README b/examples/pdb/README index c18e128e78..ab1baed236 100644 --- a/examples/pdb/README +++ b/examples/pdb/README @@ -1,7 +1,7 @@ README for Samba Password Database (PDB) examples ==================================================== Jelmer Vernooij -Stefan (metze) Metzmacher +Stefan (metze) Metzmacher The pdb_test.c file in this directory contains a very basic example of a pdb plugin. It just prints the name of the function that is executed using -- cgit From 0bb304d97f745e8bf96a080a200365419da9f460 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 Apr 2004 15:26:18 +0000 Subject: r379: Fix syntax error in example mysql table (This used to be commit 2a7aaedab66e1b69648cff2293f6661541c3a2a4) --- examples/pdb/mysql/mysql.dump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/mysql.dump b/examples/pdb/mysql/mysql.dump index 5da75f5745..8901352154 100644 --- a/examples/pdb/mysql/mysql.dump +++ b/examples/pdb/mysql/mysql.dump @@ -33,5 +33,5 @@ CREATE TABLE user ( unknown_5 int(9), unknown_6 int(9), bad_password_count int(9), - logon_count(9) + logon_count int(9) ); -- cgit From fef54a21b19b3475adfdcdde636f00a3f6be0fb9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 3 Sep 2004 13:42:02 +0000 Subject: r2210: Fix misleading comment found by Heinrich Mislik (This used to be commit 3a88ee4c444c7b953c9f88b19998a5d84fc5e17c) --- examples/pdb/pdb_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c index e46c621d48..a10d66005f 100644 --- a/examples/pdb/pdb_test.c +++ b/examples/pdb/pdb_test.c @@ -114,8 +114,8 @@ NTSTATUS testsam_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const (*pdb_method)->name = "testsam"; - /* Functions your pdb module doesn't provide should be set - * to NULL */ + /* Functions your pdb module doesn't provide should not be + set, make_pdb_methods() already provide suitable defaults for missing functions */ (*pdb_method)->setsampwent = testsam_setsampwent; (*pdb_method)->endsampwent = testsam_endsampwent; -- cgit From de72d898778635af20a1f6a394fe6c837e2ed149 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 23 Sep 2004 18:11:08 +0000 Subject: r2567: Patches from Lars Mueller : trivial fix for autoconf and autoheader versions with a letter in the version string. This happens in our current beta named distribution tree. trivial patch to fix the build with the upcoming libtool version. It will be mandatory to use --mode while using libtool. (This used to be commit 80d591f8cc62d513eb99112e6533b93ee901d27d) --- examples/pdb/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/Makefile b/examples/pdb/Makefile index a53cd5d5e2..5c0eb6fc80 100644 --- a/examples/pdb/Makefile +++ b/examples/pdb/Makefile @@ -18,10 +18,10 @@ default: $(PDB_OBJS) # Pattern rules %.so: %.lo - $(LIBTOOL) $(CC) -shared -o $@ $< $(LDFLAGS) + $(LIBTOOL) --mode=link $(CC) -shared -o $@ $< $(LDFLAGS) %.lo: %.c - $(LIBTOOL) $(CC) $(CPPFLAGS) $(CFLAGS) -c $< + $(LIBTOOL) --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS) -c $< # Misc targets -- cgit From 1ffbe8fec8923a044b0280e230fc224f1a60419f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 10 Jan 2005 19:27:24 +0000 Subject: r4653: Output file of "test" pdb backend should be called test.so (This used to be commit 95c8727045fab0c6aa3446871e19e7b29c20382d) --- examples/pdb/Makefile | 2 +- examples/pdb/README | 2 +- examples/pdb/pdb_test.c | 145 ------------------------------------------------ examples/pdb/test.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 147 deletions(-) delete mode 100644 examples/pdb/pdb_test.c create mode 100644 examples/pdb/test.c (limited to 'examples/pdb') diff --git a/examples/pdb/Makefile b/examples/pdb/Makefile index 5c0eb6fc80..10980ae62e 100644 --- a/examples/pdb/Makefile +++ b/examples/pdb/Makefile @@ -9,7 +9,7 @@ SAMBA_INCL = ../../source/include UBIQX_SRC = ../../source/ubiqx SMBWR_SRC = ../../source/smbwrapper CFLAGS = -I$(SAMBA_SRC) -I$(SAMBA_INCL) -I$(UBIQX_SRC) -I$(SMBWR_SRC) -Wall -g -I/usr/include/heimdal -fPIC -PDB_OBJS = pdb_test.so +PDB_OBJS = test.so # Default target diff --git a/examples/pdb/README b/examples/pdb/README index ab1baed236..baceb8e600 100644 --- a/examples/pdb/README +++ b/examples/pdb/README @@ -3,7 +3,7 @@ README for Samba Password Database (PDB) examples Jelmer Vernooij Stefan (metze) Metzmacher -The pdb_test.c file in this directory contains a very basic example of +The test.c file in this directory contains a very basic example of a pdb plugin. It just prints the name of the function that is executed using DEBUG. Maybe it's nice to include some of the arguments to the function in the future too.. diff --git a/examples/pdb/pdb_test.c b/examples/pdb/pdb_test.c deleted file mode 100644 index a10d66005f..0000000000 --- a/examples/pdb/pdb_test.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Test password backend for samba - * Copyright (C) Jelmer Vernooij 2002 - * - * 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" - -static int testsam_debug_level = DBGC_ALL; - -#undef DBGC_CLASS -#define DBGC_CLASS testsam_debug_level - -/*************************************************************** - Start enumeration of the passwd list. -****************************************************************/ - -static NTSTATUS testsam_setsampwent(struct pdb_methods *methods, BOOL update) -{ - DEBUG(10, ("testsam_setsampwent called\n")); - return NT_STATUS_NOT_IMPLEMENTED; -} - -/*************************************************************** - End enumeration of the passwd list. -****************************************************************/ - -static void testsam_endsampwent(struct pdb_methods *methods) -{ - DEBUG(10, ("testsam_endsampwent called\n")); -} - -/***************************************************************** - Get one SAM_ACCOUNT from the list (next in line) -*****************************************************************/ - -static NTSTATUS testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) -{ - DEBUG(10, ("testsam_getsampwent called\n")); - return NT_STATUS_NOT_IMPLEMENTED; -} - -/****************************************************************** - Lookup a name in the SAM database -******************************************************************/ - -static NTSTATUS testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) -{ - DEBUG(10, ("testsam_getsampwnam called\n")); - return NT_STATUS_NOT_IMPLEMENTED; -} - -/*************************************************************************** - Search by sid - **************************************************************************/ - -static NTSTATUS testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, const DOM_SID *sid) -{ - DEBUG(10, ("testsam_getsampwsid called\n")); - return NT_STATUS_NOT_IMPLEMENTED; -} - -/*************************************************************************** - Delete a SAM_ACCOUNT -****************************************************************************/ - -static NTSTATUS testsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT *sam_pass) -{ - DEBUG(10, ("testsam_delete_sam_account called\n")); - return NT_STATUS_NOT_IMPLEMENTED; -} - -/*************************************************************************** - Modifies an existing SAM_ACCOUNT -****************************************************************************/ - -static NTSTATUS testsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) -{ - DEBUG(10, ("testsam_update_sam_account called\n")); - return NT_STATUS_NOT_IMPLEMENTED; -} - -/*************************************************************************** - Adds an existing SAM_ACCOUNT -****************************************************************************/ - -static NTSTATUS testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) -{ - DEBUG(10, ("testsam_add_sam_account called\n")); - return NT_STATUS_NOT_IMPLEMENTED; -} - -NTSTATUS testsam_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) -{ - NTSTATUS nt_status; - - if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { - return nt_status; - } - - (*pdb_method)->name = "testsam"; - - /* Functions your pdb module doesn't provide should not be - set, make_pdb_methods() already provide suitable defaults for missing functions */ - - (*pdb_method)->setsampwent = testsam_setsampwent; - (*pdb_method)->endsampwent = testsam_endsampwent; - (*pdb_method)->getsampwent = testsam_getsampwent; - (*pdb_method)->getsampwnam = testsam_getsampwnam; - (*pdb_method)->getsampwsid = testsam_getsampwsid; - (*pdb_method)->add_sam_account = testsam_add_sam_account; - (*pdb_method)->update_sam_account = testsam_update_sam_account; - (*pdb_method)->delete_sam_account = testsam_delete_sam_account; - - testsam_debug_level = debug_add_class("testsam"); - if (testsam_debug_level == -1) { - testsam_debug_level = DBGC_ALL; - DEBUG(0, ("testsam: Couldn't register custom debugging class!\n")); - } else DEBUG(0, ("testsam: Debug class number of 'testsam': %d\n", testsam_debug_level)); - - DEBUG(0, ("Initializing testsam\n")); - if (location) - DEBUG(10, ("Location: %s\n", location)); - - return NT_STATUS_OK; -} - -NTSTATUS init_module(void) { - return smb_register_passdb(PASSDB_INTERFACE_VERSION, "testsam", - testsam_init); -} diff --git a/examples/pdb/test.c b/examples/pdb/test.c new file mode 100644 index 0000000000..a10d66005f --- /dev/null +++ b/examples/pdb/test.c @@ -0,0 +1,145 @@ +/* + * Test password backend for samba + * Copyright (C) Jelmer Vernooij 2002 + * + * 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" + +static int testsam_debug_level = DBGC_ALL; + +#undef DBGC_CLASS +#define DBGC_CLASS testsam_debug_level + +/*************************************************************** + Start enumeration of the passwd list. +****************************************************************/ + +static NTSTATUS testsam_setsampwent(struct pdb_methods *methods, BOOL update) +{ + DEBUG(10, ("testsam_setsampwent called\n")); + return NT_STATUS_NOT_IMPLEMENTED; +} + +/*************************************************************** + End enumeration of the passwd list. +****************************************************************/ + +static void testsam_endsampwent(struct pdb_methods *methods) +{ + DEBUG(10, ("testsam_endsampwent called\n")); +} + +/***************************************************************** + Get one SAM_ACCOUNT from the list (next in line) +*****************************************************************/ + +static NTSTATUS testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) +{ + DEBUG(10, ("testsam_getsampwent called\n")); + return NT_STATUS_NOT_IMPLEMENTED; +} + +/****************************************************************** + Lookup a name in the SAM database +******************************************************************/ + +static NTSTATUS testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) +{ + DEBUG(10, ("testsam_getsampwnam called\n")); + return NT_STATUS_NOT_IMPLEMENTED; +} + +/*************************************************************************** + Search by sid + **************************************************************************/ + +static NTSTATUS testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, const DOM_SID *sid) +{ + DEBUG(10, ("testsam_getsampwsid called\n")); + return NT_STATUS_NOT_IMPLEMENTED; +} + +/*************************************************************************** + Delete a SAM_ACCOUNT +****************************************************************************/ + +static NTSTATUS testsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT *sam_pass) +{ + DEBUG(10, ("testsam_delete_sam_account called\n")); + return NT_STATUS_NOT_IMPLEMENTED; +} + +/*************************************************************************** + Modifies an existing SAM_ACCOUNT +****************************************************************************/ + +static NTSTATUS testsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +{ + DEBUG(10, ("testsam_update_sam_account called\n")); + return NT_STATUS_NOT_IMPLEMENTED; +} + +/*************************************************************************** + Adds an existing SAM_ACCOUNT +****************************************************************************/ + +static NTSTATUS testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +{ + DEBUG(10, ("testsam_add_sam_account called\n")); + return NT_STATUS_NOT_IMPLEMENTED; +} + +NTSTATUS testsam_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +{ + NTSTATUS nt_status; + + if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { + return nt_status; + } + + (*pdb_method)->name = "testsam"; + + /* Functions your pdb module doesn't provide should not be + set, make_pdb_methods() already provide suitable defaults for missing functions */ + + (*pdb_method)->setsampwent = testsam_setsampwent; + (*pdb_method)->endsampwent = testsam_endsampwent; + (*pdb_method)->getsampwent = testsam_getsampwent; + (*pdb_method)->getsampwnam = testsam_getsampwnam; + (*pdb_method)->getsampwsid = testsam_getsampwsid; + (*pdb_method)->add_sam_account = testsam_add_sam_account; + (*pdb_method)->update_sam_account = testsam_update_sam_account; + (*pdb_method)->delete_sam_account = testsam_delete_sam_account; + + testsam_debug_level = debug_add_class("testsam"); + if (testsam_debug_level == -1) { + testsam_debug_level = DBGC_ALL; + DEBUG(0, ("testsam: Couldn't register custom debugging class!\n")); + } else DEBUG(0, ("testsam: Debug class number of 'testsam': %d\n", testsam_debug_level)); + + DEBUG(0, ("Initializing testsam\n")); + if (location) + DEBUG(10, ("Location: %s\n", location)); + + return NT_STATUS_OK; +} + +NTSTATUS init_module(void) { + return smb_register_passdb(PASSDB_INTERFACE_VERSION, "testsam", + testsam_init); +} -- cgit From e7eb70928c216706ec1ed4fe7ca152283c917209 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 30 Jan 2005 22:45:46 +0000 Subject: r5111: Fix up changed prototype for setsampwent pdb function. (This used to be commit 331748202077ce9e0b5dcf3ed9b3ab6f89e9c0e4) --- examples/pdb/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/pdb') diff --git a/examples/pdb/test.c b/examples/pdb/test.c index a10d66005f..63eb1eaaf9 100644 --- a/examples/pdb/test.c +++ b/examples/pdb/test.c @@ -29,7 +29,7 @@ static int testsam_debug_level = DBGC_ALL; Start enumeration of the passwd list. ****************************************************************/ -static NTSTATUS testsam_setsampwent(struct pdb_methods *methods, BOOL update) +static NTSTATUS testsam_setsampwent(struct pdb_methods *methods, BOOL update, uint16 acb_mask) { DEBUG(10, ("testsam_setsampwent called\n")); return NT_STATUS_NOT_IMPLEMENTED; -- cgit From 2eab58d3fdaef69eef4958f11b4dec730ae18372 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 30 Jan 2005 22:47:26 +0000 Subject: r5112: Fix for shared object creation in examples. Bugzilla #2058. (This used to be commit 8e5db6f08ceb969bd2580558031f3737b32f10b1) --- examples/pdb/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/Makefile b/examples/pdb/Makefile index 10980ae62e..09d901d374 100644 --- a/examples/pdb/Makefile +++ b/examples/pdb/Makefile @@ -9,7 +9,7 @@ SAMBA_INCL = ../../source/include UBIQX_SRC = ../../source/ubiqx SMBWR_SRC = ../../source/smbwrapper CFLAGS = -I$(SAMBA_SRC) -I$(SAMBA_INCL) -I$(UBIQX_SRC) -I$(SMBWR_SRC) -Wall -g -I/usr/include/heimdal -fPIC -PDB_OBJS = test.so +PDB_OBJS = test.la # Default target @@ -17,8 +17,8 @@ default: $(PDB_OBJS) # Pattern rules -%.so: %.lo - $(LIBTOOL) --mode=link $(CC) -shared -o $@ $< $(LDFLAGS) +%.la: %.lo + $(LIBTOOL) --mode=link $(CC) -module -o $@ $< $(LDFLAGS) -rpath /usr/lib/samba/pdb/ %.lo: %.c $(LIBTOOL) --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS) -c $< @@ -28,4 +28,4 @@ default: $(PDB_OBJS) clean: rm -rf .libs rm -f core *~ *% *.bak \ - $(PDB_OBJS) $(PDB_OBJS:.so=.o) $(PDB_OBJS:.so=.lo) + $(PDB_OBJS) $(PDB_OBJS:.la=.o) $(PDB_OBJS:.la=.lo) -- cgit From 64b9f829cf4e9c347ef7ff095ce468de4df260a4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 9 Mar 2005 10:10:43 +0000 Subject: r5705: Have unknown_6 default to 1260 (fixed #892) (This used to be commit 710ce847a79fa9e7ba488de46a2f69fc9d617e62) --- examples/pdb/mysql/mysql.dump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/mysql.dump b/examples/pdb/mysql/mysql.dump index 8901352154..72018ce5a7 100644 --- a/examples/pdb/mysql/mysql.dump +++ b/examples/pdb/mysql/mysql.dump @@ -31,7 +31,7 @@ CREATE TABLE user ( logon_divs int(9), hours_len int(9), unknown_5 int(9), - unknown_6 int(9), + unknown_6 int(9) default "1260", bad_password_count int(9), logon_count int(9) ); -- cgit From 9ca890e414bddf093ef09f1219b5347cb3b16625 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 4 Feb 2006 10:01:56 +0000 Subject: r13343: More sql cleanup (This used to be commit bd1be2388ebdc332c00289f10f0af17e6cd8b44a) --- examples/pdb/mysql/mysql.dump | 37 ------------------------------------- examples/pdb/mysql/smb.conf | 11 ----------- 2 files changed, 48 deletions(-) delete mode 100644 examples/pdb/mysql/mysql.dump delete mode 100644 examples/pdb/mysql/smb.conf (limited to 'examples/pdb') diff --git a/examples/pdb/mysql/mysql.dump b/examples/pdb/mysql/mysql.dump deleted file mode 100644 index 72018ce5a7..0000000000 --- a/examples/pdb/mysql/mysql.dump +++ /dev/null @@ -1,37 +0,0 @@ -# Put this in your MySQL database by running -# mysql -u -p -h < mysql.dump - -CREATE TABLE user ( - logon_time int(9), - logoff_time int(9), - kickoff_time int(9), - pass_last_set_time int(9), - pass_can_change_time int(9), - pass_must_change_time int(9), - username varchar(255), - domain varchar(255), - nt_username varchar(255), - nt_fullname varchar(255), - home_dir varchar(255), - dir_drive varchar(4), - logon_script varchar(255), - profile_path varchar(255), - acct_desc varchar(255), - workstations varchar(255), - unknown_str varchar(255), - munged_dial varchar(255), - uid int(9) NOT NULL DEFAULT "0" PRIMARY KEY auto_increment, - gid int(9), - user_sid varchar(255), - group_sid varchar(255), - lm_pw varchar(255), - nt_pw varchar(255), - acct_ctrl int(9), - unknown_3 int(9), - logon_divs int(9), - hours_len int(9), - unknown_5 int(9), - unknown_6 int(9) default "1260", - bad_password_count int(9), - logon_count int(9) -); diff --git a/examples/pdb/mysql/smb.conf b/examples/pdb/mysql/smb.conf deleted file mode 100644 index 61a3f19816..0000000000 --- a/examples/pdb/mysql/smb.conf +++ /dev/null @@ -1,11 +0,0 @@ -[global] -netbios name = FOOBAR -workgroup = TESTGROUP -security = domain -domain logons = yes -domain master = yes -passdb backend = plugin:/usr/local/samba/lib/pdb_mysql.so:mysql -mysql:mysql host = rhonwyn -mysql:mysql user = samba -mysql:mysql password = ambas -mysql:mysql database = samba -- cgit From e54786b53543b4667288c64abb55478fddd95061 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 27 Feb 2006 10:32:45 +0000 Subject: r13711: * Correctly handle acb_info/acct_flags as uint32 not as uint16. * Fix a couple of related parsing issues. * in the info3 reply in a samlogon, return the ACB-flags (instead of returning zero) Guenther (This used to be commit 5b89e8bc24f0fdc8b52d5c9e849aba723df34ea7) --- examples/pdb/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/pdb') diff --git a/examples/pdb/test.c b/examples/pdb/test.c index 63eb1eaaf9..68b5b9a3e5 100644 --- a/examples/pdb/test.c +++ b/examples/pdb/test.c @@ -29,7 +29,7 @@ static int testsam_debug_level = DBGC_ALL; Start enumeration of the passwd list. ****************************************************************/ -static NTSTATUS testsam_setsampwent(struct pdb_methods *methods, BOOL update, uint16 acb_mask) +static NTSTATUS testsam_setsampwent(struct pdb_methods *methods, BOOL update, uint32 acb_mask) { DEBUG(10, ("testsam_setsampwent called\n")); return NT_STATUS_NOT_IMPLEMENTED; -- cgit From 2036c47c63f68a03639b14f60c2f7031350cd7a7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Mar 2006 20:19:05 +0000 Subject: r14684: Remove obsolete file (belonged to pdb_xml) (This used to be commit 15c36233fb2e5164ea0fbb2389a066e34838dd20) --- examples/pdb/sambapdb.dtd | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 examples/pdb/sambapdb.dtd (limited to 'examples/pdb') diff --git a/examples/pdb/sambapdb.dtd b/examples/pdb/sambapdb.dtd deleted file mode 100644 index 1f4054ddec..0000000000 --- a/examples/pdb/sambapdb.dtd +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit From 23afde616dc611bc525cb17838b3cfc72eb2a8f3 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 12 Jul 2006 21:05:11 +0000 Subject: r16998: patch from Paul Griffith to fix compile of the test.c pdb file (This used to be commit 34ad8e183cf882913c32b4d03c9ab5fc09181ad2) --- examples/pdb/test.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/test.c b/examples/pdb/test.c index 68b5b9a3e5..c553f72f0b 100644 --- a/examples/pdb/test.c +++ b/examples/pdb/test.c @@ -45,10 +45,10 @@ static void testsam_endsampwent(struct pdb_methods *methods) } /***************************************************************** - Get one SAM_ACCOUNT from the list (next in line) + Get one struct samu from the list (next in line) *****************************************************************/ -static NTSTATUS testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) +static NTSTATUS testsam_getsampwent(struct pdb_methods *methods, struct samu *user) { DEBUG(10, ("testsam_getsampwent called\n")); return NT_STATUS_NOT_IMPLEMENTED; @@ -58,7 +58,7 @@ static NTSTATUS testsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *us Lookup a name in the SAM database ******************************************************************/ -static NTSTATUS testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) +static NTSTATUS testsam_getsampwnam (struct pdb_methods *methods, struct samu *user, const char *sname) { DEBUG(10, ("testsam_getsampwnam called\n")); return NT_STATUS_NOT_IMPLEMENTED; @@ -68,47 +68,47 @@ static NTSTATUS testsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *u Search by sid **************************************************************************/ -static NTSTATUS testsam_getsampwsid (struct pdb_methods *methods, SAM_ACCOUNT *user, const DOM_SID *sid) +static NTSTATUS testsam_getsampwsid (struct pdb_methods *methods, struct samu *user, const DOM_SID *sid) { DEBUG(10, ("testsam_getsampwsid called\n")); return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** - Delete a SAM_ACCOUNT + Delete a struct samu ****************************************************************************/ -static NTSTATUS testsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT *sam_pass) +static NTSTATUS testsam_delete_sam_account(struct pdb_methods *methods, struct samu *sam_pass) { DEBUG(10, ("testsam_delete_sam_account called\n")); return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** - Modifies an existing SAM_ACCOUNT + Modifies an existing struct samu ****************************************************************************/ -static NTSTATUS testsam_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +static NTSTATUS testsam_update_sam_account (struct pdb_methods *methods, struct samu *newpwd) { DEBUG(10, ("testsam_update_sam_account called\n")); return NT_STATUS_NOT_IMPLEMENTED; } /*************************************************************************** - Adds an existing SAM_ACCOUNT + Adds an existing struct samu ****************************************************************************/ -static NTSTATUS testsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +static NTSTATUS testsam_add_sam_account (struct pdb_methods *methods, struct samu *newpwd) { DEBUG(10, ("testsam_add_sam_account called\n")); return NT_STATUS_NOT_IMPLEMENTED; } -NTSTATUS testsam_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +NTSTATUS testsam_init(struct pdb_methods **pdb_method, const char *location) { NTSTATUS nt_status; - if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { + if (!NT_STATUS_IS_OK(nt_status = make_pdb_method( pdb_method ))) { return nt_status; } -- cgit From 0484aca691c727ce4694924db6daac82011d1740 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Fri, 11 May 2007 20:42:51 +0000 Subject: r22805: Inform in examples/pdb about the location of the external support for the SQL backends. (This used to be commit 37f2191cd364dd6c2223b2e19072920ad2a257d6) --- examples/pdb/README | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples/pdb') diff --git a/examples/pdb/README b/examples/pdb/README index baceb8e600..692d32225d 100644 --- a/examples/pdb/README +++ b/examples/pdb/README @@ -14,3 +14,7 @@ debugger. New passdb plugins should go into the samba lib directory, (/usr/lib/samba/pdb/ for most distributions). An example would be: /usr/lib/samba/pdb/test.so + +Be aware that the SQL and XML based passdb modules have been removed since the +3.0.23 release. More information of external support for SQL passdb modules +can be found at http://pdbsql.sourceforge.net/. -- 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) --- examples/pdb/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/pdb') diff --git a/examples/pdb/test.c b/examples/pdb/test.c index c553f72f0b..a5e98c74ba 100644 --- a/examples/pdb/test.c +++ b/examples/pdb/test.c @@ -4,7 +4,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 (at your option) + * 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 -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- examples/pdb/test.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/pdb') diff --git a/examples/pdb/test.c b/examples/pdb/test.c index a5e98c74ba..b5ddefc480 100644 --- a/examples/pdb/test.c +++ b/examples/pdb/test.c @@ -13,8 +13,7 @@ * 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. + * this program; if not, see . */ -- cgit