Fixes https://fedorahosted.org/sssd/ticket/1160

I tested this against a case-sensitive LDAP server and proxy->files, but
I don't have access to a case-insensitive LDAP server at the moment.
From 41409f5ef049a5a8acc1ab50c59f539634de5095 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgall...@redhat.com>
Date: Thu, 16 Feb 2012 08:43:35 -0500
Subject: [PATCH] NSS: Always return the same protocol that was requested

https://fedorahosted.org/sssd/ticket/1160
---
 src/responder/nss/nsssrv_private.h  |    3 +++
 src/responder/nss/nsssrv_services.c |   32 +++++++++++++++++++++++---------
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/responder/nss/nsssrv_private.h b/src/responder/nss/nsssrv_private.h
index c6526595f03309f4dfc866609d85b07d58676d78..c9fb0d0a0bd94ac333635e6c23d10dfa835a6e74 100644
--- a/src/responder/nss/nsssrv_private.h
+++ b/src/responder/nss/nsssrv_private.h
@@ -70,6 +70,9 @@ struct nss_dom_ctx {
 
     /* Netgroup-specific */
     struct getent_ctx *netgr;
+
+    /* Service-specific */
+    const char *protocol;
 };
 
 struct setent_step_ctx {
diff --git a/src/responder/nss/nsssrv_services.c b/src/responder/nss/nsssrv_services.c
index 2f2a25c238392b8129a35f22918040c04227183b..13d142e44b2bc149f80f8d5ead6a768f44169689 100644
--- a/src/responder/nss/nsssrv_services.c
+++ b/src/responder/nss/nsssrv_services.c
@@ -591,6 +591,7 @@ static errno_t
 fill_service(struct sss_packet *packet,
              struct sss_domain_info *dom,
              struct nss_ctx *nctx,
+             const char *protocol,
              struct ldb_message **msgs,
              unsigned int *count)
 {
@@ -603,7 +604,7 @@ fill_service(struct sss_packet *packet,
     struct ldb_message_element *el;
     TALLOC_CTX *tmp_ctx = NULL;
     const char *orig_name;
-    char *orig_proto;
+    const char *orig_proto;
     struct sized_string cased_name;
     struct sized_string cased_proto;
     uint16_t port;
@@ -662,16 +663,23 @@ fill_service(struct sss_packet *packet,
         }
 
         /* Get the service protocol.
+         * Use the requested protocol if present,
+         * otherwise take the first protocol returned
+         * by the sysdb.
          * If more than one is available, select the
          * first in the message.
          */
-        el = ldb_msg_find_element(msg, SYSDB_SVC_PROTO);
-        if (el->num_values == 0) {
-            ret = EINVAL;
-            num = 0;
-            goto done;
+        if (protocol) {
+            orig_proto = protocol;
+        } else {
+            el = ldb_msg_find_element(msg, SYSDB_SVC_PROTO);
+            if (el->num_values == 0) {
+                ret = EINVAL;
+                num = 0;
+                goto done;
+            }
+            orig_proto = (const char *)el->values[0].data;
         }
-        orig_proto = (char *)el->values[0].data;
 
         tmpstr = sss_get_cased_name(tmp_ctx, orig_proto, dom->case_sensitive);
         if (tmpstr == NULL) {
@@ -817,6 +825,8 @@ int nss_cmd_getservbyname(struct cli_ctx *cctx)
         goto done;
     }
 
+    dctx->protocol = service_protocol;
+
     DEBUG(SSSDBG_TRACE_FUNC,
           ("Requesting info for service [%s:%s] from [%s]\n",
            service_name,
@@ -999,7 +1009,9 @@ nss_cmd_getserv_done(struct tevent_req *req)
             i = dctx->res->count;
             ret = fill_service(cmdctx->cctx->creq->out,
                                dctx->domain,
-                               nctx, dctx->res->msgs,
+                               nctx,
+                               dctx->protocol,
+                               dctx->res->msgs,
                                &i);
         }
         if (ret != EOK) {
@@ -1130,6 +1142,8 @@ int nss_cmd_getservbyport(struct cli_ctx *cctx)
         goto done;
     }
 
+    dctx->protocol = service_protocol;
+
     DEBUG(SSSDBG_TRACE_FUNC,
           ("Requesting info for service on port [%lu/%s]\n",
            port, service_protocol ? service_protocol : "<ANY>"));
@@ -1770,7 +1784,7 @@ retservent(struct cli_ctx *cctx, int num)
 
         ret = fill_service(cctx->creq->out,
                            pdom->domain,
-                           nctx, msgs,
+                           nctx, NULL, msgs,
                            &n);
 
         cctx->svcent_cur += n;
-- 
1.7.7.6

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to