some more idmapping :)
authorSimo Sorce <idra@samba.org>
Sat, 5 Apr 2003 08:53:23 +0000 (08:53 +0000)
committerSimo Sorce <idra@samba.org>
Sat, 5 Apr 2003 08:53:23 +0000 (08:53 +0000)
(This used to be commit 5ac94535d7b7ce0cc0d44b9a77d6e42ddfd0cd26)

source3/auth/auth_util.c
source3/python/py_winbind.c
source3/sam/idmap_winbind.c

index a3ca0b226f287d2f3ee79f734448ea1d0bf36fb6..ddb833a0e56df3597376f0c0ac2308d0e3b3d6c1 100644 (file)
@@ -869,8 +869,8 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
 
        struct passwd *passwd;
 
-       uid_t uid;
-       gid_t gid;
+       unid_t u_id, g_id;
+       int u_type, g_type;
 
        int n_lgroupSIDs;
        DOM_SID *lgroupSIDs   = NULL;
@@ -907,9 +907,11 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
                domain = domain;
        }
 
-       if (winbind_sid_to_uid(&uid, &user_sid) 
-           && winbind_sid_to_gid(&gid, &group_sid) 
-           && ((passwd = getpwuid_alloc(uid)))) {
+       u_type = ID_USERID;
+       g_type = ID_GROUPID;
+       if (NT_STATUS_IS_OK(idmap_get_id_from_sid(&u_id, &u_type, &user_sid))
+           && NT_STATUS_IS_OK(idmap_get_id_from_sid(&g_id, &g_type, &group_sid))
+           && ((passwd = getpwuid_alloc(u_id.uid)))) {
                nt_status = pdb_init_sam_pw(&sam_account, passwd);
                passwd_free(&passwd);
        } else {
index db66be2321a0f638519484b41ce0c8002fd90c3d..0c40861c7012c638bb410bb4eec1f37c577a87b4 100644 (file)
@@ -261,12 +261,12 @@ static PyObject *py_config_dict(void)
 
        /* Winbind uid/gid range */
 
-       if (lp_winbind_uid(&ulow, &uhi)) {
+       if (lp_idmap_uid(&ulow, &uhi)) {
                PyDict_SetItemString(result, "uid_low", PyInt_FromLong(ulow));
                PyDict_SetItemString(result, "uid_high", PyInt_FromLong(uhi));
        }
 
-       if (lp_winbind_gid(&glow, &ghi)) {
+       if (lp_idmap_gid(&glow, &ghi)) {
                PyDict_SetItemString(result, "gid_low", PyInt_FromLong(glow));
                PyDict_SetItemString(result, "gid_high", PyInt_FromLong(ghi));
        }
index a5ba658674938b3393f4038eb748969be0e76755..c2c46cfb57980747cb0704cae60c20c9a2266883 100644 (file)
 */
 
 #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) {
+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;
+       fstring sid_str;
+
+       ZERO_STRUCT(request);
+       ZERO_STRUCT(response);
+
        switch (id_type & ID_TYPEMASK) {
                case ID_USERID:
-                       if (winbind_uid_to_sid(sid, id.uid)) {
-                               return NT_STATUS_OK;
-                       }
+                       request.data.uid = id.uid;
+                       operation = WINBINDD_UID_TO_SID;
                        break;
                case ID_GROUPID:
-                       if (winbind_gid_to_sid(sid, id.gid)) {
-                               return NT_STATUS_OK;
-                       }
+                       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) {
+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;
+       }
+
+       ZERO_STRUCT(request);
+       ZERO_STRUCT(response);
+
        switch (*id_type & ID_TYPEMASK) {
                case ID_USERID:
-                       if (winbind_sid_to_uid(&((*id).uid), sid)) {
-                               return NT_STATUS_OK;
-                       }
+                       operation = WINBINDD_SID_TO_UID;
                        break;
                case ID_GROUPID:
-                       if (winbind_sid_to_gid(&((*id).gid), sid)) {
-                               return NT_STATUS_OK;
-                       }
+                       operation = WINBINDD_SID_TO_GID;
                        break;
                default:
-                       if (winbind_sid_to_uid(&((*id).uid), sid) ||
-                           winbind_sid_to_gid(&((*id).gid), sid)) {
-                               return NT_STATUS_OK;
-                       }
+                       return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       /* 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;