r25174: Export header from just one place.
[samba.git] / source4 / lib / samba3 / registry.c
index 82a08c908872f1c7af72383af9952b6d9fb17ada..69197883b7a254cd340a0c7b99235482f7df9477 100644 (file)
@@ -6,7 +6,7 @@
  *
  *  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
+ *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
  *  
  *  This program is distributed in the hope that it will be useful,
@@ -15,8 +15,7 @@
  *  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.
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 /* Implementation of internal registry database functions. */
@@ -24,7 +23,8 @@
 #include "includes.h"
 #include "lib/samba3/samba3.h"
 #include "librpc/gen_ndr/winreg.h"
-#include "lib/tdb/include/tdbutil.h"
+#include "lib/tdb/include/tdb.h"
+#include "lib/util/util_tdb.h"
 #include "system/filesys.h"
 #include "pstring.h"
 
@@ -40,14 +40,14 @@ static int regdb_unpack_values(TDB_CONTEXT *tdb, TALLOC_CTX *ctx, struct samba3_
        int             len = 0;
        uint32_t        type;
        uint32_t        size;
-       uint8_t         *data_p;
+       uint8_t *data_p;
        uint32_t        num_values = 0;
        int             i;
        fstring valuename;
        
        /* loop and unpack the rest of the registry values */
        
-       len += tdb_unpack(tdb, data.dptr+len, data.dsize-len, "d", &num_values);
+       len += tdb_unpack(tdb, (char *)data.dptr+len, data.dsize-len, "d", &num_values);
        
        for ( i=0; i<num_values; i++ ) {
                struct samba3_regval val;
@@ -56,7 +56,7 @@ static int regdb_unpack_values(TDB_CONTEXT *tdb, TALLOC_CTX *ctx, struct samba3_
                type = REG_NONE;
                size = 0;
                data_p = NULL;
-               len += tdb_unpack(tdb, data.dptr+len, data.dsize-len, "fdB",
+               len += tdb_unpack(tdb, (char *)data.dptr+len, data.dsize-len, "fdB",
                                  valuename,
                                  &val.type,
                                  &size,
@@ -88,6 +88,7 @@ NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regd
        
        if ( !(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600)) )
        {
+               DEBUG(0, ("Unable to open registry database %s\n", fn));
                return NT_STATUS_UNSUCCESSFUL;
        }
 
@@ -96,8 +97,10 @@ NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regd
        db->key_count = 0;
        db->keys = NULL;
        
-       if (vers_id > REGVER_V1) 
+       if (vers_id != -1 && vers_id >= REGVER_V1) {
+               DEBUG(0, ("Registry version mismatch: %d\n", vers_id));
                return NT_STATUS_UNSUCCESSFUL;
+       }
 
        for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf))
        {
@@ -106,14 +109,14 @@ NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regd
                struct samba3_regkey key;
                char *skey;
                        
-               if (strncmp(kbuf.dptr, VALUE_PREFIX, strlen(VALUE_PREFIX)))
+               if (strncmp((char *)kbuf.dptr, VALUE_PREFIX, strlen(VALUE_PREFIX)) == 0)
                        continue;
 
                vbuf = tdb_fetch(tdb, kbuf);
 
-               key.name = talloc_strdup(ctx, kbuf.dptr); 
+               key.name = talloc_strdup(ctx, (char *)kbuf.dptr); 
 
-               len = tdb_unpack(tdb, vbuf.dptr, vbuf.dsize, "d", &key.subkey_count);
+               len = tdb_unpack(tdb, (char *)vbuf.dptr, vbuf.dsize, "d", &key.subkey_count);
 
                key.value_count = 0;
                key.values = NULL;
@@ -121,7 +124,7 @@ NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regd
        
                for (i = 0; i < key.subkey_count; i++) {
                        fstring tmp;
-                       len += tdb_unpack( tdb, vbuf.dptr+len, vbuf.dsize-len, "f", tmp );
+                       len += tdb_unpack( tdb, (char *)vbuf.dptr+len, vbuf.dsize-len, "f", tmp );
                        key.subkeys[i] = talloc_strdup(ctx, tmp);
                }
 
@@ -134,7 +137,7 @@ NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regd
                }
 
                db->keys = talloc_realloc(ctx, db->keys, struct samba3_regkey, db->key_count+1);
-               db->keys[i] = key;
+               db->keys[db->key_count] = key;
                db->key_count++;
        }