summaryrefslogtreecommitdiffstats
path: root/source/rpc_server/srv_reg.c
blob: 3f9cdc20f49c79e0690ab4214571c889d1beed26 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

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

extern int DEBUGLEVEL;


/*******************************************************************
 reg_reply_unknown_1
 ********************************************************************/
static void reg_reply_close(REG_Q_CLOSE *q_r,
				prs_struct *rdata)
{
	REG_R_CLOSE r_u;

	/* set up the REG unknown_1 response */
	bzero(r_u.pol.data, POL_HND_SIZE);

	/* close the policy handle */
	if (close_lsa_policy_hnd(&(q_r->pol)))
	{
		r_u.status = 0;
	}
	else
	{
		r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_INVALID;
	}

	DEBUG(5,("reg_unknown_1: %d\n", __LINE__));

	/* store the response in the SMB stream */
	reg_io_r_close("", &r_u, rdata, 0);

	DEBUG(5,("reg_unknown_1: %d\n", __LINE__));
}

/*******************************************************************
 api_reg_close
 ********************************************************************/
static void api_reg_close( int uid, prs_struct *data,
                                    prs_struct *rdata )
{
	REG_Q_CLOSE q_r;

	/* grab the reg unknown 1 */
	reg_io_q_close("", &q_r, data, 0);

	/* construct reply.  always indicate success */
	reg_reply_close(&q_r, rdata);
}


/*******************************************************************
 reg_reply_open
 ********************************************************************/
static void reg_reply_open(REG_Q_OPEN_POLICY *q_r,
				prs_struct *rdata)
{
	REG_R_OPEN_POLICY r_u;

	r_u.status = 0x0;
	/* get a (unique) handle.  open a policy on it. */
	if (r_u.status == 0x0 && !open_lsa_policy_hnd(&(r_u.pol)))
	{
		r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
	}

	DEBUG(5,("reg_open: %d\n", __LINE__));

	/* store the response in the SMB stream */
	reg_io_r_open_policy("", &r_u, rdata, 0);

	DEBUG(5,("reg_open: %d\n", __LINE__));
}

/*******************************************************************
 api_reg_open
 ********************************************************************/
static void api_reg_open( int uid, prs_struct *data,
                                    prs_struct *rdata )
{
	REG_Q_OPEN_POLICY q_u;

	/* grab the reg open */
	reg_io_q_open_policy("", &q_u, data, 0);

	/* construct reply.  always indicate success */
	reg_reply_open(&q_u, rdata);
}


/*******************************************************************
 reg_reply_open_entry
 ********************************************************************/
static void reg_reply_open_entry(REG_Q_OPEN_ENTRY *q_u,
				prs_struct *rdata)
{
	uint32 status     = 0;
	POLICY_HND pol;
	REG_R_OPEN_ENTRY r_u;
	fstring name;

	DEBUG(5,("reg_open_entry: %d\n", __LINE__));

	if (status == 0 && find_lsa_policy_by_hnd(&(q_u->pol)) == -1)
	{
		status = 0xC000000 | NT_STATUS_INVALID_HANDLE;
	}

	if (status == 0x0 && !open_lsa_policy_hnd(&pol))
	{
		status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
	}

	fstrcpy(name, unistrn2(q_u->uni_name.buffer, q_u->uni_name.uni_str_len));

	if (status == 0x0)
	{
		DEBUG(5,("reg_open_entry: %s\n", name));
		/* lkcl XXXX do a check on the name, here */
	}

	if (status == 0x0 && !set_lsa_policy_reg_name(&pol, name))
	{
		status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
	}

	make_reg_r_open_entry(&r_u, &pol, status);

	/* store the response in the SMB stream */
	reg_io_r_open_entry("", &r_u, rdata, 0);

	DEBUG(5,("reg_open_entry: %d\n", __LINE__));
}

/*******************************************************************
 api_reg_open_entry
 ********************************************************************/
static void api_reg_open_entry( int uid, prs_struct *data,
                                    prs_struct *rdata )
{
	REG_Q_OPEN_ENTRY q_u;

	/* grab the reg open entry */
	reg_io_q_open_entry("", &q_u, data, 0);

	/* construct reply. */
	reg_reply_open_entry(&q_u, rdata);
}


/*******************************************************************
 reg_reply_info
 ********************************************************************/
static void reg_reply_info(REG_Q_INFO *q_u,
				prs_struct *rdata)
{
	uint32 status     = 0;

	REG_R_INFO r_u;

	DEBUG(5,("reg_info: %d\n", __LINE__));

	if (status == 0 && find_lsa_policy_by_hnd(&(q_u->pol)) == -1)
	{
		status = 0xC000000 | NT_STATUS_INVALID_HANDLE;
	}

	if (status == 0)
	{
	}

	make_reg_r_info(&r_u, 1, "LanmanNT", 0x12, 0x12, status);

	/* store the response in the SMB stream */
	reg_io_r_info("", &r_u, rdata, 0);

	DEBUG(5,("reg_open_entry: %d\n", __LINE__));
}

/*******************************************************************
 api_reg_info
 ********************************************************************/
static void api_reg_info( int uid, prs_struct *data,
                                    prs_struct *rdata )
{
	REG_Q_INFO q_u;

	/* grab the reg unknown 0x11*/
	reg_io_q_info("", &q_u, data, 0);

	/* construct reply.  always indicate success */
	reg_reply_info(&q_u, rdata);
}


/*******************************************************************
 array of \PIPE\reg operations
 ********************************************************************/
static struct api_struct api_reg_cmds[] =
{
	{ "REG_CLOSE"        , REG_CLOSE        , api_reg_close        },
	{ "REG_OPEN_ENTRY"   , REG_OPEN_ENTRY   , api_reg_open_entry   },
	{ "REG_OPEN"         , REG_OPEN_POLICY  , api_reg_open         },
	{ "REG_INFO"         , REG_INFO         , api_reg_info         },
    { NULL,		           0                , NULL                 }
};

/*******************************************************************
 receives a reg pipe and responds.
 ********************************************************************/
BOOL api_reg_rpc(pipes_struct *p, prs_struct *data)
{
	return api_rpcTNP(p, "api_reg_rpc", api_reg_cmds, data);
}