summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--source4/Makefile46
-rw-r--r--source4/build/m4/public.m47
-rw-r--r--source4/build/smb_build/makefile.pm7
-rw-r--r--source4/lib/samba3/config.mk14
-rw-r--r--source4/lib/samba3/group.c141
-rw-r--r--source4/lib/samba3/idmap.c98
-rw-r--r--source4/lib/samba3/policy.c50
-rw-r--r--source4/lib/samba3/registry.c147
-rw-r--r--source4/lib/samba3/samba3.c132
-rw-r--r--source4/lib/samba3/samba3.h1
-rw-r--r--source4/lib/samba3/secrets.c263
-rw-r--r--source4/lib/samba3/share_info.c89
-rw-r--r--source4/lib/samba3/smbpasswd.c139
-rw-r--r--source4/lib/samba3/tdbsam.c263
-rw-r--r--source4/lib/samba3/winsdb.c160
-rw-r--r--source4/lib/talloc/config.mk2
-rw-r--r--source4/lib/talloc/talloc.c197
-rw-r--r--source4/lib/talloc/talloc.h1
-rw-r--r--source4/lib/talloc/testsuite.c37
-rw-r--r--source4/lib/tls/config.m44
-rw-r--r--source4/libnet/config.mk2
-rw-r--r--source4/pidl/config.mk36
-rw-r--r--source4/rules.mk1
-rw-r--r--source4/scripting/ejs/config.mk7
-rw-r--r--source4/scripting/ejs/smbcalls_samba3.c501
-rwxr-xr-xsource4/selftest/samba4_tests.sh3
-rw-r--r--source4/torture/config.mk4
-rwxr-xr-xtestdata/samba3/verify59
-rwxr-xr-xtestprogs/ejs/samba3sam.js1255
30 files changed, 288 insertions, 3379 deletions
diff --git a/.gitignore b/.gitignore
index 7a093f5205..e51be509ed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+source/mkconfig.mk
source/test-results
source/lib/gencache/gencache.h
source/lib/ldb/bin
diff --git a/source4/Makefile b/source4/Makefile
index 3aebc831af..a5f32e19d6 100644
--- a/source4/Makefile
+++ b/source4/Makefile
@@ -1,4 +1,6 @@
#!gmake
+# The Samba 4 Makefile.
+# This file is *NOT* autogenerated.
include mkconfig.mk
@@ -68,8 +70,8 @@ showflags::
# The permissions to give the executables
INSTALLPERMS = 0755
-install:: showlayout everything installbin installdat installswat installmisc installlib \
- installheader installpc installplugins
+install:: showlayout everything installbin installdat installswat installmisc \
+ installlib installheader installpc installplugins
# DESTDIR is used here to prevent packagers wasting their time
# duplicating the Makefile. Remove it and you will have the privilege
@@ -162,44 +164,16 @@ uninstallheader::
uninstallman::
@$(SHELL) $(srcdir)/script/uninstallman.sh $(DESTDIR)$(mandir) $(MANPAGES)
+config.status:
+ @echo "config.status does not exist. Please run ./configure."
+ @/bin/false
+
data.mk: config.status $(MK_FILES)
./config.status
-pidl/Makefile: pidl/Makefile.PL
- cd pidl && $(PERL) Makefile.PL
-
-testcov-html:: pidl-testcov
-
-pidl-testcov: pidl/Makefile
- cd pidl && cover -test
-
-installpidl:: pidl/Makefile
- $(MAKE) -C pidl install
-
-uninstallpidl:: pidl/Makefile
- $(MAKE) -C pidl uninstall
-
-$(IDL_HEADER_FILES) \
- $(IDL_NDR_PARSE_H_FILES) $(IDL_NDR_PARSE_C_FILES) \
- $(IDL_NDR_CLIENT_C_FILES) $(IDL_NDR_CLIENT_H_FILES) \
- $(IDL_NDR_SERVER_C_FILES) $(IDL_SWIG_FILES) \
- $(IDL_NDR_EJS_C_FILES) $(IDL_NDR_EJS_H_FILES) \
- $(IDL_NDR_PY_C_FILES) $(IDL_NDR_PY_H_FILES): idl
-
-idl_full:: pidl/lib/Parse/Pidl/IDL.pm pidl/lib/Parse/Pidl/Expr.pm
- @CPP="$(CPP)" PERL="$(PERL)" srcdir=$(srcdir) $(srcdir)/script/build_idl.sh FULL
-
-idl:: pidl/lib/Parse/Pidl/IDL.pm pidl/lib/Parse/Pidl/Expr.pm
- @CPP="$(CPP)" PERL="$(PERL)" srcdir=$(srcdir) $(srcdir)/script/build_idl.sh PARTIAL
-
-pidl/lib/Parse/Pidl/IDL.pm: pidl/idl.yp
- -$(YAPP) -m 'Parse::Pidl::IDL' -o pidl/lib/Parse/Pidl/IDL.pm pidl/idl.yp ||\
- touch pidl/lib/Parse/Pidl/IDL.pm
-
-pidl/lib/Parse/Pidl/Expr.pm: pidl/idl.yp
- -$(YAPP) -m 'Parse::Pidl::Expr' -o pidl/lib/Parse/Pidl/Expr.pm pidl/expr.yp ||\
- touch pidl/lib/Parse/Pidl/Expr.pm
+testcov-html::
+include pidl/config.mk
include selftest/config.mk
include rules.mk
diff --git a/source4/build/m4/public.m4 b/source4/build/m4/public.m4
index 467b63055c..e8fbe4b286 100644
--- a/source4/build/m4/public.m4
+++ b/source4/build/m4/public.m4
@@ -24,6 +24,7 @@ AC_DEFUN([SMB_SUBSYSTEM],
MAKE_SETTINGS="$MAKE_SETTINGS
$1_OBJ_FILES = $2
$1_CFLAGS = $4
+$1_ENABLE = YES
"
SMB_INFO_SUBSYSTEMS="$SMB_INFO_SUBSYSTEMS
@@ -46,6 +47,7 @@ MAKE_SETTINGS="$MAKE_SETTINGS
$1_OBJ_FILES = $2
$1_CFLAGS = $6
$1_LDFLAGS = $7
+$1_ENABLE = YES
"
SMB_INFO_LIBRARIES="$SMB_INFO_LIBRARIES
@@ -162,8 +164,9 @@ PC_NAME = $6
dnl SMB_ENABLE(name,default_build)
AC_DEFUN([SMB_ENABLE],
[
- [SMB_ENABLE_][$1]="$2";
-
+ MAKE_SETTINGS="$MAKE_SETTINGS
+$1_ENABLE = $2
+"
SMB_INFO_ENABLES="$SMB_INFO_ENABLES
\$enabled{$1} = \"$2\";"
])
diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm
index 0393e2b258..50a16c543f 100644
--- a/source4/build/smb_build/makefile.pm
+++ b/source4/build/smb_build/makefile.pm
@@ -24,7 +24,6 @@ sub new($$$)
$self->{manpages} = [];
$self->{sbin_progs} = [];
$self->{bin_progs} = [];
- $self->{torture_progs} = [];
$self->{static_libs} = [];
$self->{python_dsos} = [];
$self->{python_pys} = [];
@@ -340,9 +339,6 @@ sub Binary($$)
my $installdir;
my $extradir = "";
- if (defined($ctx->{INSTALLDIR}) && $ctx->{INSTALLDIR} =~ /^TORTUREDIR/) {
- $extradir = "/torture" . substr($ctx->{INSTALLDIR}, length("TORTUREDIR"));
- }
my $localdir = "bin$extradir";
$installdir = "bin$extradir";
@@ -354,8 +350,6 @@ sub Binary($$)
push (@{$self->{sbin_progs}}, "$installdir/$ctx->{BINARY}");
} elsif ($ctx->{INSTALLDIR} eq "BINDIR") {
push (@{$self->{bin_progs}}, "$installdir/$ctx->{BINARY}");
- } elsif ($ctx->{INSTALLDIR} =~ /^TORTUREDIR/) {
- push (@{$self->{torture_progs}}, "$installdir/$ctx->{BINARY}");
}
push (@{$self->{binaries}}, "$localdir/$ctx->{BINARY}");
@@ -455,7 +449,6 @@ sub write($$)
$self->output("MANPAGES = ".array2oneperline($self->{manpages})."\n");
$self->output("BIN_PROGS = " . array2oneperline($self->{bin_progs}) . "\n");
$self->output("SBIN_PROGS = " . array2oneperline($self->{sbin_progs}) . "\n");
- $self->output("TORTURE_PROGS = " . array2oneperline($self->{torture_progs}) . "\n");
$self->output("BINARIES = " . array2oneperline($self->{binaries}) . "\n");
$self->output("STATIC_LIBS = " . array2oneperline($self->{static_libs}) . "\n");
$self->output("SHARED_LIBS = " . array2oneperline($self->{shared_libs}) . "\n");
diff --git a/source4/lib/samba3/config.mk b/source4/lib/samba3/config.mk
index 705bdd4002..2d129c5f8c 100644
--- a/source4/lib/samba3/config.mk
+++ b/source4/lib/samba3/config.mk
@@ -1,19 +1,5 @@
################################################
# Start SUBSYSTEM LIBSAMBA3
-[SUBSYSTEM::LIBSAMBA3]
-PRIVATE_PROTO_HEADER = samba3_proto.h
-PUBLIC_HEADERS = samba3.h
-OBJ_FILES = tdbsam.o policy.o \
- idmap.o winsdb.o samba3.o group.o \
- registry.o secrets.o share_info.o
-PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL LIBTDB NDR_SECURITY \
- SMBPASSWD LIBSECURITY
-PUBLIC_DEPENDENCIES = CREDENTIALS
-# End SUBSYSTEM LIBSAMBA3
-################################################
-
-################################################
-# Start SUBSYSTEM LIBSAMBA3
[SUBSYSTEM::SMBPASSWD]
PRIVATE_PROTO_HEADER = samba3_smbpasswd_proto.h
OBJ_FILES = smbpasswd.o
diff --git a/source4/lib/samba3/group.c b/source4/lib/samba3/group.c
deleted file mode 100644
index a0b4c15f0c..0000000000
--- a/source4/lib/samba3/group.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * RPC Pipe client / server routines
- * Copyright (C) Andrew Tridgell 1992-2000,
- * Copyright (C) Jean François Micouleau 1998-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 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "includes.h"
-#include "lib/samba3/samba3.h"
-#include "lib/tdb/include/tdb.h"
-#include "lib/util/util_tdb.h"
-#include "system/filesys.h"
-#include "libcli/security/security.h"
-
-#define DATABASE_VERSION_V1 1 /* native byte format. */
-#define DATABASE_VERSION_V2 2 /* le format. */
-
-#define GROUP_PREFIX "UNIXGROUP/"
-
-/* Alias memberships are stored reverse, as memberships. The performance
- * critical operation is to determine the aliases a SID is member of, not
- * listing alias members. So we store a list of alias SIDs a SID is member of
- * hanging of the member as key.
- */
-#define MEMBEROF_PREFIX "MEMBEROF/"
-
-/****************************************************************************
- Open the group mapping tdb.
-****************************************************************************/
-NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_groupdb *db)
-{
- int32_t vers_id;
- TDB_DATA kbuf, dbuf, newkey;
- int ret;
- TDB_CONTEXT *tdb;
-
- tdb = tdb_open(file, 0, TDB_DEFAULT, O_RDONLY, 0600);
- if (!tdb) {
- DEBUG(0,("Failed to open group mapping database\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Cope with byte-reversed older versions of the db. */
- vers_id = tdb_fetch_int32(tdb, "INFO/version");
- if ((vers_id == DATABASE_VERSION_V1) || (IREV(vers_id) == DATABASE_VERSION_V1)) {
- /* Written on a bigendian machine with old fetch_int code. Save as le. */
- vers_id = DATABASE_VERSION_V2;
- }
-
- if (vers_id != DATABASE_VERSION_V2) {
- DEBUG(0, ("Group database version mismatch: %d\n", vers_id));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- db->groupmappings = NULL;
- db->groupmap_count = 0;
- db->aliases = NULL;
- db->alias_count = 0;
-
- for (kbuf = tdb_firstkey(tdb);
- kbuf.dptr;
- newkey = tdb_nextkey(tdb, kbuf), free(kbuf.dptr), kbuf=newkey) {
- struct samba3_groupmapping map;
- const char *k = (const char *)kbuf.dptr;
-
- if (strncmp(k, GROUP_PREFIX, strlen(GROUP_PREFIX)) == 0)
- {
- dbuf = tdb_fetch(tdb, kbuf);
- if (!dbuf.dptr)
- continue;
-
- ZERO_STRUCT(map);
-
- map.sid = dom_sid_parse_talloc(ctx, k+strlen(GROUP_PREFIX));
-
- ret = tdb_unpack(tdb, (char *)dbuf.dptr, dbuf.dsize, "dd",
- &map.gid, &map.sid_name_use);
-
- if ( ret == -1 ) {
- DEBUG(3,("enum_group_mapping: tdb_unpack failure\n"));
- continue;
- }
-
- map.nt_name = talloc_strdup(ctx, (const char *)(dbuf.dptr+ret));
- map.comment = talloc_strdup(ctx, (const char *)(dbuf.dptr+ret+strlen(map.nt_name)));
-
- db->groupmappings = talloc_realloc(ctx, db->groupmappings, struct samba3_groupmapping, db->groupmap_count+1);
-
- if (!db->groupmappings)
- return NT_STATUS_NO_MEMORY;
-
- db->groupmappings[db->groupmap_count] = map;
-
- db->groupmap_count++;
- } else if (strncmp(k, MEMBEROF_PREFIX, strlen(MEMBEROF_PREFIX)) == 0)
- {
- struct samba3_alias alias;
- const char **member_strlist;
- int i;
-
- dbuf = tdb_fetch(tdb, kbuf);
- if (!dbuf.dptr)
- continue;
-
- alias.sid = dom_sid_parse_talloc(ctx, k+strlen(MEMBEROF_PREFIX));
- alias.member_count = 0;
- alias.members = NULL;
-
- member_strlist = str_list_make_shell(ctx, (const char *)dbuf.dptr, " ");
-
- for (i = 0; member_strlist[i]; i++) {
- alias.members = talloc_realloc(ctx, alias.members, struct dom_sid *, alias.member_count+1);
- alias.members[alias.member_count] = dom_sid_parse_talloc(ctx, member_strlist[i]);
- alias.member_count++;
- }
-
- talloc_free(member_strlist);
-
- db->aliases = talloc_realloc(ctx, db->aliases, struct samba3_alias, db->alias_count+1);
- db->aliases[db->alias_count] = alias;
- db->alias_count++;
- }
- }
-
- tdb_close(tdb);
-
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/samba3/idmap.c b/source4/lib/samba3/idmap.c
deleted file mode 100644
index 3eeb2931a8..0000000000
--- a/source4/lib/samba3/idmap.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- idmap TDB backend
-
- Copyright (C) Tim Potter 2000
- Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
- Copyright (C) Simo Sorce 2003
- Copyright (C) Jelmer Vernooij 2005
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "lib/tdb/include/tdb.h"
-#include "lib/util/util_tdb.h"
-#include "lib/samba3/samba3.h"
-#include "system/filesys.h"
-#include "libcli/security/security.h"
-
-/* High water mark keys */
-#define HWM_GROUP "GROUP HWM"
-#define HWM_USER "USER HWM"
-
-/* idmap version determines auto-conversion */
-#define IDMAP_VERSION 2
-
-/*****************************************************************************
- Initialise idmap database.
-*****************************************************************************/
-
-NTSTATUS samba3_read_idmap(const char *fn, TALLOC_CTX *ctx, struct samba3_idmapdb *idmap)
-{
- TDB_CONTEXT *tdb;
- TDB_DATA key, val;
- int32_t version;
-
- /* Open idmap repository */
- if (!(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0644))) {
- DEBUG(0, ("idmap_init: Unable to open idmap database '%s'\n", fn));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- idmap->mapping_count = 0;
- idmap->mappings = NULL;
- idmap->user_hwm = tdb_fetch_int32(tdb, HWM_USER);
- idmap->group_hwm = tdb_fetch_int32(tdb, HWM_GROUP);
-
- /* check against earlier versions */
- version = tdb_fetch_int32(tdb, "IDMAP_VERSION");
- if (version != IDMAP_VERSION) {
- DEBUG(0, ("idmap_init: Unable to open idmap database, it's in an old format!\n"));
- return NT_STATUS_INTERNAL_DB_ERROR;
- }
-
- for (key = tdb_firstkey(tdb); key.dptr; key = tdb_nextkey(tdb, key))
- {
- struct samba3_idmap_mapping map;
- const char *k = (const char *)key.dptr;
- const char *v;
-
- if (strncmp(k, "GID ", 4) == 0) {
- map.type = IDMAP_GROUP;
- map.unix_id = atoi(k+4);
- val = tdb_fetch(tdb, key);
- v = (const char *)val.dptr;
- map.sid = dom_sid_parse_talloc(ctx, v);
- } else if (strncmp(k, "UID ", 4) == 0) {
- map.type = IDMAP_USER;
- map.unix_id = atoi(k+4);
- val = tdb_fetch(tdb, key);
- v = (const char *)val.dptr;
- map.sid = dom_sid_parse_talloc(ctx, v);
- } else {
- continue;
- }
-
- idmap->mappings = talloc_realloc(ctx, idmap->mappings, struct samba3_idmap_mapping, idmap->mapping_count+1);
-
- idmap->mappings[idmap->mapping_count] = map;
- idmap->mapping_count++;
- }
-
- tdb_close(tdb);
-
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/samba3/policy.c b/source4/lib/samba3/policy.c
deleted file mode 100644
index 44944770c1..0000000000
--- a/source4/lib/samba3/policy.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * account policy storage
- * Copyright (C) Jelmer Vernooij 2005
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "includes.h"
-#include "lib/tdb/include/tdb.h"
-#include "lib/util/util_tdb.h"
-#include "lib/samba3/samba3.h"
-#include "system/filesys.h"
-
-NTSTATUS samba3_read_account_policy(const char *fn, TALLOC_CTX *ctx, struct samba3_policy *ret)
-{
- TDB_CONTEXT *tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600);
- if (!tdb) {
- DEBUG(0,("Failed to open account policy database\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- tdb_fetch_uint32(tdb, "min password length", &ret->min_password_length);
- tdb_fetch_uint32(tdb, "password history", &ret->password_history);
- tdb_fetch_uint32(tdb, "user must logon to change pasword", &ret->user_must_logon_to_change_password);
- tdb_fetch_uint32(tdb, "maximum password age", &ret->maximum_password_age);
- tdb_fetch_uint32(tdb, "minimum password age", &ret->minimum_password_age);
- tdb_fetch_uint32(tdb, "lockout duration", &ret->lockout_duration);
- tdb_fetch_uint32(tdb, "reset count minutes", &ret->reset_count_minutes);
- tdb_fetch_uint32(tdb, "bad lockout minutes", &ret->bad_lockout_minutes);
- tdb_fetch_uint32(tdb, "disconnect time", &ret->disconnect_time);
- tdb_fetch_uint32(tdb, "refuse machine password change", &ret->refuse_machine_password_change);
-
- /* FIXME: Read privileges as well */
-
- tdb_close(tdb);
-
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/samba3/registry.c b/source4/lib/samba3/registry.c
deleted file mode 100644
index 69197883b7..0000000000
--- a/source4/lib/samba3/registry.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * Virtual Windows Registry Layer
- * Copyright (C) Gerald Carter 2002-2005
- * Copyright (C) Jelmer Vernooij 2005
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-/* Implementation of internal registry database functions. */
-
-#include "includes.h"
-#include "lib/samba3/samba3.h"
-#include "librpc/gen_ndr/winreg.h"
-#include "lib/tdb/include/tdb.h"
-#include "lib/util/util_tdb.h"
-#include "system/filesys.h"
-#include "pstring.h"
-
-#define VALUE_PREFIX "SAMBA_REGVAL"
-#define REGVER_V1 1 /* first db version with write support */
-
-/****************************************************************************
- Unpack a list of registry values from the TDB
- ***************************************************************************/
-
-static int regdb_unpack_values(TDB_CONTEXT *tdb, TALLOC_CTX *ctx, struct samba3_regkey *key, TDB_DATA data )
-{
- int len = 0;
- uint32_t type;
- uint32_t size;
- uint8_t *data_p;
- uint32_t num_values = 0;
- int i;
- fstring valuename;
-
- /* loop and unpack the rest of the registry values */
-
- len += tdb_unpack(tdb, (char *)data.dptr+len, data.dsize-len, "d", &num_values);
-
- for ( i=0; i<num_values; i++ ) {
- struct samba3_regval val;
- /* unpack the next regval */
-
- type = REG_NONE;
- size = 0;
- data_p = NULL;
- len += tdb_unpack(tdb, (char *)data.dptr+len, data.dsize-len, "fdB",
- valuename,
- &val.type,
- &size,
- &data_p);
- val.name = talloc_strdup(ctx, valuename);
- val.data = data_blob_talloc(ctx, data_p, size);
-
- key->values = talloc_realloc(ctx, key->values, struct samba3_regval, key->value_count+1);
- key->values[key->value_count] = val;
- key->value_count++;
- }
-
- return len;
-}
-
-
-
-/***********************************************************************
- Open the registry database
- ***********************************************************************/
-
-NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regdb *db )
-{
- uint32_t vers_id;
- TDB_CONTEXT *tdb;
- TDB_DATA kbuf, vbuf;
-
- /* placeholder tdb; reinit upon startup */
-
- if ( !(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600)) )
- {
- DEBUG(0, ("Unable to open registry database %s\n", fn));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- vers_id = tdb_fetch_int32(tdb, "INFO/version");
-
- db->key_count = 0;
- db->keys = NULL;
-
- if (vers_id != -1 && vers_id >= REGVER_V1) {
- DEBUG(0, ("Registry version mismatch: %d\n", vers_id));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf))
- {
- uint32_t len;
- int i;
- struct samba3_regkey key;
- char *skey;
-
- if (strncmp((char *)kbuf.dptr, VALUE_PREFIX, strlen(VALUE_PREFIX)) == 0)
- continue;
-
- vbuf = tdb_fetch(tdb, kbuf);
-
- key.name = talloc_strdup(ctx, (char *)kbuf.dptr);
-
- len = tdb_unpack(tdb, (char *)vbuf.dptr, vbuf.dsize, "d", &key.subkey_count);
-
- key.value_count = 0;
- key.values = NULL;
- key.subkeys = talloc_array(ctx, char *, key.subkey_count);
-
- for (i = 0; i < key.subkey_count; i++) {
- fstring tmp;
- len += tdb_unpack( tdb, (char *)vbuf.dptr+len, vbuf.dsize-len, "f", tmp );
- key.subkeys[i] = talloc_strdup(ctx, tmp);
- }
-
- skey = talloc_asprintf(ctx, "%s/%s", VALUE_PREFIX, kbuf.dptr );
-
- vbuf = tdb_fetch_bystring( tdb, skey );
-
- if ( vbuf.dptr ) {
- regdb_unpack_values( tdb, ctx, &key, vbuf );
- }
-
- db->keys = talloc_realloc(ctx, db->keys, struct samba3_regkey, db->key_count+1);
- db->keys[db->key_count] = key;
- db->key_count++;
- }
-
- tdb_close(tdb);
-
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/samba3/samba3.c b/source4/lib/samba3/samba3.c
deleted file mode 100644
index 4bd08f188a..0000000000
--- a/source4/lib/samba3/samba3.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * Copyright (C) Jelmer Vernooij 2005
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "includes.h"
-#include "lib/samba3/samba3.h"
-
-struct samba3_domainsecrets *samba3_find_domainsecrets(struct samba3 *db, const char *name)
-{
- int i;
-
- for (i = 0; i < db->secrets.domain_count; i++) {
- if (!strcasecmp_m(db->secrets.domains[i].name, name))
- return &db->secrets.domains[i];
- }
-
- return NULL;
-}
-
-NTSTATUS samba3_read_passdb_backends(TALLOC_CTX *ctx, const char *libdir, struct samba3 *samba3)
-{
- char *dbfile;
- NTSTATUS status = NT_STATUS_OK;
- int i;
- const char **backends = param_get_string_list(samba3->configuration, "passdb backend", NULL, NULL);
-
- /* Default to smbpasswd */
- if (backends == NULL)
- backends = str_list_make(ctx, "smbpasswd", LIST_SEP);
- else
- backends = str_list_copy(ctx, backends);
-
-
- for (i = 0; backends[i]; i++) {
- if (!strncmp(backends[i], "tdbsam", strlen("tdbsam"))) {
- const char *p = strchr(backends[i], ':');
- if (p && p[1]) {
- dbfile = talloc_strdup(ctx, p+1);
- } else {
- dbfile = talloc_asprintf(ctx, "%s/passdb.tdb", libdir);
- }
- samba3_read_tdbsam(dbfile, ctx, &samba3->samaccounts, &samba3->samaccount_count);
- talloc_free(dbfile);
- } else if (!strncmp(backends[i], "smbpasswd", strlen("smbpasswd"))) {
- const char *p = strchr(backends[i], ':');
- if (p && p[1]) {
- dbfile = talloc_strdup(ctx, p+1);
- } else if ((p = param_get_string(samba3->configuration, "smb passwd file", NULL))) {
- dbfile = talloc_strdup(ctx, p);
- } else {
- dbfile = talloc_strdup(ctx, "/etc/samba/smbpasswd");
- }
-
- samba3_read_smbpasswd(dbfile, ctx, &samba3->samaccounts, &samba3->samaccount_count);
- talloc_free(dbfile);
- } else if (!strncmp(backends[i], "ldapsam", strlen("ldapsam"))) {
- /* Will use samba3sam mapping module */
- } else {
- DEBUG(0, ("Upgrade from %s database not supported", backends[i]));
- status = NT_STATUS_NOT_SUPPORTED;
- continue;
- }
- }
-
- talloc_free(backends);
-
- return status;
-}
-
-NTSTATUS samba3_read(const char *libdir, const char *smbconf, TALLOC_CTX *ctx, struct samba3 **samba3)
-{
- struct samba3 *ret;
- char *dbfile = NULL;
-
- ret = talloc_zero(ctx, struct samba3);
-
- if (smbconf != NULL) {
- ret->configuration = param_init(ret);
- if (param_read(ret->configuration, smbconf) == -1) {
- talloc_free(ret);
- return NT_STATUS_UNSUCCESSFUL;
- }
- }
-
- dbfile = talloc_asprintf(ctx, "%s/account_policy.tdb", libdir);
- samba3_read_account_policy(dbfile, ctx, &ret->policy);
- talloc_free(dbfile);
-
- dbfile = talloc_asprintf(ctx, "%s/registry.tdb", libdir);
- samba3_read_regdb(dbfile, ctx, &ret->registry);
- talloc_free(dbfile);
-
- dbfile = talloc_asprintf(ctx, "%s/secrets.tdb", libdir);
- samba3_read_secrets(dbfile, ctx, &ret->secrets);
- talloc_free(dbfile);
-
- dbfile = talloc_asprintf(ctx, "%s/share_info.tdb", libdir);
- samba3_read_share_info(dbfile, ctx, ret);
- talloc_free(dbfile);
-
- dbfile = talloc_asprintf(ctx, "%s/winbindd_idmap.tdb", libdir);
- samba3_read_idmap(dbfile, ctx, &ret->idmap);
- talloc_free(dbfile);
-
- dbfile = talloc_asprintf(ctx, "%s/wins.dat", libdir);
- samba3_read_winsdb(dbfile, ret, &ret->winsdb_entries, &ret->winsdb_count);
- talloc_free(dbfile);
-
- samba3_read_passdb_backends(ctx, libdir, ret);
-
- dbfile = talloc_asprintf(ctx, "%s/group_mapping.tdb", libdir);
- samba3_read_grouptdb(dbfile, ctx, &ret->group);
- talloc_free(dbfile);
-
- *samba3 = ret;
-
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/samba3/samba3.h b/source4/lib/samba3/samba3.h
index 202ac767ec..aea87dac14 100644
--- a/source4/lib/samba3/samba3.h
+++ b/source4/lib/samba3/samba3.h
@@ -209,7 +209,6 @@ struct samba3
struct samba3_regdb registry;
};
-#include "lib/samba3/samba3_proto.h"
#include "lib/samba3/samba3_smbpasswd_proto.h"
#endif /* _SAMBA3_H */
diff --git a/source4/lib/samba3/secrets.c b/source4/lib/samba3/secrets.c
deleted file mode 100644
index cd1df991a4..0000000000
--- a/source4/lib/samba3/secrets.c
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Copyright (C) Andrew Tridgell 1992-2001
- Copyright (C) Andrew Bartlett 2002
- Copyright (C) Rafal Szczesniak 2002
- Copyright (C) Tim Potter 2001
- Copyright (C) Jelmer Vernooij 2005
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* the Samba secrets database stores any generated, private information
- such as the local SID and machine trust password */
-
-#include "includes.h"
-#include "lib/tdb/include/tdb.h"
-#include "lib/util/util_tdb.h"
-#include "lib/samba3/samba3.h"
-#include "system/filesys.h"
-#include "librpc/gen_ndr/security.h"
-#include "auth/credentials/credentials.h"
-
-/**
- * Unpack SID into a pointer
- *
- * @param pack_buf pointer to buffer with packed representation
- * @param bufsize size of the buffer
- * @param sid pointer to sid structure to be filled with unpacked data
- *
- * @return size of structure unpacked from buffer
- **/
-static size_t tdb_sid_unpack(TDB_CONTEXT *tdb, char* pack_buf, int bufsize, struct dom_sid* sid)
-{
- int idx, len = 0;
-
- if (!sid || !pack_buf) return -1;
-
- len += tdb_unpack(tdb, pack_buf + len, bufsize - len, "bb",
- &sid->sid_rev_num, &sid->num_auths);
-
- for (idx = 0; idx < 6; idx++) {
- len += tdb_unpack(tdb, pack_buf + len, bufsize - len, "b", &sid->id_auth[idx]);
- }
-
- for (idx = 0; idx < 15; idx++) {
- len += tdb_unpack(tdb, pack_buf + len, bufsize - len, "d", &sid->sub_auths[idx]);
- }
-
- return len;
-}
-
-static struct samba3_domainsecrets *secrets_find_domain(TALLOC_CTX *ctx, struct samba3_secrets *db, const char *key)
-{
- int i;
-
- for (i = 0; i < db->domain_count; i++)
- {
- if (!strcasecmp_m(db->domains[i].name, key))
- return &db->domains[i];
- }
-
- db->domains = talloc_realloc(ctx, db->domains, struct samba3_domainsecrets, db->domain_count+1);
- ZERO_STRUCT(db->domains[db->domain_count]);
- db->domains[db->domain_count].name = talloc_strdup(db->domains, key);
-
- db->domain_count++;
-
- return &db->domains[db->domain_count-1];
-}
-
-static NTSTATUS ipc_password (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- cli_credentials_set_password(db->ipc_cred, (const char *)vbuf.dptr, CRED_SPECIFIED);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS ipc_username (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- cli_credentials_set_username(db->ipc_cred, (const char *)vbuf.dptr, CRED_SPECIFIED);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS ipc_domain (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- cli_credentials_set_domain(db->ipc_cred, (const char *)vbuf.dptr, CRED_SPECIFIED);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS domain_sid (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key);
- domainsec->sid.sub_auths = talloc_array(ctx, uint32_t, 15);
- tdb_sid_unpack(tdb, (char *)vbuf.dptr, vbuf.dsize, &domainsec->sid);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS domain_guid (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key);
- memcpy(&domainsec->guid, vbuf.dptr, vbuf.dsize);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS ldap_bind_pw (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- struct samba3_ldappw pw;
- pw.dn = talloc_strdup(ctx, key);
- pw.password = talloc_strdup(ctx, (const char *)vbuf.dptr);
-
- db->ldappws = talloc_realloc(ctx, db->ldappws, struct samba3_ldappw, db->ldappw_count+1);
- db->ldappws[db->ldappw_count] = pw;
- db->ldappw_count++;
- return NT_STATUS_OK;
-}
-
-static NTSTATUS afs_keyfile (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- struct samba3_afs_keyfile keyfile;
- memcpy(&keyfile, vbuf.dptr, vbuf.dsize);
- keyfile.cell = talloc_strdup(ctx, key);
-
- db->afs_keyfiles = talloc_realloc(ctx, db->afs_keyfiles, struct samba3_afs_keyfile, db->afs_keyfile_count+1);
- db->afs_keyfiles[db->afs_keyfile_count] = keyfile;
- db->afs_keyfile_count++;
-
- return NT_STATUS_OK;
-}
-
-static NTSTATUS machine_sec_channel_type (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key);
-
- domainsec->sec_channel_type = IVAL(vbuf.dptr, 0);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS machine_last_change_time (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key);
- domainsec->last_change_time = IVAL(vbuf.dptr, 0);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS machine_password (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key);
- domainsec->plaintext_pw = talloc_strdup(ctx, (const char *)vbuf.dptr);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS machine_acc (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key);
-
- memcpy(&domainsec->hash_pw, vbuf.dptr, vbuf.dsize);
-
- return NT_STATUS_OK;
-}
-
-static NTSTATUS random_seed (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- /* Ignore */
- return NT_STATUS_OK;
-}
-
-static NTSTATUS domtrust_acc (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- int idx, len = 0;
- struct samba3_trusted_dom_pass pass;
- int pass_len;
-
- if (!vbuf.dptr)
- return NT_STATUS_UNSUCCESSFUL;
-
- /* unpack unicode domain name and plaintext password */
- len += tdb_unpack(tdb, (char *)vbuf.dptr, vbuf.dsize - len, "d", &pass.uni_name_len);
-
- for (idx = 0; idx < 32; idx++)
- len += tdb_unpack(tdb, (char *)(vbuf.dptr + len), vbuf.dsize - len, "w", &pass.uni_name[idx]);
-
- len += tdb_unpack(tdb, (char *)(vbuf.dptr + len), vbuf.dsize - len, "d", &pass_len);
- pass.pass = talloc_strdup(ctx, (char *)(vbuf.dptr+len));
- len += strlen((const char *)vbuf.dptr)+1;
- len += tdb_unpack(tdb, (char *)(vbuf.dptr + len), vbuf.dsize - len, "d", &pass.mod_time);
-
- pass.domain_sid.sub_auths = talloc_array(ctx, uint32_t, 15);
- /* unpack domain sid */
- len += tdb_sid_unpack(tdb, (char *)(vbuf.dptr + len), vbuf.dsize - len, &pass.domain_sid);
-
- /* FIXME: Add to list */
-
- return NT_STATUS_OK;
-}
-
-static const struct {
- const char *prefix;
- NTSTATUS (*handler) (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db);
-} secrets_handlers[] = {
- { "SECRETS/AUTH_PASSWORD", ipc_password },
- { "SECRETS/AUTH_DOMAIN", ipc_domain },
- { "SECRETS/AUTH_USER", ipc_username },
- { "SECRETS/SID/", domain_sid },
- { "SECRETS/DOMGUID/", domain_guid },
- { "SECRETS/LDAP_BIND_PW/", ldap_bind_pw },
- { "SECRETS/AFS_KEYFILE/", afs_keyfile },
- { "SECRETS/MACHINE_SEC_CHANNEL_TYPE/", machine_sec_channel_type },
- { "SECRETS/MACHINE_LAST_CHANGE_TIME/", machine_last_change_time },
- { "SECRETS/MACHINE_PASSWORD/", machine_password },
- { "SECRETS/$MACHINE.ACC/", machine_acc },
- { "SECRETS/$DOMTRUST.ACC/", domtrust_acc },
- { "INFO/random_seed", random_seed },
-};
-
-
-NTSTATUS samba3_read_secrets(const char *fname, TALLOC_CTX *ctx, struct samba3_secrets *db)
-{
- TDB_CONTEXT *tdb = tdb_open(fname, 0, TDB_DEFAULT, O_RDONLY, 0600);
- TDB_DATA kbuf, vbuf;
-
- if (!tdb) {
- DEBUG(0,("Failed to open %s\n", fname));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- ZERO_STRUCTP(db);
-
- db->ipc_cred = cli_credentials_init(ctx);
-
- for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf))
- {
- int i;
- char *key;
- vbuf = tdb_fetch(tdb, kbuf);
-
- for (i = 0; secrets_handlers[i].prefix; i++) {
- if (!strncmp((const char *)kbuf.dptr, secrets_handlers[i].prefix, strlen(secrets_handlers[i].prefix))) {
- key = talloc_strndup(ctx, (const char *)(kbuf.dptr+strlen(secrets_handlers[i].prefix)), kbuf.dsize-strlen(secrets_handlers[i].prefix));
- secrets_handlers[i].handler(tdb, key, vbuf, ctx, db);
- talloc_free(key);
- break;
- }
- }
-
- if (!secrets_handlers[i].prefix) {
- DEBUG(0, ("Unable to find handler for string %s\n", kbuf.dptr));
- }
- }
-
- tdb_close(tdb);
-
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/samba3/share_info.c b/source4/lib/samba3/share_info.c
deleted file mode 100644
index 4dd15aa918..0000000000
--- a/source4/lib/samba3/share_info.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * Share Info parsing
- * Copyright (C) Andrew Tridgell 1992-1997,
- * Copyright (C) Jeremy Allison 2001.
- * Copyright (C) Nigel Williams 2001.
- * Copyright (C) Jelmer Vernooij 2005.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "includes.h"
-#include "librpc/gen_ndr/ndr_security.h"
-#include "lib/tdb/include/tdb.h"
-#include "lib/util/util_tdb.h"
-#include "lib/samba3/samba3.h"
-#include "system/filesys.h"
-
-#define SHARE_DATABASE_VERSION_V1 1
-#define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */
-
-NTSTATUS samba3_read_share_info(const char *fn, TALLOC_CTX *ctx, struct samba3 *db)
-{
- int32_t vers_id;
- TDB_CONTEXT *tdb;
- TDB_DATA kbuf, vbuf;
- DATA_BLOB blob;
-
- tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600);
- if (!tdb) {
- DEBUG(0,("Failed to open share info database %s (%s)\n",
- fn, strerror(errno) ));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Cope with byte-reversed older versions of the db. */
- vers_id = tdb_fetch_int32(tdb, "INFO/version");
- if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
- /* Written on a bigendian machine with old fetch_int code. Save as le. */
- vers_id = SHARE_DATABASE_VERSION_V2;
- }
-
- if (vers_id != SHARE_DATABASE_VERSION_V2) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf))
- {
- struct ndr_pull *pull;
- struct samba3_share_info *share;
- char *name;
-
- if (strncmp((char *)kbuf.dptr, "SECDESC/", strlen("SECDESC/")) != 0)
- continue;
-
- name = talloc_strndup(ctx, (char *)kbuf.dptr+strlen("SECDESC/"), kbuf.dsize-strlen("SECDESC/"));
-
- db->shares = talloc_realloc(db, db->shares, struct samba3_share_info, db->share_count+1);
- share = &db->shares[db->share_count];
- db->share_count++;
-
- share->name = talloc_strdup(db, name);
-
- vbuf = tdb_fetch(tdb, kbuf);
- blob.data = (uint8_t *)vbuf.dptr;
- blob.length = vbuf.dsize;
-
- pull = ndr_pull_init_blob(&blob, ctx, lp_iconv_convenience(global_loadparm));
-
- ndr_pull_security_descriptor(pull, NDR_SCALARS|NDR_BUFFERS, &share->secdesc);
-
- talloc_free(pull);
- }
-
- tdb_close(tdb);
-
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/samba3/smbpasswd.c b/source4/lib/samba3/smbpasswd.c
index 39e2448b98..47c826f9df 100644
--- a/source4/lib/samba3/smbpasswd.c
+++ b/source4/lib/samba3/smbpasswd.c
@@ -204,142 +204,3 @@ char *smbpasswd_encode_acb_info(TALLOC_CTX *mem_ctx, uint16_t acb_info)
return acct_str;
}
-
-NTSTATUS samba3_read_smbpasswd(const char *filename, TALLOC_CTX *ctx, struct samba3_samaccount **accounts, uint32_t *count)
-{
- int numlines;
- char **lines;
- int i;
-
- *count = 0;
- *accounts = NULL;
-
- lines = file_lines_load(filename, &numlines, ctx);
-
- if (lines == NULL) {
- DEBUG(0, ("Unable to load lines from %s\n", filename));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- *accounts = talloc_array(ctx, struct samba3_samaccount, numlines);
-
- for (i = 0; i < numlines; i++) {
- char *p = lines[i], *q;
- uid_t uid;
- struct samba3_samaccount *acc = &((*accounts)[*count]);
-
- if (p[0] == '\0' || p[0] == '#')
- continue;
-
- ZERO_STRUCTP(acc);
-
- q = strchr(p, ':');
- if (!q) {
- DEBUG(0, ("%s:%d: expected ':'\n", filename, i));
- continue;
- }
-
- acc->username = talloc_strndup(ctx, p, PTR_DIFF(q, p));
- p = q+1;
-
- uid = atoi(p);
-
- /* uid is ignored here.. */
-
- q = strchr(p, ':');
- if (!q) {
- DEBUG(0, ("%s:%d: expected ':'\n", filename, i));
- continue;
- }
- p = q+1;
-
- if (strlen(p) < 33) {
- DEBUG(0, ("%s:%d: expected 32 byte password blob\n", filename, i));
- continue;
- }
-
- if (!strncmp(p, "NO PASSWORD", strlen("NO PASSWORD"))) {
- acc->acct_ctrl |= ACB_PWNOTREQ;
- } else if (p[0] == '*' || p[0] == 'X') {
- /* No password set */
- } else {
- struct samr_Password *pw = smbpasswd_gethexpwd(*accounts, p);
-
- if (!pw) {
- DEBUG(0, ("%s:%d: Malformed LM pw entry\n", filename, i));
- continue;
- }
-
- memcpy(acc->lm_pw.hash, pw, sizeof(*pw));
- }
-
- if (p[32] != ':') {
- DEBUG(0, ("%s:%d: expected ':' after 32 byte password blob\n", filename, i));
- continue;
- }
-
- p += 33;
-
- if (p[0] == '*' || p[0] == 'X') {
- /* No password set */
- } else {
- struct samr_Password *pw = smbpasswd_gethexpwd(*accounts, p);
-
- if (!pw) {
- DEBUG(0, ("%s:%d: Malformed LM pw entry\n", filename, i));
- continue;
- }
-
- memcpy(acc->nt_pw.hash, pw, sizeof(*pw));
- }
-
- if (p[32] != ':') {
- DEBUG(0, ("%s:%d: expected ':' after 32 byte password blob\n", filename, i));
- continue;
- }
-
- p += 33;
-
- if (p[0] == '[') {
- q = strchr(p, ']');
- if (!q) {
- DEBUG(0, ("%s:%d: expected ']'\n", filename, i));
- continue;
- }
-
- acc->acct_ctrl |= smbpasswd_decode_acb_info(p);
-
- p = q+1;
- if (p[0] == ':' && strncmp(p, "LCT-", 4) == 0) {
- int j;
- p += 4;
-
- for(j = 0; j < 8; j++) {
- if(p[j] == '\0' || !isxdigit(p[j])) {
- break;
- }
- }
- if(i == 8) {
- acc->pass_last_set_time = (time_t)strtol((char *)p, NULL, 16);
- }
- }
- } else {
- /* 'Old' style file. Fake up based on user name. */
- /*
- * Currently trust accounts are kept in the same
- * password file as 'normal accounts'. If this changes
- * we will have to fix this code. JRA.
- */
- if(acc->username[strlen(acc->username) - 1] == '$') {
- acc->acct_ctrl &= ~ACB_NORMAL;
- acc->acct_ctrl |= ACB_WSTRUST;
- }
- }
-
- (*count)++;
- }
-
- talloc_free(lines);
-
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/samba3/tdbsam.c b/source4/lib/samba3/tdbsam.c
deleted file mode 100644
index 8e6b0daf2b..0000000000
--- a/source4/lib/samba3/tdbsam.c
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- tdb passdb backend format routines
-
- Copyright (C) Simo Sorce 2000-2003
- Copyright (C) Jelmer Vernooij 2005
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "system/filesys.h"
-#include "lib/tdb/include/tdb.h"
-#include "lib/util/util_tdb.h"
-#include "lib/samba3/samba3.h"
-
-#define TDB_FORMAT_STRING_V0 "ddddddBBBBBBBBBBBBddBBwdwdBwwd"
-#define TDB_FORMAT_STRING_V1 "dddddddBBBBBBBBBBBBddBBwdwdBwwd"
-#define TDB_FORMAT_STRING_V2 "dddddddBBBBBBBBBBBBddBBBwwdBwwd"
-#define TDBSAM_VERSION_STRING "INFO/version"
-
-static bool init_sam_from_buffer_v0(TDB_CONTEXT *tdb, struct samba3_samaccount *sampass, TDB_DATA buf)
-{
- uint32_t username_len, domain_len, nt_username_len,
- dir_drive_len, unknown_str_len, munged_dial_len,
- fullname_len, homedir_len, logon_script_len,
- profile_path_len, acct_desc_len, workstations_len;
-
- uint32_t remove_me;
- uint32_t len = 0;
- uint32_t lm_pw_len, nt_pw_len, hourslen;
-
- if(sampass == NULL || buf.dptr == NULL) {
- DEBUG(0, ("init_sam_from_buffer_v0: NULL parameters found!\n"));
- return false;
- }
-
- /* unpack the buffer into variables */
- len = tdb_unpack (tdb, (char *)buf.dptr, buf.dsize, TDB_FORMAT_STRING_V0,
- &sampass->logon_time, /* d */
- &sampass->logoff_time, /* d */
- &sampass->kickoff_time, /* d */
- &sampass->pass_last_set_time, /* d */
- &sampass->pass_can_change_time, /* d */
- &sampass->pass_must_change_time, /* d */
- &username_len, &sampass->username, /* B */
- &domain_len, &sampass->domain, /* B */
- &nt_username_len, &sampass->nt_username, /* B */
- &fullname_len, &sampass->fullname, /* B */
- &homedir_len, &sampass->homedir, /* B */
- &dir_drive_len, &sampass->dir_drive, /* B */
- &logon_script_len, &sampass->logon_script, /* B */
- &profile_path_len, &sampass->profile_path, /* B */
- &acct_desc_len, &sampass->acct_desc, /* B */
- &workstations_len, &sampass->workstations, /* B */
- &unknown_str_len, &sampass->unknown_str, /* B */
- &munged_dial_len, &sampass->munged_dial, /* B */
- &sampass->user_rid, /* d */
- &sampass->group_rid, /* d */
- &lm_pw_len, sampass->lm_pw.hash, /* B */
- &nt_pw_len, sampass->nt_pw.hash, /* B */
- &sampass->acct_ctrl, /* w */
- &remove_me, /* remove on the next TDB_FORMAT upgarde */ /* d */
- &sampass->logon_divs, /* w */
- &sampass->hours_len, /* d */
- &hourslen, &sampass->hours, /* B */
- &sampass->bad_password_count, /* w */
- &sampass->logon_count, /* w */
- &sampass->unknown_6); /* d */
-
- if (len == (uint32_t) -1) {
- return false;
- }
-
- return true;
-}
-
-static bool init_sam_from_buffer_v1(TDB_CONTEXT *tdb, struct samba3_samaccount *sampass, TDB_DATA buf)
-{
- uint32_t username_len, domain_len, nt_username_len,
- dir_drive_len, unknown_str_len, munged_dial_len,
- fullname_len, homedir_len, logon_script_len,
- profile_path_len, acct_desc_len, workstations_len;
-
- uint32_t remove_me;
- uint32_t len = 0;
- uint32_t lm_pw_len, nt_pw_len, hourslen;
-
- if(sampass == NULL || buf.dptr == NULL) {
- DEBUG(0, ("init_sam_from_buffer_v1: NULL parameters found!\n"));
- return false;
- }
-
- /* unpack the buffer into variables */
- len = tdb_unpack (tdb, (char *)buf.dptr, buf.dsize, TDB_FORMAT_STRING_V1,
- &sampass->logon_time, /* d */
- &sampass->logoff_time, /* d */
- &sampass->kickoff_time, /* d */
- /* Change from V0 is addition of bad_password_time field. */
- &sampass->bad_password_time, /* d */
- &sampass->pass_last_set_time, /* d */
- &sampass->pass_can_change_time, /* d */
- &sampass->pass_must_change_time, /* d */
- &username_len, &sampass->username, /* B */
- &domain_len, &sampass->domain, /* B */
- &nt_username_len, &sampass->nt_username, /* B */
- &fullname_len, &sampass->fullname, /* B */
- &homedir_len, &sampass->homedir, /* B */
- &dir_drive_len, &sampass->dir_drive, /* B */
- &logon_script_len, &sampass->logon_script, /* B */
- &profile_path_len, &sampass->profile_path, /* B */
- &acct_desc_len, &sampass->acct_desc, /* B */
- &workstations_len, &sampass->workstations, /* B */
- &unknown_str_len, &sampass->unknown_str, /* B */
- &munged_dial_len, &sampass->munged_dial, /* B */
- &sampass->user_rid, /* d */
- &sampass->group_rid, /* d */
- &lm_pw_len, sampass->lm_pw.hash, /* B */
- &nt_pw_len, sampass->nt_pw.hash, /* B */
- &sampass->acct_ctrl, /* w */
- &remove_me, /* d */
- &sampass->logon_divs, /* w */
- &sampass->hours_len, /* d */
- &hourslen, &sampass->hours, /* B */
- &sampass->bad_password_count, /* w */
- &sampass->logon_count, /* w */
- &sampass->unknown_6); /* d */
-
- if (len == (uint32_t) -1) {
- return false;
- }
-
- return true;
-}
-
-static bool init_sam_from_buffer_v2(TDB_CONTEXT *tdb, struct samba3_samaccount *sampass, TDB_DATA buf)
-{
- uint32_t username_len, domain_len, nt_username_len,
- dir_drive_len, unknown_str_len, munged_dial_len,
- fullname_len, homedir_len, logon_script_len,
- profile_path_len, acct_desc_len, workstations_len;
-
- uint32_t len = 0;
- uint32_t lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen;
-
- if(sampass == NULL || buf.dptr == NULL) {
- DEBUG(0, ("init_sam_from_buffer_v2: NULL parameters found!\n"));
- return false;
- }
-
- /* unpack the buffer into variables */
- len = tdb_unpack (tdb, (char *)buf.dptr, buf.dsize, TDB_FORMAT_STRING_V2,
- &sampass->logon_time, /* d */
- &sampass->logoff_time, /* d */
- &sampass->kickoff_time, /* d */
- &sampass->bad_password_time, /* d */
- &sampass->pass_last_set_time, /* d */
- &sampass->pass_can_change_time, /* d */
- &sampass->pass_must_change_time, /* d */
- &username_len, &sampass->username, /* B */
- &domain_len, &sampass->domain, /* B */
- &nt_username_len, &sampass->nt_username, /* B */
- &fullname_len, &sampass->fullname, /* B */
- &homedir_len, &sampass->homedir, /* B */
- &dir_drive_len, &sampass->dir_drive, /* B */
- &logon_script_len, &sampass->logon_script, /* B */
- &profile_path_len, &sampass->profile_path, /* B */
- &acct_desc_len, &sampass->acct_desc, /* B */
- &workstations_len, &sampass->workstations, /* B */
- &unknown_str_len, &sampass->unknown_str, /* B */
- &munged_dial_len, &sampass->munged_dial, /* B */
- &sampass->user_rid, /* d */
- &sampass->group_rid, /* d */
- &lm_pw_len, sampass->lm_pw.hash, /* B */
- &nt_pw_len, sampass->nt_pw.hash, /* B */
- /* Change from V1 is addition of password history field. */
- &nt_pw_hist_len, &sampass->nt_pw_hist_ptr, /* B */
- &sampass->acct_ctrl, /* w */
- /* Also "remove_me" field was removed. */
- &sampass->logon_divs, /* w */
- &sampass->hours_len, /* d */
- &hourslen, &sampass->hours, /* B */
- &sampass->bad_password_count, /* w */
- &sampass->logon_count, /* w */
- &sampass->unknown_6); /* d */
-
- if (len == (uint32_t) -1) {
- return false;
- }
-
- return true;
-}
-
-NTSTATUS samba3_read_tdbsam(const char *filename, TALLOC_CTX *ctx, struct samba3_samaccount **accounts, uint32_t *count)
-{
- int32_t version;
- TDB_CONTEXT *tdb;
- TDB_DATA key, val;
-
- /* Try to open tdb passwd */
- if (!(tdb = tdb_open(filename, 0, TDB_DEFAULT, O_RDONLY, 0600))) {
- DEBUG(0, ("Unable to open TDB passwd file '%s'\n", filename));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Check the version */
- version = tdb_fetch_int32(tdb,
- TDBSAM_VERSION_STRING);
- if (version == -1)
- version = 0; /* Version not found, assume version 0 */
-
- /* Compare the version */
- if (version > 2) {
- /* Version more recent than the latest known */
- DEBUG(0, ("TDBSAM version unknown: %d\n", version));
- tdb_close(tdb);
- return NT_STATUS_NOT_SUPPORTED;
- }
-
- *accounts = NULL;
- *count = 0;
-
- for (key = tdb_firstkey(tdb); key.dptr; key = tdb_nextkey(tdb, key))
- {
- bool ret;
- if (strncmp((const char *)key.dptr, "USER_", 5) != 0)
- continue;
-
- val = tdb_fetch(tdb, key);
-
- *accounts = talloc_realloc(ctx, *accounts, struct samba3_samaccount, (*count)+1);
-
- switch (version)
- {
- case 0: ret = init_sam_from_buffer_v0(tdb, &(*accounts)[*count], val); break;
- case 1: ret = init_sam_from_buffer_v1(tdb, &(*accounts)[*count], val); break;
- case 2: ret = init_sam_from_buffer_v2(tdb, &(*accounts)[*count], val); break;
- default: ret = false; break;
-
- }
-
- if (!ret) {
- DEBUG(0, ("Unable to parse SAM account %s\n", key.dptr));
- }
-
- (*count)++;
- }
-
- tdb_close(tdb);
-
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/samba3/winsdb.c b/source4/lib/samba3/winsdb.c
deleted file mode 100644
index 5bed3523ea..0000000000
--- a/source4/lib/samba3/winsdb.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Wins Database
-
- Copyright (C) Jeremy Allison 1994-2003
- Copyright (C) Jelmer Vernooij 2005
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "includes.h"
-#include "system/filesys.h"
-#include "lib/samba3/samba3.h"
-#include "system/network.h"
-
-#define WINS_VERSION 1
-
-NTSTATUS samba3_read_winsdb( const char *fn, TALLOC_CTX *ctx, struct samba3_winsdb_entry **entries, uint32_t *count )
-{
- XFILE *fp;
- char *line;
-
- if((fp = x_fopen(fn,O_RDONLY,0)) == NULL) {
- DEBUG(0,("initialise_wins: Can't open wins database file %s. Error was %s\n",
- fn, strerror(errno) ));
- return NT_STATUS_OPEN_FAILED;
- }
-
- *count = 0;
- *entries = NULL;
-
- while (!x_feof(fp)) {
- struct samba3_winsdb_entry entry;
- const char *name_str, *ttl_str, *nb_flags_str;
- const char **args;
- char *p;
- int i;
- unsigned int hash;
- int version;
-
- /* Read a line from the wins.dat file. Strips whitespace
- from the beginning and end of the line. */
- line = fgets_slash(NULL,8,fp);
- if (!line) {
- return NT_STATUS_UNEXPECTED_IO_ERROR;
- }
-
- if (*line == '#') {
- SAFE_FREE(line);
- continue;
- }
-
- if (strncmp(line,"VERSION ", 8) == 0) {
- if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 ||
- version != WINS_VERSION) {
- DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line));
- SAFE_FREE(line);
- x_fclose(fp);
- return NT_STATUS_REVISION_MISMATCH;
- }
- SAFE_FREE(line);
-
- continue;
- }
-
- args = str_list_make_shell(ctx, line, NULL);
-
- /*
- * Now we handle multiple IP addresses per name we need
- * to iterate over the line twice. The first time to
- * determine how many IP addresses there are, the second
- * time to actually parse them into the ip_list array.
- */
-
- name_str = args[0];
- if (!name_str) {
- DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line ));
- SAFE_FREE(line);
- continue;
- }
-
- ttl_str = args[1];
- if (!ttl_str) {
- DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line ));
- SAFE_FREE(line);
- continue;
- }
-
- /*
- * Determine the number of IP addresses per line.
- */
- entry.ip_count = 0;
- for (i = 2; args[i] && strchr(args[i], '.'); i++) entry.ip_count++;
-
- if(entry.ip_count == 0) {
- DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line ));
- SAFE_FREE(line);
- continue;
- }
-
- /* Allocate the space for the ip_list. */
- if((entry.ips = talloc_array ( ctx, struct in_addr, entry.ip_count)) == NULL) {
- DEBUG(0,("initialise_wins: Malloc fail !\n"));
- SAFE_FREE(line);
- return NT_STATUS_NO_MEMORY;
- }
-
- /* Reset and re-parse the line. */
- for(i = 0; i < entry.ip_count; i++) {
- entry.ips[i] = interpret_addr2(args[i+2]);
- }
- nb_flags_str = args[2 + entry.ip_count];
-
- SMB_ASSERT(nb_flags_str);
-
- /*
- * Deal with SELF or REGISTER name encoding. Default is REGISTER
- * for compatibility with old nmbds.
- */
-
- if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') {
- DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line));
- talloc_free(entry.ips);
- SAFE_FREE(line);
- continue;
- }
-
- /* Netbios name. # divides the name from the type (hex): netbios#xx */
- entry.name = talloc_strdup(ctx, name_str);
-
- if((p = strchr(entry.name,'#')) != NULL) {
- *p = 0;
- sscanf(p+1,"%x",&entry.type);
- }
-
- /* Decode the netbios flags (hex) and the time-to-live (in seconds). */
- sscanf(nb_flags_str,"%x",&entry.nb_flags);
- entry.ttl = atol(ttl_str);
-
- *entries = talloc_realloc(ctx, *entries, struct samba3_winsdb_entry, (*count)+1);
- (*entries)[*count] = entry;
-
- (*count)++;
- }
-
- x_fclose(fp);
- return NT_STATUS_OK;
-}
diff --git a/source4/lib/talloc/config.mk b/source4/lib/talloc/config.mk
index 16b5063f87..9e949f900f 100644
--- a/source4/lib/talloc/config.mk
+++ b/source4/lib/talloc/config.mk
@@ -1,5 +1,5 @@
[LIBRARY::LIBTALLOC]
-VERSION = 1.0.0
+VERSION = 1.1.0
SO_VERSION = 1
OBJ_FILES = talloc.o
PC_FILE = talloc.pc
diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c
index f9aefcd6de..12b85f5a65 100644
--- a/source4/lib/talloc/talloc.c
+++ b/source4/lib/talloc/talloc.c
@@ -60,6 +60,8 @@
#define TALLOC_MAGIC 0xe814ec70
#define TALLOC_FLAG_FREE 0x01
#define TALLOC_FLAG_LOOP 0x02
+#define TALLOC_FLAG_POOL 0x04 /* This is a talloc pool */
+#define TALLOC_FLAG_POOLMEM 0x08 /* This is allocated in a pool */
#define TALLOC_MAGIC_REFERENCE ((const char *)1)
/* by default we abort when given a bad pointer (such as when talloc_free() is called
@@ -109,6 +111,19 @@ struct talloc_chunk {
const char *name;
size_t size;
unsigned flags;
+
+ /*
+ * "pool" has dual use:
+ *
+ * For the talloc pool itself (i.e. TALLOC_FLAG_POOL is set), "pool"
+ * marks the end of the currently allocated area.
+ *
+ * For members of the pool (i.e. TALLOC_FLAG_POOLMEM is set), "pool"
+ * is a pointer to the struct talloc_chunk of the pool that it was
+ * allocated from. This way children can quickly find the pool to chew
+ * from.
+ */
+ void *pool;
};
/* 16 byte alignment seems to keep everyone happy */
@@ -200,12 +215,87 @@ const char *talloc_parent_name(const void *ptr)
return tc? tc->name : NULL;
}
+/*
+ A pool carries an in-pool object count count in the first 16 bytes.
+ bytes. This is done to support talloc_steal() to a parent outside of the
+ pool. The count includes the pool itself, so a talloc_free() on a pool will
+ only destroy the pool if the count has dropped to zero. A talloc_free() of a
+ pool member will reduce the count, and eventually also call free(3) on the
+ pool memory.
+
+ The object count is not put into "struct talloc_chunk" because it is only
+ relevant for talloc pools and the alignment to 16 bytes would increase the
+ memory footprint of each talloc chunk by those 16 bytes.
+*/
+
+#define TALLOC_POOL_HDR_SIZE 16
+
+static unsigned int *talloc_pool_objectcount(struct talloc_chunk *tc)
+{
+ return (unsigned int *)((char *)tc + sizeof(struct talloc_chunk));
+}
+
+/*
+ Allocate from a pool
+*/
+
+static struct talloc_chunk *talloc_alloc_pool(struct talloc_chunk *parent,
+ size_t size)
+{
+ struct talloc_chunk *pool_ctx = NULL;
+ size_t space_left;
+ struct talloc_chunk *result;
+ size_t chunk_size;
+
+ if (parent == NULL) {
+ return NULL;
+ }
+
+ if (parent->flags & TALLOC_FLAG_POOL) {
+ pool_ctx = parent;
+ }
+ else if (parent->flags & TALLOC_FLAG_POOLMEM) {
+ pool_ctx = (struct talloc_chunk *)parent->pool;
+ }
+
+ if (pool_ctx == NULL) {
+ return NULL;
+ }
+
+ space_left = ((char *)pool_ctx + TC_HDR_SIZE + pool_ctx->size)
+ - ((char *)pool_ctx->pool);
+
+ /*
+ * Align size to 16 bytes
+ */
+ chunk_size = ((size + 15) & ~15);
+
+ if (space_left < chunk_size) {
+ return NULL;
+ }
+
+ result = (struct talloc_chunk *)pool_ctx->pool;
+
+#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_UNDEFINED)
+ VALGRIND_MAKE_MEM_UNDEFINED(result, size);
+#endif
+
+ pool_ctx->pool = (void *)((char *)result + chunk_size);
+
+ result->flags = TALLOC_MAGIC | TALLOC_FLAG_POOLMEM;
+ result->pool = pool_ctx;
+
+ *talloc_pool_objectcount(pool_ctx) += 1;
+
+ return result;
+}
+
/*
Allocate a bit of memory as a child of an existing pointer
*/
static inline void *__talloc(const void *context, size_t size)
{
- struct talloc_chunk *tc;
+ struct talloc_chunk *tc = NULL;
if (unlikely(context == NULL)) {
context = null_context;
@@ -215,11 +305,19 @@ static inline void *__talloc(const void *context, size_t size)
return NULL;
}
- tc = (struct talloc_chunk *)malloc(TC_HDR_SIZE+size);
- if (unlikely(tc == NULL)) return NULL;
+ if (context != NULL) {
+ tc = talloc_alloc_pool(talloc_chunk_from_ptr(context),
+ TC_HDR_SIZE+size);
+ }
+
+ if (tc == NULL) {
+ tc = (struct talloc_chunk *)malloc(TC_HDR_SIZE+size);
+ if (unlikely(tc == NULL)) return NULL;
+ tc->flags = TALLOC_MAGIC;
+ tc->pool = NULL;
+ }
tc->size = size;
- tc->flags = TALLOC_MAGIC;
tc->destructor = NULL;
tc->child = NULL;
tc->name = NULL;
@@ -246,6 +344,33 @@ static inline void *__talloc(const void *context, size_t size)
}
/*
+ * Create a talloc pool
+ */
+
+void *talloc_pool(const void *context, size_t size)
+{
+ void *result = __talloc(context, size + TALLOC_POOL_HDR_SIZE);
+ struct talloc_chunk *tc;
+
+ if (unlikely(result == NULL)) {
+ return NULL;
+ }
+
+ tc = talloc_chunk_from_ptr(result);
+
+ tc->flags |= TALLOC_FLAG_POOL;
+ tc->pool = (char *)result + TALLOC_POOL_HDR_SIZE;
+
+ *talloc_pool_objectcount(tc) = 1;
+
+#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_NOACCESS)
+ VALGRIND_MAKE_MEM_NOACCESS(tc->pool, size);
+#endif
+
+ return result;
+}
+
+/*
setup a destructor to be called on free of a pointer
the destructor should return 0 on success, or -1 on failure.
if the destructor fails then the free is failed, and the memory can
@@ -420,7 +545,29 @@ static inline int _talloc_free(void *ptr)
}
tc->flags |= TALLOC_FLAG_FREE;
- free(tc);
+
+ if (tc->flags & (TALLOC_FLAG_POOL|TALLOC_FLAG_POOLMEM)) {
+ struct talloc_chunk *pool;
+ unsigned int *pool_object_count;
+
+ pool = (tc->flags & TALLOC_FLAG_POOL)
+ ? tc : (struct talloc_chunk *)tc->pool;
+
+ pool_object_count = talloc_pool_objectcount(pool);
+
+ if (*pool_object_count == 0) {
+ TALLOC_ABORT("Pool object count zero!");
+ }
+
+ *pool_object_count -= 1;
+
+ if (*pool_object_count == 0) {
+ free(pool);
+ }
+ }
+ else {
+ free(tc);
+ }
return 0;
}
@@ -718,6 +865,15 @@ void talloc_free_children(void *ptr)
talloc_steal(new_parent, child);
}
}
+
+ if ((tc->flags & TALLOC_FLAG_POOL)
+ && (*talloc_pool_objectcount(tc) == 1)) {
+ tc->pool = ((char *)tc + TC_HDR_SIZE + TALLOC_POOL_HDR_SIZE);
+#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_NOACCESS)
+ VALGRIND_MAKE_MEM_NOACCESS(
+ tc->pool, tc->size - TALLOC_POOL_HDR_SIZE);
+#endif
+ }
}
/*
@@ -769,6 +925,7 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n
{
struct talloc_chunk *tc;
void *new_ptr;
+ bool malloced = false;
/* size zero is equivalent to free() */
if (unlikely(size == 0)) {
@@ -792,6 +949,12 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n
return NULL;
}
+ /* don't shrink if we have less than 1k to gain */
+ if ((size < tc->size) && ((tc->size - size) < 1024)) {
+ tc->size = size;
+ return ptr;
+ }
+
/* by resetting magic we catch users of the old memory */
tc->flags |= TALLOC_FLAG_FREE;
@@ -802,7 +965,24 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n
free(tc);
}
#else
- new_ptr = realloc(tc, size + TC_HDR_SIZE);
+ if (tc->flags & TALLOC_FLAG_POOLMEM) {
+
+ new_ptr = talloc_alloc_pool(tc, size + TC_HDR_SIZE);
+ *talloc_pool_objectcount((struct talloc_chunk *)
+ (tc->pool)) -= 1;
+
+ if (new_ptr == NULL) {
+ new_ptr = malloc(TC_HDR_SIZE+size);
+ malloced = true;
+ }
+
+ if (new_ptr) {
+ memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE);
+ }
+ }
+ else {
+ new_ptr = realloc(tc, size + TC_HDR_SIZE);
+ }
#endif
if (unlikely(!new_ptr)) {
tc->flags &= ~TALLOC_FLAG_FREE;
@@ -810,7 +990,10 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n
}
tc = (struct talloc_chunk *)new_ptr;
- tc->flags &= ~TALLOC_FLAG_FREE;
+ tc->flags &= ~TALLOC_FLAG_FREE;
+ if (malloced) {
+ tc->flags &= ~TALLOC_FLAG_POOLMEM;
+ }
if (tc->parent) {
tc->parent->child = tc;
}
diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h
index e103391681..5431971655 100644
--- a/source4/lib/talloc/talloc.h
+++ b/source4/lib/talloc/talloc.h
@@ -116,6 +116,7 @@ typedef void TALLOC_CTX;
/* The following definitions come from talloc.c */
void *_talloc(const void *context, size_t size);
+void *talloc_pool(const void *context, size_t size);
void _talloc_set_destructor(const void *ptr, int (*destructor)(void *));
int talloc_increase_ref_count(const void *ptr);
size_t talloc_reference_count(const void *ptr);
diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c
index e16c91f8b9..fedbda95aa 100644
--- a/source4/lib/talloc/testsuite.c
+++ b/source4/lib/talloc/testsuite.c
@@ -813,6 +813,25 @@ static bool test_speed(void)
talloc_free(ctx);
+ ctx = talloc_pool(NULL, 1024);
+
+ tv = timeval_current();
+ count = 0;
+ do {
+ void *p1, *p2, *p3;
+ for (i=0;i<loop;i++) {
+ p1 = talloc_size(ctx, loop % 100);
+ p2 = talloc_strdup(p1, "foo bar");
+ p3 = talloc_size(p1, 300);
+ talloc_free_children(ctx);
+ }
+ count += 3 * loop;
+ } while (timeval_elapsed(&tv) < 5.0);
+
+ talloc_free(ctx);
+
+ fprintf(stderr, "talloc_pool: %.0f ops/sec\n", count/timeval_elapsed(&tv));
+
tv = timeval_current();
count = 0;
do {
@@ -1066,6 +1085,23 @@ static bool test_autofree(void)
return true;
}
+static bool test_pool(void)
+{
+ void *pool;
+ void *p1, *p2, *p3, *p4;
+
+ pool = talloc_pool(NULL, 1024);
+
+ p1 = talloc_size(pool, 80);
+ p2 = talloc_size(pool, 20);
+ p3 = talloc_size(p1, 50);
+ p4 = talloc_size(p3, 1000);
+
+ talloc_free(pool);
+
+ return true;
+}
+
struct torture_context;
bool torture_local_talloc(struct torture_context *tctx)
{
@@ -1094,6 +1130,7 @@ bool torture_local_talloc(struct torture_context *tctx)
ret &= test_free_parent_deny_child();
ret &= test_talloc_ptrtype();
ret &= test_talloc_free_in_destructor();
+ ret &= test_pool();
if (ret) {
ret &= test_speed();
diff --git a/source4/lib/tls/config.m4 b/source4/lib/tls/config.m4
index 00d4194b3a..8b6ad7dcbc 100644
--- a/source4/lib/tls/config.m4
+++ b/source4/lib/tls/config.m4
@@ -1,7 +1,9 @@
###############################
# start SMB_EXT_LIB_GNUTLS
# check for gnutls/gnutls.h and -lgnutls
-SMB_EXT_LIB_FROM_PKGCONFIG(GNUTLS, gnutls)
+SMB_EXT_LIB_FROM_PKGCONFIG(GNUTLS, gnutls,
+ [SMB_ENABLE_GNUTLS=YES],
+ [SMB_ENABLE_GNUTLS=NO])
if test x$SMB_ENABLE_GNUTLS = xNO; then
AC_CHECK_HEADERS(gnutls/gnutls.h)
diff --git a/source4/libnet/config.mk b/source4/libnet/config.mk
index 9041ff5a23..a72ae5b51f 100644
--- a/source4/libnet/config.mk
+++ b/source4/libnet/config.mk
@@ -27,7 +27,7 @@ OBJ_FILES = \
userman.o \
groupman.o \
prereq_domain.o
-PUBLIC_DEPENDENCIES = CREDENTIALS dcerpc dcerpc_samr RPC_NDR_LSA RPC_NDR_SRVSVC RPC_NDR_DRSUAPI LIBCLI_COMPOSITE LIBCLI_RESOLVE LIBCLI_FINDDCS LIBSAMBA3 LIBCLI_CLDAP LIBCLI_FINDDCS gensec_schannel LIBCLI_AUTH LIBNDR
+PUBLIC_DEPENDENCIES = CREDENTIALS dcerpc dcerpc_samr RPC_NDR_LSA RPC_NDR_SRVSVC RPC_NDR_DRSUAPI LIBCLI_COMPOSITE LIBCLI_RESOLVE LIBCLI_FINDDCS LIBCLI_CLDAP LIBCLI_FINDDCS gensec_schannel LIBCLI_AUTH LIBNDR SMBPASSWD
[PYTHON::swig_net]
PRIVATE_DEPENDENCIES = LIBSAMBA-NET
diff --git a/source4/pidl/config.mk b/source4/pidl/config.mk
new file mode 100644
index 0000000000..3793008319
--- /dev/null
+++ b/source4/pidl/config.mk
@@ -0,0 +1,36 @@
+pidl/Makefile: pidl/Makefile.PL
+ cd pidl && $(PERL) Makefile.PL
+
+pidl-testcov: pidl/Makefile
+ cd pidl && cover -test
+
+installpidl:: pidl/Makefile
+ $(MAKE) -C pidl install
+
+uninstallpidl:: pidl/Makefile
+ $(MAKE) -C pidl uninstall
+
+idl_full:: pidl/lib/Parse/Pidl/IDL.pm pidl/lib/Parse/Pidl/Expr.pm
+ @CPP="$(CPP)" PERL="$(PERL)" srcdir=$(srcdir) $(srcdir)/script/build_idl.sh FULL
+
+idl:: pidl/lib/Parse/Pidl/IDL.pm pidl/lib/Parse/Pidl/Expr.pm
+ @CPP="$(CPP)" PERL="$(PERL)" srcdir=$(srcdir) $(srcdir)/script/build_idl.sh PARTIAL
+
+pidl/lib/Parse/Pidl/IDL.pm: pidl/idl.yp
+ -$(YAPP) -m 'Parse::Pidl::IDL' -o pidl/lib/Parse/Pidl/IDL.pm pidl/idl.yp ||\
+ touch pidl/lib/Parse/Pidl/IDL.pm
+
+pidl/lib/Parse/Pidl/Expr.pm: pidl/idl.yp
+ -$(YAPP) -m 'Parse::Pidl::Expr' -o pidl/lib/Parse/Pidl/Expr.pm pidl/expr.yp ||\
+ touch pidl/lib/Parse/Pidl/Expr.pm
+
+testcov-html:: pidl-testcov
+
+$(IDL_HEADER_FILES) \
+ $(IDL_NDR_PARSE_H_FILES) $(IDL_NDR_PARSE_C_FILES) \
+ $(IDL_NDR_CLIENT_C_FILES) $(IDL_NDR_CLIENT_H_FILES) \
+ $(IDL_NDR_SERVER_C_FILES) $(IDL_SWIG_FILES) \
+ $(IDL_NDR_EJS_C_FILES) $(IDL_NDR_EJS_H_FILES) \
+ $(IDL_NDR_PY_C_FILES) $(IDL_NDR_PY_H_FILES): idl
+
+
diff --git a/source4/rules.mk b/source4/rules.mk
index 606e3dbf6e..1ef751b00a 100644
--- a/source4/rules.mk
+++ b/source4/rules.mk
@@ -77,6 +77,7 @@ clean:: clean_pch
distclean:: clean
-rm -f include/config.h include/config_tmp.h include/build.h
+ -rm -f data.mk
-rm -f config.status
-rm -f config.log config.cache
-rm -f config.pm config.mk
diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk
index 656ecdae16..5de17263b7 100644
--- a/source4/scripting/ejs/config.mk
+++ b/source4/scripting/ejs/config.mk
@@ -28,13 +28,6 @@ SUBSYSTEM = smbcalls
OUTPUT_TYPE = INTEGRATED
INIT_FUNCTION = smb_setup_ejs_nbt
-[MODULE::smbcalls_samba3]
-OBJ_FILES = smbcalls_samba3.o
-SUBSYSTEM = smbcalls
-OUTPUT_TYPE = INTEGRATED
-INIT_FUNCTION = smb_setup_ejs_samba3
-PRIVATE_DEPENDENCIES = LIBSAMBA3
-
[MODULE::smbcalls_rand]
OBJ_FILES = smbcalls_rand.o
SUBSYSTEM = smbcalls
diff --git a/source4/scripting/ejs/smbcalls_samba3.c b/source4/scripting/ejs/smbcalls_samba3.c
deleted file mode 100644
index 36ec2a54e4..0000000000
--- a/source4/scripting/ejs/smbcalls_samba3.c
+++ /dev/null
@@ -1,501 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- provide hooks into smbd C calls from ejs scripts
-
- Copyright (C) Jelmer Vernooij 2005
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "scripting/ejs/smbcalls.h"
-#include "lib/appweb/ejs/ejs.h"
-#include "lib/samba3/samba3.h"
-#include "libcli/security/security.h"
-#include "librpc/gen_ndr/ndr_misc.h"
-#include "system/network.h"
-
-
-static struct MprVar mprRegistry(struct samba3_regdb *reg)
-{
- struct MprVar mpv = mprObject("registry"), ks, vs, k, v;
- int i, j;
-
- ks = mprArray("array");
-
- for (i = 0; i < reg->key_count; i++) {
- k = mprObject("regkey");
-
- mprSetVar(&k, "name", mprString(reg->keys[i].name));
-
- vs = mprArray("array");
-
- for (j = 0; j < reg->keys[i].value_count; j++) {
- v = mprObject("regval");
-
- mprSetVar(&v, "name", mprString(reg->keys[i].values[j].name));
- mprSetVar(&v, "type", mprCreateIntegerVar(reg->keys[i].values[j].type));
- mprSetVar(&v, "data", mprDataBlob(reg->keys[i].values[j].data));
-
- mprAddArray(&vs, j, v);
- }
-
- mprSetVar(&k, "values", vs);
-
- mprAddArray(&ks, i, k);
- }
-
- if (i == 0) {
- mprSetVar(&ks, "length", mprCreateIntegerVar(i));
- }
-
- mprSetVar(&mpv, "keys", ks);
-
- return mpv;
-}
-
-static struct MprVar mprPolicy(struct samba3_policy *pol)
-{
- struct MprVar mpv = mprObject("policy");
-
- mprSetVar(&mpv, "min_password_length", mprCreateIntegerVar(pol->min_password_length));
- mprSetVar(&mpv, "password_history", mprCreateIntegerVar(pol->password_history));
- mprSetVar(&mpv, "user_must_logon_to_change_password", mprCreateIntegerVar(pol->user_must_logon_to_change_password));
- mprSetVar(&mpv, "maximum_password_age", mprCreateIntegerVar(pol->maximum_password_age));
- mprSetVar(&mpv, "minimum_password_age", mprCreateIntegerVar(pol->minimum_password_age));
- mprSetVar(&mpv, "lockout_duration", mprCreateIntegerVar(pol->lockout_duration));
- mprSetVar(&mpv, "reset_count_minutes", mprCreateIntegerVar(pol->reset_count_minutes));
- mprSetVar(&mpv, "bad_lockout_minutes", mprCreateIntegerVar(pol->bad_lockout_minutes));
- mprSetVar(&mpv, "disconnect_time", mprCreateIntegerVar(pol->disconnect_time));
- mprSetVar(&mpv, "refuse_machine_password_change", mprCreateIntegerVar(pol->refuse_machine_password_change));
-
- return mpv;
-}
-
-static struct MprVar mprIdmapDb(struct samba3_idmapdb *db)
-{
- struct MprVar mpv = mprObject("idmapdb"), mps, mp;
- int i;
-
- mprSetVar(&mpv, "user_hwm", mprCreateIntegerVar(db->user_hwm));
- mprSetVar(&mpv, "group_hwm", mprCreateIntegerVar(db->group_hwm));
-
- mps = mprArray("array");
-
- for (i = 0; i < db->mapping_count; i++) {
- char *tmp;
- mp = mprObject("idmap");
-
- mprSetVar(&mp, "IDMAP_GROUP", mprCreateIntegerVar(IDMAP_GROUP));
- mprSetVar(&mp, "IDMAP_USER", mprCreateIntegerVar(IDMAP_USER));
- mprSetVar(&mp, "type", mprCreateIntegerVar(db->mappings[i].type));
- mprSetVar(&mp, "unix_id", mprCreateIntegerVar(db->mappings[i].unix_id));
-
- tmp = dom_sid_string(NULL, db->mappings[i].sid);
- mprSetVar(&mp, "sid", mprString(tmp));
- talloc_free(tmp);
-
- mprAddArray(&mps, i, mp);
- }
-
- if (i == 0) {
- mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
- }
-
-
- mprSetVar(&mpv, "mappings", mps);
-
- return mpv;
-}
-
-static struct MprVar mprGroupMappings(struct samba3_groupdb *db)
-{
- struct MprVar mpv = mprArray("array"), g;
- int i;
-
- for (i = 0; i < db->groupmap_count; i++) {
- char *tmp;
- g = mprObject("group");
-
- mprSetVar(&g, "gid", mprCreateIntegerVar(db->groupmappings[i].gid));
-
- tmp = dom_sid_string(NULL, db->groupmappings[i].sid);
- mprSetVar(&g, "sid", mprString(tmp));
- talloc_free(tmp);
-
- mprSetVar(&g, "sid_name_use", mprCreateIntegerVar(db->groupmappings[i].sid_name_use));
- mprSetVar(&g, "nt_name", mprString(db->groupmappings[i].nt_name));
- mprSetVar(&g, "comment", mprString(db->groupmappings[i].comment));
-
- mprAddArray(&mpv, i, g);
- }
-
- if (i == 0) {
- mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
- }
-
-
- return mpv;
-}
-
-static struct MprVar mprAliases(struct samba3_groupdb *db)
-{
- struct MprVar mpv = mprObject("array"), a, am;
- int i, j;
-
- for (i = 0; i < db->alias_count; i++) {
- char *tmp;
- a = mprObject("alias");
-
- tmp = dom_sid_string(NULL, db->aliases[i].sid);
- mprSetVar(&a, "sid", mprString(tmp));
- talloc_free(tmp);
-
- am = mprArray("array");
-
- for (j = 0; j < db->aliases[i].member_count; j++) {
- tmp = dom_sid_string(NULL, db->aliases[i].members[j]);
- mprAddArray(&am, j, mprString(tmp));
- talloc_free(tmp);
- }
-
- mprSetVar(&a, "members", am);
- }
-
- if (i == 0) {
- mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
- }
-
- return mpv;
-}
-
-static struct MprVar mprDomainSecrets(struct samba3_domainsecrets *ds)
-{
- struct MprVar v, e = mprObject("domainsecrets");
- char *tmp;
- DATA_BLOB blob;
-
- mprSetVar(&e, "name", mprString(ds->name));
-
- tmp = dom_sid_string(NULL, &ds->sid);
- mprSetVar(&e, "sid", mprString(tmp));
- talloc_free(tmp);
-
- tmp = GUID_string(NULL, &ds->guid);
- mprSetVar(&e, "guid", mprString(tmp));
- talloc_free(tmp);
-
- mprSetVar(&e, "plaintext_pw", mprString(ds->plaintext_pw));
-
- mprSetVar(&e, "last_change_time", mprCreateIntegerVar(ds->last_change_time));
- mprSetVar(&e, "sec_channel_type", mprCreateIntegerVar(ds->sec_channel_type));
-
- v = mprObject("hash_pw");
-
- blob.data = ds->hash_pw.hash;
- blob.length = 16;
- mprSetVar(&v, "hash", mprDataBlob(blob));
-
- mprSetVar(&v, "mod_time", mprCreateIntegerVar(ds->hash_pw.mod_time));
-
- mprSetVar(&e, "hash_pw", v);
-
- return e;
-}
-
-static struct MprVar mprSecrets(struct samba3_secrets *sec)
-{
- struct MprVar mpv = mprObject("samba3_secrets"), es, e;
- int i;
-
- es = mprArray("array");
-
- for (i = 0; i < sec->ldappw_count; i++) {
- e = mprObject("ldappw");
-
- mprSetVar(&e, "dn", mprString(sec->ldappws[i].dn));
- mprSetVar(&e, "password", mprString(sec->ldappws[i].password));
-
- mprAddArray(&es, i, e);
- }
-
- mprSetVar(&mpv, "ldappws", es);
-
- es = mprArray("array");
-
- for (i = 0; i < sec->domain_count; i++) {
- mprAddArray(&es, i, mprDomainSecrets(&sec->domains[i]));
- }
-
- if (i == 0) {
- mprSetVar(&es, "length", mprCreateIntegerVar(i));
- }
-
- mprSetVar(&mpv, "domains", es);
-
- es = mprArray("trusted_domains");
-
- for (i = 0; i < sec->trusted_domain_count; i++) {
- struct MprVar ns;
- char *tmp;
- int j;
- e = mprObject("trusted_domain");
-
- ns = mprArray("array");
-
- for (j = 0; j < sec->trusted_domains[i].uni_name_len; j++) {
- mprAddArray(&ns, j, mprString(sec->trusted_domains[i].uni_name[j]));
- }
-
- mprSetVar(&e, "uni_name", ns);
-
- mprSetVar(&e, "pass", mprString(sec->trusted_domains[i].pass));
- mprSetVar(&e, "mod_time", mprCreateIntegerVar(sec->trusted_domains[i].mod_time));
-
- tmp = dom_sid_string(NULL, &sec->trusted_domains[i].domain_sid);
- mprSetVar(&e, "domains_sid", mprString(tmp));
- talloc_free(tmp);
-
- mprAddArray(&es, i, e);
- }
-
- if (i == 0) {
- mprSetVar(&es, "length", mprCreateIntegerVar(i));
- }
-
- mprSetVar(&mpv, "trusted_domains", es);
-
- es = mprArray("array");
-
- for (i = 0; i < sec->afs_keyfile_count; i++) {
- struct MprVar ks;
- int j;
- e = mprObject("afs_keyfile");
-
- mprSetVar(&e, "cell", mprString(sec->afs_keyfiles[i].cell));
-
- ks = mprArray("array");
-
- for (j = 0; j < 8; j++) {
- struct MprVar k = mprObject("entry");
- DATA_BLOB blob;
-
- mprSetVar(&k, "kvno", mprCreateIntegerVar(sec->afs_keyfiles[i].entry[j].kvno));
- blob.data = (uint8_t*)sec->afs_keyfiles[i].entry[j].key;
- blob.length = 8;
- mprSetVar(&k, "key", mprDataBlob(blob));
-
- mprAddArray(&ks, j, k);
- }
-
- mprSetVar(&e, "entry", ks);
-
- mprSetVar(&e, "nkeys", mprCreateIntegerVar(sec->afs_keyfiles[i].nkeys));
-
- mprAddArray(&es, i, e);
- }
-
- if (i == 0) {
- mprSetVar(&es, "length", mprCreateIntegerVar(i));
- }
-
- mprSetVar(&mpv, "afs_keyfiles", es);
-
- mprSetVar(&mpv, "ipc_cred", mprCredentials(sec->ipc_cred));
-
- return mpv;
-}
-
-static struct MprVar mprShares(struct samba3 *samba3)
-{
- struct MprVar mpv = mprArray("array"), s;
- int i;
-
- for (i = 0; i < samba3->share_count; i++) {
- s = mprObject("share");
-
- mprSetVar(&s, "name", mprString(samba3->shares[i].name));
-
- /* FIXME: secdesc */
-
- mprAddArray(&mpv, i, s);
- }
-
- if (i == 0) {
- mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
- }
-
- return mpv;
-}
-
-static struct MprVar mprSamAccounts(struct samba3 *samba3)
-{
- struct MprVar mpv = mprArray("array"), m;
- int i;
-
- for (i = 0; i < samba3->samaccount_count; i++) {
- struct samba3_samaccount *a = &samba3->samaccounts[i];
- DATA_BLOB blob;
-
- m = mprObject("samba3_samaccount");
-
- mprSetVar(&m, "logon_time", mprCreateIntegerVar(a->logon_time));
- mprSetVar(&m, "logoff_time", mprCreateIntegerVar(a->logoff_time));
- mprSetVar(&m, "kickoff_time", mprCreateIntegerVar(a->kickoff_time));
- mprSetVar(&m, "bad_password_time", mprCreateIntegerVar(a->bad_password_time));
- mprSetVar(&m, "pass_last_set_time", mprCreateIntegerVar(a->pass_last_set_time));
- mprSetVar(&m, "pass_can_change_time", mprCreateIntegerVar(a->pass_can_change_time));
- mprSetVar(&m, "pass_must_change_time", mprCreateIntegerVar(a->pass_must_change_time));
- mprSetVar(&m, "user_rid", mprCreateIntegerVar(a->user_rid));
- mprSetVar(&m, "group_rid", mprCreateIntegerVar(a->group_rid));
- mprSetVar(&m, "acct_ctrl", mprCreateIntegerVar(a->acct_ctrl));
- mprSetVar(&m, "logon_divs", mprCreateIntegerVar(a->logon_divs));
- mprSetVar(&m, "bad_password_count", mprCreateIntegerVar(a->bad_password_count));
- mprSetVar(&m, "logon_count", mprCreateIntegerVar(a->logon_count));
- mprSetVar(&m, "username", mprString(a->username));
- mprSetVar(&m, "domain", mprString(a->domain));
- mprSetVar(&m, "nt_username", mprString(a->nt_username));
- mprSetVar(&m, "dir_drive", mprString(a->dir_drive));
- mprSetVar(&m, "munged_dial", mprString(a->munged_dial));
- mprSetVar(&m, "fullname", mprString(a->fullname));
- mprSetVar(&m, "homedir", mprString(a->homedir));
- mprSetVar(&m, "logon_script", mprString(a->logon_script));
- mprSetVar(&m, "profile_path", mprString(a->profile_path));
- mprSetVar(&m, "acct_desc", mprString(a->acct_desc));
- mprSetVar(&m, "workstations", mprString(a->workstations));
- blob.length = 16;
- blob.data = a->lm_pw.hash;
- mprSetVar(&m, "lm_pw", mprDataBlob(blob));
- blob.data = a->nt_pw.hash;
- mprSetVar(&m, "nt_pw", mprDataBlob(blob));
-
- mprAddArray(&mpv, i, m);
- }
-
- if (i == 0) {
- mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
- }
-
- return mpv;
-}
-
-static struct MprVar mprWinsEntries(struct samba3 *samba3)
-{
- struct MprVar mpv = mprArray("array");
- int i, j;
-
- for (i = 0; i < samba3->winsdb_count; i++) {
- struct MprVar w = mprObject("wins_entry"), ips;
-
- mprSetVar(&w, "name", mprString(samba3->winsdb_entries[i].name));
- mprSetVar(&w, "nb_flags", mprCreateIntegerVar(samba3->winsdb_entries[i].nb_flags));
- mprSetVar(&w, "type", mprCreateIntegerVar(samba3->winsdb_entries[i].type));
- mprSetVar(&w, "ttl", mprCreateIntegerVar(samba3->winsdb_entries[i].ttl));
-
- ips = mprObject("array");
-
- for (j = 0; j < samba3->winsdb_entries[i].ip_count; j++) {
- const char *addr;
- addr = inet_ntoa(samba3->winsdb_entries[i].ips[j]);
- mprAddArray(&ips, j, mprString(addr));
- }
-
- mprSetVar(&w, "ips", ips);
-
- mprAddArray(&mpv, i, w);
- }
-
- if (i == 0) {
- mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
- }
-
- return mpv;
-}
-
-static int ejs_find_domainsecrets(MprVarHandle eid, int argc, struct MprVar **argv)
-{
- struct samba3 *samba3 = NULL;
- struct samba3_domainsecrets *sec;
-
- if (argc < 1) {
- ejsSetErrorMsg(eid, "find_domainsecrets invalid arguments");
- return -1;
- }
-
- samba3 = (struct samba3 *)mprGetThisPtr(eid, "samba3");
- mprAssert(samba3);
- sec = samba3_find_domainsecrets(samba3, mprToString(argv[0]));
-
- if (sec == NULL) {
- mpr_Return(eid, mprCreateUndefinedVar());
- } else {
- mpr_Return(eid, mprDomainSecrets(sec));
- }
-
- return 0;
-}
-
-/*
- initialise samba3 ejs subsystem
-
- samba3 = samba3_read(libdir,smbconf)
-*/
-static int ejs_samba3_read(MprVarHandle eid, int argc, struct MprVar **argv)
-{
- struct MprVar mpv = mprObject("samba3");
- struct samba3 *samba3;
- NTSTATUS status;
-
- if (argc < 2) {
- ejsSetErrorMsg(eid, "samba3_read invalid arguments");
- return -1;
- }
-
- status = samba3_read(mprToString(argv[0]), mprToString(argv[1]), mprMemCtx(), &samba3);
-
- if (NT_STATUS_IS_ERR(status)) {
- ejsSetErrorMsg(eid, "samba3_read: error");
- return -1;
- }
-
- mprAssert(samba3);
-
- mprSetPtrChild(&mpv, "samba3", samba3);
- mprSetVar(&mpv, "winsentries", mprWinsEntries(samba3));
- mprSetVar(&mpv, "samaccounts", mprSamAccounts(samba3));
- mprSetVar(&mpv, "shares", mprShares(samba3));
- mprSetVar(&mpv, "secrets", mprSecrets(&samba3->secrets));
- mprSetVar(&mpv, "groupmappings", mprGroupMappings(&samba3->group));
- mprSetVar(&mpv, "aliases", mprAliases(&samba3->group));
- mprSetVar(&mpv, "idmapdb", mprIdmapDb(&samba3->idmap));
- mprSetVar(&mpv, "policy", mprPolicy(&samba3->policy));
- mprSetVar(&mpv, "registry", mprRegistry(&samba3->registry));
- mprSetVar(&mpv, "configuration", mprParam(samba3->configuration));
- mprSetCFunction(&mpv, "find_domainsecrets", ejs_find_domainsecrets);
-
- mpr_Return(eid, mpv);
-
- return 0;
-}
-
-
-/*
- setup C functions that be called from ejs
-*/
-NTSTATUS smb_setup_ejs_samba3(void)
-{
- ejsDefineCFunction(-1, "samba3_read", ejs_samba3_read, NULL, MPR_VAR_SCRIPT_HANDLE);
- return NT_STATUS_OK;
-}
diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh
index c2ce9dc6f1..fba9e8603e 100755
--- a/source4/selftest/samba4_tests.sh
+++ b/source4/selftest/samba4_tests.sh
@@ -262,9 +262,6 @@ done
DATADIR=$samba4srcdir/../testdata
-plantest "parse samba3" none $samba4bindir/smbscript $DATADIR/samba3/verify $CONFIGURATION $DATADIR/samba3
-plantest "js.samba3sam" none $SCRIPTDIR/samba3sam.js $CONFIGURATION `pwd` $DATADIR/samba3/
-
# Domain Member Tests
plantest "RPC-ECHO against member server with local creds" member $VALGRIND $smb4torture ncacn_np:"\$NETBIOSNAME" -U"\$NETBIOSNAME/\$USERNAME"%"\$PASSWORD" RPC-ECHO "$*"
diff --git a/source4/torture/config.mk b/source4/torture/config.mk
index e9ef18ac07..0c5e641b4b 100644
--- a/source4/torture/config.mk
+++ b/source4/torture/config.mk
@@ -196,8 +196,8 @@ OBJ_FILES = \
auth/ntlmssp.o \
auth/pac.o
PRIVATE_DEPENDENCIES = \
- LIBCLI_SMB gensec auth LIBSAMBA3 KERBEROS \
- POPT_CREDENTIALS
+ LIBCLI_SMB gensec auth KERBEROS \
+ POPT_CREDENTIALS SMBPASSWD
# End SUBSYSTEM TORTURE_AUTH
#################################
diff --git a/testdata/samba3/verify b/testdata/samba3/verify
deleted file mode 100755
index ca495b137d..0000000000
--- a/testdata/samba3/verify
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env smbscript
-/* Verifies that the data present in this directory
- Can be read correctly by Samba4. Do not update
- without changing the corresponding TDB file!
- Written by Jelmer Vernooij, 2005.
- */
-
-var sys;
-var options = GetOptions(ARGV, "POPT_AUTOHELP", "POPT_COMMON_SAMBA");
-if (options == undefined) {
- println("Failed to parse options");
- return -1;
-}
-
-libinclude("base.js");
-
-var path = substr(ARGV[0], 0, -strlen("verify"));
-printf("Reading from %s\n", path);
-
-var s = samba3_read(path, path+"smb.conf");
-assert(s != undefined);
-
-// smb.conf checks
-assert(s.configuration.get("passdb backend") != undefined);
-
-var data = s.configuration.data();
-assert(data != undefined);
-var global = data["global"];
-assert(global != undefined);
-assert(global["passdb backend"] == s.configuration.get("passdb backend"));
-assert(global["passdb backend"] != undefined);
-
-println("smb.conf ok");
-
-assert(s.winsentries.length == 22);
-assert(s.samaccounts.length == 3);
-assert(s.shares.length == 0);
-assert(s.registry.keys.length == 28);
-assert(s.groupmappings.length == 13);
-assert(s.aliases.length == 0);
-assert(s.idmapdb.mappings.length == 4);
-
-println("database entry count correct");
-
-// account policies
-assert(s.policy.min_password_length == 5);
-assert(s.policy.minimum_password_age == 0);
-assert(s.policy.maximum_password_age == 999999999);
-assert(s.policy.refuse_machine_password_change == 0);
-assert(s.policy.reset_count_minutes == 0);
-assert(s.policy.disconnect_time == -1);
-assert(s.policy.user_must_logon_to_change_password == 0);
-assert(s.policy.password_history == 0);
-assert(s.policy.lockout_duration == 0);
-assert(s.policy.bad_lockout_minutes == 0);
-
-println("account policies ok");
-
-exit(0);
diff --git a/testprogs/ejs/samba3sam.js b/testprogs/ejs/samba3sam.js
deleted file mode 100755
index e5639b8ec8..0000000000
--- a/testprogs/ejs/samba3sam.js
+++ /dev/null
@@ -1,1255 +0,0 @@
-#!/usr/bin/env smbscript
-/*
- (C) Jelmer Vernooij <jelmer@samba.org> 2005
- (C) Martin Kuehl <mkhl@samba.org> 2006
- Published under the GNU GPL
- Sponsored by Google Summer of Code
- */
-
-var sys;
-var options = GetOptions(ARGV, "POPT_AUTOHELP", "POPT_COMMON_SAMBA");
-if (options == undefined) {
- println("Failed to parse options");
- return -1;
-}
-
-libinclude("base.js");
-
-if (options.ARGV.length != 2) {
- println("Usage: samba3sam.js <TESTDIR> <DATADIR>");
- return -1;
-}
-
-var prefix = options.ARGV[0];
-var datadir = options.ARGV[1];
-
-function setup_data(obj, ldif)
-{
- assert(ldif != undefined);
- ldif = substitute_var(ldif, obj);
- assert(ldif != undefined);
- var ok = obj.db.add(ldif);
- assert(ok.error == 0);
-}
-
-function setup_modules(ldb, s3, s4, ldif)
-{
- assert(ldif != undefined);
- ldif = substitute_var(ldif, s4);
- assert(ldif != undefined);
- var ok = ldb.add(ldif);
- assert(ok.error == 0);
-
- var ldif = "
-dn: @MAP=samba3sam
-@FROM: " + s4.BASEDN + "
-@TO: sambaDomainName=TESTS," + s3.BASEDN + "
-
-dn: @MODULES
-@LIST: rootdse,paged_results,server_sort,extended_dn,asq,samldb,password_hash,operational,objectguid,rdn_name,samba3sam,partition
-
-dn: @PARTITION
-partition: " + s4.BASEDN + ":" + s4.url + "
-partition: " + s3.BASEDN + ":" + s3.url + "
-replicateEntries: @SUBCLASSES
-replicateEntries: @ATTRIBUTES
-replicateEntries: @INDEXLIST
-";
- var ok = ldb.add(ldif);
- assert(ok.error == 0);
-}
-
-function test_s3sam_search(ldb)
-{
- println("Looking up by non-mapped attribute");
- var msg = ldb.search("(cn=Administrator)");
- assert(msg.error == 0);
- assert(msg.msgs.length == 1);
- assert(msg.msgs[0].cn == "Administrator");
-
- println("Looking up by mapped attribute");
- var msg = ldb.search("(name=Backup Operators)");
- assert(msg.error == 0);
- assert(msg.msgs.length == 1);
- assert(msg.msgs[0].name == "Backup Operators");
-
- println("Looking up by old name of renamed attribute");
- var msg = ldb.search("(displayName=Backup Operators)");
- assert(msg.msgs.length == 0);
-
- println("Looking up mapped entry containing SID");
- var msg = ldb.search("(cn=Replicator)");
- assert(msg.error == 0);
- assert(msg.msgs.length == 1);
- println(msg.msgs[0].dn);
- assert(msg.msgs[0].dn == "cn=Replicator,ou=Groups,dc=vernstok,dc=nl");
- assert(msg.msgs[0].objectSid == "S-1-5-21-4231626423-2410014848-2360679739-552");
-
- println("Checking mapping of objectClass");
- var oc = msg.msgs[0].objectClass;
- assert(oc != undefined);
- for (var i in oc) {
- assert(oc[i] == "posixGroup" || oc[i] == "group");
- }
-
- println("Looking up by objectClass");
- var msg = ldb.search("(|(objectClass=user)(cn=Administrator))");
- assert(msg.error == 0);
- assert(msg.msgs.length == 2);
- for (var i = 0; i < msg.msgs.length; i++) {
- assert((msg.msgs[i].dn == "unixName=Administrator,ou=Users,dc=vernstok,dc=nl") ||
- (msg.msgs[i].dn == "unixName=nobody,ou=Users,dc=vernstok,dc=nl"));
- }
-}
-
-function test_s3sam_modify(ldb, s3)
-{
- var msg, ok;
- println("Adding a record that will be fallbacked");
- ok = ldb.add("
-dn: cn=Foo
-foo: bar
-blah: Blie
-cn: Foo
-showInAdvancedViewOnly: TRUE
-");
- if (ok.error != 0) {
- println(ok.errstr);
- assert(ok.error == 0);
- }
-
- println("Checking for existence of record (local)");
- /* TODO: This record must be searched in the local database, which is currently only supported for base searches
- * msg = ldb.search("(cn=Foo)", new Array('foo','blah','cn','showInAdvancedViewOnly'));
- * TODO: Actually, this version should work as well but doesn't...
- *
- */
- var attrs = new Array('foo','blah','cn','showInAdvancedViewOnly');
- msg = ldb.search("(cn=Foo)", "cn=Foo", ldb.LDB_SCOPE_BASE, attrs);
- assert(msg.error == 0);
- assert(msg.msgs.length == 1);
- assert(msg.msgs[0].showInAdvancedViewOnly == "TRUE");
- assert(msg.msgs[0].foo == "bar");
- assert(msg.msgs[0].blah == "Blie");
-
- println("Adding record that will be mapped");
- ok = ldb.add("
-dn: cn=Niemand,cn=Users,dc=vernstok,dc=nl
-objectClass: user
-unixName: bin
-sambaUnicodePwd: geheim
-cn: Niemand
-");
- if (ok.error != 0) {
- println(ok.errstr);
- assert(ok.error == 0);
- }
- assert(ok.error == 0);
-
- println("Checking for existence of record (remote)");
- msg = ldb.search("(unixName=bin)", new Array('unixName','cn','dn', 'sambaUnicodePwd'));
- assert(msg.error == 0);
- assert(msg.msgs.length == 1);
- assert(msg.msgs[0].cn == "Niemand");
- assert(msg.msgs[0].sambaUnicodePwd == "geheim");
-
- println("Checking for existence of record (local && remote)");
- msg = ldb.search("(&(unixName=bin)(sambaUnicodePwd=geheim))", new Array('unixName','cn','dn', 'sambaUnicodePwd'));
- assert(msg.error == 0);
- assert(msg.msgs.length == 1); // TODO: should check with more records
- assert(msg.msgs[0].cn == "Niemand");
- assert(msg.msgs[0].unixName == "bin");
- assert(msg.msgs[0].sambaUnicodePwd == "geheim");
-
- println("Checking for existence of record (local || remote)");
- msg = ldb.search("(|(unixName=bin)(sambaUnicodePwd=geheim))", new Array('unixName','cn','dn', 'sambaUnicodePwd'));
- println("got " + msg.msgs.length + " replies");
- assert(msg.error == 0);
- assert(msg.msgs.length == 1); // TODO: should check with more records
- assert(msg.msgs[0].cn == "Niemand");
- assert(msg.msgs[0].unixName == "bin" || msg.msgs[0].sambaUnicodePwd == "geheim");
-
- println("Checking for data in destination database");
- msg = s3.db.search("(cn=Niemand)");
- assert(msg.error == 0);
- assert(msg.msgs.length >= 1);
- assert(msg.msgs[0].sambaSID == "S-1-5-21-4231626423-2410014848-2360679739-2001");
- assert(msg.msgs[0].displayName == "Niemand");
-
- println("Adding attribute...");
- ok = ldb.modify("
-dn: cn=Niemand,cn=Users,dc=vernstok,dc=nl
-changetype: modify
-add: description
-description: Blah
-");
- if (ok.error != 0) {
- println(ok.errstr);
- assert(ok.error == 0);
- }
- assert(ok.error == 0);
-
- println("Checking whether changes are still there...");
- msg = ldb.search("(cn=Niemand)");
- assert(msg.error == 0);
- assert(msg.msgs.length >= 1);
- assert(msg.msgs[0].cn == "Niemand");
- assert(msg.msgs[0].description == "Blah");
-
- println("Modifying attribute...");
- ok = ldb.modify("
-dn: cn=Niemand,cn=Users,dc=vernstok,dc=nl
-changetype: modify
-replace: description
-description: Blie
-");
- if (ok.error != 0) {
- println(ok.errstr);
- assert(ok.error == 0);
- }
- assert(ok.error == 0);
-
- println("Checking whether changes are still there...");
- msg = ldb.search("(cn=Niemand)");
- assert(msg.error == 0);
- assert(msg.msgs.length >= 1);
- assert(msg.msgs[0].description == "Blie");
-
- println("Deleting attribute...");
- ok = ldb.modify("
-dn: cn=Niemand,cn=Users,dc=vernstok,dc=nl
-changetype: modify
-delete: description
-");
- if (ok.error != 0) {
- println(ok.errstr);
- assert(ok.error == 0);
- }
- assert(ok.error == 0);
-
- println("Checking whether changes are no longer there...");
- msg = ldb.search("(cn=Niemand)");
- assert(msg.error == 0);
- assert(msg.msgs.length >= 1);
- assert(msg.msgs[0].description == undefined);
-
- println("Renaming record...");
- ok = ldb.rename("cn=Niemand,cn=Users,dc=vernstok,dc=nl", "cn=Niemand2,cn=Users,dc=vernstok,dc=nl");
- assert(ok.error == 0);
-
- println("Checking whether DN has changed...");
- msg = ldb.search("(cn=Niemand2)");
- assert(msg.error == 0);
- assert(msg.msgs.length == 1);
- assert(msg.msgs[0].dn == "cn=Niemand2,cn=Users,dc=vernstok,dc=nl");
-
- println("Deleting record...");
- ok = ldb.del("cn=Niemand2,cn=Users,dc=vernstok,dc=nl");
- if (ok.error != 0) {
- println(ok.errstr);
- assert(ok.error == 0);
- }
-
- println("Checking whether record is gone...");
- msg = ldb.search("(cn=Niemand2)");
- assert(msg.error == 0);
- assert(msg.msgs.length == 0);
-}
-
-function test_map_search(ldb, s3, s4)
-{
- println("Running search tests on mapped data");
- var res;
- var dn;
- var attrs;
-
-
- var ldif = "
-dn: " + "sambaDomainName=TESTS," + s3.BASEDN + "
-objectclass: sambaDomain
-objectclass: top
-sambaSID: S-1-5-21-4231626423-2410014848-2360679739
-sambaNextRid: 2000
-sambaDomainName: TESTS"
- ldif = substitute_var(ldif, s3);
- assert(ldif != undefined);
- var ok = s3.db.add(ldif);
- assert(ok.error == 0);
-
- printf("Add a set of split records");
- var ldif = "
-dn: " + s4.dn("cn=X") + "
-objectClass: user
-cn: X
-codePage: x
-revision: x
-dnsHostName: x
-nextRid: y
-lastLogon: x
-description: x
-objectSid: S-1-5-21-4231626423-2410014848-2360679739-552
-primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
-
-dn: " + s4.dn("cn=Y") + "
-objectClass: top
-cn: Y
-codePage: x
-revision: x
-dnsHostName: y
-nextRid: y
-lastLogon: y
-description: x
-
-dn: " + s4.dn("cn=Z") + "
-objectClass: top
-cn: Z
-codePage: x
-revision: y
-dnsHostName: z
-nextRid: y
-lastLogon: z
-description: y
-";
-
- ldif = substitute_var(ldif, s4);
- assert(ldif != undefined);
- var ok = ldb.add(ldif);
- if (ok.error != 0) {
- println(ok.errstr);
- assert(ok.error == 0);
- }
-
- println("Add a set of remote records");
-
- var ldif = "
-dn: " + s3.dn("cn=A") + "
-objectClass: posixAccount
-cn: A
-sambaNextRid: x
-sambaBadPasswordCount: x
-sambaLogonTime: x
-description: x
-sambaSID: S-1-5-21-4231626423-2410014848-2360679739-552
-sambaPrimaryGroupSID: S-1-5-21-4231626423-2410014848-2360679739-512
-
-dn: " + s3.dn("cn=B") + "
-objectClass: top
-cn:B
-sambaNextRid: x
-sambaBadPasswordCount: x
-sambaLogonTime: y
-description: x
-
-dn: " + s3.dn("cn=C") + "
-objectClass: top
-cn: C
-sambaNextRid: x
-sambaBadPasswordCount: y
-sambaLogonTime: z
-description: y
-";
- ldif = substitute_var(ldif, s3);
- assert(ldif != undefined);
- var ok = s3.db.add(ldif);
- assert(ok.error == 0);
-
- println("Testing search by DN");
-
- /* Search remote record by local DN */
- dn = s4.dn("cn=A");
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "x");
-
- /* Search remote record by remote DN */
- dn = s3.dn("cn=A");
- attrs = new Array("dnsHostName", "lastLogon", "sambaLogonTime");
- res = s3.db.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == undefined);
- assert(res.msgs[0].sambaLogonTime == "x");
-
- /* Search split record by local DN */
- dn = s4.dn("cn=X");
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].dnsHostName == "x");
- assert(res.msgs[0].lastLogon == "x");
-
- /* Search split record by remote DN */
- dn = s3.dn("cn=X");
- attrs = new Array("dnsHostName", "lastLogon", "sambaLogonTime");
- res = s3.db.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == undefined);
- assert(res.msgs[0].sambaLogonTime == "x");
-
- println("Testing search by attribute");
-
- /* Search by ignored attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(revision=x)", NULL, ldb. SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 2);
- assert(res.msgs[0].dn == s4.dn("cn=Y"));
- assert(res.msgs[0].dnsHostName == "y");
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=X"));
- assert(res.msgs[1].dnsHostName == "x");
- assert(res.msgs[1].lastLogon == "x");
-
- /* Search by kept attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(description=y)", NULL, ldb. SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 2);
- assert(res.msgs[0].dn == s4.dn("cn=Z"));
- assert(res.msgs[0].dnsHostName == "z");
- assert(res.msgs[0].lastLogon == "z");
- assert(res.msgs[1].dn == s4.dn("cn=C"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "z");
-
- /* Search by renamed attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(badPwdCount=x)", NULL, ldb. SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 2);
- assert(res.msgs[0].dn == s4.dn("cn=B"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=A"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "x");
-
- /* Search by converted attribute */
- attrs = new Array("dnsHostName", "lastLogon", "objectSid");
- /* TODO:
- Using the SID directly in the parse tree leads to conversion
- errors, letting the search fail with no results.
- res = ldb.search("(objectSid=S-1-5-21-4231626423-2410014848-2360679739-552)", NULL, ldb. SCOPE_DEFAULT, attrs);
- */
- res = ldb.search("(objectSid=*)", NULL, ldb. SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 3);
- assert(res.msgs[0].dn == s4.dn("cn=X"));
- assert(res.msgs[0].dnsHostName == "x");
- assert(res.msgs[0].lastLogon == "x");
- assert(res.msgs[0].objectSid == "S-1-5-21-4231626423-2410014848-2360679739-552");
- assert(res.msgs[1].dn == s4.dn("cn=A"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "x");
- assert(res.msgs[1].objectSid == "S-1-5-21-4231626423-2410014848-2360679739-552");
-
- /* Search by generated attribute */
- /* In most cases, this even works when the mapping is missing
- * a `convert_operator' by enumerating the remote db. */
- attrs = new Array("dnsHostName", "lastLogon", "primaryGroupID");
- res = ldb.search("(primaryGroupID=512)", NULL, ldb. SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == s4.dn("cn=A"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "x");
- assert(res.msgs[0].primaryGroupID == "512");
-
- /* TODO: There should actually be two results, A and X. The
- * primaryGroupID of X seems to get corrupted somewhere, and the
- * objectSid isn't available during the generation of remote (!) data,
- * which can be observed with the following search. Also note that Xs
- * objectSid seems to be fine in the previous search for objectSid... */
- /*
- res = ldb.search("(primaryGroupID=*)", NULL, ldb. SCOPE_DEFAULT, attrs);
- println(res.msgs.length + " results found");
- for (i=0;i<res.msgs.length;i++) {
- for (obj in res.msgs[i]) {
- println(obj + ": " + res.msgs[i][obj]);
- }
- println("---");
- }
- */
-
- /* Search by remote name of renamed attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(sambaBadPasswordCount=*)", "", ldb. SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
-
- /* Search by objectClass */
- attrs = new Array("dnsHostName", "lastLogon", "objectClass");
- res = ldb.search("(objectClass=user)", NULL, ldb. SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 2);
- assert(res.msgs[0].dn == s4.dn("cn=X"));
- assert(res.msgs[0].dnsHostName == "x");
- assert(res.msgs[0].lastLogon == "x");
- assert(res.msgs[0].objectClass != undefined);
- assert(res.msgs[0].objectClass[0] == "user");
- assert(res.msgs[1].dn == s4.dn("cn=A"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "x");
- assert(res.msgs[1].objectClass != undefined);
- assert(res.msgs[1].objectClass[0] == "user");
-
- /* Prove that the objectClass is actually used for the search */
- res = ldb.search("(|(objectClass=user)(badPwdCount=x))", NULL, ldb. SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 3);
- assert(res.msgs[0].dn == s4.dn("cn=B"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[0].objectClass != undefined);
- for (i=0;i<res.msgs[0].objectClass.length;i++) {
- assert(res.msgs[0].objectClass[i] != "user");
- }
- assert(res.msgs[1].dn == s4.dn("cn=X"));
- assert(res.msgs[1].dnsHostName == "x");
- assert(res.msgs[1].lastLogon == "x");
- assert(res.msgs[1].objectClass != undefined);
- assert(res.msgs[1].objectClass[0] == "user");
- assert(res.msgs[2].dn == s4.dn("cn=A"));
- assert(res.msgs[2].dnsHostName == undefined);
- assert(res.msgs[2].lastLogon == "x");
- assert(res.msgs[2].objectClass != undefined);
- assert(res.msgs[2].objectClass[0] == "user");
-
- println("Testing search by parse tree");
-
- /* Search by conjunction of local attributes */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(&(codePage=x)(revision=x))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 2);
- assert(res.msgs[0].dn == s4.dn("cn=Y"));
- assert(res.msgs[0].dnsHostName == "y");
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=X"));
- assert(res.msgs[1].dnsHostName == "x");
- assert(res.msgs[1].lastLogon == "x");
-
- /* Search by conjunction of remote attributes */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(&(lastLogon=x)(description=x))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 2);
- assert(res.msgs[0].dn == s4.dn("cn=X"));
- assert(res.msgs[0].dnsHostName == "x");
- assert(res.msgs[0].lastLogon == "x");
- assert(res.msgs[1].dn == s4.dn("cn=A"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "x");
-
- /* Search by conjunction of local and remote attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(&(codePage=x)(description=x))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 2);
- assert(res.msgs[0].dn == s4.dn("cn=Y"));
- assert(res.msgs[0].dnsHostName == "y");
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=X"));
- assert(res.msgs[1].dnsHostName == "x");
- assert(res.msgs[1].lastLogon == "x");
-
- /* Search by conjunction of local and remote attribute w/o match */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(&(codePage=x)(nextRid=x))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
- res = ldb.search("(&(revision=x)(lastLogon=z))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
-
- /* Search by disjunction of local attributes */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(|(revision=x)(dnsHostName=x))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 2);
- assert(res.msgs[0].dn == s4.dn("cn=Y"));
- assert(res.msgs[0].dnsHostName == "y");
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=X"));
- assert(res.msgs[1].dnsHostName == "x");
- assert(res.msgs[1].lastLogon == "x");
-
- /* Search by disjunction of remote attributes */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(|(badPwdCount=x)(lastLogon=x))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 3);
- assert(res.msgs[0].dn == s4.dn("cn=B"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=X"));
- assert(res.msgs[1].dnsHostName == "x");
- assert(res.msgs[1].lastLogon == "x");
- assert(res.msgs[2].dn == s4.dn("cn=A"));
- assert(res.msgs[2].dnsHostName == undefined);
- assert(res.msgs[2].lastLogon == "x");
-
- /* Search by disjunction of local and remote attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(|(revision=x)(lastLogon=y))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 3);
- assert(res.msgs[0].dn == s4.dn("cn=Y"));
- assert(res.msgs[0].dnsHostName == "y");
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=B"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "y");
- assert(res.msgs[2].dn == s4.dn("cn=X"));
- assert(res.msgs[2].dnsHostName == "x");
- assert(res.msgs[2].lastLogon == "x");
-
- /* Search by disjunction of local and remote attribute w/o match */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(|(codePage=y)(nextRid=z))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
-
- /* Search by negated local attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(!(revision=x))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 5);
- assert(res.msgs[0].dn == s4.dn("cn=B"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=A"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "x");
- assert(res.msgs[2].dn == s4.dn("cn=Z"));
- assert(res.msgs[2].dnsHostName == "z");
- assert(res.msgs[2].lastLogon == "z");
- assert(res.msgs[3].dn == s4.dn("cn=C"));
- assert(res.msgs[3].dnsHostName == undefined);
- assert(res.msgs[3].lastLogon == "z");
-
- /* Search by negated remote attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(!(description=x))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 3);
- assert(res.msgs[0].dn == s4.dn("cn=Z"));
- assert(res.msgs[0].dnsHostName == "z");
- assert(res.msgs[0].lastLogon == "z");
- assert(res.msgs[1].dn == s4.dn("cn=C"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "z");
-
- /* Search by negated conjunction of local attributes */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(!(&(codePage=x)(revision=x)))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 5);
- assert(res.msgs[0].dn == s4.dn("cn=B"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=A"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "x");
- assert(res.msgs[2].dn == s4.dn("cn=Z"));
- assert(res.msgs[2].dnsHostName == "z");
- assert(res.msgs[2].lastLogon == "z");
- assert(res.msgs[3].dn == s4.dn("cn=C"));
- assert(res.msgs[3].dnsHostName == undefined);
- assert(res.msgs[3].lastLogon == "z");
-
- /* Search by negated conjunction of remote attributes */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(!(&(lastLogon=x)(description=x)))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 5);
- assert(res.msgs[0].dn == s4.dn("cn=Y"));
- assert(res.msgs[0].dnsHostName == "y");
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=B"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "y");
- assert(res.msgs[2].dn == s4.dn("cn=Z"));
- assert(res.msgs[2].dnsHostName == "z");
- assert(res.msgs[2].lastLogon == "z");
- assert(res.msgs[3].dn == s4.dn("cn=C"));
- assert(res.msgs[3].dnsHostName == undefined);
- assert(res.msgs[3].lastLogon == "z");
-
- /* Search by negated conjunction of local and remote attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(!(&(codePage=x)(description=x)))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 5);
- assert(res.msgs[0].dn == s4.dn("cn=B"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=A"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "x");
- assert(res.msgs[2].dn == s4.dn("cn=Z"));
- assert(res.msgs[2].dnsHostName == "z");
- assert(res.msgs[2].lastLogon == "z");
- assert(res.msgs[3].dn == s4.dn("cn=C"));
- assert(res.msgs[3].dnsHostName == undefined);
- assert(res.msgs[3].lastLogon == "z");
-
- /* Search by negated disjunction of local attributes */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(!(|(revision=x)(dnsHostName=x)))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs[0].dn == s4.dn("cn=B"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=A"));
- assert(res.msgs[1].dnsHostName == undefined);
- assert(res.msgs[1].lastLogon == "x");
- assert(res.msgs[2].dn == s4.dn("cn=Z"));
- assert(res.msgs[2].dnsHostName == "z");
- assert(res.msgs[2].lastLogon == "z");
- assert(res.msgs[3].dn == s4.dn("cn=C"));
- assert(res.msgs[3].dnsHostName == undefined);
- assert(res.msgs[3].lastLogon == "z");
-
- /* Search by negated disjunction of remote attributes */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(!(|(badPwdCount=x)(lastLogon=x)))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 4);
- assert(res.msgs[0].dn == s4.dn("cn=Y"));
- assert(res.msgs[0].dnsHostName == "y");
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=Z"));
- assert(res.msgs[1].dnsHostName == "z");
- assert(res.msgs[1].lastLogon == "z");
- assert(res.msgs[2].dn == s4.dn("cn=C"));
- assert(res.msgs[2].dnsHostName == undefined);
- assert(res.msgs[2].lastLogon == "z");
-
- /* Search by negated disjunction of local and remote attribute */
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(!(|(revision=x)(lastLogon=y)))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 4);
- assert(res.msgs[0].dn == s4.dn("cn=A"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "x");
- assert(res.msgs[1].dn == s4.dn("cn=Z"));
- assert(res.msgs[1].dnsHostName == "z");
- assert(res.msgs[1].lastLogon == "z");
- assert(res.msgs[2].dn == s4.dn("cn=C"));
- assert(res.msgs[2].dnsHostName == undefined);
- assert(res.msgs[2].lastLogon == "z");
-
- println("Search by complex parse tree");
- attrs = new Array("dnsHostName", "lastLogon");
- res = ldb.search("(|(&(revision=x)(dnsHostName=x))(!(&(description=x)(nextRid=y)))(badPwdCount=y))", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 6);
- assert(res.msgs[0].dn == s4.dn("cn=B"));
- assert(res.msgs[0].dnsHostName == undefined);
- assert(res.msgs[0].lastLogon == "y");
- assert(res.msgs[1].dn == s4.dn("cn=X"));
- assert(res.msgs[1].dnsHostName == "x");
- assert(res.msgs[1].lastLogon == "x");
- assert(res.msgs[2].dn == s4.dn("cn=A"));
- assert(res.msgs[2].dnsHostName == undefined);
- assert(res.msgs[2].lastLogon == "x");
- assert(res.msgs[3].dn == s4.dn("cn=Z"));
- assert(res.msgs[3].dnsHostName == "z");
- assert(res.msgs[3].lastLogon == "z");
- assert(res.msgs[4].dn == s4.dn("cn=C"));
- assert(res.msgs[4].dnsHostName == undefined);
- assert(res.msgs[4].lastLogon == "z");
-
- /* Clean up */
- var dns = new Array();
- dns[0] = s4.dn("cn=A");
- dns[1] = s4.dn("cn=B");
- dns[2] = s4.dn("cn=C");
- dns[3] = s4.dn("cn=X");
- dns[4] = s4.dn("cn=Y");
- dns[5] = s4.dn("cn=Z");
- for (i=0;i<dns.length;i++) {
- var ok = ldb.del(dns[i]);
- assert(ok.error == 0);
- }
-}
-
-function test_map_modify(ldb, s3, s4)
-{
- println("Running modification tests on mapped data");
-
- var ldif;
- var attrs;
- var dn, dn2;
- var res;
- var ok;
-
- println("Testing modification of local records");
-
- /* Add local record */
- dn = "cn=test,dc=idealx,dc=org";
- ldif = "
-dn: " + dn + "
-cn: test
-foo: bar
-revision: 1
-description: test
-";
- ok = ldb.add(ldif);
- assert(ok.error == 0);
- /* Check it's there */
- attrs = new Array("foo", "revision", "description");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].foo == "bar");
- assert(res.msgs[0].revision == "1");
- assert(res.msgs[0].description == "test");
- /* Check it's not in the local db */
- res = s4.db.search("(cn=test)", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
- /* Check it's not in the remote db */
- res = s3.db.search("(cn=test)", NULL, ldb.SCOPE_DEFAULT, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
-
- /* Modify local record */
- ldif = "
-dn: " + dn + "
-replace: foo
-foo: baz
-replace: description
-description: foo
-";
- ok = ldb.modify(ldif);
- assert(ok.error == 0);
- /* Check in local db */
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].foo == "baz");
- assert(res.msgs[0].revision == "1");
- assert(res.msgs[0].description == "foo");
-
- /* Rename local record */
- dn2 = "cn=toast,dc=idealx,dc=org";
- ok = ldb.rename(dn, dn2);
- assert(ok.error == 0);
- /* Check in local db */
- res = ldb.search("", dn2, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn2);
- assert(res.msgs[0].foo == "baz");
- assert(res.msgs[0].revision == "1");
- assert(res.msgs[0].description == "foo");
-
- /* Delete local record */
- ok = ldb.del(dn2);
- assert(ok.error == 0);
- /* Check it's gone */
- res = ldb.search("", dn2, ldb.SCOPE_BASE);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
-
- println("Testing modification of remote records");
-
- /* Add remote record */
- dn = s4.dn("cn=test");
- dn2 = s3.dn("cn=test");
- ldif = "
-dn: " + dn2 + "
-cn: test
-description: foo
-sambaBadPasswordCount: 3
-sambaNextRid: 1001
-";
- ok = s3.db.add(ldif);
- assert(ok.error == 0);
- /* Check it's there */
- attrs = new Array("description", "sambaBadPasswordCount", "sambaNextRid");
- res = s3.db.search("", dn2, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn2);
- assert(res.msgs[0].description == "foo");
- assert(res.msgs[0].sambaBadPasswordCount == "3");
- assert(res.msgs[0].sambaNextRid == "1001");
- /* Check in mapped db */
- attrs = new Array("description", "badPwdCount", "nextRid");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == "foo");
- assert(res.msgs[0].badPwdCount == "3");
- assert(res.msgs[0].nextRid == "1001");
- /* Check in local db */
- res = s4.db.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
-
- /* Modify remote data of remote record */
- ldif = "
-dn: " + dn + "
-replace: description
-description: test
-replace: badPwdCount
-badPwdCount: 4
-";
- ok = ldb.modify(ldif);
- /* Check in mapped db */
- attrs = new Array("description", "badPwdCount", "nextRid");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].badPwdCount == "4");
- assert(res.msgs[0].nextRid == "1001");
- /* Check in remote db */
- attrs = new Array("description", "sambaBadPasswordCount", "sambaNextRid");
- res = s3.db.search("", dn2, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn2);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].sambaBadPasswordCount == "4");
- assert(res.msgs[0].sambaNextRid == "1001");
-
- /* Rename remote record */
- dn2 = s4.dn("cn=toast");
- ok = ldb.rename(dn, dn2);
- assert(ok.error == 0);
- /* Check in mapped db */
- dn = dn2;
- attrs = new Array("description", "badPwdCount", "nextRid");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].badPwdCount == "4");
- assert(res.msgs[0].nextRid == "1001");
- /* Check in remote db */
- dn2 = s3.dn("cn=toast");
- attrs = new Array("description", "sambaBadPasswordCount", "sambaNextRid");
- res = s3.db.search("", dn2, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn2);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].sambaBadPasswordCount == "4");
- assert(res.msgs[0].sambaNextRid == "1001");
-
- /* Delete remote record */
- ok = ldb.del(dn);
- assert(ok.error == 0);
- /* Check in mapped db */
- res = ldb.search("", dn, ldb.SCOPE_BASE);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
- /* Check in remote db */
- res = s3.db.search("", dn2, ldb.SCOPE_BASE);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
-
- /* Add remote record (same as before) */
- dn = s4.dn("cn=test");
- dn2 = s3.dn("cn=test");
- ldif = "
-dn: " + dn2 + "
-cn: test
-description: foo
-sambaBadPasswordCount: 3
-sambaNextRid: 1001
-";
- ok = s3.db.add(ldif);
- assert(ok.error == 0);
-
- /* Modify local data of remote record */
- ldif = "
-dn: " + dn + "
-add: revision
-revision: 1
-replace: description
-description: test
-";
- ok = ldb.modify(ldif);
- /* Check in mapped db */
- attrs = new Array("revision", "description");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].revision == "1");
- /* Check in remote db */
- res = s3.db.search("", dn2, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn2);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].revision == undefined);
- /* Check in local db */
- res = s4.db.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == undefined);
- assert(res.msgs[0].revision == "1");
-
- /* Delete (newly) split record */
- ok = ldb.del(dn);
- assert(ok.error == 0);
-
- println("Testing modification of split records");
-
- /* Add split record */
- dn = s4.dn("cn=test");
- dn2 = s3.dn("cn=test");
- ldif = "
-dn: " + dn + "
-cn: test
-description: foo
-badPwdCount: 3
-nextRid: 1001
-revision: 1
-";
- ok = ldb.add(ldif);
- assert(ok.error == 0);
- /* Check it's there */
- attrs = new Array("description", "badPwdCount", "nextRid", "revision");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == "foo");
- assert(res.msgs[0].badPwdCount == "3");
- assert(res.msgs[0].nextRid == "1001");
- assert(res.msgs[0].revision == "1");
- /* Check in local db */
- res = s4.db.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == undefined);
- assert(res.msgs[0].badPwdCount == undefined);
- assert(res.msgs[0].nextRid == undefined);
- assert(res.msgs[0].revision == "1");
- /* Check in remote db */
- attrs = new Array("description", "sambaBadPasswordCount", "sambaNextRid", "revision");
- res = s3.db.search("", dn2, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn2);
- assert(res.msgs[0].description == "foo");
- assert(res.msgs[0].sambaBadPasswordCount == "3");
- assert(res.msgs[0].sambaNextRid == "1001");
- assert(res.msgs[0].revision == undefined);
-
- /* Modify of split record */
- ldif = "
-dn: " + dn + "
-replace: description
-description: test
-replace: badPwdCount
-badPwdCount: 4
-replace: revision
-revision: 2
-";
- ok = ldb.modify(ldif);
- assert(ok.error == 0);
- /* Check in mapped db */
- attrs = new Array("description", "badPwdCount", "nextRid", "revision");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].badPwdCount == "4");
- assert(res.msgs[0].nextRid == "1001");
- assert(res.msgs[0].revision == "2");
- /* Check in local db */
- res = s4.db.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == undefined);
- assert(res.msgs[0].badPwdCount == undefined);
- assert(res.msgs[0].nextRid == undefined);
- assert(res.msgs[0].revision == "2");
- /* Check in remote db */
- attrs = new Array("description", "sambaBadPasswordCount", "sambaNextRid", "revision");
- res = s3.db.search("", dn2, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn2);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].sambaBadPasswordCount == "4");
- assert(res.msgs[0].sambaNextRid == "1001");
- assert(res.msgs[0].revision == undefined);
-
- /* Rename split record */
- dn2 = s4.dn("cn=toast");
- ok = ldb.rename(dn, dn2);
- assert(ok.error == 0);
- /* Check in mapped db */
- dn = dn2;
- attrs = new Array("description", "badPwdCount", "nextRid", "revision");
- res = ldb.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].badPwdCount == "4");
- assert(res.msgs[0].nextRid == "1001");
- assert(res.msgs[0].revision == "2");
- /* Check in local db */
- res = s4.db.search("", dn, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn);
- assert(res.msgs[0].description == undefined);
- assert(res.msgs[0].badPwdCount == undefined);
- assert(res.msgs[0].nextRid == undefined);
- assert(res.msgs[0].revision == "2");
- /* Check in remote db */
- dn2 = s3.dn("cn=toast");
- attrs = new Array("description", "sambaBadPasswordCount", "sambaNextRid", "revision");
- res = s3.db.search("", dn2, ldb.SCOPE_BASE, attrs);
- assert(res.error == 0);
- assert(res.msgs.length == 1);
- assert(res.msgs[0].dn == dn2);
- assert(res.msgs[0].description == "test");
- assert(res.msgs[0].sambaBadPasswordCount == "4");
- assert(res.msgs[0].sambaNextRid == "1001");
- assert(res.msgs[0].revision == undefined);
-
- /* Delete split record */
- ok = ldb.del(dn);
- assert(ok.error == 0);
- /* Check in mapped db */
- res = ldb.search("", dn, ldb.SCOPE_BASE);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
- /* Check in local db */
- res = s4.db.search("", dn, ldb.SCOPE_BASE);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
- /* Check in remote db */
- res = s3.db.search("", dn2, ldb.SCOPE_BASE);
- assert(res.error == 0);
- assert(res.msgs.length == 0);
-}
-
-function make_dn(rdn)
-{
- return rdn + ",sambaDomainName=TESTS," + this.BASEDN;
-}
-
-function make_s4dn(rdn)
-{
- return rdn + "," + this.BASEDN;
-}
-
-var ldb = ldb_init();
-
-sys = sys_init();
-var ldbfile = prefix + "/" + "test.ldb";
-var ldburl = "tdb://" + ldbfile;
-
-var samba4 = new Object("samba4 partition info");
-samba4.file = prefix + "/" + "samba4.ldb";
-samba4.url = "tdb://" + samba4.file;
-samba4.BASEDN = "dc=vernstok,dc=nl";
-samba4.db = ldb_init();
-samba4.dn = make_s4dn;
-
-var samba3 = new Object("samba3 partition info");
-samba3.file = prefix + "/" + "samba3.ldb";
-samba3.url = "tdb://" + samba3.file;
-samba3.BASEDN = "cn=Samba3Sam";
-samba3.db = ldb_init();
-samba3.dn = make_dn;
-
-var templates = new Object("templates partition info");
-templates.file = prefix + "/" + "templates.ldb";
-templates.url = "tdb://" + templates.file;
-templates.BASEDN = "cn=templates";
-templates.db = ldb_init();
-
-sys.unlink(ldbfile);
-sys.unlink(samba3.file);
-sys.unlink(templates.file);
-sys.unlink(samba4.file);
-
-var ok = ldb.connect(ldburl);
-assert(ok);
-var ok = samba3.db.connect(samba3.url);
-assert(ok);
-var ok = templates.db.connect(templates.url);
-assert(ok);
-var ok = samba4.db.connect(samba4.url);
-assert(ok);
-
-setup_data(samba3, sys.file_load(datadir + "/" + "samba3.ldif"));
-setup_data(templates, sys.file_load(datadir + "/" + "provision_samba3sam_templates.ldif"));
-setup_modules(ldb, samba3, samba4, sys.file_load(datadir + "/" + "provision_samba3sam.ldif"));
-
-ldb = ldb_init();
-var ok = ldb.connect(ldburl);
-assert(ok);
-
-test_s3sam_search(ldb);
-test_s3sam_modify(ldb, samba3);
-
-sys.unlink(ldbfile);
-sys.unlink(samba3.file);
-sys.unlink(templates.file);
-sys.unlink(samba4.file);
-
-ldb = ldb_init();
-var ok = ldb.connect(ldburl);
-assert(ok);
-samba3.db = ldb_init();
-var ok = samba3.db.connect(samba3.url);
-assert(ok);
-templates.db = ldb_init();
-var ok = templates.db.connect(templates.url);
-assert(ok);
-samba4.db = ldb_init();
-var ok = samba4.db.connect(samba4.url);
-assert(ok);
-
-setup_data(templates, sys.file_load(datadir + "/" + "provision_samba3sam_templates.ldif"));
-setup_modules(ldb, samba3, samba4, sys.file_load(datadir + "provision_samba3sam.ldif"));
-
-ldb = ldb_init();
-var ok = ldb.connect(ldburl);
-assert(ok);
-
-test_map_search(ldb, samba3, samba4);
-test_map_modify(ldb, samba3, samba4);
-
-sys.unlink(ldbfile);
-sys.unlink(samba3.file);
-sys.unlink(samba4.file);
-
-return 0;