xref: /reactos/dll/win32/ntdsapi/ntdsapi.c (revision 8c2e9189)
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 #include <stdarg.h>
20 
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winerror.h"
24 #include "winuser.h"
25 #include "ntdsapi.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
28 
29 WINE_DEFAULT_DEBUG_CHANNEL(ntdsapi);
30 
31 /*****************************************************
32  *      DllMain
33  */
34 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
35 {
36     TRACE("(%p, %d, %p)\n", hinst, reason, reserved);
37 
38     switch(reason)
39     {
40     case DLL_WINE_PREATTACH:
41         return FALSE;  /* prefer native version */
42 
43     case DLL_PROCESS_ATTACH:
44         DisableThreadLibraryCalls( hinst );
45         break;
46     }
47     return TRUE;
48 }
49 
50 /***********************************************************************
51  *             DsBindA (NTDSAPI.@)
52  */
53 DWORD WINAPI DsBindA(LPCSTR controller, LPCSTR domain, HANDLE *handle)
54  {
55     FIXME("(%s,%s, %p): stub!\n", debugstr_a(controller), debugstr_a(domain), handle);
56     return ERROR_CALL_NOT_IMPLEMENTED;
57 }
58 
59 /***********************************************************************
60  *             DsBindW (NTDSAPI.@)
61  */
62 DWORD WINAPI DsBindW(LPCWSTR controller, LPCWSTR domain, HANDLE *handle)
63  {
64     FIXME("(%s,%s, %p): stub!\n", debugstr_w(controller), debugstr_w(domain), handle);
65     return ERROR_CALL_NOT_IMPLEMENTED;
66 }
67 
68 /***********************************************************************
69  *             DsMakeSpnW (NTDSAPI.@)
70  */
71 DWORD WINAPI DsMakeSpnW(LPCWSTR svc_class, LPCWSTR svc_name,
72                         LPCWSTR inst_name, USHORT inst_port,
73                         LPCWSTR ref, DWORD *spn_length, LPWSTR spn)
74 {
75     DWORD new_spn_length;
76     INT len;
77     LPWSTR p;
78 
79     TRACE("(%s,%s,%s,%d,%s,%p,%p)\n", debugstr_w(svc_class),
80             debugstr_w(svc_name), debugstr_w(inst_name), inst_port,
81             debugstr_w(ref), spn_length, spn);
82 
83     if (!svc_class || !svc_name)
84         return ERROR_INVALID_PARAMETER;
85 
86     new_spn_length = strlenW(svc_class) + 1 /* for '/' */ + 1 /* for terminating '\0' */;
87     if (inst_name)
88         new_spn_length += strlenW(inst_name);
89     else
90         new_spn_length += strlenW(svc_name);
91     if (inst_port)
92     {
93         USHORT n = inst_port;
94         new_spn_length += 1 /* for ':' */;
95         do
96         {
97             n /= 10;
98             new_spn_length++;
99         } while (n != 0);
100     }
101     if (inst_name)
102         new_spn_length += 1 /* for '/' */ + strlenW(svc_name);
103 
104     if (*spn_length < new_spn_length)
105     {
106         *spn_length = new_spn_length;
107         return ERROR_BUFFER_OVERFLOW;
108     }
109     *spn_length = new_spn_length;
110 
111     p = spn;
112     len = strlenW(svc_class);
113     memcpy(p, svc_class, len * sizeof(WCHAR));
114     p += len;
115     *p = '/';
116     p++;
117     if (inst_name)
118     {
119         len = strlenW(inst_name);
120         memcpy(p, inst_name, len * sizeof(WCHAR));
121         p += len;
122         *p = '\0';
123     }
124     else
125     {
126         len = strlenW(svc_name);
127         memcpy(p, svc_name, len * sizeof(WCHAR));
128         p += len;
129         *p = '\0';
130     }
131 
132     if (inst_port)
133     {
134         static const WCHAR percentU[] = {'%','u',0};
135         *p = ':';
136         p++;
137         wsprintfW(p, percentU, inst_port);
138         p += strlenW(p);
139     }
140 
141     if (inst_name)
142     {
143         *p = '/';
144         p++;
145         len = strlenW(svc_name);
146         memcpy(p, svc_name, len * sizeof(WCHAR));
147         p += len;
148         *p = '\0';
149     }
150 
151     TRACE("spn = %s\n", debugstr_w(spn));
152 
153     return ERROR_SUCCESS;
154 }
155 
156 /***********************************************************************
157  *             DsMakeSpnA (NTDSAPI.@)
158  *
159  * See DsMakeSpnW.
160  */
161 DWORD WINAPI DsMakeSpnA(LPCSTR svc_class, LPCSTR svc_name,
162                         LPCSTR inst_name, USHORT inst_port,
163                         LPCSTR ref, DWORD *spn_length, LPSTR spn)
164 {
165     FIXME("(%s,%s,%s,%d,%s,%p,%p): stub!\n", debugstr_a(svc_class),
166             debugstr_a(svc_name), debugstr_a(inst_name), inst_port,
167             debugstr_a(ref), spn_length, spn);
168 
169     return ERROR_CALL_NOT_IMPLEMENTED;
170 }
171 
172 /***********************************************************************
173  *             DsMakeSpnA (NTDSAPI.@)
174  */
175 DWORD WINAPI DsGetSpnA(DS_SPN_NAME_TYPE ServType, LPCSTR Servlass, LPCSTR ServName,
176                        USHORT InstPort, USHORT nInstanceNames,
177                        LPCSTR *pInstanceNames, const USHORT *pInstancePorts,
178                        DWORD *pSpn, LPSTR **pszSpn)
179 {
180     FIXME("(%d,%s,%s,%d,%d,%p,%p,%p,%p): stub!\n", ServType,
181             debugstr_a(Servlass), debugstr_a(ServName), InstPort,
182             nInstanceNames, pInstanceNames, pInstancePorts, pSpn, pszSpn);
183 
184     return ERROR_CALL_NOT_IMPLEMENTED;
185 }
186 
187 /***********************************************************************
188  *             DsServerRegisterSpnA (NTDSAPI.@)
189  */
190 DWORD WINAPI DsServerRegisterSpnA(DS_SPN_WRITE_OP operation, LPCSTR ServiceClass, LPCSTR UserObjectDN)
191 {
192     FIXME("(%d,%s,%s): stub!\n", operation,
193             debugstr_a(ServiceClass), debugstr_a(UserObjectDN));
194     return ERROR_CALL_NOT_IMPLEMENTED;
195 }
196 
197 /***********************************************************************
198  *             DsServerRegisterSpnW (NTDSAPI.@)
199  */
200 DWORD WINAPI DsServerRegisterSpnW(DS_SPN_WRITE_OP operation, LPCWSTR ServiceClass, LPCWSTR UserObjectDN)
201 {
202     FIXME("(%d,%s,%s): stub!\n", operation,
203             debugstr_w(ServiceClass), debugstr_w(UserObjectDN));
204     return ERROR_CALL_NOT_IMPLEMENTED;
205 }
206 
207 DWORD WINAPI DsClientMakeSpnForTargetServerW(LPCWSTR class, LPCWSTR name, DWORD *buflen, LPWSTR buf)
208 {
209     DWORD len;
210     WCHAR *p;
211 
212     TRACE("(%s,%s,%p,%p)\n", debugstr_w(class), debugstr_w(name), buflen, buf);
213 
214     if (!class || !name || !buflen) return ERROR_INVALID_PARAMETER;
215 
216     len = strlenW(class) + 1 + strlenW(name) + 1;
217     if (*buflen < len)
218     {
219         *buflen = len;
220         return ERROR_BUFFER_OVERFLOW;
221     }
222     *buflen = len;
223 
224     memcpy(buf, class, strlenW(class) * sizeof(WCHAR));
225     p = buf + strlenW(class);
226     *p++ = '/';
227     memcpy(p, name, strlenW(name) * sizeof(WCHAR));
228     buf[len - 1] = 0;
229 
230     return ERROR_SUCCESS;
231 }
232