1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-13 16:23:50 +03:00
Files
samba-mirror/source/libsmb/cli_dfs.c
Andrew Bartlett fa67e4626b Given Jeremy's positive response, and a lack of one from tpot, I'll commit
this:

More code cleanup - this lot a bit more dodgy than the last:

The aim is to trim pwd_cache down to size.  Its overly complex, and a
pain to deal with.  With a header comment like this:

'obfusticaion is planned'

I think it deserved to die (at least partly).

This was being done to allow 'cli_establish_connection' to die - its
functionality has been replaced by cli_full_connection(), which does
not duplicate code everywhere for creating names etc.

This also removes the little 'init' fucntions for the various pipes,
becouse they were only used in one place, and even then it was dodgy.

(I've reworked smbcacls not to use anonymous connections any more, as
this will (should) fail with a 'restrict anonymous' PDC).

This allowed me to remove cli_pipe_util.c, which was calling
cli_establish_connection.

tpot:  I'm not sure what direction you were going with the client stuff,
and you may well have been wanting the init functions.  If thats the case,
give me a yell and I'll reimplement them against cli_full_connection.

Andrew Bartlett
-

246 lines
5.3 KiB
C

/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Tim Potter 2000-2001,
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"
/* Query DFS support */
NTSTATUS cli_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx,
BOOL *dfs_exists)
{
prs_struct qbuf, rbuf;
DFS_Q_DFS_EXIST q;
DFS_R_DFS_EXIST r;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
ZERO_STRUCT(q);
ZERO_STRUCT(r);
/* Initialise parse structures */
prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
/* Marshall data and send request */
init_dfs_q_dfs_exist(&q);
if (!dfs_io_q_dfs_exist("", &q, &qbuf, 0) ||
!rpc_api_pipe_req(cli, DFS_EXIST, &qbuf, &rbuf)) {
goto done;
}
/* Unmarshall response */
if (!dfs_io_r_dfs_exist("", &r, &rbuf, 0)) {
goto done;
}
/* Return result */
*dfs_exists = (r.status != 0);
result = NT_STATUS_OK;
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}
NTSTATUS cli_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
char *entrypath, char *servername, char *sharename,
char *comment, uint32 flags)
{
prs_struct qbuf, rbuf;
DFS_Q_DFS_ADD q;
DFS_R_DFS_ADD r;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
ZERO_STRUCT(q);
ZERO_STRUCT(r);
/* Initialise parse structures */
prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
/* Marshall data and send request */
init_dfs_q_dfs_add(&q, entrypath, servername, sharename, comment,
flags);
if (!dfs_io_q_dfs_add("", &q, &qbuf, 0) ||
!rpc_api_pipe_req(cli, DFS_ADD, &qbuf, &rbuf)) {
goto done;
}
/* Unmarshall response */
if (!dfs_io_r_dfs_add("", &r, &rbuf, 0)) {
goto done;
}
/* Return result */
result = werror_to_ntstatus(r.status);
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}
NTSTATUS cli_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
char *entrypath, char *servername, char *sharename)
{
prs_struct qbuf, rbuf;
DFS_Q_DFS_REMOVE q;
DFS_R_DFS_REMOVE r;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
ZERO_STRUCT(q);
ZERO_STRUCT(r);
/* Initialise parse structures */
prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
/* Marshall data and send request */
init_dfs_q_dfs_remove(&q, entrypath, servername, sharename);
if (!dfs_io_q_dfs_remove("", &q, &qbuf, 0) ||
!rpc_api_pipe_req(cli, DFS_REMOVE, &qbuf, &rbuf)) {
goto done;
}
/* Unmarshall response */
if (!dfs_io_r_dfs_remove("", &r, &rbuf, 0)) {
goto done;
}
/* Return result */
result = werror_to_ntstatus(r.status);
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}
NTSTATUS cli_dfs_get_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
char *entrypath, char *servername, char *sharename,
uint32 info_level, DFS_INFO_CTR *ctr)
{
prs_struct qbuf, rbuf;
DFS_Q_DFS_GET_INFO q;
DFS_R_DFS_GET_INFO r;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
ZERO_STRUCT(q);
ZERO_STRUCT(r);
/* Initialise parse structures */
prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
/* Marshall data and send request */
init_dfs_q_dfs_get_info(&q, entrypath, servername, sharename,
info_level);
if (!dfs_io_q_dfs_get_info("", &q, &qbuf, 0) ||
!rpc_api_pipe_req(cli, DFS_GET_INFO, &qbuf, &rbuf)) {
goto done;
}
/* Unmarshall response */
if (!dfs_io_r_dfs_get_info("", &r, &rbuf, 0)) {
goto done;
}
/* Return result */
result = werror_to_ntstatus(r.status);
*ctr = r.ctr;
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}
/* Enumerate dfs shares */
NTSTATUS cli_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
uint32 info_level, DFS_INFO_CTR *ctr)
{
prs_struct qbuf, rbuf;
DFS_Q_DFS_ENUM q;
DFS_R_DFS_ENUM r;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
ZERO_STRUCT(q);
ZERO_STRUCT(r);
/* Initialise parse structures */
prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
/* Marshall data and send request */
init_dfs_q_dfs_enum(&q, info_level, ctr);
if (!dfs_io_q_dfs_enum("", &q, &qbuf, 0) ||
!rpc_api_pipe_req(cli, DFS_ENUM, &qbuf, &rbuf)) {
goto done;
}
/* Unmarshall response */
r.ctr = ctr;
if (!dfs_io_r_dfs_enum("", &r, &rbuf, 0)) {
goto done;
}
/* Return result */
result = werror_to_ntstatus(r.status);
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}