| 1 | /*
|
|---|
| 2 | * Unix SMB/CIFS implementation.
|
|---|
| 3 | *
|
|---|
| 4 | * ID mapping: abstract r/w new-mapping mechanism
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (C) Michael Adam 2010
|
|---|
| 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 3 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, see <http://www.gnu.org/licenses/>.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 23 | #include "winbindd.h"
|
|---|
| 24 | #include "idmap.h"
|
|---|
| 25 | #include "idmap_rw.h"
|
|---|
| 26 |
|
|---|
| 27 | #undef DBGC_CLASS
|
|---|
| 28 | #define DBGC_CLASS DBGC_IDMAP
|
|---|
| 29 |
|
|---|
| 30 | NTSTATUS idmap_rw_new_mapping(struct idmap_domain *dom,
|
|---|
| 31 | struct idmap_rw_ops *ops,
|
|---|
| 32 | struct id_map *map)
|
|---|
| 33 | {
|
|---|
| 34 | NTSTATUS status;
|
|---|
| 35 |
|
|---|
| 36 | if (map == NULL) {
|
|---|
| 37 | return NT_STATUS_INVALID_PARAMETER;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | if ((map->xid.type != ID_TYPE_UID) && (map->xid.type != ID_TYPE_GID)) {
|
|---|
| 41 | return NT_STATUS_INVALID_PARAMETER;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | if (map->sid == NULL) {
|
|---|
| 45 | return NT_STATUS_INVALID_PARAMETER;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | status = ops->get_new_id(dom, &map->xid);
|
|---|
| 49 |
|
|---|
| 50 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 51 | DEBUG(3, ("Could not allocate id: %s\n", nt_errstr(status)));
|
|---|
| 52 | return status;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | DEBUG(10, ("Setting mapping: %s <-> %s %lu\n",
|
|---|
| 56 | sid_string_dbg(map->sid),
|
|---|
| 57 | (map->xid.type == ID_TYPE_UID) ? "UID" : "GID",
|
|---|
| 58 | (unsigned long)map->xid.id));
|
|---|
| 59 |
|
|---|
| 60 | map->status = ID_MAPPED;
|
|---|
| 61 | status = ops->set_mapping(dom, map);
|
|---|
| 62 |
|
|---|
| 63 | if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
|
|---|
| 64 | struct id_map *ids[2];
|
|---|
| 65 | DEBUG(5, ("Mapping for %s exists - retrying to map sid\n",
|
|---|
| 66 | sid_string_dbg(map->sid)));
|
|---|
| 67 | ids[0] = map;
|
|---|
| 68 | ids[1] = NULL;
|
|---|
| 69 | status = dom->methods->sids_to_unixids(dom, ids);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 73 | DEBUG(3, ("Could not store the new mapping: %s\n",
|
|---|
| 74 | nt_errstr(status)));
|
|---|
| 75 | return status;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | return NT_STATUS_OK;
|
|---|
| 79 | }
|
|---|