Hi,

Something to be aware about when modifying the password file is that it
should be locked to prevent another process from modifying it at the
same time.  There are different conventions on different systems for
doing this and they depend also on the tool for modifying the password
file.

For example, as far as I know the original BSD vipw utility creates an
advisory lock named /etc/ptmp on BSD, Solaris and Linux systems.  On
some of these systems, it does also does postprocessing of the updated
password file into dbm files.

These days, however, useradd, usermod and userdel are the standard for
updating /etc/password and they use a different locking convention on
Linux vs Solaris.  On linux, they create a lock file named
/etc/password.lock that contains the PID of the locking process.  On
Solaris, the lock file is named /etc/.pwd.lock and is created by the
lckpwdf(3C) basic C library function (see
http://docs.sun.com/db/doc/816-0213/6m6ne3852?q=password+file+lock&a=vie
w).

One way to avoid having to remember these "trivialities" is to find a
perl module in which they are all coded -- or at least mostly, so you
only have to extend the existing framework or get the original author to
do it :)

So how can you find such a module?

1. In your web browser, surf to http://www.perl.com/pub/q/resources

2. In the list of resource categories, click on one that suits the
problem.  In this case the problem is system administration, so click on
the Sysadmin link which takes you to
http://www.perl.com/cs/user/query/q/6?id_topic=71

3. Scan the list of Sysadmin topics for something directly relevant to
the problem.  Presto, there is a module named Unix::ConfigFile near the
bottom that includes a module named Unix::PasswdFile which does things
with the password file.  Clicking on the Unix::ConfigFile link takes you
to http://www.perl.com/CPAN/modules/by-authors/id/S/SS/SSNODGRA/ from
where you can download the latest sources and view the readme file.  

4. Taking a look at the readme at
http://www.perl.com/CPAN/modules/by-authors/id/S/SS/SSNODGRA/Unix-Config
File-0.06.readme it says to run "perldoc Unix::PasswdFile" after
installation to see the documentation, but let's find out now in the
hope that someone has already put it up on the Internet.

5. Enter "perldoc Unix::PasswdFile" in the Google web search form at
http://www.google.com  and 7th down on the list of returned URLs is a
link to "trustno1.net - perldoc" that redirects to
http://perldoc.trustno1.net/new/index.html which contains the perldocs
for a lot of modules including Unix::PasswdFile.  

8. Click on the Unix::PasswdFile link to read its perldoc and find it
contains a method named users( [SORTBY] ) that provides the means to
sort /etc/password by UID and by username -- see
http://perldoc.trustno1.net/new/site_perl/5.8.0/Unix/PasswdFile.html#use
rs(_[sortby]_).  And notice in the Description section of the
Unix::PasswdFile perdoc it says that "it automatically handles file
locking"!

9.  If this is the functionality you want, then install Unix::ConfigFile
from the CPAN link in (3).  Probably you will find some working example
perl programs in the distribution that you can simply modify to create
your program.

10.  If this is not the functionality you want, then you can use the
source code of Unix::PasswdFile:users( SORTBY] ) to create a another
method that sorts on the password field of your choice, or you can go
back to (3) and (2) to find another module that better does what you
need.

11.  One of the great things about perl is the large community of
programmers who have contributed opensource modules for a huge variety
of applications so that you can almost always find one that you can
either use directly to solve your problem at hand perhaps in combination
with other modules, or you can use it's sources as the starting point
for developing the precise program you need by extension and imitation.

Now you know how to do the research to find existing perl solutions and
starting points for the solutions of many problems!

-tristram


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to