svn commit: samba r6410 - in trunk/source: include registry utils
jerry at samba.org
jerry at samba.org
Thu Apr 21 03:09:10 GMT 2005
Author: jerry
Date: 2005-04-21 03:09:10 +0000 (Thu, 21 Apr 2005)
New Revision: 6410
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=6410
Log:
read in a hbin record
Modified:
trunk/source/include/regfio.h
trunk/source/registry/regfio.c
trunk/source/utils/net_rpc_registry.c
Changeset:
Modified: trunk/source/include/regfio.h
===================================================================
--- trunk/source/include/regfio.h 2005-04-21 02:26:19 UTC (rev 6409)
+++ trunk/source/include/regfio.h 2005-04-21 03:09:10 UTC (rev 6410)
@@ -25,6 +25,8 @@
*/
#define REGF_HDR_SIZE 4
+#define HBIN_HDR_SIZE 4
+
#define REGF_BLOCKSIZE 0x1000
/*
@@ -57,15 +59,21 @@
} REGF_VALUE_LIST;
typedef struct {
- uint32 offset; /* offset from fist hbin block */
+ char header[HBIN_HDR_SIZE]; /* "hbin" */
+ uint32 first_hbin_off; /* offset from first hbin block */
+ uint32 next_hbin_off; /* offset from next hbin block */
uint32 block_size; /* block size of this block (always 4kb) */
- uint8 buffer[REGF_BLOCKSIZE]; /* data */
+ uint32 data_size; /* data size of this block -- not sure .... */
+
+ prs_struct ps; /* data */
+
BOOL dirty; /* should block be flushed to disk before releasing? */
} REGF_HBIN;
typedef struct {
/* run time information */
int fd; /* file descriptor */
+ TALLOC_CTX *mem_ctx;
off_t current_block; /* offset to the current file block */
REGF_HBIN *current_hbin; /* current hbin block */
Modified: trunk/source/registry/regfio.c
===================================================================
--- trunk/source/registry/regfio.c 2005-04-21 02:26:19 UTC (rev 6409)
+++ trunk/source/registry/regfio.c 2005-04-21 03:09:10 UTC (rev 6410)
@@ -126,6 +126,35 @@
/*******************************************************************
*******************************************************************/
+static BOOL prs_hbin_block( const char *desc, prs_struct *ps, int depth, REGF_HBIN *hbin )
+{
+ prs_debug(ps, depth, desc, "prs_regf_block");
+ depth++;
+
+ if ( !prs_uint8s( True, "header", ps, depth, hbin->header, sizeof( hbin->header )) )
+ return False;
+
+ if ( !prs_uint32( "first_hbin_off", ps, depth, &hbin->first_hbin_off ))
+ return False;
+ if ( !prs_uint32( "next_hbin_off", ps, depth, &hbin->next_hbin_off ))
+ return False;
+
+ if ( !prs_set_offset( ps, 0x001c ) )
+ return False;
+ if ( !prs_uint32( "block_size", ps, depth, &hbin->block_size ))
+ return False;
+
+ if ( !prs_set_offset( ps, 0x0020 ) )
+ return False;
+ if ( !prs_uint32( "data_size", ps, depth, &hbin->data_size ))
+ return False;
+
+ return True;
+}
+
+/*******************************************************************
+*******************************************************************/
+
static uint32 regf_block_checksum( prs_struct *ps )
{
char *buffer = prs_data_p( ps );
@@ -150,15 +179,9 @@
static BOOL read_regf_block( REGF_FILE *file )
{
prs_struct ps;
- TALLOC_CTX *ctx;
uint32 checksum;
- if ( !(ctx = talloc_init( "read_regf_block" )) ) {
- DEBUG(0,("read_regf_block: talloc_init() failed!\n"));
- return False;
- }
-
- prs_init( &ps, REGF_BLOCKSIZE, ctx, UNMARSHALL );
+ prs_init( &ps, REGF_BLOCKSIZE, file->mem_ctx, UNMARSHALL );
/* grab the first block from the file */
@@ -183,6 +206,35 @@
}
/*******************************************************************
+*******************************************************************/
+
+static REGF_HBIN* read_hbin_block( REGF_FILE *file, off_t offset )
+{
+ REGF_HBIN *hbin;
+
+ if ( !(hbin = (REGF_HBIN*)malloc(sizeof(REGF_HBIN)) ) )
+ return NULL;
+ ZERO_STRUCTP( hbin );
+
+ prs_init( &hbin->ps, REGF_BLOCKSIZE, file->mem_ctx, UNMARSHALL );
+
+ /* an offset of 0 means grab the first hbin block */
+
+ if ( offset == 0 )
+ offset = REGF_BLOCKSIZE;
+
+ if ( read_block( &hbin->ps, offset, file->fd ) == -1 )
+ return False;
+
+ if ( !prs_hbin_block( "hbin", &hbin->ps, 0, hbin ) )
+ return False;
+
+ if ( !prs_set_offset( &hbin->ps, file->data_offset+HBIN_HDR_SIZE ) )
+ return False;
+
+ return hbin;
+}
+/*******************************************************************
Open the registry file and then read in the REGF block to get the
first hbin offset.
*******************************************************************/
@@ -198,7 +250,13 @@
return NULL;
}
ZERO_STRUCTP( rb );
+ rb->fd = -1;
+ if ( !(rb->mem_ctx = talloc_init( "read_regf_block" )) ) {
+ regfio_close( rb );
+ return NULL;
+ }
+
/* open and existing file */
if ( (rb->fd = open(filename, flags, mode)) == -1 ) {
@@ -221,6 +279,12 @@
regfio_close( rb );
return NULL;
}
+
+ if ( !(rb->current_hbin = read_hbin_block( rb, 0x0 )) ) {
+ DEBUG(0,("regfio_open: Failed to read first hbin block\n"));
+ regfio_close( rb );
+ return NULL;
+ }
return rb;
Modified: trunk/source/utils/net_rpc_registry.c
===================================================================
--- trunk/source/utils/net_rpc_registry.c 2005-04-21 02:26:19 UTC (rev 6409)
+++ trunk/source/utils/net_rpc_registry.c 2005-04-21 03:09:10 UTC (rev 6410)
@@ -274,6 +274,8 @@
d_printf("ok\n");
+
+
d_printf("Closing registry...");
regfio_close( registry );
d_printf("ok\n");
More information about the samba-cvs
mailing list