summaryrefslogtreecommitdiffstats
path: root/base/tps/apache/cgi-bin/sow/cfg.pl
blob: 64e612aaa89b647719aaf07d56a53279cc6dacec (plain)
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
#! /usr/bin/perl
#
# --- BEGIN COPYRIGHT BLOCK ---
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright (C) 2007 Red Hat, Inc.
# All rights reserved.
# --- END COPYRIGHT BLOCK ---
#

#
# Establish platform-dependent variables:
#
my $ldapsearch="/usr/bin/ldapsearch";

#
# Feel free to modify the following parameters:
#
my $ldapHost = "localhost";
my $ldapPort = "389";
my $basedn = "ou=People,dc=sfbay,dc=redhat,dc=com";
my $port = "7888";
my $secure_port = "7889";
my $host = "localhost";

my $cfg = "/var/lib/pki-tps/conf/CS.cfg";

sub get_ldapsearch()
{
  return $ldapsearch;
}

sub get_ldap_host()
{
  my $ldapport = `grep auth.instance.0.hostport $cfg | cut -c26-`;
  chomp($ldapport);
  my ($ldapHost, $p) = split(/:/, $ldapport);
  return $ldapHost;
}

sub get_ldap_port()
{
  my $ldapport = `grep auth.instance.0.hostport $cfg | cut -c26-`;
  chomp($ldapport);
  my ($p, $ldapPort) = split(/:/, $ldapport);
  return $ldapPort;
}

sub get_base_dn()
{
  my $basedn = `grep auth.instance.0.baseDN $cfg | cut -c24-`;
  chomp($basedn);
  return $basedn;
}

sub get_port()
{
  my $port = `grep service.unsecurePort $cfg | cut -c22-`;
  chomp($port);
  return $port;
}

sub get_secure_port()
{
  my $secure_port = `grep service.securePort $cfg | cut -c20-`;
  chomp($secure_port);
  return $secure_port;
}

sub get_host()
{
  my $host = `grep service.machineName $cfg | cut -c21-`;
  chomp($host);
  return $host;
}

sub is_agent()
{
  my ($dn) = @_;

  my $uid = $dn;
  # need to map a subject dn into user DN
  $uid =~ /uid=([^,]*)/; # retrieve the uid
  $uid = $1;

  my $x_hostport = `grep -e "^tokendb.hostport" $cfg | cut -c18-`;
  chomp($x_hostport);
  my ($x_host, $x_port) = split(/:/, $x_hostport);
  my $x_basedn = `grep -e "^tokendb.userBaseDN" $cfg | cut -c20-`;
  chomp($x_basedn);
  my $x_binddn = `grep -e "^tokendb.bindDN" $cfg | cut -c16-`;
  chomp($x_binddn);
  my $x_bindpwdpath = `grep -e "^tokendb.bindPassPath" $cfg | cut -c22-`;
  chomp($x_bindpwdpath);
  my $x_bindpwd = `grep -e "^tokendbBindPass" $x_bindpwdpath | cut -c17-`;
  chomp($x_bindpwd);

   my $cmd = $ldapsearch . " " .
            "-x" .
            "-D \"" . $x_binddn . "\" " .
            "-w \"" . $x_bindpwd . "\" " .
            "-b \"" . "cn=TUS Officers,ou=Groups,".$x_basedn . "\" " .
            "-h \"" . $x_host . "\" " .
            "-p \"" . $x_port ."\" " .
            "-LLL \"(uid=" . $uid . "*)\" | wc -l";

  my $matched = `$cmd`;

  chomp($matched);

  if ($matched eq "0" || $matched eq "") {
    return 0;
  } else {
    return 1;
  }
}

sub is_user()
{
  my ($dn) = @_;

  my $uid = $dn;
  # need to map a subject dn into user DN
  $uid =~ /uid=([^,]*)/; # retrieve the uid
  $uid = $1;

  my $x_host = get_ldap_host();
  $x_port = get_ldap_port();
  my $x_basedn = get_base_dn();
  chomp($x_basedn);
  my $x_binddn = `grep -e "^tokendb.bindDN" $cfg | cut -c16-`;
  chomp($x_binddn);
  my $x_bindpwdpath = `grep -e "^tokendb.bindPassPath" $cfg | cut -c22-`;
  chomp($x_bindpwdpath);
  my $x_bindpwd = `grep -e "^tokendbBindPass" $x_bindpwdpath | cut -c17-`;
  chomp($x_bindpwd);

   my $cmd = $ldapsearch . " " .
            "-x" .
            "-D \"" . $x_binddn . "\" " .
            "-w \"" . $x_bindpwd . "\" " .
            "-b \"" . "ou=people,".$x_basedn . "\" " .
            "-h \"" . $x_host . "\" " .
            "-p \"" . $x_port ."\" " .
            "-LLL \"(uid=" . $uid . "*)\" | wc -l";


  my $matched = `$cmd`;

  chomp($matched);

  if ($matched eq "0" || $matched eq "") {
    return 0;
  } else {
    return 1;
  }
}