/
PipeTest.java
105 lines (86 loc) · 3.42 KB
/
PipeTest.java
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
/*tr
* © 2017 AgNO3 Gmbh & Co. KG
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package jcifs.tests;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import jcifs.dcerpc.DcerpcException;
import jcifs.dcerpc.DcerpcHandle;
import jcifs.dcerpc.msrpc.LsaPolicyHandle;
import jcifs.dcerpc.msrpc.MsrpcLookupSids;
import jcifs.dcerpc.msrpc.MsrpcShareEnum;
import jcifs.smb.SID;
/**
* @author mbechler
*
*/
@RunWith ( Parameterized.class )
@SuppressWarnings ( "javadoc" )
public class PipeTest extends BaseCIFSTest {
/**
* @param name
* @param properties
*/
public PipeTest ( String name, Map<String, String> properties ) {
super(name, properties);
}
@Parameters ( name = "{0}" )
public static Collection<Object> configs () {
return getConfigs("smb1", "noUnicode", "forceUnicode", "noNTStatus", "noNTSmbs", "smb2", "smb30", "smb31");
}
@Test
public void testSRVS () throws DcerpcException, IOException {
try ( DcerpcHandle handle = DcerpcHandle
.getHandle("ncacn_np:" + getTestServer() + "[\\PIPE\\srvsvc]", withTestNTLMCredentials(getContext())) ) {
MsrpcShareEnum rpc = new MsrpcShareEnum(handle.getServerWithDfs());
handle.sendrecv(rpc);
assertEquals(0, rpc.retval);
}
}
@Test
public void exclusiveConnection () throws IOException {
try ( DcerpcHandle handle = DcerpcHandle
.getHandle("ncacn_np:" + getTestServer() + "[\\PIPE\\srvsvc]", withTestNTLMCredentials(getContext()), true) ) {
MsrpcShareEnum rpc = new MsrpcShareEnum(handle.getServerWithDfs());
handle.sendrecv(rpc);
assertEquals(0, rpc.retval);
}
}
@Test
public void testLSA () throws DcerpcException, IOException {
try ( DcerpcHandle handle = DcerpcHandle
.getHandle("ncacn_np:" + getTestServer() + "[\\PIPE\\lsarpc]", withTestNTLMCredentials(getContext())) ) {
String server = handle.getServerWithDfs();
int dot = server.indexOf('.');
if ( dot > 0 && Character.isDigit(server.charAt(0)) == false )
server = server.substring(0, dot);
try ( LsaPolicyHandle policyHandle = new LsaPolicyHandle(handle, "\\\\" + server, 0x00000800) ) {
MsrpcLookupSids rpc = new MsrpcLookupSids(policyHandle, new SID[] {
SID.EVERYONE
});
handle.sendrecv(rpc);
assertEquals(0, rpc.retval);
}
}
}
}