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