msvcp100: Remove superfluous semicolons.
[wine] / dlls / 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 <stdarg.h>
22
23 #include "ntstatus.h"
24 #define WIN32_NO_STATUS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "ntsecapi.h"
29 #include "wine/debug.h"
30 #include "dsrole.h"
31 #include "dsgetdc.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(ds);
34
35 DWORD WINAPI DsGetDcNameW(LPCWSTR ComputerName, LPCWSTR AvoidDCName,
36  GUID* DomainGuid, LPCWSTR SiteName, ULONG Flags,
37  PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
38 {
39     FIXME("(%s, %s, %s, %s, %08x, %p): stub\n", debugstr_w(ComputerName),
40      debugstr_w(AvoidDCName), debugstr_guid(DomainGuid),
41      debugstr_w(SiteName), Flags, DomainControllerInfo);
42     return ERROR_CALL_NOT_IMPLEMENTED;
43 }
44
45 DWORD WINAPI DsGetDcNameA(LPCSTR ComputerName, LPCSTR AvoidDCName,
46  GUID* DomainGuid, LPCSTR SiteName, ULONG Flags,
47  PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
48 {
49     FIXME("(%s, %s, %s, %s, %08x, %p): stub\n", debugstr_a(ComputerName),
50      debugstr_a(AvoidDCName), debugstr_guid(DomainGuid),
51      debugstr_a(SiteName), Flags, DomainControllerInfo);
52     return ERROR_CALL_NOT_IMPLEMENTED;
53 }
54
55 DWORD WINAPI DsGetSiteNameW(LPCWSTR ComputerName, LPWSTR *SiteName)
56 {
57     FIXME("(%s, %p): stub\n", debugstr_w(ComputerName), SiteName);
58     return ERROR_CALL_NOT_IMPLEMENTED;
59 }
60
61 DWORD WINAPI DsGetSiteNameA(LPCSTR ComputerName, LPSTR *SiteName)
62 {
63     FIXME("(%s, %p): stub\n", debugstr_a(ComputerName), SiteName);
64     return ERROR_CALL_NOT_IMPLEMENTED;
65 }
66
67 /************************************************************
68  *  DsRoleFreeMemory (NETAPI32.@)
69  *
70  * PARAMS
71  *  Buffer [I] Pointer to the to-be-freed buffer.
72  *
73  * RETURNS
74  *  Nothing
75  */
76 VOID WINAPI DsRoleFreeMemory(PVOID Buffer)
77 {
78     TRACE("(%p)\n", Buffer);
79     HeapFree(GetProcessHeap(), 0, Buffer);
80 }
81
82 /************************************************************
83  *  DsRoleGetPrimaryDomainInformation  (NETAPI32.@)
84  *
85  * PARAMS
86  *  lpServer  [I] Pointer to UNICODE string with ComputerName
87  *  InfoLevel [I] Type of data to retrieve      
88  *  Buffer    [O] Pointer to to the requested data
89  *
90  * RETURNS
91  *
92  * NOTES
93  *  When lpServer is NULL, use the local computer
94  */
95 DWORD WINAPI DsRoleGetPrimaryDomainInformation(
96     LPCWSTR lpServer, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
97     PBYTE* Buffer)
98 {
99     DWORD ret;
100
101     FIXME("(%p, %d, %p) stub\n", lpServer, InfoLevel, Buffer);
102
103     /* Check some input parameters */
104
105     if (!Buffer) return ERROR_INVALID_PARAMETER;
106     if ((InfoLevel < DsRolePrimaryDomainInfoBasic) || (InfoLevel > DsRoleOperationState)) return ERROR_INVALID_PARAMETER;
107
108     *Buffer = NULL;
109     switch (InfoLevel)
110     {
111         case DsRolePrimaryDomainInfoBasic:
112         {
113             LSA_OBJECT_ATTRIBUTES ObjectAttributes;
114             LSA_HANDLE PolicyHandle;
115             PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo;
116             NTSTATUS NtStatus;
117             int logon_domain_sz;
118             DWORD size;
119             PDSROLE_PRIMARY_DOMAIN_INFO_BASIC basic;
120
121             ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
122             NtStatus = LsaOpenPolicy(NULL, &ObjectAttributes,
123              POLICY_VIEW_LOCAL_INFORMATION, &PolicyHandle);
124             if (NtStatus != STATUS_SUCCESS)
125             {
126                 TRACE("LsaOpenPolicyFailed with NT status %x\n",
127                     LsaNtStatusToWinError(NtStatus));
128                 return ERROR_OUTOFMEMORY;
129             }
130             LsaQueryInformationPolicy(PolicyHandle,
131              PolicyAccountDomainInformation, (PVOID*)&DomainInfo);
132             logon_domain_sz = lstrlenW(DomainInfo->DomainName.Buffer) + 1;
133             LsaClose(PolicyHandle);
134
135             size = sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC) +
136              logon_domain_sz * sizeof(WCHAR);
137             basic = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
138             if (basic)
139             {
140                 basic->MachineRole = DsRole_RoleStandaloneWorkstation;
141                 basic->DomainNameFlat = (LPWSTR)((LPBYTE)basic +
142                  sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
143                 lstrcpyW(basic->DomainNameFlat, DomainInfo->DomainName.Buffer);
144                 ret = ERROR_SUCCESS;
145             }
146             else
147                 ret = ERROR_OUTOFMEMORY;
148             *Buffer = (PBYTE)basic;
149             LsaFreeMemory(DomainInfo);
150         }
151         break;
152     default:
153         ret = ERROR_CALL_NOT_IMPLEMENTED;
154     }
155     return ret;
156 }