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