source: trunk/include/regfio.h @ 31

Last change on this file since 31 was 31, checked in by tim, 19 years ago

Added new lightweight stack library

rewrote test program to use this instead of string concatenation/recursion.

  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1/*
2 * Branched from Samba project, Subversion repository version #6903:
3 *   http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/include/regfio.h
4 *
5 * Unix SMB/CIFS implementation.
6 * Windows NT registry I/O library
7 *
8 * Copyright (C) 2005 Timothy D. Morgan
9 * Copyright (C) 2005 Gerald (Jerry) Carter
10 *
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; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * $Id: regfio.h 31 2005-07-16 19:05:19Z tim $
25 */
26
27/************************************************************
28 * Most of this information was obtained from
29 * http://www.wednesday.demon.co.uk/dosreg.html
30 * Thanks Nigel!
31 ***********************************************************/
32
33#ifndef _REGFIO_H
34#define _REGFIO_H
35
36#include <stdlib.h>
37#include <stdio.h>
38#include <stdbool.h>
39#include <string.h>
40#include <errno.h>
41#include <time.h>
42#include <fcntl.h>
43#include <sys/stat.h>
44#include <sys/types.h>
45#include <unistd.h>
46#include <assert.h>
47
48#include "smb_deps.h"
49
50
51/******************************************************************************/
52/* Macros */
53 
54#define REGF_BLOCKSIZE          0x1000
55#define REGF_ALLOC_BLOCK        0x1000
56
57/* header sizes for various records */
58
59#define REGF_HDR_SIZE           4
60#define HBIN_HDR_SIZE           4
61#define HBIN_HEADER_REC_SIZE    0x24
62#define REC_HDR_SIZE            2
63
64#define REGF_OFFSET_NONE        0xffffffff
65
66/* Flags for the vk records */
67
68#define VK_FLAG_NAME_PRESENT    0x0001
69#define VK_DATA_IN_OFFSET       0x80000000
70
71/* NK record macros */
72
73#define NK_TYPE_LINKKEY         0x0010
74#define NK_TYPE_NORMALKEY       0x0020
75#define NK_TYPE_ROOTKEY         0x002c
76
77#define HBIN_STORE_REF(x, y)    { x->hbin = y; y->ref_count++ };
78#define HBIN_REMOVE_REF(x, y)   { x->hbin = NULL; y->ref_count-- /* if the count == 0; we can clean up */ };
79
80
81/* HBIN block */
82struct regf_hbin;
83typedef struct regf_hbin {
84        struct regf_hbin *prev, *next;
85        uint32 file_off;                /* my offset in the registry file */
86        uint32 free_off;                /* offset to free space within the hbin record */
87        uint32 free_size;               /* amount of data left in the block */
88        int ref_count;                  /* how many active records are pointing to this block (not used currently) */
89       
90        char   header[HBIN_HDR_SIZE];   /* "hbin" */
91        uint32 first_hbin_off;          /* offset from first hbin block */
92        uint32 block_size;              /* block size of this blockually a multiple of 4096Kb) */
93
94        prs_struct ps;                  /* data */
95
96        bool dirty;                     /* has this hbin block been modified? */
97} REGF_HBIN;
98
99/* ??? List -- list of key offsets and hashed names for consistency */
100
101typedef struct {
102        uint32 nk_off;
103        uint8 keycheck[sizeof(uint32)];
104} REGF_HASH_REC;
105
106typedef struct {
107        REGF_HBIN *hbin;        /* pointer to HBIN record (in memory) containing this nk record */
108        uint32 hbin_off;        /* offset from beginning of this hbin block */
109        uint32 rec_size;        /* ((start_offset - end_offset) & 0xfffffff8) */
110
111        char header[REC_HDR_SIZE];
112        uint16 num_keys;
113        REGF_HASH_REC *hashes;
114} REGF_LF_REC;
115
116/* Key Value */
117
118typedef struct {
119        REGF_HBIN *hbin;        /* pointer to HBIN record (in memory) containing this nk record */
120        uint32 hbin_off;        /* offset from beginning of this hbin block */
121        uint32 rec_size;        /* ((start_offset - end_offset) & 0xfffffff8) */
122        uint32 rec_off;         /* offset stored in the value list */
123       
124        char header[REC_HDR_SIZE];
125        char *valuename;
126        uint32 data_size;
127        uint32 data_off;
128        uint8  *data;
129        uint32 type;
130        uint16 flag;
131} REGF_VK_REC;
132
133
134/* Key Security */
135struct _regf_sk_rec;
136
137typedef struct _regf_sk_rec {
138        struct _regf_sk_rec *next, *prev;
139        REGF_HBIN *hbin;        /* pointer to HBIN record (in memory) containing this nk record */
140        uint32 hbin_off;        /* offset from beginning of this hbin block */
141        uint32 rec_size;        /* ((start_offset - end_offset) & 0xfffffff8) */
142
143        uint32 sk_off;          /* offset parsed from NK record used as a key
144                                   to lookup reference to this SK record */
145
146        char header[REC_HDR_SIZE];
147        uint32 prev_sk_off;
148        uint32 next_sk_off;
149        uint32 ref_count;
150        uint32 size;
151        SEC_DESC *sec_desc;
152} REGF_SK_REC;
153
154/* Key Name */ 
155
156typedef struct {
157        REGF_HBIN *hbin;        /* pointer to HBIN record (in memory) containing this nk record */
158        uint32 hbin_off;        /* offset from beginning of this hbin block */
159        uint32 subkey_index;    /* index to next subkey record to return */
160        uint32 rec_size;        /* ((start_offset - end_offset) & 0xfffffff8) */
161       
162        /* header information */
163       
164        char header[REC_HDR_SIZE];
165        uint16 key_type;
166        NTTIME mtime;
167        uint32 parent_off;      /* back pointer in registry hive */
168        uint32 classname_off;   
169        char *classname;
170        char *keyname;
171
172        /* max lengths */
173
174        uint32 max_bytes_subkeyname;            /* max subkey name * 2 */
175        uint32 max_bytes_subkeyclassname;       /* max subkey classname length (as if) */
176        uint32 max_bytes_valuename;             /* max valuename * 2 */
177        uint32 max_bytes_value;                 /* max value data size */
178
179        /* unknowns */
180
181        uint32 unk_index;                       /* nigel says run time index ? */
182       
183        /* children */
184       
185        uint32 num_subkeys;
186        uint32 subkeys_off;     /* hash records that point to NK records */     
187        uint32 num_values;
188        uint32 values_off;      /* value lists which point to VK records */
189        uint32 sk_off;          /* offset to SK record */
190       
191        /* link in the other records here */
192       
193        REGF_LF_REC subkeys;
194        REGF_VK_REC *values;
195        REGF_SK_REC *sec_desc;
196       
197} REGF_NK_REC;
198
199/* REGF block */
200 
201typedef struct {
202        /* run time information */
203
204        int fd;                         /* file descriptor */
205        int open_flags;                 /* flags passed to the open() call */
206        void *mem_ctx;          /* memory context for run-time file access information */
207        REGF_HBIN *block_list;          /* list of open hbin blocks */
208
209        /* file format information */
210
211        char   header[REGF_HDR_SIZE];   /* "regf" */
212        uint32 data_offset;             /* offset to record in the first (or any?) hbin block */
213        uint32 last_block;              /* offset to last hbin block in file */
214        uint32 checksum;                /* XOR of bytes 0x0000 - 0x01FB */
215        NTTIME mtime;
216       
217        REGF_SK_REC *sec_desc_list;     /* list of security descriptors referenced by NK records */
218
219        /* unknowns used to simply writing */
220       
221        uint32 unknown1;
222        uint32 unknown2;
223        uint32 unknown3;
224        uint32 unknown4;
225        uint32 unknown5;
226        uint32 unknown6;
227       
228} REGF_FILE;
229
230/* Function Declarations */
231 
232REGF_FILE*    regfio_open( const char *filename );
233int           regfio_close( REGF_FILE *r );
234
235REGF_NK_REC*  regfio_rootkey( REGF_FILE *file );
236REGF_NK_REC*  regfio_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk );
237
238#endif  /* _REGFIO_H */
Note: See TracBrowser for help on using the repository browser.