Hello folks,
How could I change a linux user password (with shadow) in a fpc program?
Thanx
Helio

Mailing lists / fpc-pascal / 2002-06
11 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hello folks,
How could I change a linux user password (with shadow) in a fpc program?
Thanx
Helio
Perhaps you could try something like this:
program changemypasswd;
uses Linux;
var f : text;
begin
Popen(f, '/usr/bin/passwd --stdin userid > /dev/null','w');
writeln(f, 'password');
Flush(f);
Close(f);
end.It must work - test yourself to make sure it is working.
If you like you can email me privately with info regarding the project you're making - perhaps I do have code to share (if I guess correctly what you are building).
Vassilis
Thank you Vassilis, but I thought fpc had a function to do that. I'm currently using...
shell('echo "',user,':',pass,'" | chpasswd');...but would prefer something system independent.
Does it? I know nothing about it :-)
I can't find any info in the docs as well.
Perhaps Michael can help us here (btw, michael, thanks for sending me the unit).
Vassilis
Thank you Vassilis, but I thought fpc had a function to do that. I'm currently using...…
The correct way is to use get(s)pwnam()/put(s)pwnam() from the libc library.
TPasswordRecord = record
pw_name : pchar;
pw_passwd : pchar;
pw_uid : pchar;
pw_gid : pchar;
pw_gecos : pchar;
pw_dir : pchar;
pw_shell : pchar;
end;
PPasswordRecord = ^TPasswordRecord;
getpwnam (UserName : Pchar) : PPasswordRecord;cdecl;external 'c' name getpwnam;and similar for putpwnam.
Do a man getpwent and you should get all possible info.
Take care that systems with shadow passwords use getspwnam().
Michael.
That is a Linuxism. *BSD always uses shadow passwds (stores them in /etc/master.passwd), and these are callable using the usualy functions (getpwent).
The correct way is to use get(s)pwnam()/put(s)pwnam() from the libc library.…
Great Michael, but I don't know how to use yet.
Is there any special unit to install, or everything I need is in fpc full package?
I've tried the following example, but it didn't compile.
Program Getpw;
Uses
Linux;
var
p: ^TPasswordRecord;
begin
p := getpwnam('helio');
writeln(p.pw_dir);
end.try changing this:
.....
var p: pPasswordRecord;
.....
writeln(p^.pw_dir);
ciao, ivan
It hasn't found nor the type TPasswordRecord or pPasswordRecord, neither the function getpwnam. Are them in any other unit?
Helio Cavichiolo Jr wroteIt hasn't found nor the type TPasswordRecord or pPasswordRecord, neither the function getpwnam. Are them in any other unit?
No.
You must translate the needed header files yourself; I haven't done this (yet).
Michael.
Is there any documentation or any sample to learn about this? I've never did any translation of that kind yet.