Reading .REG files
Copyright (C) Jelmer Vernooij 2004-2007
- Copyright (C) Wilco Baan Hofman 2006
+ Copyright (C) Wilco Baan Hofman 2006-2008
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* FIXME Newer .REG files, created by Windows XP and above use unicode UTF-16 */
+/* FIXME Newer .REG files, created by Windows XP and above use unicode UCS-2 */
#include "includes.h"
-#include "lib/registry/patchfile.h"
#include "lib/registry/registry.h"
#include "system/filesys.h"
-#include "param/param.h"
/**
* @file
struct dotreg_data {
int fd;
- struct smb_iconv_convenience *iconv_convenience;
};
static WERROR reg_dotreg_diff_add_key(void *_data, const char *key_name)
uint32_t value_type, DATA_BLOB value)
{
struct dotreg_data *data = (struct dotreg_data *)_data;
-
+ char *data_string = reg_val_data_string(NULL,
+ value_type, value);
+ W_ERROR_HAVE_NO_MEMORY(data_string);
fdprintf(data->fd, "\"%s\"=%s:%s\n",
- value_name, str_regtype(value_type),
- reg_val_data_string(NULL, data->iconv_convenience, value_type, value));
+ value_name, str_regtype(value_type), data_string);
+ talloc_free(data_string);
return WERR_OK;
}
* Save registry diff
*/
_PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename,
- struct smb_iconv_convenience *iconv_convenience,
struct reg_diff_callbacks **callbacks,
void **callback_data)
{
data = talloc_zero(ctx, struct dotreg_data);
*callback_data = data;
- data->iconv_convenience = iconv_convenience;
-
if (filename) {
- data->fd = open(filename, O_CREAT, 0755);
- if (data->fd == -1) {
+ data->fd = open(filename, O_CREAT|O_WRONLY, 0755);
+ if (data->fd < 0) {
DEBUG(0, ("Unable to open %s\n", filename));
return WERR_BADFILE;
}
data->fd = STDOUT_FILENO;
}
- fdprintf(data->fd, "%s\n", HEADER_STRING);
+ fdprintf(data->fd, "%s\n\n", HEADER_STRING);
*callbacks = talloc(ctx, struct reg_diff_callbacks);
* Load diff file
*/
_PUBLIC_ WERROR reg_dotreg_diff_load(int fd,
- struct smb_iconv_convenience *iconv_convenience,
const struct reg_diff_callbacks *callbacks,
void *callback_data)
{
/* Deleting key */
if (line[1] == '-') {
curkey = talloc_strndup(line, line+2, strlen(line)-3);
+ W_ERROR_HAVE_NO_MEMORY(curkey);
error = callbacks->del_key(callback_data,
curkey);
+
if (!W_ERROR_IS_OK(error)) {
DEBUG(0,("Error deleting key %s\n",
curkey));
continue;
}
curkey = talloc_strndup(mem_ctx, line+1, strlen(line)-2);
+ W_ERROR_HAVE_NO_MEMORY(curkey);
error = callbacks->add_key(callback_data, curkey);
if (!W_ERROR_IS_OK(error)) {
q++;
}
- reg_string_to_val(line, iconv_convenience,
+ reg_string_to_val(line,
q?p:"REG_SZ", q?q:p,
&value_type, &value);