From bbaa05c52e43abebe34619bf83403f64974670e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 10 Sep 2013 10:40:06 +0200
Subject: [PATCH 06/12] ad: simplify get_conn_list()

It was originally design to return list of connection objects,
it really always work with only one connection.
---
 src/providers/ad/ad_id.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/providers/ad/ad_id.c b/src/providers/ad/ad_id.c
index 446b60154403f9e2d571517400b5d5cc3df452b4..061d172654d28b3284c6d476d5a7dcfd3f5d268d 100644
--- a/src/providers/ad/ad_id.c
+++ b/src/providers/ad/ad_id.c
@@ -180,31 +180,35 @@ get_conn_list(struct be_req *breq, struct ad_id_ctx *ad_ctx,
               struct sss_domain_info *dom, struct be_acct_req *ar)
 {
     struct sdap_id_conn_ctx **clist;
-    int i=0;
+    struct sdap_id_conn_ctx *conn;
 
     /* LDAP, GC, sentinel */
-    clist = talloc_zero_array(breq, struct sdap_id_conn_ctx *, 3);
+    clist = talloc_zero_array(breq, struct sdap_id_conn_ctx *, 2);
     if (clist == NULL) return NULL;
 
+    if (ad_ctx->gc_ctx == NULL) {
+        conn = ad_ctx->ldap_ctx;
+        goto done;
+    }
+
     switch (ar->entry_type & BE_REQ_TYPE_MASK) {
     case BE_REQ_USER: /* user */
     case BE_REQ_BY_SECID:   /* by SID */
     case BE_REQ_USER_AND_GROUP: /* get SID */
     case BE_REQ_GROUP: /* group */
     case BE_REQ_INITGROUPS: /* init groups for user */
-        if (ad_ctx->gc_ctx && IS_SUBDOMAIN(dom)) {
-            clist[i] = ad_ctx->gc_ctx;
-            i++;
-        } else {
-            clist[i] = ad_ctx->ldap_ctx;
-        }
+        conn = IS_SUBDOMAIN(dom) ? ad_ctx->gc_ctx : ad_ctx->ldap_ctx;
         break;
 
     default:
-        clist[0] = ad_ctx->ldap_ctx;
+        conn = ad_ctx->ldap_ctx;
         break;
     }
 
+done:
+    clist[0] = conn;
+    clist[1] = NULL;
+
     return clist;
 }
 
-- 
1.7.11.7

