Advertisement
Dyrcona

PINES-ldirectord.patch

Sep 11th, 2019
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 13.85 KB | None | 0 0
  1. --- /usr/sbin/ldirectord    2019-05-08 16:53:17.000000000 -0400
  2. +++ ldirectord  2019-09-11 13:00:24.857759067 -0400
  3. @@ -130,10 +130,10 @@
  4.  
  5.  If defined in a virtual server section then the global value is overridden.
  6.  
  7. -If undefined then the value of checktimeout is used.  checktimeout is
  8. +If undefined then the value of connecttimeout is used.  connecttimeout is
  9.  also a global value that may be overridden by a per-virtual setting.
  10.  
  11. -If both negotiatetimeout and checktimeout are unset, the default is used.
  12. +If both negotiatetimeout and connecttimeout are unset, the default is used.
  13.  
  14.  Default: 30 seconds
  15.  
  16. @@ -214,9 +214,6 @@
  17.  real servers for a virtual service are down or when the first real server
  18.  comes up again. In the first case, it is called with "start" as its first
  19.  argument, in the latter with "stop".
  20. -Additional parameters are vserver with vport (vserver:vport) as second param
  21. -and protocol (tcp/udp) as third param to identify the virtual service
  22. -within the fallback script.
  23.  
  24.  If defined in a virtual server section then the global value is overridden.
  25.  
  26. @@ -341,12 +338,6 @@
  27.  
  28.  Default: I<yes>
  29.  
  30. -B<readdquiescent = >B<yes> | B<no>
  31. -
  32. -If I<yes>, then when real or failback servers are determined
  33. -to be down, they are readded to the kernel's LVS table with weight 0 if
  34. -they do not exist in the table. Setting the value to no, allows manually
  35. -removing the realserver to manually disable all persistent connections.
  36.  
  37.  B<cleanstop = >B<yes> | B<no>
  38.  
  39. @@ -576,8 +567,6 @@
  40.  
  41.  For a DNS check this should be any one the A record's addresses or
  42.  any one of the PTR record's names.
  43. -In case of dynamic DNS answers (different answers on the same question)
  44. -a regex to match multiple addresses or PTR record names could also defined.
  45.  
  46.  For a MySQL check, the receive setting is not used.
  47.  
  48. @@ -602,7 +591,7 @@
  49.  For FTP, IMAP, LDAP, MySQL, Oracle, POP and PostgreSQL, the username
  50.  used to log in.
  51.  
  52. -For Radius the username is used for the attribute User-Name.
  53. +For Radius the passwd is used for the attribute User-Name.
  54.  
  55.  For SIP, the username is used as both the to and from address for an
  56.  OPTIONS query.
  57. @@ -705,13 +694,6 @@
  58.  
  59.  Default: no separate logging of service checks.
  60.  
  61. -B<ops = >B<yes> | B<no>
  62. -
  63. -Specify that a virtual service uses one-packet scheduling. This option
  64. -can be used only for UDP services. If this option is specified, all connections
  65. -are created only to schedule one packet. Option is useful to schedule
  66. -UDP packets from same client port to different real servers.
  67. -
  68.  =head1 IPv6
  69.  
  70.  Directives for IPv6 are virtual6, real6, fallback6.
  71. @@ -723,9 +705,7 @@
  72.  
  73.  B<checktype: >B<connect> | B<external> | B<external-perl> | B<negotiate> | B<off> | B<on> | B<checktimeout>I<N>
  74.  
  75. -B<service: >B<dns> | B<http> | B<https> | B<nntp> | B<none> | B<simpletcp> | B<sip>
  76. -
  77. -Note: When using a service type with http or https, you need to install perl module perl-Net-INET6Glue.
  78. +B<service: >B<dns> | B<nntp> | B<none> | B<simpletcp> | B<sip>
  79.  
  80.  
  81.  =head1 FILES
  82. @@ -753,6 +733,8 @@
  83.  
  84.  =cut
  85.  
  86. +#Disable SSL Verification
  87. +$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
  88.  use strict;
  89.  # Set defaults for configuration variables in the "set_defaults" function
  90.  use vars qw(
  91. @@ -769,7 +751,6 @@
  92.         $CHECKCOUNT
  93.         $FAILURECOUNT
  94.         $QUIESCENT
  95. -       $READDQUIESCENT
  96.         $FORKING
  97.         $EMAILALERT
  98.         $EMAILALERTFREQ
  99. @@ -849,12 +830,7 @@
  100.  #use English;
  101.  #use Time::HiRes qw( gettimeofday tv_interval );
  102.  use Socket;
  103. -use Socket6 qw(NI_NUMERICHOST NI_NUMERICSERV NI_NAMEREQD getaddrinfo getnameinfo inet_pton inet_ntop);
  104. -# Workaround warnning messages : Three "_in6" symbols redefined.
  105. -eval "use Socket6 qw(pack_sockaddr_in6)" unless defined &pack_sockaddr_in6;
  106. -eval "use Socket6 qw(sockaddr_in6)" unless defined &sockaddr_in6;
  107. -eval "use Socket6 qw(unpack_sockaddr_in6)" unless defined &unpack_sockaddr_in6;
  108. -
  109. +use Socket6;
  110.  use Sys::Hostname;
  111.  use POSIX qw(setsid :sys_wait_h);
  112.  use Sys::Syslog qw(:DEFAULT setlogsock);
  113. @@ -1281,7 +1257,6 @@
  114.     $MAINTDIR         = undef;
  115.     $NEGOTIATETIMEOUT = -1;
  116.     $QUIESCENT        = "no";
  117. -   $READDQUIESCENT   = "no";
  118.     $SUPERVISED       = "no";
  119.     $SMTP             = undef;
  120.  }
  121. @@ -1381,7 +1356,6 @@
  122.             $vsrv{num_connects} = 0;
  123.             $vsrv{httpmethod} = "GET";
  124.             $vsrv{secret} = "";
  125. -           $vsrv{ops} = "no";
  126.             push(@VIRTUAL, \%vsrv);
  127.             while(<CFGFILE>) {
  128.                 $line++;
  129. @@ -1515,12 +1489,6 @@
  130.                     } else {
  131.                         &config_error($line, "invalid protocol");
  132.                     }
  133. -               } elsif ($rcmd  =~ /^ops\s*=\s*(.*)/) {
  134. -                   if ($1 eq "yes" || $1 eq "no") {
  135. -                       $vsrv{ops} = $1;
  136. -                   } else {
  137. -                       &config_error($line, "ops must be 'yes' or 'no'");
  138. -                   }
  139.                 } elsif ($rcmd =~ /^service\s*=\s*(.*)/) {
  140.                     $1 =~ /(\w+)/ && ($1 eq "dns"   ||
  141.                               $1 eq "ftp"   ||
  142. @@ -1731,11 +1699,6 @@
  143.                 or &config_error($line,
  144.                     "quiescent must be 'yes' or 'no'");
  145.             $QUIESCENT = $1;
  146. -       } elsif ($linedata  =~ /^readdquiescent\s*=\s*(.*)/) {
  147. -           ($1 eq "yes" || $1 eq "no")
  148. -               or &config_error($line,
  149. -                   "readdquiescent must be 'yes' or 'no'");
  150. -           $READDQUIESCENT = $1;
  151.         } elsif  ($linedata  =~ /^emailalert\s*=\s*(.*)/) {
  152.             $EMAILALERT = read_emailalert($line, $1);
  153.         } elsif  ($linedata  =~ /^emailalertfreq\s*=\s*(\d*)/) {
  154. @@ -2011,7 +1974,7 @@
  155.                 " (could not resolve host)");
  156.         }
  157.         if( defined($port) ){
  158. -           $resolved_port=&ld_getservbyname($port,"");
  159. +           $resolved_port=&ld_getservbyname($port);
  160.             unless( defined($resolved_port) ){
  161.                 &config_error($line,
  162.                     "invalid port ($port) for real server" .
  163. @@ -2108,7 +2071,7 @@
  164.     my $new_rsrv;
  165.     my $rsrv;
  166.  
  167. -   $new_rsrv = {"server"=>$ip, "port"=>$port, "failcount"=>0};
  168. +   $new_rsrv = {"server"=>$ip, "port"=>$port};
  169.  
  170.     $flags =~ /(\w+)(.*)/ && ($1 eq "gate" || $1 eq "masq" || $1 eq "ipip")
  171.         or &config_error($line, "forward method must be gate, masq or ipip");
  172. @@ -2263,9 +2226,6 @@
  173.             $$v{proto} = "-f";
  174.         }
  175.         $$v{flags} = "$$v{proto} " .  &get_virtual_option($v) . " ";
  176. -       if ($$v{protocol} eq "udp" && $$v{ops} eq "yes") {
  177. -           $$v{flags} .= "-o ";
  178. -       }
  179.         $$v{flags} .= "-s $$v{scheduler} " if defined ($$v{scheduler});
  180.         if (defined $$v{persistent}) {
  181.             $$v{flags} .= "-p $$v{persistent} ";
  182. @@ -2500,7 +2460,7 @@
  183.     my ($v) = (@_);
  184.  
  185.     if ($v->{"protocol"} eq "fwm") {
  186. -       return &get_virtual($v) . " "  . $v->{protocol} . (($v->{addressfamily} == AF_INET6) ? "6" : "");
  187. +       return &get_virtual($v) . " "  . $v->{protocol} . ($v->{addressfamily} == AF_INET6 ? "6" : "");
  188.     }
  189.     else {
  190.         return &get_virtual($v) . " "  . $v->{protocol};
  191. @@ -2572,12 +2532,7 @@
  192.     }
  193.  
  194.     for my $k (keys (%$server_down)) {
  195. -       my $v = $server_down->{$k};
  196. -       if ($READDQUIESCENT eq "no") {
  197. -           # Ensure that the server is initially added
  198. -           service_set(@$v[0], @$v[1], "up", {force => 1});
  199. -       }
  200. -       # Remove Server
  201. +       my $v = $server_down->{$k};
  202.         service_set(@$v[0], @$v[1], "down", {force => 1});
  203.         delete($server_down->{$k});
  204.         #sleep 5;
  205. @@ -2855,22 +2810,16 @@
  206.     }
  207.     my ($v, $r) = @_;
  208.  
  209. -   my $host = $$r{server};
  210. +   $$r{url} =~ /(http|https):\/\/([^:\/]+)(:([^\/]+))?(\/.*)/;
  211. +   my $host = $2;
  212. +   #my $port = $3;
  213. +   my $uri = $4;
  214.     my $virtualhost = (defined $$v{virtualhost} ? $$v{virtualhost} : $host);
  215.  
  216.     &ld_debug(2, "check_http: url=\"$$r{url}\" "
  217.         . "virtualhost=\"$virtualhost\"");
  218.  
  219. -   if (inet_pton(AF_INET6,&ld_strip_brackets($host))) {
  220. -       no warnings 'once';
  221. -       require Net::INET6Glue::INET_is_INET6;
  222. -       # Workaround for Net-HTTP IPv6 Address URLs Broken
  223. -       @LWP::Protocol::http::EXTRA_SOCK_OPTS = (PeerAddr => $host,
  224. -                            PeerHost => &ld_strip_brackets($host),
  225. -                            Host => &ld_strip_brackets($host));
  226. -   }
  227. -
  228. -   my $ua = new LWP::UserAgent(ssl_opts => { verify_hostname => 0 });
  229. +   my $ua = new LWP::UserAgent();
  230.  
  231.     my $h = undef;
  232.     if ($$v{service} eq "http_proxy") {
  233. @@ -2911,16 +2860,14 @@
  234.     }
  235.  
  236.     if ($$v{service} eq "https") {
  237. -                &ld_debug(2, "SSL-Cipher: " .
  238. -                        ($res->header('Client-SSL-Cipher') || '<not set>'));
  239. -                &ld_debug(2, "SSL-Cert-Subject: " .
  240. -                        ($res->header('Client-SSL-Cert-Subject') || '<not set>'));
  241. -                &ld_debug(2, "SSL-Cert-Issuer: " .
  242. -                        ($res->header('Client-SSL-Cert-Issuer') || '<not set>'));
  243. +       &ld_debug(2, "SSL-Cipher: " .
  244. +           $res->header('Client-SSL-Cipher'));
  245. +       &ld_debug(2, "SSL-Cert-Subject: " .
  246. +           $res->header('Client-SSL-Cert-Subject'));
  247. +       &ld_debug(2, "SSL-Cert-Issuer: " .
  248. +           $res->header('Client-SSL-Cert-Issuer'));
  249.     }
  250.  
  251. -   &ld_debug(2, "Return status: " . $res->status_line);
  252. -
  253.     my $recstr = $$r{receive};
  254.     if ($res->is_success && (!($recstr =~ /.+/) ||
  255.                 $res->content =~ /$recstr/)) {
  256. @@ -3060,55 +3007,36 @@
  257.     require Net::LDAP;
  258.     my $port = ld_checkport($v, $r);
  259.  
  260. -   my $result;
  261. -   my $recstr = $$r{receive};
  262. -
  263.     &ld_debug(2, "Checking ldap server=$$r{server} port=$port");
  264. -   eval {
  265. -       local $SIG{'__DIE__'} = "DEFAULT";
  266. -       local $SIG{'ALRM'} = sub { die "Timeout Alarm" };
  267. -       &ld_debug(4, "Timeout is $$v{checktimeout}");
  268. -       &ld_debug(2, "Starting Check");
  269. -       alarm $$v{checktimeout};
  270.  
  271. -       my $ldap = Net::LDAP->new("$$r{server}", port => $port,
  272. +   my $recstr = $$r{receive};
  273. +   my $ldap = Net::LDAP->new("$$r{server}", port => $port,
  274.                     timeout => $$v{negotiatetimeout});
  275. -       if(!$ldap) {
  276. -           service_set($v, $r, "down", {do_log => 1}, "Connection failed");
  277. -           &ld_debug(4, "Connection failed");
  278. -           alarm 0; # Cancel the alarm
  279. -           return $SERVICE_DOWN;
  280. -       }
  281. -
  282. -       my $mesg;
  283. -       if ($$v{login} && $$v{passwd}) {
  284. -           $mesg = $ldap->bind($$v{login}, password=>$$v{passwd}) ;
  285. -       }
  286. -       else {
  287. -           $mesg = $ldap->bind ;
  288. -       }
  289. -       if ($mesg->is_error) {
  290. -           service_set($v, $r, "down", {do_log => 1}, "Bind failed");
  291. -           &ld_debug(4, "Bind failed");
  292. -           alarm 0; # Cancel the alarm
  293. -           return $SERVICE_DOWN;
  294. -       }
  295. -
  296. -       &ld_debug(4, "Base : " . substr($$r{request},1));
  297. -       $result = $ldap->search (
  298. -           base    => substr($$r{request},1) . "",
  299. -           scope   => "base",
  300. -           filter  => "(objectClass=*)"
  301. -           );
  302. +   if(!$ldap) {
  303. +       service_set($v, $r, "down", {do_log => 1}, "Connection failed");
  304. +       &ld_debug(4, "Connection failed");
  305. +       return $SERVICE_DOWN;
  306. +   }
  307.  
  308. -       alarm 0; # Cancel the alarm
  309. -   };
  310. +   my $mesg;
  311. +   if ($$v{login} && $$v{passwd}) {
  312. +       $mesg = $ldap->bind($$v{login}, password=>$$v{passwd}) ;
  313. +   }
  314. +   else {
  315. +       $mesg = $ldap->bind ;
  316. +   }
  317. +   if ($mesg->is_error) {
  318. +       service_set($v, $r, "down", {do_log => 1}, "Bind failed");
  319. +       &ld_debug(4, "Bind failed");
  320. +       return $SERVICE_DOWN;
  321. +   }
  322.  
  323. -   if (!defined($result)) {
  324. -       service_set($v, $r, "down", {do_log => 1}, "No answer received");
  325. -                &ld_debug(2, "check timeout alarm");
  326. -                return $SERVICE_DOWN;
  327. -        }
  328. +   &ld_debug(4, "Base : " . substr($$r{request},1));
  329. +   my $result = $ldap->search (
  330. +       base    => substr($$r{request},1) . "",
  331. +       scope   => "base",
  332. +       filter  => "(objectClass=*)"
  333. +       );
  334.  
  335.     if($result->count != 1) {
  336.         service_set($v, $r, "down", {do_log => 1}, "No answer received");
  337. @@ -3637,7 +3565,6 @@
  338.     my $request;
  339.     my $server;
  340.     my ($v,$r) = @_;
  341. -   my $port = ld_checkport($v, $r);
  342.     {
  343.         # Net::DNS makes unguarded calls to eval
  344.         # which throw a fatal exception if they fail
  345. @@ -3665,7 +3592,6 @@
  346.         local $SIG{'ALRM'} = sub { die "timeout\n"; };
  347.         alarm($$v{negotiatetimeout});
  348.         $res->nameservers($server);
  349. -       $res->port($port);
  350.         if ($$v{"protocol"} eq "tcp") {
  351.             $res->usevc(1);
  352.         }
  353. @@ -3678,10 +3604,9 @@
  354.         return $SERVICE_DOWN;
  355.     }
  356.  
  357. -   my $recstr = $$r{receive};
  358.     foreach $rr ($query->answer) {
  359. -       if (($rr->type eq "A" and length($recstr) and $rr->address =~ /$recstr/) or
  360. -           ($rr->type eq "PTR" and length($recstr) and $rr->ptrdname =~ /$recstr/)) {
  361. +       if (($rr->type eq "A" and $rr->address eq $$r{"receive"}) or
  362. +           ($rr->type eq "PTR" and $rr->ptrdname eq $$r{"receive"})) {
  363.             service_set($v, $r, "up", {do_log => 1}, "Success");
  364.             return $SERVICE_UP;
  365.         }
  366. @@ -3916,23 +3841,20 @@
  367.         if (defined($or)) {
  368.             &system_wrapper("$IPVSADM -e "
  369.                     . "$ipvsadm_args $rforw -w 0");
  370. -           &ld_log("Quiescent $log_args (Weight set to 0)");
  371. -           &ld_emailalert_send("Quiescent $log_args (Weight set to 0)",
  372. -                   $v, $rservice, $currenttime);
  373.         }
  374. -       elsif ($READDQUIESCENT eq "yes") {
  375. +       else {
  376.             &system_wrapper("$IPVSADM -a "
  377.                     . "$ipvsadm_args $rforw -w 0");
  378. -           &ld_log("Readd Quiescent $log_args (Weight set to 0)");
  379. -           &ld_emailalert_send("Quiescent $log_args (Weight set to 0)",
  380. -                   $v, $rservice, $currenttime);
  381.         }
  382. +       &ld_log("Quiescent $log_args (Weight set to 0)");
  383. +       &ld_emailalert_send("Quiescent $log_args (Weight set to 0)",
  384. +                   $v, $rservice, $currenttime);
  385.     }
  386.     else {
  387.         &system_wrapper("$IPVSADM -d $ipvsadm_args");
  388.         &ld_log("Deleted $log_args");
  389.         &ld_emailalert_send("Deleted $log_args", $v,
  390. -                   $rservice, $tag eq "fallback" ? 0 : $currenttime);
  391. +                   $rservice, $currenttime);
  392.     }
  393.  }
  394.  
  395. @@ -4246,9 +4168,9 @@
  396.     $v->{fallbackcommand_status} = $status;
  397.  
  398.     if (defined($v->{fallbackcommand})) {
  399. -       &system_wrapper($v->{fallbackcommand} . " " . $status . " " . $v->{server} . ":" . $v->{port} . " " . $v->{protocol});
  400. +       &system_wrapper($v->{fallbackcommand} . " " . $status);
  401.     } elsif (defined($FALLBACKCOMMAND)) {
  402. -       &system_wrapper($FALLBACKCOMMAND . " " . $status . " " . $v->{server} . ":" . $v->{port} . " " . $v->{protocol});
  403. +       &system_wrapper($FALLBACKCOMMAND . " " . $status);
  404.     }
  405.  }
  406.  
  407. @@ -4477,14 +4399,13 @@
  408.     my $smtp = Net::SMTP->new($smtp_server);
  409.  
  410.     if ($smtp) {
  411. -       my $myusername = getpwuid( $< );
  412. -       $smtp->mail("$myusername\@$hostname");
  413. +       $smtp->mail("$ENV{USER}\@$hostname");
  414.         $smtp->to($to_addr);
  415.         $smtp->data();
  416.         if($EMAILALERTFROM) {
  417.             $smtp->datasend("From: $EMAILALERTFROM\n");
  418.         } else {
  419. -           $smtp->datasend("From: $myusername\@$hostname\n");
  420. +           $smtp->datasend("From: $ENV{USER}\@$hostname\n");
  421.         }
  422.         $smtp->datasend("To: $to_addr\n");
  423.         $smtp->datasend("Subject: $subject\n\n");
  424. @@ -4906,7 +4827,7 @@
  425.     my ($v) = (@_);
  426.  
  427.     if ($v->{"protocol"} eq "fwm") {
  428. -       return $v->{"protocol"} . (($v->{addressfamily} == AF_INET6)?"6":"") . ":" .  &get_virtual($v);
  429. +       return $v->{"protocol"} . ($v->{addressfamily} == AF_INET6?"6":"") . ":" .  &get_virtual($v);
  430.     }
  431.     else {
  432.         return $v->{"protocol"} . ":" .  &get_virtual($v);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement