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