Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-06

Password changing

11 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Helio Cavichiolo Jr

Hello folks,

How could I change a linux user password (with shadow) in a fpc program?

Thanx

Helio

Vassilis Stathopoulos
to Helio Cavichiolo Jr

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

Show quoted text 11 lines
Hello folks, How could I change a linux user password (with shadow) in a fpc program? Thanx Helio _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Helio Cavichiolo Jr
to Vassilis Stathopoulos

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.

você wrote 22 lines
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
Vassilis Stathopoulos
to Helio Cavichiolo Jr

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

Show quoted text 6 lines
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.
Michael Van Canneyt
to Helio Cavichiolo Jr: Thank you Vassilis, but I thought fpc had a function to do that. I'm currently using...…
Helio Cavichiolo Jr wrote 6 lines
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.

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.

Marco van de Voort
to Michael Van Canneyt
Show quoted text 8 lines
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().

That is a Linuxism. *BSD always uses shadow passwds (stores them in /etc/master.passwd), and these are callable using the usualy functions (getpwent).

Helio Cavichiolo Jr
to Michael Van Canneyt: 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.
Michael Van Canneyt wrote 29 lines
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. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Ivan Montes
to Helio Cavichiolo Jr
Show quoted text 13 lines
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

Helio Cavichiolo Jr
to Ivan Montes

It hasn't found nor the type TPasswordRecord or pPasswordRecord, neither the function getpwnam. Are them in any other unit?

você wrote 27 lines
> 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 _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Michael Van Canneyt
to Helio Cavichiolo Jr
Helio Cavichiolo Jr wrote
It 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.

Helio Cavichiolo Jr
to Michael Van Canneyt

Is there any documentation or any sample to learn about this? I've never did any translation of that kind yet.

você wrote 15 lines
On Fri, 7 Jun 2002, Helio Cavichiolo Jr wrote: > It 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. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal