20 #include <winpr/config.h>
22 #include <winpr/dsparse.h>
23 #include <winpr/assert.h>
45 #if !defined(_WIN32) || defined(_UWP)
47 DWORD DsMakeSpnW(LPCWSTR ServiceClass, LPCWSTR ServiceName, LPCWSTR InstanceName,
48 USHORT InstancePort, LPCWSTR Referrer, DWORD* pcSpnLength, LPWSTR pszSpn)
50 DWORD res = ERROR_OUTOFMEMORY;
51 char* ServiceClassA = NULL;
52 char* ServiceNameA = NULL;
53 char* InstanceNameA = NULL;
54 char* ReferrerA = NULL;
58 WINPR_ASSERT(ServiceClass);
59 WINPR_ASSERT(ServiceName);
60 WINPR_ASSERT(pcSpnLength);
62 length = *pcSpnLength;
63 if ((length > 0) && pszSpn)
64 pszSpnA = calloc(length + 1,
sizeof(
char));
68 ServiceClassA = ConvertWCharToUtf8Alloc(ServiceClass, NULL);
74 ServiceNameA = ConvertWCharToUtf8Alloc(ServiceName, NULL);
80 InstanceNameA = ConvertWCharToUtf8Alloc(InstanceName, NULL);
86 ReferrerA = ConvertWCharToUtf8Alloc(Referrer, NULL);
90 res = DsMakeSpnA(ServiceClassA, ServiceNameA, InstanceNameA, InstancePort, ReferrerA,
91 pcSpnLength, pszSpnA);
93 if (res == ERROR_SUCCESS)
95 if (ConvertUtf8NToWChar(pszSpnA, *pcSpnLength, pszSpn, length) < 0)
96 res = ERROR_OUTOFMEMORY;
108 DWORD DsMakeSpnA(LPCSTR ServiceClass, LPCSTR ServiceName, LPCSTR InstanceName, USHORT InstancePort,
109 LPCSTR Referrer, DWORD* pcSpnLength, LPSTR pszSpn)
112 DWORD ServiceClassLength = 0;
113 DWORD ServiceNameLength = 0;
115 WINPR_ASSERT(ServiceClass);
116 WINPR_ASSERT(ServiceName);
117 WINPR_ASSERT(pcSpnLength);
119 WINPR_UNUSED(InstanceName);
120 WINPR_UNUSED(InstancePort);
121 WINPR_UNUSED(Referrer);
123 if ((*pcSpnLength != 0) && (pszSpn == NULL))
124 return ERROR_INVALID_PARAMETER;
126 ServiceClassLength = (DWORD)strlen(ServiceClass);
127 ServiceNameLength = (DWORD)strlen(ServiceName);
129 SpnLength = ServiceClassLength + 1 + ServiceNameLength + 1;
131 if ((*pcSpnLength == 0) || (*pcSpnLength < SpnLength))
133 *pcSpnLength = SpnLength;
134 return ERROR_BUFFER_OVERFLOW;
137 (void)sprintf_s(pszSpn, *pcSpnLength,
"%s/%s", ServiceClass, ServiceName);
139 return ERROR_SUCCESS;