LCOV - code coverage report
Current view: top level - sss_client - pam_test_client.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             :         Sumit Bose <sbose@redhat.com>
       4             : 
       5             :     Copyright (C) 2009 Red Hat
       6             : 
       7             :     This program is free software; you can redistribute it and/or modify
       8             :     it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
      16             : 
      17             :     You should have received a copy of the GNU Lesser General Public License
      18             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : #include <config.h>
      23             : #endif
      24             : 
      25             : #include <stdio.h>
      26             : #include <unistd.h>
      27             : #include <string.h>
      28             : 
      29             : #include <security/pam_appl.h>
      30             : 
      31             : #ifdef HAVE_SECURITY_PAM_MISC_H
      32             : # include <security/pam_misc.h>
      33             : #elif defined(HAVE_SECURITY_OPENPAM_H)
      34             : # include <security/openpam.h>
      35             : #endif
      36             : 
      37             : #ifdef HAVE_SECURITY_PAM_MISC_H
      38             : static struct pam_conv conv = {
      39             :     misc_conv,
      40             :     NULL
      41             : };
      42             : #elif defined(HAVE_SECURITY_OPENPAM_H)
      43             : static struct pam_conv conv = {
      44             :     openpam_ttyconv,
      45             :     NULL
      46             : };
      47             : #else
      48             : # error "Missing text based pam conversation function"
      49             : #endif
      50             : 
      51           0 : int main(int argc, char *argv[]) {
      52             : 
      53             :     pam_handle_t *pamh;
      54             :     char *user;
      55             :     char *action;
      56             :     int ret;
      57             : 
      58           0 :     if (argc == 1) {
      59           0 :         fprintf(stderr, "missing action and user name, using default\n");
      60           0 :         action = strdup("auth");
      61           0 :         user = strdup("dummy");
      62           0 :     } else if (argc == 2) {
      63           0 :         fprintf(stdout, "using first argument as action and default user name\n");
      64           0 :         action = strdup(argv[1]);
      65           0 :         user = strdup("dummy");
      66             :     } else {
      67           0 :         action = strdup(argv[1]);
      68           0 :         user = strdup(argv[2]);
      69             :     }
      70             : 
      71           0 :     if (action == NULL || user == NULL) {
      72           0 :         fprintf(stderr, "Out of memory!\n");
      73           0 :         return 1;
      74             :     }
      75             : 
      76           0 :     fprintf(stdout, "action: %s\nuser: %s\n", action,user);
      77             : 
      78           0 :     ret = pam_start("sss_test", user, &conv, &pamh);
      79           0 :     if (ret != PAM_SUCCESS) {
      80           0 :         fprintf(stderr, "pam_start failed: %s\n", pam_strerror(pamh, ret));
      81           0 :         return 1;
      82             :     }
      83             : 
      84           0 :     if ( strncmp(action, "auth", 4)== 0 ) {
      85           0 :         fprintf(stdout, "testing pam_authenticate\n");
      86           0 :         ret = pam_authenticate(pamh, 0);
      87           0 :         fprintf(stderr, "pam_authenticate: %s\n", pam_strerror(pamh, ret));
      88           0 :     } else if ( strncmp(action, "chau", 4)== 0 ) {
      89           0 :         fprintf(stdout, "testing pam_chauthtok\n");
      90           0 :         ret = pam_chauthtok(pamh, 0);
      91           0 :         fprintf(stderr, "pam_chauthtok: %s\n", pam_strerror(pamh, ret));
      92           0 :     } else if ( strncmp(action, "acct", 4)== 0 ) {
      93           0 :         fprintf(stdout, "testing pam_acct_mgmt\n");
      94           0 :         ret = pam_acct_mgmt(pamh, 0);
      95           0 :         fprintf(stderr, "pam_acct_mgmt: %s\n", pam_strerror(pamh, ret));
      96           0 :     } else if ( strncmp(action, "setc", 4)== 0 ) {
      97           0 :         fprintf(stdout, "testing pam_setcred\n");
      98           0 :         ret = pam_setcred(pamh, 0);
      99           0 :         fprintf(stderr, "pam_setcred: %d[%s]\n", ret, pam_strerror(pamh, ret));
     100           0 :     } else if ( strncmp(action, "open", 4)== 0 ) {
     101           0 :         fprintf(stdout, "testing pam_open_session\n");
     102           0 :         ret = pam_open_session(pamh, 0);
     103           0 :         fprintf(stderr, "pam_open_session: %s\n", pam_strerror(pamh, ret));
     104           0 :     } else if ( strncmp(action, "clos", 4)== 0 ) {
     105           0 :         fprintf(stdout, "testing pam_close_session\n");
     106           0 :         ret = pam_close_session(pamh, 0);
     107           0 :         fprintf(stderr, "pam_close_session: %s\n", pam_strerror(pamh, ret));
     108             :     } else {
     109           0 :         fprintf(stderr, "unknown action\n");
     110             :     }
     111             : 
     112           0 :     pam_end(pamh, ret);
     113             : 
     114           0 :     return 0;
     115             : }

Generated by: LCOV version 1.10