diff options
author | Günther Deschner <gd@samba.org> | 2009-05-27 22:35:14 +0200 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2009-05-28 10:32:21 +0200 |
commit | 7bb9e08d7e75be88a9788563f053794554f680a8 (patch) | |
tree | ab9938ecffa2bbd2d0ab54aa3c377ffa68d6c885 /lib/nss_wrapper | |
parent | ec9a0917055d731aa95e2fea2045445f9945b74d (diff) | |
download | samba-7bb9e08d7e75be88a9788563f053794554f680a8.tar.gz |
nss_wrapper: split out passwd and group paths in nss_wrapper.pl.
Guenther
Diffstat (limited to 'lib/nss_wrapper')
-rw-r--r-- | lib/nss_wrapper/nss_wrapper.pl | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/lib/nss_wrapper/nss_wrapper.pl b/lib/nss_wrapper/nss_wrapper.pl index cfd3206c2ae..89958245ca4 100644 --- a/lib/nss_wrapper/nss_wrapper.pl +++ b/lib/nss_wrapper/nss_wrapper.pl @@ -7,7 +7,8 @@ use Getopt::Long; use Cwd qw(abs_path); my $opt_help = 0; -my $opt_path = undef; +my $opt_passwd_path = undef; +my $opt_group_path = undef; my $opt_action = undef; my $opt_type = undef; my $opt_name = undef; @@ -23,7 +24,8 @@ sub group_delete($$); my $result = GetOptions( 'help|h|?' => \$opt_help, - 'path=s' => \$opt_path, + 'passwd_path=s' => \$opt_passwd_path, + 'group_path=s' => \$opt_group_path, 'action=s' => \$opt_action, 'type=s' => \$opt_type, 'name=s' => \$opt_name @@ -39,7 +41,8 @@ sub usage($;$) --help|-h|-? Show this help. - --path <path> Path of the 'passwd' or 'group' file. + --passwd_path <path> Path of the 'passwd' file. + --group_path <path> Path of the 'group' file. --type <type> Only 'passwd' and 'group' are supported yet, maybe 'member' will be added in future. @@ -55,18 +58,6 @@ usage(1) if (not $result); usage(0) if ($opt_help); -if (not defined($opt_path)) { - usage(1, "missing: --path <path>"); -} -if ($opt_path eq "" or $opt_path eq "/") { - usage(1, "invalid: --path <path>: '$opt_path'"); -} -my $opt_fullpath = abs_path($opt_path); -if (not defined($opt_fullpath)) { - usage(1, "invalid: --path <path>: '$opt_path'"); -} - - if (not defined($opt_action)) { usage(1, "missing: --action [add|delete]"); } @@ -83,10 +74,13 @@ if ($opt_action eq "add") { if (not defined($opt_type)) { usage(1, "missing: --type [passwd|group]"); } +my $opt_fullpath; if ($opt_type eq "passwd") { $actionfn = $passwdfn; + $opt_fullpath = check_path($opt_passwd_path, $opt_type); } elsif ($opt_type eq "group") { $actionfn = $groupfn; + $opt_fullpath = check_path($opt_group_path, $opt_type); } else { usage(1, "invalid: --type [passwd|group]: '$opt_type'") } @@ -100,6 +94,23 @@ if ($opt_name eq "") { exit $actionfn->($opt_fullpath, $opt_name); +sub check_path($$) +{ + my ($path,$type) = @_; + + if (not defined($path)) { + usage(1, "missing: --$type\_path <path>"); + } + if ($path eq "" or $path eq "/") { + usage(1, "invalid: --$type\_path <path>: '$path'"); + } + my $fullpath = abs_path($path); + if (not defined($fullpath)) { + usage(1, "invalid: --$type\_path <path>: '$path'"); + } + return $fullpath; +} + sub passwd_add_entry($$); sub passwd_load($) |