1 package org.metricshub.wmi.wbem;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import com.sun.jna.Memory;
24 import com.sun.jna.Native;
25 import com.sun.jna.Pointer;
26 import com.sun.jna.Structure;
27
28
29
30
31
32
33 @Structure.FieldOrder({ "user", "userLength", "domain", "domainLength", "password", "passwordLength", "flags" })
34 public class CoAuthIdentity extends Structure {
35
36 public Pointer user;
37 public int userLength;
38 public Pointer domain;
39 public int domainLength;
40 public Pointer password;
41 public int passwordLength;
42 public int flags;
43
44
45
46
47
48
49 public CoAuthIdentity(final String username, final char[] password) {
50 String domain = null;
51 String user = username;
52
53
54
55 final int backslashIndex = username.indexOf('\\');
56 if (backslashIndex > -1) {
57 domain = username.substring(0, backslashIndex);
58 user = username.substring(backslashIndex + 1);
59 } else {
60 final int atIndex = username.indexOf('@');
61 if (atIndex > -1) {
62 user = username.substring(0, atIndex);
63 domain = username.substring(atIndex + 1);
64 }
65 }
66
67
68 this.user = new Memory(Native.WCHAR_SIZE * (user.length() + 1L));
69 this.user.setWideString(0, user);
70 this.userLength = user.length();
71
72
73 if (domain != null) {
74 this.domain = new Memory(Native.WCHAR_SIZE * (domain.length() + 1L));
75 this.domain.setWideString(0, domain);
76 this.domainLength = domain.length();
77 } else {
78 this.domain = null;
79 this.domainLength = 0;
80 }
81
82
83
84
85 if (password != null) {
86 this.password = new Memory(Native.WCHAR_SIZE * (password.length + 1L));
87 this.password.setWideString(0, String.valueOf(password));
88 this.passwordLength = password.length;
89 } else {
90 this.password = null;
91 this.passwordLength = 0;
92 }
93
94
95 this.flags = 0x2;
96 }
97 }