msi: Only specifically resolve the TARGETDIR directory once.
[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 "winternl.h"
29 #include "ntsecapi.h"
30 #include "wine/debug.h"
31 #include "dsrole.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(ds);
34
35 /************************************************************
36  *  DsRoleFreeMemory (NETAPI32.@)
37  *
38  * PARAMS
39  *  Buffer [I] Pointer to the to-be-freed buffer.
40  *
41  * RETURNS
42  *  Nothing
43  */
44 VOID WINAPI DsRoleFreeMemory(PVOID Buffer)
45 {
46     TRACE("(%p)\n", Buffer);
47     HeapFree(GetProcessHeap(), 0, Buffer);
48 }
49
50 /************************************************************
51  *  DsRoleGetPrimaryDomainInformation  (NETAPI32.@)
52  *
53  * PARAMS
54  *  lpServer  [I] Pointer to UNICODE string with Computername
55  *  InfoLevel [I] Type of data to retrieve      
56  *  Buffer    [O] Pointer to to the requested data
57  *
58  * RETURNS
59  *
60  * NOTES
61  *  When lpServer is NULL, use the local computer
62  */
63 DWORD WINAPI DsRoleGetPrimaryDomainInformation(
64     LPCWSTR lpServer, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel,
65     PBYTE* Buffer)
66 {
67     DWORD ret;
68
69     FIXME("(%p, %d, %p) stub\n", lpServer, InfoLevel, Buffer);
70
71     /* Check some input parameters */
72
73     if (!Buffer) return ERROR_INVALID_PARAMETER;
74     if ((InfoLevel < DsRolePrimaryDomainInfoBasic) || (InfoLevel > DsRoleOperationState)) return ERROR_INVALID_PARAMETER;
75
76     switch (InfoLevel)
77     {
78         case DsRolePrimaryDomainInfoBasic:
79         {
80             LSA_OBJECT_ATTRIBUTES ObjectAttributes;
81             LSA_HANDLE PolicyHandle;
82             PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo;
83             NTSTATUS NtStatus;
84             int logon_domain_sz;
85             DWORD size;
86             PDSROLE_PRIMARY_DOMAIN_INFO_BASIC basic;
87
88             ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
89             NtStatus = LsaOpenPolicy(NULL, &ObjectAttributes,
90              POLICY_VIEW_LOCAL_INFORMATION, &PolicyHandle);
91             if (NtStatus != STATUS_SUCCESS)
92             {
93                 ERR("LsaOpenPolicyFailed with NT status %lx\n",
94                     LsaNtStatusToWinError(NtStatus));
95                 return ERROR_OUTOFMEMORY;
96             }
97             LsaQueryInformationPolicy(PolicyHandle,
98              PolicyAccountDomainInformation, (PVOID*)&DomainInfo);
99             logon_domain_sz = lstrlenW(DomainInfo->DomainName.Buffer) + 1;
100             LsaClose(PolicyHandle);
101
102             size = sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC) +
103              logon_domain_sz * sizeof(WCHAR);
104             basic = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
105             if (basic)
106             {
107                 basic->MachineRole = DsRole_RoleStandaloneWorkstation;
108                 basic->DomainNameFlat = (LPWSTR)((LPBYTE)basic +
109                  sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
110                 lstrcpyW(basic->DomainNameFlat, DomainInfo->DomainName.Buffer);
111                 ret = ERROR_SUCCESS;
112             }
113             else
114                 ret = ERROR_OUTOFMEMORY;
115             *Buffer = (PBYTE)basic;
116             LsaFreeMemory(DomainInfo);
117         }
118         break;
119     default:
120         ret = ERROR_CALL_NOT_IMPLEMENTED;
121     }
122     return ret;
123 }