initial commit of file from CVS for e-smith-lib on Wed 12 Jul 08:58:46 BST 2023
This commit is contained in:
10
root/sbin/e-smith/config
Executable file
10
root/sbin/e-smith/config
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Copyright 1999-2003 Mitel Networks Corporation
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the same terms as Perl itself.
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
exec "/sbin/e-smith/db", "configuration", @ARGV;
|
||||
die "Could not exec /sbin/e-smith/db";
|
84
root/sbin/e-smith/create-system-user
Normal file
84
root/sbin/e-smith/create-system-user
Normal file
@@ -0,0 +1,84 @@
|
||||
#! /usr/bin/perl -w
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Copyright 1999-2003 Mitel Networks Corporation
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the same terms as Perl itself.
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
|
||||
sub usage
|
||||
{
|
||||
my $msg = shift;
|
||||
warn("$msg\n") if $msg;
|
||||
die("Usage: $0: user userid descr home_dir shell\n");
|
||||
}
|
||||
|
||||
my $user = shift || usage("Must give username param");
|
||||
my $uid = shift || usage("Must give userid param");
|
||||
my $user_desc = shift || usage("Must give user desc param");
|
||||
my $home = shift || usage("Must give home param");
|
||||
my $shell = shift || usage("Must give shell param");
|
||||
|
||||
use User::pwent;
|
||||
use User::grent;
|
||||
|
||||
if (my $pw = getpwnam($user))
|
||||
{
|
||||
my $euid = $pw->uid;
|
||||
exit 0 if $euid == $uid; # Do not create user if it already exists with correct uid
|
||||
warn ("Users $user exists but has uid of $euid - should be $uid\n");
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if (my $pw = getpwuid($uid))
|
||||
{
|
||||
my $name = $pw->name;
|
||||
warn "User id of $uid is already taken by user $name\n";
|
||||
warn "Falling back to a system chosen uid\n";
|
||||
# We can now go ahead and create the user and group leaving the system to choose uid/gid
|
||||
die ("Failed to create user $user\n") if
|
||||
system("/usr/sbin/useradd",
|
||||
"-r",
|
||||
"-d", $home,
|
||||
"-M",
|
||||
"-s", $shell,
|
||||
"-c", $user_desc,
|
||||
$user);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
if (my $pw = getgrgid($uid))
|
||||
{
|
||||
my $name = $pw->name;
|
||||
warn "Group id of $uid is already taken by user $name\n";
|
||||
# We can now go ahead and create the user but the gid will be chosen by the system
|
||||
die ("Failed to create user $user\n") if
|
||||
system("/usr/sbin/useradd",
|
||||
"-u", $uid,
|
||||
"-d", $home,
|
||||
"-M",
|
||||
"-s", $shell,
|
||||
"-c", $user_desc,
|
||||
$user);
|
||||
}
|
||||
else
|
||||
{
|
||||
# We can now go ahead and create the user and group
|
||||
die ("Failed to create group $uid\n") if
|
||||
system("/usr/sbin/groupadd",
|
||||
"-g", $uid,
|
||||
$user);
|
||||
|
||||
die ("Failed to create user $user\n") if
|
||||
system("/usr/sbin/useradd",
|
||||
"-u", $uid,
|
||||
"-g", $uid,
|
||||
"-d", $home,
|
||||
"-M",
|
||||
"-s", $shell,
|
||||
"-c", $user_desc,
|
||||
$user);
|
||||
}
|
||||
exit 0;
|
344
root/sbin/e-smith/db
Normal file
344
root/sbin/e-smith/db
Normal file
@@ -0,0 +1,344 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Copyright 1999-2003 Mitel Networks Corporation
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the same terms as Perl itself.
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
package esmith;
|
||||
|
||||
use strict;
|
||||
use esmith::config;
|
||||
use esmith::db;
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Set up the command list and usage strings
|
||||
|
||||
my %commands = (
|
||||
'keys'
|
||||
=> {
|
||||
'function' => \&DB_keys,
|
||||
'usage' => "$0 dbfile keys",
|
||||
},
|
||||
|
||||
'print'
|
||||
=> {
|
||||
'function' => \&DB_print,
|
||||
'usage' => "$0 dbfile print [key]",
|
||||
},
|
||||
|
||||
'show'
|
||||
=> {
|
||||
'function' => \&DB_show,
|
||||
'usage' => "$0 dbfile show [key]",
|
||||
},
|
||||
|
||||
'get'
|
||||
=> {
|
||||
'function' => \&DB_get,
|
||||
'usage' => "$0 dbfile get key",
|
||||
},
|
||||
|
||||
'set'
|
||||
=> {
|
||||
'function' => \&DB_set,
|
||||
'usage' => "$0 dbfile set key type "
|
||||
. "[prop1 val1] [prop2 val2] ...",
|
||||
},
|
||||
|
||||
'setdefault'
|
||||
=> {
|
||||
'function' => \&DB_set_default,
|
||||
'usage' => "$0 dbfile setdefault key type "
|
||||
. "[prop1 val1] [prop2 val2] ...",
|
||||
},
|
||||
|
||||
'delete'
|
||||
=> {
|
||||
'function' => \&DB_delete,
|
||||
'usage' => "$0 dbfile delete key",
|
||||
},
|
||||
|
||||
'printtype'
|
||||
=> {
|
||||
'function' => \&DB_printtype,
|
||||
'usage' => "$0 dbfile printtype [key]",
|
||||
},
|
||||
|
||||
'gettype'
|
||||
=> {
|
||||
'function' => \&DB_gettype,
|
||||
'usage' => "$0 dbfile gettype key",
|
||||
},
|
||||
|
||||
'settype'
|
||||
=> {
|
||||
'function' => \&DB_settype,
|
||||
'usage' => "$0 dbfile settype key type",
|
||||
},
|
||||
|
||||
'printprop'
|
||||
=> {
|
||||
'function' => \&DB_printprop,
|
||||
'usage' => "$0 dbfile printprop key [prop1] "
|
||||
. "[prop2] [prop3] ...",
|
||||
},
|
||||
|
||||
'getprop'
|
||||
=> {
|
||||
'function' => \&DB_getprop,
|
||||
'usage' => "$0 dbfile getprop key prop",
|
||||
},
|
||||
|
||||
'setprop'
|
||||
=> {
|
||||
'function' => \&DB_setprop,
|
||||
'usage' => "$0 dbfile setprop key "
|
||||
. "prop1 val1 [prop2 val2] "
|
||||
. "[prop3 val3] ...",
|
||||
},
|
||||
|
||||
'delprop'
|
||||
=> {
|
||||
'function' => \&DB_delprop,
|
||||
'usage' => "$0 dbfile delprop key prop1 "
|
||||
. "[prop2] [prop3] ...",
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Set up general usage message.
|
||||
|
||||
my $usage = "usage:
|
||||
$commands{'keys'}{'usage'}
|
||||
$commands{'print'}{'usage'}
|
||||
$commands{'show'}{'usage'}
|
||||
$commands{'get'}{'usage'}
|
||||
$commands{'set'}{'usage'}
|
||||
$commands{'setdefault'}{'usage'}
|
||||
$commands{'delete'}{'usage'}
|
||||
$commands{'printtype'}{'usage'}
|
||||
$commands{'gettype'}{'usage'}
|
||||
$commands{'settype'}{'usage'}
|
||||
$commands{'printprop'}{'usage'}
|
||||
$commands{'getprop'}{'usage'}
|
||||
$commands{'setprop'}{'usage'}
|
||||
$commands{'delprop'}{'usage'}
|
||||
";
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Prepend $ENV{'DBPATH'} to dbfile if defined otherwise let the library
|
||||
# deal with it.
|
||||
|
||||
my $dbfile = shift;
|
||||
die $usage unless $dbfile;
|
||||
|
||||
my $dbpath = $ENV{'DBPATH'};
|
||||
$dbfile = "$dbpath/$dbfile" if defined $dbpath;
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Tie the databasefile to a hash
|
||||
|
||||
my $db = esmith::db->open($dbfile);
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Run the appropriate command
|
||||
|
||||
my $command = shift;
|
||||
die $usage unless $command;
|
||||
die $usage unless exists $commands{$command};
|
||||
$commands{$command}{'function'}->(@ARGV);
|
||||
|
||||
exit 0;
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
sub DB_print
|
||||
{
|
||||
my $key = shift;
|
||||
|
||||
if (defined $key)
|
||||
{
|
||||
$db->print($key) ? exit 0 : exit 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->print() ? exit 0 : exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub DB_keys
|
||||
{
|
||||
my @keys = $db->get();
|
||||
|
||||
exit 1 unless (scalar @keys);
|
||||
print join("\n", @keys), "\n";
|
||||
}
|
||||
|
||||
sub DB_show
|
||||
{
|
||||
my $key = shift;
|
||||
|
||||
if (defined $key)
|
||||
{
|
||||
$db->show($key) ? exit 0 : exit 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->show() ? exit 0 : exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub DB_get
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'get'}{'usage'}\n" unless $key;
|
||||
|
||||
my $value = $db->get($key);
|
||||
exit 1 unless defined $value;
|
||||
print "$value\n" if defined $value;
|
||||
}
|
||||
|
||||
sub DB_set
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'set'}{'usage'}\n" unless $key;
|
||||
die "$commands{'set'}{'usage'}\n" unless scalar @_;
|
||||
|
||||
my $type = shift;
|
||||
die "$commands{'set'}{'usage'}\n" unless defined $type;
|
||||
die "$commands{'set'}{'usage'}\n" if scalar @_ % 2;
|
||||
|
||||
$db->set($key, $type) or exit 1;
|
||||
|
||||
&DB_setprop($key, @_) if scalar @_;
|
||||
}
|
||||
|
||||
sub DB_set_default
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'setdefault'}{'usage'}\n" unless $key;
|
||||
die "$commands{'setdefault'}{'usage'}\n" unless scalar @_;
|
||||
|
||||
my $type = shift;
|
||||
die "$commands{'setdefault'}{'usage'}\n" unless $type;
|
||||
die "$commands{'setdefault'}{'usage'}\n" if scalar @_ % 2;
|
||||
|
||||
# Only set values if the key does not exist
|
||||
|
||||
exit 0 if defined $db->get($key);
|
||||
|
||||
&DB_set($key, $type, @_);
|
||||
}
|
||||
|
||||
sub DB_delete
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'delete'}{'usage'}\n" unless $key;
|
||||
|
||||
$db->delete($key) ? exit 0 : exit 1;
|
||||
}
|
||||
|
||||
sub DB_printtype
|
||||
{
|
||||
my $key = shift;
|
||||
|
||||
if (defined $key)
|
||||
{
|
||||
$db->print_type($key) ? exit 0 : exit 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->print_type() ? exit 0 : exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub DB_gettype
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'get'}{'usage'}\n" unless $key;
|
||||
|
||||
my $value = $db->get_type($key);
|
||||
exit 1 unless defined $value;
|
||||
print "$value\n" if defined $value;
|
||||
}
|
||||
|
||||
sub DB_settype
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'settype'}{'usage'}\n" unless $key;
|
||||
my $type = shift;
|
||||
die "$commands{'settype'}{'usage'}\n" unless $type;
|
||||
|
||||
$db->set_type($key, $type) ? exit 0 : exit 1;
|
||||
}
|
||||
|
||||
sub DB_printprop
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'printprop'}{'usage'}\n" unless $key;
|
||||
|
||||
my @props = @_;
|
||||
|
||||
if (scalar @props)
|
||||
{
|
||||
foreach (@props)
|
||||
{
|
||||
$db->print_prop($key, $_)
|
||||
if defined $db->get_prop($key, $_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->print_prop($key) ? exit 0 : exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub DB_getprop
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'getprop'}{'usage'}\n" unless $key;
|
||||
|
||||
my $prop = shift;
|
||||
die "$commands{'getprop'}{'usage'}\n" unless scalar $prop;
|
||||
|
||||
my $val = $db->get_prop($key, $prop);
|
||||
|
||||
if (defined $val)
|
||||
{
|
||||
print "$val\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub DB_setprop
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'setprop'}{'usage'}\n" unless $key;
|
||||
die "$commands{'setprop'}{'usage'}\n" unless scalar @_;
|
||||
die "$commands{'setprop'}{'usage'}\n" if scalar @_ % 2;
|
||||
|
||||
my %properties = @_;
|
||||
|
||||
foreach (sort keys %properties)
|
||||
{
|
||||
$db->set_prop($key, $_, $properties{$_});
|
||||
}
|
||||
}
|
||||
|
||||
sub DB_delprop
|
||||
{
|
||||
my $key = shift;
|
||||
die "$commands{'delprop'}{'usage'}\n" unless $key;
|
||||
die "$commands{'delprop'}{'usage'}\n" unless scalar @_;
|
||||
|
||||
foreach (@_)
|
||||
{
|
||||
$db->delete_prop($key, $_);
|
||||
}
|
||||
}
|
46
root/sbin/e-smith/expand-template
Normal file
46
root/sbin/e-smith/expand-template
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Copyright 1999-2004 Mitel Networks Corporation
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the same terms as Perl itself.
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
package esmith;
|
||||
|
||||
use strict;
|
||||
use Errno;
|
||||
use Getopt::Long;
|
||||
use esmith::templates;
|
||||
|
||||
my %options = ();
|
||||
|
||||
GetOptions(\%options, 'output_filename=s', 'expand_queue=s');
|
||||
|
||||
$options{'template_path'} = $ARGV[0] || die "Usage: $0 /path/to/file/to/expand\n";
|
||||
|
||||
$options{'output_filename'} = $options{'template_path'}
|
||||
unless ( exists $options{'output_filename'} );
|
||||
|
||||
|
||||
my %args = (
|
||||
TEMPLATE_PATH => $options{'template_path'},
|
||||
OUTPUT_FILENAME => $options{'output_filename'},
|
||||
);
|
||||
|
||||
$args{TEMPLATE_EXPAND_QUEUE} = [$options{'expand_queue'}]
|
||||
if exists $options{expand_queue};
|
||||
|
||||
if ( -f $options{'output_filename'} )
|
||||
{
|
||||
# If the target file exists, preserve its ownership and mode
|
||||
use File::stat;
|
||||
|
||||
my $f = stat($options{'output_filename'} );
|
||||
$args{UID} = $f->uid;
|
||||
$args{GID} = $f->gid;
|
||||
$args{PERMS} = $f->mode;
|
||||
}
|
||||
|
||||
esmith::templates::processTemplate(\%args);
|
||||
|
24
root/sbin/e-smith/signal-event
Normal file
24
root/sbin/e-smith/signal-event
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Copyright 1999-2003 Mitel Networks Corporation
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the same terms as Perl itself.
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
use esmith::event;
|
||||
|
||||
my $usage = "usage:
|
||||
$0 eventname [arg1 [arg2...]]
|
||||
";
|
||||
|
||||
my ($event, @args) = @ARGV;
|
||||
die $usage unless $event;
|
||||
|
||||
my $exitcode = event_signal($event, @args);
|
||||
|
||||
# reverse exitcode for command-line usage
|
||||
exit ($exitcode ? 0 : 1);
|
||||
|
Reference in New Issue
Block a user