2 Unix SMB/CIFS implementation.
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
8 Copyright (C) Simo Sorce 2003
9 Copyright (C) Jelmer Vernooij 2005
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "lib/tdb/include/tdbutil.h"
28 #include "lib/samba3/samba3.h"
29 #include "system/filesys.h"
31 /* High water mark keys */
32 #define HWM_GROUP "GROUP HWM"
33 #define HWM_USER "USER HWM"
35 /* idmap version determines auto-conversion */
36 #define IDMAP_VERSION 2
38 /*****************************************************************************
39 Initialise idmap database.
40 *****************************************************************************/
42 NTSTATUS samba3_read_idmap(const char *fn, TALLOC_CTX *ctx, struct samba3_idmapdb *idmap)
47 /* Open idmap repository */
48 if (!(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0644))) {
49 DEBUG(0, ("idmap_init: Unable to open idmap database '%s'\n", fn));
50 return NT_STATUS_UNSUCCESSFUL;
53 idmap->mapping_count = 0;
54 idmap->mappings = NULL;
55 idmap->user_hwm = tdb_fetch_int32(tdb, HWM_USER);
56 idmap->group_hwm = tdb_fetch_int32(tdb, HWM_GROUP);
58 for (key = tdb_firstkey(tdb); key.dptr; key = tdb_nextkey(tdb, key))
60 struct samba3_idmap_mapping map;
62 if (strncmp(key.dptr, "GID ", 4) == 0) {
63 map.type = IDMAP_GROUP;
64 map.unix_id = atoi(key.dptr+4);
65 val = tdb_fetch(tdb, key);
66 map.sid = dom_sid_parse_talloc(ctx, val.dptr);
67 } else if (strncmp(key.dptr, "UID ", 4) == 0) {
68 map.type = IDMAP_USER;
69 map.unix_id = atoi(key.dptr+4);
70 val = tdb_fetch(tdb, key);
71 map.sid = dom_sid_parse_talloc(ctx, val.dptr);
76 idmap->mappings = talloc_realloc(ctx, idmap->mappings, struct samba3_idmap_mapping, idmap->mapping_count+1);
78 idmap->mappings[idmap->mapping_count] = map;
79 idmap->mapping_count++;