From 381593a6cb1ff0ccbc560ee9329b0d2e59938264 Mon Sep 17 00:00:00 2001
From: Bo Yang <boyang@samba.org>
Date: Sun, 7 Feb 2010 14:45:42 +0800
Subject: [PATCH] s3: Fix malformed require_membership_of_sid.

Signed-off-by: Bo Yang <boyang@samba.org>
(cherry picked from commit 913a9f4e420c7a4177e6a7874e8ec2703f447918)
---
 nsswitch/pam_winbind.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

Index: nsswitch/pam_winbind.c
===================================================================
--- nsswitch/pam_winbind.c.orig
+++ nsswitch/pam_winbind.c
@@ -1133,6 +1133,7 @@ static bool winbind_name_list_to_sid_str
 	char *current_name = NULL;
 	const char *search_location;
 	const char *comma;
+	int len;
 
 	if (sid_list_buffer_size > 0) {
 		sid_list_buffer[0] = 0;
@@ -1188,6 +1189,17 @@ static bool winbind_name_list_to_sid_str
 		_make_remark_format(ctx, PAM_TEXT_INFO, _("Cannot convert group %s "
 				"to sid, please contact your administrator to see "
 				"if group %s is valid."), search_location, search_location);
+		/*
+		 * The lookup of the last name failed..
+		 * It results in require_member_of_sid ends with ','
+		 * It is malformated parameter here, overwrite the last ','.
+		 */
+		len = strlen(sid_list_buffer);
+		if (len) {
+			if (sid_list_buffer[len - 1] == ',') {
+				sid_list_buffer[len - 1] = '\0';
+			}
+		}
 	}
 
 	result = true;
