It is currently Sat, 05 Dec 2020 13:02:00 GMT



 
Author Message
 Changing User Passwords in Shell Script
Can give me some pointers on how to properly write the part of the script
after I specify which username to change the password for.

passwd joeblow
<here>
<here>

Do I use EXPECT???  The system will prompt me for a new password, and the to
verify it a 2nd time.



 Wed, 13 Aug 2003 00:42:45 GMT   
 Changing User Passwords in Shell Script

Please try the attached code. It replaces getpass() and getpassphrase()
with versions which accepts input from stdin - how "passwd"&co. may read
their passwords from stdin...
Try something like this:
% cat secret_passwd.txt | passwd

WARNING: Do not use "echo"&co. because a "ps -ef" dump may show the
"echo" line - including arguments...

----

Bye,
Roland

--
  __ .  . __
 (o.\ \/ /.o) Roland.Ma...@informatik.med.uni-giessen.de
  \__\/\/__/  gisb...@informatik.med.uni-giessen.de
  /O /==\ O\  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
 (;O/ \/ \O;) TEL +49 641 99-41370 FAX +49 641 99-41359

[ getpass_from_stdin.c 2K ]
/*
** $ver: getpass_from_stdin.c 1.1 (24.10.2000)
** Written by Roland.Ma...@informatik.med.uni-giessen.de
**
** Usage:
** cc -c -g -Xc getpass_from_stdin.c -ldl -o getpass_from_stdin.o
** export LD_PRELOAD=<abolute_pathname_of_object_file>
**
 */

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

#include <unistd.h>
#include <dlfcn.h>

#if PASS_MAX > 256
#ifdef __sun
/* confusing: manpage for getpass says PASS_MAX (which is 8)
 * but code uses 9 (=_SC_PASS_MAX)
 */
#define MY_PASS_MAX (_SC_PASS_MAX)
#else
#define MY_PASS_MAX (PASS_MAX)
#endif
#else
#define MY_PASS_MAX (256)
#endif

static char static_buffer[MY_PASS_MAX+2];

static char *getpass_from_stdin( const char *prompt, const int maxlength )
{  
    fprintf( stdout, "%s", prompt );
    fflush( stdout );

    /* be nice to buggy apps. */
    static_buffer[0] = '\0';

    /* both getpass and getpassphrase are mt-unsafe, therefore we can use a static buffer here */

    return( fgets( static_buffer, maxlength+1, stdin ) );

char *getpass( const char *prompt )
{
    char *retval;
    char *(*original_getpass)( const char * );

    /* find the address of function and data objects */
    original_getpass = (char *(*)( const char * ))dlsym( RTLD_NEXT, "getpass" );
    if( original_getpass == NULL )
    {
      fprintf( stderr, "getpass symbol not found ;-(" );
      exit( EXIT_FAILURE );
    }

#if 0    
    retval = original_getpass( prompt );
#else
    retval = getpass_from_stdin( prompt, PASS_MAX );
#endif

    return( retval );

/* identical to getpass() except it returns up to 256 intead of PASS_MAX */
char *getpassphrase( const char *prompt )
{
    char *retval;
    char *(*original_getpass)( const char * );

    /* find the address of function and data objects */
    original_getpass = (char *(*)( const char * ))dlsym( RTLD_NEXT, "getpassphrase" );
    if( original_getpass == NULL )
    {
      fprintf( stderr, "getpass symbol not found ;-(" );
      exit( EXIT_FAILURE );
    }

#if 0    
    retval = original_getpass( prompt );
#else
    retval = getpass_from_stdin( prompt, 256 );
#endif

     return( retval );

/* EOF. */



 Wed, 13 Aug 2003 02:46:14 GMT   
 Changing User Passwords in Shell Script
Something like this, you would enter say the name of the script is passman
enter:  # passman <user>
They will be prompted for the login passwd and then the new one which will
not echoed to the screen when it is entered.

#!/usr/local/bin/expect

spawn passwd [lindex $argv 0]
stty -echo
send_user "Enter login passwd:\n"
expect_user -re "(.*)\n"
set password $expect_out(1,string)

send_user "New passwd:\n"
expect_user -re "(.*)\n"
set newpass $expect_out(1,string)

expect "password:"
send "$password\r"

expect "password:"
send "$newpass\r"

expect "password:"
send "$newpass\r"
expect eof

I don't know if this is what you want but it is something to build off of,
and if you have root you won't need the enter login passwd.

Mike

news:t9d4sc9gfvupfd@corp.supernews.com...



 Wed, 13 Aug 2003 10:31:04 GMT   
 Changing User Passwords in Shell Script
Roland Mainz  <roland.ma...@informatik.med.uni-giessen.de> wrote:

echo is a shell built-in, and hence does not fork a new process,
and it means ps -eaf will not show.



 Thu, 14 Aug 2003 05:24:30 GMT   
 Changing User Passwords in Shell Script

Maybe a build-in in bash2 - but AFAIK not in /bin/ksh...
% ls -l /bin/echo
-r-xr-xr-x   1 bin      bin         5680 Oct  6  1998 /bin/echo

In theory yes...
But I prefer to store it in a file, pipe this file via stdin to
passwd/nispasswd/chkey and delete it afterwards to be sure that none can
"snoop" the passwords...

----

Bye,
Roland

--
  __ .  . __
 (o.\ \/ /.o) Roland.Ma...@informatik.med.uni-giessen.de
  \__\/\/__/  gisb...@informatik.med.uni-giessen.de
  /O /==\ O\  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
 (;O/ \/ \O;) TEL +49 641 99-41370 FAX +49 641 99-41359



 Fri, 15 Aug 2003 21:54:30 GMT   
 Changing User Passwords in Shell Script
Roland Mainz  <roland.ma...@informatik.med.uni-giessen.de> wrote:

Bolsky and Korn, the new Kornshell command and programming language,
index:

echo built-in command, 60, 225



 Sat, 16 Aug 2003 00:56:30 GMT   
 Changing User Passwords in Shell Script
In article <3A9A6016.5AFB...@informatik.med.uni-giessen.de>,
Roland Mainz  <roland.ma...@informatik.med.uni-giessen.de> wrote:

It seems to be:

        $ uname -sr
        SunOS 5.8
        $ for s in sh ksh bash csh
        > do
        >         $s -c 'type echo'
        > done
        echo is a shell builtin
        echo is a shell builtin
        echo is a shell builtin
        echo is a shell builtin
        $

This wasn't always the case, of course.  I'm pretty sure I remember it
not being a built-in in old versions of Bourne shell.

Anyway, I'm sure /bin/echo is still there to maintain compatibility
with scripts that call /bin/echo directly.  Strangely, /bin/echo is a
binary, although this seems like a prime candidate for one of those
scripts that goes like this:

        #!/bin/ksh
        cmd=`basename $0`
        $cmd "$@"

But maybe the built-in echo does something different than what people
are expecting when they do /bin/echo...

  - Logan
--
my  your   his  her   our   their   *its*
I'm you're he's she's we're they're *it's*



 Sat, 16 Aug 2003 02:00:04 GMT   
 Changing User Passwords in Shell Script

It is even an /sbin/sh builtin. /bin/echo is available for two purposes:
- Compatibility: Some script programmers insisted typing /bin/echo instead of
  echo
- *csh use the BSD echo syntax. If you want to use the SysV syntax you have
  to call /bin/echo (this is configurable in tcsh though).

--
Daniel



 Sat, 16 Aug 2003 02:07:02 GMT   
 Changing User Passwords in Shell Script

three purposes:
3. getting rid of bash2 echo build-in...
Example (print "beep" and ring bell):
-- snip --
% bash -c 'echo "beep\a"; /bin/echo "beep\a"'
beep\a
beep
-- snip --

/bin/echo works much better here... =:-)

----

Bye,
Roland

--
  __ .  . __
 (o.\ \/ /.o) Roland.Ma...@informatik.med.uni-giessen.de
  \__\/\/__/  gisb...@informatik.med.uni-giessen.de
  /O /==\ O\  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
 (;O/ \/ \O;) TEL +49 641 99-41370 FAX +49 641 99-41359



 Sat, 16 Aug 2003 02:51:57 GMT   
 Changing User Passwords in Shell Script

Ok... see "AFAIK" in my previous posting... :-))
Thanks !!

----

Bye,
Roland

--
  __ .  . __
 (o.\ \/ /.o) Roland.Ma...@informatik.med.uni-giessen.de
  \__\/\/__/  gisb...@informatik.med.uni-giessen.de
  /O /==\ O\  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
 (;O/ \/ \O;) TEL +49 641 99-41370 FAX +49 641 99-41359



 Sat, 16 Aug 2003 02:53:06 GMT   
 Changing User Passwords in Shell Script

[snip - % for s in /sbin/sh sh ksh dtksh bash csh ; do /bin/echo "$s:
\c" ; $s -c 'type echo' ; done]

OK OK, change AFAIK to AFAIKFHA (As Fas As I Knew Few Hours Ago)... :-)

I assume this "script" version would be very slow (think about 70MHz
sun4m and below...)...

----

Bye,
Roland

--
  __ .  . __
 (o.\ \/ /.o) Roland.Ma...@informatik.med.uni-giessen.de
  \__\/\/__/  gisb...@informatik.med.uni-giessen.de
  /O /==\ O\  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
 (;O/ \/ \O;) TEL +49 641 99-41370 FAX +49 641 99-41359



 Sat, 16 Aug 2003 03:01:47 GMT   
 Changing User Passwords in Shell Script

Not really - see man -s1 echo:

     The C shell, the Korn shell, and the Bourne shell  all  have
     echo  built-in  commands, which, by default, will be invoked
     if  the  user  calls  echo  without  a  full  pathname.  See
     shell_builtins(1).  sh's echo, ksh's echo, and /usr/bin/echo
     understand the back-slashed escape characters,  except  that
     sh's  echo does not understand \a as the alert character. In
     addition, ksh's echo, does not have an -n option. sh's  echo
     and  /usr/bin/echo  only  have  an  -n  option  if the SYSV3
     environment  variable  is  set  (see  ENVIRONMENT  VARIABLES
     below).  If  it  is, none of the backslashed characters men-
     tioned above are available. csh's echo and /usr/ucb/echo, on
     the other hand, have an -n option, but do not understand the
     back-slashed escape characters.

The entry for (builtin) echo on the ksh and sh manpages just refers to
the echo(1) manpage.  The entry for echo on the csh manpage does little
more.

--
Tony



 Sat, 16 Aug 2003 19:30:21 GMT   
 
   [ 12 post ] 

Similar Threads

1. Change user password using shell script

2. Automated password change from within shell script.

3. changing password via shell script

4. Automated password change from within shell script.

5. Change User's password in shell

6. Looking for a cgi script so users can change their passwords through apache

7. Connecting telnet users from shell script without giving password

8. Running a script in csh that will change the password of 200 users without being interactive


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software