riched20/tests: Avoid using flaky method of simulating typing.
[wine] / dlls / 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 #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  *             DsMakeSpnW (NTDSAPI.@)
52  */
53 DWORD WINAPI DsMakeSpnW(LPCWSTR svc_class, LPCWSTR svc_name,
54                         LPCWSTR inst_name, USHORT inst_port,
55                         LPCWSTR ref, DWORD *spn_length, LPWSTR spn)
56 {
57     DWORD new_spn_length;
58     INT len;
59     LPWSTR p;
60
61     TRACE("(%s,%s,%s,%d,%s,%p,%p)\n", debugstr_w(svc_class),
62             debugstr_w(svc_name), debugstr_w(inst_name), inst_port,
63             debugstr_w(ref), spn_length, spn);
64
65     if (!svc_class || !svc_name)
66         return ERROR_INVALID_PARAMETER;
67
68     new_spn_length = strlenW(svc_class) + 1 /* for '/' */ + 1 /* for terminating '\0' */;
69     if (inst_name)
70         new_spn_length += strlenW(inst_name);
71     else
72         new_spn_length += strlenW(svc_name);
73     if (inst_port)
74     {
75         USHORT n = inst_port;
76         new_spn_length += 1 /* for ':' */;
77         do
78         {
79             n /= 10;
80             new_spn_length++;
81         } while (n != 0);
82     }
83     if (inst_name)
84         new_spn_length += 1 /* for '/' */ + strlenW(svc_name);
85
86     if (*spn_length < new_spn_length)
87     {
88         *spn_length = new_spn_length;
89         return ERROR_BUFFER_OVERFLOW;
90     }
91     *spn_length = new_spn_length;
92
93     p = spn;
94     len = strlenW(svc_class);
95     memcpy(p, svc_class, len * sizeof(WCHAR));
96     p += len;
97     *p = '/';
98     p++;
99     if (inst_name)
100     {
101         len = strlenW(inst_name);
102         memcpy(p, inst_name, len * sizeof(WCHAR));
103         p += len;
104         *p = '\0';
105     }
106     else
107     {
108         len = strlenW(svc_name);
109         memcpy(p, svc_name, len * sizeof(WCHAR));
110         p += len;
111         *p = '\0';
112     }
113
114     if (inst_port)
115     {
116         static const WCHAR percentU[] = {'%','u',0};
117         *p = ':';
118         p++;
119         wsprintfW(p, percentU, inst_port);
120         p += strlenW(p);
121     }
122
123     if (inst_name)
124     {
125         *p = '/';
126         p++;
127         len = strlenW(svc_name);
128         memcpy(p, svc_name, len * sizeof(WCHAR));
129         p += len;
130         *p = '\0';
131     }
132
133     TRACE("spn = %s\n", debugstr_w(spn));
134
135     return ERROR_SUCCESS;
136 }
137
138 /***********************************************************************
139  *             DsMakeSpnA (NTDSAPI.@)
140  *
141  * See DsMakeSpnW.
142  */
143 DWORD WINAPI DsMakeSpnA(LPCSTR svc_class, LPCSTR svc_name,
144                         LPCSTR inst_name, USHORT inst_port,
145                         LPCSTR ref, DWORD *spn_length, LPSTR spn)
146 {
147     FIXME("(%s,%s,%s,%d,%s,%p,%p): stub!\n", debugstr_a(svc_class),
148             debugstr_a(svc_name), debugstr_a(inst_name), inst_port,
149             debugstr_a(ref), spn_length, spn);
150
151     return ERROR_CALL_NOT_IMPLEMENTED;
152 }
153
154 /***********************************************************************
155  *             DsMakeSpnA (NTDSAPI.@)
156  */
157 DWORD WINAPI DsGetSpnA(DS_SPN_NAME_TYPE ServType, LPCSTR Servlass, LPCSTR ServName,
158                        USHORT InstPort, USHORT nInstanceNames,
159                        LPCSTR *pInstanceNames, const USHORT *pInstancePorts,
160                        DWORD *pSpn, LPSTR **pszSpn)
161 {
162     FIXME("(%d,%s,%s,%d,%d,%p,%p,%p,%p): stub!\n", ServType,
163             debugstr_a(Servlass), debugstr_a(ServName), InstPort,
164             nInstanceNames, pInstanceNames, pInstancePorts, pSpn, pszSpn);
165
166     return ERROR_CALL_NOT_IMPLEMENTED;
167 }
168
169 /***********************************************************************
170  *             DsServerRegisterSpnA (NTDSAPI.@)
171  */
172 DWORD WINAPI DsServerRegisterSpnA(DS_SPN_WRITE_OP operation, LPCSTR ServiceClass, LPCSTR UserObjectDN)
173 {
174     FIXME("(%d,%s,%s): stub!\n", operation,
175             debugstr_a(ServiceClass), debugstr_a(UserObjectDN));
176     return ERROR_CALL_NOT_IMPLEMENTED;
177 }
178
179 /***********************************************************************
180  *             DsServerRegisterSpnW (NTDSAPI.@)
181  */
182 DWORD WINAPI DsServerRegisterSpnW(DS_SPN_WRITE_OP operation, LPCWSTR ServiceClass, LPCWSTR UserObjectDN)
183 {
184     FIXME("(%d,%s,%s): stub!\n", operation,
185             debugstr_w(ServiceClass), debugstr_w(UserObjectDN));
186     return ERROR_CALL_NOT_IMPLEMENTED;
187 }