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