diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2004-04-12 11:02:38 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:51:15 -0500 |
commit | 24cd656ab0cd6501e321661883ae564c8d548298 (patch) | |
tree | 5e6a517d5170a06f1a802eb8c5820b1f1f3cbb46 /source4/lib/registry | |
parent | 9d6a284567b832eee6fd47ac48c3471e69c0cc17 (diff) | |
download | samba-24cd656ab0cd6501e321661883ae564c8d548298.tar.gz samba-24cd656ab0cd6501e321661883ae564c8d548298.tar.bz2 samba-24cd656ab0cd6501e321661883ae564c8d548298.zip |
r174: Win95 registry files (like USER.DAT) can now be partially parsed
(This used to be commit dd31d3bcbfbb0ef7a96a1b86c1b4c54b650e9fd5)
Diffstat (limited to 'source4/lib/registry')
-rw-r--r-- | source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c | 2 | ||||
-rw-r--r-- | source4/lib/registry/reg_backend_w95/reg_backend_w95.c | 127 | ||||
-rw-r--r-- | source4/lib/registry/tools/gregedit.c | 16 |
3 files changed, 100 insertions, 45 deletions
diff --git a/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c b/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c index fd91b4fbe6..74d7bbd3b1 100644 --- a/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c +++ b/source4/lib/registry/reg_backend_nt4/reg_backend_nt4.c @@ -487,7 +487,7 @@ typedef struct regf_struct_s { HBIN_BLK *blk_head, *blk_tail, *free_space; } REGF; -DWORD str_to_dword(const char *a) { +static DWORD str_to_dword(const char *a) { int i; unsigned long ret = 0; for(i = strlen(a)-1; i >= 0; i--) { diff --git a/source4/lib/registry/reg_backend_w95/reg_backend_w95.c b/source4/lib/registry/reg_backend_w95/reg_backend_w95.c index 79ebd54510..8b20b830e1 100644 --- a/source4/lib/registry/reg_backend_w95/reg_backend_w95.c +++ b/source4/lib/registry/reg_backend_w95/reg_backend_w95.c @@ -31,18 +31,17 @@ typedef unsigned int DWORD; typedef unsigned short WORD; -typedef struct regc_block { - DWORD REGC_ID; /* REGC */ +typedef struct creg_block { + DWORD CREG_ID; /* CREG */ DWORD uk1; DWORD rgdb_offset; DWORD chksum; WORD num_rgdb; WORD flags; - DWORD uk2; - DWORD uk3; - DWORD uk4; - DWORD uk5; -} REGC_HDR; + DWORD uk2; + DWORD uk3; + DWORD uk4; +} CREG_HDR; typedef struct rgkn_block { DWORD RGKN_ID; /* RGKN */ @@ -56,7 +55,7 @@ typedef struct rgkn_block { } RGKN_HDR; typedef struct rgkn_key { - DWORD inuse; + DWORD type; DWORD hash; DWORD next_free; DWORD parent; @@ -80,7 +79,7 @@ typedef struct rgdb_block { } RGDB_HDR; typedef struct rgdb_key { - DWORD inuse; + DWORD type; DWORD hash; DWORD next_free; DWORD parent; @@ -97,64 +96,112 @@ typedef struct rgdb_value { DWORD data_len; } RGDB_VALUE; -typedef struct regc_struct_s { +typedef struct creg_struct_s { int fd; - struct stat sbuf; BOOL modified; char *base; -} REGC; + struct stat sbuf; + CREG_HDR *creg_hdr; + RGKN_HDR *rgkn_hdr; + char *rgkn; +} CREG; + +static DWORD str_to_dword(const char *a) { + int i; + unsigned long ret = 0; + for(i = strlen(a)-1; i >= 0; i--) { + ret = ret * 0x100 + a[i]; + } + return ret; +} + +#define LOCN(creg, o) (((creg)->base + sizeof(CREG_HDR) + o)) static WERROR w95_open_reg (REG_HANDLE *h, const char *location, const char *credentials) { - REGC *regc = talloc_p(h->mem_ctx, REGC); - REGC_HDR *regc_hdr; - RGKN_HDR *rgkn_hdr; - DWORD regc_id, rgkn_id; - memset(regc, 0, sizeof(REGC)); - h->backend_data = regc; - - if((regc->fd = open(location, O_RDONLY, 0000)) < 0) { + CREG *creg = talloc_p(h->mem_ctx, CREG); + DWORD creg_id, rgkn_id; + memset(creg, 0, sizeof(CREG)); + h->backend_data = creg; + DWORD i, nfree = 0; + DWORD offset; + + if((creg->fd = open(location, O_RDONLY, 0000)) < 0) { return WERR_FOOBAR; } - if(fstat(regc->fd, ®c->sbuf) < 0) { + if (fstat(creg->fd, &creg->sbuf) < 0) { return WERR_FOOBAR; - } + } - regc->base = mmap(0, regc->sbuf.st_size, PROT_READ, MAP_SHARED, regc->fd, 0); - regc_hdr = (REGC_HDR *)regc->base; + creg->base = mmap(0, creg->sbuf.st_size, PROT_READ, MAP_SHARED, creg->fd, 0); + + if ((int)creg->base == 1) { + DEBUG(0,("Could not mmap file: %s, %s\n", location, strerror(errno))); + return WERR_FOOBAR; + } - if ((int)regc->base == 1) { - return WERR_FOOBAR; - } - - if ((regc_id = IVAL(®c_hdr->REGC_ID,0)) != str_to_dword("REGC")) { - DEBUG(0, ("Unrecognized Windows 95 registry header id: %0X, %s\n", - regc_id, location)); + creg->creg_hdr = (CREG_HDR *)creg->base; + + if ((creg_id = IVAL(&creg->creg_hdr->CREG_ID,0)) != str_to_dword("CREG")) { + DEBUG(0, ("Unrecognized Windows 95 registry header id: 0x%0X, %s\n", + creg_id, location)); return WERR_FOOBAR; } - rgkn_hdr = (RGKN_HDR *)regc->base + sizeof(REGC_HDR); + creg->rgkn_hdr = (RGKN_HDR *)LOCN(creg, 0); - if ((rgkn_id = IVAL(&rgkn_hdr->RGKN_ID,0)) != str_to_dword("RGKN")) { - DEBUG(0, ("Unrecognized Windows 95 registry key index id: %0X, %s\n", + if ((rgkn_id = IVAL(&creg->rgkn_hdr->RGKN_ID,0)) != str_to_dword("RGKN")) { + DEBUG(0, ("Unrecognized Windows 95 registry key index id: 0x%0X, %s\n", rgkn_id, location)); return WERR_FOOBAR; } - //rgkn = (RGKN_KEY *)regc->base + sizeof(REGC_HDR) + sizeof(RGKN_HDR); +#if 0 + for(i = 0; i < creg->rgkn_hdr->size; i+=sizeof(RGKN_KEY)) { + RGKN_KEY *key = (RGKN_KEY *)LOCN(creg, sizeof(RGKN_HDR) + i); + if(nfree > 0) { + nfree--; + } else if(key->type == 0) { + DEBUG(0,("Not used\n")); + /* Not used */ + } else if(key->type == 0x80000000) { + DEBUG(0,("Regular key\n")); + /* Regular key */ + } else { + DEBUG(0,("Invalid key type in RGKN: %0X\n", key->type)); + } + } - /* FIXME */ + curpos += creg->rgkn_hdr->size + sizeof(RGKN_HDR); +#endif + offset = creg->rgkn_hdr->size; + + DEBUG(0, ("Reading %d rgdb entries\n", creg->creg_hdr->num_rgdb)); + for(i = 0; i < creg->creg_hdr->num_rgdb; i++) { + RGDB_HDR *rgdb_hdr = (RGDB_HDR *)LOCN(creg, offset); + + if(strncmp((char *)&(rgdb_hdr->RGDB_ID), "RGDB", 4)) { + DEBUG(0, ("unrecognized rgdb entry: %4s, %s\n", + &rgdb_hdr->RGDB_ID, location)); + return WERR_FOOBAR; + } else { + DEBUG(0, ("Valid rgdb entry\n")); + } + + offset+=rgdb_hdr->size; + } + return WERR_OK; } static WERROR w95_close_reg(REG_HANDLE *h) { - REGC *regc = h->backend_data; - if (regc->base) munmap(regc->base, regc->sbuf.st_size); - regc->base = NULL; - close(regc->fd); + CREG *creg = h->backend_data; + if (creg->base) munmap(creg->base, creg->sbuf.st_size); + creg->base = NULL; + close(creg->fd); return WERR_OK; } diff --git a/source4/lib/registry/tools/gregedit.c b/source4/lib/registry/tools/gregedit.c index 0c9084ad3e..10e5f45468 100644 --- a/source4/lib/registry/tools/gregedit.c +++ b/source4/lib/registry/tools/gregedit.c @@ -220,7 +220,7 @@ GtkWidget* create_rpcwin (void) return rpcwin; } -static void on_open_nt4_activate (GtkMenuItem *menuitem, gpointer user_data) +static void on_open_file_activate (GtkMenuItem *menuitem, gpointer user_data) { gint result = gtk_dialog_run(GTK_DIALOG(create_openfilewin())); char *filename; @@ -228,7 +228,7 @@ static void on_open_nt4_activate (GtkMenuItem *menuitem, gpointer user_data) switch(result) { case GTK_RESPONSE_OK: filename = strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(openfilewin))); - error = reg_open("nt4", filename, NULL, ®istry); + error = reg_open(user_data, filename, NULL, ®istry); if(!W_ERROR_IS_OK(error)) { gtk_show_werror(error); break; @@ -407,6 +407,7 @@ GtkWidget* create_mainwin (void) GtkWidget *menu_file; GtkWidget *menu_file_menu; GtkWidget *open_nt4; + GtkWidget *open_w95; GtkWidget *open_gconf; GtkWidget *open_remote; GtkWidget *separatormenuitem1; @@ -455,6 +456,10 @@ GtkWidget* create_mainwin (void) gtk_widget_show (open_nt4); gtk_container_add (GTK_CONTAINER (menu_file_menu), open_nt4); + open_w95 = gtk_image_menu_item_new_with_mnemonic("_Open Win9x file"); + gtk_widget_show (open_w95); + gtk_container_add (GTK_CONTAINER (menu_file_menu), open_w95); + open_gconf = gtk_image_menu_item_new_with_mnemonic ("_Open GConf"); gtk_widget_show (open_gconf); gtk_container_add (GTK_CONTAINER (menu_file_menu), open_gconf); @@ -595,8 +600,11 @@ GtkWidget* create_mainwin (void) gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE); g_signal_connect ((gpointer) open_nt4, "activate", - G_CALLBACK (on_open_nt4_activate), - NULL); + G_CALLBACK (on_open_file_activate), + "nt4"); + g_signal_connect ((gpointer) open_w95, "activate", + G_CALLBACK (on_open_file_activate), + "w95"); g_signal_connect ((gpointer) open_gconf, "activate", G_CALLBACK (on_open_gconf_activate), NULL); |