LCOV - code coverage report
Current view: top level - providers - data_provider_be.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 45 214 21.0 %
Date: 2016-06-29 Functions: 6 19 31.6 %

          Line data    Source code
       1             : /*
       2             :    SSSD
       3             : 
       4             :    Data Provider Process
       5             : 
       6             :    Copyright (C) Simo Sorce <ssorce@redhat.com>   2008
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include <stdio.h>
      23             : #include <unistd.h>
      24             : #include <fcntl.h>
      25             : #include <sys/types.h>
      26             : #include <sys/stat.h>
      27             : #include <sys/socket.h>
      28             : #include <sys/un.h>
      29             : #include <string.h>
      30             : #include <sys/time.h>
      31             : #include <errno.h>
      32             : #include <dlfcn.h>
      33             : #include <popt.h>
      34             : #include <dbus/dbus.h>
      35             : 
      36             : #include <security/pam_appl.h>
      37             : #include <security/pam_modules.h>
      38             : 
      39             : #include "util/util.h"
      40             : #include "util/sss_utf8.h"
      41             : #include "confdb/confdb.h"
      42             : #include "db/sysdb.h"
      43             : #include "sbus/sssd_dbus.h"
      44             : #include "providers/backend.h"
      45             : #include "providers/fail_over.h"
      46             : #include "providers/be_refresh.h"
      47             : #include "providers/be_ptask.h"
      48             : #include "util/child_common.h"
      49             : #include "resolv/async_resolv.h"
      50             : #include "monitor/monitor_interfaces.h"
      51             : 
      52             : static int data_provider_res_init(struct sbus_request *dbus_req, void *data);
      53             : static int data_provider_go_offline(struct sbus_request *dbus_req, void *data);
      54             : static int data_provider_reset_offline(struct sbus_request *dbus_req, void *data);
      55             : static int data_provider_logrotate(struct sbus_request *dbus_req, void *data);
      56             : 
      57             : struct mon_cli_iface monitor_be_methods = {
      58             :     { &mon_cli_iface_meta, 0 },
      59             :     .ping = monitor_common_pong,
      60             :     .resInit = data_provider_res_init,
      61             :     .shutDown = NULL,
      62             :     .goOffline = data_provider_go_offline,
      63             :     .resetOffline = data_provider_reset_offline,
      64             :     .rotateLogs = data_provider_logrotate,
      65             :     .clearMemcache = NULL,
      66             :     .clearEnumCache = NULL,
      67             :     .sysbusReconnect = NULL,
      68             : };
      69             : 
      70           4 : bool be_is_offline(struct be_ctx *ctx)
      71             : {
      72           4 :     return ctx->offstat.offline;
      73             : }
      74             : 
      75             : static void check_if_online(struct be_ctx *be_ctx);
      76             : 
      77             : static errno_t
      78           0 : try_to_go_online(TALLOC_CTX *mem_ctx,
      79             :                  struct tevent_context *ev,
      80             :                  struct be_ctx *be_ctx,
      81             :                  struct be_ptask *be_ptask,
      82             :                  void *be_ctx_void)
      83             : {
      84           0 :     struct be_ctx *ctx = (struct be_ctx*) be_ctx_void;
      85             : 
      86           0 :     check_if_online(ctx);
      87           0 :     return EOK;
      88             : }
      89             : 
      90           4 : static int get_offline_timeout(struct be_ctx *ctx)
      91             : {
      92             :     errno_t ret;
      93             :     int offline_timeout;
      94             : 
      95           4 :     ret = confdb_get_int(ctx->cdb, ctx->conf_path,
      96             :                          CONFDB_DOMAIN_OFFLINE_TIMEOUT, 60,
      97             :                          &offline_timeout);
      98           4 :     if (ret != EOK) {
      99           0 :         DEBUG(SSSDBG_CRIT_FAILURE,
     100             :               "Failed to get offline_timeout from confdb. "
     101             :               "Will use 60 seconds.\n");
     102           0 :         offline_timeout = 60;
     103             :     }
     104             : 
     105           4 :     return offline_timeout;
     106             : }
     107             : 
     108           1 : void be_mark_offline(struct be_ctx *ctx)
     109             : {
     110             :     int offline_timeout;
     111             :     errno_t ret;
     112             : 
     113           1 :     DEBUG(SSSDBG_TRACE_INTERNAL, "Going offline!\n");
     114             : 
     115           1 :     ctx->offstat.went_offline = time(NULL);
     116           1 :     ctx->offstat.offline = true;
     117           1 :     ctx->run_online_cb = true;
     118             : 
     119           1 :     if (ctx->check_if_online_ptask == NULL) {
     120             :         /* This is the first time we go offline - create a periodic task
     121             :          * to check if we can switch to online. */
     122           1 :         DEBUG(SSSDBG_TRACE_INTERNAL, "Initialize check_if_online_ptask.\n");
     123             : 
     124           1 :         offline_timeout = get_offline_timeout(ctx);
     125             : 
     126           1 :         ret = be_ptask_create_sync(ctx, ctx,
     127             :                                    offline_timeout, offline_timeout,
     128             :                                    offline_timeout, 30, offline_timeout,
     129             :                                    BE_PTASK_OFFLINE_EXECUTE,
     130             :                                    3600 /* max_backoff */,
     131             :                                    try_to_go_online,
     132             :                                    ctx, "Check if online (periodic)",
     133             :                                    &ctx->check_if_online_ptask);
     134           1 :         if (ret != EOK) {
     135           1 :             DEBUG(SSSDBG_FATAL_FAILURE,
     136             :                   "be_ptask_create_sync failed [%d]: %s\n",
     137             :                   ret, sss_strerror(ret));
     138             :         }
     139             :     } else {
     140             :         /* Periodic task was already created. Just enable it. */
     141           0 :         DEBUG(SSSDBG_TRACE_INTERNAL, "Enable check_if_online_ptask.\n");
     142           0 :         be_ptask_enable(ctx->check_if_online_ptask);
     143             :     }
     144             : 
     145           1 :     be_run_offline_cb(ctx);
     146           1 : }
     147             : 
     148           1 : static void be_subdom_reset_status(struct tevent_context *ev,
     149             :                                   struct tevent_timer *te,
     150             :                                   struct timeval current_time,
     151             :                                   void *pvt)
     152             : {
     153           1 :     struct sss_domain_info *subdom = talloc_get_type(pvt,
     154             :                                                      struct sss_domain_info);
     155             : 
     156           1 :     DEBUG(SSSDBG_TRACE_LIBS, "Resetting subdomain %s\n", subdom->name);
     157           1 :     subdom->state = DOM_ACTIVE;
     158           1 : }
     159             : 
     160           3 : static void be_mark_subdom_offline(struct sss_domain_info *subdom,
     161             :                                    struct be_ctx *be_ctx)
     162             : {
     163             :     struct timeval tv;
     164           3 :     struct tevent_timer *timeout = NULL;
     165             :     int reset_status_timeout;
     166             : 
     167           3 :     reset_status_timeout = get_offline_timeout(be_ctx);
     168           3 :     tv = tevent_timeval_current_ofs(reset_status_timeout, 0);
     169             : 
     170           3 :     switch (subdom->state) {
     171             :     case DOM_DISABLED:
     172           1 :         DEBUG(SSSDBG_MINOR_FAILURE, "Won't touch disabled subdomain\n");
     173           3 :         return;
     174             :     case DOM_INACTIVE:
     175           1 :         DEBUG(SSSDBG_TRACE_ALL, "Subdomain already inactive\n");
     176           1 :         return;
     177             :     case DOM_ACTIVE:
     178           1 :         DEBUG(SSSDBG_TRACE_LIBS,
     179             :               "Marking subdomain %s as inactive\n", subdom->name);
     180           1 :         break;
     181             :     }
     182             : 
     183           1 :     timeout = tevent_add_timer(be_ctx->ev, be_ctx, tv,
     184             :                                be_subdom_reset_status, subdom);
     185           1 :     if (timeout == NULL) {
     186           0 :         DEBUG(SSSDBG_OP_FAILURE, "Cannot create timer\n");
     187           0 :         return;
     188             :     }
     189             : 
     190           1 :     subdom->state = DOM_INACTIVE;
     191             : }
     192             : 
     193           4 : void be_mark_dom_offline(struct sss_domain_info *dom, struct be_ctx *ctx)
     194             : {
     195           4 :     if (IS_SUBDOMAIN(dom) == false) {
     196           1 :         DEBUG(SSSDBG_TRACE_LIBS, "Marking back end offline\n");
     197           1 :         be_mark_offline(ctx);
     198             :     } else {
     199           3 :         DEBUG(SSSDBG_TRACE_LIBS, "Marking subdomain %s offline\n", dom->name);
     200           3 :         be_mark_subdom_offline(dom, ctx);
     201             :     }
     202           4 : }
     203             : 
     204           0 : static void reactivate_subdoms(struct sss_domain_info *head)
     205             : {
     206             :     struct sss_domain_info *dom;
     207             : 
     208           0 :     DEBUG(SSSDBG_TRACE_LIBS, "Resetting all subdomains\n");
     209             : 
     210           0 :     for (dom = head; dom; dom = get_next_domain(dom, true)) {
     211           0 :         if (sss_domain_get_state(dom) == DOM_INACTIVE) {
     212           0 :             sss_domain_set_state(dom, DOM_ACTIVE);
     213             :         }
     214             :     }
     215           0 : }
     216             : 
     217           0 : static void be_reset_offline(struct be_ctx *ctx)
     218             : {
     219           0 :     ctx->offstat.went_offline = 0;
     220           0 :     ctx->offstat.offline = false;
     221             : 
     222           0 :     reactivate_subdoms(ctx->domain);
     223             : 
     224           0 :     be_ptask_disable(ctx->check_if_online_ptask);
     225           0 :     be_run_online_cb(ctx);
     226           0 : }
     227             : 
     228             : static void be_check_online_done(struct tevent_req *req);
     229             : 
     230           0 : static errno_t be_check_online_request(struct be_ctx *be_ctx)
     231             : {
     232             :     struct tevent_req *req;
     233             : 
     234           0 :     be_ctx->offstat.went_offline = time(NULL);
     235           0 :     reset_fo(be_ctx);
     236             : 
     237           0 :     req = dp_req_send(be_ctx, be_ctx->provider, NULL, NULL, "Online Check",
     238             :                       DPT_ID, DPM_CHECK_ONLINE, 0, NULL, NULL);
     239           0 :     if (req == NULL) {
     240           0 :         return ENOMEM;
     241             :     }
     242             : 
     243           0 :     tevent_req_set_callback(req, be_check_online_done, be_ctx);
     244             : 
     245           0 :     return EOK;
     246             : }
     247             : 
     248           0 : static void be_check_online_done(struct tevent_req *req)
     249             : {
     250             :     struct be_ctx *be_ctx;
     251             :     struct dp_reply_std reply;
     252             :     errno_t ret;
     253             : 
     254           0 :     be_ctx = tevent_req_callback_data(req, struct be_ctx);
     255             : 
     256           0 :     ret = dp_req_recv_ptr(be_ctx, req, struct dp_reply_std, &reply);
     257           0 :     talloc_zfree(req);
     258           0 :     if (ret != EOK) {
     259           0 :         goto done;
     260             :     }
     261             : 
     262           0 :     switch (reply.dp_error) {
     263             :     case DP_ERR_OK:
     264           0 :         DEBUG(SSSDBG_TRACE_FUNC, "Backend is online\n");
     265           0 :         break;
     266             :     case DP_ERR_OFFLINE:
     267           0 :         DEBUG(SSSDBG_TRACE_FUNC, "Backend is offline\n");
     268           0 :         break;
     269             :     default:
     270           0 :         DEBUG(SSSDBG_TRACE_FUNC, "Error during online check [%d]: %s\n",
     271             :               ret, sss_strerror(ret));
     272           0 :         break;
     273             :     }
     274             : 
     275           0 :     be_ctx->check_online_ref_count--;
     276             : 
     277           0 :     if (reply.dp_error != DP_ERR_OK && be_ctx->check_online_ref_count > 0) {
     278           0 :         ret = be_check_online_request(be_ctx);
     279           0 :         if (ret != EOK) {
     280           0 :             DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create check online req.\n");
     281           0 :             goto done;
     282             :         }
     283           0 :         return;
     284             :     }
     285             : 
     286             : done:
     287           0 :     be_ctx->check_online_ref_count = 0;
     288           0 :     if (reply.dp_error != DP_ERR_OFFLINE) {
     289           0 :         if (reply.dp_error != DP_ERR_OK) {
     290           0 :             reset_fo(be_ctx);
     291             :         }
     292           0 :         be_reset_offline(be_ctx);
     293             :     }
     294             : }
     295             : 
     296           0 : static void check_if_online(struct be_ctx *be_ctx)
     297             : {
     298             :     errno_t ret;
     299             : 
     300           0 :     be_run_unconditional_online_cb(be_ctx);
     301             : 
     302           0 :     if (!be_is_offline(be_ctx)) {
     303           0 :         DEBUG(SSSDBG_TRACE_INTERNAL,
     304             :               "Backend is already online, nothing to do.\n");
     305           0 :         return;
     306             :     }
     307             : 
     308             :     /* Make sure nobody tries to go online while we are checking */
     309           0 :     be_ctx->offstat.went_offline = time(NULL);
     310             : 
     311           0 :     DEBUG(SSSDBG_TRACE_INTERNAL, "Trying to go back online!\n");
     312             : 
     313           0 :     be_ctx->check_online_ref_count++;
     314             : 
     315           0 :     if (be_ctx->check_online_ref_count != 1) {
     316           0 :         DEBUG(SSSDBG_TRACE_INTERNAL,
     317             :               "There is an online check already running.\n");
     318           0 :         return;
     319             :     }
     320             : 
     321           0 :     if (!dp_method_enabled(be_ctx->provider, DPT_ID, DPM_CHECK_ONLINE)) {
     322           0 :         DEBUG(SSSDBG_TRACE_INTERNAL,
     323             :               "ID providers does not provide a check_online method.\n");
     324           0 :         goto failed;
     325             :     }
     326             : 
     327           0 :     ret = be_check_online_request(be_ctx);
     328           0 :     if (ret != EOK) {
     329           0 :         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create check online req.\n");
     330           0 :         goto failed;
     331             :     }
     332             : 
     333           0 :     return;
     334             : 
     335             : failed:
     336           0 :     be_ctx->check_online_ref_count--;
     337           0 :     DEBUG(SSSDBG_CRIT_FAILURE, "Failed to run a check_online test.\n");
     338             : 
     339           0 :     if (be_ctx->check_online_ref_count == 0) {
     340           0 :         reset_fo(be_ctx);
     341           0 :         be_reset_offline(be_ctx);
     342             :     }
     343             : 
     344           0 :     return;
     345             : }
     346             : 
     347           0 : static void signal_be_offline(struct tevent_context *ev,
     348             :                               struct tevent_signal *se,
     349             :                               int signum,
     350             :                               int count,
     351             :                               void *siginfo,
     352             :                               void *private_data)
     353             : {
     354           0 :     struct be_ctx *ctx = talloc_get_type(private_data, struct be_ctx);
     355           0 :     be_mark_offline(ctx);
     356           0 : }
     357             : 
     358           0 : static void signal_be_reset_offline(struct tevent_context *ev,
     359             :                                     struct tevent_signal *se,
     360             :                                     int signum,
     361             :                                     int count,
     362             :                                     void *siginfo,
     363             :                                     void *private_data)
     364             : {
     365           0 :     struct be_ctx *ctx = talloc_get_type(private_data, struct be_ctx);
     366           0 :     check_if_online(ctx);
     367           0 : }
     368             : 
     369           0 : errno_t be_process_init(TALLOC_CTX *mem_ctx,
     370             :                         const char *be_domain,
     371             :                         uid_t uid,
     372             :                         gid_t gid,
     373             :                         struct tevent_context *ev,
     374             :                         struct confdb_ctx *cdb)
     375             : {
     376             :     uint32_t refresh_interval;
     377             :     struct tevent_signal *tes;
     378             :     struct be_ctx *be_ctx;
     379             :     errno_t ret;
     380             : 
     381           0 :     be_ctx = talloc_zero(mem_ctx, struct be_ctx);
     382           0 :     if (be_ctx == NULL) {
     383           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "talloc_zero() failed\n");
     384           0 :         return ENOMEM;
     385             :     }
     386             : 
     387           0 :     be_ctx->ev = ev;
     388           0 :     be_ctx->cdb = cdb;
     389           0 :     be_ctx->identity = talloc_asprintf(be_ctx, "%%BE_%s", be_domain);
     390           0 :     be_ctx->conf_path = talloc_asprintf(be_ctx, CONFDB_DOMAIN_PATH_TMPL, be_domain);
     391           0 :     if (be_ctx->identity == NULL || be_ctx->conf_path == NULL) {
     392           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory!?\n");
     393           0 :         ret = ENOMEM;
     394           0 :         goto done;
     395             :     }
     396             : 
     397           0 :     ret = be_init_failover(be_ctx);
     398           0 :     if (ret != EOK) {
     399           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize failover\n");
     400           0 :         goto done;
     401             :     }
     402             : 
     403           0 :     ret = sssd_domain_init(be_ctx, cdb, be_domain, DB_PATH, &be_ctx->domain);
     404           0 :     if (ret != EOK) {
     405           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize domain\n");
     406           0 :         goto done;
     407             :     }
     408             : 
     409           0 :     ret = sss_monitor_init(be_ctx, be_ctx->ev, &monitor_be_methods,
     410             :                            be_ctx->identity, DATA_PROVIDER_VERSION,
     411             :                            be_ctx, &be_ctx->mon_conn);
     412           0 :     if (ret != EOK) {
     413           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize monitor connection\n");
     414           0 :         goto done;
     415             :     }
     416             : 
     417             :     /* We need this for subdomains support, as they have to store fully
     418             :      * qualified user and group names for now. */
     419           0 :     ret = sss_names_init(be_ctx->domain, cdb, be_ctx->domain->name,
     420           0 :                          &be_ctx->domain->names);
     421           0 :     if (ret != EOK) {
     422           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to setup fully qualified name "
     423             :               "format for %s\n", be_ctx->domain->name);
     424           0 :         goto done;
     425             :     }
     426             : 
     427             :     /* Initialize be_refresh periodic task. */
     428           0 :     be_ctx->refresh_ctx = be_refresh_ctx_init(be_ctx);
     429           0 :     if (be_ctx->refresh_ctx == NULL) {
     430           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize refresh_ctx\n");
     431           0 :         ret = ENOMEM;
     432           0 :         goto done;
     433             :     }
     434             : 
     435           0 :     refresh_interval = be_ctx->domain->refresh_expired_interval;
     436           0 :     if (refresh_interval > 0) {
     437           0 :         ret = be_ptask_create(be_ctx, be_ctx, refresh_interval, 30, 5, 0,
     438             :                               refresh_interval, BE_PTASK_OFFLINE_SKIP, 0,
     439             :                               be_refresh_send, be_refresh_recv,
     440           0 :                               be_ctx->refresh_ctx, "Refresh Records", NULL);
     441           0 :         if (ret != EOK) {
     442           0 :             DEBUG(SSSDBG_FATAL_FAILURE,
     443             :                   "Unable to initialize refresh periodic task\n");
     444           0 :             goto done;
     445             :         }
     446             :     }
     447             : 
     448           0 :     ret = dp_init(be_ctx->ev, be_ctx, be_ctx->uid, be_ctx->gid);
     449           0 :     if (ret != EOK) {
     450           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to setup data provider "
     451             :               "[%d]: %s\n", ret, sss_strerror(ret));
     452           0 :         goto done;
     453             :     }
     454             : 
     455             :     /* Handle SIGUSR1 to force offline behavior */
     456           0 :     BlockSignals(false, SIGUSR1);
     457           0 :     tes = tevent_add_signal(be_ctx->ev, be_ctx, SIGUSR1, 0,
     458             :                             signal_be_offline, be_ctx);
     459           0 :     if (tes == NULL) {
     460           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to setup SIGUSR1 handler\n");
     461           0 :         ret = EIO;
     462           0 :         goto done;
     463             :     }
     464             : 
     465             :     /* Handle SIGUSR2 to force going online */
     466           0 :     BlockSignals(false, SIGUSR2);
     467           0 :     tes = tevent_add_signal(be_ctx->ev, be_ctx, SIGUSR2, 0,
     468             :                             signal_be_reset_offline, be_ctx);
     469           0 :     if (tes == NULL) {
     470           0 :         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to setup SIGUSR2 handler\n");
     471           0 :         ret = EIO;
     472           0 :         goto done;
     473             :     }
     474             : 
     475           0 :     ret = EOK;
     476             : 
     477             : done:
     478           0 :     if (ret != EOK) {
     479           0 :         talloc_free(be_ctx);
     480             :     }
     481             : 
     482           0 :     return ret;
     483             : }
     484             : 
     485             : #ifndef UNIT_TESTING
     486             : int main(int argc, const char *argv[])
     487             : {
     488             :     int opt;
     489             :     poptContext pc;
     490             :     char *be_domain = NULL;
     491             :     char *srv_name = NULL;
     492             :     struct main_context *main_ctx;
     493             :     char *confdb_path;
     494             :     int ret;
     495             :     uid_t uid;
     496             :     gid_t gid;
     497             : 
     498             :     struct poptOption long_options[] = {
     499             :         POPT_AUTOHELP
     500             :         SSSD_MAIN_OPTS
     501             :         SSSD_SERVER_OPTS(uid, gid)
     502             :         {"domain", 0, POPT_ARG_STRING, &be_domain, 0,
     503             :          _("Domain of the information provider (mandatory)"), NULL },
     504             :         POPT_TABLEEND
     505             :     };
     506             : 
     507             :     /* Set debug level to invalid value so we can deside if -d 0 was used. */
     508             :     debug_level = SSSDBG_INVALID;
     509             : 
     510             :     pc = poptGetContext(argv[0], argc, argv, long_options, 0);
     511             :     while((opt = poptGetNextOpt(pc)) != -1) {
     512             :         switch(opt) {
     513             :         default:
     514             :         fprintf(stderr, "\nInvalid option %s: %s\n\n",
     515             :                   poptBadOption(pc, 0), poptStrerror(opt));
     516             :             poptPrintUsage(pc, stderr, 0);
     517             :             return 1;
     518             :         }
     519             :     }
     520             : 
     521             :     if (be_domain == NULL) {
     522             :         fprintf(stderr, "\nMissing option, --domain is a mandatory option.\n\n");
     523             :             poptPrintUsage(pc, stderr, 0);
     524             :             return 1;
     525             :     }
     526             : 
     527             :     poptFreeContext(pc);
     528             : 
     529             :     DEBUG_INIT(debug_level);
     530             : 
     531             :     /* set up things like debug , signals, daemonization, etc... */
     532             :     debug_log_file = talloc_asprintf(NULL, "sssd_%s", be_domain);
     533             :     if (!debug_log_file) return 2;
     534             : 
     535             :     srv_name = talloc_asprintf(NULL, "sssd[be[%s]]", be_domain);
     536             :     if (!srv_name) return 2;
     537             : 
     538             :     confdb_path = talloc_asprintf(NULL, CONFDB_DOMAIN_PATH_TMPL, be_domain);
     539             :     if (!confdb_path) return 2;
     540             : 
     541             :     ret = server_setup(srv_name, 0, 0, 0, confdb_path, &main_ctx);
     542             :     if (ret != EOK) {
     543             :         DEBUG(SSSDBG_FATAL_FAILURE, "Could not set up mainloop [%d]\n", ret);
     544             :         return 2;
     545             :     }
     546             : 
     547             :     ret = setenv(SSS_DOM_ENV, be_domain, 1);
     548             :     if (ret != 0) {
     549             :         DEBUG(SSSDBG_MINOR_FAILURE, "Setting "SSS_DOM_ENV" failed, journald "
     550             :               "logging mightnot work as expected\n");
     551             :     }
     552             : 
     553             :     ret = die_if_parent_died();
     554             :     if (ret != EOK) {
     555             :         /* This is not fatal, don't return */
     556             :         DEBUG(SSSDBG_OP_FAILURE,
     557             :               "Could not set up to exit when parent process does\n");
     558             :     }
     559             : 
     560             :     ret = be_process_init(main_ctx,
     561             :                           be_domain, uid, gid,
     562             :                           main_ctx->event_ctx,
     563             :                           main_ctx->confdb_ctx);
     564             :     if (ret != EOK) {
     565             :         DEBUG(SSSDBG_FATAL_FAILURE, "Could not initialize backend [%d]\n", ret);
     566             :         return 3;
     567             :     }
     568             : 
     569             :     ret = chown_debug_file(NULL, uid, gid);
     570             :     if (ret != EOK) {
     571             :         DEBUG(SSSDBG_MINOR_FAILURE,
     572             :               "Cannot chown the debug files, debugging might not work!\n");
     573             :     }
     574             : 
     575             :     ret = become_user(uid, gid);
     576             :     if (ret != EOK) {
     577             :         DEBUG(SSSDBG_FUNC_DATA,
     578             :               "Cannot become user [%"SPRIuid"][%"SPRIgid"].\n", uid, gid);
     579             :         return ret;
     580             :     }
     581             : 
     582             :     DEBUG(SSSDBG_TRACE_FUNC, "Backend provider (%s) started!\n", be_domain);
     583             : 
     584             :     /* loop on main */
     585             :     server_loop(main_ctx);
     586             : 
     587             :     return 0;
     588             : }
     589             : #endif
     590             : 
     591           0 : static int data_provider_res_init(struct sbus_request *dbus_req, void *data)
     592             : {
     593             :     struct be_ctx *be_ctx;
     594           0 :     be_ctx = talloc_get_type(data, struct be_ctx);
     595             : 
     596           0 :     resolv_reread_configuration(be_ctx->be_res->resolv);
     597           0 :     check_if_online(be_ctx);
     598             : 
     599           0 :     return monitor_common_res_init(dbus_req, data);
     600             : }
     601             : 
     602           0 : static int data_provider_go_offline(struct sbus_request *dbus_req, void *data)
     603             : {
     604             :     struct be_ctx *be_ctx;
     605           0 :     be_ctx = talloc_get_type(data, struct be_ctx);
     606           0 :     be_mark_offline(be_ctx);
     607           0 :     return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
     608             : }
     609             : 
     610           0 : static int data_provider_reset_offline(struct sbus_request *dbus_req, void *data)
     611             : {
     612             :     struct be_ctx *be_ctx;
     613           0 :     be_ctx = talloc_get_type(data, struct be_ctx);
     614           0 :     check_if_online(be_ctx);
     615           0 :     return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
     616             : }
     617             : 
     618           0 : static int data_provider_logrotate(struct sbus_request *dbus_req, void *data)
     619             : {
     620             :     errno_t ret;
     621           0 :     struct be_ctx *be_ctx = talloc_get_type(data, struct be_ctx);
     622             : 
     623           0 :     ret = server_common_rotate_logs(be_ctx->cdb, be_ctx->conf_path);
     624           0 :     if (ret != EOK) return ret;
     625             : 
     626           0 :     return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
     627             : }

Generated by: LCOV version 1.10