[SCM] Samba Shared Repository - branch v3-6-test updated
Volker Lendecke
vlendec at samba.org
Thu Mar 3 22:58:22 MST 2011
The branch, v3-6-test has been updated
via 2a5e9ef s3: Use dom_sid_string_buf in sid_to_fstring
via d640350 Add dom_sid_string_buf
via 28fdc60 s3: Use dom_sid_string in _lsa_lookup_sids_internal
via 8bd0bc2 s3: Remove an obsolete comment
via 14d9515 s3: Fix some nonempty blank lines
from 880fb9c s3: Pass the aio_force operation through vfs_gpfs
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-6-test
- Log -----------------------------------------------------------------
commit 2a5e9efc76fbc9e608273007d5447de49b8aec7e
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 d64035043053707dde17d97ef082ebe9e653daea
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 28fdc60a7f87e0bb6c93c4bfa8a7417abe6745f6
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 8bd0bc2fa2db1e2062ec7acbb9ba30bc8c61fe88
Author: Volker Lendecke <vl at samba.org>
Date: Thu Mar 3 15:26:12 2011 +0100
s3: Remove an obsolete comment
commit 14d95151c9aff506dd93da7fcbc8e4e7587a19c8
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 1dbbbd6..cd5cd7d 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 22c29af..a2509d5 100644
--- a/source3/rpc_server/lsa/srv_lsa_nt.c
+++ b/source3/rpc_server/lsa/srv_lsa_nt.c
@@ -846,7 +846,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
@@ -854,9 +853,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