samba-cvs.cvs
[Top] [All Lists]

svn commit: samba r13616 - in branches/SAMBA_4_0/source: dsdb/samdb/ldb_

Subject: svn commit: samba r13616 - in branches/SAMBA_4_0/source: dsdb/samdb/ldb_modules lib/ldb/common lib/ldb/include lib/ldb/modules
From:
Date: Wed, 22 Feb 2006 09:28:59 +0000 GMT
Author: abartlet
Date: 2006-02-22 09:28:58 +0000 (Wed, 22 Feb 2006)
New Revision: 13616

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=13616

Log:
Add new ldb functions: ldb_msg_add_steal_string() and
ldb_msg_add_steal_value().

These try to maintain the talloc heirachy, which must be correct
otherwise talloc_steal operations of entire attribute lists fails.

This fixes the currentTime value, found by using Microsoft's dcdiag
tool (before this commit, it pointed to invalid memory, due to the
changes in -r 13606)

Andrew Bartlett


Modified:
   branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/rootdse.c
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c
   branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
   branches/SAMBA_4_0/source/lib/ldb/modules/operational.c


Changeset:
Modified: branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/rootdse.c
===================================================================
--- branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/rootdse.c  2006-02-22 
05:21:43 UTC (rev 13615)
+++ branches/SAMBA_4_0/source/dsdb/samdb/ldb_modules/rootdse.c  2006-02-22 
09:28:58 UTC (rev 13616)
@@ -64,8 +64,8 @@
        msg->dn = ldb_dn_explode(msg, "");
 
        if (do_attribute(s->attrs, "currentTime")) {
-               if (ldb_msg_add_string(msg, "currentTime", 
-                                      ldb_timestring(msg, time(NULL))) != 0) {
+               if (ldb_msg_add_steal_string(msg, "currentTime", 
+                                            ldb_timestring(msg, time(NULL))) 
!= 0) {
                        goto failed;
                }
        }
@@ -77,8 +77,8 @@
                        if (!control) {
                                goto failed;
                        }
-                       if (ldb_msg_add_string(msg, "supportedControl",
-                                              control) != 0) {
+                       if (ldb_msg_add_steal_string(msg, "supportedControl",
+                                                    control) != 0) {
                                goto failed;
                        }
                }
@@ -95,12 +95,12 @@
                int i;
                for (i = 0; ops && ops[i]; i++) {
                        if (ops[i]->sasl_name) {
-                               const char *sasl_name = talloc_strdup(msg, 
ops[i]->sasl_name);
+                               char *sasl_name = talloc_strdup(msg, 
ops[i]->sasl_name);
                                if (!sasl_name) {
                                        goto failed;
                                }
-                               if (ldb_msg_add_string(msg, 
"supportedSASLMechanisms",
-                                                      sasl_name) != 0) {
+                               if (ldb_msg_add_steal_string(msg, 
"supportedSASLMechanisms",
+                                                            sasl_name) != 0) {
                                        goto failed;
                                }
                        }

Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c  2006-02-22 05:21:43 UTC 
(rev 13615)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_msg.c  2006-02-22 09:28:58 UTC 
(rev 13616)
@@ -199,6 +199,24 @@
 
 
 /*
+  add a value to a message, stealing it into the 'right' place
+*/
+int ldb_msg_add_steal_value(struct ldb_message *msg, 
+                           const char *attr_name,
+                           struct ldb_val *val)
+{
+       int ret;
+       ret = ldb_msg_add_value(msg, attr_name, val);
+       if (ret == LDB_SUCCESS) {
+               struct ldb_message_element *el;
+               el = ldb_msg_find_element(msg, attr_name);
+               talloc_steal(el->values, val->data);
+       }
+       return ret;
+}
+
+
+/*
   add a string element to a message
 */
 int ldb_msg_add_string(struct ldb_message *msg, 
@@ -213,6 +231,20 @@
 }
 
 /*
+  add a string element to a message, stealing it into the 'right' place
+*/
+int ldb_msg_add_steal_string(struct ldb_message *msg, 
+                            const char *attr_name, char *str)
+{
+       struct ldb_val val;
+
+       val.data = (uint8_t *)str;
+       val.length = strlen(str);
+
+       return ldb_msg_add_steal_value(msg, attr_name, &val);
+}
+
+/*
   add a printf formatted element to a message
 */
 int ldb_msg_add_fmt(struct ldb_message *msg, 

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h     2006-02-22 05:21:43 UTC 
(rev 13615)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h     2006-02-22 09:28:58 UTC 
(rev 13616)
@@ -1098,6 +1098,11 @@
 int ldb_msg_add_value(struct ldb_message *msg, 
                      const char *attr_name,
                      const struct ldb_val *val);
+int ldb_msg_add_steal_value(struct ldb_message *msg, 
+                     const char *attr_name,
+                     struct ldb_val *val);
+int ldb_msg_add_steal_string(struct ldb_message *msg, 
+                            const char *attr_name, char *str);
 int ldb_msg_add_string(struct ldb_message *msg, 
                       const char *attr_name, const char *str);
 int ldb_msg_add_fmt(struct ldb_message *msg, 

Modified: branches/SAMBA_4_0/source/lib/ldb/modules/operational.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/modules/operational.c     2006-02-22 
05:21:43 UTC (rev 13615)
+++ branches/SAMBA_4_0/source/lib/ldb/modules/operational.c     2006-02-22 
09:28:58 UTC (rev 13616)
@@ -86,7 +86,7 @@
        if (canonicalName == NULL) {
                return -1;
        }
-       return ldb_msg_add_string(msg, "canonicalName", canonicalName);
+       return ldb_msg_add_steal_string(msg, "canonicalName", canonicalName);
 }
 
 /*

<Prev in Thread] Current Thread [Next in Thread>
  • svn commit: samba r13616 - in branches/SAMBA_4_0/source: dsdb/samdb/ldb_modules lib/ldb/common lib/ldb/include lib/ldb/modules, abartlet <=