svn commit: samba r9552 - in branches/SAMBA_4_0/source/lib/samba3: .

jelmer at samba.org jelmer at samba.org
Tue Aug 23 23:55:41 GMT 2005


Author: jelmer
Date: 2005-08-23 23:55:41 +0000 (Tue, 23 Aug 2005)
New Revision: 9552

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9552

Log:
Add idmap support.

Added:
   branches/SAMBA_4_0/source/lib/samba3/idmap.c


Changeset:
Added: branches/SAMBA_4_0/source/lib/samba3/idmap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/samba3/idmap.c	2005-08-23 23:48:37 UTC (rev 9551)
+++ branches/SAMBA_4_0/source/lib/samba3/idmap.c	2005-08-23 23:55:41 UTC (rev 9552)
@@ -0,0 +1,93 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   idmap TDB backend
+
+   Copyright (C) Tim Potter 2000
+   Copyright (C) Jim McDonough <jmcd at 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 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/tdb/include/tdbutil.h"
+#include "lib/samba3/sam.h"
+#include "system/filesys.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_idmap *idmap )
+{
+	int32_t version;
+	TDB_CONTEXT *tdb;
+	TDB_DATA key, val;
+
+	/* Open idmap repository */
+	if (!(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0644))) {
+		DEBUG(0, ("idmap_init: Unable to open idmap database\n"));
+		return NT_STATUS_UNSUCCESSFUL;
+	}
+
+	/* 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;
+	}
+
+	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);
+
+	for (key = tdb_firstkey(tdb); key.dptr; key = tdb_nextkey(tdb, key)) 
+	{
+		struct samba3_idmap_mapping map;
+		
+		if (strncmp(key.dptr, "GID ", 4) == 0) {
+			map.type = IDMAP_GROUP;
+			map.unix_id = atoi(key.dptr+4);
+			val = tdb_fetch(tdb, key);
+			map.sid = dom_sid_parse_talloc(ctx, val.dptr);
+		} else if (strncmp(key.dptr, "UID ", 4) == 0) {
+			map.type = IDMAP_USER;
+			map.unix_id = atoi(key.dptr+4);
+			val = tdb_fetch(tdb, key);
+			map.sid = dom_sid_parse_talloc(ctx, val.dptr);
+		} 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;
+}


Property changes on: branches/SAMBA_4_0/source/lib/samba3/idmap.c
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the samba-cvs mailing list