2 Unix SMB/CIFS implementation.
4 implement the DsWriteAccountSpn call
6 Copyright (C) Stefan Metzmacher 2009
7 Copyright (C) Andrew Tridgell 2010
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "rpc_server/dcerpc_server.h"
25 #include "dsdb/samdb/samdb.h"
26 #include "rpc_server/drsuapi/dcesrv_drsuapi.h"
29 drsuapi_DsWriteAccountSpn
31 WERROR dcesrv_drsuapi_DsWriteAccountSpn(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
32 struct drsuapi_DsWriteAccountSpn *r)
34 struct drsuapi_bind_state *b_state;
35 struct dcesrv_handle *h;
37 *r->out.level_out = r->in.level;
39 DCESRV_PULL_HANDLE_WERR(h, r->in.bind_handle, DRSUAPI_BIND_HANDLE);
42 r->out.res = talloc(mem_ctx, union drsuapi_DsWriteAccountSpnResult);
43 W_ERROR_HAVE_NO_MEMORY(r->out.res);
45 switch (r->in.level) {
47 struct drsuapi_DsWriteAccountSpnRequest1 *req;
48 struct ldb_message *msg;
52 req = &r->in.req->req1;
55 msg = ldb_msg_new(mem_ctx);
60 msg->dn = ldb_dn_new(msg, b_state->sam_ctx, req->object_dn);
61 if ( ! ldb_dn_validate(msg->dn)) {
62 r->out.res->res1.status = WERR_OK;
67 for (i = 0; i < count; i++) {
68 ret = samdb_msg_add_string(b_state->sam_ctx,
69 msg, msg, "servicePrincipalName",
70 req->spn_names[i].str);
71 if (ret != LDB_SUCCESS) {
77 if (msg->num_elements == 0) {
78 DEBUG(2,("No SPNs need changing on %s\n", ldb_dn_get_linearized(msg->dn)));
79 r->out.res->res1.status = WERR_OK;
83 for (i=0;i<msg->num_elements;i++) {
84 switch (req->operation) {
85 case DRSUAPI_DS_SPN_OPERATION_ADD:
86 msg->elements[i].flags = LDB_FLAG_MOD_ADD;
88 case DRSUAPI_DS_SPN_OPERATION_REPLACE:
89 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
91 case DRSUAPI_DS_SPN_OPERATION_DELETE:
92 msg->elements[i].flags = LDB_FLAG_MOD_DELETE;
97 /* Apply to database */
98 ret = dsdb_modify_permissive(b_state->sam_ctx, msg);
100 DEBUG(0,("Failed to modify SPNs on %s: %s\n",
101 ldb_dn_get_linearized(msg->dn),
102 ldb_errstring(b_state->sam_ctx)));
103 r->out.res->res1.status = WERR_ACCESS_DENIED;
105 DEBUG(2,("Modified %u SPNs on %s\n", spn_count, ldb_dn_get_linearized(msg->dn)));
106 r->out.res->res1.status = WERR_OK;
113 return WERR_UNKNOWN_LEVEL;