LCOV - code coverage report
Current view: top level - tools - sss_groupdel.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 0 65 0.0 %
Date: 2015-10-19 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :    SSSD
       3             : 
       4             :    sss_groupdel
       5             : 
       6             :    Copyright (C) Jakub Hrozek <jhrozek@redhat.com>        2009
       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 <nss.h>
      23             : #include <stdio.h>
      24             : #include <stdlib.h>
      25             : #include <talloc.h>
      26             : #include <popt.h>
      27             : 
      28             : #include "db/sysdb.h"
      29             : #include "util/util.h"
      30             : #include "tools/tools_util.h"
      31             : #include "tools/sss_sync_ops.h"
      32             : 
      33           0 : int main(int argc, const char **argv)
      34             : {
      35           0 :     int ret = EXIT_SUCCESS;
      36           0 :     int pc_debug = SSSDBG_DEFAULT;
      37           0 :     const char *pc_groupname = NULL;
      38           0 :     struct tools_ctx *tctx = NULL;
      39             : 
      40           0 :     poptContext pc = NULL;
      41           0 :     struct poptOption long_options[] = {
      42             :         POPT_AUTOHELP
      43             :         { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug,
      44           0 :                     0, _("The debug level to run with"), NULL },
      45             :         POPT_TABLEEND
      46             :     };
      47             : 
      48           0 :     debug_prg_name = argv[0];
      49             : 
      50           0 :     ret = set_locale();
      51           0 :     if (ret != EOK) {
      52           0 :         DEBUG(SSSDBG_CRIT_FAILURE,
      53             :               "set_locale failed (%d): %s\n", ret, strerror(ret));
      54           0 :         ERROR("Error setting the locale\n");
      55           0 :         ret = EXIT_FAILURE;
      56           0 :         goto fini;
      57             :     }
      58             : 
      59             :     /* parse ops_ctx */
      60           0 :     pc = poptGetContext(NULL, argc, argv, long_options, 0);
      61           0 :     poptSetOtherOptionHelp(pc, "GROUPNAME");
      62           0 :     if ((ret = poptGetNextOpt(pc)) < -1) {
      63           0 :         BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini);
      64             :     }
      65             : 
      66           0 :     DEBUG_CLI_INIT(pc_debug);
      67             : 
      68           0 :     pc_groupname = poptGetArg(pc);
      69           0 :     if (pc_groupname == NULL) {
      70           0 :         BAD_POPT_PARAMS(pc, _("Specify group to delete\n"), ret, fini);
      71             :     }
      72             : 
      73           0 :     CHECK_ROOT(ret, debug_prg_name);
      74             : 
      75           0 :     ret = init_sss_tools(&tctx);
      76           0 :     if (ret != EOK) {
      77           0 :         DEBUG(SSSDBG_CRIT_FAILURE,
      78             :               "init_sss_tools failed (%d): %s\n", ret, strerror(ret));
      79           0 :         if (ret == ENOENT) {
      80           0 :             ERROR("Error initializing the tools - no local domain\n");
      81             :         } else {
      82           0 :             ERROR("Error initializing the tools\n");
      83             :         }
      84           0 :         ret = EXIT_FAILURE;
      85           0 :         goto fini;
      86             :     }
      87             : 
      88             :     /* if the domain was not given as part of FQDN, default to local domain */
      89           0 :     ret = parse_name_domain(tctx, pc_groupname);
      90           0 :     if (ret != EOK) {
      91           0 :         ERROR("Invalid domain specified in FQDN\n");
      92           0 :         ret = EXIT_FAILURE;
      93           0 :         goto fini;
      94             :     }
      95             : 
      96           0 :     ret = sysdb_getgrnam_sync(tctx, tctx->octx->name, tctx->octx);
      97           0 :     if (ret != EOK) {
      98             :         /* Error message will be printed in the switch */
      99           0 :         goto done;
     100             :     }
     101             : 
     102           0 :     if ((tctx->octx->gid < tctx->local->id_min) ||
     103           0 :         (tctx->local->id_max && tctx->octx->gid > tctx->local->id_max)) {
     104           0 :         ERROR("Group %1$s is outside the defined ID range for domain\n",
     105             :               tctx->octx->name);
     106           0 :         ret = EXIT_FAILURE;
     107           0 :         goto fini;
     108             :     }
     109             : 
     110             :     /* groupdel */
     111           0 :     ret = groupdel(tctx, tctx->sysdb, tctx->octx);
     112           0 :     if (ret != EOK) {
     113           0 :         goto done;
     114             :     }
     115             : 
     116             :     /* Delete group from memory cache */
     117           0 :     ret = sss_mc_refresh_group(pc_groupname);
     118           0 :     if (ret != EOK) {
     119           0 :         ERROR("NSS request failed (%1$d). Entry might remain in memory "
     120             :               "cache.\n", ret);
     121             :         /* Nothing we can do about it */
     122             :     }
     123             : 
     124           0 :     ret = EOK;
     125             : 
     126             : done:
     127           0 :     if (ret) {
     128           0 :         DEBUG(SSSDBG_CRIT_FAILURE,
     129             :               "sysdb operation failed (%d)[%s]\n", ret, strerror(ret));
     130           0 :         switch (ret) {
     131             :             case ENOENT:
     132           0 :                 ERROR("No such group in local domain. "
     133             :                       "Removing groups only allowed in local domain.\n");
     134           0 :                 break;
     135             : 
     136             :             default:
     137           0 :                 ERROR("Internal error. Could not remove group.\n");
     138           0 :                 break;
     139             :         }
     140           0 :         ret = EXIT_FAILURE;
     141           0 :         goto fini;
     142             :     }
     143             : 
     144           0 :     ret = EXIT_SUCCESS;
     145             : 
     146             : fini:
     147           0 :     talloc_free(tctx);
     148           0 :     poptFreeContext(pc);
     149           0 :     exit(ret);
     150             : }
     151             : 

Generated by: LCOV version 1.10