diff options
author | Jeremy Allison <jra@samba.org> | 2006-07-11 18:01:26 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:19:14 -0500 |
commit | fbdcf2663b56007a438ac4f0d8d82436b1bfe688 (patch) | |
tree | 4e42c1f061391cea3d640152fd240682cbf4fd9a /source3/rpc_client | |
parent | 5bf62a0c3cc95abe918f3e772bb10e0a90fdce22 (diff) | |
download | samba-fbdcf2663b56007a438ac4f0d8d82436b1bfe688.tar.gz samba-fbdcf2663b56007a438ac4f0d8d82436b1bfe688.tar.bz2 samba-fbdcf2663b56007a438ac4f0d8d82436b1bfe688.zip |
r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
to do the upper layer directories but this is what
everyone is waiting for....
Jeremy.
(This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8)
Diffstat (limited to 'source3/rpc_client')
-rw-r--r-- | source3/rpc_client/cli_lsarpc.c | 38 | ||||
-rw-r--r-- | source3/rpc_client/cli_srvsvc.c | 29 | ||||
-rw-r--r-- | source3/rpc_client/cli_unixinfo.c | 226 | ||||
-rw-r--r-- | source3/rpc_client/ndr.c | 90 |
4 files changed, 350 insertions, 33 deletions
diff --git a/source3/rpc_client/cli_lsarpc.c b/source3/rpc_client/cli_lsarpc.c index 97d8eb621b..7e29332ef9 100644 --- a/source3/rpc_client/cli_lsarpc.c +++ b/source3/rpc_client/cli_lsarpc.c @@ -1284,43 +1284,43 @@ done: BOOL fetch_domain_sid( char *domain, char *remote_machine, DOM_SID *psid) { extern pstring global_myname; - struct cli_state cli; + struct cli_state *cli; NTSTATUS result; POLICY_HND lsa_pol; BOOL ret = False; ZERO_STRUCT(cli); - if(cli_initialise(&cli) == False) { + if((cli = cli_initialise()) == NULL) { DEBUG(0,("fetch_domain_sid: unable to initialize client connection.\n")); return False; } - if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) { + if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) { DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine)); goto done; } - if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) { + if (!cli_connect(cli, remote_machine, &cli->dest_ip)) { DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \ -machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) )); +machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) )); goto done; } - if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) { + if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) { DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS session request.\n", remote_machine)); goto done; } - cli.protocol = PROTOCOL_NT1; + cli->protocol = PROTOCOL_NT1; - if (!cli_negprot(&cli)) { + if (!cli_negprot(cli)) { DEBUG(0,("fetch_domain_sid: machine %s rejected the negotiate protocol. \ -Error was : %s.\n", remote_machine, cli_errstr(&cli) )); +Error was : %s.\n", remote_machine, cli_errstr(cli) )); goto done; } - if (cli.protocol != PROTOCOL_NT1) { + if (cli->protocol != PROTOCOL_NT1) { DEBUG(0,("fetch_domain_sid: machine %s didn't negotiate NT protocol.\n", remote_machine)); goto done; @@ -1330,39 +1330,39 @@ Error was : %s.\n", remote_machine, cli_errstr(&cli) )); * Do an anonymous session setup. */ - if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) { + if (!cli_session_setup(cli, "", "", 0, "", 0, "")) { DEBUG(0,("fetch_domain_sid: machine %s rejected the session setup. \ -Error was : %s.\n", remote_machine, cli_errstr(&cli) )); +Error was : %s.\n", remote_machine, cli_errstr(cli) )); goto done; } - if (!(cli.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) { + if (!(cli->sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) { DEBUG(0,("fetch_domain_sid: machine %s isn't in user level security mode\n", remote_machine)); goto done; } - if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { + if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) { DEBUG(0,("fetch_domain_sid: machine %s rejected the tconX on the IPC$ share. \ -Error was : %s.\n", remote_machine, cli_errstr(&cli) )); +Error was : %s.\n", remote_machine, cli_errstr(cli) )); goto done; } /* Fetch domain sid */ - if (!cli_nt_session_open(&cli, PI_LSARPC)) { + if (!cli_nt_session_open(cli, PI_LSARPC)) { DEBUG(0, ("fetch_domain_sid: Error connecting to SAM pipe\n")); goto done; } - result = cli_lsa_open_policy(&cli, cli.mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol); + result = cli_lsa_open_policy(cli, cli->mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol); if (!NT_STATUS_IS_OK(result)) { DEBUG(0, ("fetch_domain_sid: Error opening lsa policy handle. %s\n", nt_errstr(result) )); goto done; } - result = cli_lsa_query_info_policy(&cli, cli.mem_ctx, &lsa_pol, 5, domain, psid); + result = cli_lsa_query_info_policy(cli, cli->mem_ctx, &lsa_pol, 5, domain, psid); if (!NT_STATUS_IS_OK(result)) { DEBUG(0, ("fetch_domain_sid: Error querying lsa policy handle. %s\n", nt_errstr(result) )); @@ -1373,7 +1373,7 @@ Error was : %s.\n", remote_machine, cli_errstr(&cli) )); done: - cli_shutdown(&cli); + cli_shutdown(cli); return ret; } diff --git a/source3/rpc_client/cli_srvsvc.c b/source3/rpc_client/cli_srvsvc.c index 0d50e94d57..7b4818b4b0 100644 --- a/source3/rpc_client/cli_srvsvc.c +++ b/source3/rpc_client/cli_srvsvc.c @@ -5,6 +5,8 @@ Copyright (C) Tim Potter 2001 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002 Copyright (C) Jeremy Allison 2005. + Copyright (C) Gerald (Jerry) Carter 2006. + 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 @@ -537,38 +539,37 @@ WERROR rpccli_srvsvc_net_file_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ ZERO_STRUCTP(ctr); - ctr->switch_value = file_level; + ctr->level = file_level; ctr->num_entries = ctr->num_entries2 = r.ctr.num_entries; switch(file_level) { case 3: - ctr->file.info3 = TALLOC_ARRAY(mem_ctx, SRV_FILE_INFO_3, ctr->num_entries); - if (ctr->file.info3 == NULL) { + if ( (ctr->file.info3 = TALLOC_ARRAY(mem_ctx, FILE_INFO_3, ctr->num_entries)) == NULL ) { return WERR_NOMEM; } - memset(ctr->file.info3, 0, - sizeof(SRV_FILE_INFO_3) * ctr->num_entries); + memset(ctr->file.info3, 0, sizeof(FILE_INFO_3) * ctr->num_entries); for (i = 0; i < r.ctr.num_entries; i++) { - SRV_FILE_INFO_3 *info3 = &ctr->file.info3[i]; + FILE_INFO_3 *info3 = &ctr->file.info3[i]; char *s; /* Copy pointer crap */ - memcpy(&info3->info_3, &r.ctr.file.info3[i].info_3, - sizeof(FILE_INFO_3)); + memcpy(info3, &r.ctr.file.info3[i], sizeof(FILE_INFO_3)); /* Duplicate strings */ - s = unistr2_tdup(mem_ctx, &r.ctr.file.info3[i].info_3_str.uni_path_name); - if (s) - init_unistr2(&info3->info_3_str.uni_path_name, s, UNI_STR_TERMINATE); + if ( (s = unistr2_tdup(mem_ctx, r.ctr.file.info3[i].path)) != NULL ) { + info3->path = TALLOC_P( mem_ctx, UNISTR2 ); + init_unistr2(info3->path, s, UNI_STR_TERMINATE); + } - s = unistr2_tdup(mem_ctx, &r.ctr.file.info3[i].info_3_str.uni_user_name); - if (s) - init_unistr2(&info3->info_3_str.uni_user_name, s, UNI_STR_TERMINATE); + if ( (s = unistr2_tdup(mem_ctx, r.ctr.file.info3[i].user)) != NULL ) { + info3->user = TALLOC_P( mem_ctx, UNISTR2 ); + init_unistr2(info3->user, s, UNI_STR_TERMINATE); + } } diff --git a/source3/rpc_client/cli_unixinfo.c b/source3/rpc_client/cli_unixinfo.c new file mode 100644 index 0000000000..b9a960dfd1 --- /dev/null +++ b/source3/rpc_client/cli_unixinfo.c @@ -0,0 +1,226 @@ +/* + Unix SMB/CIFS implementation. + + RPC pipe client + + 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" + +NTSTATUS rpccli_unixinfo_uid2sid(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, uid_t uid, DOM_SID *sid) +{ + prs_struct qbuf, rbuf; + UNIXINFO_Q_UID_TO_SID q; + UNIXINFO_R_UID_TO_SID r; + NTSTATUS result = NT_STATUS_NET_WRITE_FAULT; + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + /* Marshall data and send request */ + { + UINT64_S uid64; + uid64.high = 0; + uid64.low = uid; + init_q_unixinfo_uid_to_sid(&q, uid64); + } + + CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_UID_TO_SID, + q, r, + qbuf, rbuf, + unixinfo_io_q_unixinfo_uid_to_sid, + unixinfo_io_r_unixinfo_uid_to_sid, + NT_STATUS_NET_WRITE_FAULT); + + if (NT_STATUS_IS_OK(r.status) && (sid != NULL)) { + sid_copy(sid, &r.sid); + } + + result = r.status; + return result; +} + +NTSTATUS rpccli_unixinfo_sid2uid(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + const DOM_SID *sid, uid_t *uid) +{ + prs_struct qbuf, rbuf; + UNIXINFO_Q_SID_TO_UID q; + UNIXINFO_R_SID_TO_UID r; + NTSTATUS result = NT_STATUS_NET_WRITE_FAULT; + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + /* Marshall data and send request */ + init_q_unixinfo_sid_to_uid(&q, sid); + + CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_SID_TO_UID, + q, r, + qbuf, rbuf, + unixinfo_io_q_unixinfo_sid_to_uid, + unixinfo_io_r_unixinfo_sid_to_uid, + NT_STATUS_NET_WRITE_FAULT); + + if (NT_STATUS_IS_OK(r.status)) { + if (r.uid.high != 0) { + /* 64-Bit uid's not yet handled */ + return NT_STATUS_INVALID_PARAMETER; + } + if (uid != NULL) { + *uid = r.uid.low; + } + } + + result = r.status; + return result; +} + +NTSTATUS rpccli_unixinfo_gid2sid(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, gid_t gid, DOM_SID *sid) +{ + prs_struct qbuf, rbuf; + UNIXINFO_Q_GID_TO_SID q; + UNIXINFO_R_GID_TO_SID r; + NTSTATUS result = NT_STATUS_NET_WRITE_FAULT; + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + /* Marshall data and send request */ + { + UINT64_S gid64; + gid64.high = 0; + gid64.low = gid; + init_q_unixinfo_gid_to_sid(&q, gid64); + } + + CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_GID_TO_SID, + q, r, + qbuf, rbuf, + unixinfo_io_q_unixinfo_gid_to_sid, + unixinfo_io_r_unixinfo_gid_to_sid, + NT_STATUS_NET_WRITE_FAULT); + + if (NT_STATUS_IS_OK(r.status) && (sid != NULL)) { + sid_copy(sid, &r.sid); + } + + result = r.status; + return result; +} + +NTSTATUS rpccli_unixinfo_sid2gid(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + const DOM_SID *sid, gid_t *gid) +{ + prs_struct qbuf, rbuf; + UNIXINFO_Q_SID_TO_GID q; + UNIXINFO_R_SID_TO_GID r; + NTSTATUS result = NT_STATUS_NET_WRITE_FAULT; + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + /* Marshall data and send request */ + init_q_unixinfo_sid_to_gid(&q, sid); + + CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_SID_TO_GID, + q, r, + qbuf, rbuf, + unixinfo_io_q_unixinfo_sid_to_gid, + unixinfo_io_r_unixinfo_sid_to_gid, + NT_STATUS_NET_WRITE_FAULT); + + if (NT_STATUS_IS_OK(r.status)) { + if (r.gid.high != 0) { + /* 64-Bit gid's not yet handled */ + return NT_STATUS_INVALID_PARAMETER; + } + if (gid != NULL) { + *gid = r.gid.low; + } + } + + result = r.status; + return result; +} + +NTSTATUS rpccli_unixinfo_getpwuid(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + int count, uid_t *uids, + struct unixinfo_getpwuid **info) +{ + prs_struct qbuf, rbuf; + UNIXINFO_Q_GETPWUID q; + UNIXINFO_R_GETPWUID r; + NTSTATUS result = NT_STATUS_NET_WRITE_FAULT; + int i; + UINT64_S *uids64; + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + /* Marshall data and send request */ + + uids64 = TALLOC_ARRAY(mem_ctx, UINT64_S, count); + if (uids64 == NULL) { + return NT_STATUS_NO_MEMORY; + } + + for (i=0; i<count; i++) { + uids64[i].high = 0; + uids64[i].low = uids[i]; + } + + init_q_unixinfo_getpwuid(&q, count, uids64); + + CLI_DO_RPC(cli, mem_ctx, PI_UNIXINFO, UNIXINFO_GETPWUID, + q, r, + qbuf, rbuf, + unixinfo_io_q_unixinfo_getpwuid, + unixinfo_io_r_unixinfo_getpwuid, + NT_STATUS_NET_WRITE_FAULT); + + if (!NT_STATUS_IS_OK(r.status)) { + result = r.status; + *info = NULL; + return result; + } + + if (r.count != count) { + DEBUG(0, ("Expected array size %d, got %d\n", + count, r.count)); + return NT_STATUS_INVALID_PARAMETER; + } + + *info = TALLOC_ARRAY(mem_ctx, struct unixinfo_getpwuid, count); + if (*info == NULL) { + return NT_STATUS_NO_MEMORY; + } + + for (i=0; i<count; i++) { + (*info)[i].status = r.info[i].status; + (*info)[i].homedir = talloc_strdup(mem_ctx, r.info[i].homedir); + (*info)[i].shell = talloc_strdup(mem_ctx, r.info[i].shell); + } + + result = r.status; + return result; +} diff --git a/source3/rpc_client/ndr.c b/source3/rpc_client/ndr.c new file mode 100644 index 0000000000..985490f71c --- /dev/null +++ b/source3/rpc_client/ndr.c @@ -0,0 +1,90 @@ +/* + Unix SMB/CIFS implementation. + + libndr interface + + Copyright (C) Jelmer Vernooij 2006 + + 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" + + +NTSTATUS cli_do_rpc_ndr(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, + int p_idx, int opnum, void *data, + ndr_pull_flags_fn_t pull_fn, ndr_push_flags_fn_t push_fn) +{ + prs_struct q_ps, r_ps; + struct ndr_pull *pull; + DATA_BLOB blob; + struct ndr_push *push; + NTSTATUS status; + + SMB_ASSERT(cli->pipe_idx == p_idx); + + push = ndr_push_init_ctx(mem_ctx); + if (!push) { + return NT_STATUS_NO_MEMORY; + } + + status = push_fn(push, NDR_IN, data); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + blob = ndr_push_blob(push); + + if (!prs_init_data_blob(&q_ps, &blob, mem_ctx)) { + return NT_STATUS_NO_MEMORY; + } + + talloc_free(push); + + if (!prs_init( &r_ps, 0, mem_ctx, UNMARSHALL )) { + prs_mem_free( &q_ps ); + return NT_STATUS_NO_MEMORY; + } + + status = rpc_api_pipe_req(cli, opnum, &q_ps, &r_ps); + + prs_mem_free( &q_ps ); + + if (!NT_STATUS_IS_OK(status)) { + prs_mem_free( &r_ps ); + return status; + } + + if (!prs_data_blob(&r_ps, &blob, mem_ctx)) { + prs_mem_free( &r_ps ); + return NT_STATUS_NO_MEMORY; + } + + prs_mem_free( &r_ps ); + + pull = ndr_pull_init_blob(&blob, mem_ctx); + if (pull == NULL) { + return NT_STATUS_NO_MEMORY; + } + + status = pull_fn(pull, NDR_OUT, data); + talloc_free(pull); + + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + return NT_STATUS_OK; +} |