[PATCH] change SAM DB (files,tdb,ldap,nisplus) in smb.conf

Stefan Metzmacher stefan.metzmacher at metzemix.de
Wed Dec 19 15:41:04 GMT 2001


Hello,

I have a patch to change the samdb dynamicly in smb.conf with the parameter:

sam database = files (default)
sam database = tdb
sam database = ldap
sam database = nisplus


I hope it's usefull!?

PS: things in configure and configure.in should be cleaner!!!

metze

patch is for samba-2.2.2
-------------------------------------------------------------------------------------------------------------------------

diff -urN samba-2.2.2/source/configure samba-2.2.2-MX/source/configure
--- samba-2.2.2/source/configure        Sat Oct 13 23:09:16 2001
+++ samba-2.2.2-MX/source/configure     Tue Oct 30 05:33:01 2001
@@ -11375,7 +11375,7 @@
 #define WITH_TDB_SAM 1
 EOF
 
-    with_smbpasswd_sam=no
+    with_smbpasswd_sam=yes
     ;;
   *)
     echo "$ac_t""no" 1>&6
@@ -11402,7 +11402,7 @@
 EOF
 
     LIBS="-lldap -llber -lresolv $LIBS"
-    with_smbpasswd_sam=no
+    with_smbpasswd_sam=yes
     ;;
   *)
     echo "$ac_t""no" 1>&6
@@ -11428,7 +11428,7 @@
 #define WITH_NISPLUS_SAM 1
 EOF
 
-    with_smbpasswd_sam=no
+    with_smbpasswd_sam=yes
     ;;
   *)
     echo "$ac_t""no" 1>&6
diff -urN samba-2.2.2/source/configure.in samba-2.2.2-MX/source/configure.in
--- samba-2.2.2/source/configure.in     Sat Oct 13 23:09:16 2001
+++ samba-2.2.2-MX/source/configure.in  Tue Oct 30 14:51:28 2001
@@ -1029,92 +1029,7 @@
 fi 
 
 AC_CACHE_CHECK([for ut_time in utmp],samba_cv_HAVE_UT_UT_TIME,[
-AC_TRY_COMPILE([#include <sys/types.h>
-#include <utmp.h>],
-[struct utmp ut;  time_t t; ut.ut_time = t;],
-samba_cv_HAVE_UT_UT_TIME=yes,samba_cv_HAVE_UT_UT_TIME=no,samba_cv_HAVE_UT_UT_TIME=cross)])
-if test x"$samba_cv_HAVE_UT_UT_TIME" = x"yes"; then
-    AC_DEFINE(HAVE_UT_UT_TIME)
-fi 
-
-AC_CACHE_CHECK([for ut_tv in utmp],samba_cv_HAVE_UT_UT_TV,[
-AC_TRY_COMPILE([#include <sys/types.h>
-#include <utmp.h>],
-[struct utmp ut;  struct timeval tv; ut.ut_tv = tv;],
-samba_cv_HAVE_UT_UT_TV=yes,samba_cv_HAVE_UT_UT_TV=no,samba_cv_HAVE_UT_UT_TV=cross)])
-if test x"$samba_cv_HAVE_UT_UT_TV" = x"yes"; then
-    AC_DEFINE(HAVE_UT_UT_TV)
-fi 
-
-AC_CACHE_CHECK([for ut_type in utmp],samba_cv_HAVE_UT_UT_TYPE,[
-AC_TRY_COMPILE([#include <sys/types.h>
-#include <utmp.h>],
-[struct utmp ut;  ut.ut_type = 0;],
-samba_cv_HAVE_UT_UT_TYPE=yes,samba_cv_HAVE_UT_UT_TYPE=no,samba_cv_HAVE_UT_UT_TYPE=cross)])
-if test x"$samba_cv_HAVE_UT_UT_TYPE" = x"yes"; then
-    AC_DEFINE(HAVE_UT_UT_TYPE)
-fi 
-
-AC_CACHE_CHECK([for ut_pid in utmp],samba_cv_HAVE_UT_UT_PID,[
-AC_TRY_COMPILE([#include <sys/types.h>
-#include <utmp.h>],
-[struct utmp ut;  ut.ut_pid = 0;],
-samba_cv_HAVE_UT_UT_PID=yes,samba_cv_HAVE_UT_UT_PID=no,samba_cv_HAVE_UT_UT_PID=cross)])
-if test x"$samba_cv_HAVE_UT_UT_PID" = x"yes"; then
-    AC_DEFINE(HAVE_UT_UT_PID)
-fi 
-
-AC_CACHE_CHECK([for ut_exit in utmp],samba_cv_HAVE_UT_UT_EXIT,[
-AC_TRY_COMPILE([#include <sys/types.h>
-#include <utmp.h>],
-[struct utmp ut;  ut.ut_exit.e_exit = 0;],
-samba_cv_HAVE_UT_UT_EXIT=yes,samba_cv_HAVE_UT_UT_EXIT=no,samba_cv_HAVE_UT_UT_EXIT=cross)])
-if test x"$samba_cv_HAVE_UT_UT_EXIT" = x"yes"; then
-    AC_DEFINE(HAVE_UT_UT_EXIT)
-fi 
-
-AC_CACHE_CHECK([for ut_addr in utmp],samba_cv_HAVE_UT_UT_ADDR,[
-AC_TRY_COMPILE([#include <sys/types.h>
-#include <utmp.h>],
-[struct utmp ut;  ut.ut_addr = 0;],
-samba_cv_HAVE_UT_UT_ADDR=yes,samba_cv_HAVE_UT_UT_ADDR=no,samba_cv_HAVE_UT_UT_ADDR=cross)])
-if test x"$samba_cv_HAVE_UT_UT_ADDR" = x"yes"; then
-    AC_DEFINE(HAVE_UT_UT_ADDR)
-fi 
-
-if test x$ac_cv_func_pututline = xyes ; then
-  AC_CACHE_CHECK([whether pututline returns pointer],samba_cv_PUTUTLINE_RETURNS_UTMP,[
-  AC_TRY_COMPILE([#include <sys/types.h>
-#include <utmp.h>],
-  [struct utmp utarg; struct utmp *utreturn; utreturn = pututline(&utarg);],
-  samba_cv_PUTUTLINE_RETURNS_UTMP=yes,samba_cv_PUTUTLINE_RETURNS_UTMP=no)])
-  if test x"$samba_cv_PUTUTLINE_RETURNS_UTMP" = x"yes"; then
-      AC_DEFINE(PUTUTLINE_RETURNS_UTMP)
-  fi
-fi
-
-AC_CACHE_CHECK([for ut_syslen in utmpx],samba_cv_HAVE_UX_UT_SYSLEN,[
-AC_TRY_COMPILE([#include <sys/types.h>
-#include <utmpx.h>],
-[struct utmpx ux;  ux.ut_syslen = 0;],
-samba_cv_HAVE_UX_UT_SYSLEN=yes,samba_cv_HAVE_UX_UT_SYSLEN=no,samba_cv_HAVE_UX_UT_SYSLEN=cross)])
-if test x"$samba_cv_HAVE_UX_UT_SYSLEN" = x"yes"; then
-    AC_DEFINE(HAVE_UX_UT_SYSLEN)
-fi 
-
-AC_CACHE_CHECK([for Linux kernel oplocks],samba_cv_HAVE_KERNEL_OPLOCKS_LINUX,[
-AC_TRY_RUN([
-#include <sys/types.h>
-#include <fcntl.h>
-#ifndef F_GETLEASE
-#define F_GETLEASE     1025
-#endif
-main() {
-       int fd = open("/dev/null", O_RDONLY);
-       return fcntl(fd, F_GETLEASE, 0) == -1;
-}
-],
-samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=yes,samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=no,samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=cross)])
+AC_TRY_COMPILE([#include samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=no,samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=cross)])
 if test x"$samba_cv_HAVE_KERNEL_OPLOCKS_LINUX" = x"yes"; then
     AC_DEFINE(HAVE_KERNEL_OPLOCKS_LINUX)
 fi
@@ -1778,7 +1693,6 @@
   yes)
     AC_MSG_RESULT(yes)
     AC_DEFINE(WITH_TDB_SAM)
-    with_smbpasswd_sam=no
     ;;
   *)
     AC_MSG_RESULT(no)
@@ -1797,7 +1711,6 @@
     AC_MSG_RESULT(yes)
     AC_DEFINE(WITH_LDAP_SAM)
     LIBS="-lldap -llber -lresolv $LIBS"
-    with_smbpasswd_sam=no
     ;;
   *)
     AC_MSG_RESULT(no)
@@ -1815,7 +1728,6 @@
   yes)
     AC_MSG_RESULT(yes)
     AC_DEFINE(WITH_NISPLUS_SAM)
-    with_smbpasswd_sam=no
     ;;
   *)
     AC_MSG_RESULT(no)
@@ -1828,15 +1740,18 @@
 # This test should come last because the
 # smbpasswd SAM is only used if another format
 # has not been defined
+with_smbpasswd_sam=yes
+#smbpasswd SAM is always compiled 
+#Use : sam database = ldap  ... to Change the SAM Database /*MX*/
 AC_MSG_CHECKING(whether to use traditional smbpasswd file)
-if test $with_smbpasswd_sam = yes; then
+#if test $with_smbpasswd_sam = yes; then
        AC_MSG_RESULT(yes)
        AC_DEFINE(WITH_SMBPASSWD_SAM)
-       PDBEDIT=""
-else
-       AC_MSG_RESULT(no)
-       PDBEDIT=bin/pdbedit
-fi
+#      PDBEDIT=""
+#else
+#      AC_MSG_RESULT(no)
+#      PDBEDIT=bin/pdbedit
+#fi
 
 ########################################################################################
 ##
diff -urN samba-2.2.2/source/include/proto.h samba-2.2.2-MX/source/include/proto.h
--- samba-2.2.2/source/include/proto.h  Sat Oct 13 23:09:22 2001
+++ samba-2.2.2-MX/source/include/proto.h       Tue Oct 30 12:12:45 2001
@@ -1724,6 +1724,7 @@
 void lp_talloc_free(void);
 char *lp_logfile(void);
 char *lp_configfile(void);
+int  lp_samdb(void);
 char *lp_tdb_passwd_file(void);
 char *lp_smb_passwd_file(void);
 char *lp_serverstring(void);
diff -urN samba-2.2.2/source/include/samdb.h samba-2.2.2-MX/source/include/samdb.h
--- samba-2.2.2/source/include/samdb.h  Thu Jan  1 01:00:00 1970
+++ samba-2.2.2-MX/source/include/samdb.h       Tue Oct 30 16:12:35 2001
@@ -0,0 +1,84 @@
+/* 
+   Unix SMB/Netbios implementation.
+   Version 1.0.
+   SMB parameters and setup
+   Copyright (C) Stefan Metzmacher              2001
+
+   
+   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.
+*/
+
+/*MX : Change SAM Database in /etc/smb.conf */
+
+#define SAM_Files 0
+BOOL files_pdb_setsampwent(BOOL update);
+void files_pdb_endsampwent(void);
+BOOL files_pdb_getsampwent(SAM_ACCOUNT * user);
+BOOL files_pdb_getsampwnam(SAM_ACCOUNT * user, char *sname);
+BOOL files_pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid);
+BOOL files_pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid);
+BOOL files_pdb_delete_sam_account(char *sname);
+BOOL files_pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override);
+BOOL files_pdb_add_sam_account(SAM_ACCOUNT * newpwd);
+
+#ifdef WITH_LDAP_SAM
+#define SAM_LDAP 2
+BOOL ldap_pdb_setsampwent(BOOL update);
+void ldap_pdb_endsampwent(void);
+BOOL ldap_pdb_getsampwent(SAM_ACCOUNT * user);
+BOOL ldap_pdb_getsampwnam(SAM_ACCOUNT * user, char *sname);
+BOOL ldap_pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid);
+BOOL ldap_pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid);
+BOOL ldap_pdb_delete_sam_account(char *sname);
+BOOL ldap_pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override);
+BOOL ldap_pdb_add_sam_account(SAM_ACCOUNT * newpwd);
+#endif
+
+#ifdef WITH_NISPLUS_SAM
+#define SAM_NISPLUS 3
+BOOL nisplus_pdb_setsampwent(BOOL update);
+void nisplus_pdb_endsampwent(void);
+BOOL nisplus_pdb_getsampwent(SAM_ACCOUNT * user);
+BOOL nisplus_pdb_getsampwnam(SAM_ACCOUNT * user, char *sname);
+BOOL nisplus_pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid);
+BOOL nisplus_pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid);
+BOOL nisplus_pdb_delete_sam_account(char *sname);
+BOOL nisplus_pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override);
+BOOL nisplus_pdb_add_sam_account(SAM_ACCOUNT * newpwd);
+#endif
+
+#ifdef WITH_TDB_SAM
+#define SAM_TDB 1
+BOOL tdb_pdb_setsampwent(BOOL update);
+void tdb_pdb_endsampwent(void);
+BOOL tdb_pdb_getsampwent(SAM_ACCOUNT * user);
+BOOL tdb_pdb_getsampwnam(SAM_ACCOUNT * user, char *sname);
+BOOL tdb_pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid);
+BOOL tdb_pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid);
+BOOL tdb_pdb_delete_sam_account(char *sname);
+BOOL tdb_pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override);
+BOOL tdb_pdb_add_sam_account(SAM_ACCOUNT * newpwd);
+#endif
+
+/*
+BOOL pdb_setsampwent(BOOL update);
+void pdb_endsampwent(void);
+BOOL pdb_getsampwent(SAM_ACCOUNT * user);
+BOOL pdb_getsampwnam(SAM_ACCOUNT * user, char *sname);
+BOOL pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid);
+BOOL pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid);
+BOOL pdb_delete_sam_account(char *sname);
+BOOL pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override);
+BOOL pdb_add_sam_account(SAM_ACCOUNT * newpwd);*/
diff -urN samba-2.2.2/source/param/loadparm.c samba-2.2.2-MX/source/param/loadparm.c
--- samba-2.2.2/source/param/loadparm.c Sat Oct 13 23:09:31 2001
+++ samba-2.2.2-MX/source/param/loadparm.c      Tue Oct 30 12:06:34 2001
@@ -96,6 +96,7 @@
 
 static BOOL defaults_saved = False;
 
+#include "samdb.h"
 /* 
  * This structure describes global (ie., server-wide) parameters.
  */
@@ -118,11 +119,11 @@
        char *szPasswdChat;
        char *szLogFile;
        char *szConfigFile;
+       int  SAMDB;
 #ifdef WITH_TDB_SAM
        char *szTDBPasswdFile;
-#else
-       char *szSMBPasswdFile;
 #endif
+       char *szSMBPasswdFile;
        char *szPasswordServer;
        char *szSocketOptions;
        char *szValidChars;
@@ -563,6 +564,20 @@
        {-1, NULL}
 };
 
+static struct enum_list enum_samdb[] = {
+       {SAM_Files, "files"},
+#ifdef WITH_TDB_SAM 
+       {SAM_TDB, "tdb"},
+#endif
+#ifdef WITH_LDAP_SAM
+       {SAM_LDAP, "ldap"},
+#endif
+#ifdef WITH_NISPLUS_SAM
+       {SAM_NISPLUS, "nisplus"},
+#endif
+       {-1, NULL}
+};
+
 static struct enum_list enum_printing[] = {
        {PRINT_SYSV, "sysv"},
        {PRINT_AIX, "aix"},
@@ -699,11 +714,11 @@
        {"null passwords", P_BOOL, P_GLOBAL, &Globals.bNullPasswords, NULL, NULL, 0},
        {"obey pam restrictions", P_BOOL, P_GLOBAL, &Globals.bObeyPamRestrictions, NULL, NULL, 0},
        {"password server", P_STRING, P_GLOBAL, &Globals.szPasswordServer, NULL, NULL, 0},
+       {"sam database", P_ENUM, P_GLOBAL, &Globals.SAMDB, NULL, enum_samdb, 0},
 #ifdef WITH_TDB_SAM
        {"tdb passwd file", P_STRING, P_GLOBAL, &Globals.szTDBPasswdFile, NULL, NULL, 0},
-#else
-       {"smb passwd file", P_STRING, P_GLOBAL, &Globals.szSMBPasswdFile, NULL, NULL, 0},
 #endif
+       {"smb passwd file", P_STRING, P_GLOBAL, &Globals.szSMBPasswdFile, NULL, NULL, 0},
        {"root directory", P_STRING, P_GLOBAL, &Globals.szRootdir, NULL, NULL, 0},
        {"root dir", P_STRING, P_GLOBAL, &Globals.szRootdir, NULL, NULL, 0},
        {"root", P_STRING, P_GLOBAL, &Globals.szRootdir, NULL, NULL, 0},
@@ -1207,11 +1222,13 @@
 
        DEBUG(3, ("Initialising global parameters\n"));
 
+
+       Globals.SAMDB = SAM_Files;
 #ifdef WITH_TDB_SAM
        string_set(&Globals.szTDBPasswdFile, TDB_PASSWD_FILE);
-#else
-       string_set(&Globals.szSMBPasswdFile, SMB_PASSWD_FILE);
 #endif
+       string_set(&Globals.szSMBPasswdFile, SMB_PASSWD_FILE);
+
        /*
        * Allow the default PASSWD_CHAT to be overridden in local.h.
        */
@@ -1457,11 +1474,11 @@
 
 FN_GLOBAL_STRING(lp_logfile, &Globals.szLogFile)
 FN_GLOBAL_STRING(lp_configfile, &Globals.szConfigFile)
+FN_GLOBAL_INTEGER(lp_samdb, &Globals.SAMDB)
 #ifdef WITH_TDB_SAM
 FN_GLOBAL_STRING(lp_tdb_passwd_file, &Globals.szTDBPasswdFile)
-#else
-FN_GLOBAL_STRING(lp_smb_passwd_file, &Globals.szSMBPasswdFile)
 #endif
+FN_GLOBAL_STRING(lp_smb_passwd_file, &Globals.szSMBPasswdFile)
 FN_GLOBAL_STRING(lp_serverstring, &Globals.szServerString)
 FN_GLOBAL_STRING(lp_printcapname, &Globals.szPrintcapname)
 FN_GLOBAL_STRING(lp_enumports_cmd, &Globals.szEnumPortsCommand)
@@ -3680,9 +3697,9 @@
 
 #ifdef WITH_TDB_SAM
        pstrcpy(priv_dir, lp_tdb_passwd_file());
-#else
-       pstrcpy(priv_dir, lp_smb_passwd_file());
 #endif
+       pstrcpy(priv_dir, lp_smb_passwd_file());
+
 
        p = strrchr(priv_dir, '/');
        if (p)  *p = 0;
diff -urN samba-2.2.2/source/passdb/passdb.c samba-2.2.2-MX/source/passdb/passdb.c
--- samba-2.2.2/source/passdb/passdb.c  Sat Oct 13 23:09:31 2001
+++ samba-2.2.2-MX/source/passdb/passdb.c       Tue Oct 30 12:18:56 2001
@@ -33,6 +33,8 @@
 
 extern DOM_SID global_sam_sid;
 
+#include "samdb.h"
+
 struct passdb_ops *pdb_ops;
 
 #if 0  /* JERRY */
@@ -1666,3 +1668,239 @@
 
        return True;
 }
+
+/*MX: Change SAM Database in /etc/smb.conf : sam database = files */
+
+
+BOOL pdb_setsampwent(BOOL update)
+{
+   DEBUG(2,("SAM_DB: %i\n",lp_samdb()));
+   switch(lp_samdb()){
+#ifdef WITH_LDAP_SAM
+       case SAM_LDAP:
+       return  ldap_pdb_setsampwent(update);
+       break;
+#endif
+#ifdef WITH_TDB_SAM
+       case SAM_TDB:
+       return  tdb_pdb_setsampwent(update);
+       break;
+#endif
+#ifdef WITH_NISPLUS_SAM
+       case SAM_NISPLUS:
+       return  nisplus_pdb_setsampwent(update);
+       break;
+#endif
+       default:
+       return files_pdb_setsampwent(update);
+       break;
+       };      
+};
+
+
+void pdb_endsampwent(void)
+{
+   DEBUG(2,("SAM_DB: %i\n",lp_samdb()));
+   switch(lp_samdb()){
+#ifdef WITH_LDAP_SAM
+       case SAM_LDAP:
+       ldap_pdb_endsampwent();
+       break;
+#endif
+#ifdef WITH_TDB_SAM
+       case SAM_TDB:
+       tdb_pdb_endsampwent();
+       break;
+#endif
+#ifdef WITH_NISPLUS_SAM
+       case SAM_NISPLUS:
+       nisplus_pdb_endsampwent();
+       break;
+#endif
+       default:
+       files_pdb_endsampwent();
+       break;
+       };      
+};
+
+
+BOOL pdb_getsampwent(SAM_ACCOUNT * user)
+{
+   DEBUG(2,("SAM_DB: %i\n",lp_samdb()));
+   switch(lp_samdb()){
+#ifdef WITH_LDAP_SAM
+       case SAM_LDAP:
+       return  ldap_pdb_getsampwent(user);
+       break;
+#endif
+#ifdef WITH_TDB_SAM
+       case SAM_TDB:
+       return  tdb_pdb_getsampwent(user);
+       break;
+#endif
+#ifdef WITH_NISPLUS_SAM
+       case SAM_NISPLUS:
+       return  nisplus_pdb_getsampwent(user);
+       break;
+#endif
+       default:
+       return files_pdb_getsampwent(user);
+       break;
+       };      
+};
+
+
+BOOL pdb_getsampwnam(SAM_ACCOUNT * user, char *sname)
+{
+   DEBUG(2,("SAM_DB: %i\n",lp_samdb()));
+   switch(lp_samdb()){
+#ifdef WITH_LDAP_SAM
+       case SAM_LDAP:
+       return  ldap_pdb_getsampwnam(user,sname);
+       break;
+#endif
+#ifdef WITH_TDB_SAM
+       case SAM_TDB:
+       return  tdb_pdb_getsampwnam(user,sname);
+       break;
+#endif
+#ifdef WITH_NISPLUS_SAM
+       case SAM_NISPLUS:
+       return  nisplus_pdb_getsampwnam(user,sname);
+       break;
+#endif
+       default:
+       return files_pdb_getsampwnam(user,sname);
+       break;
+       };      
+};
+
+
+BOOL pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid)
+{
+   DEBUG(2,("SAM_DB: %i\n",lp_samdb()));
+   switch(lp_samdb()){
+#ifdef WITH_LDAP_SAM
+       case SAM_LDAP:
+       return  ldap_pdb_getsampwrid(user,rid);
+       break;
+#endif
+#ifdef WITH_TDB_SAM
+       case SAM_TDB:
+       return  tdb_pdb_getsampwrid(user,rid);
+       break;
+#endif
+#ifdef WITH_NISPLUS_SAM
+       case SAM_NISPLUS:
+       return  nisplus_pdb_getsampwrid(user,rid);
+       break;
+#endif
+       default:
+       return files_pdb_getsampwrid(user,rid);
+       break;
+       };      
+};
+
+
+BOOL pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid)
+{
+   DEBUG(2,("SAM_DB: %i\n",lp_samdb()));
+   switch(lp_samdb()){
+#ifdef WITH_LDAP_SAM
+       case SAM_LDAP:
+       return  ldap_pdb_getsampwuid(user,uid);
+       break;
+#endif
+#ifdef WITH_TDB_SAM
+       case SAM_TDB:
+       return  tdb_pdb_getsampwuid(user,uid);
+       break;
+#endif
+#ifdef WITH_NISPLUS_SAM
+       case SAM_NISPLUS:
+       return  nisplus_pdb_getsampwuid(user,uid);
+       break;
+#endif
+       default:
+       return files_pdb_getsampwuid(user,uid);
+       break;
+       };      
+};
+
+
+BOOL pdb_delete_sam_account(char *sname)
+{
+   DEBUG(2,("SAM_DB: %i\n",lp_samdb()));
+   switch(lp_samdb()){
+#ifdef WITH_LDAP_SAM
+       case SAM_LDAP:
+       return  ldap_pdb_delete_sam_account(sname);
+       break;
+#endif
+#ifdef WITH_TDB_SAM
+       case SAM_TDB:
+       return  tdb_pdb_delete_sam_account(sname);
+       break;
+#endif
+#ifdef WITH_NISPLUS_SAM
+       case SAM_NISPLUS:
+       return  nisplus_pdb_delete_sam_account(sname);
+       break;
+#endif
+       default:
+       return files_pdb_delete_sam_account(sname);
+       break;
+       };      
+};
+
+
+BOOL pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override)
+{
+   DEBUG(2,("SAM_DB: %i\n",lp_samdb()));
+   switch(lp_samdb()){
+#ifdef WITH_LDAP_SAM
+       case SAM_LDAP:
+       return  ldap_pdb_update_sam_account(newpwd,override);
+       break;
+#endif
+#ifdef WITH_TDB_SAM
+       case SAM_TDB:
+       return  tdb_pdb_update_sam_account(newpwd,override);
+       break;
+#endif
+#ifdef WITH_NISPLUS_SAM
+       case SAM_NISPLUS:
+       return  nisplus_pdb_update_sam_account(newpwd,override);
+       break;
+#endif
+       default:
+       return files_pdb_update_sam_account(newpwd,override);
+       break;
+       };      
+};
+
+
+BOOL pdb_add_sam_account(SAM_ACCOUNT * newpwd)
+{
+   DEBUG(2,("SAM_DB: %i\n",lp_samdb()));
+   switch(lp_samdb()){
+#ifdef WITH_LDAP_SAM
+       case SAM_LDAP:
+       return  ldap_pdb_add_sam_account(newpwd);
+       break;
+#endif
+#ifdef WITH_TDB_SAM
+       case SAM_TDB:
+       return  tdb_pdb_add_sam_account(newpwd);
+       break;
+#endif
+#ifdef WITH_NISPLUS_SAM
+       case SAM_NISPLUS:
+       return  nisplus_pdb_add_sam_account(newpwd);
+       break;
+#endif
+       default:
+       return files_pdb_add_sam_account(newpwd);
+       break;
+       };      
+};
diff -urN samba-2.2.2/source/passdb/pdb_ldap.c samba-2.2.2-MX/source/passdb/pdb_ldap.c
--- samba-2.2.2/source/passdb/pdb_ldap.c        Thu Oct 11 11:40:00 2001
+++ samba-2.2.2-MX/source/passdb/pdb_ldap.c     Tue Oct 30 13:43:51 2001
@@ -599,7 +599,7 @@
 /**********************************************************************
 Connect to LDAP server for password enumeration
 *********************************************************************/
-BOOL pdb_setsampwent(BOOL update)
+BOOL ldap_pdb_setsampwent(BOOL update)
 {
        int rc;
        pstring filter;
@@ -645,7 +645,7 @@
 /**********************************************************************
 End enumeration of the LDAP password list 
 *********************************************************************/
-void pdb_endsampwent(void)
+void ldap_pdb_endsampwent(void)
 {
        if (global_ldap_ent.ldap_struct && global_ldap_ent.result)
        {
@@ -659,7 +659,7 @@
 /**********************************************************************
 Get the next entry in the LDAP password database 
 *********************************************************************/
-BOOL pdb_getsampwent(SAM_ACCOUNT * user)
+BOOL ldap_pdb_getsampwent(SAM_ACCOUNT * user)
 {
        if (!global_ldap_ent.entry)
                return False;
@@ -678,7 +678,7 @@
 /**********************************************************************
 Get SAM_ACCOUNT entry from LDAP by username 
 *********************************************************************/
-BOOL pdb_getsampwnam(SAM_ACCOUNT * user, char *sname)
+BOOL ldap_pdb_getsampwnam(SAM_ACCOUNT * user, char *sname)
 {
        LDAP *ldap_struct;
        LDAPMessage *result;
@@ -724,7 +724,7 @@
 /**********************************************************************
 Get SAM_ACCOUNT entry from LDAP by rid 
 *********************************************************************/
-BOOL pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid)
+BOOL ldap_pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid)
 {
        LDAP *ldap_struct;
        LDAPMessage *result;
@@ -773,7 +773,7 @@
 /**********************************************************************
  Get SAM_ACCOUNT entry from LDAP by uid 
 *********************************************************************/
-BOOL pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid)
+BOOL ldap_pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid)
 {
        LDAP *ldap_struct;
        LDAPMessage *result;
@@ -822,7 +822,7 @@
 /**********************************************************************
 Delete entry from LDAP for username 
 *********************************************************************/
-BOOL pdb_delete_sam_account(char *sname)
+BOOL ldap_pdb_delete_sam_account(char *sname)
 {
        int rc;
        char *dn;
@@ -873,7 +873,7 @@
 /**********************************************************************
 Update SAM_ACCOUNT 
 *********************************************************************/
-BOOL pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override)
+BOOL ldap_pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override)
 {
        int rc;
        char *dn;
@@ -934,7 +934,7 @@
 /**********************************************************************
 Add SAM_ACCOUNT to LDAP 
 *********************************************************************/
-BOOL pdb_add_sam_account(SAM_ACCOUNT * newpwd)
+BOOL ldap_pdb_add_sam_account(SAM_ACCOUNT * newpwd)
 {
        int rc;
        pstring filter;
diff -urN samba-2.2.2/source/passdb/pdb_nisplus.c samba-2.2.2-MX/source/passdb/pdb_nisplus.c
--- samba-2.2.2/source/passdb/pdb_nisplus.c     Thu Oct 11 11:40:00 2001
+++ samba-2.2.2-MX/source/passdb/pdb_nisplus.c  Tue Oct 30 08:00:43 2001
@@ -882,7 +882,7 @@
 /***************************************************************
  Start to enumerate the nisplus passwd list.
  ****************************************************************/
-BOOL pdb_setsampwent(BOOL update)
+BOOL nisplus_pdb_setsampwent(BOOL update)
 {
        char *sp, * p = lp_smb_passwd_file();
        pstring pfiletmp;
@@ -902,7 +902,7 @@
 /***************************************************************
  End enumeration of the nisplus passwd list.
 ****************************************************************/
-void pdb_endsampwent(void)
+void nisplus_pdb_endsampwent(void)
 {
   if( global_nisp_ent.result )
     nis_freeresult(global_nisp_ent.result);
@@ -913,7 +913,7 @@
 /*************************************************************************
  Routine to return the next entry in the nisplus passwd list.
  *************************************************************************/
-BOOL pdb_getsampwent(SAM_ACCOUNT *user)
+BOOL nisplus_pdb_getsampwent(SAM_ACCOUNT *user)
 {
   int enum_entry = (int)(global_nisp_ent.enum_entry);
   nis_result *result = global_nisp_ent.result;
@@ -941,7 +941,7 @@
 /*************************************************************************
  Routine to search the nisplus passwd file for an entry matching the username
  *************************************************************************/
-BOOL pdb_getsampwnam(SAM_ACCOUNT * user, char *sname)
+BOOL nisplus_pdb_getsampwnam(SAM_ACCOUNT * user, char *sname)
 {
        /* Static buffers we will return. */
        nis_result *result = NULL;
@@ -977,7 +977,7 @@
 /*************************************************************************
  Routine to search the nisplus passwd file for an entry matching the username
  *************************************************************************/
-BOOL pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid)
+BOOL nisplus_pdb_getsampwrid(SAM_ACCOUNT * user, uint32 rid)
 {
        nis_result *result;
        char *nisname;
@@ -1017,7 +1017,7 @@
 /*************************************************************************
  Routine to search the nisplus passwd file for an entry matching the username
  *************************************************************************/
-BOOL pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid)
+BOOL nisplus_pdb_getsampwuid(SAM_ACCOUNT * user, uid_t uid)
 {
        nis_result *result;
        char *nisname;
@@ -1057,7 +1057,7 @@
 /*************************************************************************
  Routine to remove entry from the nisplus smbpasswd table
  *************************************************************************/
-BOOL pdb_delete_sam_account(char *sname)
+BOOL nisplus_pdb_delete_sam_account(char *sname)
 {
   char *pfile = lp_smb_passwd_file();
   pstring nisname;
@@ -1113,7 +1113,7 @@
 /************************************************************************
  Routine to add an entry to the nisplus passwd file.
 *************************************************************************/
-BOOL pdb_add_sam_account(SAM_ACCOUNT * newpwd)
+BOOL nisplus_pdb_add_sam_account(SAM_ACCOUNT * newpwd)
 {
   int local_user = 0;
   char           *pfile;
@@ -1308,7 +1308,7 @@
 /************************************************************************
  Routine to modify the nisplus passwd entry.
 ************************************************************************/
-BOOL pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override)
+BOOL nisplus_pdb_update_sam_account(SAM_ACCOUNT * newpwd, BOOL override)
 {
   nis_result *result, *addresult;
   nis_object *obj;
diff -urN samba-2.2.2/source/passdb/pdb_smbpasswd.c samba-2.2.2-MX/source/passdb/pdb_smbpasswd.c
--- samba-2.2.2/source/passdb/pdb_smbpasswd.c   Thu Oct 11 11:40:01 2001
+++ samba-2.2.2-MX/source/passdb/pdb_smbpasswd.c        Tue Oct 30 07:54:40 2001
@@ -1259,7 +1259,7 @@
 /*****************************************************************
  Functions to be implemented by the new passdb API 
  ****************************************************************/
-BOOL pdb_setsampwent (BOOL update)
+BOOL files_pdb_setsampwent (BOOL update)
 {
        global_vp = startsmbfilepwent(lp_smb_passwd_file(), 
                                update ? PWF_UPDATE : PWF_READ, 
@@ -1287,14 +1287,14 @@
        return (global_vp != NULL);                
 }
 
-void pdb_endsampwent (void)
+void files_pdb_endsampwent (void)
 {
        endsmbfilepwent(global_vp, &pw_file_lock_depth);
 }
  
 /*****************************************************************
  ****************************************************************/
-BOOL pdb_getsampwent(SAM_ACCOUNT *user)
+BOOL files_pdb_getsampwent(SAM_ACCOUNT *user)
 {
        struct smb_passwd *pw_buf=NULL;
        BOOL done = False;
@@ -1334,7 +1334,7 @@
  call getpwnam() for unix account information until we have found
  the correct entry
  ***************************************************************/
-BOOL pdb_getsampwnam(SAM_ACCOUNT *sam_acct, char *username)
+BOOL files_pdb_getsampwnam(SAM_ACCOUNT *sam_acct, char *username)
 {
        struct smb_passwd *smb_pw;
        void *fp = NULL;
@@ -1403,7 +1403,7 @@
 }
 
 
-BOOL pdb_getsampwuid (SAM_ACCOUNT *sam_acct, uid_t uid)
+BOOL files_pdb_getsampwuid (SAM_ACCOUNT *sam_acct, uid_t uid)
 {
        struct smb_passwd *smb_pw;
        void *fp = NULL;
@@ -1445,7 +1445,7 @@
        return True;
 }
 
-BOOL pdb_getsampwrid(SAM_ACCOUNT *sam_acct,uint32 rid)
+BOOL files_pdb_getsampwrid(SAM_ACCOUNT *sam_acct,uint32 rid)
 {
        struct smb_passwd *smb_pw;
        void *fp = NULL;
@@ -1488,7 +1488,7 @@
        return True;
 }
 
-BOOL pdb_add_sam_account(SAM_ACCOUNT *sampass)
+BOOL files_pdb_add_sam_account(SAM_ACCOUNT *sampass)
 {
        struct smb_passwd smb_pw;
        
@@ -1502,7 +1502,7 @@
        return True;
 }
 
-BOOL pdb_update_sam_account(SAM_ACCOUNT *sampass, BOOL override)
+BOOL files_pdb_update_sam_account(SAM_ACCOUNT *sampass, BOOL override)
 {
        struct smb_passwd smb_pw;
        
@@ -1516,7 +1516,7 @@
        return True;
 }
 
-BOOL pdb_delete_sam_account (char* username)
+BOOL files_pdb_delete_sam_account (char* username)
 {
        return del_smbfilepwd_entry(username);
 }
diff -urN samba-2.2.2/source/passdb/pdb_tdb.c samba-2.2.2-MX/source/passdb/pdb_tdb.c
--- samba-2.2.2/source/passdb/pdb_tdb.c Thu Oct 11 11:40:02 2001
+++ samba-2.2.2-MX/source/passdb/pdb_tdb.c      Tue Oct 30 07:58:52 2001
@@ -382,7 +382,7 @@
  Open the TDB passwd database for SAM account enumeration.
 ****************************************************************/
 
-BOOL pdb_setsampwent(BOOL update)
+BOOL tdb_pdb_setsampwent(BOOL update)
 {
        pstring         tdbfile;
        
@@ -405,7 +405,7 @@
  End enumeration of the TDB passwd list.
 ****************************************************************/
 
-void pdb_endsampwent(void)
+void tdb_pdb_endsampwent(void)
 {
        if (global_tdb_ent.passwd_tdb) {
                tdb_close(global_tdb_ent.passwd_tdb);
@@ -419,7 +419,7 @@
  Get one SAM_ACCOUNT from the TDB (next in line)
 *****************************************************************/
 
-BOOL pdb_getsampwent(SAM_ACCOUNT *user)
+BOOL tdb_pdb_getsampwent(SAM_ACCOUNT *user)
 {
        TDB_DATA        data;
        struct passwd   *pw;
@@ -489,7 +489,7 @@
  Lookup a name in the SAM TDB
 ******************************************************************/
 
-BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname)
+BOOL tdb_pdb_getsampwnam (SAM_ACCOUNT *user, char *sname)
 {
        TDB_CONTEXT     *pwd_tdb;
        TDB_DATA        data, key;
@@ -572,7 +572,7 @@
  Search by uid
  **************************************************************************/
 
-BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid)
+BOOL tdb_pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid)
 {
        struct passwd   *pw;
        fstring         name;
@@ -597,7 +597,7 @@
  Search by rid
  **************************************************************************/
 
-BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid)
+BOOL tdb_pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid)
 {
        TDB_CONTEXT             *pwd_tdb;
        TDB_DATA                data, key;
@@ -645,7 +645,7 @@
  Delete a SAM_ACCOUNT
 ****************************************************************************/
 
-BOOL pdb_delete_sam_account(char *sname)
+BOOL tdb_pdb_delete_sam_account(char *sname)
 {
        SAM_ACCOUNT     *sam_pass = NULL;
        TDB_CONTEXT     *pwd_tdb;
@@ -823,7 +823,7 @@
  Modifies an existing SAM_ACCOUNT
 ****************************************************************************/
 
-BOOL pdb_update_sam_account (SAM_ACCOUNT *newpwd, BOOL override)
+BOOL tdb_pdb_update_sam_account (SAM_ACCOUNT *newpwd, BOOL override)
 {
        return (tdb_update_sam(newpwd, override, TDB_MODIFY));
 }
@@ -832,7 +832,7 @@
  Adds an existing SAM_ACCOUNT
 ****************************************************************************/
 
-BOOL pdb_add_sam_account (SAM_ACCOUNT *newpwd)
+BOOL tdb_pdb_add_sam_account (SAM_ACCOUNT *newpwd)
 {
        return (tdb_update_sam(newpwd, True, TDB_INSERT));
 }
diff -urN samba-2.2.2/source/utils/smbpasswd.c samba-2.2.2-MX/source/utils/smbpasswd.c
--- samba-2.2.2/source/utils/smbpasswd.c        Sat Oct 13 23:09:44 2001
+++ samba-2.2.2-MX/source/utils/smbpasswd.c     Tue Oct 30 23:35:44 2001
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 
+#include "samdb.h"
 extern pstring global_myname;
 extern int DEBUGLEVEL;
 
@@ -664,13 +665,16 @@
        argv += optind;
 
 #ifdef WITH_LDAP_SAM
-       if (local_flags & LOCAL_SET_LDAP_ADMIN_PW)
+       if (lp_samdb()==SAM_LDAP)
        {
+       if (local_flags & LOCAL_SET_LDAP_ADMIN_PW)
+       {
                printf("Setting stored password for \"%s\" in secrets.tdb\n", 
                        lp_ldap_admin_dn());
                if (!store_ldap_admin_pw(ldap_secret))
                        DEBUG(0,("ERROR: Failed to store the ldap admin password!\n"));
                goto done;
+       }
        }
 #endif


-------------------------------------------------------------------------------------------------------------------------------------------

MfG
Stefan Metzmacher

stefan.metzmacher at metzemix.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: samba-2.2.2-MX-samdb.patch
Type: application/octet-stream
Size: 30919 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20011219/d4a9669e/samba-2.2.2-MX-samdb.obj


More information about the samba-technical mailing list