add idmap_winbind unless I made a better way to solve SID type for domain
authorSimo Sorce <idra@samba.org>
Fri, 16 May 2003 06:20:33 +0000 (06:20 +0000)
committerSimo Sorce <idra@samba.org>
Fri, 16 May 2003 06:20:33 +0000 (06:20 +0000)
SIDs
(This used to be commit b24c0efc4b363cb0d4ed71588e9617d668c16be9)

source3/Makefile.in
source3/sam/idmap.c
source3/sam/idmap_winbind.c [new file with mode: 0644]

index f1c497663f67a7d991a50d1127a458a894eff0a1..b3183a620358c8a04170ac3d5899f4b348bfd8b0 100644 (file)
@@ -280,7 +280,7 @@ XML_OBJ = passdb/pdb_xml.o
 MYSQL_OBJ = passdb/pdb_mysql.o
 DEVEL_HELP_OBJ = modules/weird.o
 
-IDMAP_OBJ = sam/idmap.o sam/idmap_util.o sam/idmap_tdb.o
+IDMAP_OBJ = sam/idmap.o sam/idmap_util.o sam/idmap_tdb.o sam/idmap_winbind.o
 
 GROUPDB_OBJ = groupdb/mapping.o
 
index 9695e7b764e28e3f62b89b39a4d392158cd411d0..e2796e0864e4c8b2330820e86943f71e4d6220ed 100644 (file)
@@ -32,6 +32,7 @@ static struct {
        struct idmap_methods *methods;
 
 } remote_idmap_functions[] = {
+       { "winbind", idmap_reg_winbind, NULL },
        { NULL, NULL, NULL }
 };
 
diff --git a/source3/sam/idmap_winbind.c b/source3/sam/idmap_winbind.c
new file mode 100644 (file)
index 0000000..bc3c8ad
--- /dev/null
@@ -0,0 +1,155 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   idmap Winbind backend
+
+   Copyright (C) Simo Sorce 2003
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "nsswitch/winbind_nss.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_IDMAP
+
+extern DOM_SID global_sid_NULL;                        /* NULL sid */
+
+NSS_STATUS winbindd_request(int req_type,
+                                 struct winbindd_request *request,
+                                 struct winbindd_response *response);
+
+/* Get a sid from an id */
+static NTSTATUS db_get_sid_from_id(DOM_SID *sid, unid_t id, int id_type)
+{
+       struct winbindd_request request;
+       struct winbindd_response response;
+       int result, operation;
+
+       ZERO_STRUCT(request);
+       ZERO_STRUCT(response);
+
+       switch (id_type & ID_TYPEMASK) {
+               case ID_USERID:
+                       request.data.uid = id.uid;
+                       operation = WINBINDD_UID_TO_SID;
+                       break;
+               case ID_GROUPID:
+                       request.data.gid = id.gid;
+                       operation = WINBINDD_GID_TO_SID;
+                       break;
+               default:
+                       return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       /* Make The Request */
+       result = winbindd_request(operation, &request, &response);
+       if (result == NSS_STATUS_SUCCESS) {
+               if (!string_to_sid(sid, response.data.sid.sid)) {
+                       return NT_STATUS_INVALID_SID;
+               }
+               return NT_STATUS_OK;
+       } else {
+               sid_copy(sid, &global_sid_NULL);
+       }
+
+       return NT_STATUS_UNSUCCESSFUL;
+}
+
+/* Get an id from a sid */
+static NTSTATUS db_get_id_from_sid(unid_t *id, int *id_type, const DOM_SID *sid)
+{
+       struct winbindd_request request;
+       struct winbindd_response response;
+       int result, operation;
+       fstring sid_str;
+
+       if (!id || !id_type) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       /* setup request */
+
+       ZERO_STRUCT(request);
+       ZERO_STRUCT(response);
+
+       switch (*id_type & ID_TYPEMASK) {
+               case ID_USERID:
+                       operation = WINBINDD_SID_TO_UID;
+                       break;
+               case ID_GROUPID:
+                       operation = WINBINDD_SID_TO_GID;
+                       break;
+               default:
+                       return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       sid_to_string(sid_str, sid);
+       fstrcpy(request.data.sid, sid_str);
+
+       /* Make The Request */
+       result = winbindd_request(operation, &request, &response);
+
+       if (result == NSS_STATUS_SUCCESS) {
+               if (operation == WINBINDD_SID_TO_UID) {
+                       (*id).uid = response.data.uid;
+               } else {
+                       (*id).gid = response.data.gid;
+               }
+               return NT_STATUS_OK;
+       }
+
+       return NT_STATUS_UNSUCCESSFUL;
+}      
+
+static NTSTATUS db_set_mapping(const DOM_SID *sid, unid_t id, int id_type) {
+       return NT_STATUS_UNSUCCESSFUL;
+}
+
+/*****************************************************************************
+ Initialise idmap database. 
+*****************************************************************************/
+static NTSTATUS db_init(void) {
+       return NT_STATUS_OK;
+}
+
+/* Close the tdb */
+static NTSTATUS db_close(void) {
+       return NT_STATUS_OK;
+}
+
+static void db_status(void) {
+       return;
+}
+
+struct idmap_methods winbind_methods = {
+
+       db_init,
+       db_get_sid_from_id,
+       db_get_id_from_sid,
+       db_set_mapping,
+       db_close,
+       db_status
+
+};
+
+NTSTATUS idmap_reg_winbind(struct idmap_methods **meth)
+{
+       *meth = &winbind_methods;
+
+       return NT_STATUS_OK;
+}
+