コード例 #1
0
ファイル: serverinfo.c プロジェクト: nikatshun/asuswrt-merlin
WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
		      struct NetRemoteTOD *r)
{
	NTSTATUS status;
	WERROR werr;
	struct srvsvc_NetRemoteTODInfo *info = NULL;
	struct dcerpc_binding_handle *b;

	werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
					    &ndr_table_srvsvc.syntax_id,
					    &b);
	if (!W_ERROR_IS_OK(werr)) {
		goto done;
	}

	status = dcerpc_srvsvc_NetRemoteTOD(b, talloc_tos(),
					    r->in.server_name,
					    &info,
					    &werr);
	if (!NT_STATUS_IS_OK(status)) {
		werr = ntstatus_to_werror(status);
		goto done;
	}

	if (!W_ERROR_IS_OK(werr)) {
		goto done;
	}

	*r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
			  sizeof(struct srvsvc_NetRemoteTODInfo));
	W_ERROR_HAVE_NO_MEMORY(*r->out.buffer);

 done:
	return werr;
}
コード例 #2
0
ファイル: libnet_time.c プロジェクト: 0x24bin/winexe-1
/*
 * get the remote time of a server via srvsvc_NetRemoteTOD
 */
static NTSTATUS libnet_RemoteTOD_srvsvc(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, union libnet_RemoteTOD *r)
{
        NTSTATUS status;
	struct libnet_RpcConnect c;
	struct srvsvc_NetRemoteTOD tod;
	struct srvsvc_NetRemoteTODInfo *info = NULL;
	struct tm tm;

	ZERO_STRUCT(c);

	/* prepare connect to the SRVSVC pipe of a timeserver */
	c.level             = LIBNET_RPC_CONNECT_SERVER;
	c.in.name           = r->srvsvc.in.server_name;
	c.in.dcerpc_iface   = &ndr_table_srvsvc;

	/* 1. connect to the SRVSVC pipe of a timeserver */
	status = libnet_RpcConnect(ctx, mem_ctx, &c);
	if (!NT_STATUS_IS_OK(status)) {
		r->srvsvc.out.error_string = talloc_asprintf(mem_ctx,
						"Connection to SRVSVC pipe of server '%s' failed: %s",
						r->srvsvc.in.server_name, nt_errstr(status));
		return status;
	}

	/* prepare srvsvc_NetrRemoteTOD */
	tod.in.server_unc = talloc_asprintf(mem_ctx, "\\%s", c.in.name);
	tod.out.info = &info;

	/* 2. try srvsvc_NetRemoteTOD */
	status = dcerpc_srvsvc_NetRemoteTOD(c.out.dcerpc_pipe, mem_ctx, &tod);
	if (!NT_STATUS_IS_OK(status)) {
		r->srvsvc.out.error_string = talloc_asprintf(mem_ctx,
						"srvsvc_NetrRemoteTOD on server '%s' failed: %s",
						r->srvsvc.in.server_name, nt_errstr(status));
		goto disconnect;
	}

	/* check result of srvsvc_NetrRemoteTOD */
	if (!W_ERROR_IS_OK(tod.out.result)) {
		r->srvsvc.out.error_string = talloc_asprintf(mem_ctx,
						"srvsvc_NetrRemoteTOD on server '%s' failed: %s",
						r->srvsvc.in.server_name, win_errstr(tod.out.result));
		status = werror_to_ntstatus(tod.out.result);
		goto disconnect;
	}

	/* need to set the out parameters */
	tm.tm_sec = (int)info->secs;
	tm.tm_min = (int)info->mins;
	tm.tm_hour = (int)info->hours;
	tm.tm_mday = (int)info->day;
	tm.tm_mon = (int)info->month -1;
	tm.tm_year = (int)info->year - 1900;
	tm.tm_wday = -1;
	tm.tm_yday = -1;
	tm.tm_isdst = -1;

	r->srvsvc.out.time = timegm(&tm);
	r->srvsvc.out.time_zone = info->timezone * 60;

	goto disconnect;

disconnect:
	/* close connection */
	talloc_free(c.out.dcerpc_pipe);

	return status;
}