*/
#include "includes.h"
+#include "dynconfig.h"
+#include "registry.h"
#include "lib/cmdline/popt_common.h"
+#include "system/filesys.h"
/*
* Routines to parse a REGEDIT4 file
#define CMD_KEY 1
#define CMD_VAL 2
-#include <include/includes.h>
-
typedef struct val_spec_list {
struct val_spec_list *next;
char *name;
*/
static struct cmd_line *get_cmd_line(int fd)
{
- struct cmd_line *cl = (CMD_LINE *)smb_xmalloc(sizeof(CMD_LINE));
+ CMD_LINE *cl = smb_xmalloc_p(CMD_LINE);
int i = 0, rc;
uint8_t ch;
struct cmd_line *cl = NULL;
struct val_spec_list *vl = NULL;
- cmd = (struct command_s *)smb_xmalloc(sizeof(struct command_s));
+ cmd = smb_xmalloc_p(struct command_s);
cmd->cmd = CMD_NONE;
cmd->key = NULL;
* There could be a \ on the end which we need to
* handle at some time
*/
- vl = (struct val_spec_list *)smb_xmalloc(sizeof(struct val_spec_list));
+ vl = smb_xmalloc_p(struct val_spec_list);
vl->next = NULL;
vl->val = NULL;
vl->name = parse_value(cl, &vl->type, &vl->val);
return NULL;
}
- tmp = (CMD_FILE *)smb_xmalloc(sizeof(CMD_FILE));
+ tmp = smb_xmalloc_p(CMD_FILE);
/*
* Let's fill in some of the fields;
/* If we found it, apply the other bits, else create such a key */
if (W_ERROR_EQUAL(error, WERR_DEST_NOT_FOUND)) {
- if(W_ERROR_IS_OK(reg_key_add_name_recursive_abs(r, cmd->key))) {
- error = reg_open_key_abs(mem_ctx, r, cmd->key, &tmp);
- if(!W_ERROR_IS_OK(error)) {
- DEBUG(0, ("Error finding new key '%s' after it has been added\n", cmd->key));
- continue;
- }
- } else {
+ if(!W_ERROR_IS_OK(reg_key_add_abs(mem_ctx, r, cmd->key, 0, NULL, &tmp))) {
DEBUG(0, ("Error adding new key '%s'\n", cmd->key));
continue;
}
while (cmd->val_count) {
VAL_SPEC_LIST *val = cmd->val_spec_list;
- struct registry_value *reg_val = NULL;
if (val->type == REG_DELETE) {
- error = reg_key_get_value_by_name( mem_ctx, tmp, val->name, ®_val);
- if(W_ERROR_IS_OK(error)) {
- error = reg_del_value(reg_val);
- }
+ error = reg_del_value(tmp, val->name);
if(!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Error removing value '%s'\n", val->name));
}
* Find the key if it exists, and delete it ...
*/
- error = reg_open_key_abs(mem_ctx, r, cmd->key, &tmp);
- if(!W_ERROR_IS_OK(error)) {
- DEBUG(0, ("Unable to open key '%s'\n", cmd->key));
- continue;
- }
-
- error = reg_key_del_recursive(tmp);
+ error = reg_key_del_abs(r, cmd->key);
if(!W_ERROR_IS_OK(error)) {
DEBUG(0, ("Unable to delete key '%s'\n", cmd->key));
continue;
{
int opt;
poptContext pc;
- const char *location;
- const char *credentials = NULL;
const char *patch;
- const char *backend = "rpc";
struct registry_context *h;
+ const char *remote = NULL;
WERROR error;
struct poptOption long_options[] = {
POPT_AUTOHELP
- {"backend", 'b', POPT_ARG_STRING, &backend, 'b', "backend to use", NULL},
- {"credentials", 'c', POPT_ARG_STRING, &credentials, 'c', "credentials (user%password", NULL},
+ POPT_COMMON_CREDENTIALS
+ {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL},
POPT_TABLEEND
};
+ regpatch_init_subsystems;
if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
setup_logging(argv[0], True);
- location = poptGetArg(pc);
- if(!location) {
- poptPrintUsage(pc, stderr, 0);
- return 1;
+ if (remote) {
+ error = reg_open_remote (&h, cli_credentials_get_username(cmdline_credentials), cli_credentials_get_password(cmdline_credentials), remote);
+ } else {
+ error = reg_open_local (&h);
}
- error = reg_open(&h, backend, location, credentials);
- if(!h) {
- fprintf(stderr, "Unable to open '%s' with backend '%s'\n", location, backend);
+ if (W_ERROR_IS_OK(error)) {
+ fprintf(stderr, "Error: %s\n", win_errstr(error));
return 1;
}
-
+
patch = poptGetArg(pc);
if(!patch) patch = "/dev/stdin";
poptFreeContext(pc);
nt_apply_reg_command_file(h, patch);
- talloc_destroy(h->mem_ctx);
-
return 0;
}