LCOV - code coverage report
Current view: top level - providers/ipa - ipa_config.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 58 0.0 %
Date: 2016-06-29 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :     SSSD
       3             : 
       4             :     IPA Backend Module -- configuration retrieval
       5             : 
       6             :     Authors:
       7             :         Jan Zeleny <jzeleny@redhat.com>
       8             : 
       9             :     Copyright (C) 2012 Red Hat
      10             : 
      11             :     This program is free software; you can redistribute it and/or modify
      12             :     it under the terms of the GNU General Public License as published by
      13             :     the Free Software Foundation; either version 3 of the License, or
      14             :     (at your option) any later version.
      15             : 
      16             :     This program is distributed in the hope that it will be useful,
      17             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :     GNU General Public License for more details.
      20             : 
      21             :     You should have received a copy of the GNU General Public License
      22             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      23             : */
      24             : 
      25             : #include "providers/ipa/ipa_config.h"
      26             : #include "providers/ipa/ipa_common.h"
      27             : #include "providers/ldap/sdap_async.h"
      28             : 
      29             : struct ipa_get_config_state {
      30             :     char *base;
      31             :     const char **attrs;
      32             : 
      33             :     struct sysdb_attrs *config;
      34             : };
      35             : 
      36             : static void ipa_get_config_done(struct tevent_req *subreq);
      37             : 
      38             : struct tevent_req *
      39           0 : ipa_get_config_send(TALLOC_CTX *mem_ctx,
      40             :                     struct tevent_context *ev,
      41             :                     struct sdap_handle *sh,
      42             :                     struct sdap_options *opts,
      43             :                     const char *domain,
      44             :                     const char **attrs)
      45             : {
      46             :     struct tevent_req *req;
      47             :     struct tevent_req *subreq;
      48             :     struct ipa_get_config_state *state;
      49             :     errno_t ret;
      50             :     char *ldap_basedn;
      51             : 
      52           0 :     req = tevent_req_create(mem_ctx, &state, struct ipa_get_config_state);
      53           0 :     if (req == NULL) {
      54           0 :         return NULL;
      55             :     }
      56             : 
      57           0 :     if (attrs == NULL) {
      58           0 :         state->attrs = talloc_zero_array(state, const char *, 4);
      59           0 :         if (state->attrs == NULL) {
      60           0 :             ret = ENOMEM;
      61           0 :             goto done;
      62             :         }
      63           0 :         state->attrs[0] = IPA_CONFIG_MIGRATION_ENABLED;
      64           0 :         state->attrs[1] = IPA_CONFIG_SELINUX_DEFAULT_USER_CTX;
      65           0 :         state->attrs[2] = IPA_CONFIG_SELINUX_MAP_ORDER;
      66           0 :         state->attrs[3] = NULL;
      67             :     } else {
      68           0 :         state->attrs = attrs;
      69             :     }
      70             : 
      71           0 :     ret = domain_to_basedn(state, domain, &ldap_basedn);
      72           0 :     if (ret != EOK) {
      73           0 :         DEBUG(SSSDBG_OP_FAILURE, "domain_to_basedn failed.\n");
      74           0 :         goto done;
      75             :     }
      76             : 
      77           0 :     state->base = talloc_asprintf(state, IPA_CONFIG_SEARCH_BASE_TEMPLATE,
      78             :                                   ldap_basedn);
      79           0 :     if (state->base == NULL) {
      80           0 :         DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
      81           0 :         ret = ENOMEM;
      82           0 :         goto done;
      83             :     }
      84             : 
      85           0 :     subreq = sdap_get_generic_send(state, ev, opts,
      86           0 :                                    sh, state->base,
      87             :                                    LDAP_SCOPE_SUBTREE, IPA_CONFIG_FILTER,
      88           0 :                                    state->attrs, NULL, 0,
      89             :                                    dp_opt_get_int(opts->basic,
      90             :                                                   SDAP_ENUM_SEARCH_TIMEOUT),
      91             :                                    false);
      92           0 :     if (subreq == NULL) {
      93           0 :         ret = ENOMEM;
      94           0 :         goto done;
      95             :     }
      96             : 
      97           0 :     tevent_req_set_callback(subreq, ipa_get_config_done, req);
      98             : 
      99           0 :     ret = EOK;
     100             : 
     101             : done:
     102           0 :     if (ret != EOK) {
     103           0 :         tevent_req_error(req, ret);
     104           0 :         tevent_req_post(req, ev);
     105             :     }
     106             : 
     107           0 :     return req;
     108             : }
     109             : 
     110           0 : static void ipa_get_config_done(struct tevent_req *subreq)
     111             : {
     112           0 :     struct tevent_req *req = tevent_req_callback_data(subreq,
     113             :                                                       struct tevent_req);
     114           0 :     struct ipa_get_config_state *state = tevent_req_data(req,
     115             :                                             struct ipa_get_config_state);
     116             :     size_t reply_count;
     117           0 :     struct sysdb_attrs **reply = NULL;
     118             :     errno_t ret;
     119             : 
     120           0 :     ret = sdap_get_generic_recv(subreq, state, &reply_count, &reply);
     121           0 :     talloc_zfree(subreq);
     122           0 :     if (ret) {
     123           0 :         goto done;
     124             :     }
     125             : 
     126           0 :     if (reply_count != 1) {
     127           0 :         DEBUG(SSSDBG_OP_FAILURE, "Unexpected number of results, expected 1, "
     128             :                                   "got %zu.\n", reply_count);
     129           0 :         ret = EINVAL;
     130           0 :         goto done;
     131             :     }
     132             : 
     133           0 :     state->config = reply[0];
     134             : 
     135           0 :     ret = EOK;
     136             : 
     137             : done:
     138           0 :     if (ret != EOK) {
     139           0 :         tevent_req_error(req, ret);
     140             :     } else {
     141           0 :         tevent_req_done(req);
     142             :     }
     143           0 : }
     144             : 
     145           0 : errno_t ipa_get_config_recv(struct tevent_req *req,
     146             :                             TALLOC_CTX *mem_ctx,
     147             :                             struct sysdb_attrs **config)
     148             : {
     149           0 :     struct ipa_get_config_state *state = tevent_req_data(req,
     150             :                                               struct ipa_get_config_state);
     151             : 
     152           0 :     TEVENT_REQ_RETURN_ON_ERROR(req);
     153             : 
     154           0 :     *config = talloc_steal(mem_ctx, state->config);
     155             : 
     156           0 :     return EOK;
     157             : }

Generated by: LCOV version 1.10