s3:idmap_ad: use range from idmap_domain in idmap_ad_sids_to_unixids()
[amitay/samba.git] / source3 / winbindd / idmap_ad.c
index 5c29ba0b223dfd9aa604aaa11a9038634b0e7549..26d71401536473b6c37030d3190788c6b90b5e84 100644 (file)
 
 #include "includes.h"
 #include "winbindd.h"
+#include "../libds/common/flags.h"
+#include "ads.h"
+#include "libads/ldap_schema.h"
+#include "nss_info.h"
+#include "secrets.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_IDMAP
@@ -267,7 +272,7 @@ static struct id_map *find_map_by_id(struct id_map **maps, enum id_type type, ui
  Search up to IDMAP_AD_MAX_IDS entries in maps for a match
  ***********************************************************************/
 
-static struct id_map *find_map_by_sid(struct id_map **maps, DOM_SID *sid)
+static struct id_map *find_map_by_sid(struct id_map **maps, struct dom_sid *sid)
 {
        int i;
 
@@ -400,7 +405,7 @@ again:
 
        entry = res;
        for (i = 0; (i < count) && entry; i++) {
-               DOM_SID sid;
+               struct dom_sid sid;
                enum id_type type;
                struct id_map *map;
                uint32_t id;
@@ -453,11 +458,9 @@ again:
                        continue;
                }
 
-               if ((id == 0) ||
-                   (ctx->filter_low_id && (id < ctx->filter_low_id)) ||
-                   (ctx->filter_high_id && (id > ctx->filter_high_id))) {
+               if (!idmap_unix_id_is_in_range(id, dom)) {
                        DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n",
-                               id, ctx->filter_low_id, ctx->filter_high_id));
+                               id, dom->low_id, dom->high_id));
                        continue;
                }
 
@@ -570,10 +573,10 @@ again:
 
                ids[idx]->status = ID_UNKNOWN;
 
-               sidstr = sid_binstring(ids[idx]->sid);
+               sidstr = sid_binstring(talloc_tos(), ids[idx]->sid);
                filter = talloc_asprintf_append_buffer(filter, "(objectSid=%s)", sidstr);
                        
-               free(sidstr);
+               TALLOC_FREE(sidstr);
                CHECK_ALLOC_DONE(filter);
        }
        filter = talloc_asprintf_append_buffer(filter, "))");
@@ -593,7 +596,7 @@ again:
 
        entry = res;    
        for (i = 0; (i < count) && entry; i++) {
-               DOM_SID sid;
+               struct dom_sid sid;
                enum id_type type;
                struct id_map *map;
                uint32_t id;
@@ -651,11 +654,9 @@ again:
                        DEBUG(1, ("Could not get unix ID\n"));
                        continue;
                }
-               if ((id == 0) ||
-                   (ctx->filter_low_id && (id < ctx->filter_low_id)) ||
-                   (ctx->filter_high_id && (id > ctx->filter_high_id))) {
+               if (!idmap_unix_id_is_in_range(id, dom)) {
                        DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n",
-                               id, ctx->filter_low_id, ctx->filter_high_id));
+                               id, dom->low_id, dom->high_id));
                        continue;
                }
 
@@ -818,13 +819,13 @@ static NTSTATUS nss_rfc2307_init( struct nss_domain_entry *e )
  ***********************************************************************/
 
 static NTSTATUS nss_ad_get_info( struct nss_domain_entry *e, 
-                                 const DOM_SID *sid, 
+                                 const struct dom_sid *sid,
                                  TALLOC_CTX *mem_ctx,
                                  ADS_STRUCT *ads, 
                                  LDAPMessage *msg,
-                                 char **homedir,
-                                 char **shell, 
-                                 char **gecos,
+                                 const char **homedir,
+                                 const char **shell,
+                                 const char **gecos,
                                  uint32 *gid )
 {
        const char *attrs[] = {NULL, /* attr_homedir */
@@ -894,9 +895,9 @@ static NTSTATUS nss_ad_get_info( struct nss_domain_entry *e,
        attrs[2] = ctx->ad_schema->posix_gecos_attr;
        attrs[3] = ctx->ad_schema->posix_gidnumber_attr;
 
-       sidstr = sid_binstring(sid);
+       sidstr = sid_binstring(mem_ctx, sid);
        filter = talloc_asprintf(mem_ctx, "(objectSid=%s)", sidstr);
-       SAFE_FREE(sidstr);
+       TALLOC_FREE(sidstr);
 
        if (!filter) {
                nt_status = NT_STATUS_NO_MEMORY;