This file is indexed.

/usr/sbin/faimond is in fai-server 3.4.8ubuntu2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/perl -w
# vim:et:ts=2:sw=2:

# $Id$
#*********************************************************************
#
# faimond -- monitor daemon which collects client status info
#
# This script is part of FAI (Fully Automatic Installation)
# (c) 2003-2007 by Thomas Lange, lange@informatik.uni-koeln.de
# Universitaet zu Koeln
#
#*********************************************************************

use strict;
use Socket;
use Getopt::Std;

$| = 1;
my ($port, $timeout, $daemon, $timestamp);
my $pidfile = '/var/run/faimond.pid';
my $logfile = '-';
my $daemonlogfile = '/var/log/faimond.log';
my $useip;

our ($opt_b,$opt_h,$opt_p,$opt_l,$opt_t,$opt_d,$opt_P,$opt_T,$opt_i);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub logline(@) {
  open(LOGFILE, $logfile) or return 0;
  print LOGFILE (scalar localtime(), ' - ') if ($timestamp);
  print LOGFILE @_ or return 0;
  close(LOGFILE);
  return 1;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub signal_die(@) {
  logline(@_);
  unlink($pidfile);
  exit(1);
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub signal_warn(@) {
  logline(@_) or die "log: $!";
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub signal_deadly(@) {
  # Use the die-handler
  signal_die('Caught deadly signal ' . shift() . "\n");
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub server_init() {
  logline("FAI monitoring daemon starting..\n") or die "log: $!";

  # Init signals
  $SIG{INT} = \&signal_deadly;
  $SIG{QUIT} = \&signal_deadly;
  $SIG{TERM} = \&signal_deadly;
  $SIG{__DIE__} = \&signal_die;
  $SIG{__WARN__} = \&signal_warn;
  # HUP is usually used to reopen log files. This is not a problem
  # in this design.
  $SIG{HUP} = 'IGNORE';

  if ($daemon) {
    if (-e $pidfile) {
    # Pid file already exists. Check if it's a valid pid.
      open(PIDFILE, '<', "$pidfile") or die "open $pidfile: $!";
      my $pid = <PIDFILE>;
      chomp($pid);
      if ($pid ne '') {
      # Kill -0 exits with value 0 if pid is alive
        system("kill -0 $pid 2> /dev/null");
        if ($? == 0) {
          logline("Pidfile $pidfile exists and contains an existing pid. Exiting.\n");
          exit(1);
        }
      }
      close(PIDFILE);
    }
    eval "Proc::Daemon::Init";
    umask 022;

    open(PIDFILE, '>', "$pidfile") or die "open $pidfile: $!";
    print PIDFILE $$ or die "print $pidfile: $!";
    close(PIDFILE);
  }

  # Listen
  my $proto = getprotobyname('tcp');
  socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
  setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsockopt: $!";

  my $paddr = sockaddr_in($port, INADDR_ANY);

  bind(SERVER, $paddr) or die "bind: $!";
  listen(SERVER, SOMAXCONN) or die "listen: $!";
  logline("FAI monitoring daemon started on port $port with pid $$\n") or die "log: $!";
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub big_loop() {

  # accept a connection, print message received and close
  my ($client_addr);
  while ($client_addr = accept(CLIENT, SERVER)) {
    my ($port, $iaddr) = sockaddr_in($client_addr);
    my $ip = inet_ntoa($iaddr);

    my $inp = '';

    eval {
      local $SIG{__DIE__};
      local $SIG{__WARN__};
      local $SIG{'ALRM'} = sub { die("Timeout"); };

      alarm($timeout);
      $inp = <CLIENT>;
      alarm(0);
    };

    close CLIENT;

    if (!defined($inp) || $inp eq '') {
      # Client did not send anything, or alarm went off
      logline("$ip:$port: No data or timeout.\n") or die "log: $!"; 
      next;
    }

    if ($inp =~ /^([^\s;]+)\s+TASKEND install 0/ && $opt_b) {
      my $cname = $1;
      if ($useip) {
        $cname = $ip;
      }
      system('fai-chboot', '-d', $cname);
      logline("$ip:$port: Disabling pxelinux configuration for $cname\n") or die "log: $!";
    }
    logline("$inp") or die "log: $!";
  }
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub usage {

  print << "EOF";
faimond, FAI monitor daemon.

    Copyright (C) 2003-2007 by Thomas Lange

Usage: faimond [OPTIONS]

    -b                  Call fai-chboot to change boot parameter.
    -p PORT             Set port to listen to. Default is 4711.
    -l FILE             Logfile. Default is standard out and
                        '$daemonlogfile' in daemon mode.
    -t TIMEOUT          Timeout for bad clients. 0 to disable.
    -d                  Daemon mode.
    -P FILE             PID-file. Default is '$pidfile'.
                        Used only if starting in daemon mode.
    -T                  Print timestamps in the log.
    -i                  When using -b: send IP of client to fai-choot
                        instead of the hostname the host reports.

EOF
  exit 0;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

getopts('bhTp:l:t:dP:i') || usage;
$opt_h && usage;
$port = $opt_p || 4711;
$timeout = $opt_t || 5;
$daemon = $opt_d || 0;
$timestamp = $opt_T || 0;
$useip = $opt_i || 0;

if (defined($opt_P)) {
  $pidfile = $opt_P;
}

if (defined($opt_d)) {
  (eval "require Proc::Daemon") or
    die "Daemon mode not available, Proc::Daemon not found. Please install libproc-daemon-perl\n";
  # If in daemon mode, use standard daemon log file
  $logfile = $daemonlogfile;
}

if (defined($opt_l)) {
  $logfile = $opt_l;
}

# Constuct a $logfile that open can take as an argument
if ($logfile eq '-') {
  $logfile = ">&STDOUT";
}
else {
  $logfile = ">>$logfile";
}


server_init;
big_loop;