Modula-2 || Compiler & Tools || Library || Search Engine
TYPE Pwent = RECORD logname: ARRAY [0..7] OF CHAR; password: ARRAY [0..15] OF CHAR; uid: CARDINAL; gid: CARDINAL; fullname: ARRAY [0..31] OF CHAR; dir: ARRAY [0..31] OF CHAR; shell: ARRAY [0..31] OF CHAR; END;
PROCEDURE OpenPw(filename: ARRAY OF CHAR): BOOLEAN; PROCEDURE GetPwent(VAR pwent: Pwent): BOOLEAN; PROCEDURE GetPwuid(uid: CARDINAL; VAR pwent: Pwent): BOOLEAN; PROCEDURE GetPwnam(logn: ARRAY OF CHAR; VAR pwent: Pwent): BOOLEAN; PROCEDURE ReopenPw(): BOOLEAN; PROCEDURE ClosePw(): BOOLEAN; PROCEDURE FetchPwuid(uid: CARDINAL; VAR pwent: Pwent): BOOLEAN; PROCEDURE FetchPwnam(logn: ARRAY OF CHAR; VAR pwent: Pwent): BOOLEAN;
Between
OpenPw
and
ClosePw,
any (using
GetPwent) or the next entry whose uid cf. logname field matches
uid
cf.
logn
(using
GetPwuid
cf.
GetPwnam) that has not yet been read
will be written into the
pwent
record.
At end of file, the
GetXXX
functions return
FALSE
and the data in
pwent
is not valid.
ReopenPw
restarts reading the file from the top
if it is seekable,
otherwise reports an error.
Opening the file "/etc/passwd", searching for a single uid cf. logname and closing the file again, can all be done at once using FetchPwuid cf. FetchPwnam. This is useful for mapping numerical user IDs to names, e.g., which is the main purpose of this module.
Modula-2 || Compiler & Tools || Library || Search Engine