s3: include ntdomain.h before including generated srv_ headers.
[samba.git] / source3 / rpc_server / dssetup / srv_dssetup_nt.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell               1992-1997.
5  *  Copyright (C) Luke Kenneth Casson Leighton  1996-1997.
6  *  Copyright (C) Paul Ashton                        1997.
7  *  Copyright (C) Jeremy Allison                     2001.
8  *  Copyright (C) Gerald Carter                      2002.
9  *  Copyright (C) Guenther Deschner                  2008.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 3 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
23  */
24
25 #include "includes.h"
26 #include "ntdomain.h"
27 #include "../librpc/gen_ndr/srv_dssetup.h"
28 #include "secrets.h"
29
30 #undef DBGC_CLASS
31 #define DBGC_CLASS DBGC_RPC_SRV
32
33 /********************************************************************
34  Fill in a dssetup_DsRolePrimaryDomInfoBasic structure
35  ********************************************************************/
36
37 static WERROR fill_dsrole_dominfo_basic(TALLOC_CTX *ctx,
38                                         struct dssetup_DsRolePrimaryDomInfoBasic **info)
39 {
40         struct dssetup_DsRolePrimaryDomInfoBasic *basic = NULL;
41         char *dnsdomain = NULL;
42
43         DEBUG(10,("fill_dsrole_dominfo_basic: enter\n"));
44
45         basic = TALLOC_ZERO_P(ctx, struct dssetup_DsRolePrimaryDomInfoBasic);
46         if (!basic) {
47                 DEBUG(0,("fill_dsrole_dominfo_basic: out of memory\n"));
48                 return WERR_NOMEM;
49         }
50
51         switch (lp_server_role()) {
52                 case ROLE_STANDALONE:
53                         basic->role = DS_ROLE_STANDALONE_SERVER;
54                         basic->domain = get_global_sam_name();
55                         break;
56                 case ROLE_DOMAIN_MEMBER:
57                         basic->role = DS_ROLE_MEMBER_SERVER;
58                         basic->domain = lp_workgroup();
59                         break;
60                 case ROLE_DOMAIN_BDC:
61                         basic->role = DS_ROLE_BACKUP_DC;
62                         basic->domain = get_global_sam_name();
63                         break;
64                 case ROLE_DOMAIN_PDC:
65                         basic->role = DS_ROLE_PRIMARY_DC;
66                         basic->domain = get_global_sam_name();
67                         break;
68         }
69
70         if (secrets_fetch_domain_guid(lp_workgroup(), &basic->domain_guid)) {
71                 basic->flags |= DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT;
72         }
73
74         /* fill in some additional fields if we are a member of an AD domain */
75
76         if (lp_security() == SEC_ADS) {
77                 dnsdomain = talloc_strdup(ctx, lp_realm());
78                 if (!dnsdomain) {
79                         return WERR_NOMEM;
80                 }
81                 strlower_m(dnsdomain);
82                 basic->dns_domain = dnsdomain;
83
84                 /* FIXME!! We really should fill in the correct forest
85                    name.  Should get this information from winbindd.  */
86                 basic->forest = dnsdomain;
87         } else {
88                 /* security = domain should not fill in the dns or
89                    forest name */
90                 basic->dns_domain = NULL;
91                 basic->forest = NULL;
92         }
93
94         *info = basic;
95
96         return WERR_OK;
97 }
98
99 /********************************************************************
100  Implement the _dssetup_DsRoleGetPrimaryDomainInformation() call
101  ********************************************************************/
102
103 WERROR _dssetup_DsRoleGetPrimaryDomainInformation(struct pipes_struct *p,
104                                                   struct dssetup_DsRoleGetPrimaryDomainInformation *r)
105 {
106         WERROR werr = WERR_OK;
107
108         switch (r->in.level) {
109
110                 case DS_ROLE_BASIC_INFORMATION: {
111                         struct dssetup_DsRolePrimaryDomInfoBasic *basic = NULL;
112                         werr = fill_dsrole_dominfo_basic(p->mem_ctx, &basic);
113                         if (W_ERROR_IS_OK(werr)) {
114                                 r->out.info->basic = *basic;
115                         }
116                         break;
117                 }
118                 default:
119                         DEBUG(0,("_dssetup_DsRoleGetPrimaryDomainInformation: "
120                                 "Unknown info level [%d]!\n", r->in.level));
121                         werr = WERR_UNKNOWN_LEVEL;
122         }
123
124         return werr;
125 }
126
127 /****************************************************************
128 ****************************************************************/
129
130 WERROR _dssetup_DsRoleDnsNameToFlatName(struct pipes_struct *p,
131                                         struct dssetup_DsRoleDnsNameToFlatName *r)
132 {
133         p->rng_fault_state = true;
134         return WERR_NOT_SUPPORTED;
135 }
136
137 /****************************************************************
138 ****************************************************************/
139
140 WERROR _dssetup_DsRoleDcAsDc(struct pipes_struct *p,
141                              struct dssetup_DsRoleDcAsDc *r)
142 {
143         p->rng_fault_state = true;
144         return WERR_NOT_SUPPORTED;
145 }
146
147 /****************************************************************
148 ****************************************************************/
149
150 WERROR _dssetup_DsRoleDcAsReplica(struct pipes_struct *p,
151                                   struct dssetup_DsRoleDcAsReplica *r)
152 {
153         p->rng_fault_state = true;
154         return WERR_NOT_SUPPORTED;
155 }
156
157 /****************************************************************
158 ****************************************************************/
159
160 WERROR _dssetup_DsRoleDemoteDc(struct pipes_struct *p,
161                                struct dssetup_DsRoleDemoteDc *r)
162 {
163         p->rng_fault_state = true;
164         return WERR_NOT_SUPPORTED;
165 }
166
167 /****************************************************************
168 ****************************************************************/
169
170 WERROR _dssetup_DsRoleGetDcOperationProgress(struct pipes_struct *p,
171                                              struct dssetup_DsRoleGetDcOperationProgress *r)
172 {
173         p->rng_fault_state = true;
174         return WERR_NOT_SUPPORTED;
175 }
176
177 /****************************************************************
178 ****************************************************************/
179
180 WERROR _dssetup_DsRoleGetDcOperationResults(struct pipes_struct *p,
181                                             struct dssetup_DsRoleGetDcOperationResults *r)
182 {
183         p->rng_fault_state = true;
184         return WERR_NOT_SUPPORTED;
185 }
186
187 /****************************************************************
188 ****************************************************************/
189
190 WERROR _dssetup_DsRoleCancel(struct pipes_struct *p,
191                              struct dssetup_DsRoleCancel *r)
192 {
193         p->rng_fault_state = true;
194         return WERR_NOT_SUPPORTED;
195 }
196
197 /****************************************************************
198 ****************************************************************/
199
200 WERROR _dssetup_DsRoleServerSaveStateForUpgrade(struct pipes_struct *p,
201                                                 struct dssetup_DsRoleServerSaveStateForUpgrade *r)
202 {
203         p->rng_fault_state = true;
204         return WERR_NOT_SUPPORTED;
205 }
206
207 /****************************************************************
208 ****************************************************************/
209
210 WERROR _dssetup_DsRoleUpgradeDownlevelServer(struct pipes_struct *p,
211                                              struct dssetup_DsRoleUpgradeDownlevelServer *r)
212 {
213         p->rng_fault_state = true;
214         return WERR_NOT_SUPPORTED;
215 }
216
217 /****************************************************************
218 ****************************************************************/
219
220 WERROR _dssetup_DsRoleAbortDownlevelServerUpgrade(struct pipes_struct *p,
221                                                   struct dssetup_DsRoleAbortDownlevelServerUpgrade *r)
222 {
223         p->rng_fault_state = true;
224         return WERR_NOT_SUPPORTED;
225 }