FreeRDP
Loading...
Searching...
No Matches
TestDsMakeSpn.c
1
2#include <stdio.h>
3#include <winpr/crt.h>
4#include <winpr/winpr.h>
5#include <winpr/tchar.h>
6#include <winpr/dsparse.h>
7
8static BOOL test_DsMakeSpnA(void)
9{
10 LPCSTR testServiceClass = "HTTP";
11 LPCSTR testServiceName = "LAB1-W2K8R2-GW.lab1.awake.local";
12 LPCSTR testSpn = "HTTP/LAB1-W2K8R2-GW.lab1.awake.local";
13 BOOL rc = FALSE;
14 CHAR Spn[100] = WINPR_C_ARRAY_INIT;
15 DWORD status = 0;
16 DWORD SpnLength = -1;
17
18 status =
19 DsMakeSpnA(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, nullptr);
20
21 if (status != ERROR_INVALID_PARAMETER)
22 {
23 printf("DsMakeSpnA: expected ERROR_INVALID_PARAMETER\n");
24 goto fail;
25 }
26
27 SpnLength = 0;
28 status =
29 DsMakeSpnA(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, nullptr);
30
31 if (status != ERROR_BUFFER_OVERFLOW)
32 {
33 printf("DsMakeSpnA: expected ERROR_BUFFER_OVERFLOW\n");
34 goto fail;
35 }
36
37 if (SpnLength != 37)
38 {
39 printf("DsMakeSpnA: SpnLength mismatch: Actual: %" PRIu32 ", Expected: 37\n", SpnLength);
40 goto fail;
41 }
42
43 status = DsMakeSpnA(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, Spn);
44
45 if (status != ERROR_SUCCESS)
46 {
47 printf("DsMakeSpnA: expected ERROR_SUCCESS\n");
48 goto fail;
49 }
50
51 if (strcmp(Spn, testSpn) != 0)
52 {
53 printf("DsMakeSpnA: SPN mismatch: Actual: %s, Expected: %s\n", Spn, testSpn);
54 goto fail;
55 }
56
57 printf("DsMakeSpnA: %s\n", Spn);
58 rc = TRUE;
59fail:
60 return rc;
61}
62
63static BOOL test_DsMakeSpnW(void)
64{
65 const CHAR ctestServiceClass[] = { 'H', 'T', 'T', 'P', '\0' };
66 const CHAR ctestServiceName[] = { 'L', 'A', 'B', '1', '-', 'W', '2', 'K', '8', 'R', '2',
67 '-', 'G', 'W', '.', 'l', 'a', 'b', '1', '.', 'a', 'w',
68 'a', 'k', 'e', '.', 'l', 'o', 'c', 'a', 'l', '\0' };
69 const CHAR ctestSpn[] = { 'H', 'T', 'T', 'P', '/', 'L', 'A', 'B', '1', '-', 'W', '2', 'K',
70 '8', 'R', '2', '-', 'G', 'W', '.', 'l', 'a', 'b', '1', '.', 'a',
71 'w', 'a', 'k', 'e', '.', 'l', 'o', 'c', 'a', 'l', '\0' };
72 WCHAR testServiceClass[ARRAYSIZE(ctestServiceClass)] = WINPR_C_ARRAY_INIT;
73 WCHAR testServiceName[ARRAYSIZE(ctestServiceName)] = WINPR_C_ARRAY_INIT;
74 WCHAR testSpn[ARRAYSIZE(ctestSpn)] = WINPR_C_ARRAY_INIT;
75
76 BOOL rc = FALSE;
77 WCHAR Spn[100] = WINPR_C_ARRAY_INIT;
78 DWORD status = 0;
79 DWORD SpnLength = -1;
80
81 (void)ConvertUtf8NToWChar(ctestServiceClass, ARRAYSIZE(ctestServiceClass), testServiceClass,
82 ARRAYSIZE(testServiceClass));
83 (void)ConvertUtf8NToWChar(ctestServiceName, ARRAYSIZE(ctestServiceName), testServiceName,
84 ARRAYSIZE(testServiceName));
85 (void)ConvertUtf8NToWChar(ctestSpn, ARRAYSIZE(ctestSpn), testSpn, ARRAYSIZE(testSpn));
86
87 status =
88 DsMakeSpnW(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, nullptr);
89
90 if (status != ERROR_INVALID_PARAMETER)
91 {
92 printf("DsMakeSpnW: expected ERROR_INVALID_PARAMETER\n");
93 goto fail;
94 }
95
96 SpnLength = 0;
97 status =
98 DsMakeSpnW(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, nullptr);
99
100 if (status != ERROR_BUFFER_OVERFLOW)
101 {
102 printf("DsMakeSpnW: expected ERROR_BUFFER_OVERFLOW\n");
103 goto fail;
104 }
105
106 if (SpnLength != 37)
107 {
108 printf("DsMakeSpnW: SpnLength mismatch: Actual: %" PRIu32 ", Expected: 37\n", SpnLength);
109 goto fail;
110 }
111
112 status = DsMakeSpnW(testServiceClass, testServiceName, nullptr, 0, nullptr, &SpnLength, Spn);
113
114 if (status != ERROR_SUCCESS)
115 {
116 printf("DsMakeSpnW: expected ERROR_SUCCESS\n");
117 goto fail;
118 }
119
120 if (_wcscmp(Spn, testSpn) != 0)
121 {
122 char buffer1[8192] = WINPR_C_ARRAY_INIT;
123 char buffer2[8192] = WINPR_C_ARRAY_INIT;
124 char* SpnA = buffer1;
125 char* testSpnA = buffer2;
126
127 (void)ConvertWCharToUtf8(Spn, SpnA, ARRAYSIZE(buffer1));
128 (void)ConvertWCharToUtf8(testSpn, testSpnA, ARRAYSIZE(buffer2));
129 printf("DsMakeSpnW: SPN mismatch: Actual: %s, Expected: %s\n", SpnA, testSpnA);
130 goto fail;
131 }
132
133 {
134 char buffer[8192] = WINPR_C_ARRAY_INIT;
135 char* SpnA = buffer;
136
137 (void)ConvertWCharToUtf8(Spn, SpnA, ARRAYSIZE(buffer));
138 printf("DsMakeSpnW: %s\n", SpnA);
139 }
140
141 rc = TRUE;
142fail:
143 return rc;
144}
145int TestDsMakeSpn(int argc, char* argv[])
146{
147 WINPR_UNUSED(argc);
148 WINPR_UNUSED(argv);
149
150 if (!test_DsMakeSpnA())
151 return -1;
152 if (!test_DsMakeSpnW())
153 return -2;
154 return 0;
155}