This file is indexed.

/usr/bin/nuaclgen is in nuauth-utils 2.4.3-3.4.

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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/usr/bin/perl
###################################################################################
#
# nuaclgen.pl : insertion of ACls in the Nu Ldap tree.
#
# Copyright(C) 2003,2005 Eric Leblond <eric@regit.org>
#                        Vincent Deffontaines <vincent@gryzor.com>
# INL http://www.inl.fr/
#
# $Id$
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
###################################################################################
use strict;
use warnings;
use Net::LDAP;
use Getopt::Long;
use Socket;
$Getopt::Long::ignorecase=0;

my %acl;
# TODO unused variable ?
my $exit_code;

our ($basedn, $ldap_host, $username, $password);

# include conf variables
do "/etc/nufw/nuaclgen.conf" or die "Can not find config file";


sub convert_addr {
  my @list;
  my $partsum;
  my @parts;
  foreach my $address (@_) {
    @parts=split /\./, $address;
    $partsum=0;
    foreach my $part (@parts) {
      $partsum = $partsum*256 + $part;
    }
    push @list, ($partsum);
  }
  return @list if @list > 1;
  return $list[0] if @list == 1;
}

sub construct_addr_range {
  my ($range, $src , $dst);

  $range=shift;
  if ($range=~m#([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/([0-9]{1,2})#) {
    return (convert_addr($1),convert_addr($1)+2**(32-$2)-1)
  } elsif ( $range=~m/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/ ) {
    my $ip=convert_addr($range);
    return ($ip,$ip);
  } else {
    return "Invalid";
  }
}

sub construct_port_range {
  my @range =  split /:/ , shift;
  if (scalar @range == 2) {
    return @range;
  } elsif (scalar @range == 1) {
    return ($range[0], $range[0]);
  } else {
    return "OOPs";
  }
}

sub todotquad {
  my $ip = shift;
  my $stringip = $ip % 256;
  foreach my $i (0..2) {
    $ip = ( $ip - $ip%256 ) / 256;
    $stringip = $ip % 256 . "." . $stringip;
  }
  return $stringip;
}

my $separator = ",";
my ($help, $schema, $saddr, $daddr, $proto, $sport, $dport);
my ($decision, $groups, $users, $aclname, $osname, $osversion, $authquality);
my ($osrelease, $appname, $appsig, $list, $delete );


my $result = GetOptions("help" => \$help,
		     "Schema" => \$schema,
		     "saddr=s" => \$saddr,
		     "daddr=s" => \$daddr,
		     "proto=i" => \$proto,
		     "sport=s" => \$sport,
		     "dport=s" => \$dport,
		     "jump=s" => \$decision,
		     "groups=s" => \$groups,
		     "users=s" => \$users,
		     "Aclname=s" => \$aclname,
		     "OsName=s" => \$osname,
		     "OsVersion=s" => \$osversion,
		     "OsRelease=s" => \$osrelease,
		     "AppName=s" => \$appname,
		     "AppSig=s" => \$appsig,
		     "AuthQuality" => \$authquality,
                     "Separator" => \$separator,
		     "List" => \$list,
		     "Delete=s" => \$delete,
		    );

if ($result == 0) {
  die "Error parsing options\n";
}

if ($help) {
  print "nuaclgen [-S (eq|ineq)] --Aclname [ACLDN] [--saddr NETWORK1] [--daddr NETWORK2] [--proto PROTONUMBER]
        [--sport P1[:P2]] [--dport P3[:P4]] --jump [ACCEPT|DROP] [--groups [GROUPLIST] || --users [USERSLIST]]
        [--OsName N1,N2... [--OsVersion V1,V2...] [--OsRelease R1,R2...]]
        [--AppName N1,N2... [--AppSig S1,S2...]] [--AuthQuality 1]: add an acl
nuaclgen -L -g [Id Group] : list acl(s) for a group.
nuaclgen -L -u [Id User] : list acl(s) for a user.
nuaclgen --Delete dn : delete this dn ACL
SYNTAX :
\t- NETWORK : aaa.bbb.ccc.ddd[/ee]
\t- GROUPSLIST : gid1[,gid2,gid3]
\t- USERSLIST : uid1[,uid2,uid3]
\t- PORTRANGE: NNNN[:MMMM]
";
  exit;
}
if ((defined $aclname)+(defined $list)+defined($delete) > 1)
{
  die "Sorry, one mode allowed at a time only!";
}

if (defined $delete)
{
  my $mybase = $basedn;
  chomp $mybase;
  if ($delete!~/.*$mybase$/){
    print "basedn : $mybase\n";
    print "delete : $delete\n";
    die "Sorry, not allowed to delete that cn. It's not in the ACL base!";
  }
}else{

  if (not (defined($groups) or defined($users))) {
    die "No group(s) or user(s) given\n";
  }

  if (defined($groups)) {
    if ($groups=~m/,/) {
      $acl{"Group"}= [split /,/ , $groups];
    } else {
      $acl{"Group"}= $groups;
    }
  }

  if (defined($users)) {
    if ($users=~m/,/) {
      $acl{"User"}= [split /,/ , $users];
    } else {
      $acl{"User"}= $users;
    }
  }
}

#do ldap connect
my $ldap = Net::LDAP->new($ldap_host)  or die $@;;
# bind to a directory with dn and password
$result = $ldap->bind ( $username,
			password => $password
		      )  or die $@;
$result->code && warn "failed to bind: ", $result->error;


if ($aclname){

if (not defined($saddr)) {
  $saddr="0.0.0.0/0";
}
($acl{"SrcIpStart"},$acl{"SrcIpEnd"})=construct_addr_range($saddr);

if (not defined($daddr)) {
  $daddr="0.0.0.0/0";
}
($acl{"DstIpStart"},$acl{"DstIpEnd"})=construct_addr_range($daddr);

if (not defined($sport)) {
  $sport="0:65535";
}
($acl{"SrcPortStart"},$acl{"SrcPortEnd"})=construct_port_range($sport);





if (not defined($proto)) {
  $acl{"Proto"}=[6,17];
} else {
  $acl{"Proto"}=$proto;
}



if (not defined($schema) or $schema eq 'eq') {
  if (not defined($dport)) {
    die "Equality schema specified, destination port needed";
  } else {
    # split by comma
    my @dports = split(/,/,$dport);
    $acl{"DstPort"}=\@dports;
  }
} else {
  if (not defined($dport)) {
    $dport="0:65535";
  }
  ($acl{"DstPortStart"},$acl{"DstPortEnd"})=construct_port_range($dport);
}

$acl{"objectclass"}  = [ "top", "NuAccessControlList" ];
if (defined $osname){
  my @os = split(/$separator/,$osname);
  $acl{"OsName"}=\@os;
  if (defined $osversion){
    my @ver= split(/$separator/,$osversion);
    $acl{"OsVersion"}=\@ver;
  }
  if (defined $osrelease){
    my @rel= split(/$separator/,$osrelease);
    $acl{"OsVersion"}=\@rel;
  }
}
if (defined $appname){
  my @app= split(/$separator/,$appname);
  $acl{"AppName"}=\@app;
  if (defined $appsig){
    my @sig= split(/$separator/,$appsig);
    $acl{"AppSig"}=\@sig;
  }
}

if (defined $authquality){
    my @sig= split(/$separator/,$authquality);
    $acl{"AuthQuality"}=\@sig;
}

# look for Add mode
if (not defined($aclname)) {
  $exit_code = "No Acl Name given, Aborting\n";
} else {
  $aclname=~/^[a-zA-Z0-9,=_\s]+$/ or die "Sorry, bad characters in Acl name ( $aclname )";
  $aclname=~m/^cn=(\w+),.*/ and $acl{"cn"}=$1;
  if (not defined($decision)) {
    die "No decision given\n";
  } else {
    if ($decision eq "ACCEPT") {
      $acl{"Decision"}=1;
    } else {
      $acl{"Decision"}=0;
    }
  }
  print "Adding $aclname\n";
  $result = $ldap->add( $aclname,
			attr => [%acl ]) ;

  $result->code && warn "failed to add entry: ", $result->error or print "done\n";

  $ldap->unbind;		# take down session
  exit;
}
}

my $filter;

if (defined ($list)) {
  if (defined($groups)) {
    $filter = "(&(objectClass=NuAccessControlList)(Group=".$acl{"Group"}."))";
  } elsif (defined($users)) {
    $filter = "(&(objectClass=NuAccessControlList)(User=".$acl{"User"}."))";
  } else {
    die("No group or user given");
  }
  my $results = $ldap->search(	# perform a search
			   base   => $basedn,
			   filter => $filter,
			  );
  foreach my $entry ($results->all_entries) {
    my $dn = $entry->dn;
    # $entry->dump;
    # print source address
    my $sad = todotquad($entry->get_value("SrcIpStart"));
    $sad .="-". todotquad($entry->get_value("SrcIpEnd"));
    # print dest address
    my $dad = todotquad($entry->get_value("DstIpStart"));
    $dad .="-". todotquad($entry->get_value("DstIpEnd"));
    # print source port
    my $sport = $entry->get_value("SrcPortStart").":".$entry->get_value("SrcPortEnd");
    # print dest port
    my $dport = $entry->get_value("DstPort");
    if (! $dport){
    $dport = $entry->get_value("DstPortStart").":".$entry->get_value("DstPortEnd");
    }
    # print groups
    my ($dec)=$entry->get_value("Decision");
    # OSname
    $osname=$entry->get_value("OsName");
    $osversion=$entry->get_value("OsVersion");
    $osrelease=$entry->get_value("OsRelease");
    $appname=$entry->get_value("AppName");
    $appsig=$entry->get_value("AppSig");
    if ($dec) {
      $dec="ACCEPT";
    } else {
      $dec="DROP";
    }
    print "dn: $dn src : $sad $sport dst : $dad $dport OS: $osname $osversion $osrelease App: $appname $appsig $$dec\n";
  }

  $ldap->unbind;		# take down session
  exit;
}
if (defined ($delete)) {
  my $results = $ldap->delete($delete);
  $results->code && warn "failed to delete entry: ", $results->error ;
  $ldap->unbind;		# take down session
  exit;

}else {
  $exit_code = "No List mode";
}