Sponsored Content
Full Discussion: Useradd issue
Operating Systems Linux Red Hat Useradd issue Post 302410405 by m1xram on Tuesday 6th of April 2010 01:24:17 AM
Old 04-06-2010
Perl crypt()

See perldoc -f crypt.
Quote:
crypt PLAINTEXT, SALT
Where PLAINTEXT is the password in this case
Where SALT is a two character string, matches regexp /[./0-9A-Za-z]{2}/
Many people use seconds to come up with a SALT string but in a tight loop you may pull the the same second. Do something with this...
Code:
sub fractime () {
  use Time::HiRes qw ( time );
  my $now = time;
  $now -= int($now);
  return $now;
}

That will give you a factional time where you can use string operators to suck out two digits at a time and the modulo them to the set of 64 characters available for the SALT with...
Code:
sub randsalt($) {
  my ($fractime) = @_;

  my $saltset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
  my $salt = "";
  for (my $i = 0; $i < 2; ++$i) {
    my $s = substr($fractime, ($i * 2) + 2, 2) % length($saltset);
    $salt .= substr($saltset, $s, 1);
  }
  return $salt;
}

So we call these two functions in Perl and return the password.
Code:
my $ft = fractime();
#print $ft, "\n";
my $salt = randsalt($ft);
#print $salt, "\n";
print crypt($ARGV[0], $salt), "\n";

See attachment for Perl code and remember to 'chmod' it. We can now get the proper password in BASH with...
Code:
#!/bin/bash
PASS=$(./test8.pl somepassword)

I tested the 'useradd' command and it worked correctly with adding the account under Fedora12. Sorry for the hedge bet but the documentation says the default '-p' option is to disable the account? This sounds strange.

Good Luck.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

useradd

I work on some hp ux 11.00 Servers. i have to add an user. i use the useradd command like follows: useradd -u 72022 -g 71095 -c " comment " -d /PACKAGE_NAME/home/username -s /usr/bin/sh username The command returns with error 3. The manpage means value number 3: Invalid argument supplied to an... (6 Replies)
Discussion started by: ortsvorsteher
6 Replies

2. UNIX for Advanced & Expert Users

useradd

Hi. due to some needs i gave a user the premission to use useradd command with sudo. i want to know if there is a way to let him set the initial password, without giving him the premission to use passwd command as root (sudo). maybe a way to set a default password for all the new users that... (2 Replies)
Discussion started by: dorilevy
2 Replies

3. Solaris

useradd

Hi, I need to add a new user who will only be able to access one single folder on my Solaris 9 system. Can this be achieved by using just useradd or do i need to fiddle with auth_attr table? TIA, Selma (4 Replies)
Discussion started by: Selma
4 Replies

4. UNIX for Dummies Questions & Answers

useradd question

The man pages for useradd show the -k flag as a option, problem is I don't know what the description means. Could someone explain what "an alternative skel directory" is? Is skel an acronym? Thanks From the man page: -k, --skel skeldir Specify an alternative skel... (1 Reply)
Discussion started by: thumper
1 Replies

5. Shell Programming and Scripting

useradd

Gurus, I need to add a user to all the machines. I need a script to do this. I did one but it does not allow me to su to root within a ssh session i open. It exists saying su: Sorry. Please let me know how i can do it. I do not have the freedom of using sudo either. Regards (4 Replies)
Discussion started by: earlysame55
4 Replies

6. UNIX for Advanced & Expert Users

useradd?

Hi Experts, when using useradd command, what are the necessary options/arguments to be included? Please advice. (4 Replies)
Discussion started by: etcpasswd
4 Replies

7. Shell Programming and Scripting

Help with useradd script

Ok Im trying too make this shell script create users from my text file, I also want to type in a password for the new users. So thay can make a uniq one themself after first logon. #!/bin/sh # Sebastian schmidt clear echo "*************************************************************"... (3 Replies)
Discussion started by: chipmunken
3 Replies

8. Solaris

useradd

if useradd command is deleted in solaris how do we add user (3 Replies)
Discussion started by: vivek_ng
3 Replies

9. Solaris

useradd problem

:wall:i want to create a user in solaris whose password expires after every 30 minutes and he has to change his password after evry thirty minutes.How can we do that?:confused: thanx and regards, shekhar (17 Replies)
Discussion started by: shekhar_4_u
17 Replies

10. Solaris

useradd

I want to creat a 27 logins in solaris.Can anyone tell me how to write a script for that so that i create at a time for all 27 people. Thanks to guide me. (6 Replies)
Discussion started by: kkalyan
6 Replies
Crypt::UnixCrypt_XS(3pm)				User Contributed Perl Documentation				  Crypt::UnixCrypt_XS(3pm)

NAME
Crypt::UnixCrypt_XS - perl xs interface for a portable traditional crypt function. SYNOPSIS
use Crypt::UnixCrypt_XS qw/crypt/; my $hashed = crypt( $password, $salt ); use Crypt::UnixCrypt_XS qw/crypt_rounds fold_password base64_to_block block_to_base64 base64_to_int24 int24_to_base64 base64_to_int12 int12_to_base64/; $block = crypt_rounds( $password, $nrounds, $saltnum, $block ); $password = fold_password( $password ); $block = base64_to_block( $base64 ); $base64 = block_to_base64( $block ); $saltnum = base64_to_int24( $base64 ); $base64 = int24_to_base64( $saltnum ); $saltnum = base64_to_int12( $base64 ); $base64 = int12_to_base64( $saltnum ); DESCRIPTION
This module implements the DES-based Unix crypt function. For those who need to construct non-standard variants of crypt, the various building blocks used in crypt are also supplied separately. FUNCTIONS
crypt( PASSWORD, SALT ) This is the conventional crypt interface. PASSWORD and SALT are both strings. The password will be hashed, in a manner determined by the salt, and a string is returned containing the salt and hash. The salt is at the beginning of the returned string, and only the beginning of the salt string is examined, so it is acceptable to use a string returned by crypt as a salt argument. Three different types of hashing may occur: If the salt is an empty string, then the password is ignored and an empty string is returned. The empty salt/hash string is thus used to not require a password. If the salt string starts with two base 64 digits (from the set [./0-9A-Za-z]), then the password is hashed using the traditional DES- based algorithm. The salt is used to modify the DES algorithm in one of 4096 different ways. The first eight characters of the password are used as a DES key, to encrypt a block of zeroes through 25 iterations of the modified DES. The block output by the final iteration is the hash, and it is returned in base 64 (as eleven digits). If the salt string starts with an underscore character and then eight base 64 digits then the password is hashed using the extended DES-based algorithm from BSDi. The first four base 64 digits specify how many encryption rounds are to be performed. The next four base 64 digits are used to modify the DES algorithm in one of 16777216 different ways. If the password is longer than eight characters, it is hashed down to eight characters before being used as a key, so all characters of the password are significant. crypt_rounds( PASSWORD, NROUNDS, SALTNUM, BLOCK ) This is the core of the DES-based crypt algorithm, exposed here to allow variant hash functions to be built. PASSWORD is a string; its first eight characters are used as a DES key. SALTNUM is an integer; its low 24 bits are used to modify the DES algorithm. BLOCK must be a string exactly eight bytes long. The data block is passed through NROUNDS iterations of the modified DES, and the final output block (also a string of exactly eight bytes) is returned. fold_password( PASSWORD ) This is the pre-hashing algorithm used in the extended DES algorithm to fold a long password to the size of a DES key. It takes a password of any length, and returns a password of eight characters which is completely equivalent in the extended DES algorithm. Note: the password returned may contain NUL characters. The functions in this module correctly handle NULs in password strings, but a normal C library crypt cannot. If you need the short password to contain no NULs, perform the substitution "s//x80/g": the top bit of each password character is ignored, so the result is equivalent. base64_to_block( BASE64 ) This converts a data block from a string of eleven base 64 digits to a raw string of eight bytes. block_to_base64( BLOCK ) This converts a data block from a raw string of eight bytes to a string of eleven base 64 digits. base64_to_int24( BASE64 ) This converts a 24-bit integer from a string of four base 64 digits to a Perl integer. int24_to_base64( VALUE ) This converts a 24-bit integer from a Perl integer to a string of four base 64 digits. base64_to_int12( BASE64 ) This converts a 12-bit integer from a string of two base 64 digits to a Perl integer. int12_to_base64( VALUE ) This converts a 12-bit integer from a Perl integer to a string of two base 64 digits. EXPORT None by default. RATIONALE
Crypt::UnixCrypt_XS provide a fast portable crypt function. Perl's internal crypt is not present at every system. Perl calls the crypt function of the system's C library. This may lead to trouble if the system's crypt presents different results for the same key and salt, but different processid's. Crypt::UnixCrypt is the cure here, but it is to slow. On my computer Crypt::UnixCrypt_XS is about 800 times faster than Crypt::UnixCrypt. SEE ALSO
crypt(3), Crypt::UnixCrypt AUTHOR
Boris Zentner, <bzm@2bz.de>, the original C source code was written by Eric Young, eay@psych.uq.oz.au. CREDITS
Fixes, Bug Reports, Docs have been generously provided by: Andrew Main (Zefram) <zefram@fysh.org> Guenter Knauf Thanks! COPYRIGHT AND LICENSE
Copyright (C) 2004, 2005, 2006, 2007 by Boris Zentner This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2007-09-10 Crypt::UnixCrypt_XS(3pm)
All times are GMT -4. The time now is 06:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy