[NTDSAPI] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / reactos / dll / win32 / ntdsapi / ntdsapi.c
1 /*
2 * Copyright (C) 2006 Dmitry Timoshkov
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define WIN32_NO_STATUS
20
21 #include <stdarg.h>
22
23 #include <windef.h>
24 //#include "winbase.h"
25 //#include "winerror.h"
26 #include <winuser.h>
27 #include <ntdsapi.h>
28 #include <wine/debug.h>
29 #include <wine/unicode.h>
30
31 WINE_DEFAULT_DEBUG_CHANNEL(ntdsapi);
32
33 /*****************************************************
34 * DllMain
35 */
36 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
37 {
38 TRACE("(%p, %d, %p)\n", hinst, reason, reserved);
39
40 switch(reason)
41 {
42 case DLL_WINE_PREATTACH:
43 return FALSE; /* prefer native version */
44
45 case DLL_PROCESS_ATTACH:
46 DisableThreadLibraryCalls( hinst );
47 break;
48 }
49 return TRUE;
50 }
51
52 /***********************************************************************
53 * DsBindA (NTDSAPI.@)
54 */
55 DWORD WINAPI DsBindA(LPCSTR controller, LPCSTR domain, HANDLE *handle)
56 {
57 FIXME("(%s,%s, %p): stub!\n", debugstr_a(controller), debugstr_a(domain), handle);
58 return ERROR_CALL_NOT_IMPLEMENTED;
59 }
60
61 /***********************************************************************
62 * DsBindW (NTDSAPI.@)
63 */
64 DWORD WINAPI DsBindW(LPCWSTR controller, LPCWSTR domain, HANDLE *handle)
65 {
66 FIXME("(%s,%s, %p): stub!\n", debugstr_w(controller), debugstr_w(domain), handle);
67 return ERROR_CALL_NOT_IMPLEMENTED;
68 }
69
70 /***********************************************************************
71 * DsMakeSpnW (NTDSAPI.@)
72 */
73 DWORD WINAPI DsMakeSpnW(LPCWSTR svc_class, LPCWSTR svc_name,
74 LPCWSTR inst_name, USHORT inst_port,
75 LPCWSTR ref, DWORD *spn_length, LPWSTR spn)
76 {
77 DWORD new_spn_length;
78 INT len;
79 LPWSTR p;
80
81 TRACE("(%s,%s,%s,%d,%s,%p,%p)\n", debugstr_w(svc_class),
82 debugstr_w(svc_name), debugstr_w(inst_name), inst_port,
83 debugstr_w(ref), spn_length, spn);
84
85 if (!svc_class || !svc_name)
86 return ERROR_INVALID_PARAMETER;
87
88 new_spn_length = strlenW(svc_class) + 1 /* for '/' */ + 1 /* for terminating '\0' */;
89 if (inst_name)
90 new_spn_length += strlenW(inst_name);
91 else
92 new_spn_length += strlenW(svc_name);
93 if (inst_port)
94 {
95 USHORT n = inst_port;
96 new_spn_length += 1 /* for ':' */;
97 do
98 {
99 n /= 10;
100 new_spn_length++;
101 } while (n != 0);
102 }
103 if (inst_name)
104 new_spn_length += 1 /* for '/' */ + strlenW(svc_name);
105
106 if (*spn_length < new_spn_length)
107 {
108 *spn_length = new_spn_length;
109 return ERROR_BUFFER_OVERFLOW;
110 }
111 *spn_length = new_spn_length;
112
113 p = spn;
114 len = strlenW(svc_class);
115 memcpy(p, svc_class, len * sizeof(WCHAR));
116 p += len;
117 *p = '/';
118 p++;
119 if (inst_name)
120 {
121 len = strlenW(inst_name);
122 memcpy(p, inst_name, len * sizeof(WCHAR));
123 p += len;
124 *p = '\0';
125 }
126 else
127 {
128 len = strlenW(svc_name);
129 memcpy(p, svc_name, len * sizeof(WCHAR));
130 p += len;
131 *p = '\0';
132 }
133
134 if (inst_port)
135 {
136 static const WCHAR percentU[] = {'%','u',0};
137 *p = ':';
138 p++;
139 wsprintfW(p, percentU, inst_port);
140 p += strlenW(p);
141 }
142
143 if (inst_name)
144 {
145 *p = '/';
146 p++;
147 len = strlenW(svc_name);
148 memcpy(p, svc_name, len * sizeof(WCHAR));
149 p += len;
150 *p = '\0';
151 }
152
153 TRACE("spn = %s\n", debugstr_w(spn));
154
155 return ERROR_SUCCESS;
156 }
157
158 /***********************************************************************
159 * DsMakeSpnA (NTDSAPI.@)
160 *
161 * See DsMakeSpnW.
162 */
163 DWORD WINAPI DsMakeSpnA(LPCSTR svc_class, LPCSTR svc_name,
164 LPCSTR inst_name, USHORT inst_port,
165 LPCSTR ref, DWORD *spn_length, LPSTR spn)
166 {
167 FIXME("(%s,%s,%s,%d,%s,%p,%p): stub!\n", debugstr_a(svc_class),
168 debugstr_a(svc_name), debugstr_a(inst_name), inst_port,
169 debugstr_a(ref), spn_length, spn);
170
171 return ERROR_CALL_NOT_IMPLEMENTED;
172 }
173
174 /***********************************************************************
175 * DsMakeSpnA (NTDSAPI.@)
176 */
177 DWORD WINAPI DsGetSpnA(DS_SPN_NAME_TYPE ServType, LPCSTR Servlass, LPCSTR ServName,
178 USHORT InstPort, USHORT nInstanceNames,
179 LPCSTR *pInstanceNames, const USHORT *pInstancePorts,
180 DWORD *pSpn, LPSTR **pszSpn)
181 {
182 FIXME("(%d,%s,%s,%d,%d,%p,%p,%p,%p): stub!\n", ServType,
183 debugstr_a(Servlass), debugstr_a(ServName), InstPort,
184 nInstanceNames, pInstanceNames, pInstancePorts, pSpn, pszSpn);
185
186 return ERROR_CALL_NOT_IMPLEMENTED;
187 }
188
189 /***********************************************************************
190 * DsServerRegisterSpnA (NTDSAPI.@)
191 */
192 DWORD WINAPI DsServerRegisterSpnA(DS_SPN_WRITE_OP operation, LPCSTR ServiceClass, LPCSTR UserObjectDN)
193 {
194 FIXME("(%d,%s,%s): stub!\n", operation,
195 debugstr_a(ServiceClass), debugstr_a(UserObjectDN));
196 return ERROR_CALL_NOT_IMPLEMENTED;
197 }
198
199 /***********************************************************************
200 * DsServerRegisterSpnW (NTDSAPI.@)
201 */
202 DWORD WINAPI DsServerRegisterSpnW(DS_SPN_WRITE_OP operation, LPCWSTR ServiceClass, LPCWSTR UserObjectDN)
203 {
204 FIXME("(%d,%s,%s): stub!\n", operation,
205 debugstr_w(ServiceClass), debugstr_w(UserObjectDN));
206 return ERROR_CALL_NOT_IMPLEMENTED;
207 }
208
209 DWORD WINAPI DsClientMakeSpnForTargetServerW(LPCWSTR class, LPCWSTR name, DWORD *buflen, LPWSTR buf)
210 {
211 DWORD len;
212 WCHAR *p;
213
214 TRACE("(%s,%s,%p,%p)\n", debugstr_w(class), debugstr_w(name), buflen, buf);
215
216 if (!class || !name || !buflen) return ERROR_INVALID_PARAMETER;
217
218 len = strlenW(class) + 1 + strlenW(name) + 1;
219 if (*buflen < len)
220 {
221 *buflen = len;
222 return ERROR_BUFFER_OVERFLOW;
223 }
224 *buflen = len;
225
226 memcpy(buf, class, strlenW(class) * sizeof(WCHAR));
227 p = buf + strlenW(class);
228 *p++ = '/';
229 memcpy(p, name, strlenW(name) * sizeof(WCHAR));
230 buf[len - 1] = 0;
231
232 return ERROR_SUCCESS;
233 }