1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

Added some msdfs client routines.

This commit is contained in:
Tim Potter 0001-01-01 00:00:00 +00:00
parent bdb9714380
commit 13df2304b3
4 changed files with 1159 additions and 600 deletions

File diff suppressed because it is too large Load Diff

View File

@ -77,3 +77,225 @@ void cli_dfs_shutdown(struct cli_state *cli)
if (cli->fd != -1) cli_ulogoff(cli);
cli_shutdown(cli);
}
/* Query DFS support */
uint32 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;
uint32 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 == 1);
result = NT_STATUS_NOPROBLEMO;
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}
uint32 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;
uint32 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 */
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}
uint32 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;
uint32 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 = r.status;
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}
uint32 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;
uint32 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 = r.status;
*ctr = r.ctr;
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}
/* Enumerate dfs shares */
uint32 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;
uint32 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 = r.status;
done:
prs_mem_free(&qbuf);
prs_mem_free(&rbuf);
return result;
}

View File

@ -28,6 +28,15 @@
extern int DEBUGLEVEL;
/*******************************************************************
Make a DFS_Q_DFS_QUERY structure
*******************************************************************/
void init_dfs_q_dfs_exist(DFS_Q_DFS_EXIST *q_d)
{
q_d->dummy = 0;
}
/*************************************************************
Read/write a DFS_Q_DFS_EXIST structure - dummy...
************************************************************/
@ -67,10 +76,10 @@ BOOL dfs_io_r_dfs_exist(char *desc, DFS_R_DFS_EXIST *q_d, prs_struct *ps, int de
Make a DFS_Q_DFS_REMOVE structure
*******************************************************************/
BOOL make_dfs_q_dfs_remove(DFS_Q_DFS_REMOVE *q_d, char *entrypath,
BOOL init_dfs_q_dfs_remove(DFS_Q_DFS_REMOVE *q_d, char *entrypath,
char *servername, char *sharename)
{
DEBUG(5,("make_dfs_q_dfs_remove\n"));
DEBUG(5,("init_dfs_q_dfs_remove\n"));
init_unistr2(&q_d->DfsEntryPath, entrypath, strlen(entrypath)+1);
init_unistr2(&q_d->ServerName, servername, strlen(servername)+1);
init_unistr2(&q_d->ShareName, sharename, strlen(sharename)+1);
@ -140,10 +149,10 @@ BOOL dfs_io_r_dfs_remove(char *desc, DFS_R_DFS_REMOVE *r_d, prs_struct *ps, int
Make a DFS_Q_DFS_ADD structure
*******************************************************************/
BOOL make_dfs_q_dfs_add(DFS_Q_DFS_ADD *q_d, char *entrypath, char *servername,
BOOL init_dfs_q_dfs_add(DFS_Q_DFS_ADD *q_d, char *entrypath, char *servername,
char *sharename, char *comment, uint32 flags)
{
DEBUG(5,("make_dfs_q_dfs_add\n"));
DEBUG(5,("init_dfs_q_dfs_add\n"));
q_d->ptr_DfsEntryPath = q_d->ptr_ServerName = q_d->ptr_ShareName = 1;
init_unistr2(&q_d->DfsEntryPath, entrypath, strlen(entrypath)+1);
init_unistr2(&q_d->ServerName, servername, strlen(servername)+1);
@ -222,6 +231,19 @@ BOOL dfs_io_r_dfs_add(char *desc, DFS_R_DFS_ADD *r_d, prs_struct *ps, int depth)
return True;
}
BOOL init_dfs_q_dfs_get_info(DFS_Q_DFS_GET_INFO *q_d, char *entrypath,
char *servername, char *sharename,
uint32 info_level)
{
DEBUG(5,("init_dfs_q2_get_info\n"));
init_unistr2(&q_d->uni_path, entrypath, strlen(entrypath)+1);
init_unistr2(&q_d->uni_server, servername, strlen(servername)+1);
init_unistr2(&q_d->uni_share, sharename, strlen(sharename)+1);
q_d->level = info_level;
q_d->ptr_server = q_d->ptr_share = 1;
return True;
}
/************************************************************
Read/write a DFS_Q_GET_INFO structure
************************************************************/
@ -286,7 +308,7 @@ BOOL dfs_io_r_dfs_get_info(char* desc, DFS_R_DFS_GET_INFO* r_i, prs_struct* ps,
/************************************************************
Make a DFS_Q_DFS_ENUM structure
************************************************************/
BOOL make_dfs_q_dfs_enum(DFS_Q_DFS_ENUM *q_d, uint32 level, DFS_INFO_CTR *ctr)
BOOL init_dfs_q_dfs_enum(DFS_Q_DFS_ENUM *q_d, uint32 level, DFS_INFO_CTR *ctr)
{
q_d->level = level;
q_d->maxpreflen = -1;

View File

@ -25,8 +25,299 @@
extern int DEBUGLEVEL;
extern pstring server;
/* Check DFS is supported by the remote server */
static uint32 cmd_dfs_exist(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
BOOL dfs_exists;
uint32 result;
if (argc != 1) {
printf("Usage: %s\n", argv[0]);
return 0;
}
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_exist: talloc_init failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
return NT_STATUS_UNSUCCESSFUL;
}
result = cli_dfs_exist(cli, mem_ctx, &dfs_exists);
if (result == NT_STATUS_NOPROBLEMO)
printf("dfs is %spresent\n", dfs_exists ? "" : "not ");
cli_nt_session_close(cli);
return result;
}
static uint32 cmd_dfs_add(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
uint32 result;
char *entrypath, *servername, *sharename, *comment;
uint32 flags = 0;
if (argc != 5) {
printf("Usage: %s entrypath servername sharename comment\n",
argv[0]);
return 0;
}
entrypath = argv[1];
servername = argv[2];
sharename = argv[3];
comment = argv[4];
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_add: talloc_init failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
return NT_STATUS_UNSUCCESSFUL;
}
result = cli_dfs_add(cli, mem_ctx, entrypath, servername,
sharename, comment, flags);
cli_nt_session_close(cli);
return result;
}
static uint32 cmd_dfs_remove(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
uint32 result;
char *entrypath, *servername, *sharename;
if (argc != 4) {
printf("Usage: %s entrypath servername sharename\n", argv[0]);
return 0;
}
entrypath = argv[1];
servername = argv[2];
sharename = argv[3];
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_remove: talloc_init failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
return NT_STATUS_UNSUCCESSFUL;
}
result = cli_dfs_remove(cli, mem_ctx, entrypath, servername,
sharename);
cli_nt_session_close(cli);
return result;
}
/* Display a DFS_INFO_1 structure */
static void display_dfs_info_1(DFS_INFO_1 *info1)
{
fstring temp;
unistr2_to_ascii(temp, &info1->entrypath, sizeof(temp) - 1);
printf("entrypath: %s\n", temp);
}
/* Display a DFS_INFO_2 structure */
static void display_dfs_info_2(DFS_INFO_2 *info2)
{
fstring temp;
unistr2_to_ascii(temp, &info2->entrypath, sizeof(temp) - 1);
printf("entrypath: %s\n", temp);
unistr2_to_ascii(temp, &info2->comment, sizeof(temp) - 1);
printf("\tcomment: %s\n", temp);
printf("\tstate: %d\n", info2->state);
printf("\tnum_storages: %d\n", info2->num_storages);
}
/* Display a DFS_INFO_3 structure */
static void display_dfs_info_3(DFS_INFO_3 *info3)
{
fstring temp;
int i;
unistr2_to_ascii(temp, &info3->entrypath, sizeof(temp) - 1);
printf("entrypath: %s\n", temp);
unistr2_to_ascii(temp, &info3->comment, sizeof(temp) - 1);
printf("\tcomment: %s\n", temp);
printf("\tstate: %d\n", info3->state);
printf("\tnum_storages: %d\n", info3->num_storages);
for (i = 0; i < info3->num_storages; i++) {
DFS_STORAGE_INFO *dsi = &info3->storages[i];
unistr2_to_ascii(temp, &dsi->servername, sizeof(temp) - 1);
printf("\t\tstorage[%d] servername: %s\n", i, temp);
unistr2_to_ascii(temp, &dsi->sharename, sizeof(temp) - 1);
printf("\t\tstorage[%d] sharename: %s\n", i, temp);
}
}
/* Display a DFS_INFO_CTR structure */
static void display_dfs_info_ctr(DFS_INFO_CTR *ctr)
{
int i;
for (i = 0; i < ctr->num_entries; i++) {
switch (ctr->switch_value) {
case 0x01:
display_dfs_info_1(&ctr->dfs.info1[i]);
break;
case 0x02:
display_dfs_info_2(&ctr->dfs.info2[i]);
break;
case 0x03:
display_dfs_info_3(&ctr->dfs.info3[i]);
break;
default:
printf("unsupported info level %d\n",
ctr->switch_value);
break;
}
}
}
/* Enumerate dfs shares */
static uint32 cmd_dfs_enum(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
DFS_INFO_CTR ctr;
uint32 result, info_level = 1;
if (argc > 2) {
printf("Usage: %s [info_level]\n", argv[0]);
return 0;
}
if (argc == 2)
info_level = atoi(argv[1]);
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_enum: talloc_init failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Call RPC function */
if ((result = cli_dfs_enum(cli, mem_ctx, info_level, &ctr))
!= NT_STATUS_NOPROBLEMO) {
goto done;
}
/* Print results */
display_dfs_info_ctr(&ctr);
done:
cli_nt_session_close(cli);
return result;
}
static uint32 cmd_dfs_getinfo(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
uint32 result;
char *entrypath, *servername, *sharename;
uint32 info_level = 1;
DFS_INFO_CTR ctr;
if (argc < 4 || argc > 5) {
printf("Usage: %s entrypath servername sharename [info_level]\n", argv[0]);
return 0;
}
entrypath = argv[1];
servername = argv[2];
sharename = argv[3];
if (argc == 5)
info_level = atoi(argv[4]);
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_getinfo: talloc_init failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Call RPC function */
if ((result = cli_dfs_get_info(cli, mem_ctx, entrypath, servername,
sharename, info_level, &ctr))
!= NT_STATUS_NOPROBLEMO) {
goto done;
}
/* Print results */
display_dfs_info_ctr(&ctr);
done:
cli_nt_session_close(cli);
return result;
}
/* List of commands exported by this module */
struct cmd_set dfs_commands[] = {
{ "DFS", NULL, "" },
{ "dfsexist", cmd_dfs_exist, "Query DFS support" },
{ "dfsadd", cmd_dfs_add, "Add a DFS share" },
{ "dfsremove", cmd_dfs_remove, "Remove a DFS share" },
{ "dfsgetinfo", cmd_dfs_getinfo, "Query DFS share info" },
{ "dfsenum", cmd_dfs_enum, "Enumerate dfs shares" },
{ NULL, NULL, NULL }
};