r2527: - add a dummy for a simple ldb backend
[gd/samba-autobuild/.git] / source4 / ldap_server / ldap_rootdse.c
1 /* 
2    Unix SMB/CIFS implementation.
3    LDAP server ROOT DSE
4    Copyright (C) Stefan Metzmacher 2004
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 #define ATTR_BLOB_CONST(val) data_blob_talloc(attrs, val, sizeof(val)-1)
24 #define ATTR_SINGLE_NOVAL(attr, blob, num, nam) do { \
25         attr.name = talloc_strdup(attrs, nam);\
26         attr.num_values = num; \
27         attr.values = blob;\
28 } while(0)
29
30 void ldapsrv_RootDSE_Search(struct ldapsrv_call *call,
31                                      struct ldap_SearchRequest *r)
32 {
33         struct ldap_SearchResEntry *ent;
34         struct ldap_Result *done;
35         int code = 0;
36         struct ldapsrv_reply *ent_r, *done_r;
37         int num_attrs = 3;
38         struct ldap_attribute *attrs;
39
40         DEBUG(10, ("Root DSE: %s\n", r->filter));
41
42         if (r->scope != LDAP_SEARCH_SCOPE_BASE) {
43                 code = 32; /* nosuchobject */
44                 goto no_base_scope;
45         }
46
47         attrs = talloc_array_p(call, struct ldap_attribute, num_attrs); 
48         if (!attrs) {
49                 ldapsrv_terminate_connection(call->conn, "no memory");
50                 return;
51         }
52
53         /* 
54          * currentTime
55          * 20040918090350.0Z
56          */
57         {
58                 int num_currentTime = 1;
59                 DATA_BLOB *currentTime = talloc_array_p(attrs, DATA_BLOB, num_currentTime);
60                 char *str = ldap_timestring(call, time(NULL));
61                 if (!str) {
62                         ldapsrv_terminate_connection(call->conn, "no memory");
63                         return;
64                 }
65                 currentTime[0].data = str;
66                 currentTime[0].length = strlen(str);
67                 ATTR_SINGLE_NOVAL(attrs[0], currentTime, num_currentTime, "currentTime");
68         }
69
70         /* 
71          * subschemaSubentry 
72          * CN=Aggregate,CN=Schema,CN=Configuration,DC=DOM,DC=TLD
73          */
74
75         /* 
76          * dsServiceName
77          * CN=NTDS Settings,CN=NETBIOSNAME,CN=Servers,CN=Default-First-Site,CN=Sites,CN=Configuration,DC=DOM,DC=TLD
78          */
79
80         /* 
81          * namingContexts
82          * DC=DOM,DC=TLD
83          * CN=Configuration,DC=DOM,DC=TLD
84          * CN=Schema,CN=Configuration,DC=DOM,DC=TLD
85          * DC=DomainDnsZones,DC=DOM,DC=TLD
86          * DC=ForestDnsZones,DC=DOM,DC=TLD
87          */
88
89         /* 
90          * defaultNamingContext
91          * DC=DOM,DC=TLD
92          */
93
94         /* 
95          * schemaNamingContext
96          * CN=Schema,CN=Configuration,DC=DOM,DC=TLD
97          */
98
99         /* 
100          * configurationNamingContext
101          * CN=Configuration,DC=DOM,DC=TLD
102          */
103
104         /* 
105          * rootDomainNamingContext
106          * DC=DOM,DC=TLD
107          */
108
109         /* 
110          * supportedControl
111          * 1.2.840.113556.1.4.319
112          * 1.2.840.113556.1.4.801
113          * 1.2.840.113556.1.4.473
114          * 1.2.840.113556.1.4.528
115          * 1.2.840.113556.1.4.417
116          * 1.2.840.113556.1.4.619
117          * 1.2.840.113556.1.4.841
118          * 1.2.840.113556.1.4.529
119          * 1.2.840.113556.1.4.805
120          * 1.2.840.113556.1.4.521
121          * 1.2.840.113556.1.4.970
122          * 1.2.840.113556.1.4.1338
123          * 1.2.840.113556.1.4.474
124          * 1.2.840.113556.1.4.1339
125          * 1.2.840.113556.1.4.1340
126          * 1.2.840.113556.1.4.1413
127          * 2.16.840.1.113730.3.4.9
128          * 2.16.840.1.113730.3.4.10
129          * 1.2.840.113556.1.4.1504
130          * 1.2.840.113556.1.4.1852
131          * 1.2.840.113556.1.4.802
132          */
133
134         /* 
135          * supportedLDAPVersion 
136          * 3
137          * 2
138          */
139         {
140                 int num_supportedLDAPVersion = 1;
141                 DATA_BLOB *supportedLDAPVersion = talloc_array_p(attrs, DATA_BLOB, num_supportedLDAPVersion);
142                 supportedLDAPVersion[0] = ATTR_BLOB_CONST("3");
143                 ATTR_SINGLE_NOVAL(attrs[1], supportedLDAPVersion, num_supportedLDAPVersion, "supportedLDAPVersion");
144         }
145
146         /* 
147          * supportedLDAPPolicies
148          * MaxPoolThreads
149          * MaxDatagramRecv
150          * MaxReceiveBuffer
151          * InitRecvTimeout
152          * MaxConnections
153          * MaxConnIdleTime
154          * MaxPageSize
155          * MaxQueryDuration
156          * MaxTempTableSize
157          * MaxResultSetSize
158          * MaxNotificationPerConn
159          * MaxValRange
160          */
161
162         /* 
163          * highestCommittedUSN 
164          * 4555
165          */
166
167         /* 
168          * supportedSASLMechanisms
169          * GSSAPI
170          * GSS-SPNEGO
171          * EXTERNAL
172          * DIGEST-MD5
173          */
174
175         /* 
176          * dnsHostName
177          * netbiosname.dom.tld
178          */
179         {
180                 int num_dnsHostName = 1;
181                 DATA_BLOB *dnsHostName = talloc_array_p(attrs, DATA_BLOB, num_dnsHostName);
182                 dnsHostName[0] = data_blob_talloc(attrs, lp_netbios_name(),strlen(lp_netbios_name()));
183                 ATTR_SINGLE_NOVAL(attrs[2], dnsHostName, num_dnsHostName, "dnsHostName");
184         }
185
186         /* 
187          * ldapServiceName
188          * dom.tld:netbiosname$@DOM.TLD
189          */
190
191         /* 
192          * serverName:
193          * CN=NETBIOSNAME,CN=Servers,CN=Default-First-Site,CN=Sites,CN=Configuration,DC=DOM,DC=TLD
194          */
195
196         /* 
197          * supportedCapabilities
198          * 1.2.840.113556.1.4.800
199          * 1.2.840.113556.1.4.1670
200          * 1.2.840.113556.1.4.1791
201          */
202
203         /* 
204          * isSynchronized:
205          * TRUE/FALSE
206          */
207
208         /* 
209          * isGlobalCatalogReady
210          * TRUE/FALSE
211          */
212
213         /* 
214          * domainFunctionality
215          * 0
216          */
217
218         /* 
219          * forestFunctionality
220          * 0
221          */
222
223         /* 
224          * domainControllerFunctionality
225          * 2
226          */
227
228
229         ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
230         if (!ent_r) {
231                 ldapsrv_terminate_connection(call->conn, "ldapsrv_init_reply() failed");
232                 return;
233         }
234
235         ent = &ent_r->msg.r.SearchResultEntry;
236         ent->dn = "";
237         ent->num_attributes = num_attrs;
238         ent->attributes = attrs;
239
240         ldapsrv_queue_reply(call, ent_r);
241
242 no_base_scope:
243
244         done_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultDone);
245         if (!done_r) {
246                 ldapsrv_terminate_connection(call->conn, "ldapsrv_init_reply() failed");
247                 return;
248         }
249
250         done = &done_r->msg.r.SearchResultDone;
251         done->resultcode = code;
252         done->dn = NULL;
253         done->errormessage = NULL;
254         done->referral = NULL;
255
256         ldapsrv_queue_reply(call, done_r);
257 }