2 * Unix SMB/CIFS implementation.
4 * ID mapping: abstract r/w new-mapping mechanism
6 * Copyright (C) Michael Adam 2010
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 3 of the License, or
11 * (at your option) any later version.
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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "libcli/security/dom_sid.h"
29 #define DBGC_CLASS DBGC_IDMAP
31 NTSTATUS
idmap_rw_new_mapping(struct idmap_domain
*dom
,
32 struct idmap_rw_ops
*ops
,
35 struct dom_sid_buf buf
;
39 return NT_STATUS_INVALID_PARAMETER
;
42 if (map
->sid
== NULL
) {
43 return NT_STATUS_INVALID_PARAMETER
;
46 switch (map
->xid
.type
) {
47 case ID_TYPE_NOT_SPECIFIED
:
49 * We need to know if we need a user or group mapping.
50 * Ask the winbindd parent to provide a valid type hint.
52 DBG_INFO("%s ID_TYPE_NOT_SPECIFIED => ID_REQUIRE_TYPE\n",
53 dom_sid_str_buf(map
->sid
, &buf
));
54 map
->status
= ID_REQUIRE_TYPE
;
55 return NT_STATUS_SOME_NOT_MAPPED
;
59 * For now we still require
60 * an explicit type as hint
61 * and don't support ID_TYPE_BOTH
63 DBG_INFO("%s ID_TYPE_BOTH => ID_REQUIRE_TYPE\n",
64 dom_sid_str_buf(map
->sid
, &buf
));
65 map
->status
= ID_REQUIRE_TYPE
;
66 return NT_STATUS_SOME_NOT_MAPPED
;
75 return NT_STATUS_INVALID_PARAMETER
;
78 status
= ops
->get_new_id(dom
, &map
->xid
);
80 if (!NT_STATUS_IS_OK(status
)) {
81 DEBUG(3, ("Could not allocate id: %s\n", nt_errstr(status
)));
85 DEBUG(10, ("Setting mapping: %s <-> %s %lu\n",
86 dom_sid_str_buf(map
->sid
, &buf
),
87 (map
->xid
.type
== ID_TYPE_UID
) ? "UID" : "GID",
88 (unsigned long)map
->xid
.id
));
90 map
->status
= ID_MAPPED
;
91 status
= ops
->set_mapping(dom
, map
);
93 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
94 struct id_map
*ids
[2];
95 DEBUG(5, ("Mapping for %s exists - retrying to map sid\n",
96 dom_sid_str_buf(map
->sid
, &buf
)));
99 status
= dom
->methods
->sids_to_unixids(dom
, ids
);
102 if (!NT_STATUS_IS_OK(status
)) {
103 DEBUG(3, ("Could not store the new mapping: %s\n",