xref: /reactos/dll/win32/netapi32/dssetup.c (revision 1734f297)
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 VOID
81 WINAPI
82 DsRoleFreeMemory(
83     _In_ PVOID Buffer)
84 {
85     TRACE("DsRoleFreeMemory(%p)\n", Buffer);
86     HeapFree(GetProcessHeap(), 0, Buffer);
87 }
88 
89 
90 DWORD
91 WINAPI
92 DsRoleGetPrimaryDomainInformation(
93     LPCWSTR lpServer,
94     DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
95     PBYTE* Buffer)
96 {
97     handle_t hBinding = NULL;
98     NET_API_STATUS status;
99 
100     TRACE("DsRoleGetPrimaryDomainInformation(%p, %d, %p)\n",
101           lpServer, InfoLevel, Buffer);
102 
103     /* Check some input parameters */
104 
105     if (!Buffer)
106         return ERROR_INVALID_PARAMETER;
107 
108     if ((InfoLevel < DsRolePrimaryDomainInfoBasic) || (InfoLevel > DsRoleOperationState))
109         return ERROR_INVALID_PARAMETER;
110 
111     *Buffer = NULL;
112 
113     status = DsSetupBind((LPWSTR)lpServer, &hBinding);
114     if (status)
115     {
116         TRACE("DsSetupBind() failed (Status %lu\n)\n", status);
117         return status;
118     }
119 
120     RpcTryExcept
121     {
122         status = DsRolerGetPrimaryDomainInformation(hBinding,
123                                                     InfoLevel,
124                                                     (PDSROLER_PRIMARY_DOMAIN_INFORMATION *)Buffer);
125     }
126     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
127     {
128         status = I_RpcMapWin32Status(RpcExceptionCode());
129     }
130     RpcEndExcept;
131 
132     if (hBinding != NULL)
133         DsSetupUnbind(hBinding);
134 
135     return status;
136 }
137 
138 /* EOF */
139