[NETAPI32]
[reactos.git] / reactos / dll / win32 / netapi32 / ds.c
1 /*
2 * Copyright 2005 Paul Vriens
3 *
4 * netapi32 directory service functions
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "netapi32.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(ds);
24
25 DWORD WINAPI DsGetDcNameW(LPCWSTR ComputerName, LPCWSTR AvoidDCName,
26 GUID* DomainGuid, LPCWSTR SiteName, ULONG Flags,
27 PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
28 {
29 FIXME("(%s, %s, %s, %s, %08x, %p): stub\n", debugstr_w(ComputerName),
30 debugstr_w(AvoidDCName), debugstr_guid(DomainGuid),
31 debugstr_w(SiteName), Flags, DomainControllerInfo);
32 return ERROR_CALL_NOT_IMPLEMENTED;
33 }
34
35 DWORD WINAPI DsGetDcNameA(LPCSTR ComputerName, LPCSTR AvoidDCName,
36 GUID* DomainGuid, LPCSTR SiteName, ULONG Flags,
37 PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
38 {
39 FIXME("(%s, %s, %s, %s, %08x, %p): stub\n", debugstr_a(ComputerName),
40 debugstr_a(AvoidDCName), debugstr_guid(DomainGuid),
41 debugstr_a(SiteName), Flags, DomainControllerInfo);
42 return ERROR_CALL_NOT_IMPLEMENTED;
43 }
44
45 DWORD WINAPI DsGetSiteNameW(LPCWSTR ComputerName, LPWSTR *SiteName)
46 {
47 FIXME("(%s, %p): stub\n", debugstr_w(ComputerName), SiteName);
48 return ERROR_CALL_NOT_IMPLEMENTED;
49 }
50
51 /************************************************************
52 * DsRoleFreeMemory (NETAPI32.@)
53 *
54 * PARAMS
55 * Buffer [I] Pointer to the to-be-freed buffer.
56 *
57 * RETURNS
58 * Nothing
59 */
60 VOID WINAPI DsRoleFreeMemory(PVOID Buffer)
61 {
62 TRACE("(%p)\n", Buffer);
63 HeapFree(GetProcessHeap(), 0, Buffer);
64 }
65
66 /************************************************************
67 * DsRoleGetPrimaryDomainInformation (NETAPI32.@)
68 *
69 * PARAMS
70 * lpServer [I] Pointer to UNICODE string with ComputerName
71 * InfoLevel [I] Type of data to retrieve
72 * Buffer [O] Pointer to to the requested data
73 *
74 * RETURNS
75 *
76 * NOTES
77 * When lpServer is NULL, use the local computer
78 */
79 DWORD WINAPI DsRoleGetPrimaryDomainInformation(
80 LPCWSTR lpServer, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
81 PBYTE* Buffer)
82 {
83 DWORD ret;
84
85 FIXME("(%p, %d, %p) stub\n", lpServer, InfoLevel, Buffer);
86
87 /* Check some input parameters */
88
89 if (!Buffer) return ERROR_INVALID_PARAMETER;
90 if ((InfoLevel < DsRolePrimaryDomainInfoBasic) || (InfoLevel > DsRoleOperationState)) return ERROR_INVALID_PARAMETER;
91
92 *Buffer = NULL;
93 switch (InfoLevel)
94 {
95 case DsRolePrimaryDomainInfoBasic:
96 {
97 LSA_OBJECT_ATTRIBUTES ObjectAttributes;
98 LSA_HANDLE PolicyHandle;
99 PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo;
100 NTSTATUS NtStatus;
101 int logon_domain_sz;
102 DWORD size;
103 PDSROLE_PRIMARY_DOMAIN_INFO_BASIC basic;
104
105 ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
106 NtStatus = LsaOpenPolicy(NULL, &ObjectAttributes,
107 POLICY_VIEW_LOCAL_INFORMATION, &PolicyHandle);
108 if (NtStatus != STATUS_SUCCESS)
109 {
110 TRACE("LsaOpenPolicyFailed with NT status %x\n",
111 LsaNtStatusToWinError(NtStatus));
112 return ERROR_OUTOFMEMORY;
113 }
114 LsaQueryInformationPolicy(PolicyHandle,
115 PolicyAccountDomainInformation, (PVOID*)&DomainInfo);
116 logon_domain_sz = lstrlenW(DomainInfo->DomainName.Buffer) + 1;
117 LsaClose(PolicyHandle);
118
119 size = sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC) +
120 logon_domain_sz * sizeof(WCHAR);
121 basic = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
122 if (basic)
123 {
124 basic->MachineRole = DsRole_RoleStandaloneWorkstation;
125 basic->DomainNameFlat = (LPWSTR)((LPBYTE)basic +
126 sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
127 lstrcpyW(basic->DomainNameFlat, DomainInfo->DomainName.Buffer);
128 ret = ERROR_SUCCESS;
129 }
130 else
131 ret = ERROR_OUTOFMEMORY;
132 *Buffer = (PBYTE)basic;
133 LsaFreeMemory(DomainInfo);
134 }
135 break;
136 default:
137 ret = ERROR_CALL_NOT_IMPLEMENTED;
138 }
139 return ret;
140 }