From 110b458d18c2760e9d6b1fe790eb23783e1dd510 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnther=20Deschner?= Date: Wed, 27 May 2009 22:35:14 +0200 Subject: [PATCH] nss_wrapper: split out passwd and group paths in nss_wrapper.pl. Guenther (cherry picked from commit 7bb9e08d7e75be88a9788563f053794554f680a8) (cherry picked from commit 8bda8295ffc6fa9a9776f821b11075b6bac7a80d) --- lib/nss_wrapper/nss_wrapper.pl | 41 ++++++++++++++++++++++++++--------------- 1 file 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 of the 'passwd' or 'group' file. + --passwd_path Path of the 'passwd' file. + --group_path Path of the 'group' file. --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 "); -} -if ($opt_path eq "" or $opt_path eq "/") { - usage(1, "invalid: --path : '$opt_path'"); -} -my $opt_fullpath = abs_path($opt_path); -if (not defined($opt_fullpath)) { - usage(1, "invalid: --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 "); + } + if ($path eq "" or $path eq "/") { + usage(1, "invalid: --$type\_path : '$path'"); + } + my $fullpath = abs_path($path); + if (not defined($fullpath)) { + usage(1, "invalid: --$type\_path : '$path'"); + } + return $fullpath; +} + sub passwd_add_entry($$); sub passwd_load($) -- 2.11.4.GIT