2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Jeremy Allison 2001.
6 * Copyright (C) Nigel Williams 2001.
7 * Copyright (C) Jelmer Vernooij 2005.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "librpc/gen_ndr/ndr_security.h"
26 #include "lib/tdb/include/tdbutil.h"
27 #include "lib/samba3/samba3.h"
28 #include "system/filesys.h"
30 #define SHARE_DATABASE_VERSION_V1 1
31 #define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */
33 NTSTATUS samba3_read_share_info(const char *fn, TALLOC_CTX *ctx, struct samba3 *db)
40 tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600);
42 DEBUG(0,("Failed to open share info database %s (%s)\n",
43 fn, strerror(errno) ));
44 return NT_STATUS_UNSUCCESSFUL;
47 /* Cope with byte-reversed older versions of the db. */
48 vers_id = tdb_fetch_int32(tdb, "INFO/version");
49 if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
50 /* Written on a bigendian machine with old fetch_int code. Save as le. */
51 vers_id = SHARE_DATABASE_VERSION_V2;
54 if (vers_id != SHARE_DATABASE_VERSION_V2) {
55 return NT_STATUS_UNSUCCESSFUL;
58 for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf))
60 struct ndr_pull *pull;
61 struct samba3_share_info *share;
64 if (strncmp(kbuf.dptr, "SECDESC/", strlen("SECDESC/")) != 0)
67 name = talloc_strndup(ctx, kbuf.dptr+strlen("SECDESC/"), kbuf.dsize-strlen("SECDESC/"));
69 db->shares = talloc_realloc(db, db->shares, struct samba3_share_info, db->share_count+1);
70 share = &db->shares[db->share_count];
73 share->name = talloc_strdup(db, name);
75 vbuf = tdb_fetch(tdb, kbuf);
76 blob.data = (uint8_t *)vbuf.dptr;
77 blob.length = vbuf.dsize;
79 pull = ndr_pull_init_blob(&blob, ctx);
81 ndr_pull_security_descriptor(pull, NDR_SCALARS|NDR_BUFFERS, &share->secdesc);