r9712: Bunch of small fixes
[sfrench/samba-autobuild/.git] / source4 / lib / samba3 / group.c
index fc8f8c40b87e1aecab568deeea06e47c7599ed68..220f206e993a6b12eb5391214028b9a5846203e0 100644 (file)
@@ -46,8 +46,9 @@ NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_g
        int32_t vers_id;
        TDB_DATA kbuf, dbuf, newkey;
        int ret;
-       
-       TDB_CONTEXT *tdb = tdb_open(file, 0, TDB_DEFAULT, O_RDONLY, 0600);
+       TDB_CONTEXT *tdb; 
+
+       tdb = tdb_open(file, 0, TDB_DEFAULT, O_RDONLY, 0600);
        if (!tdb) {
                DEBUG(0,("Failed to open group mapping database\n"));
                return NT_STATUS_UNSUCCESSFUL;
@@ -61,6 +62,7 @@ NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_g
        }
 
        if (vers_id != DATABASE_VERSION_V2) {
+               DEBUG(0, ("Group database version mismatch: %d\n", vers_id));
                return NT_STATUS_UNSUCCESSFUL;
        }
 
@@ -80,19 +82,22 @@ NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_g
                        if (!dbuf.dptr)
                                continue;
 
-                       map.sid = dom_sid_parse_talloc(tdb, kbuf.dptr+strlen(GROUP_PREFIX));
-
-                       ret = tdb_unpack(tdb, dbuf.dptr, dbuf.dsize, "ddff",
-                                                        &map.gid, &map.sid_name_use, &map.nt_name, &map.comment);
+                       ZERO_STRUCT(map);
 
-                       SAFE_FREE(dbuf.dptr);
+                       map.sid = dom_sid_parse_talloc(ctx, kbuf.dptr+strlen(GROUP_PREFIX));
 
+                       ret = tdb_unpack(tdb, dbuf.dptr, dbuf.dsize, "dd",
+                                                        &map.gid, &map.sid_name_use);
+                       
                        if ( ret == -1 ) {
                                DEBUG(3,("enum_group_mapping: tdb_unpack failure\n"));
                                continue;
                        }
 
-                       db->groupmappings = talloc_realloc(tdb, db->groupmappings, struct samba3_groupmapping, db->groupmap_count+1);
+                       map.nt_name = talloc_strdup(ctx, dbuf.dptr+ret);
+                       map.comment = talloc_strdup(ctx, dbuf.dptr+ret+strlen(map.nt_name));
+
+                       db->groupmappings = talloc_realloc(ctx, db->groupmappings, struct samba3_groupmapping, db->groupmap_count+1);
 
                        if (!db->groupmappings) 
                                return NT_STATUS_NO_MEMORY;
@@ -100,9 +105,7 @@ NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_g
                        db->groupmappings[db->groupmap_count] = map;
 
                        db->groupmap_count++;
-               } 
-
-               if (strncmp(kbuf.dptr, MEMBEROF_PREFIX, strlen(MEMBEROF_PREFIX)) == 0)
+               } else if (strncmp(kbuf.dptr, MEMBEROF_PREFIX, strlen(MEMBEROF_PREFIX)) == 0)
                {
                        struct samba3_alias alias;
                        pstring alias_string;