[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-1708-ge11f9b4

Günther Deschner gd at samba.org
Wed May 20 10:38:45 GMT 2009


The branch, master has been updated
       via  e11f9b46c6345471cca76b9772080d3bfd687852 (commit)
       via  3bd360c73de77559593e11301d247fd53c4ce128 (commit)
       via  b3cc01fd68e30ebd616897982e0d8befd2a2a7e0 (commit)
      from  8cd9c72d75aeb92d64e2781081fed8847727d289 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit e11f9b46c6345471cca76b9772080d3bfd687852
Author: Günther Deschner <gd at samba.org>
Date:   Wed May 20 02:12:17 2009 +0200

    s3-selftest: add add and delete group scripts using nss_wrapper.
    
    Guenther

commit 3bd360c73de77559593e11301d247fd53c4ce128
Author: Günther Deschner <gd at samba.org>
Date:   Wed May 20 02:10:12 2009 +0200

    nsswrapper: implement group_del() in nss_wrapper.pl.
    
    Guenther

commit b3cc01fd68e30ebd616897982e0d8befd2a2a7e0
Author: Günther Deschner <gd at samba.org>
Date:   Wed May 20 02:06:22 2009 +0200

    nsswrapper: implement group_add() in nss_wrapper.pl.
    
    Guenther

-----------------------------------------------------------------------

Summary of changes:
 lib/nss_wrapper/nss_wrapper.pl   |  132 ++++++++++++++++++++++++++++++++++++--
 selftest/target/Samba3.pm        |    2 +
 source3/script/tests/selftest.sh |    2 +
 3 files changed, 131 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/nss_wrapper/nss_wrapper.pl b/lib/nss_wrapper/nss_wrapper.pl
index dbb7f85..cfd3206 100644
--- a/lib/nss_wrapper/nss_wrapper.pl
+++ b/lib/nss_wrapper/nss_wrapper.pl
@@ -41,9 +41,8 @@ sub usage($;$)
 
 	--path <path>		Path of the 'passwd' or 'group' file.
 
-	--type <type>		Only 'passwd' is supported yet,
-				but 'group' and maybe 'member' will be added
-				in future.
+	--type <type>		Only 'passwd' and 'group' are supported yet,
+				maybe 'member' will be added in future.
 
 	--action <action>	'add' or 'delete'.
 
@@ -125,6 +124,30 @@ sub passwd_load($)
 	return $passwd;
 }
 
+sub group_add_entry($$);
+
+sub group_load($)
+{
+	my ($path) = @_;
+	my @lines;
+	my $group = undef;
+
+	open(GROUP, "<$path") or die("Unable to open '$path' for read");
+	@lines = <GROUP>;
+	close(GROUP);
+
+	$group->{array} = ();
+	$group->{name} = {};
+	$group->{gid} = {};
+	$group->{path} = $path;
+
+	foreach my $line (@lines) {
+		group_add_entry($group, $line);
+	}
+
+	return $group;
+}
+
 sub passwd_lookup_name($$)
 {
 	my ($passwd, $name) = @_;
@@ -134,6 +157,15 @@ sub passwd_lookup_name($$)
 	return $passwd->{name}{$name};
 }
 
+sub group_lookup_name($$)
+{
+	my ($group, $name) = @_;
+
+	return undef unless defined($group->{name}{$name});
+
+	return $group->{name}{$name};
+}
+
 sub passwd_lookup_uid($$)
 {
 	my ($passwd, $uid) = @_;
@@ -143,6 +175,15 @@ sub passwd_lookup_uid($$)
 	return $passwd->{uid}{$uid};
 }
 
+sub group_lookup_gid($$)
+{
+	my ($group, $gid) = @_;
+
+	return undef unless defined($group->{gid}{$gid});
+
+	return $group->{gid}{$gid};
+}
+
 sub passwd_get_free_uid($)
 {
 	my ($passwd) = @_;
@@ -155,6 +196,18 @@ sub passwd_get_free_uid($)
 	return $uid;
 }
 
+sub group_get_free_gid($)
+{
+	my ($group) = @_;
+	my $gid = 1000;
+
+	while (group_lookup_gid($group, $gid)) {
+		$gid++;
+	}
+
+	return $gid;
+}
+
 sub passwd_add_entry($$)
 {
 	my ($passwd, $str) = @_;
@@ -167,6 +220,18 @@ sub passwd_add_entry($$)
 	$passwd->{uid}{$e[2]} = \@e;
 }
 
+sub group_add_entry($$)
+{
+	my ($group, $str) = @_;
+
+	chomp $str;
+	my @e = split(':', $str);
+
+	push(@{$group->{array}}, \@e);
+	$group->{name}{$e[0]} = \@e;
+	$group->{gid}{$e[2]} = \@e;
+}
+
 sub passwd_remove_entry($$)
 {
 	my ($passwd, $eref) = @_;
@@ -181,6 +246,20 @@ sub passwd_remove_entry($$)
 	delete $passwd->{uid}{${$eref}[2]};
 }
 
+sub group_remove_entry($$)
+{
+	my ($group, $eref) = @_;
+
+	for (my $i = 0; defined($group->{array}[$i]); $i++) {
+		if ($eref == $group->{array}[$i]) {
+			$group->{array}[$i] = undef;
+		}
+	}
+
+	delete $group->{name}{${$eref}[0]};
+	delete $group->{gid}{${$eref}[2]};
+}
+
 sub passwd_save($)
 {
 	my ($passwd) = @_;
@@ -201,6 +280,29 @@ sub passwd_save($)
 	rename($tmppath, $path) or die("Unable to rename $tmppath => $path");
 }
 
+sub group_save($)
+{
+	my ($group) = @_;
+	my @lines = ();
+	my $path = $group->{path};
+	my $tmppath = $path.$$;
+
+	foreach my $eref (@{$group->{array}}) {
+		next unless defined($eref);
+
+		my $line = join(':', @{$eref});
+		if (scalar(@{$eref}) == 3) {
+			$line .= ":";
+		}
+		push(@lines, $line);
+	}
+
+	open(GROUP, ">$tmppath") or die("Unable to open '$tmppath' for write");
+	print GROUP join("\n", @lines)."\n";
+	close(GROUP);
+	rename($tmppath, $path) or die("Unable to rename $tmppath => $path");
+}
+
 sub passwd_add($$)
 {
 	my ($path, $name) = @_;
@@ -248,7 +350,20 @@ sub group_add($$)
 
 	#print "group_add: '$name' in '$path'\n";
 
-	die("group_add: not implemented yet!");
+	my $group = group_load($path);
+
+	my $e = group_lookup_name($group, $name);
+	die("group[$name] already exists in '$path'") if defined($e);
+
+	my $gid = group_get_free_gid($group);
+
+	my $gwent = $name.":x:".$gid.":".""; #no members yet
+
+	group_add_entry($group, $gwent);
+
+	group_save($group);
+
+	#printf("%d\n", $gid);
 
 	return 0;
 }
@@ -259,7 +374,14 @@ sub group_delete($$)
 
 	#print "group_delete: '$name' in '$path'\n";
 
-	die("group_delete: not implemented yet!");
+	my $group = group_load($path);
+
+	my $e = group_lookup_name($group, $name);
+	die("group[$name] does not exists in '$path'") unless defined($e);
+
+	group_remove_entry($group, $e);
+
+	group_save($group);
 
 	return 0;
 }
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index bf27f36..30453f2 100644
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -459,8 +459,10 @@ sub provision($$$$$$)
 	time server = yes
 
 	add user script = $nss_wrapper_pl --path $nss_wrapper_passwd --type passwd --action add --name %u
+	add group script = $nss_wrapper_pl --path $nss_wrapper_group --type group --action add --name %g
 	add machine script = $nss_wrapper_pl --path $nss_wrapper_passwd --type passwd --action add --name %u
 	delete user script = $nss_wrapper_pl --path $nss_wrapper_passwd --type passwd --action delete --name %u
+	delete group script = $nss_wrapper_pl --path $nss_wrapper_group --type group --action delete --name %g
 
 	kernel oplocks = no
 	kernel change notify = no
diff --git a/source3/script/tests/selftest.sh b/source3/script/tests/selftest.sh
index 8f078d2..1e84d1c 100755
--- a/source3/script/tests/selftest.sh
+++ b/source3/script/tests/selftest.sh
@@ -217,8 +217,10 @@ cat >$SERVERCONFFILE<<EOF
 	time server = yes
 
 	add user script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
+	add group script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper_pl --path $NSS_WRAPPER_GROUP --type group --action add --name %g
 	add machine script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
 	delete user script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u
+	delete group script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper_pl --path $NSS_WRAPPER_GROUP --type group --action delete --name %g
 
 	kernel oplocks = no
 	kernel change notify = no


-- 
Samba Shared Repository


More information about the samba-cvs mailing list