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