ReactOS  0.4.14-dev-583-g2a1ba2c
ntdsapi.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 Robert Shearman (for CodeWeavers)
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 "winnls.h"
25 #include "rpc.h"
26 #include "rpcdce.h"
27 #include "ntdsapi.h"
28 
29 #include "wine/test.h"
30 
31 static void test_DsMakeSpn(void)
32 {
33  DWORD ret;
34  WCHAR spn[256];
35  DWORD spn_length;
36  static const WCHAR wszServiceClass[] = {'c','l','a','s','s',0};
37  static const WCHAR wszServiceHost[] = {'h','o','s','t',0};
38  static const WCHAR wszInstanceName[] = {'i','n','s','t','a','n','c','e',0};
39  static const WCHAR wszReferrer[] = {'r','e','f','e','r','r','e','r',0};
40  static const WCHAR wszSpn1[] = {'c','l','a','s','s','/','h','o','s','t',0};
41  static const WCHAR wszSpn2[] = {'c','l','a','s','s','/','i','n','s','t','a','n','c','e','/','h','o','s','t',0};
42  static const WCHAR wszSpn3[] = {'c','l','a','s','s','/','i','n','s','t','a','n','c','e',':','5','5','5','/','h','o','s','t',0};
43  static const WCHAR wszSpn4[] = {'c','l','a','s','s','/','i','n','s','t','a','n','c','e',':','5','5','5','/','h','o','s','t',0};
44  static const WCHAR wszSpn5[] = {'c','l','a','s','s','/','h','o','s','t',':','5','5','5',0};
45 
46  spn[0] = '\0';
47 
48  spn_length = ARRAY_SIZE(spn);
49  ret = DsMakeSpnW(NULL, NULL, NULL, 0, NULL, &spn_length, spn);
50  ok(ret == ERROR_INVALID_PARAMETER, "DsMakeSpnW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
51 
52  spn_length = ARRAY_SIZE(spn);
53  ret = DsMakeSpnW(NULL, wszServiceHost, NULL, 0, NULL, &spn_length, spn);
54  ok(ret == ERROR_INVALID_PARAMETER, "DsMakeSpnW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
55 
56  spn_length = ARRAY_SIZE(spn);
57  ret = DsMakeSpnW(wszServiceClass, wszServiceHost, NULL, 0, NULL, &spn_length, spn);
58  ok(ret == ERROR_SUCCESS, "DsMakeSpnW should have succeeded instead of failing with %d\n", ret);
59  ok(!lstrcmpW(spn, wszSpn1), "DsMakeSpnW returned unexpected SPN %s\n", wine_dbgstr_w(spn));
60  ok(spn_length == lstrlenW(wszSpn1) + 1, "DsMakeSpnW should have returned spn_length of %d instead of %d\n", lstrlenW(wszSpn1) + 1, spn_length);
61 
62  spn_length = ARRAY_SIZE(spn);
63  ret = DsMakeSpnW(wszServiceClass, wszServiceHost, wszInstanceName, 0, NULL, &spn_length, spn);
64  ok(ret == ERROR_SUCCESS, "DsMakeSpnW should have succeeded instead of failing with %d\n", ret);
65  ok(!lstrcmpW(spn, wszSpn2), "DsMakeSpnW returned unexpected SPN %s\n", wine_dbgstr_w(spn));
66  ok(spn_length == lstrlenW(wszSpn2) + 1, "DsMakeSpnW should have returned spn_length of %d instead of %d\n", lstrlenW(wszSpn2) + 1, spn_length);
67 
68  spn_length = ARRAY_SIZE(spn);
69  ret = DsMakeSpnW(wszServiceClass, wszServiceHost, wszInstanceName, 555, NULL, &spn_length, spn);
70  ok(ret == ERROR_SUCCESS, "DsMakeSpnW should have succeeded instead of failing with %d\n", ret);
71  ok(!lstrcmpW(spn, wszSpn3), "DsMakeSpnW returned unexpected SPN %s\n", wine_dbgstr_w(spn));
72  ok(spn_length == lstrlenW(wszSpn3) + 1, "DsMakeSpnW should have returned spn_length of %d instead of %d\n", lstrlenW(wszSpn3) + 1, spn_length);
73 
74  spn_length = ARRAY_SIZE(spn);
75  ret = DsMakeSpnW(wszServiceClass, wszServiceHost, wszInstanceName, 555, wszReferrer, &spn_length, spn);
76  ok(ret == ERROR_SUCCESS, "DsMakeSpnW should have succeeded instead of failing with %d\n", ret);
77  ok(!lstrcmpW(spn, wszSpn4), "DsMakeSpnW returned unexpected SPN %s\n", wine_dbgstr_w(spn));
78  ok(spn_length == lstrlenW(wszSpn4) + 1, "DsMakeSpnW should have returned spn_length of %d instead of %d\n", lstrlenW(wszSpn4) + 1, spn_length);
79 
80  spn_length = ARRAY_SIZE(spn);
81  ret = DsMakeSpnW(wszServiceClass, wszServiceHost, NULL, 555, wszReferrer, &spn_length, spn);
82  ok(ret == ERROR_SUCCESS, "DsMakeSpnW should have succeeded instead of failing with %d\n", ret);
83  ok(!lstrcmpW(spn, wszSpn5), "DsMakeSpnW returned unexpected SPN %s\n", wine_dbgstr_w(spn));
84  ok(spn_length == lstrlenW(wszSpn5) + 1, "DsMakeSpnW should have returned spn_length of %d instead of %d\n", lstrlenW(wszSpn5) + 1, spn_length);
85 }
86 
88 {
89  static const WCHAR classW[] = {'c','l','a','s','s',0};
90  static const WCHAR hostW[] = {'h','o','s','t','.','d','o','m','a','i','n',0};
91  static const WCHAR resultW[] = {'c','l','a','s','s','/','h','o','s','t','.','d','o','m','a','i','n',0};
92  DWORD ret, len;
93  WCHAR buf[256];
94 
96  ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
97 
99  ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
100 
102  ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
103 
104  len = 0;
106  ok( ret == ERROR_BUFFER_OVERFLOW, "got %u\n", ret );
107  ok( len == lstrlenW(resultW) + 1, "got %u\n", len );
108 
109  len = ARRAY_SIZE(buf);
110  buf[0] = 0;
112  ok( ret == ERROR_SUCCESS, "got %u\n", ret );
113  ok( len == lstrlenW(resultW) + 1, "got %u\n", len );
114  ok( !lstrcmpW( buf, resultW ), "wrong data\n" );
115 }
116 
117 START_TEST( ntdsapi )
118 {
119  test_DsMakeSpn();
121 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
static const WCHAR classW[]
Definition: lex.c:40
static const WCHAR hostW[]
Definition: http.c:71
#define ERROR_SUCCESS
Definition: deptool.c:10
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
START_TEST(ntdsapi)
Definition: ntdsapi.c:117
#define lstrlenW
Definition: compat.h:415
DWORD WINAPI DsClientMakeSpnForTargetServerW(LPCWSTR class, LPCWSTR name, DWORD *buflen, LPWSTR buf)
Definition: ntdsapi.c:209
smooth NULL
Definition: ftsmooth.c:416
static void test_DsMakeSpn(void)
Definition: ntdsapi.c:31
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
GLenum GLsizei len
Definition: glext.h:6722
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ok(value,...)
Definition: atltest.h:57
DWORD WINAPI DsMakeSpnW(LPCWSTR svc_class, LPCWSTR svc_name, LPCWSTR inst_name, USHORT inst_port, LPCWSTR ref, DWORD *spn_length, LPWSTR spn)
Definition: ntdsapi.c:70
static void test_DsClientMakeSpnForTargetServer(void)
Definition: ntdsapi.c:87