summaryrefslogtreecommitdiff
path: root/source/rpc_server/srv_pipe_noauth.c
blob: e998a0874add29dcfef4f3fc466b9ab6142a7c54 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

/* 
 *  Unix SMB/Netbios implementation.
 *  Version 1.9.
 *  RPC Pipe client / server routines
 *  Copyright (C) Andrew Tridgell              1992-2000,
 *  Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
 *  Copyright (C) Paul Ashton                  1997-2000.
 *  
 *  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 "rpc_parse.h"
#include "nterr.h"

extern int DEBUGLEVEL;


/*******************************************************************
turns a DCE/RPC request into a DCE/RPC reply
********************************************************************/
static BOOL api_noauth_create_pdu(rpcsrv_struct * l, uint32 data_start,
				  prs_struct * resp)
{
	BOOL ret;
	uint32 data_len;
	uint32 frag_len;
	uint32 data_end = l->rdata.offset;
	prs_struct rhdr;
	prs_struct rdata_i;
	RPC_HDR_RESP hdr_resp;
	uint8 flags = 0x0;
	uint32 call_id = l->hdr.call_id;

	DEBUG(5,
	      ("create_noauth_reply: data_start: %d data_end: %d max_tsize: %d\n",
	       data_start, data_end, l->hdr_ba.bba.max_tsize));

	if (l->hdr.auth_len != 0)
	{
		return False;
	}

	prs_init(&rhdr, 0, 4, False);

	/* set up rpc header (fragmentation issues) */
	if (data_start == 0)
	{
		flags = RPC_FLG_FIRST;
	}
	else
	{
		flags = 0;
	}

	hdr_resp.alloc_hint = data_end - data_start;	/* calculate remaining data to be sent */
	hdr_resp.cancel_count = 0x0;
	hdr_resp.context_id = 0x0;
	hdr_resp.reserved = 0x0;

	DEBUG(10, ("alloc_hint: %d\n", hdr_resp.alloc_hint));

	if (hdr_resp.alloc_hint + 0x18 <= l->hdr_ba.bba.max_tsize)
	{
		flags |= RPC_FLG_LAST;
		frag_len = hdr_resp.alloc_hint + 0x18;
	}
	else
	{
		frag_len = l->hdr_ba.bba.max_tsize;
	}

	data_len = frag_len - 0x18;

	rhdr.start = 0;
	rhdr.end = 0x18;

	if (!make_rpc_hdr(&l->hdr, RPC_RESPONSE, flags, call_id, frag_len, 0))
	{
		return False;
	}

	DEBUG(10, ("hdr flags: %x\n", flags));

	/* store the header in the data stream */
	smb_io_rpc_hdr("rhdr", &(l->hdr), &(rhdr), 0);
	smb_io_rpc_hdr_resp("resp", &(hdr_resp), &(rhdr), 0);

	/* don't use rdata: use rdata_i instead, which moves... */
	/* make a pointer to the rdata data, NOT A COPY */

	prs_create(&rdata_i, prs_data(&l->rdata, data_start),
		   data_len, l->rdata.align, rdata_i.io);
	rdata_i.offset = data_len;
	l->rdata_offset += data_len;

	prs_debug_out(&rdata_i, "rdata_i", 200);
	prs_debug_out(&l->rdata, "rdata", 200);

	prs_link(NULL, &rhdr, &rdata_i);
	prs_link(&rhdr, &rdata_i, NULL);

	prs_init(resp, 0, 4, False);
	ret = prs_copy(resp, &rhdr);

	prs_free_data(&rhdr);

	return ret;
}

static BOOL api_noauth_auth_gen(rpcsrv_struct * l, prs_struct * resp,
				enum RPC_PKT_TYPE pkt_type)
{
	prs_struct rhdr;
	BOOL ret;

	DEBUG(10, ("api_noauth_auth_gen\n"));

	prs_init(&rhdr, 0, 4, False);

	make_rpc_hdr(&l->hdr, pkt_type, RPC_FLG_FIRST | RPC_FLG_LAST,
		     l->hdr.call_id, l->rdata.offset + 0x10, 0);

	smb_io_rpc_hdr("", &l->hdr, &rhdr, 0);
	prs_realloc_data(&rhdr, l->rdata.offset);

	/***/
	/*** link rpc header and bind acknowledgment ***/
	/***/

	prs_link(NULL, &rhdr, &l->rdata);
	prs_link(&rhdr, &l->rdata, NULL);

	prs_init(resp, 0, 4, False);
	ret = prs_copy(resp, &rhdr);

	prs_free_data(&l->rdata);
	prs_free_data(&rhdr);

	return ret;
}

static BOOL api_noauth_auth_chk(rpcsrv_struct * l, enum RPC_PKT_TYPE pkt_type)
{
	l->auth_validated = True;

	return True;
}

static BOOL api_noauth_decode_pdu(rpcsrv_struct * l)
{
	return True;
}

srv_auth_fns noauth_fns = {
	NULL,
	api_noauth_auth_chk,
	api_noauth_auth_gen,
	api_noauth_decode_pdu,
	api_noauth_create_pdu,
};