[PATCH] lib/util: Fixup tcopy_passwd() to also copy the pw_comment, field

Stefan Behrens samba-technical at giantdisaster.de
Fri May 31 13:33:48 UTC 2019


All fields of the passwd structure are copied except for pw_comment, and
I needed pw_comment to be copied and here is the commit for the change.

Bug 13975

Review appreciated.
-------------- next part --------------
From c8c6829e0b167c85fc804b2559a643232a36f9fa Mon Sep 17 00:00:00 2001
From: Stefan Behrens <sbehrens at giantdisaster.de>
Date: Wed, 27 Mar 2019 11:26:09 +0100
Subject: [PATCH] lib/util: Fixup tcopy_passwd() to also copy the pw_comment
 field

This change isn't needed by the Samba code itself but by a passdb
module of mine. This module makes use of the comment field and
requires that the copy of a passwd structure includes the pw_comment
field. And I see no reason why all fields of the passwd structure
are copied except for pw_comment.

Signed-off-by: Stefan Behrens <sbehrens at giantdisaster.de>
---
 lib/util/util_pw.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/util/util_pw.c b/lib/util/util_pw.c
index 8035de4392c3..62e6e1e36a64 100644
--- a/lib/util/util_pw.c
+++ b/lib/util/util_pw.c
@@ -34,14 +34,21 @@ struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx,
 {
 	struct passwd *ret;
 	size_t len = 0;
+	unsigned int num_subobjs;
 
 	len += strlen(from->pw_name)+1;
 	len += strlen(from->pw_passwd)+1;
 	len += strlen(from->pw_gecos)+1;
 	len += strlen(from->pw_dir)+1;
 	len += strlen(from->pw_shell)+1;
+	if (from->pw_comment != NULL) {
+		len += strlen(from->pw_comment)+1;
+		num_subobjs = 6;
+	} else {
+		num_subobjs = 5;
+	}
 
-	ret = talloc_pooled_object(mem_ctx, struct passwd, 5, len);
+	ret = talloc_pooled_object(mem_ctx, struct passwd, num_subobjs, len);
 
 	if (ret == NULL) {
 		return NULL;
@@ -54,6 +61,9 @@ struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx,
 	ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
 	ret->pw_dir = talloc_strdup(ret, from->pw_dir);
 	ret->pw_shell = talloc_strdup(ret, from->pw_shell);
+	if (from->pw_comment != NULL) {
+		ret->pw_comment = talloc_strdup(ret, from->pw_comment);
+	}
 
 	return ret;
 }
-- 
2.19.2



More information about the samba-technical mailing list