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