2 Samba Unix/Linux SMB client utility libeditreg.c
3 Copyright (C) 2004 Jelmer Vernooij, jelmer@samba.org
5 Backend for Windows '95 registry files. Explanation of file format
6 comes from http://www.cs.mun.ca/~michael/regutils/.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "lib/registry/common/registry.h"
26 * The registry starts with a header that contains pointers to
29 * After the main header follows the RGKN header (key index table) */
31 typedef unsigned int DWORD;
32 typedef unsigned short WORD;
34 typedef struct regc_block {
35 DWORD REGC_ID; /* REGC */
47 typedef struct rgkn_block {
48 DWORD RGKN_ID; /* RGKN */
58 typedef struct rgkn_key {
69 typedef struct rgdb_block {
70 DWORD RGDB_ID; /* RGDB */
75 DWORD free_offset; /* -1 if there is no free space */
82 typedef struct rgdb_key {
93 typedef struct rgdb_value {
100 typedef struct regc_struct_s {
107 static WERROR w95_open_reg (REG_HANDLE *h, const char *location, const char *credentials)
109 REGC *regc = talloc_p(h->mem_ctx, REGC);
112 DWORD regc_id, rgkn_id;
113 memset(regc, 0, sizeof(REGC));
114 h->backend_data = regc;
116 if((regc->fd = open(location, O_RDONLY, 0000)) < 0) {
120 if(fstat(regc->fd, ®c->sbuf) < 0) {
124 regc->base = mmap(0, regc->sbuf.st_size, PROT_READ, MAP_SHARED, regc->fd, 0);
125 regc_hdr = (REGC_HDR *)regc->base;
127 if ((int)regc->base == 1) {
131 if ((regc_id = IVAL(®c_hdr->REGC_ID,0)) != str_to_dword("REGC")) {
132 DEBUG(0, ("Unrecognized Windows 95 registry header id: %0X, %s\n",
137 rgkn_hdr = (RGKN_HDR *)regc->base + sizeof(REGC_HDR);
139 if ((rgkn_id = IVAL(&rgkn_hdr->RGKN_ID,0)) != str_to_dword("RGKN")) {
140 DEBUG(0, ("Unrecognized Windows 95 registry key index id: %0X, %s\n",
145 //rgkn = (RGKN_KEY *)regc->base + sizeof(REGC_HDR) + sizeof(RGKN_HDR);
152 static WERROR w95_close_reg(REG_HANDLE *h)
154 REGC *regc = h->backend_data;
155 if (regc->base) munmap(regc->base, regc->sbuf.st_size);
161 static struct registry_ops reg_backend_w95 = {
163 .open_registry = w95_open_reg,
164 .close_registry = w95_close_reg,
167 NTSTATUS reg_w95_init(void)
169 return register_backend("registry", ®_backend_w95);