2163a0c9e1132d103b0aafe238bea4afe2552449
[reactos.git] / reactos / dll / win32 / netapi32 / dssetup.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: NetAPI DLL
4 * FILE: reactos/dll/win32/netapi32/dssetup.c
5 * PURPOSE: Directory Service Setup interface code
6 * PROGRAMMERS: Eric Kohl
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "netapi32.h"
12
13 #include <rpc.h>
14 #include "dssetup_c.h"
15
16 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
17
18 /* FUNCTIONS *****************************************************************/
19
20 static
21 RPC_STATUS
22 DsSetupBind(
23 LPWSTR lpServerName,
24 handle_t *hBinding)
25 {
26 LPWSTR pszStringBinding;
27 RPC_STATUS status;
28
29 TRACE("DsSetupBind() called\n");
30
31 *hBinding = NULL;
32
33 status = RpcStringBindingComposeW(NULL,
34 L"ncacn_np",
35 lpServerName,
36 L"\\pipe\\lsarpc",
37 NULL,
38 &pszStringBinding);
39 if (status)
40 {
41 TRACE("RpcStringBindingCompose returned 0x%x\n", status);
42 return status;
43 }
44
45 /* Set the binding handle that will be used to bind to the server. */
46 status = RpcBindingFromStringBindingW(pszStringBinding,
47 hBinding);
48 if (status)
49 {
50 TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
51 }
52
53 status = RpcStringFreeW(&pszStringBinding);
54 if (status)
55 {
56 TRACE("RpcStringFree returned 0x%x\n", status);
57 }
58
59 return status;
60 }
61
62
63 static
64 void
65 DsSetupUnbind(
66 handle_t hBinding)
67 {
68 RPC_STATUS status;
69
70 TRACE("DsSetupUnbind()\n");
71
72 status = RpcBindingFree(&hBinding);
73 if (status)
74 {
75 TRACE("RpcBindingFree returned 0x%x\n", status);
76 }
77 }
78
79
80 DWORD
81 WINAPI
82 DsRoleGetPrimaryDomainInformation(
83 LPCWSTR lpServer,
84 DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
85 PBYTE* Buffer)
86 {
87 handle_t hBinding = NULL;
88 NET_API_STATUS status;
89
90 TRACE("DsRoleGetPrimaryDomainInformation(%p, %d, %p)\n",
91 lpServer, InfoLevel, Buffer);
92
93 /* Check some input parameters */
94
95 if (!Buffer)
96 return ERROR_INVALID_PARAMETER;
97
98 if ((InfoLevel < DsRolePrimaryDomainInfoBasic) || (InfoLevel > DsRoleOperationState))
99 return ERROR_INVALID_PARAMETER;
100
101 *Buffer = NULL;
102
103 status = DsSetupBind((LPWSTR)lpServer, &hBinding);
104 if (status)
105 {
106 TRACE("DsSetupBind() failed (Status %lu\n)", status);
107 return status;
108 }
109
110 RpcTryExcept
111 {
112 status = DsRolerGetPrimaryDomainInformation(hBinding,
113 InfoLevel,
114 (PDSROLER_PRIMARY_DOMAIN_INFORMATION *)Buffer);
115 }
116 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
117 {
118 status = I_RpcMapWin32Status(RpcExceptionCode());
119 }
120 RpcEndExcept;
121
122 if (hBinding != NULL)
123 DsSetupUnbind(hBinding);
124
125 return status;
126 }
127
128 /* EOF */