From 5e8f0e662dd8aeadac3757f9716da6bf50f008ef Mon Sep 17 00:00:00 2001 From: HAT Date: Tue, 21 Jan 2014 20:32:00 +0900 Subject: [PATCH] macusers showed root user. Bug #495. --- NEWS | 1 + contrib/macusers/macusers.in | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 2504a47d..2c150bdf 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,7 @@ Changes in 3.0.7 * FIX: Registering with mDNS crashed. Bug #540 * FIX: Saving from applications like Photoshop may fail, because removing the ressource fork AppleDouble file failed. Bug #542. +* FIX: macusers showed root user. Bug #495. Changes in 3.0.6 ================ diff --git a/contrib/macusers/macusers.in b/contrib/macusers/macusers.in index b3795551..7366a8b6 100644 --- a/contrib/macusers/macusers.in +++ b/contrib/macusers/macusers.in @@ -3,7 +3,7 @@ use strict; use Socket; use File::Basename; -use vars qw($MAC_PROCESS $PS_STR $MATCH_STR $ASIP_PORT_NO $ASIP_PORT $LSOF); +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 . @@ -19,7 +19,8 @@ if ($ARGV[0] =~ /^(-v|-version|--version)$/ ) { exit(1); } -$MAC_PROCESS = "afpd"; +$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:]+)'; @@ -38,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 () { - 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); @@ -82,8 +83,19 @@ if ($^O eq "freebsd") { open(PS, "ps $PS_STR |") || die "Unable to open a pipe to ``ps''"; +$MAIN_PID = 1; while () { - next if ($_ !~ /$MAC_PROCESS/); + 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 () { + next if ($_ !~ /$AFPD_PROCESS/); my ($user, $pid, $ppid, $time, $name, $uid, $t, $ip); $_ =~ /$MATCH_STR/; $user = $1; @@ -91,7 +103,7 @@ while () { $ppid = $3; $time = $4; - if ($ppid != 1) { + if ($ppid != $MAIN_PID) { if ($^O eq "solaris") { open(PFILES, "pfiles $pid |"); while () { -- 2.39.2