summaryrefslogtreecommitdiff
path: root/net/tinyldap/files/patch-tinyldap.c
blob: 91a964a170dc030b84380cdae3464b4cf993e7c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--- tinyldap.c.orig	Sat Mar 13 00:21:25 2004
+++ tinyldap.c	Fri Apr  2 13:15:39 2004
@@ -448,6 +448,83 @@
   }
 }
 
+static void answerall(uint32 ofs,long messageid,int out) {
+  struct SearchResultEntry sre;
+  struct PartialAttributeList** pal=&sre.attributes;
+
+  sre.objectName.l=bstrlen(sre.objectName.s=map+uint32_read(map+ofs+8));
+  sre.attributes=0;
+  /* now go through list of requested attributes */
+  {
+    uint32 adl=1,last=0;
+    struct string attr_key;
+
+    attr_key.s = NULL;
+    attr_key.l = 0;
+    uint32_unpack(map+ofs,&last);
+    while (adl < last) {
+      const char* att=0;
+      const char* val=0;
+      uint32 i=adl,j=last;
+
+      if (adl == 1) {
+         att="objectClass";
+	 val=map+uint32_read(map+ofs+12);
+      } else {
+         att=map+uint32_read(map+ofs+i*8);
+	 if (matchstring(&attr_key,att)) {
+	    val=map+uint32_read(map+ofs+i*8+4);
+	    ++i;
+         }
+      }
+      if (val) {
+	*pal=malloc(sizeof(struct PartialAttributeList));
+	if (!*pal) {
+nomem:
+	  buffer_putsflush(buffer_2,"out of virtual memory!\n");
+	  exit(1);
+	}
+        attr_key.s = att;
+        attr_key.l = strlen(att);
+	(*pal)->type=attr_key;
+	{
+	  struct AttributeDescriptionList** a=&(*pal)->values;
+add_attribute:
+	  *a=malloc(sizeof(struct AttributeDescriptionList));
+	  if (!*a) goto nomem;
+	  (*a)->a.s=bstrfirst(val);
+	  (*a)->a.l=bstrlen(val);
+	  for (;i<j; ++i)
+	    if (!matchstring(&attr_key,map+uint32_read(map+ofs+i*8))) {
+	      val=map+uint32_read(map+ofs+i*8+4);
+	      ++i;
+	      a=&(*a)->next;
+	      goto add_attribute;
+	    }
+	  (*a)->next=0;
+	}
+	(*pal)->next=0;
+	pal=&(*pal)->next;
+      }
+      adl++;
+    }
+  }
+  {
+    long l=fmt_ldapsearchresultentry(0,&sre);
+    char *buf=alloca(l+300); /* you never know ;) */
+    long tmp;
+    if (verbose) {
+      buffer_puts(buffer_2,"sre len ");
+      buffer_putulong(buffer_2,l);
+      buffer_putsflush(buffer_2,".\n");
+    }
+    tmp=fmt_ldapmessage(buf,messageid,SearchResultEntry,l);
+    fmt_ldapsearchresultentry(buf+tmp,&sre);
+    write(out,buf,l+tmp);
+  }
+  free_ldappal(sre.attributes);
+}
+
 static void answerwith(uint32 ofs,struct SearchRequest* sr,long messageid,int out) {
   struct SearchResultEntry sre;
   struct PartialAttributeList** pal=&sre.attributes;
@@ -483,6 +560,10 @@
   /* now go through list of requested attributes */
   {
     struct AttributeDescriptionList* adl=sr->attributes;
+    if ( adl == NULL ) {
+      answerall(ofs,messageid,out);
+      return;
+    }
     while (adl) {
       const char* val=0;
       uint32 i=2,j;