예제 #1
0
파일: cifsdd.c 프로젝트: 0x24bin/winexe-1
static struct dd_iohandle * open_file(struct resolve_context *resolve_ctx, 
				      struct tevent_context *ev,
				      const char * which, const char **ports,
				      struct smbcli_options *smb_options,
				      const char *socket_options,
				      struct smbcli_session_options *smb_session_options,
				      struct smb_iconv_convenience *iconv_convenience,
				      struct gensec_settings *gensec_settings)
{
	int			options = 0;
	const char *		path = NULL;
	struct dd_iohandle *	handle = NULL;

	if (check_arg_bool("direct")) {
		options |= DD_DIRECT_IO;
	}

	if (check_arg_bool("sync")) {
		options |= DD_SYNC_IO;
	}

	if (check_arg_bool("oplock")) {
		options |= DD_OPLOCK;
	}

	if (strcmp(which, "if") == 0) {
		path = check_arg_pathname("if");
		handle = dd_open_path(resolve_ctx, ev, path, ports,
				      check_arg_numeric("ibs"), options,
				      socket_options,
				      smb_options, smb_session_options,
				      iconv_convenience,
				      gensec_settings);
	} else if (strcmp(which, "of") == 0) {
		options |= DD_WRITE;
		path = check_arg_pathname("of");
		handle = dd_open_path(resolve_ctx, ev, path, ports,
				      check_arg_numeric("obs"), options,
				      socket_options,
				      smb_options, smb_session_options,
				      iconv_convenience,
				      gensec_settings);
	} else {
		SMB_ASSERT(0);
		return(NULL);
	}

	if (!handle) {
		fprintf(stderr, "%s: failed to open %s\n", PROGNAME, path);
	}

	return(handle);
}
예제 #2
0
static struct dd_iohandle * open_file(const char * which)
{
	int			options = 0;
	const char *		path = NULL;
	struct dd_iohandle *	handle = NULL;

	if (check_arg_bool("direct")) {
		options |= DD_DIRECT_IO;
	}

	if (check_arg_bool("sync")) {
		options |= DD_SYNC_IO;
	}

	if (check_arg_bool("oplock")) {
		options |= DD_OPLOCK;
	}

	if (strcmp(which, "if") == 0) {
		path = check_arg_pathname("if");
		handle = dd_open_path(path, check_arg_numeric("ibs"),
					options);
	} else if (strcmp(which, "of") == 0) {
		options |= DD_WRITE;
		path = check_arg_pathname("of");
		handle = dd_open_path(path, check_arg_numeric("obs"),
					options);
	} else {
		SMB_ASSERT(0);
		return(NULL);
	}

	if (!handle) {
		fprintf(stderr, "%s: failed to open %s\n", PROGNAME, path);
	}

	return(handle);
}
예제 #3
0
int main(int argc, const char ** argv)
{
	int i;
	const char ** dd_args;
	struct tevent_context *ev;

	poptContext pctx;
	struct poptOption poptions[] = {
		/* POPT_AUTOHELP */
		{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, cifsddHelpOptions,
			0, "Help options:", NULL },
		POPT_COMMON_SAMBA
		POPT_COMMON_CONNECTION
		POPT_COMMON_CREDENTIALS
		POPT_COMMON_VERSION
		{ NULL }
	};

	/* Block sizes. */
	set_arg_val("bs", (uint64_t)4096);
	set_arg_val("ibs", (uint64_t)4096);
	set_arg_val("obs", (uint64_t)4096);
	/* Block counts. */
	set_arg_val("count", (uint64_t)-1);
	set_arg_val("seek", (uint64_t)0);
	set_arg_val("seek", (uint64_t)0);
	/* Files. */
	set_arg_val("if", NULL);
	set_arg_val("of", NULL);
	/* Options. */
	set_arg_val("direct", false);
	set_arg_val("sync", false);
	set_arg_val("oplock", false);

	pctx = poptGetContext(PROGNAME, argc, argv, poptions, 0);
	while ((i = poptGetNextOpt(pctx)) != -1) {
		;
	}

	for (dd_args = poptGetArgs(pctx); dd_args && *dd_args; ++dd_args) {

		if (!set_arg_argv(*dd_args)) {
			fprintf(stderr, "%s: invalid option: %s\n",
					PROGNAME, *dd_args);
			exit(SYNTAX_EXIT_CODE);
		}

		/* "bs" has the side-effect of setting "ibs" and "obs". */
		if (strncmp(*dd_args, "bs=", 3) == 0) {
			uint64_t bs = check_arg_numeric("bs");
			set_arg_val("ibs", bs);
			set_arg_val("obs", bs);
		}
	}

	ev = s4_event_context_init(talloc_autofree_context());

	gensec_init(cmdline_lp_ctx);
	dump_args();

	if (check_arg_numeric("ibs") == 0 || check_arg_numeric("ibs") == 0) {
		fprintf(stderr, "%s: block sizes must be greater that zero\n",
				PROGNAME);
		exit(SYNTAX_EXIT_CODE);
	}

	if (check_arg_pathname("if") == NULL) {
		fprintf(stderr, "%s: missing input filename\n", PROGNAME);
		exit(SYNTAX_EXIT_CODE);
	}

	if (check_arg_pathname("of") == NULL) {
		fprintf(stderr, "%s: missing output filename\n", PROGNAME);
		exit(SYNTAX_EXIT_CODE);
	}

	CatchSignal(SIGINT, dd_handle_signal);
	CatchSignal(SIGUSR1, dd_handle_signal);
	return(copy_files(ev, cmdline_lp_ctx));
}