Exemplo n.º 1
0
int main(int argc, const char **argv)
{
  	int opt;
	poptContext pc;
	const char *patch;
	struct registry_context *h;
	const char *file = NULL;
	const char *remote = NULL;
	struct tevent_context *ev_ctx;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL},
		{"file", 'F', POPT_ARG_STRING, &file, 0, "file path", NULL },
		POPT_COMMON_SAMBA
		POPT_COMMON_CREDENTIALS
		{ NULL }
	};

	pc = poptGetContext(argv[0], argc, argv, long_options,0);

	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	ev_ctx = s4_event_context_init(NULL);

	if (remote) {
		h = reg_common_open_remote (remote, ev_ctx, cmdline_lp_ctx, cmdline_credentials);
	} else {
		h = reg_common_open_local (cmdline_credentials, ev_ctx, cmdline_lp_ctx);
	}

	if (h == NULL)
		return 1;

	patch = poptGetArg(pc);
	if (patch == NULL) {
		poptPrintUsage(pc, stderr, 0);
		return 1;
	}

	poptFreeContext(pc);

	reg_diff_apply(h, patch);

	return 0;
}
Exemplo n.º 2
0
int main(int argc, const char **argv)
{
	int opt;
	unsigned int i;
	const char *file = NULL;
	const char *remote = NULL;
	poptContext pc;
	struct registry_context *h = NULL;
	struct registry_key *start_key = NULL;
	struct tevent_context *ev_ctx;
	WERROR error;
	bool fullpath = false, no_values = false;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"file", 'F', POPT_ARG_STRING, &file, 0, "file path", NULL },
		{"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL },
		{"fullpath", 'f', POPT_ARG_NONE, &fullpath, 0, "show full paths", NULL},
		{"no-values", 'V', POPT_ARG_NONE, &no_values, 0, "don't show values", NULL},
		POPT_COMMON_SAMBA
		POPT_COMMON_CREDENTIALS
		POPT_COMMON_VERSION
		{ NULL }
	};

	pc = poptGetContext(argv[0], argc, argv, long_options,0);

	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	ev_ctx = s4_event_context_init(NULL);

	if (remote != NULL) {
		h = reg_common_open_remote(remote, ev_ctx, cmdline_lp_ctx, cmdline_credentials);
	} else if (file != NULL) {
		start_key = reg_common_open_file(file, ev_ctx, cmdline_lp_ctx, cmdline_credentials);
	} else {
		h = reg_common_open_local(cmdline_credentials, ev_ctx, cmdline_lp_ctx);
	}

	if (h == NULL && start_key == NULL)
		return 1;

	poptFreeContext(pc);

	error = WERR_OK;

	if (start_key != NULL) {
		print_tree(0, start_key, "", fullpath, no_values);
	} else {
		for(i = 0; reg_predefined_keys[i].handle; i++) {
			error = reg_get_predefined_key(h,
						       reg_predefined_keys[i].handle,
						       &start_key);
			if (!W_ERROR_IS_OK(error)) {
				fprintf(stderr, "Skipping %s: %s\n",
					reg_predefined_keys[i].name,
					win_errstr(error));
				continue;
			}
			SMB_ASSERT(start_key != NULL);
			print_tree(0, start_key, reg_predefined_keys[i].name,
				   fullpath, no_values);
		}
	}

	return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	int opt;
	const char *file = NULL;
	poptContext pc;
	const char *remote = NULL;
	struct regshell_context *ctx;
	struct tevent_context *ev_ctx;
	bool ret = true;
	struct poptOption long_options[] = {
		POPT_AUTOHELP
		{"file", 'F', POPT_ARG_STRING, &file, 0, "open hive file", NULL },
		{"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL},
		POPT_COMMON_SAMBA
		POPT_COMMON_CREDENTIALS
		POPT_COMMON_VERSION
		{ NULL }
	};

	pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);

	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	ctx = talloc_zero(NULL, struct regshell_context);

	ev_ctx = s4_event_context_init(ctx);

	if (remote != NULL) {
		ctx->registry = reg_common_open_remote(remote, ev_ctx,
					 cmdline_lp_ctx, cmdline_credentials);
	} else if (file != NULL) {
		ctx->current = reg_common_open_file(file, ev_ctx, cmdline_lp_ctx, cmdline_credentials);
		if (ctx->current == NULL)
			return 1;
		ctx->registry = ctx->current->context;
		ctx->path = talloc_strdup(ctx, "");
		ctx->predef = NULL;
		ctx->root = ctx->current;
	} else {
		ctx->registry = reg_common_open_local(cmdline_credentials, ev_ctx, cmdline_lp_ctx);
	}

	if (ctx->registry == NULL)
		return 1;

	if (ctx->current == NULL) {
		unsigned int i;

		for (i = 0; (reg_predefined_keys[i].handle != 0) &&
			(ctx->current == NULL); i++) {
			WERROR err;
			err = reg_get_predefined_key(ctx->registry,
						     reg_predefined_keys[i].handle,
						     &ctx->current);
			if (W_ERROR_IS_OK(err)) {
				ctx->predef = talloc_strdup(ctx,
							  reg_predefined_keys[i].name);
				ctx->path = talloc_strdup(ctx, "");
				ctx->root = ctx->current;
				break;
			} else {
				ctx->current = NULL;
				ctx->root = NULL;
			}
		}
	}

	if (ctx->current == NULL) {
		fprintf(stderr, "Unable to access any of the predefined keys\n");
		return 1;
	}

	poptFreeContext(pc);

	while (true) {
		char *line, *prompt;

		if (asprintf(&prompt, "%s\\%s> ", ctx->predef?ctx->predef:"",
			     ctx->path) < 0) {
			ret = false;
			break;
		}

		current_key = ctx->current; 		/* No way to pass a void * pointer
							   via readline :-( */
		line = smb_readline(prompt, NULL, reg_completion);

		if (line == NULL) {
			free(prompt);
			break;
		}

		if (line[0] != '\n') {
			ret = W_ERROR_IS_OK(process_cmd(ctx, line));
		}
		free(line);
		free(prompt);
	}
	talloc_free(ctx);

	return (ret?0:1);
}