1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | idmap PASSDB backend
|
---|
5 |
|
---|
6 | Copyright (C) Simo Sorce 2006
|
---|
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 |
|
---|
24 | #undef DBGC_CLASS
|
---|
25 | #define DBGC_CLASS DBGC_IDMAP
|
---|
26 |
|
---|
27 | /*****************************
|
---|
28 | Initialise idmap database.
|
---|
29 | *****************************/
|
---|
30 |
|
---|
31 | static NTSTATUS idmap_pdb_init(struct idmap_domain *dom, const char *params)
|
---|
32 | {
|
---|
33 | return NT_STATUS_OK;
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**********************************
|
---|
37 | lookup a set of unix ids.
|
---|
38 | **********************************/
|
---|
39 |
|
---|
40 | static NTSTATUS idmap_pdb_unixids_to_sids(struct idmap_domain *dom, struct id_map **ids)
|
---|
41 | {
|
---|
42 | int i;
|
---|
43 |
|
---|
44 | for (i = 0; ids[i]; i++) {
|
---|
45 |
|
---|
46 | /* unmapped by default */
|
---|
47 | ids[i]->status = ID_UNMAPPED;
|
---|
48 |
|
---|
49 | switch (ids[i]->xid.type) {
|
---|
50 | case ID_TYPE_UID:
|
---|
51 | if (pdb_uid_to_sid((uid_t)ids[i]->xid.id, ids[i]->sid)) {
|
---|
52 | ids[i]->status = ID_MAPPED;
|
---|
53 | }
|
---|
54 | break;
|
---|
55 | case ID_TYPE_GID:
|
---|
56 | if (pdb_gid_to_sid((gid_t)ids[i]->xid.id, ids[i]->sid)) {
|
---|
57 | ids[i]->status = ID_MAPPED;
|
---|
58 | }
|
---|
59 | break;
|
---|
60 | default: /* ?? */
|
---|
61 | ids[i]->status = ID_UNKNOWN;
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | return NT_STATUS_OK;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**********************************
|
---|
69 | lookup a set of sids.
|
---|
70 | **********************************/
|
---|
71 |
|
---|
72 | static NTSTATUS idmap_pdb_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids)
|
---|
73 | {
|
---|
74 | int i;
|
---|
75 |
|
---|
76 | for (i = 0; ids[i]; i++) {
|
---|
77 | enum lsa_SidType type;
|
---|
78 | union unid_t id;
|
---|
79 |
|
---|
80 | if (pdb_sid_to_id(ids[i]->sid, &id, &type)) {
|
---|
81 | switch (type) {
|
---|
82 | case SID_NAME_USER:
|
---|
83 | ids[i]->xid.id = id.uid;
|
---|
84 | ids[i]->xid.type = ID_TYPE_UID;
|
---|
85 | ids[i]->status = ID_MAPPED;
|
---|
86 | break;
|
---|
87 |
|
---|
88 | case SID_NAME_DOM_GRP:
|
---|
89 | case SID_NAME_ALIAS:
|
---|
90 | case SID_NAME_WKN_GRP:
|
---|
91 | ids[i]->xid.id = id.gid;
|
---|
92 | ids[i]->xid.type = ID_TYPE_GID;
|
---|
93 | ids[i]->status = ID_MAPPED;
|
---|
94 | break;
|
---|
95 |
|
---|
96 | default: /* ?? */
|
---|
97 | /* make sure it is marked as unmapped */
|
---|
98 | ids[i]->status = ID_UNKNOWN;
|
---|
99 | break;
|
---|
100 | }
|
---|
101 | } else {
|
---|
102 | /* Query Failed */
|
---|
103 | ids[i]->status = ID_UNMAPPED;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | return NT_STATUS_OK;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**********************************
|
---|
111 | Close the idmap tdb instance
|
---|
112 | **********************************/
|
---|
113 |
|
---|
114 | static NTSTATUS idmap_pdb_close(struct idmap_domain *dom)
|
---|
115 | {
|
---|
116 | return NT_STATUS_OK;
|
---|
117 | }
|
---|
118 |
|
---|
119 | static struct idmap_methods passdb_methods = {
|
---|
120 |
|
---|
121 | .init = idmap_pdb_init,
|
---|
122 | .unixids_to_sids = idmap_pdb_unixids_to_sids,
|
---|
123 | .sids_to_unixids = idmap_pdb_sids_to_unixids,
|
---|
124 | .close_fn =idmap_pdb_close
|
---|
125 | };
|
---|
126 |
|
---|
127 | NTSTATUS idmap_passdb_init(void)
|
---|
128 | {
|
---|
129 | return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "passdb", &passdb_methods);
|
---|
130 | }
|
---|