xref: /reactos/base/services/wkssvc/domain.c (revision b09b5584)
1 /*
2  * COPYRIGHT:        See COPYING in the top level directory
3  * PROJECT:          ReactOS Services
4  * FILE:             base/services/wkssvc/domain.c
5  * PURPOSE:          Workstation service
6  * PROGRAMMER:       Eric Kohl
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include "precomp.h"
12 
13 WINE_DEFAULT_DEBUG_CHANNEL(wkssvc);
14 
15 /* FUNCTIONS *****************************************************************/
16 
17 static
18 NET_API_STATUS
19 NetpSetPrimaryDomain(
20     _In_ LPCWSTR lpWorkgroupName)
21 {
22     LSA_OBJECT_ATTRIBUTES ObjectAttributes;
23     POLICY_PRIMARY_DOMAIN_INFO PrimaryDomainInfo;
24     LSA_HANDLE PolicyHandle = NULL;
25     NTSTATUS Status;
26 
27     ZeroMemory(&ObjectAttributes, sizeof(LSA_OBJECT_ATTRIBUTES));
28     ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
29 
30     Status = LsaOpenPolicy(NULL,
31                            &ObjectAttributes,
32                            POLICY_TRUST_ADMIN,
33                            &PolicyHandle);
34     if (!LSA_SUCCESS(Status))
35         return LsaNtStatusToWinError(Status);
36 
37     RtlInitUnicodeString(&PrimaryDomainInfo.Name,
38                          lpWorkgroupName);
39     PrimaryDomainInfo.Sid = NULL;
40 
41     Status = LsaSetInformationPolicy(PolicyHandle,
42                                      PolicyPrimaryDomainInformation,
43                                      &PrimaryDomainInfo);
44 
45     LsaClose(PolicyHandle);
46 
47     return LsaNtStatusToWinError(Status);
48 }
49 
50 
51 NET_API_STATUS
52 NetpJoinWorkgroup(
53     _In_ LPCWSTR lpWorkgroupName)
54 {
55     NET_API_STATUS status;
56 
57     FIXME("NetpJoinWorkgroup(%S)\n", lpWorkgroupName);
58 
59     status = NetpSetPrimaryDomain(lpWorkgroupName);
60     if (status != NERR_Success)
61     {
62         ERR("NetpSetPrimaryDomain failed (Status %lu)\n", status);
63         return status;
64     }
65 
66     return NERR_Success;
67 }
68 
69 
70 NET_API_STATUS
71 NetpGetJoinInformation(
72     LPWSTR *NameBuffer,
73     PNETSETUP_JOIN_STATUS BufferType)
74 {
75     LSA_OBJECT_ATTRIBUTES ObjectAttributes;
76     PPOLICY_PRIMARY_DOMAIN_INFO PrimaryDomainInfo = NULL;
77     LSA_HANDLE PolicyHandle = NULL;
78     NTSTATUS Status;
79 
80     *BufferType = NetSetupUnknownStatus;
81     *NameBuffer = NULL;
82 
83     ZeroMemory(&ObjectAttributes, sizeof(LSA_OBJECT_ATTRIBUTES));
84     ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
85 
86     Status = LsaOpenPolicy(NULL,
87                            &ObjectAttributes,
88                            POLICY_VIEW_LOCAL_INFORMATION,
89                            &PolicyHandle);
90     if (!LSA_SUCCESS(Status))
91         return LsaNtStatusToWinError(Status);
92 
93     Status = LsaQueryInformationPolicy(PolicyHandle,
94                                        PolicyPrimaryDomainInformation,
95                                        (PVOID*)&PrimaryDomainInfo);
96     if (LSA_SUCCESS(Status))
97     {
98         TRACE("Sid: %p\n", PrimaryDomainInfo->Sid);
99         TRACE("Name: %S\n", PrimaryDomainInfo->Name.Buffer);
100 
101         if (PrimaryDomainInfo->Name.Length > 0)
102         {
103             if (PrimaryDomainInfo->Sid != NULL)
104                 *BufferType = NetSetupDomainName;
105             else
106                 *BufferType = NetSetupWorkgroupName;
107 
108             *NameBuffer = midl_user_allocate(PrimaryDomainInfo->Name.Length + sizeof(WCHAR));
109             if (*NameBuffer)
110                 wcscpy(*NameBuffer, PrimaryDomainInfo->Name.Buffer);
111         }
112         else
113         {
114             *BufferType = NetSetupUnjoined;
115         }
116 
117         if (PrimaryDomainInfo->Sid)
118             LsaFreeMemory(PrimaryDomainInfo->Sid);
119 
120         LsaFreeMemory(PrimaryDomainInfo);
121     }
122 
123     LsaClose(PolicyHandle);
124 
125     return LsaNtStatusToWinError(Status);
126 }
127 
128 /* EOF */
129