summaryrefslogtreecommitdiff
path: root/source4/lib/samba3/share_info.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-08-25 01:12:43 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:34:33 -0500
commitdcd27d550fcc6fc8ddbec2f4a310a862f3fbbffc (patch)
tree48e603b8172393f14df0af969567e58d8675130c /source4/lib/samba3/share_info.c
parent2dc45bd4841a0b7ea640d9a41e381f4601809262 (diff)
downloadsamba-dcd27d550fcc6fc8ddbec2f4a310a862f3fbbffc.tar.gz
samba-dcd27d550fcc6fc8ddbec2f4a310a862f3fbbffc.tar.bz2
samba-dcd27d550fcc6fc8ddbec2f4a310a862f3fbbffc.zip
r9602: Add support for reading share_info.tdb and smb.conf.
Add userdata argument to function pointers for pm_process() (This used to be commit 84b2fb34675fa557173621433838c5a7ec0f1283)
Diffstat (limited to 'source4/lib/samba3/share_info.c')
-rw-r--r--source4/lib/samba3/share_info.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/source4/lib/samba3/share_info.c b/source4/lib/samba3/share_info.c
new file mode 100644
index 0000000000..098d6c552e
--- /dev/null
+++ b/source4/lib/samba3/share_info.c
@@ -0,0 +1,85 @@
+/*
+ * 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 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 "librpc/gen_ndr/ndr_security.h"
+#include "lib/tdb/include/tdbutil.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(kbuf.dptr, "SECDESC/", strlen("SECDESC/")) != 0)
+ continue;
+
+ name = talloc_strndup(ctx, kbuf.dptr+strlen("SECDESC/"), kbuf.dsize-strlen("SECDESC/"));
+
+ share = samba3_find_share(db, ctx, name);
+
+ vbuf = tdb_fetch(tdb, kbuf);
+ blob.data = (uint8_t *)vbuf.dptr;
+ blob.length = vbuf.dsize;
+
+ pull = ndr_pull_init_blob(&blob, ctx);
+
+ ndr_pull_security_descriptor(pull, NDR_SCALARS|NDR_BUFFERS, &share->secdesc);
+
+ talloc_free(pull);
+ }
+
+ tdb_close(tdb);
+
+ return NT_STATUS_OK;
+}