werror: replace WERR_UNKNOWN_LEVEL with WERR_INVALID_LEVEL in source3/rpc_server/
[metze/samba/wip.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(ctx, struct dssetup_DsRolePrimaryDomInfoBasic);
46         if (!basic) {
47                 DEBUG(0,("fill_dsrole_dominfo_basic: out of memory\n"));
48                 return WERR_NOT_ENOUGH_MEMORY;
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_NOT_ENOUGH_MEMORY;
80                 }
81                 if (!strlower_m(dnsdomain)) {
82                         return WERR_INVALID_PARAMETER;
83                 }
84                 basic->dns_domain = dnsdomain;
85
86                 /* FIXME!! We really should fill in the correct forest
87                    name.  Should get this information from winbindd.  */
88                 basic->forest = dnsdomain;
89         } else {
90                 /* security = domain should not fill in the dns or
91                    forest name */
92                 basic->dns_domain = NULL;
93                 basic->forest = NULL;
94         }
95
96         *info = basic;
97
98         return WERR_OK;
99 }
100
101 /********************************************************************
102  Implement the _dssetup_DsRoleGetPrimaryDomainInformation() call
103  ********************************************************************/
104
105 WERROR _dssetup_DsRoleGetPrimaryDomainInformation(struct pipes_struct *p,
106                                                   struct dssetup_DsRoleGetPrimaryDomainInformation *r)
107 {
108         WERROR werr = WERR_OK;
109
110         switch (r->in.level) {
111
112                 case DS_ROLE_BASIC_INFORMATION: {
113                         struct dssetup_DsRolePrimaryDomInfoBasic *basic = NULL;
114                         werr = fill_dsrole_dominfo_basic(p->mem_ctx, &basic);
115                         if (W_ERROR_IS_OK(werr)) {
116                                 r->out.info->basic = *basic;
117                         }
118                         break;
119                 }
120                 default:
121                         DEBUG(0,("_dssetup_DsRoleGetPrimaryDomainInformation: "
122                                 "Unknown info level [%d]!\n", r->in.level));
123                         werr = WERR_INVALID_LEVEL;
124         }
125
126         return werr;
127 }
128
129 /****************************************************************
130 ****************************************************************/
131
132 WERROR _dssetup_DsRoleDnsNameToFlatName(struct pipes_struct *p,
133                                         struct dssetup_DsRoleDnsNameToFlatName *r)
134 {
135         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
136         return WERR_NOT_SUPPORTED;
137 }
138
139 /****************************************************************
140 ****************************************************************/
141
142 WERROR _dssetup_DsRoleDcAsDc(struct pipes_struct *p,
143                              struct dssetup_DsRoleDcAsDc *r)
144 {
145         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
146         return WERR_NOT_SUPPORTED;
147 }
148
149 /****************************************************************
150 ****************************************************************/
151
152 WERROR _dssetup_DsRoleDcAsReplica(struct pipes_struct *p,
153                                   struct dssetup_DsRoleDcAsReplica *r)
154 {
155         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
156         return WERR_NOT_SUPPORTED;
157 }
158
159 /****************************************************************
160 ****************************************************************/
161
162 WERROR _dssetup_DsRoleDemoteDc(struct pipes_struct *p,
163                                struct dssetup_DsRoleDemoteDc *r)
164 {
165         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
166         return WERR_NOT_SUPPORTED;
167 }
168
169 /****************************************************************
170 ****************************************************************/
171
172 WERROR _dssetup_DsRoleGetDcOperationProgress(struct pipes_struct *p,
173                                              struct dssetup_DsRoleGetDcOperationProgress *r)
174 {
175         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
176         return WERR_NOT_SUPPORTED;
177 }
178
179 /****************************************************************
180 ****************************************************************/
181
182 WERROR _dssetup_DsRoleGetDcOperationResults(struct pipes_struct *p,
183                                             struct dssetup_DsRoleGetDcOperationResults *r)
184 {
185         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
186         return WERR_NOT_SUPPORTED;
187 }
188
189 /****************************************************************
190 ****************************************************************/
191
192 WERROR _dssetup_DsRoleCancel(struct pipes_struct *p,
193                              struct dssetup_DsRoleCancel *r)
194 {
195         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
196         return WERR_NOT_SUPPORTED;
197 }
198
199 /****************************************************************
200 ****************************************************************/
201
202 WERROR _dssetup_DsRoleServerSaveStateForUpgrade(struct pipes_struct *p,
203                                                 struct dssetup_DsRoleServerSaveStateForUpgrade *r)
204 {
205         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
206         return WERR_NOT_SUPPORTED;
207 }
208
209 /****************************************************************
210 ****************************************************************/
211
212 WERROR _dssetup_DsRoleUpgradeDownlevelServer(struct pipes_struct *p,
213                                              struct dssetup_DsRoleUpgradeDownlevelServer *r)
214 {
215         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
216         return WERR_NOT_SUPPORTED;
217 }
218
219 /****************************************************************
220 ****************************************************************/
221
222 WERROR _dssetup_DsRoleAbortDownlevelServerUpgrade(struct pipes_struct *p,
223                                                   struct dssetup_DsRoleAbortDownlevelServerUpgrade *r)
224 {
225         p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
226         return WERR_NOT_SUPPORTED;
227 }