s3:idmap_ldap: rename idmap_ldap_allocate_id to idmap_ldap_allocate_id_internal
[samba.git] / source3 / winbindd / idmap_nss.c
index 5d5bd8c65ea1e9480f1bbf58cd8e8e435ac679fd..5cd2bc24c36cc9053440297087c431688a14e9fd 100644 (file)
 */
 
 #include "includes.h"
+#include "system/passwd.h"
 #include "winbindd.h"
 #include "nsswitch/winbind_client.h"
 #include "idmap.h"
+#include "lib/winbind_util.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_IDMAP
@@ -31,8 +33,7 @@
  Initialise idmap database. 
 *****************************/
 
-static NTSTATUS idmap_nss_int_init(struct idmap_domain *dom,
-                                  const char *params)
+static NTSTATUS idmap_nss_int_init(struct idmap_domain *dom)
 {      
        return NT_STATUS_OK;
 }
@@ -43,7 +44,6 @@ static NTSTATUS idmap_nss_int_init(struct idmap_domain *dom,
 
 static NTSTATUS idmap_nss_unixids_to_sids(struct idmap_domain *dom, struct id_map **ids)
 {
-       TALLOC_CTX *ctx;
        int i;
 
        /* initialize the status to avoid suprise */
@@ -51,12 +51,6 @@ static NTSTATUS idmap_nss_unixids_to_sids(struct idmap_domain *dom, struct id_ma
                ids[i]->status = ID_UNKNOWN;
        }
 
-       ctx = talloc_new(dom);
-       if ( ! ctx) {
-               DEBUG(0, ("Out of memory!\n"));
-               return NT_STATUS_NO_MEMORY;
-       }
-
        for (i = 0; ids[i]; i++) {
                struct passwd *pw;
                struct group *gr;
@@ -122,9 +116,6 @@ static NTSTATUS idmap_nss_unixids_to_sids(struct idmap_domain *dom, struct id_ma
                        break;
                }
        }
-
-
-       talloc_free(ctx);
        return NT_STATUS_OK;
 }
 
@@ -134,7 +125,6 @@ static NTSTATUS idmap_nss_unixids_to_sids(struct idmap_domain *dom, struct id_ma
 
 static NTSTATUS idmap_nss_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids)
 {
-       TALLOC_CTX *ctx;
        int i;
 
        /* initialize the status to avoid suprise */
@@ -142,23 +132,17 @@ static NTSTATUS idmap_nss_sids_to_unixids(struct idmap_domain *dom, struct id_ma
                ids[i]->status = ID_UNKNOWN;
        }
 
-       ctx = talloc_new(dom);
-       if ( ! ctx) {
-               DEBUG(0, ("Out of memory!\n"));
-               return NT_STATUS_NO_MEMORY;
-       }
-
        for (i = 0; ids[i]; i++) {
                struct group *gr;
                enum lsa_SidType type;
-               const char *dom_name = NULL;
-               const char *name = NULL;
+               char *name = NULL;
                bool ret;
 
                /* by default calls to winbindd are disabled
                   the following call will not recurse so this is safe */
                (void)winbind_on();
-               ret = winbind_lookup_sid(ctx, ids[i]->sid, &dom_name, &name, &type);
+               ret = winbind_lookup_sid(talloc_tos(), ids[i]->sid, NULL,
+                                        (const char **)&name, &type);
                (void)winbind_off();
 
                if (!ret) {
@@ -200,9 +184,8 @@ static NTSTATUS idmap_nss_sids_to_unixids(struct idmap_domain *dom, struct id_ma
                        ids[i]->status = ID_UNKNOWN;
                        break;
                }
+               TALLOC_FREE(name);
        }
-
-       talloc_free(ctx);
        return NT_STATUS_OK;
 }