LCOV - code coverage report
Current view: top level - src/utils - getpassarg.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 9 9 100.0 %
Date: 2024-03-23 08:24:27 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005  Brian Bruns
       3             :  * Copyright (C) 2006, 2007, 2008, 2009, 2010  Frediano Ziglio
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or
       6             :  * modify it under the terms of the GNU Library General Public
       7             :  * License as published by the Free Software Foundation; either
       8             :  * version 2 of the License, or (at your option) any later version.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful,
      11             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13             :  * Library General Public License for more details.
      14             :  *
      15             :  * You should have received a copy of the GNU Library General Public
      16             :  * License along with this library; if not, write to the
      17             :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      18             :  * Boston, MA 02111-1307, USA.
      19             :  */
      20             : 
      21             : #include <config.h>
      22             : 
      23             : #include <stdio.h>
      24             : 
      25             : #if HAVE_STRING_H
      26             : #include <string.h>
      27             : #endif /* HAVE_STRING_H */
      28             : 
      29             : #include <freetds/sysdep_private.h>
      30             : #include <freetds/utils.h>
      31             : 
      32             : /*
      33             :  * return a copy of the password, reading from stdin if arg is '-'
      34             :  * trashing he argument in the process.
      35             :  */
      36             : char *
      37          28 : tds_getpassarg(char *arg)
      38             : {
      39             :         char pwd[256], *ptr, *q;
      40             : 
      41          28 :         if (strcmp(arg, "-") == 0) {
      42           8 :                 if (fgets(pwd, sizeof(pwd), stdin) == NULL)
      43             :                         return NULL;
      44           8 :                 ptr = strchr(pwd, '\n');
      45           8 :                 if (ptr) *ptr = '\0';
      46             :                 arg = pwd;
      47             :         }
      48             : 
      49          28 :         ptr = strdup(arg);
      50          28 :         memset(pwd, 0, sizeof(pwd));
      51             : 
      52         202 :         for (q = arg; *q; *q++ = '*')
      53         174 :                 continue;
      54             : 
      55             :         return ptr;
      56             : }
      57             : 

Generated by: LCOV version 1.13