Esempio n. 1
0
_PUBLIC_ NTSTATUS auth_check_password(struct auth_context *auth_ctx,
			     TALLOC_CTX *mem_ctx,
			     const struct auth_usersupplied_info *user_info, 
			     struct auth_user_info_dc **user_info_dc)
{
	struct tevent_req *subreq;
	struct tevent_context *ev;
	bool ok;
	NTSTATUS status;

	/*TODO: create a new event context here! */
	ev = auth_ctx->event_ctx;

	subreq = auth_check_password_send(mem_ctx,
					  ev,
					  auth_ctx,
					  user_info);
	if (subreq == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	ok = tevent_req_poll(subreq, ev);
	if (!ok) {
		return NT_STATUS_INTERNAL_ERROR;
	}

	status = auth_check_password_recv(subreq, mem_ctx, user_info_dc);
	TALLOC_FREE(subreq);

	return status;
}
Esempio n. 2
0
/**
* @brief open a socket
*
* @param pss a struct sockaddr_storage defining the address to connect to
* @param port to connect to
* @param timeout in MILLISECONDS
* @param pfd file descriptor returned
*
* @return NTSTATUS code
*/
NTSTATUS open_socket_out(const struct sockaddr_storage *pss, uint16_t port,
			 int timeout, int *pfd)
{
	TALLOC_CTX *frame = talloc_stackframe();
	struct event_context *ev;
	struct tevent_req *req;
	NTSTATUS status = NT_STATUS_NO_MEMORY;

	ev = event_context_init(frame);
	if (ev == NULL) {
		goto fail;
	}

	req = open_socket_out_send(frame, ev, pss, port, timeout);
	if (req == NULL) {
		goto fail;
	}
	if (!tevent_req_poll(req, ev)) {
		status = NT_STATUS_INTERNAL_ERROR;
		goto fail;
	}
	status = open_socket_out_recv(req, pfd);
 fail:
	TALLOC_FREE(frame);
	return status;
}
Esempio n. 3
0
NTSTATUS cli_trans(TALLOC_CTX *mem_ctx, struct cli_state *cli,
		   uint8_t trans_cmd,
		   const char *pipe_name, uint16_t fid, uint16_t function,
		   int flags,
		   uint16_t *setup, uint8_t num_setup, uint8_t max_setup,
		   uint8_t *param, uint32_t num_param, uint32_t max_param,
		   uint8_t *data, uint32_t num_data, uint32_t max_data,
		   uint16_t **rsetup, uint8_t *num_rsetup,
		   uint8_t **rparam, uint32_t *num_rparam,
		   uint8_t **rdata, uint32_t *num_rdata)
{
	TALLOC_CTX *frame = talloc_stackframe();
	struct event_context *ev;
	struct tevent_req *req;
	NTSTATUS status = NT_STATUS_OK;

	if (cli_has_async_calls(cli)) {
		/*
		 * Can't use sync call while an async call is in flight
		 */
		status = NT_STATUS_INVALID_PARAMETER;
		goto fail;
	}

	ev = event_context_init(frame);
	if (ev == NULL) {
		status = NT_STATUS_NO_MEMORY;
		goto fail;
	}

	req = cli_trans_send(frame, ev, cli, trans_cmd,
			     pipe_name, fid, function, flags,
			     setup, num_setup, max_setup,
			     param, num_param, max_param,
			     data, num_data, max_data);
	if (req == NULL) {
		status = NT_STATUS_NO_MEMORY;
		goto fail;
	}

	if (!tevent_req_poll(req, ev)) {
		status = map_nt_error_from_unix(errno);
		goto fail;
	}

	status = cli_trans_recv(req, mem_ctx, rsetup, num_rsetup,
				rparam, num_rparam, rdata, num_rdata);
 fail:
	TALLOC_FREE(frame);
	if (!NT_STATUS_IS_OK(status)) {
		cli_set_error(cli, status);
	}
	return status;
}
Esempio n. 4
0
static bool smbd_notifyd_init(struct messaging_context *msg, bool interactive)
{
	struct tevent_context *ev = messaging_tevent_context(msg);
	struct tevent_req *req;
	pid_t pid;
	NTSTATUS status;

	if (interactive) {
		req = notifyd_req(msg, ev);
		return (req != NULL);
	}

	pid = fork();
	if (pid == -1) {
		DEBUG(1, ("%s: fork failed: %s\n", __func__,
			  strerror(errno)));
		return false;
	}

	if (pid != 0) {
		return true;
	}

	status = reinit_after_fork(msg, ev, true, "smbd-notifyd");
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1, ("%s: reinit_after_fork failed: %s\n",
			  __func__, nt_errstr(status)));
		exit(1);
	}

	req = notifyd_req(msg, ev);
	if (req == NULL) {
		exit(1);
	}
	tevent_req_set_callback(req, notifyd_stopped, msg);
	return tevent_req_poll(req, ev);
}
Esempio n. 5
0
NTSTATUS smb1cli_trans(TALLOC_CTX *mem_ctx, struct smbXcli_conn *conn,
		uint8_t trans_cmd,
		uint8_t additional_flags, uint8_t clear_flags,
		uint16_t additional_flags2, uint16_t clear_flags2,
		uint32_t timeout_msec,
		uint32_t pid, uint16_t tid, uint16_t uid,
		const char *pipe_name, uint16_t fid, uint16_t function,
		int flags,
		uint16_t *setup, uint8_t num_setup, uint8_t max_setup,
		uint8_t *param, uint32_t num_param, uint32_t max_param,
		uint8_t *data, uint32_t num_data, uint32_t max_data,
		uint16_t *recv_flags2,
		uint16_t **rsetup, uint8_t min_rsetup, uint8_t *num_rsetup,
		uint8_t **rparam, uint32_t min_rparam, uint32_t *num_rparam,
		uint8_t **rdata, uint32_t min_rdata, uint32_t *num_rdata)
{
	TALLOC_CTX *frame = talloc_stackframe();
	struct tevent_context *ev;
	struct tevent_req *req;
	NTSTATUS status = NT_STATUS_OK;

	if (smbXcli_conn_has_async_calls(conn)) {
		/*
		 * Can't use sync call while an async call is in flight
		 */
		status = NT_STATUS_INVALID_PARAMETER_MIX;
		goto fail;
	}

	ev = tevent_context_init(frame);
	if (ev == NULL) {
		status = NT_STATUS_NO_MEMORY;
		goto fail;
	}

	req = smb1cli_trans_send(frame, ev, conn, trans_cmd,
				 additional_flags, clear_flags,
				 additional_flags2, clear_flags2,
				 timeout_msec,
				 pid, tid, uid,
				 pipe_name, fid, function, flags,
				 setup, num_setup, max_setup,
				 param, num_param, max_param,
				 data, num_data, max_data);
	if (req == NULL) {
		status = NT_STATUS_NO_MEMORY;
		goto fail;
	}

	if (!tevent_req_poll(req, ev)) {
		status = map_nt_error_from_unix_common(errno);
		goto fail;
	}

	status = smb1cli_trans_recv(req, mem_ctx, recv_flags2,
				    rsetup, min_rsetup, num_rsetup,
				    rparam, min_rparam, num_rparam,
				    rdata, min_rdata, num_rdata);
 fail:
	TALLOC_FREE(frame);
	return status;
}
Esempio n. 6
0
bool run_dbwrap_watch1(int dummy)
{
	struct tevent_context *ev = NULL;
	struct messaging_context *msg = NULL;
	struct db_context *db = NULL;
	const char *keystr = "key";
	TDB_DATA key = string_term_tdb_data(keystr);
	struct db_record *rec = NULL;
	struct tevent_req *req = NULL;
	NTSTATUS status;
	bool ret = false;

	ev = tevent_context_init(talloc_tos());
	if (ev == NULL) {
		fprintf(stderr, "tevent_context_init failed\n");
		goto fail;
	}
	msg = messaging_init(ev, ev);
	if (msg == NULL) {
		fprintf(stderr, "messaging_init failed\n");
		goto fail;
	}
	db = db_open(msg, "test_watch.tdb", 0, TDB_DEFAULT,
		     O_CREAT|O_RDWR, 0644, DBWRAP_LOCK_ORDER_1);
	if (db == NULL) {
		fprintf(stderr, "db_open failed: %s\n", strerror(errno));
		goto fail;
	}
	dbwrap_watch_db(db, msg);
	rec = dbwrap_fetch_locked(db, db, key);
	if (rec == NULL) {
		fprintf(stderr, "dbwrap_fetch_locked failed\n");
		goto fail;
	}
	req = dbwrap_record_watch_send(talloc_tos(), ev, rec, msg);
	if (req == NULL) {
		fprintf(stderr, "dbwrap_record_watch_send failed\n");
		goto fail;
	}
	TALLOC_FREE(rec);

	status = dbwrap_store_int32(db, keystr, 1);
	if (!NT_STATUS_IS_OK(status)) {
		fprintf(stderr, "dbwrap_store_int32 failed: %s\n",
			nt_errstr(status));
		goto fail;
	}

	if (!tevent_req_poll(req, ev)) {
		fprintf(stderr, "tevent_req_poll failed\n");
		goto fail;
	}

	status = dbwrap_record_watch_recv(req, talloc_tos(), &rec);
	if (!NT_STATUS_IS_OK(status)) {
		fprintf(stderr, "dbwrap_record_watch_recv failed: %s\n",
			nt_errstr(status));
		goto fail;
	}

	ret = true;
fail:
	TALLOC_FREE(req);
	TALLOC_FREE(rec);
	TALLOC_FREE(db);
	TALLOC_FREE(msg);
	TALLOC_FREE(ev);
	return ret;
}
Esempio n. 7
0
static WERROR ask_forwarder(struct dns_server *dns,
			    TALLOC_CTX *mem_ctx,
			    struct dns_name_question *question,
			    struct dns_res_rec **answers, uint16_t *ancount,
			    struct dns_res_rec **nsrecs, uint16_t *nscount,
			    struct dns_res_rec **additional, uint16_t *arcount)
{
	struct tevent_context *ev = tevent_context_init(mem_ctx);
	struct dns_name_packet *out_packet, *in_packet;
	uint16_t id = random();
	DATA_BLOB out, in;
	enum ndr_err_code ndr_err;
	WERROR werr = WERR_OK;
	struct tevent_req *req;
	const char *forwarder = lpcfg_dns_forwarder(dns->task->lp_ctx);

	if (!is_ipaddress(forwarder)) {
		DEBUG(0, ("Invalid 'dns forwarder' setting '%s', needs to be "
			  "an IP address\n", forwarder));
		return DNS_ERR(NAME_ERROR);
	}

	out_packet = talloc_zero(mem_ctx, struct dns_name_packet);
	W_ERROR_HAVE_NO_MEMORY(out_packet);

	out_packet->id = id;
	out_packet->operation |= DNS_OPCODE_QUERY | DNS_FLAG_RECURSION_DESIRED;

	out_packet->qdcount = 1;
	out_packet->questions = question;

	ndr_err = ndr_push_struct_blob(&out, mem_ctx, out_packet,
			(ndr_push_flags_fn_t)ndr_push_dns_name_packet);
	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		return DNS_ERR(SERVER_FAILURE);
	}

	req = dns_udp_request_send(mem_ctx, ev, forwarder, out.data, out.length);
	W_ERROR_HAVE_NO_MEMORY(req);

	if(!tevent_req_poll(req, ev)) {
		return DNS_ERR(SERVER_FAILURE);
	}

	werr = dns_udp_request_recv(req, mem_ctx, &in.data, &in.length);
	W_ERROR_NOT_OK_RETURN(werr);

	in_packet = talloc_zero(mem_ctx, struct dns_name_packet);
	W_ERROR_HAVE_NO_MEMORY(in_packet);

	ndr_err = ndr_pull_struct_blob(&in, in_packet, in_packet,
			(ndr_pull_flags_fn_t)ndr_pull_dns_name_packet);
	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		return DNS_ERR(SERVER_FAILURE);
	}

	if (in_packet->id != id) {
		DEBUG(0, ("DNS packet id mismatch: 0x%0x, expected 0x%0x\n",
			  in_packet->id, id));
		return DNS_ERR(NAME_ERROR);
	}

	*ancount = in_packet->ancount;
	*answers = talloc_move(mem_ctx, &in_packet->answers);

	*nscount = in_packet->nscount;
	*nsrecs = talloc_move(mem_ctx, &in_packet->nsrecs);

	*arcount = in_packet->arcount;
	*additional = talloc_move(mem_ctx, &in_packet->additional);

	return werr;
}
Esempio n. 8
0
int main(int argc, char **argv)
{
	TALLOC_CTX *mem_ctx = talloc_init("samba-dig");
	struct tevent_context *ev;
	struct dns_name_packet *dns_packet, *in_packet;
	struct dns_name_question *question;
	enum dns_qtype type;
	enum ndr_err_code ndr_err;
	struct tevent_req *req;
	WERROR w_err;
	DATA_BLOB out, in;
	int ret = 0;

	if (argc < 4) {
		usage();
		exit(1);
	}

	ev = tevent_context_init(mem_ctx);
	setup_logging("samba-dig", DEBUG_STDERR);
	debug_parse_levels("1");

	DEBUG(1,("Querying %s for %s %s\n", argv[1], argv[2], argv[3]));

	dns_packet = make_name_packet(mem_ctx, DNS_OPCODE_QUERY);

	type = parse_qtype(argv[3]);
	if (type == -1) {
		DEBUG(0, ("Invalid DNS_QTYPE %s\n", argv[3]));
		ret = 1;
		goto error;
	}

	question = make_question(dns_packet, argv[2], type);

	dns_packet->qdcount = 1;
	dns_packet->questions = question;
	NDR_PRINT_DEBUG(dns_name_packet, dns_packet);

	ndr_err = ndr_push_struct_blob(&out, mem_ctx, dns_packet,
			(ndr_push_flags_fn_t)ndr_push_dns_name_packet);
	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		DEBUG(0, ("Failed to marshall dns_name_packet: %d\n", ndr_err));
		ret = 1;
		goto error;
	}

	req = dns_udp_request_send(mem_ctx, ev, argv[1], out.data, out.length);
	if (req == NULL) {
		DEBUG(0, ("Failed to allocate memory for tevent_req\n"));
		ret = 1;
		goto error;
	}
	if (!tevent_req_poll(req, ev)) {
		DEBUG(0, ("Error sending dns request\n"));
		ret = 1;
		goto error;
	}
	w_err = dns_udp_request_recv(req, mem_ctx, &in.data, &in.length);
	if (!W_ERROR_IS_OK(w_err)) {
		DEBUG(0, ("Error receiving dns request: %s\n", win_errstr(w_err)));
		ret = 1;
		goto error;
	}

	in_packet = talloc(mem_ctx, struct dns_name_packet);

	ndr_err = ndr_pull_struct_blob(&in, in_packet, in_packet,
			(ndr_pull_flags_fn_t)ndr_pull_dns_name_packet);
	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		DEBUG(0, ("Failed to unmarshall dns_name_packet: %d\n", ndr_err));
		ret = 1;
		goto error;
	}

	NDR_PRINT_DEBUG(dns_name_packet, in_packet);

error:
	talloc_free(mem_ctx);
	return ret;
}
static bool fdpass2_child(int ready_fd)
{
	struct tevent_context *ev = NULL;
	struct messaging_context *msg_ctx = NULL;
	TALLOC_CTX *frame = talloc_stackframe();
	bool retval = false;
	uint8_t c = 1;
	struct tevent_req *subreq;
	int ret;
	ssize_t bytes;
	int up_fd, down_fd;
	struct messaging_rec *rec;
	bool ok;

	ev = samba_tevent_context_init(frame);
	if (ev == NULL) {
		fprintf(stderr, "child: tevent_context_init failed\n");
		goto done;
	}

	msg_ctx = messaging_init(ev, ev);
	if (msg_ctx == NULL) {
		fprintf(stderr, "child: messaging_init failed\n");
		goto done;
	}

	/* Tell the parent we are ready to receive mesages. */
	bytes = write(ready_fd, &c, 1);
	if (bytes != 1) {
		perror("child: failed to write to ready_fd");
		goto done;
	}

	subreq = messaging_filtered_read_send(frame, /* TALLOC_CTX */
					      ev, msg_ctx,
					      fdpass2_filter, NULL);
	if (subreq == NULL) {
		fprintf(stderr, "child: messaging_filtered_read_send failed\n");
		goto done;
	}

	ok = tevent_req_poll(subreq, ev);
	if (!ok) {
		fprintf(stderr, "child: tevent_req_poll failed\n");
		goto done;
	}

	ret = messaging_filtered_read_recv(subreq, frame, &rec);
	TALLOC_FREE(subreq);
	if (ret != 0) {
		fprintf(stderr, "child: messaging_filtered_read_recv failed\n");
		goto done;
	}

	SMB_ASSERT(rec->num_fds == 2);

	/* Tell the parent we are done. */
	bytes = write(ready_fd, &c, 1);
	if (bytes != 1) {
		perror("child: failed to write to ready_fd");
		goto done;
	}

	up_fd = rec->fds[0];
	down_fd = rec->fds[1];

	bytes = read(up_fd, &c, 1);
	if (bytes != 1) {
		perror("child: read from up_fd failed");
		goto done;
	}

	bytes = write(down_fd, &c, 1);
	if (bytes != 1) {
		perror("child: write to down_fd failed");
	}

	printf("child: done\n");

	retval = true;

done:
	TALLOC_FREE(frame);
	return retval;
}