2 Unix SMB/Netbios implementation.
5 Copyright (C) Tim Potter 2000,
6 Copyright (C) Andrew Tridgell 1992-1997,2000,
7 Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
8 Copyright (C) Paul Ashton 1997,2000,
9 Copyright (C) Elrond 2000.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /* Opens a SMB connection to the SAMR pipe */
30 struct cli_state *cli_samr_initialise(struct cli_state *cli, char *system_name,
31 struct ntuser_creds *creds)
33 struct in_addr dest_ip;
34 struct nmb_name calling, called;
36 extern pstring global_myname;
37 struct ntuser_creds anon;
39 /* Initialise cli_state information */
41 if (!cli_initialise(cli)) {
47 anon.pwd.null_pwd = 1;
51 cli_init_creds(cli, creds);
53 /* Establish a SMB connection */
55 if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
59 make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
60 make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
62 if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
63 &called, "IPC$", "IPC", False, True)) {
67 /* Open a NT session thingy */
69 if (!cli_nt_session_open(cli, PIPE_SAMR)) {
77 /* Shut down a SMB connection to the SAMR pipe */
79 void cli_samr_shutdown(struct cli_state *cli)
81 if (cli->fd != -1) cli_ulogoff(cli);
85 /* Connect to SAMR database */
87 uint32 cli_samr_connect(struct cli_state *cli, char *srv_name,
88 uint32 access_mask, POLICY_HND *connect_pol)
90 prs_struct qbuf, rbuf;
98 /* Initialise parse structures */
100 prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
101 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
103 /* Marshall data and send request */
105 init_samr_q_connect(&q, srv_name, access_mask);
107 if (!samr_io_q_connect("", &q, &qbuf, 0) ||
108 !rpc_api_pipe_req(cli, SAMR_CONNECT, &qbuf, &rbuf)) {
109 result = NT_STATUS_UNSUCCESSFUL;
113 /* Unmarshall response */
115 if (!samr_io_r_connect("", &r, &rbuf, 0)) {
116 result = NT_STATUS_UNSUCCESSFUL;
120 /* Return output parameters */
122 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
123 *connect_pol = r.connect_pol;
133 /* Close SAMR handle */
135 uint32 cli_samr_close(struct cli_state *cli, POLICY_HND *connect_pol)
137 prs_struct qbuf, rbuf;
145 /* Initialise parse structures */
147 prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
148 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
150 /* Marshall data and send request */
152 init_samr_q_close_hnd(&q, connect_pol);
154 if (!samr_io_q_close_hnd("", &q, &qbuf, 0) ||
155 !rpc_api_pipe_req(cli, SAMR_CLOSE_HND, &qbuf, &rbuf)) {
156 result = NT_STATUS_UNSUCCESSFUL;
160 /* Unmarshall response */
162 if (!samr_io_r_close_hnd("", &r, &rbuf, 0)) {
163 result = NT_STATUS_UNSUCCESSFUL;
167 /* Return output parameters */
169 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
170 *connect_pol = r.pol;
180 /* Open handle on a domain */
182 uint32 cli_samr_open_domain(struct cli_state *cli, POLICY_HND *connect_pol,
183 uint32 access_mask, DOM_SID *domain_sid,
184 POLICY_HND *domain_pol)
186 prs_struct qbuf, rbuf;
187 SAMR_Q_OPEN_DOMAIN q;
188 SAMR_R_OPEN_DOMAIN r;
194 /* Initialise parse structures */
196 prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
197 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
199 /* Marshall data and send request */
201 init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
203 if (!samr_io_q_open_domain("", &q, &qbuf, 0) ||
204 !rpc_api_pipe_req(cli, SAMR_OPEN_DOMAIN, &qbuf, &rbuf)) {
205 result = NT_STATUS_UNSUCCESSFUL;
209 /* Unmarshall response */
211 if (!samr_io_r_open_domain("", &r, &rbuf, 0)) {
212 result = NT_STATUS_UNSUCCESSFUL;
216 /* Return output parameters */
218 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
219 *domain_pol = r.domain_pol;
229 /* Open handle on a user */
231 uint32 cli_samr_open_user(struct cli_state *cli, POLICY_HND *domain_pol,
232 uint32 access_mask, uint32 user_rid,
233 POLICY_HND *user_pol)
235 prs_struct qbuf, rbuf;
243 /* Initialise parse structures */
245 prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
246 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
248 /* Marshall data and send request */
250 init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
252 if (!samr_io_q_open_user("", &q, &qbuf, 0) ||
253 !rpc_api_pipe_req(cli, SAMR_OPEN_USER, &qbuf, &rbuf)) {
254 result = NT_STATUS_UNSUCCESSFUL;
258 /* Unmarshall response */
260 if (!samr_io_r_open_user("", &r, &rbuf, 0)) {
261 result = NT_STATUS_UNSUCCESSFUL;
265 /* Return output parameters */
267 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
268 *user_pol = r.user_pol;
278 /* Open handle on a group */
280 uint32 cli_samr_open_group(struct cli_state *cli, POLICY_HND *domain_pol,
281 uint32 access_mask, uint32 group_rid,
282 POLICY_HND *group_pol)
284 prs_struct qbuf, rbuf;
292 /* Initialise parse structures */
294 prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
295 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
297 /* Marshall data and send request */
299 init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
301 if (!samr_io_q_open_group("", &q, &qbuf, 0) ||
302 !rpc_api_pipe_req(cli, SAMR_OPEN_GROUP, &qbuf, &rbuf)) {
303 result = NT_STATUS_UNSUCCESSFUL;
307 /* Unmarshall response */
309 if (!samr_io_r_open_group("", &r, &rbuf, 0)) {
310 result = NT_STATUS_UNSUCCESSFUL;
314 /* Return output parameters */
316 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
327 /* Query user info */
329 uint32 cli_samr_query_userinfo(struct cli_state *cli, POLICY_HND *user_pol,
330 uint16 switch_value, SAM_USERINFO_CTR *ctr)
332 prs_struct qbuf, rbuf;
333 SAMR_Q_QUERY_USERINFO q;
334 SAMR_R_QUERY_USERINFO r;
340 /* Initialise parse structures */
342 prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
343 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
345 /* Marshall data and send request */
347 init_samr_q_query_userinfo(&q, user_pol, switch_value);
349 if (!samr_io_q_query_userinfo("", &q, &qbuf, 0) ||
350 !rpc_api_pipe_req(cli, SAMR_QUERY_USERINFO, &qbuf, &rbuf)) {
351 result = NT_STATUS_UNSUCCESSFUL;
355 /* Unmarshall response */
359 if (!samr_io_r_query_userinfo("", &r, &rbuf, 0)) {
360 result = NT_STATUS_UNSUCCESSFUL;
364 /* Return output parameters */
375 /* Query group info */
377 uint32 cli_samr_query_groupinfo(struct cli_state *cli, POLICY_HND *group_pol,
378 uint32 info_level, GROUP_INFO_CTR *ctr)
380 prs_struct qbuf, rbuf;
381 SAMR_Q_QUERY_GROUPINFO q;
382 SAMR_R_QUERY_GROUPINFO r;
388 /* Initialise parse structures */
390 prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
391 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
393 /* Marshall data and send request */
395 init_samr_q_query_groupinfo(&q, group_pol, info_level);
397 if (!samr_io_q_query_groupinfo("", &q, &qbuf, 0) ||
398 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPINFO, &qbuf, &rbuf)) {
399 result = NT_STATUS_UNSUCCESSFUL;
403 /* Unmarshall response */
407 if (!samr_io_r_query_groupinfo("", &r, &rbuf, 0)) {
408 result = NT_STATUS_UNSUCCESSFUL;
412 /* Return output parameters */
423 /* Query user groups */
425 uint32 cli_samr_query_usergroups(struct cli_state *cli, POLICY_HND *user_pol,
426 uint32 *num_groups, DOM_GID **gid)
428 prs_struct qbuf, rbuf;
429 SAMR_Q_QUERY_USERGROUPS q;
430 SAMR_R_QUERY_USERGROUPS r;
436 /* Initialise parse structures */
438 prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
439 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
441 /* Marshall data and send request */
443 init_samr_q_query_usergroups(&q, user_pol);
445 if (!samr_io_q_query_usergroups("", &q, &qbuf, 0) ||
446 !rpc_api_pipe_req(cli, SAMR_QUERY_USERGROUPS, &qbuf, &rbuf)) {
447 result = NT_STATUS_UNSUCCESSFUL;
451 /* Unmarshall response */
453 if (!samr_io_r_query_usergroups("", &r, &rbuf, 0)) {
454 result = NT_STATUS_UNSUCCESSFUL;
458 /* Return output parameters */
460 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
461 *num_groups = r.num_entries;
472 /* Query user groups */
474 uint32 cli_samr_query_groupmem(struct cli_state *cli, POLICY_HND *group_pol,
475 uint32 *num_mem, uint32 **rid, uint32 **attr)
477 prs_struct qbuf, rbuf;
478 SAMR_Q_QUERY_GROUPMEM q;
479 SAMR_R_QUERY_GROUPMEM r;
485 /* Initialise parse structures */
487 prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
488 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
490 /* Marshall data and send request */
492 init_samr_q_query_groupmem(&q, group_pol);
494 if (!samr_io_q_query_groupmem("", &q, &qbuf, 0) ||
495 !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPMEM, &qbuf, &rbuf)) {
496 result = NT_STATUS_UNSUCCESSFUL;
500 /* Unmarshall response */
502 if (!samr_io_r_query_groupmem("", &r, &rbuf, 0)) {
503 result = NT_STATUS_UNSUCCESSFUL;
507 /* Return output parameters */
509 if ((result = r.status) == NT_STATUS_NOPROBLEMO) {
510 *num_mem = r.num_entries;