#$Id$
# TODO:
-# - Add check for ossec 1.4 and support longer agent names
-# - Add in eval so that older version of perl without
-# Time::HiRes still can use this script.
+# - Add check for ossec 1.4 and support longer agent names
+# - Add in eval so that older version of perl without
+# Time::HiRes still can use this script.
use strict;
use warnings;
use MIME::Base64;
use Digest::MD5 qw(md5_hex);
use Getopt::Long;
+use Regexp::Common::net;
use constant AUTH_KEY_FILE => "/var/ossec/etc/client.keys";
use constant RIDS_PATH => "/var/ossec/queue/rids/";
}
# Adding a new agent
elsif ($add) {
- if ($agentname && $ipaddress && $ipaddress =~
- m/(1?\d\d?|2[0-4]\d|25[0-5])(\.(1?\d\d?|2[0-4]\d|25[0-5])){3}/ &&
+ if ($agentname && $ipaddress &&
+ (
+ $ipaddress =~ m/$RE{net}{IPv4}/
+ ||
+ $ipaddress =~ m/$RE{net}{IPv6}/
+ ||
+ $ipaddress eq 'any'
+ ) &&
# ossec doesn't like agent names > 32 characters.
length($agentname) <= 32) {
close(FH);
if (@used_agent_ids) {
- @used_agent_ids = sort(@used_agent_ids);
+ @used_agent_ids = sort {$a <=> $b} @used_agent_ids;
$agentid = sprintf("%03d", $used_agent_ids[-1] + 1);
}
}
if(defined($key)) {
$rval = 1 if ($id == $newid && $rval == 0);
$rval = 2 if ($name eq $newname && $rval == 0);
- $rval = 3 if ($ip eq $newip && $rval == 0);
+ $rval = 3 if ($ip ne 'any' && $ip eq $newip && $rval == 0);
}
}
close(FH);
}
return $rval;
}
+