Greetings All,
I am new to this site and also to perl in many ways but do have a lot of
programming in C/C++ and a few other languages.
I am working on a small program that will inteface a CGI application
that I have with samba which we have set up but there seems to be a
problem in the getpwnam function. It seems that if I run my scripts as
"root" then they seem to run and add the user to the system passwd file
as well as the proper information to the /etc/samba/smbpasswd files as well.
But if I run it from a cgi then not all of the information is put into
the smbpasswd and only part of it is put in.
My 3 perl scripts looks like this:
adduser -------------------------------------------
#!/bin/sh
sudo adduser.pl "$@"
sudo adduser_samba.pl "$@"
-------------------------------------------
adduser.pl-------------------------------------------
#!/usr/bin/perl
use Getopt::Long;
use Crypt::PasswdMD5;
die "incorrect arguments"
if ! GetOptions( 'user-name=s', \$opt{uname},
'home-dir=s', \$opt{dir},
'group=s', \$opt{group},
'uid:i', \$opt{uid},
'gid:i', \$opt{gid},);
die "--user-name required" unless $opt{uname};
die "--home-dir required" unless $opt{dir};
die "--group required" unless $opt{group};
$plain_password = <>;
chomp($plain_password);
$salt = join '', ('.', '/', 0..9, 'A'..'Z','a'..'z')[rand 64, rand 64];
#[[PLAIN]]$password = crypt($plain_password, $salt );
# for Linux with MD5 hashed passwords
$password = unix_md5_crypt($plain_password, $salt);
$password =~ s/\$/\\\$/g;
if ($opt{gid} > 0) {
`/usr/sbin/groupadd -g $opt{gid} $opt{group} 1>&2`;
} else {
`/usr/sbin/groupadd $opt{group} 1>&2`;
}
if ($opt{uid} > 0) {
`/usr/sbin/adduser -d "$opt{dir}" -g "$opt{group}" -m -p "$password" -s
"/nonexistent" -u $opt{uid} "$opt{uname}" 1>&2`;
} else {
`/usr/sbin/adduser -d "$opt{dir}" -g "$opt{group}" -m -p "$password" -s
"/nonexistent" "$opt{uname}" 1>&2`;
}
if (0 == $?) {
# fix permissions
`chmod 711 $opt{dir}`;
print `id -u $opt{uname}`;
}
exit($?>>8);
-------------------------------------------
adduser_samba.pl---------------------------------
#!/usr/bin/perl
use Getopt::Long;
use Crypt::PasswdMD5;
use Crypt::SmbHash;
die "incorrect arguments"
if ! GetOptions( 'user-name=s', \$opt{uname},
'home-dir=s', \$opt{dir},
'group=s', \$opt{group},
'uid:i', \$opt{uid},
'gid:i', \$opt{gid},);
die "--user-name required" unless $opt{uname};
die "--home-dir required" unless $opt{dir};
die "--group required" unless $opt{group};
$plain_password = <>;
chomp($plain_password);
$salt = join '', ('.', '/', 0..9, 'A'..'Z','a'..'z')[rand 64, rand 64];
# Handle our Samba User Password for HSphere
ntlmgen $plain_password, $lm, $nt;
$uid = (getpwnam($opt{uname}))[2];
my ($login, undef, $uid) = getpwnam($opt{uname});
printf "%s:%d:%s:%s:[%-11s]:LCT-%08X\n", $login, $uid, $lm, $nt, "U", time;
open (example, ">>/etc/samba/smbpasswd") || die ("Could not open file. $!");
printf example "%s:%d:%s:%s:[%-11s]:LCT-%08X\n", $login, $uid, $lm, $nt,
"U", time;
close (example);
exit(1);
------------------------------------
If I run the script as "root" from the command line like this:
./adduser --user-name=wwwtest --home-dir=/home/wwwuser --group=wwwuser
--uid=520 --gid=503
groupadd: group wwwuser exists
520
This is in my smbpasswd file.
wwwtest:520:AAD3B435B51404EEAAD3B435B51404EE:31D6CFE0D16AE931B73C59D7E0C089C0:[U
]:LCT-43EC4D9A
If I run the scripts from my cgi application then these lines do not
seem to work:
$uid = (getpwnam($opt{uname}))[2];
my ($login, undef, $uid) = getpwnam($opt{uname});
and I get
:0:6089B6316B3577C4944E2DF489A880E4:68365827D79C4F5CC9B52B688495FD51:[U
]:LCT-43EC5035
If you notice the first 2 entries then something strange is happening.
Does anyone have any ideas on how to fix this?
--
Sincerely and have a good day,
Lonnie T. Cumberland
Email: [EMAIL PROTECTED]
[EMAIL PROTECTED]
Recommended sites:
http://www.peoplesquest.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>