>From f80acc202e4e338c26a04ba48acb669a46e94fc7 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jcholast@redhat.com>
Date: Fri, 3 Feb 2012 22:41:30 +0100
Subject: [PATCH 5/9] IPA: Add auxiliary info handler

---
 Makefile.am                    |    4 +++
 src/providers/ipa/ipa_auxid.c  |   59 ++++++++++++++++++++++++++++++++++++++++
 src/providers/ipa/ipa_auxid.h  |   33 ++++++++++++++++++++++
 src/providers/ipa/ipa_common.c |    1 +
 src/providers/ipa/ipa_common.h |    1 +
 src/providers/ipa/ipa_init.c   |   45 ++++++++++++++++++++++++++++++
 6 files changed, 143 insertions(+), 0 deletions(-)
 create mode 100644 src/providers/ipa/ipa_auxid.c
 create mode 100644 src/providers/ipa/ipa_auxid.h

diff --git a/Makefile.am b/Makefile.am
index 8b6a65d..f2569df 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -355,6 +355,7 @@ dist_noinst_HEADERS = \
     src/providers/ipa/ipa_auth.h \
     src/providers/ipa/ipa_dyndns.h \
     src/providers/ipa/ipa_id.h \
+    src/providers/ipa/ipa_auxid.h \
     src/providers/proxy/proxy.h \
     src/tools/tools_util.h \
     src/tools/sss_sync_ops.h \
@@ -1069,6 +1070,9 @@ libsss_ipa_la_SOURCES += src/providers/ldap/sdap_sudo_cache.c \
                  src/providers/ldap/sdap_sudo_timer.c \
                  src/providers/ldap/sdap_sudo.c
 endif
+if BUILD_SSH
+libsss_ipa_la_SOURCES += src/providers/ipa/ipa_auxid.c
+endif
 
 
 krb5_child_SOURCES = \
diff --git a/src/providers/ipa/ipa_auxid.c b/src/providers/ipa/ipa_auxid.c
new file mode 100644
index 0000000..eb38fbe
--- /dev/null
+++ b/src/providers/ipa/ipa_auxid.c
@@ -0,0 +1,59 @@
+/*
+    Authors:
+        Jan Cholasta <jcholast@redhat.com>
+
+    Copyright (C) 2012 Red Hat
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "util/util.h"
+#include "util/crypto/sss_crypto.h"
+#include "providers/ldap/ldap_common.h"
+#include "providers/ipa/ipa_common.h"
+#include "providers/ipa/ipa_auxid.h"
+#include "providers/ipa/ipa_hosts.h"
+#include "providers/ipa/ipa_hbac_private.h"
+
+void
+ipa_auxiliary_info_handler(struct be_req *breq)
+{
+    struct ipa_auxid_ctx *auxid_ctx;
+    struct sdap_id_ctx *ctx;
+    struct be_acct_req *ar;
+    struct tevent_req *req;
+    const char *err = "Unknown Error";
+    errno_t ret = EOK;
+
+    auxid_ctx = talloc_get_type(breq->be_ctx->bet_info[BET_AUXID].pvt_bet_data, struct ipa_auxid_ctx);
+    ctx = auxid_ctx->sdap_id_ctx;
+
+    if (be_is_offline(ctx->be)) {
+        return sdap_handler_done(breq, DP_ERR_OFFLINE, EAGAIN, "Offline");
+    }
+
+    ar = talloc_get_type(breq->req_data, struct be_acct_req);
+
+    switch (ar->entry_type & 0xFFF) {
+    case BE_REQ_HOST:
+        ret = EINVAL;
+        err = "Not implemented yet";
+
+    default:
+        ret = EINVAL;
+        err = "Invalid request type";
+    }
+
+    if (ret != EOK) return sdap_handler_done(breq, DP_ERR_FATAL, ret, err);
+}
diff --git a/src/providers/ipa/ipa_auxid.h b/src/providers/ipa/ipa_auxid.h
new file mode 100644
index 0000000..b09ac24
--- /dev/null
+++ b/src/providers/ipa/ipa_auxid.h
@@ -0,0 +1,33 @@
+/*
+    Authors:
+        Jan Cholasta <jcholast@redhat.com>
+
+    Copyright (C) 2012 Red Hat
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _IPA_AUXID_H_
+#define _IPA_AUXID_H_
+
+struct ipa_auxid_ctx {
+    struct sdap_id_ctx *sdap_id_ctx;
+    struct dp_option *ipa_options;
+
+    struct sdap_search_base **host_search_bases;
+};
+
+void ipa_auxiliary_info_handler(struct be_req *be_req);
+
+#endif /* _IPA_AUXID_H_ */
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index 790adb7..0121ca5 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -180,6 +180,7 @@ struct sdap_attr_map ipa_host_map[] = {
     { "ipa_host_object_class", "ipaHost", SYSDB_HOST_CLASS, NULL },
     { "ipa_host_fqdn", "fqdn", SYSDB_NAME, NULL },
     { "ipa_host_member_of", "memberOf", SYSDB_MEMBEROF, NULL },
+    { "ipa_host_ssh_public_key", "ipaSshPubKey", SYSDB_SSH_PUBKEY, NULL }
 };
 
 struct dp_option ipa_def_krb5_opts[] = {
diff --git a/src/providers/ipa/ipa_common.h b/src/providers/ipa/ipa_common.h
index 9cbd993..5883fce 100644
--- a/src/providers/ipa/ipa_common.h
+++ b/src/providers/ipa/ipa_common.h
@@ -78,6 +78,7 @@ enum ipa_host_attrs {
     IPA_OC_HOST = 0,
     IPA_AT_HOST_FQDN,
     IPA_AT_HOST_MEMBER_OF,
+    IPA_AT_HOST_SSH_PUBLIC_KEY,
 
     IPA_OPTS_HOST /* attrs counter */
 };
diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
index 78a102a..39a5b27 100644
--- a/src/providers/ipa/ipa_init.c
+++ b/src/providers/ipa/ipa_init.c
@@ -33,6 +33,7 @@
 #include "providers/ipa/ipa_id.h"
 #include "providers/ipa/ipa_auth.h"
 #include "providers/ipa/ipa_access.h"
+#include "providers/ipa/ipa_auxid.h"
 #include "providers/ipa/ipa_dyndns.h"
 
 struct ipa_options *ipa_options = NULL;
@@ -59,6 +60,11 @@ struct bet_ops ipa_access_ops = {
     .finalize = NULL
 };
 
+struct bet_ops ipa_auxid_ops = {
+    .handler = ipa_auxiliary_info_handler,
+    .finalize = NULL
+};
+
 int common_ipa_init(struct be_ctx *bectx)
 {
     const char *ipa_servers;
@@ -392,3 +398,42 @@ done:
     }
     return ret;
 }
+
+int sssm_ipa_auxid_init(struct be_ctx *bectx,
+                        struct bet_ops **ops,
+                        void **pvt_data)
+{
+    int ret;
+    struct ipa_auxid_ctx *auxid_ctx;
+    struct ipa_id_ctx *id_ctx;
+
+    auxid_ctx = talloc_zero(bectx, struct ipa_auxid_ctx);
+    if (auxid_ctx == NULL) {
+        DEBUG(1, ("talloc_zero failed.\n"));
+        return ENOMEM;
+    }
+
+    ret = sssm_ipa_id_init(bectx, ops, (void **) &id_ctx);
+    if (ret != EOK) {
+        DEBUG(1, ("sssm_ipa_id_init failed.\n"));
+        goto done;
+    }
+    auxid_ctx->sdap_id_ctx = id_ctx->sdap_id_ctx;
+    auxid_ctx->host_search_bases = id_ctx->ipa_options->host_search_bases;
+
+    ret = dp_copy_options(auxid_ctx, ipa_options->basic,
+                          IPA_OPTS_BASIC, &auxid_ctx->ipa_options);
+    if (ret != EOK) {
+        DEBUG(1, ("dp_copy_options failed.\n"));
+        goto done;
+    }
+
+    *ops = &ipa_auxid_ops;
+    *pvt_data = auxid_ctx;
+
+done:
+    if (ret != EOK) {
+        talloc_free(auxid_ctx);
+    }
+    return ret;
+}
-- 
1.7.6.5

