s3-secrets: only include secrets.h when needed.
[nivanova/samba-autobuild/.git] / source3 / rpc_server / 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 "../librpc/gen_ndr/srv_dssetup.h"
27 #include "secrets.h"
28
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_RPC_SRV
31
32 /********************************************************************
33  Fill in a dssetup_DsRolePrimaryDomInfoBasic structure
34  ********************************************************************/
35
36 static WERROR fill_dsrole_dominfo_basic(TALLOC_CTX *ctx,
37                                         struct dssetup_DsRolePrimaryDomInfoBasic **info)
38 {
39         struct dssetup_DsRolePrimaryDomInfoBasic *basic = NULL;
40         char *dnsdomain = NULL;
41
42         DEBUG(10,("fill_dsrole_dominfo_basic: enter\n"));
43
44         basic = TALLOC_ZERO_P(ctx, struct dssetup_DsRolePrimaryDomInfoBasic);
45         if (!basic) {
46                 DEBUG(0,("fill_dsrole_dominfo_basic: out of memory\n"));
47                 return WERR_NOMEM;
48         }
49
50         switch (lp_server_role()) {
51                 case ROLE_STANDALONE:
52                         basic->role = DS_ROLE_STANDALONE_SERVER;
53                         basic->domain = get_global_sam_name();
54                         break;
55                 case ROLE_DOMAIN_MEMBER:
56                         basic->role = DS_ROLE_MEMBER_SERVER;
57                         basic->domain = lp_workgroup();
58                         break;
59                 case ROLE_DOMAIN_BDC:
60                         basic->role = DS_ROLE_BACKUP_DC;
61                         basic->domain = get_global_sam_name();
62                         break;
63                 case ROLE_DOMAIN_PDC:
64                         basic->role = DS_ROLE_PRIMARY_DC;
65                         basic->domain = get_global_sam_name();
66                         break;
67         }
68
69         if (secrets_fetch_domain_guid(lp_workgroup(), &basic->domain_guid)) {
70                 basic->flags |= DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT;
71         }
72
73         /* fill in some additional fields if we are a member of an AD domain */
74
75         if (lp_security() == SEC_ADS) {
76                 dnsdomain = talloc_strdup(ctx, lp_realm());
77                 if (!dnsdomain) {
78                         return WERR_NOMEM;
79                 }
80                 strlower_m(dnsdomain);
81                 basic->dns_domain = dnsdomain;
82
83                 /* FIXME!! We really should fill in the correct forest
84                    name.  Should get this information from winbindd.  */
85                 basic->forest = dnsdomain;
86         } else {
87                 /* security = domain should not fill in the dns or
88                    forest name */
89                 basic->dns_domain = NULL;
90                 basic->forest = NULL;
91         }
92
93         *info = basic;
94
95         return WERR_OK;
96 }
97
98 /********************************************************************
99  Implement the _dssetup_DsRoleGetPrimaryDomainInformation() call
100  ********************************************************************/
101
102 WERROR _dssetup_DsRoleGetPrimaryDomainInformation(struct pipes_struct *p,
103                                                   struct dssetup_DsRoleGetPrimaryDomainInformation *r)
104 {
105         WERROR werr = WERR_OK;
106
107         switch (r->in.level) {
108
109                 case DS_ROLE_BASIC_INFORMATION: {
110                         struct dssetup_DsRolePrimaryDomInfoBasic *basic = NULL;
111                         werr = fill_dsrole_dominfo_basic(p->mem_ctx, &basic);
112                         if (W_ERROR_IS_OK(werr)) {
113                                 r->out.info->basic = *basic;
114                         }
115                         break;
116                 }
117                 default:
118                         DEBUG(0,("_dssetup_DsRoleGetPrimaryDomainInformation: "
119                                 "Unknown info level [%d]!\n", r->in.level));
120                         werr = WERR_UNKNOWN_LEVEL;
121         }
122
123         return werr;
124 }
125
126 /****************************************************************
127 ****************************************************************/
128
129 WERROR _dssetup_DsRoleDnsNameToFlatName(struct pipes_struct *p,
130                                         struct dssetup_DsRoleDnsNameToFlatName *r)
131 {
132         p->rng_fault_state = true;
133         return WERR_NOT_SUPPORTED;
134 }
135
136 /****************************************************************
137 ****************************************************************/
138
139 WERROR _dssetup_DsRoleDcAsDc(struct pipes_struct *p,
140                              struct dssetup_DsRoleDcAsDc *r)
141 {
142         p->rng_fault_state = true;
143         return WERR_NOT_SUPPORTED;
144 }
145
146 /****************************************************************
147 ****************************************************************/
148
149 WERROR _dssetup_DsRoleDcAsReplica(struct pipes_struct *p,
150                                   struct dssetup_DsRoleDcAsReplica *r)
151 {
152         p->rng_fault_state = true;
153         return WERR_NOT_SUPPORTED;
154 }
155
156 /****************************************************************
157 ****************************************************************/
158
159 WERROR _dssetup_DsRoleDemoteDc(struct pipes_struct *p,
160                                struct dssetup_DsRoleDemoteDc *r)
161 {
162         p->rng_fault_state = true;
163         return WERR_NOT_SUPPORTED;
164 }
165
166 /****************************************************************
167 ****************************************************************/
168
169 WERROR _dssetup_DsRoleGetDcOperationProgress(struct pipes_struct *p,
170                                              struct dssetup_DsRoleGetDcOperationProgress *r)
171 {
172         p->rng_fault_state = true;
173         return WERR_NOT_SUPPORTED;
174 }
175
176 /****************************************************************
177 ****************************************************************/
178
179 WERROR _dssetup_DsRoleGetDcOperationResults(struct pipes_struct *p,
180                                             struct dssetup_DsRoleGetDcOperationResults *r)
181 {
182         p->rng_fault_state = true;
183         return WERR_NOT_SUPPORTED;
184 }
185
186 /****************************************************************
187 ****************************************************************/
188
189 WERROR _dssetup_DsRoleCancel(struct pipes_struct *p,
190                              struct dssetup_DsRoleCancel *r)
191 {
192         p->rng_fault_state = true;
193         return WERR_NOT_SUPPORTED;
194 }
195
196 /****************************************************************
197 ****************************************************************/
198
199 WERROR _dssetup_DsRoleServerSaveStateForUpgrade(struct pipes_struct *p,
200                                                 struct dssetup_DsRoleServerSaveStateForUpgrade *r)
201 {
202         p->rng_fault_state = true;
203         return WERR_NOT_SUPPORTED;
204 }
205
206 /****************************************************************
207 ****************************************************************/
208
209 WERROR _dssetup_DsRoleUpgradeDownlevelServer(struct pipes_struct *p,
210                                              struct dssetup_DsRoleUpgradeDownlevelServer *r)
211 {
212         p->rng_fault_state = true;
213         return WERR_NOT_SUPPORTED;
214 }
215
216 /****************************************************************
217 ****************************************************************/
218
219 WERROR _dssetup_DsRoleAbortDownlevelServerUpgrade(struct pipes_struct *p,
220                                                   struct dssetup_DsRoleAbortDownlevelServerUpgrade *r)
221 {
222         p->rng_fault_state = true;
223         return WERR_NOT_SUPPORTED;
224 }
225