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

          Line data    Source code
       1             : /*
       2             :     Authors:
       3             :         Jan Cholasta <jcholast@redhat.com>
       4             : 
       5             :     Copyright (C) 2012 Red Hat
       6             : 
       7             :     This program is free software; you can redistribute it and/or modify
       8             :     it under the terms of the GNU General Public License as published by
       9             :     the Free Software Foundation; either version 3 of the License, or
      10             :     (at your option) any later version.
      11             : 
      12             :     This program is distributed in the hope that it will be useful,
      13             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :     GNU General Public License for more details.
      16             : 
      17             :     You should have received a copy of the GNU General Public License
      18             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include <stdio.h>
      22             : #include <talloc.h>
      23             : #include <popt.h>
      24             : 
      25             : #include "util/util.h"
      26             : #include "util/crypto/sss_crypto.h"
      27             : #include "util/sss_ssh.h"
      28             : #include "sss_client/sss_cli.h"
      29             : #include "sss_client/ssh/sss_ssh_client.h"
      30             : 
      31           0 : int main(int argc, const char **argv)
      32             : {
      33           0 :     TALLOC_CTX *mem_ctx = NULL;
      34           0 :     int pc_debug = SSSDBG_DEFAULT;
      35           0 :     const char *pc_domain = NULL;
      36           0 :     const char *pc_user = NULL;
      37           0 :     struct poptOption long_options[] = {
      38             :         POPT_AUTOHELP
      39             :         { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0,
      40           0 :           _("The debug level to run with"), NULL },
      41             :         { "domain", 'd', POPT_ARG_STRING, &pc_domain, 0,
      42           0 :           _("The SSSD domain to use"), NULL },
      43             :         POPT_TABLEEND
      44             :     };
      45           0 :     poptContext pc = NULL;
      46             :     struct sss_ssh_ent *ent;
      47             :     size_t i;
      48             :     char *repr;
      49             :     int ret;
      50             : 
      51           0 :     debug_prg_name = argv[0];
      52             : 
      53           0 :     ret = set_locale();
      54           0 :     if (ret != EOK) {
      55           0 :         DEBUG(SSSDBG_CRIT_FAILURE,
      56             :               "set_locale() failed (%d): %s\n", ret, strerror(ret));
      57           0 :         ERROR("Error setting the locale\n");
      58           0 :         ret = EXIT_FAILURE;
      59           0 :         goto fini;
      60             :     }
      61             : 
      62           0 :     mem_ctx = talloc_new(NULL);
      63           0 :     if (!mem_ctx) {
      64           0 :         ERROR("Not enough memory\n");
      65           0 :         ret = EXIT_FAILURE;
      66           0 :         goto fini;
      67             :     }
      68             : 
      69             :     /* parse parameters */
      70           0 :     pc = poptGetContext(NULL, argc, argv, long_options, 0);
      71           0 :     poptSetOtherOptionHelp(pc, "USER");
      72           0 :     while ((ret = poptGetNextOpt(pc)) > 0)
      73             :         ;
      74             : 
      75           0 :     DEBUG_INIT(pc_debug);
      76             : 
      77           0 :     if (ret != -1) {
      78           0 :         BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini);
      79             :     }
      80             : 
      81           0 :     pc_user = poptGetArg(pc);
      82           0 :     if (pc_user == NULL) {
      83           0 :         BAD_POPT_PARAMS(pc, _("User not specified\n"), ret, fini);
      84             :     }
      85             : 
      86             :     /* look up public keys */
      87           0 :     ret = sss_ssh_get_ent(mem_ctx, SSS_SSH_GET_USER_PUBKEYS,
      88             :                           pc_user, pc_domain, NULL, &ent);
      89           0 :     if (ret != EOK) {
      90           0 :         DEBUG(SSSDBG_CRIT_FAILURE,
      91             :               "sss_ssh_get_ent() failed (%d): %s\n", ret, strerror(ret));
      92           0 :         ERROR("Error looking up public keys\n");
      93           0 :         ret = EXIT_FAILURE;
      94           0 :         goto fini;
      95             :     }
      96             : 
      97             :     /* print results */
      98           0 :     for (i = 0; i < ent->num_pubkeys; i++) {
      99           0 :         ret = sss_ssh_format_pubkey(mem_ctx, &ent->pubkeys[i], &repr);
     100           0 :         if (ret != EOK) {
     101           0 :             DEBUG(SSSDBG_OP_FAILURE,
     102             :                   "sss_ssh_format_pubkey() failed (%d): %s\n",
     103             :                     ret, strerror(ret));
     104           0 :             continue;
     105             :         }
     106             : 
     107           0 :         printf("%s\n", repr);
     108             :     }
     109             : 
     110           0 :     ret = EXIT_SUCCESS;
     111             : 
     112             : fini:
     113           0 :     poptFreeContext(pc);
     114           0 :     talloc_free(mem_ctx);
     115             : 
     116           0 :     return ret;
     117             : }

Generated by: LCOV version 1.10