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
|
/*
Unix SMB/CIFS implementation.
Named Pipe Echo test
Copyright (C) Jelmer Vernooij 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"
#include "librpc/gen_ndr/security.h"
#include "smb.h"
#include "torture/torture.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/libcli.h"
#define ECHODATA "Good Times, Bad Times"
int torture_np_echo(void)
{
NTSTATUS status;
TALLOC_CTX *mem_ctx = NULL;
struct smbcli_state *cli;
const char *pipe_name = "\\NPECHO";
union smb_open open;
union smb_read read;
union smb_write write;
union smb_close close;
int fnum;
BOOL ret;
ret = torture_open_connection_share(mem_ctx, &cli,
lp_parm_string(-1, "torture", "host"),
"IPC$",
NULL);
if (!ret)
return False;
open.ntcreatex.level = RAW_OPEN_NTCREATEX;
open.ntcreatex.in.flags = 0;
open.ntcreatex.in.root_fid = 0;
open.ntcreatex.in.access_mask =
SEC_STD_READ_CONTROL |
SEC_FILE_WRITE_ATTRIBUTE |
SEC_FILE_WRITE_EA |
SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA;
open.ntcreatex.in.file_attr = 0;
open.ntcreatex.in.alloc_size = 0;
open.ntcreatex.in.share_access =
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE;
open.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
open.ntcreatex.in.create_options = 0;
open.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
open.ntcreatex.in.security_flags = 0;
open.ntcreatex.in.fname = pipe_name;
status = smb_raw_open(cli->tree, cli->tree, &open);
if (NT_STATUS_IS_ERR(status))
return False;
fnum = open.ntcreatex.out.fnum;
write.write.level = RAW_WRITE_WRITE;
write.write.in.fnum = fnum;
write.write.in.count = strlen(ECHODATA);
write.write.in.offset = 0;
write.write.in.remaining = 0;
write.write.in.data = (const uint8_t *)ECHODATA;
status = smb_raw_write(cli->tree, &write);
if (NT_STATUS_IS_ERR(status))
return False;
if (write.write.out.nwritten != strlen(ECHODATA))
return False;
read.read.level = RAW_READ_READ;
read.read.in.fnum = fnum;
read.read.in.count = strlen(ECHODATA);
read.read.in.offset = 0;
read.read.in.remaining = 0;
read.read.out.data = talloc_array(mem_ctx, uint8_t, strlen(ECHODATA));
status = smb_raw_read(cli->tree, &read);
if (NT_STATUS_IS_ERR(status))
return False;
if (read.read.out.nread != strlen(ECHODATA))
return False;
if (memcmp(read.read.out.data, ECHODATA, strlen(ECHODATA)) != 0) {
printf ("np_echo: Returned data did not match!\n");
return False;
}
close.close.level = RAW_CLOSE_CLOSE;
close.close.in.fnum = fnum;
close.close.in.write_time = 0;
status = smb_raw_close(cli->tree, &close);
if (NT_STATUS_IS_ERR(status))
return False;
return True;
}
|