r20597: Survive some of the notify mask tests.
[samba.git] / source3 / nsswitch / idmap_passdb.c
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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_IDMAP
27
28 /*****************************
29  Initialise idmap database. 
30 *****************************/
31
32 static NTSTATUS idmap_pdb_init(struct idmap_domain *dom, const char *compat_params)
33 {       
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         for (i = 0; ids[i]; i++) {
46                 switch (ids[i]->xid.type) {
47                 case ID_TYPE_UID:
48                         ids[i]->mapped = pdb_uid_to_sid((uid_t)ids[i]->xid.id, ids[i]->sid);
49                         break;
50                 case ID_TYPE_GID:
51                         ids[i]->mapped = pdb_gid_to_sid((gid_t)ids[i]->xid.id, ids[i]->sid);
52                         break;
53                 default: /* ?? */
54                         ids[i]->mapped = False;
55                 }
56         }
57
58         return NT_STATUS_OK;
59 }
60
61 /**********************************
62  lookup a set of sids. 
63 **********************************/
64
65 static NTSTATUS idmap_pdb_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids)
66 {
67         int i;
68
69         for (i = 0; ids[i]; i++) {
70                 enum lsa_SidType type;
71                 union unid_t id;
72                 
73                 if (pdb_sid_to_id(ids[i]->sid, &id, &type)) {
74                         switch (type) {
75                         case SID_NAME_USER:
76                                 ids[i]->xid.id = id.uid;
77                                 ids[i]->xid.type = ID_TYPE_UID;
78                                 ids[i]->mapped = True;
79                                 break;
80
81                         case SID_NAME_DOM_GRP:
82                         case SID_NAME_ALIAS:
83                         case SID_NAME_WKN_GRP:
84                                 ids[i]->xid.id = id.gid;
85                                 ids[i]->xid.type = ID_TYPE_GID;
86                                 ids[i]->mapped = True;
87                                 break;
88
89                         default: /* ?? */
90                                 /* make sure it is marked as unmapped */
91                                 ids[i]->mapped = False;
92                                 break;
93                         }
94                 } else {
95                         /* Query Failed */
96                         ids[i]->mapped = False;
97                 }
98         }
99
100         return NT_STATUS_OK;
101 }
102
103 /**********************************
104  Close the idmap tdb instance
105 **********************************/
106
107 static NTSTATUS idmap_pdb_close(struct idmap_domain *dom)
108 {
109         return NT_STATUS_OK;
110 }
111
112 static struct idmap_methods passdb_methods = {
113
114         .init = idmap_pdb_init,
115         .unixids_to_sids = idmap_pdb_unixids_to_sids,
116         .sids_to_unixids = idmap_pdb_sids_to_unixids,
117         .close_fn =idmap_pdb_close
118 };
119
120 NTSTATUS idmap_passdb_init(void)
121 {
122         return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "passdb", &passdb_methods);
123 }