Author: metze
Date: 2006-01-17 18:56:04 +0000 (Tue, 17 Jan 2006)
New Revision: 12984

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

Log:
add parse code and ldbsearch cmdline code for
NOTIFICATION LDAP Controls
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_notification_oid.asp

this doesn't work yet, but it shows that we need to extend ldb to correctly
handle async requests...

metze
Modified:
   branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
   branches/SAMBA_4_0/source/lib/ldb/tools/ldbsearch.c
   branches/SAMBA_4_0/source/libcli/ldap/ldap_controls.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h     2006-01-17 17:23:11 UTC 
(rev 12983)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h     2006-01-17 18:56:04 UTC 
(rev 12984)
@@ -375,6 +375,13 @@
 #define LDB_CONTROL_PAGED_RESULTS_OID  "1.2.840.113556.1.4.319"
 
 /**
+   OID for notification
+
+   \sa <a 
href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_notification_oid.asp";>Microsoft
 documentation of this OID</a>
+*/
+#define LDB_CONTROL_NOTIFICATION_OID   "1.2.840.113556.1.4.528"
+
+/**
    OID for extended DN
 
    \sa <a 
href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_extended_dn_oid.asp";>Microsoft
 documentation of this OID</a>

Modified: branches/SAMBA_4_0/source/lib/ldb/tools/ldbsearch.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/tools/ldbsearch.c 2006-01-17 17:23:11 UTC 
(rev 12983)
+++ branches/SAMBA_4_0/source/lib/ldb/tools/ldbsearch.c 2006-01-17 18:56:04 UTC 
(rev 12984)
@@ -216,6 +216,25 @@
                        continue;
                }
 
+               if (strncmp(control_strings[i], "notification:", 13) == 0) {
+                       const char *p;
+                       int crit, ret;
+
+                       p = &(control_strings[i][13]);
+                       ret = sscanf(p, "%d", &crit);
+                       if ((ret != 1) || (crit < 0) || (crit > 1)) {
+                               fprintf(stderr, "invalid notification control 
syntax\n");
+                               return NULL;
+                       }
+
+                       ctrl[i] = talloc(ctrl, struct ldb_control);
+                       ctrl[i]->oid = LDB_CONTROL_NOTIFICATION_OID;
+                       ctrl[i]->critical = crit;
+                       ctrl[i]->data = NULL;
+
+                       continue;
+               }
+
                /* no controls matched, throw an error */
                fprintf(stderr, "Invalid control name\n");
                return NULL;

Modified: branches/SAMBA_4_0/source/libcli/ldap/ldap_controls.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/ldap/ldap_controls.c       2006-01-17 
17:23:11 UTC (rev 12983)
+++ branches/SAMBA_4_0/source/libcli/ldap/ldap_controls.c       2006-01-17 
18:56:04 UTC (rev 12984)
@@ -60,7 +60,7 @@
                if (!asn1_read_OctetString(&data, &attr)) {
                        return False;
                }
-               lsrc->attr_desc = talloc_strndup(lsrc, attr.data, attr.length);
+               lsrc->attr_desc = talloc_strndup(lsrc, (const char *)attr.data, 
attr.length);
                if (!lsrc->attr_desc) {
                        return False;
                }
@@ -111,7 +111,7 @@
                        return False;
                }
 
-               lssc[num]->attributeName = talloc_strndup(lssc[num], attr.data, 
attr.length);
+               lssc[num]->attributeName = talloc_strndup(lssc[num], (const 
char *)attr.data, attr.length);
                if (!lssc [num]->attributeName) {
                        return False;
                }
@@ -120,7 +120,7 @@
                        if (!asn1_read_OctetString(&data, &rule)) {
                                return False;
                        }
-                       lssc[num]->orderingRule = talloc_strndup(lssc[num], 
rule.data, rule.length);
+                       lssc[num]->orderingRule = talloc_strndup(lssc[num], 
(const char *)rule.data, rule.length);
                        if (!lssc[num]->orderingRule) {
                                return False;
                        }
@@ -336,6 +336,15 @@
        return True;
 }
 
+static BOOL decode_notification_request(void *mem_ctx, DATA_BLOB in, void 
**out)
+{
+       if (in.length != 0) {
+               return False;
+       }
+
+       return True;
+}
+
 static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB 
*out)
 {
        struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct 
ldb_sort_resp_control);
@@ -549,6 +558,16 @@
        return True;
 }
 
+static BOOL encode_notification_request(void *mem_ctx, void *in, DATA_BLOB 
*out)
+{
+       if (in) {
+               return False;
+       }
+
+       *out = data_blob(NULL, 0);
+       return True;
+}
+
 struct control_handler ldap_known_controls[] = {
        { "1.2.840.113556.1.4.319", decode_paged_results_request, 
encode_paged_results_request },
        { "1.2.840.113556.1.4.529", decode_extended_dn_request, 
encode_extended_dn_request },
@@ -556,6 +575,7 @@
        { "1.2.840.113556.1.4.474", decode_server_sort_response, 
encode_server_sort_response },
        { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control },
        { "1.2.840.113556.1.4.841", decode_dirsync_request, 
encode_dirsync_request },
+       { "1.2.840.113556.1.4.528", decode_notification_request, 
encode_notification_request },
        { NULL, NULL, NULL }
 };
 

Reply via email to