summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/samba3/PLAN3
-rw-r--r--source4/lib/samba3/config.mk10
-rw-r--r--source4/lib/samba3/sam.h26
-rw-r--r--source4/lib/samba3/samba3dump.c75
-rw-r--r--source4/lib/samba3/tdbsam.c67
5 files changed, 167 insertions, 14 deletions
diff --git a/source4/lib/samba3/PLAN b/source4/lib/samba3/PLAN
index 6e83e8fc33..6076141ac0 100644
--- a/source4/lib/samba3/PLAN
+++ b/source4/lib/samba3/PLAN
@@ -7,8 +7,11 @@ Three possible viable approaches:
(one-way upgrades can be done by using ldbsearch -a on these dynamically
generated ldb's)
+ Since TDB's are local, there isn't much point in writing back backwards
+ compatible data.
2) samr "mapping" backend (alternative for samr.ldb) (two-way)
+ This would allow users to keep mixed domains containing Samba3 and Samba4.
3) The vampire way of doing things (one-way)
- samba3 pidl backend
diff --git a/source4/lib/samba3/config.mk b/source4/lib/samba3/config.mk
index 43608577c5..5045901b3b 100644
--- a/source4/lib/samba3/config.mk
+++ b/source4/lib/samba3/config.mk
@@ -7,4 +7,12 @@ INIT_OBJ_FILES = \
# End SUBSYSTEM LIBSAMBA3
################################################
-
+################################################
+# Start BINARY samba3dump
+[BINARY::samba3dump]
+INSTALLDIR = BINDIR
+INIT_OBJ_FILES = \
+ lib/samba3/samba3dump.o
+REQUIRED_SUBSYSTEMS = LIBBASIC LIBCMDLINE LIBSAMBA3
+# End BINARY samba3dump
+################################################
diff --git a/source4/lib/samba3/sam.h b/source4/lib/samba3/sam.h
index 11a9f42ec7..bc13b28e2a 100644
--- a/source4/lib/samba3/sam.h
+++ b/source4/lib/samba3/sam.h
@@ -21,6 +21,8 @@
#ifndef _SAMBA3_SAM_H /* _SAMBA3_SAM_H */
#define _SAMBA3_SAM_H
+#include "librpc/gen_ndr/security.h"
+
struct samba3_samaccount {
uint32_t logon_time,
logoff_time,
@@ -49,4 +51,28 @@ struct samba3_samaccount {
uint8_t *hours;
};
+/* SID Types */
+enum SID_NAME_USE
+{
+ SID_NAME_USE_NONE = 0,
+ SID_NAME_USER = 1, /* user */
+ SID_NAME_DOM_GRP, /* domain group */
+ SID_NAME_DOMAIN, /* domain sid */
+ SID_NAME_ALIAS, /* local group */
+ SID_NAME_WKN_GRP, /* well-known group */
+ SID_NAME_DELETED, /* deleted account: needed for c2 rating */
+ SID_NAME_INVALID, /* invalid account */
+ SID_NAME_UNKNOWN, /* unknown sid type */
+ SID_NAME_COMPUTER /* sid for a computer */
+};
+
+struct samba3_groupmapping {
+ struct pdb_methods *methods;
+ gid_t gid;
+ struct dom_sid *sid;
+ enum SID_NAME_USE sid_name_use;
+ const char *nt_name;
+ const char *comment;
+};
+
#endif /* _SAMBA3_SAM_H */
diff --git a/source4/lib/samba3/samba3dump.c b/source4/lib/samba3/samba3dump.c
new file mode 100644
index 0000000000..4071ba1bf9
--- /dev/null
+++ b/source4/lib/samba3/samba3dump.c
@@ -0,0 +1,75 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba3 database dump utility
+
+ 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 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "lib/samba3/sam.h"
+#include "lib/cmdline/popt_common.h"
+
+static const char *libdir = "/var/lib/samba";
+
+static NTSTATUS print_sam(void)
+{
+ struct samba3_samaccount *accounts;
+ uint32_t count, i;
+ char *tdbsam_file;
+ NTSTATUS status;
+
+ asprintf(&tdbsam_file, "%s/passdb.tdb", libdir);
+
+ printf("Opening TDB sam %s\n", tdbsam_file);
+
+ status = samba3_read_tdbsam(NULL, tdbsam_file, &accounts, &count);
+ if (NT_STATUS_IS_ERR(status)) {
+ fprintf(stderr, "Error reading tdbsam database %s\n", tdbsam_file);
+ return status;
+ }
+
+ for (i = 0; i < count; i++) {
+ printf("%d: %s\n", accounts[i].user_rid, accounts[i].username);
+ }
+
+ return NT_STATUS_OK;
+}
+
+int main(int argc, char **argv)
+{
+ int opt;
+ poptContext pc;
+ struct poptOption long_options[] = {
+ POPT_AUTOHELP
+ { "libdir", 0, POPT_ARG_STRING, &libdir, 'l', "Set libdir [/var/lib/samba]", "LIBDIR" },
+ POPT_COMMON_SAMBA
+ POPT_TABLEEND
+ };
+
+ pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
+
+ poptSetOtherOptionHelp(pc, "<smb.conf>");
+
+ while((opt = poptGetNextOpt(pc)) != -1) {
+ }
+
+ print_sam();
+
+ poptFreeContext(pc);
+
+ return 0;
+}
diff --git a/source4/lib/samba3/tdbsam.c b/source4/lib/samba3/tdbsam.c
index 0b2f975441..a16c07d2d1 100644
--- a/source4/lib/samba3/tdbsam.c
+++ b/source4/lib/samba3/tdbsam.c
@@ -26,6 +26,7 @@
#include "includes.h"
#include "system/iconv.h"
+#include "system/filesys.h"
#include "lib/tdb/include/tdbutil.h"
#include "lib/samba3/sam.h"
@@ -37,18 +38,18 @@
/**
* Open the TDB passwd database, check version and convert it if needed.
* @param name filename of the tdbsam file.
- * @param open_flags file access mode.
+ * @param version version of the tdbsam database
* @return a TDB_CONTEXT handle on the tdbsam file.
**/
-static TDB_CONTEXT * tdbsam_open (const char *name, int open_flags, int32_t *version)
+static TDB_CONTEXT *tdbsam_open (const char *name, int32_t *version)
{
TDB_CONTEXT *pdb_tdb;
/* Try to open tdb passwd */
if (!(pdb_tdb = tdb_open(name, 0, TDB_DEFAULT,
- open_flags, 0600))) {
- DEBUG(0, ("Unable to open/create TDB passwd\n"));
+ O_RDONLY, 0600))) {
+ DEBUG(0, ("Unable to open TDB passwd\n"));
return NULL;
}
@@ -69,7 +70,7 @@ static TDB_CONTEXT * tdbsam_open (const char *name, int open_flags, int32_t *ver
return pdb_tdb;
}
-static BOOL init_sam_from_buffer_v0(TDB_CONTEXT *tdb, struct samba3_samaccount *sampass, uint8_t *buf, uint32_t buflen)
+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,
@@ -80,13 +81,13 @@ static BOOL init_sam_from_buffer_v0(TDB_CONTEXT *tdb, struct samba3_samaccount *
uint32_t len = 0;
uint32_t lm_pw_len, nt_pw_len, hourslen;
- if(sampass == NULL || buf == NULL) {
+ 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, buflen, TDB_FORMAT_STRING_V0,
+ 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 */
@@ -133,7 +134,7 @@ static BOOL init_sam_from_buffer_v0(TDB_CONTEXT *tdb, struct samba3_samaccount *
return True;
}
-static BOOL init_sam_from_buffer_v1(TDB_CONTEXT *tdb, struct samba3_samaccount *sampass, uint8_t *buf, uint32_t buflen)
+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,
@@ -144,13 +145,13 @@ static BOOL init_sam_from_buffer_v1(TDB_CONTEXT *tdb, struct samba3_samaccount *
uint32_t len = 0;
uint32_t lm_pw_len, nt_pw_len, hourslen;
- if(sampass == NULL || buf == NULL) {
+ 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, buflen, TDB_FORMAT_STRING_V1,
+ 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 */
@@ -199,7 +200,7 @@ static BOOL init_sam_from_buffer_v1(TDB_CONTEXT *tdb, struct samba3_samaccount *
return True;
}
-static BOOL init_sam_from_buffer_v2(TDB_CONTEXT *tdb, struct samba3_samaccount *sampass, uint8_t *buf, uint32_t buflen)
+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,
@@ -209,13 +210,13 @@ static BOOL init_sam_from_buffer_v2(TDB_CONTEXT *tdb, struct samba3_samaccount *
uint32_t len = 0;
uint32_t lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen;
- if(sampass == NULL || buf == NULL) {
+ 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, buflen, TDB_FORMAT_STRING_V2,
+ 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 */
@@ -264,3 +265,43 @@ static BOOL init_sam_from_buffer_v2(TDB_CONTEXT *tdb, struct samba3_samaccount *
return True;
}
+
+NTSTATUS samba3_read_tdbsam(TALLOC_CTX *ctx, const char *filename, struct samba3_samaccount **accounts, uint32_t *count)
+{
+ int32_t version;
+ TDB_CONTEXT *tdb = tdbsam_open(filename, &version);
+ TDB_DATA key, val;
+
+ if (tdb == NULL)
+ return NT_STATUS_UNSUCCESSFUL;
+
+ if (version < 0 || version > 2) {
+ return NT_STATUS_NOT_SUPPORTED;
+ }
+
+ *accounts = NULL;
+ *count = 0;
+
+ for (key = tdb_firstkey(tdb); key.dptr; key = tdb_nextkey(tdb, key))
+ {
+ if (strncmp(key.dptr, "RID/", 4) == 0) continue;
+
+ val = tdb_fetch(tdb, key);
+
+ *accounts = talloc_realloc(ctx, *accounts, struct samba3_samaccount, (*count)+1);
+
+ switch (version)
+ {
+ case 0: init_sam_from_buffer_v0(tdb, &(*accounts)[*count], val); break;
+ case 1: init_sam_from_buffer_v1(tdb, &(*accounts)[*count], val); break;
+ case 2: init_sam_from_buffer_v2(tdb, &(*accounts)[*count], val); break;
+
+ }
+
+ (*count)++;
+ }
+
+ tdb_close(tdb);
+
+ return NT_STATUS_OK;
+}