root/source3/utils/passwd_util.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. stdin_new_passwd
  2. get_pass

   1 /* 
   2    Unix SMB/CIFS implementation.
   3    passdb editing frontend
   4 
   5    Copyright (C) Jeremy Allison  1998
   6    Copyright (C) Andrew Tridgell 1998
   7    Copyright (C) Tim Potter      2000
   8    Copyright (C) Simo Sorce      2000
   9    Copyright (C) Martin Pool     2001
  10    Copyright (C) Gerald Carter   2002
  11    Copyright (C) Andrew Bartlett 2003
  12 
  13    This program is free software; you can redistribute it and/or modify
  14    it under the terms of the GNU General Public License as published by
  15    the Free Software Foundation; either version 3 of the License, or
  16    (at your option) any later version.
  17    
  18    This program is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22    
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  25 */
  26 
  27 #include "includes.h"
  28 
  29 /*************************************************************
  30  Utility function to prompt for passwords from stdin. Each
  31  password entered must end with a newline.
  32 *************************************************************/
  33 char *stdin_new_passwd( void)
     /* [<][>][^][v][top][bottom][index][help] */
  34 {
  35         static fstring new_pw;
  36         size_t len;
  37 
  38         ZERO_ARRAY(new_pw);
  39 
  40         /*
  41          * if no error is reported from fgets() and string at least contains
  42          * the newline that ends the password, then replace the newline with
  43          * a null terminator.
  44          */
  45         if ( fgets(new_pw, sizeof(new_pw), stdin) != NULL) {
  46                 if ((len = strlen(new_pw)) > 0) {
  47                         if(new_pw[len-1] == '\n')
  48                                 new_pw[len - 1] = 0;
  49                 }
  50         }
  51         return(new_pw);
  52 }
  53 
  54 /*************************************************************
  55  Utility function to get passwords via tty or stdin
  56  Used if the '-s' (smbpasswd) or '-t' (pdbedit) option is set
  57  to silently get passwords to enable scripting.
  58 *************************************************************/
  59 char *get_pass( const char *prompt, bool stdin_get)
     /* [<][>][^][v][top][bottom][index][help] */
  60 {
  61         char *p;
  62         if (stdin_get) {
  63                 p = stdin_new_passwd();
  64         } else {
  65                 p = getpass( prompt);
  66         }
  67         return smb_xstrdup( p);
  68 }

/* [<][>][^][v][top][bottom][index][help] */