summaryrefslogtreecommitdiff
path: root/source4/winbind/wb_samba3_cmd.c
blob: 752a368d31f0da3f33c425f4314a2a81fcabda15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* 
   Unix SMB/CIFS implementation.
   Main winbindd samba3 server routines

   Copyright (C) Stefan Metzmacher	2005
   Copyright (C) Volker Lendecke	2005

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"
#include "smbd/service_stream.h"
#include "nsswitch/winbind_nss_config.h"
#include "nsswitch/winbindd_nss.h"
#include "winbind/wb_server.h"
#include "winbind/wb_samba3_protocol.h"
#include "winbind/wb_async_helpers.h"
#include "librpc/gen_ndr/nbt.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/composite/composite.h"
#include "include/version.h"

NTSTATUS wbsrv_samba3_interface_version(struct wbsrv_samba3_call *s3call)
{
	s3call->response.result			= WINBINDD_OK;
	s3call->response.data.interface_version	= WINBIND_INTERFACE_VERSION;
	return NT_STATUS_OK;
}

NTSTATUS wbsrv_samba3_info(struct wbsrv_samba3_call *s3call)
{
	s3call->response.result			= WINBINDD_OK;
	s3call->response.data.info.winbind_separator = *lp_winbind_separator();
	WBSRV_SAMBA3_SET_STRING(s3call->response.data.info.samba_version, SAMBA_VERSION_STRING);
	return NT_STATUS_OK;
}

NTSTATUS wbsrv_samba3_domain_name(struct wbsrv_samba3_call *s3call)
{
	s3call->response.result			= WINBINDD_OK;
	WBSRV_SAMBA3_SET_STRING(s3call->response.data.domain_name, lp_workgroup());
	return NT_STATUS_OK;
}

NTSTATUS wbsrv_samba3_netbios_name(struct wbsrv_samba3_call *s3call)
{
	s3call->response.result			= WINBINDD_OK;
	WBSRV_SAMBA3_SET_STRING(s3call->response.data.netbios_name, lp_netbios_name());
	return NT_STATUS_OK;
}

NTSTATUS wbsrv_samba3_priv_pipe_dir(struct wbsrv_samba3_call *s3call)
{
	s3call->response.result			= WINBINDD_OK;
	s3call->response.extra_data		= smbd_tmp_path(s3call,
						  WINBINDD_SAMBA3_PRIVILEGED_SOCKET);
	NT_STATUS_HAVE_NO_MEMORY(s3call->response.extra_data);
	return NT_STATUS_OK;
}

NTSTATUS wbsrv_samba3_ping(struct wbsrv_samba3_call *s3call)
{
	s3call->response.result			= WINBINDD_OK;
	return NT_STATUS_OK;
}

struct check_machacc_state {
	struct wb_finddcs *io;
};

static void wbsrv_samba3_check_machacc_reply(struct composite_context *action)
{
	struct wbsrv_samba3_call *s3call =
		talloc_get_type(action->async.private_data,
				struct wbsrv_samba3_call);
	struct check_machacc_state *state =
		talloc_get_type(s3call->private_data,
				struct check_machacc_state);
	NTSTATUS status;

	status = wb_finddcs_recv(action, s3call);

	s3call->response.data.auth.nt_status = NT_STATUS_V(status);
	WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.nt_status_string, nt_errstr(status));
	WBSRV_SAMBA3_SET_STRING(s3call->response.data.auth.error_string, nt_errstr(status));
	s3call->response.data.auth.pam_error = nt_status_to_pam(status);

	if (NT_STATUS_IS_OK(status)) {
		DEBUG(10, ("Got name %s\n", state->io->out.dcs[0].name));
		s3call->response.result = WINBINDD_OK;
	} else {
		DEBUG(10, ("Got no addr: %s\n", nt_errstr(status)));
		s3call->response.result = WINBINDD_ERROR;
	}

	status = wbsrv_send_reply(s3call->call);
	if (!NT_STATUS_IS_OK(status)) {
		wbsrv_terminate_connection(s3call->call->wbconn,
					   "wbsrv_queue_reply() failed");
		return;
	}
}

NTSTATUS wbsrv_samba3_check_machacc(struct wbsrv_samba3_call *s3call)
{
	struct composite_context *resolve_req;
	struct check_machacc_state *state;

	DEBUG(5, ("check_machacc called\n"));

	state = talloc(s3call, struct check_machacc_state);
	NT_STATUS_HAVE_NO_MEMORY(state);

	state->io = talloc(s3call, struct wb_finddcs);
	NT_STATUS_HAVE_NO_MEMORY(state->io);
	s3call->private_data = state;

	state->io->in.msg_ctx = s3call->call->wbconn->conn->msg_ctx;
	state->io->in.domain = lp_workgroup();

	resolve_req = wb_finddcs_send(state->io, s3call->call->event_ctx);
	NT_STATUS_HAVE_NO_MEMORY(resolve_req);

	/* setup the callbacks */
	resolve_req->async.fn		= wbsrv_samba3_check_machacc_reply;
	resolve_req->async.private_data	= s3call;

	/* tell the caller we reply later */
	s3call->call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
	return NT_STATUS_OK;
}