Some update and Fixes for typos.
[kai/samba.git] / source3 / sam / idmap_winbind.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    idmap Winbind backend
5
6    Copyright (C) Simo Sorce 2003
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 /* Get a sid from an id */
29 static NTSTATUS db_get_sid_from_id(DOM_SID *sid, unid_t id, int id_type) {
30         switch (id_type & ID_TYPEMASK) {
31                 case ID_USERID:
32                         if (winbind_uid_to_sid(sid, id.uid)) {
33                                 return NT_STATUS_OK;
34                         }
35                         break;
36                 case ID_GROUPID:
37                         if (winbind_gid_to_sid(sid, id.gid)) {
38                                 return NT_STATUS_OK;
39                         }
40                         break;
41                 default:
42                         return NT_STATUS_INVALID_PARAMETER;
43         }
44
45         return NT_STATUS_UNSUCCESSFUL;
46 }
47
48 /* Get an id from a sid */
49 static NTSTATUS db_get_id_from_sid(unid_t *id, int *id_type, const DOM_SID *sid) {
50         switch (*id_type & ID_TYPEMASK) {
51                 case ID_USERID:
52                         if (winbind_sid_to_uid(&((*id).uid), sid)) {
53                                 return NT_STATUS_OK;
54                         }
55                         break;
56                 case ID_GROUPID:
57                         if (winbind_sid_to_gid(&((*id).gid), sid)) {
58                                 return NT_STATUS_OK;
59                         }
60                         break;
61                 default:
62                         if (winbind_sid_to_uid(&((*id).uid), sid) ||
63                             winbind_sid_to_gid(&((*id).gid), sid)) {
64                                 return NT_STATUS_OK;
65                         }
66         }
67
68         return NT_STATUS_UNSUCCESSFUL;
69 }       
70
71 static NTSTATUS db_set_mapping(DOM_SID *sid, unid_t id, int id_type) {
72         return NT_STATUS_UNSUCCESSFUL;
73 }
74
75 /*****************************************************************************
76  Initialise idmap database. 
77 *****************************************************************************/
78 static NTSTATUS db_init(const char *db_name) {
79         return NT_STATUS_OK;
80 }
81
82 /* Close the tdb */
83 static NTSTATUS db_close(void) {
84         return NT_STATUS_OK;
85 }
86
87 static void db_status(void) {
88         return;
89 }
90
91 struct idmap_methods winbind_methods = {
92
93         db_init,
94         db_get_sid_from_id,
95         db_get_id_from_sid,
96         db_set_mapping,
97         db_close,
98         db_status
99
100 };
101
102 NTSTATUS idmap_reg_winbind(struct idmap_methods **meth)
103 {
104         *meth = &winbind_methods;
105
106         return NT_STATUS_OK;
107 }
108