]> arthur.barton.de Git - netatalk.git/blobdiff - contrib/macusers/macusers.in
macusers showed root user. Bug #495.
[netatalk.git] / contrib / macusers / macusers.in
index 75ddb5c4366e41eb78b2e0d432a9209ae5a06470..7366a8b6c7135fe4b1fa755eecc3fef381676ff2 100644 (file)
@@ -2,14 +2,25 @@
 
 use strict;
 use Socket;
-use vars qw($MAC_PROCESS $PS_STR $MATCH_STR $ASIP_PORT_NO $ASIP_PORT $LSOF);
+use File::Basename;
+use vars qw($MAIN_PID $NETATALK_PROCESS $AFPD_PROCESS $PS_STR $MATCH_STR $ASIP_PORT_NO $ASIP_PORT $LSOF);
 
 # Written for linux; may have to be modified for your brand of Unix.
 # Support for FreeBSD added by Joe Clarke <marcus@marcuscom.com>.
 # Support Solaris added by Frank Lahm <franklahm@googlemail.com>.
 # Support has also been added for 16 character usernames.
 
-$MAC_PROCESS = "afpd";
+if ($ARGV[0] =~ /^(-v|-version|--version)$/ ) {
+        printf ("%s \(Netatalk @NETATALK_VERSION@\)\n", basename($0));
+        exit(1);
+} elsif ($ARGV[0] =~ /^(-h|-help|--help)$/ ) {
+        printf ("usage: %s \[-v|-version|--version|-h|-help|--help\]\n", basename($0));
+        printf ("Show users connecting via AFP\n");
+        exit(1);
+}
+
+$NETATALK_PROCESS = "netatalk";
+$AFPD_PROCESS = "afpd";
 if ($^O eq "freebsd" || $^O eq "openbsd") {
         $PS_STR    = "-awwxouser,pid,ppid,start,command";
         $MATCH_STR = '(\w+)\s+(\d+)\s+(\d+)\s+([\d\w:]+)';
@@ -28,10 +39,10 @@ $LSOF = 1;
 my %mac = ();
 
 if ($^O eq "freebsd") {
-        open(SOCKSTAT, "sockstat -4 | grep $MAC_PROCESS | grep -v grep |");
+        open(SOCKSTAT, "sockstat -4 | grep $AFPD_PROCESS | grep -v grep |");
 
         while (<SOCKSTAT>) {
-                next if ($_ !~ /$MAC_PROCESS/);
+                next if ($_ !~ /$AFPD_PROCESS/);
                 $_ =~
                     /\S+\s+\S+\s+(\d+)\s+\d+\s+[\w\d]+\s+[\d\.:]+\s+([\d\.]+)/;
                 my ($pid, $addr, $host);
@@ -72,8 +83,19 @@ if ($^O eq "freebsd") {
 
 open(PS, "ps $PS_STR |") || die "Unable to open a pipe to ``ps''";
 
+$MAIN_PID = 1;
+while (<PS>) {
+        next if ($_ !~ /$NETATALK_PROCESS/);
+        my ($user, $pid, $ppid, $time, $name, $uid, $t, $ip);
+        $_ =~ /$MATCH_STR/;
+        $MAIN_PID = $2;
+}
+
+close(PS);
+open(PS, "ps $PS_STR |") || die "Unable to open a pipe to ``ps''";
+
 while (<PS>) {
-        next if ($_ !~ /$MAC_PROCESS/);
+        next if ($_ !~ /$AFPD_PROCESS/);
         my ($user, $pid, $ppid, $time, $name, $uid, $t, $ip);
         $_ =~ /$MATCH_STR/;
         $user = $1;
@@ -81,7 +103,7 @@ while (<PS>) {
         $ppid = $3;
         $time = $4;
 
-        if ($ppid != 1) {
+        if ($ppid != $MAIN_PID) {
                 if ($^O eq "solaris") {
                         open(PFILES, "pfiles $pid |");
                         while (<PFILES>) {