Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

GiveUsers

by Jerry (Scribe)
on Aug 19, 2001 at 07:01 UTC ( #105967=sourcecode: print w/ replies, xml ) Need Help??

Category: code
Author/Contact Info Jerry Fowler - jerry@digilliance.net
Description: Serves GPG encrypted versions of /etc/passwd and /etc/shadow for syncing of user accounts across multiple linux systems. Sorry about the tabs... I'll do better next time ;o)
#!/usr/bin/perl

use IO::Socket;
use File::Copy;
$sock=new IO::Socket::INET      (LocalHost => '222.22.222.22',
                                LocalPort => '60009',
                                Proto => 'tcp',
                                Listen => 2,
                                Reuse => 1
                                );
die "Socket could not be created! Reason: $!" unless $sock;
while ($new_sock = $sock->accept()) {
        copy("/etc/passwd","/tmp/giveusers/passwd");
        copy("/etc/shadow","/tmp/giveusers/shadow");
        system('gpg -e -r jerry2 -a /tmp/giveusers/passwd');
        system('gpg -e -r jerry2 -a /tmp/giveusers/shadow');
        unlink '/tmp/giveusers/passwd';
        unlink '/tmp/giveusers/shadow';

        $hersockaddr    = getpeername($new_sock);
        ($port, $iaddr) = unpack_sockaddr_in($hersockaddr);
        $herhostname    = gethostbyaddr($iaddr, AF_INET);
        $herstraddr     = inet_ntoa($iaddr);
        $date=`date`;
        open(LOG, ">>" . "/var/adm/getusers");
        print LOG "Connection from: $herhostname [$herstraddr] at $dat
+e\n";
        close(LOG);
        if (($herstraddr eq '22.22.22.22') || ($herstraddr eq '22.22.2
+2.21')) {
                open(PASSWD, "<" . "/tmp/giveusers/passwd.asc");
                while (<PASSWD>) {
                        chomp;
#                        @line=split(/:/);
#                        $cleaned="$line[0]:x:$line[2]:$line[3]::/tmp:
+/bin/false";
#                        print $new_sock "$cleaned\n";
                        print $new_sock "$_\n";
                }
                close(PASSWD);
                print $new_sock "---DELIMITER---\n";
                open(SHADOW, "<" . "/tmp/giveusers/shadow.asc");
                while (<SHADOW>) {
                        chomp;
                        print $new_sock "$_\n";
                }
                close(SHADOW);
                unlink '/tmp/giveusers/passwd.asc';
                unlink '/tmp/giveusers/shadow.asc';
        } else {
                print $new_sock "Unauthorized access from $herstraddr 
+LOGGED!!\n";
                die "$herstraddr";
        }
        close($new_sock);
}

Comment on GiveUsers
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://105967]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-07-07 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls