[Samba-it] Aggiornamento di sambaLogonTime?

Marco Gaiarin gaio at sv.lnf.it
Tue Jun 27 16:42:01 MDT 2006


Odio rispondermi da solo, ma mi piace fare progressi... ;)))

> Ovvero che samba non aggiorna il campo sambaLogonTime (almeno in LDAP,
> non ho capito se il problema è generale...) e quindi non c'è modo di
> sapere quando l'account è stato usato per l'ultima volta (e quindi,
> eventualmente, farlo scadere).

Prendendo spunto dall'idea di:

	http://lists.samba.org/archive/samba/2006-January/115883.html

ho preso gli script smbldap e ne ho creato uno ex-novo, che allego, che
non fa altro che aggiornare LogonTime e LogoffTime.

Poi ho aggiunto allo share [netlogon]

        root preexec = /usr/local/sbin/smbldap-useraccess -n "%u"
        root postexec = /usr/local/sbin/smbldap-useraccess -f "%u"

e la cosa sembra funzionare bene. Ho due dubbi:

1) vabbè che è un hack, attendo ancora la risposta a:

> Simo, mi confermi questo? Soprattutto, mi spieghi perchè?!?! ;)

ma mi chiedo se è buona cosa mettere il root preexec a [netlogon], se
esista uno share a cui sia meglio appendere quele righe.
Ad esempio, per i client che non sono in join al dominio (qualche
portatile ad esempio) ho paura che non venga effettuato nessun accesso a
netlogon...


2) ancora di più mi chiedo se abbia senso il root postexec li in
netlogon, ho paura che lo share netlogon venga aperto e chiuso solo
nella fase di logon, e quindi quel dato sia totalmente falsificato.
Di per se non trovo l'utilità di registrare il logoff time, ma ad ogni
modo...


Incredibile, so veramente poco poco di perl, ma gli smbldap-tools sono
così chiari che è stato un gioco da ragazzi fare copia e incolla tra i
vari script per generare questo.

Domani mi divertirò a fare lo script che fa il check degli account, ed
eventualmente li disabilita.


PS: brute-force hack, il file ha ancora in testa il banner GPL che
assegna il copyright a IDEALIX, e soprattutto non ho ancora contattato
la idealix stessa, a cui ovviamente ho intenzione di contribuire gli
script.

-- 
dott. Marco Gaiarin				    GNUPG Key ID: 240A3D66
  Associazione ``La Nostra Famiglia''                http://www.sv.lnf.it/
  Polo FVG  -  Via della Bontà, 7 - 33078  -  San Vito al Tagliamento (PN)
  marco.gaiarin(at)sv.lnf.it	  tel +39-0434-842711  fax +39-0434-842797
-------------- next part --------------
#!/usr/bin/perl -w

# $Id: smbldap-usermod,v 1.11 2005/01/08 12:04:45 jtournier Exp $
#
#  This code was developped by IDEALX (http://IDEALX.org/) and
#  contributors (their names can be found in the CONTRIBUTORS file).
#
#                 Copyright (C) 2001-2002 IDEALX
#
#  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; either version 2
#  of the License, or (at your option) any later version.
#
#  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.

# Purpose of smbldap-usermod : user (posix,shadow,samba) modification

use strict;
#use FindBin;
#use FindBin qw($RealBin);
#use lib "$RealBin/";
use smbldap_tools;

#####################

use Getopt::Std;
my %Options;

my $ok = getopts('t:nfh?', \%Options);
if ( (!$ok) || (@ARGV < 1) || ($Options{'?'}) || ($Options{'h'}) ) {
  print_banner;
  print "Usage: $0 [-nft?h] username\n";
  print "Available options are:\n";
  print "  -n    write LogOn timestamp\n";
  print "  -f    write LogOff timestamp\n";
  print "  -t    timestamp\n";
  print "  -?|-h show this help message\n";
  exit (1);
}

if ((! $Options{'n'}) && (! $Options{'f'})) {
  print "At least one of -n or -f have to be specified.\n";
  exit(1);
}

if ($< != 0) {
  print "You must be root to modify an user\n";
  exit (1);
}
# Read only first @ARGV
my $user = $ARGV[0];

# Let's connect to the directory first
my $ldap_master=connect_ldap_master();

# Read user data
my $user_entry = read_user_entry($user);
if (!defined($user_entry)) {
  print "$0: user $user doesn't exist\n";
  exit (1);
}

my $samba = 0;
if (grep ($_ =~ /^sambaSamAccount$/i, $user_entry->get_value('objectClass'))) {
  $samba = 1;
} else {
  print "$0: user $user doesn't have samba data, nothing to do.\n";
  exit(1);
}

# get the dn of the user
my $dn= $user_entry->dn();

# some vars...
my @mods;
my $tmp;
my $date;
if (defined($tmp = $Options{'t'})) {
  $date=$tmp;
} else {
  $date=time;
}

# build data snippet...
if ($Options{'n'}) {
  push(@mods, 'sambaLogonTime' => $date);
}
if ($Options{'f'}) {
  push(@mods, 'sambaLogoffTime' => $date);
}

# apply changes
my $modify = $ldap_master->modify ( "$dn",
				    'replace' => { @mods }
				  );
$modify->code && warn "failed to modify entry: ", $modify->error ;

# take down session
$ldap_master->unbind;

# there's no need to tackle with nscd...

############################################################

=head1 NAME

smbldap-useraccess - Update user account access timestamps

=head1 SYNOPSIS

smbldap-useraccess [-n] [-f] [-t timestamp] login

=head1 DESCRIPTION

The  smbldap-useraccess  command  update the user access timestamp field to current or specified time. The  options  which apply to the usermod command are

-n
 Update LogOn timestamp

-f
 Update LogOff timestamp

-t timestamp
 Use timestamp as value, otherwise use current time

=head1 SEE ALSO

       smbldap-uusermod(1)

=cut

#'


More information about the samba-it mailing list