# setDirectoryQuota.pl # # by Vijayababu Dandi # Version 1.0 # Oct 16, 2009 ############################################################################################## # Perl must be installed and running on the Linux server where this utility will be used. # NSS must be installed to get the VFS support. # (The SDK for this API set can be downloaded from http://developer.novell.com/wiki/index.php/# Virtual_File_Services_for_NetWare.) ############################################################################################## # # This is used to set the directory quotas on a nss directory. # ############################################################################################## sub SetDataStream($*) { my $fh = $_[0]; my $datastream = $_[1]; my $command; my $result; my $error; $command = ""; seek $fh, 0, 0; if (!syswrite($fh, $command, length($command))) { $result .= "Unable to send datastream command to NDS management. "; seek $fh, 0, 0; if (sysread($fh,$error, 1000)) { $result .= $error; } $result .= "\n"; } return $result; } sub WriteCommand($*) { my $fh = $_[0]; my $result; my $reply; my $error; my $command = $_[1]; seek $fh, 0, 0; if (!syswrite($fh, $command, length($command))) { $result .= "Unable to send command to virtual file. "; seek $fh, 0, 0; if (sysread($fh, $error, 1000)) { $result .= $error; } $result .= "\n"; } else { seek $fh, 0, 0; my $readLen = 999; while ($readLen) { $readLen = sysread($fh, $reply, 1000); $result .= $reply; } } return $result; } sub setDirQuota($$) { my $dirName = $_[0]; my $size = $_[1]; my $result; my $ret; my $nssResult; $size = $size * 1024 *1024; $command = "$size"; if (!($ret = SetDataStream(FILE, "command"))) { $result .= $ret; $nssResult = WriteCommand(FILE,"$command"); } ParseDirQuota($nssResult); } sub ParseDirQuota($) { my $xml = $_[0]; my $result; my @xml; my $ret; my $size; my $errno; my $usedSize; my $description; my $reporter; @xml = $xml =~ /(.*?)<\/directoryQuotas>/gs; $ret =''; foreach $result (@xml) { if ($result =~ //s) { $errno = $1; } if ($result =~ /(.*?)<\/description>/gs) { $description = $1; } if ($result =~ /(.*?)<\/reporter>/gs) { $reporter = $1; } if ($errno != 0) { print "\n-----------------------------------------------------------\n". "Error No : $errno\n". "Description : $description\n". "Reporter : $reporter\n". "-----------------------------------------------------------\n"; return; } else { print "--------------------------------------------------------------\n". "direcoty quotas set on directory $dirName\n". "--------------------------------------------------------------\n"; return; } } } open(FILE,"+>", "/_admin/Manage_NSS/files.cmd") or die "Error opening NSS management file ($!) on server"; MAIN :while (1) { my $action; do { print "1.To set directory quotas\n". "2.Exit\n". "Select Action: "; chomp($action = ); }while ($action != 0 && ($action < 1 || $action > 2)); if ($action == 1) { my $dirName; my $size; print "Enter directory Name to set directory quota: "; chomp($dirName = ); print "Enter the size (in MB): "; chomp($size = ); setDirQuota($dirName, $size); } else { exit(0); } } close(FILE);