s3-printing: Document the printer list functions.
[Samba/bjacke.git] / source3 / winbindd / idmap_passdb.c
blobece1b42122caeecae58533db18130c389ca43638
1 /*
2 Unix SMB/CIFS implementation.
4 idmap PASSDB backend
6 Copyright (C) Simo Sorce 2006
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/>.
22 #include "includes.h"
23 #include "idmap.h"
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_IDMAP
28 /*****************************
29 Initialise idmap database.
30 *****************************/
32 static NTSTATUS idmap_pdb_init(struct idmap_domain *dom, const char *params)
34 return NT_STATUS_OK;
37 /**********************************
38 lookup a set of unix ids.
39 **********************************/
41 static NTSTATUS idmap_pdb_unixids_to_sids(struct idmap_domain *dom, struct id_map **ids)
43 int i;
45 for (i = 0; ids[i]; i++) {
47 /* unmapped by default */
48 ids[i]->status = ID_UNMAPPED;
50 switch (ids[i]->xid.type) {
51 case ID_TYPE_UID:
52 if (pdb_uid_to_sid((uid_t)ids[i]->xid.id, ids[i]->sid)) {
53 ids[i]->status = ID_MAPPED;
55 break;
56 case ID_TYPE_GID:
57 if (pdb_gid_to_sid((gid_t)ids[i]->xid.id, ids[i]->sid)) {
58 ids[i]->status = ID_MAPPED;
60 break;
61 default: /* ?? */
62 ids[i]->status = ID_UNKNOWN;
66 return NT_STATUS_OK;
69 /**********************************
70 lookup a set of sids.
71 **********************************/
73 static NTSTATUS idmap_pdb_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids)
75 int i;
77 for (i = 0; ids[i]; i++) {
78 enum lsa_SidType type;
79 union unid_t id;
81 if (pdb_sid_to_id(ids[i]->sid, &id, &type)) {
82 switch (type) {
83 case SID_NAME_USER:
84 ids[i]->xid.id = id.uid;
85 ids[i]->xid.type = ID_TYPE_UID;
86 ids[i]->status = ID_MAPPED;
87 break;
89 case SID_NAME_DOM_GRP:
90 case SID_NAME_ALIAS:
91 case SID_NAME_WKN_GRP:
92 ids[i]->xid.id = id.gid;
93 ids[i]->xid.type = ID_TYPE_GID;
94 ids[i]->status = ID_MAPPED;
95 break;
97 default: /* ?? */
98 /* make sure it is marked as unmapped */
99 ids[i]->status = ID_UNKNOWN;
100 break;
102 } else {
103 /* Query Failed */
104 ids[i]->status = ID_UNMAPPED;
108 return NT_STATUS_OK;
111 /**********************************
112 Close the idmap tdb instance
113 **********************************/
115 static NTSTATUS idmap_pdb_close(struct idmap_domain *dom)
117 return NT_STATUS_OK;
120 static struct idmap_methods passdb_methods = {
122 .init = idmap_pdb_init,
123 .unixids_to_sids = idmap_pdb_unixids_to_sids,
124 .sids_to_unixids = idmap_pdb_sids_to_unixids,
125 .close_fn =idmap_pdb_close
128 NTSTATUS idmap_passdb_init(void)
130 return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "passdb", &passdb_methods);