*************************************************************************/
#include "includes.h"
-#include "lib/registry/common/registry.h"
#define REG_KEY_LIST_SIZE 10
+#define FLAG_HAS_NAME 0x01
/*FIXME*/
/*
#define BLK_SIZE(b) ((int)*(int *)(((int *)b)-1))
-typedef unsigned int DWORD;
+typedef uint_t DWORD;
typedef unsigned short WORD;
typedef struct sk_struct SK_HDR;
DWORD uk5; /* 0 */
DWORD uk6; /* 1 */
DWORD first_key; /* offset */
- unsigned int dblk_size;
+ uint_t dblk_size;
DWORD uk7[116]; /* 1 */
DWORD chksum;
} REGF_HDR;
int type, size;
struct hbin_blk_s *next;
char *data; /* The data block */
- unsigned int file_offset; /* Offset in file */
- unsigned int free_space; /* Amount of free space in block */
- unsigned int fsp_off; /* Start of free space in block */
+ uint_t file_offset; /* Offset in file */
+ uint_t free_space; /* Amount of free space in block */
+ uint_t fsp_off; /* Start of free space in block */
int complete, stored;
} HBIN_BLK;
/*
* Create an ACE
*/
-static BOOL nt_create_ace(SEC_ACE *ace, int type, int flags, uint32 perms, const char *sid)
+static BOOL nt_create_ace(SEC_ACE *ace, int type, int flags, uint32_t perms, const char *sid)
{
DOM_SID s;
SEC_ACCESS access;
/*
* Create a default ACL
*/
-static SEC_ACL *nt_create_default_acl(REG_HANDLE *regf)
+static SEC_ACL *nt_create_default_acl(struct registry_hive *regf)
{
SEC_ACE aces[8];
* Create a default security descriptor. We pull in things from env
* if need be
*/
-static SEC_DESC *nt_create_def_sec_desc(REG_HANDLE *regf)
+static SEC_DESC *nt_create_def_sec_desc(struct registry_hive *regf)
{
SEC_DESC *tmp;
* says, but the Owner and Group SIDs can be overwridden from the command line
* and additional ACEs can be applied from the command line etc.
*/
-static KEY_SEC_DESC *nt_inherit_security(REG_KEY *key)
+static KEY_SEC_DESC *nt_inherit_security(struct registry_key *key)
{
if (!key) return NULL;
* Create an initial security descriptor and init other structures, if needed
* We assume that the initial security stuff is empty ...
*/
-static KEY_SEC_DESC *nt_create_init_sec(REG_HANDLE *h)
+static KEY_SEC_DESC *nt_create_init_sec(struct registry_hive *h)
{
REGF *regf = h->backend_data;
KEY_SEC_DESC *tsec = NULL;
#define REG_HANDLE_REGTYPE_NT 1
#define REG_HANDLE_REGTYPE_W9X 2
-#define TTTONTTIME(r, t1, t2) (r)->last_mod_time.low = (t1); \
- (r)->last_mod_time.high = (t2);
+#define TTTONTTIME(r, t1, t2) (r)->last_mod_time = (t1) | (((uint64_t)(t2)) << 32)
#define REGF_HDR_BLKSIZ 0x1000
/* Get the header of the registry. Return a pointer to the structure
* If the mmap'd area has not been allocated, then mmap the input file
*/
-static REGF_HDR *nt_get_regf_hdr(REG_HANDLE *h)
+static REGF_HDR *nt_get_regf_hdr(struct registry_hive *h)
{
REGF *regf = h->backend_data;
SMB_REG_ASSERT(regf);
/*
* Create a new entry in the map, and increase the size of the map if needed
*/
-static SK_MAP *alloc_sk_map_entry(REG_HANDLE *h, KEY_SEC_DESC *tmp, int sk_off)
+static SK_MAP *alloc_sk_map_entry(struct registry_hive *h, KEY_SEC_DESC *tmp, int sk_off)
{
REGF *regf = h->backend_data;
if (!regf->sk_map) { /* Allocate a block of 10 */
/*
* Allocate a KEY_SEC_DESC if we can't find one in the map
*/
-static KEY_SEC_DESC *lookup_create_sec_key(REG_HANDLE *h, SK_MAP *sk_map, int sk_off)
+static KEY_SEC_DESC *lookup_create_sec_key(struct registry_hive *h, SK_MAP *sk_map, int sk_off)
{
REGF *regf = h->backend_data;
KEY_SEC_DESC *tmp = lookup_sec_key(regf->sk_map, regf->sk_count, sk_off);
}
}
-static SEC_DESC *process_sec_desc(REG_HANDLE *regf, SEC_DESC *sec_desc)
+static SEC_DESC *process_sec_desc(struct registry_hive *regf, SEC_DESC *sec_desc)
{
SEC_DESC *tmp = NULL;
return tmp;
}
-static KEY_SEC_DESC *process_sk(REG_HANDLE *regf, SK_HDR *sk_hdr, int sk_off, int size)
+static KEY_SEC_DESC *process_sk(struct registry_hive *regf, SK_HDR *sk_hdr, int sk_off, int size)
{
KEY_SEC_DESC *tmp = NULL;
int sk_next_off, sk_prev_off, sk_size;
/*
* Process a VK header and return a value
*/
-static WERROR vk_to_val(REG_KEY *parent, VK_HDR *vk_hdr, int size, REG_VAL **value)
+static WERROR vk_to_val(TALLOC_CTX *mem_ctx, struct registry_key *parent, VK_HDR *vk_hdr, int size, struct registry_value **value)
{
- char val_name[1024];
- REGF *regf = parent->handle->backend_data;
+ REGF *regf = parent->hive->backend_data;
int nam_len, dat_len, flag, dat_type, dat_off, vk_id;
- REG_VAL *tmp = NULL;
+ struct registry_value *tmp = NULL;
if (!vk_hdr) return WERR_INVALID_PARAM;
if ((vk_id = SVAL(&vk_hdr->VK_ID,0)) != str_to_dword("vk")) {
DEBUG(0, ("Unrecognized VK header ID: %0X, block: %0X, %s\n",
- vk_id, (int)vk_hdr, parent->handle->location));
+ vk_id, (int)vk_hdr, parent->hive->location));
return WERR_GENERAL_FAILURE;
}
nam_len = SVAL(&vk_hdr->nam_len,0);
- val_name[nam_len] = '\0';
flag = SVAL(&vk_hdr->flag,0);
dat_type = IVAL(&vk_hdr->dat_type,0);
dat_len = IVAL(&vk_hdr->dat_len,0); /* If top bit, offset contains data */
dat_off = IVAL(&vk_hdr->dat_off,0);
- tmp = reg_val_new(parent, NULL);
- tmp->has_name = flag;
+ tmp = talloc_p(mem_ctx, struct registry_value);
tmp->data_type = dat_type;
- if (flag & 0x01) {
- strncpy(val_name, vk_hdr->dat_name, nam_len);
- tmp->name = strdup(val_name);
+ if (flag & FLAG_HAS_NAME) {
+ tmp->name = talloc_strndup(mem_ctx, vk_hdr->dat_name, nam_len);
+ } else {
+ tmp->name = NULL;
}
- else
- strncpy(val_name, "<No Name>", 10);
/*
* Allocate space and copy the data as a BLOB
if (dat_len&0x7FFFFFFF) {
- char *dtmp = (char *)talloc(tmp->mem_ctx, dat_len&0x7FFFFFFF);
-
- tmp->data_blk = dtmp;
+ char *dtmp = (char *)talloc(mem_ctx, dat_len&0x7FFFFFFF);
if ((dat_len&0x80000000) == 0) { /* The data is pointed to by the offset */
char *dat_ptr = LOCN(regf->base, dat_off);
memcpy(dtmp, &dat_off, dat_len);
}
+
+ if(tmp->data_type == REG_SZ) {
+ char *ret;
+ dat_len = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, dtmp, dat_len, (void **)&ret);
+ dtmp = ret;
+ }
+
+
+ tmp->data_blk = dtmp;
tmp->data_len = dat_len;
}
#endif
-static WERROR lf_verify(REG_HANDLE *h, LF_HDR *lf_hdr, int size)
+static WERROR lf_verify(struct registry_hive *h, LF_HDR *lf_hdr, int size)
{
int lf_id;
if ((lf_id = SVAL(&lf_hdr->LF_ID,0)) != str_to_dword("lf")) {
return WERR_OK;
}
-static WERROR lf_num_entries(REG_HANDLE *h, LF_HDR *lf_hdr, int size, int *count)
+static WERROR lf_num_entries(struct registry_hive *h, LF_HDR *lf_hdr, int size, int *count)
{
WERROR error;
}
-static WERROR nk_to_key(REG_HANDLE *regf, NK_HDR *nk_hdr, int size, REG_KEY *parent, REG_KEY **);
+static WERROR nk_to_key(TALLOC_CTX *, struct registry_hive *regf, NK_HDR *nk_hdr, int size, struct registry_key *parent, struct registry_key **);
/*
* Process an LF Header and return a list of sub-keys
*/
-static WERROR lf_get_entry(REG_KEY *parent, LF_HDR *lf_hdr, int size, int n, REG_KEY **key)
+static WERROR lf_get_entry(TALLOC_CTX *mem_ctx, struct registry_key *parent, LF_HDR *lf_hdr, int size, int n, struct registry_key **key)
{
- REGF *regf = parent->handle->backend_data;
+ REGF *regf = parent->hive->backend_data;
int count, nk_off;
NK_HDR *nk_hdr;
WERROR error;
if (!lf_hdr) return WERR_INVALID_PARAM;
- error = lf_verify(parent->handle, lf_hdr, size);
+ error = lf_verify(parent->hive, lf_hdr, size);
if(!W_ERROR_IS_OK(error)) return error;
SMB_REG_ASSERT(size < 0);
nk_off = IVAL(&lf_hdr->hr[n].nk_off,0);
DEBUG(2, ("NK Offset: %0X\n", nk_off));
nk_hdr = (NK_HDR *)LOCN(regf->base, nk_off);
- return nk_to_key(parent->handle, nk_hdr, BLK_SIZE(nk_hdr), parent, key);
+ return nk_to_key(mem_ctx, parent->hive, nk_hdr, BLK_SIZE(nk_hdr), parent, key);
}
-static WERROR nk_to_key(REG_HANDLE *h, NK_HDR *nk_hdr, int size, REG_KEY *parent, REG_KEY **key)
+static WERROR nk_to_key(TALLOC_CTX *mem_ctx, struct registry_hive *h, NK_HDR *nk_hdr, int size, struct registry_key *parent, struct registry_key **key)
{
REGF *regf = h->backend_data;
- REG_KEY *tmp = NULL, *own;
+ struct registry_key *tmp = NULL, *own;
int namlen, clsname_len, sk_off, own_off;
- unsigned int nk_id;
+ uint_t nk_id;
SK_HDR *sk_hdr;
int type;
- char key_name[1024], cls_name[1024];
+ char key_name[1024];
if (!nk_hdr) return WERR_INVALID_PARAM;
if ((nk_id = SVAL(&nk_hdr->NK_ID,0)) != str_to_dword("nk")) {
DEBUG(0, ("Unrecognized NK Header format: %08X, Block: %0X. %s\n",
- nk_id, (int)nk_hdr, parent->handle->location));
+ nk_id, (int)nk_hdr, parent->hive->location));
return WERR_INVALID_PARAM;
}
return WERR_GENERAL_FAILURE;
}
- if(type == REG_ROOT_KEY) tmp = reg_key_new_abs(key_name, h, nk_hdr);
- else tmp = reg_key_new_rel(key_name, parent, nk_hdr);
+ tmp = talloc_p(mem_ctx, struct registry_key);
+ tmp->name = talloc_strdup(mem_ctx, key_name);
+ tmp->backend_data = nk_hdr;
DEBUG(2, ("Key name: %s\n", key_name));
*/
if (clsname_len) { /* Just print in Ascii for now */
- smb_ucs2_t *clsnamep;
+ void *clsnamep;
int clsnam_off;
clsnam_off = IVAL(&nk_hdr->clsnam_off,0);
- clsnamep = (smb_ucs2_t *)LOCN(regf->base, clsnam_off);
+ clsnamep = LOCN(regf->base, clsnam_off);
DEBUG(2, ("Class Name Offset: %0X\n", clsnam_off));
- pull_ucs2_talloc(tmp->mem_ctx, &tmp->class_name, clsnamep);
+ pull_ucs2_talloc(mem_ctx, &tmp->class_name, clsnamep);
- DEBUGADD(2,(" Class Name: %s\n", cls_name));
+ DEBUGADD(2,(" Class Name: %s\n", tmp->class_name));
}
*/
own_off = IVAL(&nk_hdr->own_off,0);
- own = (REG_KEY *)LOCN(regf->base, own_off);
+ own = (struct registry_key *)LOCN(regf->base, own_off);
DEBUG(2, ("Owner Offset: %0X\n", own_off));
DEBUGADD(2, (" Owner locn: %0X, Our locn: %0X\n",
- (unsigned int)own, (unsigned int)nk_hdr));
+ (uint_t)own, (uint_t)nk_hdr));
/*
* We should verify that the owner field is correct ...
/*
* Allocate a new hbin block, set up the header for the block etc
*/
-static HBIN_BLK *nt_create_hbin_blk(REG_HANDLE *h, int size)
+static HBIN_BLK *nt_create_hbin_blk(struct registry_hive *h, int size)
{
REGF *regf = h->backend_data;
HBIN_BLK *tmp;
* Allocate a unit of space ... and return a pointer as function param
* and the block's offset as a side effect
*/
-static void *nt_alloc_regf_space(REG_HANDLE *h, int size, unsigned int *off)
+static void *nt_alloc_regf_space(struct registry_hive *h, int size, uint_t *off)
{
REGF *regf = h->backend_data;
int tmp = 0;
/*
* Store a SID at the location provided
*/
-static int nt_store_SID(REG_HANDLE *regf, DOM_SID *sid, unsigned char *locn)
+static int nt_store_SID(struct registry_hive *regf, DOM_SID *sid, uint8_t *locn)
{
int i;
- unsigned char *p = locn;
+ uint8_t *p = locn;
if (!regf || !sid || !locn) return 0;
}
-static int nt_store_ace(REG_HANDLE *regf, SEC_ACE *ace, unsigned char *locn)
+static int nt_store_ace(struct registry_hive *regf, SEC_ACE *ace, uint8_t *locn)
{
int size = 0;
SEC_ACE *reg_ace = (SEC_ACE *)locn;
- unsigned char *p;
+ uint8_t *p;
if (!regf || !ace || !locn) return 0;
/* Deal with the length when we have stored the SID */
- p = (unsigned char *)®_ace->info.mask;
+ p = (uint8_t *)®_ace->info.mask;
SIVAL(p, 0, ace->info.mask); p += 4;
size += 8; /* Size of the fixed header */
- p = (unsigned char *)®_ace->size;
+ p = (uint8_t *)®_ace->size;
SSVAL(p, 0, size);
/*
* Store an ACL at the location provided
*/
-static int nt_store_acl(REG_HANDLE *regf, SEC_ACL *acl, unsigned char *locn) {
+static int nt_store_acl(struct registry_hive *regf, SEC_ACL *acl, uint8_t *locn) {
int size = 0, i;
- unsigned char *p = locn, *s;
+ uint8_t *p = locn, *s;
if (!regf || !acl || !locn) return 0;
* that first, then the owner, then the group SID. So, we do it that way
* too.
*/
-static unsigned int nt_store_sec_desc(REG_HANDLE *regf, SEC_DESC *sd, char *locn)
+static uint_t nt_store_sec_desc(struct registry_hive *regf, SEC_DESC *sd, char *locn)
{
SEC_DESC *rsd = (SEC_DESC *)locn;
- unsigned int size = 0, off = 0;
+ uint_t size = 0, off = 0;
if (!regf || !sd || !locn) return 0;
* If it has already been stored, just get its offset from record
* otherwise, store it and record its offset
*/
-static unsigned int nt_store_security(REG_HANDLE *regf, KEY_SEC_DESC *sec)
+static uint_t nt_store_security(struct registry_hive *regf, KEY_SEC_DESC *sec)
{
int size = 0;
- unsigned int sk_off;
+ uint_t sk_off;
SK_HDR *sk_hdr;
if (sec->offset) return sec->offset;
* means making one pass over each structure and figuring it out
*/
-//FIXME size = sec_desc_size(sec->sec_desc);
+/* FIXME size = sec_desc_size(sec->sec_desc); */
/* Allocate that much space */
* We return the offset of the NK struct
* FIXME, FIXME, FIXME: Convert to using SIVAL and SSVAL ...
*/
-static int nt_store_reg_key(REG_HANDLE *regf, REG_KEY *key)
+static int nt_store_reg_key(struct registry_hive *regf, struct registry_key *key)
{
NK_HDR *nk_hdr;
- unsigned int nk_off, sk_off, size;
+ uint_t nk_off, sk_off, size;
if (!regf || !key) return 0;
* We actually create the registry header block and link it to the chain
* of output blocks.
*/
-static REGF_HDR *nt_get_reg_header(REG_HANDLE *h) {
+static REGF_HDR *nt_get_reg_header(struct registry_hive *h) {
REGF *regf = h->backend_data;
HBIN_BLK *tmp = NULL;
#endif
-static WERROR nt_close_registry (REG_HANDLE *h)
-{
- REGF *regf = h->backend_data;
- if (regf->base) munmap(regf->base, regf->sbuf.st_size);
- regf->base = NULL;
- close(regf->fd); /* Ignore the error :-) */
-
- return WERR_OK;
-}
-
-static WERROR nt_open_registry (REG_HANDLE *h, const char *location, const char *credentials)
+static WERROR nt_open_hive (TALLOC_CTX *mem_ctx, struct registry_hive *h, struct registry_key **key)
{
REGF *regf;
REGF_HDR *regf_hdr;
- unsigned int regf_id, hbin_id;
+ uint_t regf_id, hbin_id;
HBIN_HDR *hbin_hdr;
- regf = (REGF *)talloc_p(h->mem_ctx, REGF);
+ regf = (REGF *)talloc_p(mem_ctx, REGF);
memset(regf, 0, sizeof(REGF));
- regf->owner_sid_str = credentials;
+ regf->owner_sid_str = h->credentials;
h->backend_data = regf;
DEBUG(5, ("Attempting to load registry file\n"));
h->backend_data = regf;
- return WERR_OK;
+ return nk_to_key(mem_ctx, h, ((REGF *)h->backend_data)->first_key, BLK_SIZE(((REGF *)h->backend_data)->first_key), NULL, key);
}
-static WERROR nt_get_root_key(REG_HANDLE *h, int hive, REG_KEY **key)
-{
- if(hive != 0) return WERR_NO_MORE_ITEMS;
- return nk_to_key(h, ((REGF *)h->backend_data)->first_key, BLK_SIZE(((REGF *)h->backend_data)->first_key), NULL, key);
-}
-static WERROR nt_num_subkeys(REG_KEY *k, int *num)
+static WERROR nt_num_subkeys(struct registry_key *k, int *num)
{
- REGF *regf = k->handle->backend_data;
+ REGF *regf = k->hive->backend_data;
LF_HDR *lf_hdr;
int lf_off;
NK_HDR *nk_hdr = k->backend_data;
}
lf_hdr = (LF_HDR *)LOCN(regf->base, lf_off);
- return lf_num_entries(k->handle, lf_hdr, BLK_SIZE(lf_hdr), num);
+ return lf_num_entries(k->hive, lf_hdr, BLK_SIZE(lf_hdr), num);
}
-static WERROR nt_num_values(REG_KEY *k, int *count)
+static WERROR nt_num_values(struct registry_key *k, int *count)
{
NK_HDR *nk_hdr = k->backend_data;
*count = IVAL(&nk_hdr->val_cnt,0);
return WERR_OK;
}
-static WERROR nt_value_by_index(REG_KEY *k, int n, REG_VAL **value)
+static WERROR nt_value_by_index(TALLOC_CTX *mem_ctx, struct registry_key *k, int n, struct registry_value **value)
{
VL_TYPE *vl;
int val_off, vk_off;
int val_count;
VK_HDR *vk_hdr;
- REGF *regf = k->handle->backend_data;
+ REGF *regf = k->hive->backend_data;
NK_HDR *nk_hdr = k->backend_data;
val_count = IVAL(&nk_hdr->val_cnt,0);
val_off = IVAL(&nk_hdr->val_off,0);
vk_off = IVAL(&vl[n],0);
vk_hdr = (VK_HDR *)LOCN(regf->base, vk_off);
- return vk_to_val(k, vk_hdr, BLK_SIZE(vk_hdr), value);
+ return vk_to_val(mem_ctx, k, vk_hdr, BLK_SIZE(vk_hdr), value);
}
-static WERROR nt_key_by_index(REG_KEY *k, int n, REG_KEY **subkey)
+static WERROR nt_key_by_index(TALLOC_CTX *mem_ctx, struct registry_key *k, int n, struct registry_key **subkey)
{
- REGF *regf = k->handle->backend_data;
+ REGF *regf = k->hive->backend_data;
int lf_off;
NK_HDR *nk_hdr = k->backend_data;
LF_HDR *lf_hdr;
if (lf_off != -1) {
lf_hdr = (LF_HDR *)LOCN(regf->base, lf_off);
- return lf_get_entry(k, lf_hdr, BLK_SIZE(lf_hdr), n, subkey);
+ return lf_get_entry(mem_ctx, k, lf_hdr, BLK_SIZE(lf_hdr), n, subkey);
}
return WERR_NO_MORE_ITEMS;
}
-static struct registry_ops reg_backend_nt4 = {
+static struct registry_operations reg_backend_nt4 = {
.name = "nt4",
- .open_registry = nt_open_registry,
- .close_registry = nt_close_registry,
- .get_hive = nt_get_root_key,
+ .open_hive = nt_open_hive,
.num_subkeys = nt_num_subkeys,
.num_values = nt_num_values,
.get_subkey_by_index = nt_key_by_index,