>From b9166d9e11792bf3cffa0829c5e929d4ae0b6d54 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jcholast@redhat.com>
Date: Mon, 27 Feb 2012 04:43:34 -0500
Subject: [PATCH 2/2] SSH: Add more debugging messages

---
 src/db/sysdb_ssh.c                           |   15 +++++++++++----
 src/responder/ssh/sshsrv_cmd.c               |    8 ++++++++
 src/sss_client/ssh/sss_ssh_authorizedkeys.c  |    4 ++++
 src/sss_client/ssh/sss_ssh_knownhostsproxy.c |   18 ++++++++++++++----
 4 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/src/db/sysdb_ssh.c b/src/db/sysdb_ssh.c
index d83ad96..a4d4345 100644
--- a/src/db/sysdb_ssh.c
+++ b/src/db/sysdb_ssh.c
@@ -55,8 +55,7 @@ sysdb_store_ssh_host(struct sysdb_ctx *sysdb,
 
     ret = sysdb_transaction_start(sysdb);
     if (ret != EOK) {
-        DEBUG(SSSDBG_CRIT_FAILURE,
-              ("Failed to start update transaction\n"));
+        DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
         goto done;
     }
 
@@ -70,11 +69,15 @@ sysdb_store_ssh_host(struct sysdb_ctx *sysdb,
 
     if (num_hosts > 1) {
         ret = EINVAL;
+        DEBUG(SSSDBG_CRIT_FAILURE,
+              ("Found more than one host with name [%s].\n", name));
         goto done;
     }
 
     ret = sysdb_delete_ssh_host(sysdb, name);
     if (ret != EOK && ret != ENOENT) {
+        DEBUG(SSSDBG_OP_FAILURE,
+              ("Failed to delete host [%s].\n", name));
         goto done;
     }
 
@@ -90,7 +93,9 @@ sysdb_store_ssh_host(struct sysdb_ctx *sysdb,
                 ret = sysdb_attrs_add_val(attrs,
                                           SYSDB_NAME_ALIAS, &el->values[i]);
                 if (ret != EOK) {
-                    DEBUG(SSSDBG_OP_FAILURE, ("Could not add name alias\n"));
+                    DEBUG(SSSDBG_OP_FAILURE,
+                          ("Could not add name alias [%s]\n",
+                           el->values[i].data));
                     goto done;
                 }
             }
@@ -100,7 +105,8 @@ sysdb_store_ssh_host(struct sysdb_ctx *sysdb,
     if (alias) {
         ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, alias);
         if (ret != EOK) {
-            DEBUG(SSSDBG_OP_FAILURE, ("Could not add name alias\n"));
+            DEBUG(SSSDBG_OP_FAILURE,
+                  ("Could not add name alias [%s]\n", alias));
             goto done;
         }
     }
@@ -114,6 +120,7 @@ sysdb_store_ssh_host(struct sysdb_ctx *sysdb,
 
     ret = sysdb_transaction_commit(sysdb);
     if (ret != EOK) {
+        DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n"));
         goto done;
     }
 
diff --git a/src/responder/ssh/sshsrv_cmd.c b/src/responder/ssh/sshsrv_cmd.c
index 4768d54..8e523f4 100644
--- a/src/responder/ssh/sshsrv_cmd.c
+++ b/src/responder/ssh/sshsrv_cmd.c
@@ -492,12 +492,18 @@ ssh_host_pubkeys_update_known_hosts(struct ssh_cmd_ctx *cmd_ctx)
         ret = sysdb_search_ssh_hosts(tmp_ctx, sysdb, "*", attrs,
                                      &hosts, &num_hosts);
         if (ret != EOK) {
+            if (ret != ENOENT) {
+                DEBUG(SSSDBG_OP_FAILURE,
+                      ("Host search failed for domain [%s]\n", dom->name));
+            }
             continue;
         }
 
         for (i = 0; i < num_hosts; i++) {
             ret = sss_ssh_make_ent(tmp_ctx, hosts[i], &ent);
             if (ret != EOK) {
+                DEBUG(SSSDBG_OP_FAILURE,
+                      ("Failed to get SSH host public keys\n"));
                 continue;
             }
 
@@ -505,6 +511,8 @@ ssh_host_pubkeys_update_known_hosts(struct ssh_cmd_ctx *cmd_ctx)
                 pubkey = sss_ssh_format_pubkey(tmp_ctx, ent, &ent->pubkeys[j],
                                                SSS_SSH_FORMAT_OPENSSH);
                 if (!pubkey) {
+                    DEBUG(SSSDBG_OP_FAILURE,
+                          ("Not enough memory to format SSH public key\n"));
                     continue;
                 }
 
diff --git a/src/sss_client/ssh/sss_ssh_authorizedkeys.c b/src/sss_client/ssh/sss_ssh_authorizedkeys.c
index bc3cdf4..92b21ae 100644
--- a/src/sss_client/ssh/sss_ssh_authorizedkeys.c
+++ b/src/sss_client/ssh/sss_ssh_authorizedkeys.c
@@ -99,6 +99,8 @@ int main(int argc, const char **argv)
     /* look up public keys */
     ret = sss_ssh_get_ent(mem_ctx, SSS_SSH_GET_USER_PUBKEYS, user, &ent);
     if (ret != EOK) {
+        DEBUG(SSSDBG_CRIT_FAILURE,
+              ("sss_ssh_get_ent() failed (%d): %s\n", ret, strerror(ret))));
         ERROR("Error looking up public keys\n");
         ret = EXIT_FAILURE;
         goto fini;
@@ -109,6 +111,8 @@ int main(int argc, const char **argv)
         repr = sss_ssh_format_pubkey(mem_ctx, ent, &ent->pubkeys[i],
                                      SSS_SSH_FORMAT_OPENSSH);
         if (!repr) {
+            DEBUG(SSSDBG_OP_FAILURE,
+                  ("Not enough memory to format SSH public key\n"));
             continue;
         }
 
diff --git a/src/sss_client/ssh/sss_ssh_knownhostsproxy.c b/src/sss_client/ssh/sss_ssh_knownhostsproxy.c
index 544ea71..6a5f1bc 100644
--- a/src/sss_client/ssh/sss_ssh_knownhostsproxy.c
+++ b/src/sss_client/ssh/sss_ssh_knownhostsproxy.c
@@ -136,6 +136,8 @@ connect_socket(const char *host,
             if (ret == EINTR || ret == EAGAIN) {
                 continue;
             }
+            DEBUG(SSSDBG_OP_FAILURE,
+                  ("poll() failed (%d): %s\n", ret, strerror(ret)));
             goto done;
         }
 
@@ -149,25 +151,31 @@ connect_socket(const char *host,
                     if (ret == EAGAIN || ret == EINTR || ret == EWOULDBLOCK) {
                         continue;
                     }
+                    DEBUG(SSSDBG_OP_FAILURE,
+                          ("read() failed (%d): %s\n", ret, strerror(ret)));
                     goto done;
                 } else if (res == 0) {
-                    ret = EOK;
-                    goto done;
+                    break;
                 }
 
                 res = sss_atomic_write(i == 0 ? sock : 1, buffer, res);
                 if (res == -1) {
                     ret = errno;
+                    DEBUG(SSSDBG_OP_FAILURE,
+                          ("sss_atomic_write() failed (%d): %s\n",
+                           ret, strerror(ret)));
                     goto done;
                 }
             }
             if (fds[i].revents & POLLHUP) {
-                ret = EOK;
-                goto done;
+                break;
             }
         }
     }
 
+    ret = EOK;
+    DEBUG(SSSDBG_TRACE_FUNC, ("Connection closed\n"));
+
 done:
     if (ai) freeaddrinfo(ai);
     if (sock >= 0) close(sock);
@@ -274,6 +282,8 @@ int main(int argc, const char **argv)
     /* look up public keys */
     ret = sss_ssh_get_ent(mem_ctx, SSS_SSH_GET_HOST_PUBKEYS, host, &ent);
     if (ret != EOK) {
+        DEBUG(SSSDBG_CRIT_FAILURE,
+              ("sss_ssh_get_ent() failed (%d): %s\n", ret, strerror(ret))));
         ERROR("Error looking up public keys\n");
     }
 
-- 
1.7.6.5

