[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Thu Mar 3 14:57:01 MST 2011


The branch, master has been updated
       via  7b139a4 s3: Use dom_sid_string_buf in sid_to_fstring
       via  7051747 Add dom_sid_string_buf
       via  f8a13c7 s3: Use dom_sid_string in _lsa_lookup_sids_internal
       via  ae28029 s3: Remove an obsolete comment
       via  01da00a s3: Fix some nonempty blank lines
      from  875d9b8 lib/util: LIBCRYPTO is in common already, so add it to samba-util-common.

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


- Log -----------------------------------------------------------------
commit 7b139a49dced08c4500960738bd0c06b5a57000e
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 3 17:02:40 2011 +0100

    s3: Use dom_sid_string_buf in sid_to_fstring
    
    Autobuild-User: Volker Lendecke <vlendec at samba.org>
    Autobuild-Date: Thu Mar  3 22:56:57 CET 2011 on sn-devel-104

commit 70517477f8deafc8027388d0597bbd53bd407c58
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 3 16:59:39 2011 +0100

    Add dom_sid_string_buf
    
    This prints into a fixed buffer with the same overflow semantics as snprintf
    has: Return required string length, regardless of whether it fit or not.

commit f8a13c7dbc9b0e2246fb52d4a4d5db3b23bd2340
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 3 16:20:56 2011 +0100

    s3: Use dom_sid_string in _lsa_lookup_sids_internal

commit ae28029f6788c2cbb31b2f1c9d0bf47d75bf398d
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 3 15:26:12 2011 +0100

    s3: Remove an obsolete comment

commit 01da00abfd8763f43ec1f155ed87df4a394c01c9
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 3 12:51:57 2011 +0100

    s3: Fix some nonempty blank lines

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

Summary of changes:
 libcli/security/dom_sid.c           |   49 ++++++++++++++++++++++++++--------
 libcli/security/dom_sid.h           |    3 ++
 source3/include/idmap.h             |    6 ++--
 source3/lib/util_sid.c              |    4 +--
 source3/passdb/lookup_sid.c         |    4 +--
 source3/rpc_server/lsa/srv_lsa_nt.c |    5 +---
 6 files changed, 46 insertions(+), 25 deletions(-)


Changeset truncated at 500 lines:

diff --git a/libcli/security/dom_sid.c b/libcli/security/dom_sid.c
index 217d7bb..809f20c 100644
--- a/libcli/security/dom_sid.c
+++ b/libcli/security/dom_sid.c
@@ -347,34 +347,59 @@ bool dom_sid_in_domain(const struct dom_sid *domain_sid,
 }
 
 /*
-  convert a dom_sid to a string
+  Convert a dom_sid to a string, printing into a buffer. Return the
+  string length. If it overflows, return the string length that would
+  result (buflen needs to be +1 for the terminating 0).
 */
-char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
+int dom_sid_string_buf(const struct dom_sid *sid, char *buf, int buflen)
 {
-	int i, ofs, maxlen;
+	int i, ofs;
 	uint32_t ia;
-	char *ret;
 
 	if (!sid) {
-		return talloc_strdup(mem_ctx, "(NULL SID)");
+		strlcpy(buf, "(NULL SID)", buflen);
+		return 10;	/* strlen("(NULL SID)") */
 	}
 
-	maxlen = sid->num_auths * 11 + 25;
-	ret = talloc_array(mem_ctx, char, maxlen);
-	if (!ret) return talloc_strdup(mem_ctx, "(SID ERR)");
-
 	ia = (sid->id_auth[5]) +
 		(sid->id_auth[4] << 8 ) +
 		(sid->id_auth[3] << 16) +
 		(sid->id_auth[2] << 24);
 
-	ofs = snprintf(ret, maxlen, "S-%u-%lu",
+	ofs = snprintf(buf, buflen, "S-%u-%lu",
 		       (unsigned int)sid->sid_rev_num, (unsigned long)ia);
 
 	for (i = 0; i < sid->num_auths; i++) {
-		ofs += snprintf(ret + ofs, maxlen - ofs, "-%lu",
+		ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "-%lu",
 				(unsigned long)sid->sub_auths[i]);
 	}
+	return ofs;
+}
 
-	return ret;
+/*
+  convert a dom_sid to a string
+*/
+char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
+{
+	char buf[DOM_SID_STR_BUFLEN];
+	char *result;
+	int len;
+
+	len = dom_sid_string_buf(sid, buf, sizeof(buf));
+
+	if (len+1 > sizeof(buf)) {
+		return talloc_strdup(mem_ctx, "(SID ERR)");
+	}
+
+	/*
+	 * Avoid calling strlen (via talloc_strdup), we already have
+	 * the length
+	 */
+	result = (char *)talloc_memdup(mem_ctx, buf, len+1);
+
+	/*
+	 * beautify the talloc_report output
+	 */
+	talloc_set_name_const(result, result);
+	return result;
 }
diff --git a/libcli/security/dom_sid.h b/libcli/security/dom_sid.h
index c65471b..3493fab 100644
--- a/libcli/security/dom_sid.h
+++ b/libcli/security/dom_sid.h
@@ -71,6 +71,9 @@ NTSTATUS dom_sid_split_rid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
 			   struct dom_sid **domain, uint32_t *rid);
 bool dom_sid_in_domain(const struct dom_sid *domain_sid,
 		       const struct dom_sid *sid);
+
+#define DOM_SID_STR_BUFLEN (15*11+25)
+int dom_sid_string_buf(const struct dom_sid *sid, char *buf, int buflen);
 char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
 
 
diff --git a/source3/include/idmap.h b/source3/include/idmap.h
index 8a1da81..2f95740 100644
--- a/source3/include/idmap.h
+++ b/source3/include/idmap.h
@@ -7,17 +7,17 @@
 
    Copyright (C) Jim McDonough <jmcd at us.ibm.com> 2003
    Copyright (C) Simo Sorce 2003
-   
+
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 3 of the License, or (at your option) any later version.
-   
+
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
-   
+
    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c
index bb9e2e9..0a026a1 100644
--- a/source3/lib/util_sid.c
+++ b/source3/lib/util_sid.c
@@ -34,9 +34,7 @@
 
 char *sid_to_fstring(fstring sidstr_out, const struct dom_sid *sid)
 {
-	char *str = sid_string_talloc(talloc_tos(), sid);
-	fstrcpy(sidstr_out, str);
-	TALLOC_FREE(str);
+	dom_sid_string_buf(sid, sidstr_out, sizeof(fstring));
 	return sidstr_out;
 }
 
diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
index 68072f3..0901319 100644
--- a/source3/passdb/lookup_sid.c
+++ b/source3/passdb/lookup_sid.c
@@ -728,9 +728,7 @@ static bool check_dom_sid_to_level(const struct dom_sid *sid, int level)
  * This attempts to be as efficient as possible: It collects all SIDs
  * belonging to a domain and hands them in bulk to the appropriate lookup
  * function. In particular pdb_lookup_rids with ldapsam_trusted benefits
- * *hugely* from this. Winbind is going to be extended with a lookup_rids
- * interface as well, so on a DC we can do a bulk lsa_lookuprids to the
- * appropriate DC.
+ * *hugely* from this.
  */
 
 NTSTATUS lookup_sids(TALLOC_CTX *mem_ctx, int num_sids,
diff --git a/source3/rpc_server/lsa/srv_lsa_nt.c b/source3/rpc_server/lsa/srv_lsa_nt.c
index 70e7ba5..a4fc40a 100644
--- a/source3/rpc_server/lsa/srv_lsa_nt.c
+++ b/source3/rpc_server/lsa/srv_lsa_nt.c
@@ -897,7 +897,6 @@ static NTSTATUS _lsa_lookup_sids_internal(struct pipes_struct *p,
 		struct lsa_name_info *name = &name_infos[i];
 
 		if (name->type == SID_NAME_UNKNOWN) {
-			fstring tmp;
 			name->dom_idx = -1;
 			/* Unknown sids should return the string
 			 * representation of the SID. Windows 2003 behaves
@@ -905,9 +904,7 @@ static NTSTATUS _lsa_lookup_sids_internal(struct pipes_struct *p,
 			 * RID as 8 bytes hex, in others it returns the full
 			 * SID. We (Jerry/VL) could not figure out which the
 			 * hard cases are, so leave it with the SID.  */
-			name->name = talloc_asprintf(p->mem_ctx, "%s",
-			                             sid_to_fstring(tmp,
-								    sids[i]));
+			name->name = dom_sid_string(p->mem_ctx, sids[i]);
 			if (name->name == NULL) {
 				return NT_STATUS_NO_MEMORY;
 			}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list