source: trunk/include/regfio.h @ 30

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

Added initial version of regfio interface, borrowed from Samba project.

Library has all write capability stripped, and all Samba dependency has
either been removed, or included in the smb_deps code.

  • Property svn:keywords set to Id
File size: 6.5 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 30 2005-07-16 14:31:27Z 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 <stdbool.h>
37#include <stdio.h>
38#include <errno.h>
39#include <fcntl.h>
40#include <sys/stat.h>
41#include <sys/types.h>
42#include <unistd.h>
43#include <assert.h>
44
45#include "smb_deps.h"
46
47
48/******************************************************************************/
49/* Macros */
50 
51#define REGF_BLOCKSIZE          0x1000
52#define REGF_ALLOC_BLOCK        0x1000
53
54/* header sizes for various records */
55
56#define REGF_HDR_SIZE           4
57#define HBIN_HDR_SIZE           4
58#define HBIN_HEADER_REC_SIZE    0x24
59#define REC_HDR_SIZE            2
60
61#define REGF_OFFSET_NONE        0xffffffff
62
63/* Flags for the vk records */
64
65#define VK_FLAG_NAME_PRESENT    0x0001
66#define VK_DATA_IN_OFFSET       0x80000000
67
68/* NK record macros */
69
70#define NK_TYPE_LINKKEY         0x0010
71#define NK_TYPE_NORMALKEY       0x0020
72#define NK_TYPE_ROOTKEY         0x002c
73
74#define HBIN_STORE_REF(x, y)    { x->hbin = y; y->ref_count++ };
75#define HBIN_REMOVE_REF(x, y)   { x->hbin = NULL; y->ref_count-- /* if the count == 0; we can clean up */ };
76
77
78/* HBIN block */
79struct regf_hbin;
80typedef struct regf_hbin {
81        struct regf_hbin *prev, *next;
82        uint32 file_off;                /* my offset in the registry file */
83        uint32 free_off;                /* offset to free space within the hbin record */
84        uint32 free_size;               /* amount of data left in the block */
85        int ref_count;                  /* how many active records are pointing to this block (not used currently) */
86       
87        char   header[HBIN_HDR_SIZE];   /* "hbin" */
88        uint32 first_hbin_off;          /* offset from first hbin block */
89        uint32 block_size;              /* block size of this blockually a multiple of 4096Kb) */
90
91        prs_struct ps;                  /* data */
92
93        bool dirty;                     /* has this hbin block been modified? */
94} REGF_HBIN;
95
96/* ??? List -- list of key offsets and hashed names for consistency */
97
98typedef struct {
99        uint32 nk_off;
100        uint8 keycheck[sizeof(uint32)];
101} REGF_HASH_REC;
102
103typedef struct {
104        REGF_HBIN *hbin;        /* pointer to HBIN record (in memory) containing this nk record */
105        uint32 hbin_off;        /* offset from beginning of this hbin block */
106        uint32 rec_size;        /* ((start_offset - end_offset) & 0xfffffff8) */
107
108        char header[REC_HDR_SIZE];
109        uint16 num_keys;
110        REGF_HASH_REC *hashes;
111} REGF_LF_REC;
112
113/* Key Value */
114
115typedef struct {
116        REGF_HBIN *hbin;        /* pointer to HBIN record (in memory) containing this nk record */
117        uint32 hbin_off;        /* offset from beginning of this hbin block */
118        uint32 rec_size;        /* ((start_offset - end_offset) & 0xfffffff8) */
119        uint32 rec_off;         /* offset stored in the value list */
120       
121        char header[REC_HDR_SIZE];
122        char *valuename;
123        uint32 data_size;
124        uint32 data_off;
125        uint8  *data;
126        uint32 type;
127        uint16 flag;
128} REGF_VK_REC;
129
130
131/* Key Security */
132struct _regf_sk_rec;
133
134typedef struct _regf_sk_rec {
135        struct _regf_sk_rec *next, *prev;
136        REGF_HBIN *hbin;        /* pointer to HBIN record (in memory) containing this nk record */
137        uint32 hbin_off;        /* offset from beginning of this hbin block */
138        uint32 rec_size;        /* ((start_offset - end_offset) & 0xfffffff8) */
139
140        uint32 sk_off;          /* offset parsed from NK record used as a key
141                                   to lookup reference to this SK record */
142
143        char header[REC_HDR_SIZE];
144        uint32 prev_sk_off;
145        uint32 next_sk_off;
146        uint32 ref_count;
147        uint32 size;
148        SEC_DESC *sec_desc;
149} REGF_SK_REC;
150
151/* Key Name */ 
152
153typedef struct {
154        REGF_HBIN *hbin;        /* pointer to HBIN record (in memory) containing this nk record */
155        uint32 hbin_off;        /* offset from beginning of this hbin block */
156        uint32 subkey_index;    /* index to next subkey record to return */
157        uint32 rec_size;        /* ((start_offset - end_offset) & 0xfffffff8) */
158       
159        /* header information */
160       
161        char header[REC_HDR_SIZE];
162        uint16 key_type;
163        NTTIME mtime;
164        uint32 parent_off;      /* back pointer in registry hive */
165        uint32 classname_off;   
166        char *classname;
167        char *keyname;
168
169        /* max lengths */
170
171        uint32 max_bytes_subkeyname;            /* max subkey name * 2 */
172        uint32 max_bytes_subkeyclassname;       /* max subkey classname length (as if) */
173        uint32 max_bytes_valuename;             /* max valuename * 2 */
174        uint32 max_bytes_value;                 /* max value data size */
175
176        /* unknowns */
177
178        uint32 unk_index;                       /* nigel says run time index ? */
179       
180        /* children */
181       
182        uint32 num_subkeys;
183        uint32 subkeys_off;     /* hash records that point to NK records */     
184        uint32 num_values;
185        uint32 values_off;      /* value lists which point to VK records */
186        uint32 sk_off;          /* offset to SK record */
187       
188        /* link in the other records here */
189       
190        REGF_LF_REC subkeys;
191        REGF_VK_REC *values;
192        REGF_SK_REC *sec_desc;
193       
194} REGF_NK_REC;
195
196/* REGF block */
197 
198typedef struct {
199        /* run time information */
200
201        int fd;                         /* file descriptor */
202        int open_flags;                 /* flags passed to the open() call */
203        void *mem_ctx;          /* memory context for run-time file access information */
204        REGF_HBIN *block_list;          /* list of open hbin blocks */
205
206        /* file format information */
207
208        char   header[REGF_HDR_SIZE];   /* "regf" */
209        uint32 data_offset;             /* offset to record in the first (or any?) hbin block */
210        uint32 last_block;              /* offset to last hbin block in file */
211        uint32 checksum;                /* XOR of bytes 0x0000 - 0x01FB */
212        NTTIME mtime;
213       
214        REGF_SK_REC *sec_desc_list;     /* list of security descriptors referenced by NK records */
215
216        /* unknowns used to simply writing */
217       
218        uint32 unknown1;
219        uint32 unknown2;
220        uint32 unknown3;
221        uint32 unknown4;
222        uint32 unknown5;
223        uint32 unknown6;
224       
225} REGF_FILE;
226
227/* Function Declarations */
228 
229REGF_FILE*    regfio_open( const char *filename );
230int           regfio_close( REGF_FILE *r );
231
232REGF_NK_REC*  regfio_rootkey( REGF_FILE *file );
233REGF_NK_REC*  regfio_fetch_subkey( REGF_FILE *file, REGF_NK_REC *nk );
234
235#endif  /* _REGFIO_H */
Note: See TracBrowser for help on using the repository browser.