cde2b4d69ab02069a39d8a17e23de8a66e9e738a
[samba.git] / source4 / rpc_server / dssetup / dcesrv_dssetup.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    endpoint server for the dssetup pipe
5
6    Copyright (C) Andrew Tridgell 2004
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "rpc_server/dcerpc_server.h"
25 #include "librpc/gen_ndr/ndr_dssetup.h"
26 #include "rpc_server/common/common.h"
27
28
29 /* 
30   ds_RolerGetPrimaryDomainInformation 
31 */
32 static WERROR ds_RolerGetPrimaryDomainInformation(struct dcesrv_call_state *dce_call, 
33                                                   TALLOC_CTX *mem_ctx,
34                                                   struct ds_RolerGetPrimaryDomainInformation *r)
35 {
36         WERROR err = WERR_OK;
37         void *sam_ctx;
38         const char * const attrs[] = { "dnsDomain", "objectGUID", "name", NULL };
39         int ret;
40         struct ldb_message **res;
41
42         sam_ctx = samdb_connect(mem_ctx);
43         if (sam_ctx == NULL) {
44                 return WERR_SERVER_UNAVAILABLE;
45         }
46
47         ret = samdb_search(sam_ctx, mem_ctx, NULL, &res, attrs,
48                            "(&(objectClass=domainDNS)(!(objectClass=builtinDomain)))");
49         if (ret != 1) {
50                 return WERR_SERVER_UNAVAILABLE;
51         }
52
53         r->out.info = talloc_p(mem_ctx, union ds_DomainInformation);
54         if (r->out.info == NULL) {
55                 return WERR_NOMEM;
56         }
57
58         switch (r->in.level) {
59         case DS_BASIC_INFORMATION:
60                 /* incorrect,  but needed for the moment */
61                 r->out.info->basic.role        = DS_ROLE_MEMBER_SERVER; 
62                 r->out.info->basic.flags       = 0x01000003;
63                 r->out.info->basic.domain      = samdb_result_string(res[0], "name", NULL);
64                 r->out.info->basic.dns_domain  = samdb_result_string(res[0], "dnsDomain", NULL);
65                 r->out.info->basic.forest      = samdb_result_string(res[0], "dnsDomain", NULL);
66                 r->out.info->basic.domain_guid = samdb_result_guid(res[0], "objectGUID");
67                 break;
68
69         case DS_UPGRADE_STATUS:
70                 r->out.info->upgrade.upgrading     = DS_NOT_UPGRADING;
71                 r->out.info->upgrade.previous_role = DS_PREVIOUS_UNKNOWN;
72                 break;
73
74         case DS_ROLE_OP_STATUS:
75                 r->out.info->status.status = DS_STATUS_IDLE;
76                 break;
77
78         default:
79                 err = WERR_INVALID_PARAM;
80                 break;
81         }
82
83         return err;
84 }
85
86
87 /*****************************************
88 NOTE! The remaining calls below were
89 removed in w2k3, so the DCESRV_FAULT()
90 replies are the correct implementation. Do
91 not try and fill these in with anything else
92 ******************************************/
93
94 /* 
95   ds_RolerDnsNameToFlatName 
96 */
97 static WERROR ds_RolerDnsNameToFlatName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
98                                         struct ds_RolerDnsNameToFlatName *r)
99 {
100         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
101 }
102
103
104 /* 
105   ds_RolerDcAsDc 
106 */
107 static WERROR ds_RolerDcAsDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
108                              struct ds_RolerDcAsDc *r)
109 {
110         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
111 }
112
113
114 /* 
115   ds_RolerDcAsReplica 
116 */
117 static WERROR ds_RolerDcAsReplica(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
118                                   struct ds_RolerDcAsReplica *r)
119 {
120         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
121 }
122
123
124 /* 
125   ds_RolerDemoteDc 
126 */
127 static WERROR ds_RolerDemoteDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
128                                struct ds_RolerDemoteDc *r)
129 {
130         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
131 }
132
133
134 /* 
135   ds_RolerGetDcOperationProgress 
136 */
137 static WERROR ds_RolerGetDcOperationProgress(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
138                                              struct ds_RolerGetDcOperationProgress *r)
139 {
140         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
141 }
142
143
144 /* 
145   ds_RolerGetDcOperationResults 
146 */
147 static WERROR ds_RolerGetDcOperationResults(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
148                                             struct ds_RolerGetDcOperationResults *r)
149 {
150         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
151 }
152
153
154 /* 
155   ds_RolerCancel 
156 */
157 static WERROR ds_RolerCancel(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
158                              struct ds_RolerCancel *r)
159 {
160         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
161 }
162
163
164 /* 
165   ds_RolerServerSaveStateForUpgrade 
166 */
167 static WERROR ds_RolerServerSaveStateForUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
168                                                 struct ds_RolerServerSaveStateForUpgrade *r)
169 {
170         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
171 }
172
173
174 /* 
175   ds_RolerUpgradeDownlevelServer 
176 */
177 static WERROR ds_RolerUpgradeDownlevelServer(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
178                                              struct ds_RolerUpgradeDownlevelServer *r)
179 {
180         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
181 }
182
183
184 /* 
185   ds_RolerAbortDownlevelServerUpgrade 
186 */
187 static WERROR ds_RolerAbortDownlevelServerUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
188                                                   struct ds_RolerAbortDownlevelServerUpgrade *r)
189 {
190         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
191 }
192
193
194 /* include the generated boilerplate */
195 #include "librpc/gen_ndr/ndr_dssetup_s.c"