s3:idmap_ad: untangle two assignments from checks
[metze/samba/wip.git] / source3 / winbindd / idmap_ad.c
index 967a36b3cef93e7ed060fe69d15ed7203de47cfd..d2581d1a9e90032fdb6cec1dd374d189140afc78 100644 (file)
@@ -43,8 +43,6 @@
 } while (0)
 
 struct idmap_ad_context {
-       uint32_t filter_low_id;
-       uint32_t filter_high_id;
        ADS_STRUCT *ads;
        struct posix_schema *ad_schema;
        enum wb_posix_mapping ad_map_type; /* WB_POSIX_MAP_UNKNOWN */
@@ -197,31 +195,21 @@ static NTSTATUS idmap_ad_initialize(struct idmap_domain *dom,
 {
        struct idmap_ad_context *ctx;
        char *config_option;
-       const char *range = NULL;
        const char *schema_mode = NULL; 
 
-       if ( (ctx = TALLOC_ZERO_P(dom, struct idmap_ad_context)) == NULL ) {
+       ctx = TALLOC_ZERO_P(dom, struct idmap_ad_context);
+       if (ctx == NULL) {
                DEBUG(0, ("Out of memory!\n"));
                return NT_STATUS_NO_MEMORY;
        }
 
-       if ( (config_option = talloc_asprintf(ctx, "idmap config %s", dom->name)) == NULL ) {
+       config_option = talloc_asprintf(ctx, "idmap config %s", dom->name);
+       if (config_option == NULL) {
                DEBUG(0, ("Out of memory!\n"));
                talloc_free(ctx);
                return NT_STATUS_NO_MEMORY;
        }
 
-       /* load ranges */
-       range = lp_parm_const_string(-1, config_option, "range", NULL);
-       if (range && range[0]) {
-               if ((sscanf(range, "%u - %u", &ctx->filter_low_id, &ctx->filter_high_id) != 2) ||
-                   (ctx->filter_low_id > ctx->filter_high_id)) {
-                       DEBUG(1, ("ERROR: invalid filter range [%s]", range));
-                       ctx->filter_low_id = 0;
-                       ctx->filter_high_id = 0;
-               }
-       }
-
        /* default map type */
        ctx->ad_map_type = WB_POSIX_MAP_RFC2307;
 
@@ -304,6 +292,11 @@ static NTSTATUS idmap_ad_unixids_to_sids(struct idmap_domain *dom, struct id_map
        char *u_filter = NULL;
        char *g_filter = NULL;
 
+       /* initialize the status to avoid suprise */
+       for (i = 0; ids[i]; i++) {
+               ids[i]->status = ID_UNKNOWN;
+       }
+       
        /* Only do query if we are online */
        if (idmap_is_offline()) {
                return NT_STATUS_FILE_IS_OFFLINE;
@@ -448,11 +441,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;
                }
 
@@ -516,6 +507,11 @@ static NTSTATUS idmap_ad_sids_to_unixids(struct idmap_domain *dom, struct id_map
        int i;
        char *sidstr;
 
+       /* initialize the status to avoid suprise */
+       for (i = 0; ids[i]; i++) {
+               ids[i]->status = ID_UNKNOWN;
+       }
+
        /* Only do query if we are online */
        if (idmap_is_offline()) {
                return NT_STATUS_FILE_IS_OFFLINE;
@@ -641,11 +637,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;
                }
 
@@ -830,6 +824,9 @@ static NTSTATUS nss_ad_get_info( struct nss_domain_entry *e,
        struct idmap_domain *dom;
        struct idmap_ad_context *ctx;
 
+       DEBUG(10, ("nss_ad_get_info called for sid [%s] in domain '%s'\n",
+                  sid_string_dbg(sid), e->domain?e->domain:"NULL"));
+
        /* Only do query if we are online */
        if (idmap_is_offline()) {
                return NT_STATUS_FILE_IS_OFFLINE;
@@ -930,7 +927,7 @@ static NTSTATUS nss_ad_map_to_alias(TALLOC_CTX *mem_ctx,
        ADS_STATUS ads_status = ADS_ERROR_NT(NT_STATUS_UNSUCCESSFUL);
        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        struct idmap_domain *dom;
-       struct idmap_ad_context *ctx;
+       struct idmap_ad_context *ctx = NULL;
 
        /* Check incoming parameters */
 
@@ -1010,7 +1007,7 @@ static NTSTATUS nss_ad_map_from_alias( TALLOC_CTX *mem_ctx,
        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        char *username;
        struct idmap_domain *dom;
-       struct idmap_ad_context *ctx;
+       struct idmap_ad_context *ctx = NULL;
 
        /* Check incoming parameters */