485f4055682f415f61cca9f1a92bc7adcaba95fc
[mat/samba.git] / source3 / passdb / pdb_interface.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Password and authentication handling
4    Copyright (C) Andrew Bartlett                        2002
5    Copyright (C) Jelmer Vernooij                        2002
6    Copyright (C) Simo Sorce                             2003
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_PASSDB
27
28 static struct pdb_init_function_entry *backends = NULL;
29
30 static void lazy_initialize_passdb(void)
31 {
32         static BOOL initialized = False;
33         if(initialized)return;
34         static_init_pdb;
35         initialized = True;
36 }
37
38 static struct pdb_init_function_entry *pdb_find_backend_entry(const char *name);
39
40 /*******************************************************************
41  Clean up uninitialised passwords.  The only way to tell 
42  that these values are not 'real' is that they do not
43  have a valid last set time.  Instead, the value is fixed at 0. 
44  Therefore we use that as the key for 'is this a valid password'.
45  However, it is perfectly valid to have a 'default' last change
46  time, such LDAP with a missing attribute would produce.
47 ********************************************************************/
48
49 static void pdb_force_pw_initialization(SAM_ACCOUNT *pass) 
50 {
51         const uint8 *lm_pwd, *nt_pwd;
52         
53         /* only reset a password if the last set time has been 
54            explicitly been set to zero.  A default last set time 
55            is ignored */
56
57         if ( (pdb_get_init_flags(pass, PDB_PASSLASTSET) != PDB_DEFAULT) 
58                 && (pdb_get_pass_last_set_time(pass) == 0) ) 
59         {
60                 
61                 if (pdb_get_init_flags(pass, PDB_LMPASSWD) != PDB_DEFAULT) 
62                 {
63                         lm_pwd = pdb_get_lanman_passwd(pass);
64                         if (lm_pwd) 
65                                 pdb_set_lanman_passwd(pass, NULL, PDB_CHANGED);
66                 }
67                 if (pdb_get_init_flags(pass, PDB_NTPASSWD) != PDB_DEFAULT) 
68                 {
69                         nt_pwd = pdb_get_nt_passwd(pass);
70                         if (nt_pwd) 
71                                 pdb_set_nt_passwd(pass, NULL, PDB_CHANGED);
72                 }
73         }
74
75         return;
76 }
77
78 NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function init) 
79 {
80         struct pdb_init_function_entry *entry = backends;
81
82         if(version != PASSDB_INTERFACE_VERSION) {
83                 DEBUG(0,("Can't register passdb backend!\n"
84                          "You tried to register a passdb module with PASSDB_INTERFACE_VERSION %d, "
85                          "while this version of samba uses version %d\n", 
86                          version,PASSDB_INTERFACE_VERSION));
87                 return NT_STATUS_OBJECT_TYPE_MISMATCH;
88         }
89
90         if (!name || !init) {
91                 return NT_STATUS_INVALID_PARAMETER;
92         }
93
94         DEBUG(5,("Attempting to register passdb backend %s\n", name));
95
96         /* Check for duplicates */
97         if (pdb_find_backend_entry(name)) {
98                 DEBUG(0,("There already is a passdb backend registered with the name %s!\n", name));
99                 return NT_STATUS_OBJECT_NAME_COLLISION;
100         }
101
102         entry = SMB_XMALLOC_P(struct pdb_init_function_entry);
103         entry->name = smb_xstrdup(name);
104         entry->init = init;
105
106         DLIST_ADD(backends, entry);
107         DEBUG(5,("Successfully added passdb backend '%s'\n", name));
108         return NT_STATUS_OK;
109 }
110
111 static struct pdb_init_function_entry *pdb_find_backend_entry(const char *name)
112 {
113         struct pdb_init_function_entry *entry = backends;
114
115         while(entry) {
116                 if (strcmp(entry->name, name)==0) return entry;
117                 entry = entry->next;
118         }
119
120         return NULL;
121 }
122
123 static NTSTATUS context_setsampwent(struct pdb_context *context, BOOL update, uint16 acb_mask)
124 {
125         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
126
127         if (!context) {
128                 DEBUG(0, ("invalid pdb_context specified!\n"));
129                 return ret;
130         }
131
132         context->pwent_methods = context->pdb_methods;
133
134         if (!context->pwent_methods) {
135                 /* No passdbs at all */
136                 return ret;
137         }
138
139         while (NT_STATUS_IS_ERR(ret = context->pwent_methods->setsampwent(context->pwent_methods, update, acb_mask))) {
140                 context->pwent_methods = context->pwent_methods->next;
141                 if (context->pwent_methods == NULL) 
142                         return NT_STATUS_UNSUCCESSFUL;
143         }
144         return ret;
145 }
146
147 static void context_endsampwent(struct pdb_context *context)
148 {
149         if ((!context)){
150                 DEBUG(0, ("invalid pdb_context specified!\n"));
151                 return;
152         }
153
154         if (context->pwent_methods && context->pwent_methods->endsampwent)
155                 context->pwent_methods->endsampwent(context->pwent_methods);
156
157         /* So we won't get strange data when calling getsampwent now */
158         context->pwent_methods = NULL;
159 }
160
161 static NTSTATUS context_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user)
162 {
163         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
164
165         if ((!context) || (!context->pwent_methods)) {
166                 DEBUG(0, ("invalid pdb_context specified!\n"));
167                 return ret;
168         }
169         /* Loop until we find something useful */
170         while (NT_STATUS_IS_ERR(ret = context->pwent_methods->getsampwent(context->pwent_methods, user))) {
171
172                 context->pwent_methods->endsampwent(context->pwent_methods);
173
174                 context->pwent_methods = context->pwent_methods->next;
175
176                 /* All methods are checked now. There are no more entries */
177                 if (context->pwent_methods == NULL)
178                         return ret;
179         
180                 context->pwent_methods->setsampwent(context->pwent_methods, False, 0);
181         }
182         user->methods = context->pwent_methods;
183         pdb_force_pw_initialization(user);
184         return ret;
185 }
186
187 static NTSTATUS context_getsampwnam(struct pdb_context *context, SAM_ACCOUNT *sam_acct, const char *username)
188 {
189         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
190
191         struct pdb_methods *curmethods;
192         if ((!context)) {
193                 DEBUG(0, ("invalid pdb_context specified!\n"));
194                 return ret;
195         }
196         curmethods = context->pdb_methods;
197         while (curmethods){
198                 if (NT_STATUS_IS_OK(ret = curmethods->getsampwnam(curmethods, sam_acct, username))) {
199                         pdb_force_pw_initialization(sam_acct);
200                         sam_acct->methods = curmethods;
201                         return ret;
202                 }
203                 curmethods = curmethods->next;
204         }
205
206         return ret;
207 }
208
209 static NTSTATUS context_getsampwsid(struct pdb_context *context, SAM_ACCOUNT *sam_acct, const DOM_SID *sid)
210 {
211         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
212
213         struct pdb_methods *curmethods;
214         if ((!context)) {
215                 DEBUG(0, ("invalid pdb_context specified!\n"));
216                 return ret;
217         }
218         
219         curmethods = context->pdb_methods;
220
221         while (curmethods){
222                 if (NT_STATUS_IS_OK(ret = curmethods->getsampwsid(curmethods, sam_acct, sid))) {
223                         pdb_force_pw_initialization(sam_acct);
224                         sam_acct->methods = curmethods;
225                         return ret;
226                 }
227                 curmethods = curmethods->next;
228         }
229
230         return ret;
231 }
232
233 static NTSTATUS context_add_sam_account(struct pdb_context *context, SAM_ACCOUNT *sam_acct)
234 {
235         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
236         const uint8 *lm_pw, *nt_pw;
237         uint16 acb_flags;
238
239         if ((!context) || (!context->pdb_methods)) {
240                 DEBUG(0, ("invalid pdb_context specified!\n"));
241                 return ret;
242         }
243
244         /* disable acccounts with no passwords (that has not 
245            been allowed by the  ACB_PWNOTREQ bit */
246         
247         lm_pw = pdb_get_lanman_passwd( sam_acct );
248         nt_pw = pdb_get_nt_passwd( sam_acct );
249         acb_flags = pdb_get_acct_ctrl( sam_acct );
250         if ( !lm_pw && !nt_pw && !(acb_flags&ACB_PWNOTREQ) ) {
251                 acb_flags |= ACB_DISABLED;
252                 pdb_set_acct_ctrl( sam_acct, acb_flags, PDB_CHANGED );
253         }
254         
255         /** @todo  This is where a 're-read on add' should be done */
256         /* We now add a new account to the first database listed. 
257          * Should we? */
258
259         return context->pdb_methods->add_sam_account(context->pdb_methods, sam_acct);
260 }
261
262 static NTSTATUS context_update_sam_account(struct pdb_context *context, SAM_ACCOUNT *sam_acct)
263 {
264         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
265         const uint8 *lm_pw, *nt_pw;
266         uint16 acb_flags;
267
268         if (!context) {
269                 DEBUG(0, ("invalid pdb_context specified!\n"));
270                 return ret;
271         }
272
273         if (!sam_acct || !sam_acct->methods){
274                 DEBUG(0, ("invalid sam_acct specified\n"));
275                 return ret;
276         }
277
278         /* disable acccounts with no passwords (that has not 
279            been allowed by the  ACB_PWNOTREQ bit */
280         
281         lm_pw = pdb_get_lanman_passwd( sam_acct );
282         nt_pw = pdb_get_nt_passwd( sam_acct );
283         acb_flags = pdb_get_acct_ctrl( sam_acct );
284         if ( !lm_pw && !nt_pw && !(acb_flags&ACB_PWNOTREQ) ) {
285                 acb_flags |= ACB_DISABLED;
286                 pdb_set_acct_ctrl( sam_acct, acb_flags, PDB_CHANGED );
287         }
288         
289         /** @todo  This is where a 're-read on update' should be done */
290
291         return sam_acct->methods->update_sam_account(sam_acct->methods, sam_acct);
292 }
293
294 static NTSTATUS context_delete_sam_account(struct pdb_context *context, SAM_ACCOUNT *sam_acct)
295 {
296         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
297
298         struct pdb_methods *pdb_selected;
299         if (!context) {
300                 DEBUG(0, ("invalid pdb_context specified!\n"));
301                 return ret;
302         }
303
304         if (!sam_acct->methods){
305                 pdb_selected = context->pdb_methods;
306                 /* There's no passdb backend specified for this account.
307                  * Try to delete it in every passdb available 
308                  * Needed to delete accounts in smbpasswd that are not
309                  * in /etc/passwd.
310                  */
311                 while (pdb_selected){
312                         if (NT_STATUS_IS_OK(ret = pdb_selected->delete_sam_account(pdb_selected, sam_acct))) {
313                                 return ret;
314                         }
315                         pdb_selected = pdb_selected->next;
316                 }
317                 return ret;
318         }
319
320         if (!sam_acct->methods->delete_sam_account){
321                 DEBUG(0,("invalid sam_acct->methods->delete_sam_account\n"));
322                 return ret;
323         }
324         
325         return sam_acct->methods->delete_sam_account(sam_acct->methods, sam_acct);
326 }
327
328 static NTSTATUS context_rename_sam_account(struct pdb_context *context, SAM_ACCOUNT *oldname, const char *newname)
329 {
330         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
331
332         struct pdb_methods *pdb_selected;
333         if (!context) {
334                 DEBUG(0, ("invalid pdb_context specified!\n"));
335                 return ret;
336         }
337
338         if (!oldname->methods){
339                 pdb_selected = context->pdb_methods;
340                 /* There's no passdb backend specified for this account.
341                  * Try to delete it in every passdb available 
342                  * Needed to delete accounts in smbpasswd that are not
343                  * in /etc/passwd.
344                  */
345                 while (pdb_selected){
346                         if (NT_STATUS_IS_OK(ret = pdb_selected->rename_sam_account(pdb_selected, oldname, newname))) {
347                                 return ret;
348                         }
349                         pdb_selected = pdb_selected->next;
350                 }
351                 return ret;
352         }
353
354         if (!oldname->methods->rename_sam_account){
355                 DEBUG(0,("invalid oldname->methods->rename_sam_account\n"));
356                 return ret;
357         }
358         
359         return oldname->methods->rename_sam_account(oldname->methods, oldname, newname);
360 }
361
362
363 static NTSTATUS context_update_login_attempts(struct pdb_context *context,
364                                                 SAM_ACCOUNT *sam_acct, BOOL success)
365 {
366         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
367
368         if (!context) {
369                 DEBUG(0, ("invalid pdb_context specified!\n"));
370                 return ret;
371         }
372
373         if (!sam_acct || !sam_acct->methods){
374                 DEBUG(0, ("invalid sam_acct specified\n"));
375                 return ret;
376         }
377
378         return sam_acct->methods->update_login_attempts(sam_acct->methods, sam_acct, success);
379 }
380
381 static NTSTATUS context_getgrsid(struct pdb_context *context,
382                                  GROUP_MAP *map, DOM_SID sid)
383 {
384         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
385
386         struct pdb_methods *curmethods;
387         if ((!context)) {
388                 DEBUG(0, ("invalid pdb_context specified!\n"));
389                 return ret;
390         }
391         curmethods = context->pdb_methods;
392         while (curmethods){
393                 ret = curmethods->getgrsid(curmethods, map, sid);
394                 if (NT_STATUS_IS_OK(ret)) {
395                         map->methods = curmethods;
396                         return ret;
397                 }
398                 curmethods = curmethods->next;
399         }
400
401         return ret;
402 }
403
404 static NTSTATUS context_getgrgid(struct pdb_context *context,
405                                  GROUP_MAP *map, gid_t gid)
406 {
407         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
408
409         struct pdb_methods *curmethods;
410         if ((!context)) {
411                 DEBUG(0, ("invalid pdb_context specified!\n"));
412                 return ret;
413         }
414         curmethods = context->pdb_methods;
415         while (curmethods){
416                 ret = curmethods->getgrgid(curmethods, map, gid);
417                 if (NT_STATUS_IS_OK(ret)) {
418                         map->methods = curmethods;
419                         return ret;
420                 }
421                 curmethods = curmethods->next;
422         }
423
424         return ret;
425 }
426
427 static NTSTATUS context_getgrnam(struct pdb_context *context,
428                                  GROUP_MAP *map, const char *name)
429 {
430         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
431
432         struct pdb_methods *curmethods;
433         if ((!context)) {
434                 DEBUG(0, ("invalid pdb_context specified!\n"));
435                 return ret;
436         }
437         curmethods = context->pdb_methods;
438         while (curmethods){
439                 ret = curmethods->getgrnam(curmethods, map, name);
440                 if (NT_STATUS_IS_OK(ret)) {
441                         map->methods = curmethods;
442                         return ret;
443                 }
444                 curmethods = curmethods->next;
445         }
446
447         return ret;
448 }
449
450 static NTSTATUS context_add_group_mapping_entry(struct pdb_context *context,
451                                                 GROUP_MAP *map)
452 {
453         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
454
455         if ((!context) || (!context->pdb_methods)) {
456                 DEBUG(0, ("invalid pdb_context specified!\n"));
457                 return ret;
458         }
459
460         return context->pdb_methods->add_group_mapping_entry(context->pdb_methods,
461                                                              map);
462 }
463
464 static NTSTATUS context_update_group_mapping_entry(struct pdb_context *context,
465                                                    GROUP_MAP *map)
466 {
467         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
468
469         if ((!context) || (!context->pdb_methods)) {
470                 DEBUG(0, ("invalid pdb_context specified!\n"));
471                 return ret;
472         }
473
474         return context->
475                 pdb_methods->update_group_mapping_entry(context->pdb_methods, map);
476 }
477
478 static NTSTATUS context_delete_group_mapping_entry(struct pdb_context *context,
479                                                    DOM_SID sid)
480 {
481         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
482
483         if ((!context) || (!context->pdb_methods)) {
484                 DEBUG(0, ("invalid pdb_context specified!\n"));
485                 return ret;
486         }
487
488         return context->
489                 pdb_methods->delete_group_mapping_entry(context->pdb_methods, sid);
490 }
491
492 static NTSTATUS context_enum_group_mapping(struct pdb_context *context,
493                                            enum SID_NAME_USE sid_name_use,
494                                            GROUP_MAP **rmap, int *num_entries,
495                                            BOOL unix_only)
496 {
497         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
498
499         if ((!context) || (!context->pdb_methods)) {
500                 DEBUG(0, ("invalid pdb_context specified!\n"));
501                 return ret;
502         }
503
504         return context->pdb_methods->enum_group_mapping(context->pdb_methods,
505                                                         sid_name_use, rmap,
506                                                         num_entries, unix_only);
507 }
508
509 static NTSTATUS context_enum_group_members(struct pdb_context *context,
510                                            TALLOC_CTX *mem_ctx,
511                                            const DOM_SID *group,
512                                            uint32 **member_rids,
513                                            int *num_members)
514 {
515         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
516
517         if ((!context) || (!context->pdb_methods)) {
518                 DEBUG(0, ("invalid pdb_context specified!\n"));
519                 return ret;
520         }
521
522         return context->pdb_methods->enum_group_members(context->pdb_methods,
523                                                         mem_ctx, group,
524                                                         member_rids,
525                                                         num_members);
526 }
527
528 static NTSTATUS context_enum_group_memberships(struct pdb_context *context,
529                                                const char *username,
530                                                gid_t primary_gid,
531                                                DOM_SID **sids, gid_t **gids,
532                                                int *num_groups)
533 {
534         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
535
536         if ((!context) || (!context->pdb_methods)) {
537                 DEBUG(0, ("invalid pdb_context specified!\n"));
538                 return ret;
539         }
540
541         return context->pdb_methods->
542                 enum_group_memberships(context->pdb_methods, username,
543                                        primary_gid, sids, gids, num_groups);
544 }
545
546 static NTSTATUS context_find_alias(struct pdb_context *context,
547                                    const char *name, DOM_SID *sid)
548 {
549         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
550
551         if ((!context) || (!context->pdb_methods)) {
552                 DEBUG(0, ("invalid pdb_context specified!\n"));
553                 return ret;
554         }
555
556         return context->pdb_methods->find_alias(context->pdb_methods,
557                                                 name, sid);
558 }
559
560 static NTSTATUS context_create_alias(struct pdb_context *context,
561                                      const char *name, uint32 *rid)
562 {
563         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
564
565         if ((!context) || (!context->pdb_methods)) {
566                 DEBUG(0, ("invalid pdb_context specified!\n"));
567                 return ret;
568         }
569
570         return context->pdb_methods->create_alias(context->pdb_methods,
571                                                   name, rid);
572 }
573
574 static NTSTATUS context_delete_alias(struct pdb_context *context,
575                                      const DOM_SID *sid)
576 {
577         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
578
579         if ((!context) || (!context->pdb_methods)) {
580                 DEBUG(0, ("invalid pdb_context specified!\n"));
581                 return ret;
582         }
583
584         return context->pdb_methods->delete_alias(context->pdb_methods, sid);
585 }
586
587 static NTSTATUS context_get_aliasinfo(struct pdb_context *context,
588                                       const DOM_SID *sid,
589                                       struct acct_info *info)
590 {
591         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
592
593         if ((!context) || (!context->pdb_methods)) {
594                 DEBUG(0, ("invalid pdb_context specified!\n"));
595                 return ret;
596         }
597
598         return context->pdb_methods->get_aliasinfo(context->pdb_methods,
599                                                    sid, info);
600 }
601
602 static NTSTATUS context_set_aliasinfo(struct pdb_context *context,
603                                       const DOM_SID *sid,
604                                       struct acct_info *info)
605 {
606         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
607
608         if ((!context) || (!context->pdb_methods)) {
609                 DEBUG(0, ("invalid pdb_context specified!\n"));
610                 return ret;
611         }
612
613         return context->pdb_methods->set_aliasinfo(context->pdb_methods,
614                                                    sid, info);
615 }
616
617 static NTSTATUS context_add_aliasmem(struct pdb_context *context,
618                                      const DOM_SID *alias,
619                                      const DOM_SID *member)
620 {
621         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
622
623         if ((!context) || (!context->pdb_methods)) {
624                 DEBUG(0, ("invalid pdb_context specified!\n"));
625                 return ret;
626         }
627
628         return context->pdb_methods->add_aliasmem(context->pdb_methods,
629                                                   alias, member);
630 }
631         
632 static NTSTATUS context_del_aliasmem(struct pdb_context *context,
633                                      const DOM_SID *alias,
634                                      const DOM_SID *member)
635 {
636         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
637
638         if ((!context) || (!context->pdb_methods)) {
639                 DEBUG(0, ("invalid pdb_context specified!\n"));
640                 return ret;
641         }
642
643         return context->pdb_methods->del_aliasmem(context->pdb_methods,
644                                                   alias, member);
645 }
646         
647 static NTSTATUS context_enum_aliasmem(struct pdb_context *context,
648                                       const DOM_SID *alias, DOM_SID **members,
649                                       int *num)
650 {
651         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
652
653         if ((!context) || (!context->pdb_methods)) {
654                 DEBUG(0, ("invalid pdb_context specified!\n"));
655                 return ret;
656         }
657
658         return context->pdb_methods->enum_aliasmem(context->pdb_methods,
659                                                    alias, members, num);
660 }
661         
662 static NTSTATUS context_enum_alias_memberships(struct pdb_context *context,
663                                                TALLOC_CTX *mem_ctx,
664                                                const DOM_SID *domain_sid,
665                                                const DOM_SID *members,
666                                                int num_members,
667                                                uint32 **alias_rids,
668                                                int *num_alias_rids)
669 {
670         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
671
672         if ((!context) || (!context->pdb_methods)) {
673                 DEBUG(0, ("invalid pdb_context specified!\n"));
674                 return ret;
675         }
676
677         return context->pdb_methods->
678                 enum_alias_memberships(context->pdb_methods, mem_ctx,
679                                        domain_sid, members, num_members,
680                                        alias_rids, num_alias_rids);
681 }
682
683 static NTSTATUS context_lookup_rids(struct pdb_context *context,
684                                     TALLOC_CTX *mem_ctx,
685                                     const DOM_SID *domain_sid,
686                                     int num_rids,
687                                     uint32 *rids,
688                                     const char ***names,
689                                     uint32 **attrs)
690 {
691         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
692
693         if ((!context) || (!context->pdb_methods)) {
694                 DEBUG(0, ("invalid pdb_context specified!\n"));
695                 return ret;
696         }
697
698         return context->pdb_methods->lookup_rids(context->pdb_methods,
699                                                  mem_ctx, domain_sid, num_rids,
700                                                  rids, names, attrs);
701 }
702
703 static NTSTATUS context_get_account_policy(struct pdb_context *context,
704                                            int policy_index, uint32 *value)
705 {
706         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
707
708         if ((!context) || (!context->pdb_methods)) {
709                 DEBUG(0, ("invalid pdb_context specified!\n"));
710                 return ret;
711         }
712
713         return context->pdb_methods->get_account_policy(context->pdb_methods,
714                                                         policy_index, value);
715 }
716
717 static NTSTATUS context_set_account_policy(struct pdb_context *context,
718                                            int policy_index, uint32 value)
719 {
720         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
721
722         if ((!context) || (!context->pdb_methods)) {
723                 DEBUG(0, ("invalid pdb_context specified!\n"));
724                 return ret;
725         }
726
727         return context->pdb_methods->set_account_policy(context->pdb_methods,
728                                                         policy_index, value);
729 }
730
731 static NTSTATUS context_get_seq_num(struct pdb_context *context, time_t *seq_num)
732 {
733         NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
734
735         if ((!context) || (!context->pdb_methods)) {
736                 DEBUG(0, ("invalid pdb_context specified!\n"));
737                 return ret;
738         }
739
740         return context->pdb_methods->get_seq_num(context->pdb_methods, seq_num);
741 }
742         
743 /******************************************************************
744   Free and cleanup a pdb context, any associated data and anything
745   that the attached modules might have associated.
746  *******************************************************************/
747
748 static void free_pdb_context(struct pdb_context **context)
749 {
750         struct pdb_methods *pdb_selected = (*context)->pdb_methods;
751
752         while (pdb_selected){
753                 if(pdb_selected->free_private_data)
754                         pdb_selected->free_private_data(&(pdb_selected->private_data));
755                 pdb_selected = pdb_selected->next;
756         }
757
758         talloc_destroy((*context)->mem_ctx);
759         *context = NULL;
760 }
761
762 static BOOL context_search_users(struct pdb_context *context,
763                                  struct pdb_search *search, uint16 acct_flags)
764 {
765         if ((!context) || (!context->pdb_methods)) {
766                 DEBUG(0, ("invalid pdb_context specified!\n"));
767                 return False;
768         }
769
770         return context->pdb_methods->search_users(context->pdb_methods,
771                                                   search, acct_flags);
772 }
773
774 static BOOL context_search_groups(struct pdb_context *context,
775                                   struct pdb_search *search)
776 {
777         if ((!context) || (!context->pdb_methods)) {
778                 DEBUG(0, ("invalid pdb_context specified!\n"));
779                 return False;
780         }
781
782         return context->pdb_methods->search_groups(context->pdb_methods,
783                                                    search);
784 }
785
786 static BOOL context_search_aliases(struct pdb_context *context,
787                                    struct pdb_search *search,
788                                    const DOM_SID *sid)
789 {
790         if ((!context) || (!context->pdb_methods)) {
791                 DEBUG(0, ("invalid pdb_context specified!\n"));
792                 return False;
793         }
794
795         return context->pdb_methods->search_aliases(context->pdb_methods,
796                                                     search, sid);
797 }
798
799 /******************************************************************
800   Make a pdb_methods from scratch
801  *******************************************************************/
802
803 static NTSTATUS make_pdb_methods_name(struct pdb_methods **methods, struct pdb_context *context, const char *selected)
804 {
805         char *module_name = smb_xstrdup(selected);
806         char *module_location = NULL, *p;
807         struct pdb_init_function_entry *entry;
808         NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
809
810         lazy_initialize_passdb();
811
812         p = strchr(module_name, ':');
813
814         if (p) {
815                 *p = 0;
816                 module_location = p+1;
817                 trim_char(module_location, ' ', ' ');
818         }
819
820         trim_char(module_name, ' ', ' ');
821
822
823         DEBUG(5,("Attempting to find an passdb backend to match %s (%s)\n", selected, module_name));
824
825         entry = pdb_find_backend_entry(module_name);
826         
827         /* Try to find a module that contains this module */
828         if (!entry) { 
829                 DEBUG(2,("No builtin backend found, trying to load plugin\n"));
830                 if(NT_STATUS_IS_OK(smb_probe_module("pdb", module_name)) && !(entry = pdb_find_backend_entry(module_name))) {
831                         DEBUG(0,("Plugin is available, but doesn't register passdb backend %s\n", module_name));
832                         SAFE_FREE(module_name);
833                         return NT_STATUS_UNSUCCESSFUL;
834                 }
835         }
836         
837         /* No such backend found */
838         if(!entry) { 
839                 DEBUG(0,("No builtin nor plugin backend for %s found\n", module_name));
840                 SAFE_FREE(module_name);
841                 return NT_STATUS_INVALID_PARAMETER;
842         }
843
844         DEBUG(5,("Found pdb backend %s\n", module_name));
845         nt_status = entry->init(context, methods, module_location);
846         if (NT_STATUS_IS_OK(nt_status)) {
847                 DEBUG(5,("pdb backend %s has a valid init\n", selected));
848         } else {
849                 DEBUG(0,("pdb backend %s did not correctly init (error was %s)\n", selected, nt_errstr(nt_status)));
850         }
851         SAFE_FREE(module_name);
852         return nt_status;
853 }
854
855 /******************************************************************
856   Make a pdb_context from scratch.
857  *******************************************************************/
858
859 static NTSTATUS make_pdb_context(struct pdb_context **context) 
860 {
861         TALLOC_CTX *mem_ctx;
862
863         mem_ctx = talloc_init("pdb_context internal allocation context");
864
865         if (!mem_ctx) {
866                 DEBUG(0, ("make_pdb_context: talloc init failed!\n"));
867                 return NT_STATUS_NO_MEMORY;
868         }               
869
870         *context = TALLOC_P(mem_ctx, struct pdb_context);
871         if (!*context) {
872                 DEBUG(0, ("make_pdb_context: talloc failed!\n"));
873                 return NT_STATUS_NO_MEMORY;
874         }
875
876         ZERO_STRUCTP(*context);
877
878         (*context)->mem_ctx = mem_ctx;
879
880         (*context)->pdb_setsampwent = context_setsampwent;
881         (*context)->pdb_endsampwent = context_endsampwent;
882         (*context)->pdb_getsampwent = context_getsampwent;
883         (*context)->pdb_getsampwnam = context_getsampwnam;
884         (*context)->pdb_getsampwsid = context_getsampwsid;
885         (*context)->pdb_add_sam_account = context_add_sam_account;
886         (*context)->pdb_update_sam_account = context_update_sam_account;
887         (*context)->pdb_delete_sam_account = context_delete_sam_account;
888         (*context)->pdb_rename_sam_account = context_rename_sam_account;
889         (*context)->pdb_update_login_attempts = context_update_login_attempts;
890         (*context)->pdb_getgrsid = context_getgrsid;
891         (*context)->pdb_getgrgid = context_getgrgid;
892         (*context)->pdb_getgrnam = context_getgrnam;
893         (*context)->pdb_add_group_mapping_entry = context_add_group_mapping_entry;
894         (*context)->pdb_update_group_mapping_entry = context_update_group_mapping_entry;
895         (*context)->pdb_delete_group_mapping_entry = context_delete_group_mapping_entry;
896         (*context)->pdb_enum_group_mapping = context_enum_group_mapping;
897         (*context)->pdb_enum_group_members = context_enum_group_members;
898         (*context)->pdb_enum_group_memberships = context_enum_group_memberships;
899
900         (*context)->pdb_find_alias = context_find_alias;
901         (*context)->pdb_create_alias = context_create_alias;
902         (*context)->pdb_delete_alias = context_delete_alias;
903         (*context)->pdb_get_aliasinfo = context_get_aliasinfo;
904         (*context)->pdb_set_aliasinfo = context_set_aliasinfo;
905         (*context)->pdb_add_aliasmem = context_add_aliasmem;
906         (*context)->pdb_del_aliasmem = context_del_aliasmem;
907         (*context)->pdb_enum_aliasmem = context_enum_aliasmem;
908         (*context)->pdb_enum_alias_memberships = context_enum_alias_memberships;
909         (*context)->pdb_lookup_rids = context_lookup_rids;
910
911         (*context)->pdb_get_account_policy = context_get_account_policy;
912         (*context)->pdb_set_account_policy = context_set_account_policy;
913
914         (*context)->pdb_get_seq_num = context_get_seq_num;
915
916         (*context)->pdb_search_users = context_search_users;
917         (*context)->pdb_search_groups = context_search_groups;
918         (*context)->pdb_search_aliases = context_search_aliases;
919
920         (*context)->free_fn = free_pdb_context;
921
922         return NT_STATUS_OK;
923 }
924
925
926 /******************************************************************
927   Make a pdb_context, given an array of strings
928  *******************************************************************/
929
930 NTSTATUS make_pdb_context_list(struct pdb_context **context, const char **selected) 
931 {
932         int i = 0;
933         struct pdb_methods *curmethods, *tmpmethods;
934         NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
935         BOOL have_guest = False;
936
937         if (!NT_STATUS_IS_OK(nt_status = make_pdb_context(context))) {
938                 return nt_status;
939         }
940
941         if (!selected) {
942                 DEBUG(0, ("ERROR: empty passdb backend list!\n"));
943                 return nt_status;
944         }
945
946         while (selected[i]){
947                 if (strcmp(selected[i], "guest") == 0) {
948                         have_guest = True;
949                 }
950                 /* Try to initialise pdb */
951                 DEBUG(5,("Trying to load: %s\n", selected[i]));
952                 if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods_name(&curmethods, *context, selected[i]))) {
953                         DEBUG(1, ("Loading %s failed!\n", selected[i]));
954                         free_pdb_context(context);
955                         return nt_status;
956                 }
957                 curmethods->parent = *context;
958                 DLIST_ADD_END((*context)->pdb_methods, curmethods, tmpmethods);
959                 i++;
960         }
961
962         if (have_guest)
963                 return NT_STATUS_OK;
964
965         if ( (lp_guestaccount() == NULL) ||
966              (*lp_guestaccount() == '\0') ) {
967                 /* We explicitly don't want guest access. No idea what
968                    else that breaks, but be it that way. */
969                 return NT_STATUS_OK;
970         }
971
972         if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods_name(&curmethods,
973                                                                *context,
974                                                                "guest"))) {
975                 DEBUG(1, ("Loading guest module failed!\n"));
976                 free_pdb_context(context);
977                 return nt_status;
978         }
979
980         curmethods->parent = *context;
981         DLIST_ADD_END((*context)->pdb_methods, curmethods, tmpmethods);
982         
983         return NT_STATUS_OK;
984 }
985
986 /******************************************************************
987   Make a pdb_context, given a text string.
988  *******************************************************************/
989
990 NTSTATUS make_pdb_context_string(struct pdb_context **context, const char *selected) 
991 {
992         NTSTATUS ret;
993         char **newsel = str_list_make(selected, NULL);
994         ret = make_pdb_context_list(context, (const char **)newsel);
995         str_list_free(&newsel);
996         return ret;
997 }
998
999 /******************************************************************
1000  Return an already initialised pdb_context, to facilitate backward 
1001  compatibility (see functions below).
1002 *******************************************************************/
1003
1004 static struct pdb_context *pdb_get_static_context(BOOL reload) 
1005 {
1006         static struct pdb_context *pdb_context = NULL;
1007
1008         if ((pdb_context) && (reload)) {
1009                 pdb_context->free_fn(&pdb_context);
1010                 if (!NT_STATUS_IS_OK(make_pdb_context_list(&pdb_context, lp_passdb_backend()))) {
1011                         return NULL;
1012                 }
1013         }
1014
1015         if (!pdb_context) {
1016                 if (!NT_STATUS_IS_OK(make_pdb_context_list(&pdb_context, lp_passdb_backend()))) {
1017                         return NULL;
1018                 }
1019         }
1020
1021         return pdb_context;
1022 }
1023
1024 /******************************************************************
1025  Backward compatibility functions for the original passdb interface
1026 *******************************************************************/
1027
1028 BOOL pdb_setsampwent(BOOL update, uint16 acb_mask) 
1029 {
1030         struct pdb_context *pdb_context = pdb_get_static_context(False);
1031
1032         if (!pdb_context) {
1033                 return False;
1034         }
1035
1036         return NT_STATUS_IS_OK(pdb_context->pdb_setsampwent(pdb_context, update, acb_mask));
1037 }
1038
1039 void pdb_endsampwent(void) 
1040 {
1041         struct pdb_context *pdb_context = pdb_get_static_context(False);
1042
1043         if (!pdb_context) {
1044                 return;
1045         }
1046
1047         pdb_context->pdb_endsampwent(pdb_context);
1048 }
1049
1050 BOOL pdb_getsampwent(SAM_ACCOUNT *user) 
1051 {
1052         struct pdb_context *pdb_context = pdb_get_static_context(False);
1053
1054         if (!pdb_context) {
1055                 return False;
1056         }
1057
1058         return NT_STATUS_IS_OK(pdb_context->pdb_getsampwent(pdb_context, user));
1059 }
1060
1061 static SAM_ACCOUNT *sam_account_cache = NULL;
1062
1063 BOOL pdb_getsampwnam(SAM_ACCOUNT *sam_acct, const char *username) 
1064 {
1065         struct pdb_context *pdb_context = pdb_get_static_context(False);
1066
1067         if (!pdb_context) {
1068                 return False;
1069         }
1070
1071         if (!NT_STATUS_IS_OK(pdb_context->pdb_getsampwnam(pdb_context,
1072                                                           sam_acct, username)))
1073                 return False;
1074
1075         if (sam_account_cache != NULL) {
1076                 pdb_free_sam(&sam_account_cache);
1077                 sam_account_cache = NULL;
1078         }
1079
1080         pdb_copy_sam_account(sam_acct, &sam_account_cache);
1081         return True;
1082 }
1083
1084 BOOL pdb_getsampwsid(SAM_ACCOUNT *sam_acct, const DOM_SID *sid) 
1085 {
1086         struct pdb_context *pdb_context = pdb_get_static_context(False);
1087
1088         if (!pdb_context) {
1089                 return False;
1090         }
1091
1092         if ((sam_account_cache != NULL) &&
1093             (sid_equal(sid, pdb_get_user_sid(sam_account_cache))))
1094                 return pdb_copy_sam_account(sam_account_cache, &sam_acct);
1095
1096         return NT_STATUS_IS_OK(pdb_context->pdb_getsampwsid(pdb_context, sam_acct, sid));
1097 }
1098
1099 BOOL pdb_add_sam_account(SAM_ACCOUNT *sam_acct) 
1100 {
1101         struct pdb_context *pdb_context = pdb_get_static_context(False);
1102
1103         if (!pdb_context) {
1104                 return False;
1105         }
1106         
1107         return NT_STATUS_IS_OK(pdb_context->pdb_add_sam_account(pdb_context, sam_acct));
1108 }
1109
1110 BOOL pdb_update_sam_account(SAM_ACCOUNT *sam_acct) 
1111 {
1112         struct pdb_context *pdb_context = pdb_get_static_context(False);
1113
1114         if (!pdb_context) {
1115                 return False;
1116         }
1117
1118         if (sam_account_cache != NULL) {
1119                 pdb_free_sam(&sam_account_cache);
1120                 sam_account_cache = NULL;
1121         }
1122
1123         return NT_STATUS_IS_OK(pdb_context->pdb_update_sam_account(pdb_context, sam_acct));
1124 }
1125
1126 BOOL pdb_delete_sam_account(SAM_ACCOUNT *sam_acct) 
1127 {
1128         struct pdb_context *pdb_context = pdb_get_static_context(False);
1129
1130         if (!pdb_context) {
1131                 return False;
1132         }
1133
1134         if (sam_account_cache != NULL) {
1135                 pdb_free_sam(&sam_account_cache);
1136                 sam_account_cache = NULL;
1137         }
1138
1139         return NT_STATUS_IS_OK(pdb_context->pdb_delete_sam_account(pdb_context, sam_acct));
1140 }
1141
1142 NTSTATUS pdb_rename_sam_account(SAM_ACCOUNT *oldname, const char *newname)
1143 {
1144         struct pdb_context *pdb_context = pdb_get_static_context(False);
1145
1146         if (!pdb_context) {
1147                 return NT_STATUS_NOT_IMPLEMENTED;
1148         }
1149
1150         if (sam_account_cache != NULL) {
1151                 pdb_free_sam(&sam_account_cache);
1152                 sam_account_cache = NULL;
1153         }
1154
1155         return pdb_context->pdb_rename_sam_account(pdb_context, oldname, newname);
1156 }
1157
1158 NTSTATUS pdb_update_login_attempts(SAM_ACCOUNT *sam_acct, BOOL success)
1159 {
1160         struct pdb_context *pdb_context = pdb_get_static_context(False);
1161
1162         if (!pdb_context) {
1163                 return NT_STATUS_NOT_IMPLEMENTED;
1164         }
1165
1166         return pdb_context->pdb_update_login_attempts(pdb_context, sam_acct, success);
1167 }
1168
1169 BOOL pdb_getgrsid(GROUP_MAP *map, DOM_SID sid)
1170 {
1171         struct pdb_context *pdb_context = pdb_get_static_context(False);
1172
1173         if (!pdb_context) {
1174                 return False;
1175         }
1176
1177         return NT_STATUS_IS_OK(pdb_context->
1178                                pdb_getgrsid(pdb_context, map, sid));
1179 }
1180
1181 BOOL pdb_getgrgid(GROUP_MAP *map, gid_t gid)
1182 {
1183         struct pdb_context *pdb_context = pdb_get_static_context(False);
1184
1185         if (!pdb_context) {
1186                 return False;
1187         }
1188
1189         return NT_STATUS_IS_OK(pdb_context->
1190                                pdb_getgrgid(pdb_context, map, gid));
1191 }
1192
1193 BOOL pdb_getgrnam(GROUP_MAP *map, const char *name)
1194 {
1195         struct pdb_context *pdb_context = pdb_get_static_context(False);
1196
1197         if (!pdb_context) {
1198                 return False;
1199         }
1200
1201         return NT_STATUS_IS_OK(pdb_context->
1202                                pdb_getgrnam(pdb_context, map, name));
1203 }
1204
1205 BOOL pdb_add_group_mapping_entry(GROUP_MAP *map)
1206 {
1207         struct pdb_context *pdb_context = pdb_get_static_context(False);
1208
1209         if (!pdb_context) {
1210                 return False;
1211         }
1212
1213         return NT_STATUS_IS_OK(pdb_context->
1214                                pdb_add_group_mapping_entry(pdb_context, map));
1215 }
1216
1217 BOOL pdb_update_group_mapping_entry(GROUP_MAP *map)
1218 {
1219         struct pdb_context *pdb_context = pdb_get_static_context(False);
1220
1221         if (!pdb_context) {
1222                 return False;
1223         }
1224
1225         return NT_STATUS_IS_OK(pdb_context->
1226                                pdb_update_group_mapping_entry(pdb_context, map));
1227 }
1228
1229 BOOL pdb_delete_group_mapping_entry(DOM_SID sid)
1230 {
1231         struct pdb_context *pdb_context = pdb_get_static_context(False);
1232
1233         if (!pdb_context) {
1234                 return False;
1235         }
1236
1237         return NT_STATUS_IS_OK(pdb_context->
1238                                pdb_delete_group_mapping_entry(pdb_context, sid));
1239 }
1240
1241 BOOL pdb_enum_group_mapping(enum SID_NAME_USE sid_name_use, GROUP_MAP **rmap,
1242                             int *num_entries, BOOL unix_only)
1243 {
1244         struct pdb_context *pdb_context = pdb_get_static_context(False);
1245
1246         if (!pdb_context) {
1247                 return False;
1248         }
1249
1250         return NT_STATUS_IS_OK(pdb_context->
1251                                pdb_enum_group_mapping(pdb_context, sid_name_use,
1252                                                       rmap, num_entries, unix_only));
1253 }
1254
1255 NTSTATUS pdb_enum_group_members(TALLOC_CTX *mem_ctx,
1256                                 const DOM_SID *sid,
1257                                 uint32 **member_rids,
1258                                 int *num_members)
1259 {
1260         struct pdb_context *pdb_context = pdb_get_static_context(False);
1261
1262         if (!pdb_context) {
1263                 return NT_STATUS_UNSUCCESSFUL;
1264         }
1265
1266         return pdb_context->pdb_enum_group_members(pdb_context, mem_ctx, sid, 
1267                                                    member_rids, num_members);
1268 }
1269
1270 NTSTATUS pdb_enum_group_memberships(const char *username, gid_t primary_gid,
1271                                     DOM_SID **sids, gid_t **gids,
1272                                     int *num_groups)
1273 {
1274         struct pdb_context *pdb_context = pdb_get_static_context(False);
1275
1276         if (!pdb_context) {
1277                 return NT_STATUS_UNSUCCESSFUL;
1278         }
1279
1280         return pdb_context->pdb_enum_group_memberships(pdb_context, username,
1281                                                        primary_gid, sids, gids,
1282                                                        num_groups);
1283 }
1284
1285 BOOL pdb_find_alias(const char *name, DOM_SID *sid)
1286 {
1287         struct pdb_context *pdb_context = pdb_get_static_context(False);
1288
1289         if (!pdb_context) {
1290                 return False;
1291         }
1292
1293         return NT_STATUS_IS_OK(pdb_context->pdb_find_alias(pdb_context,
1294                                                              name, sid));
1295 }
1296
1297 NTSTATUS pdb_create_alias(const char *name, uint32 *rid)
1298 {
1299         struct pdb_context *pdb_context = pdb_get_static_context(False);
1300
1301         if (!pdb_context) {
1302                 return NT_STATUS_NOT_IMPLEMENTED;
1303         }
1304
1305         return pdb_context->pdb_create_alias(pdb_context, name, rid);
1306 }
1307
1308 BOOL pdb_delete_alias(const DOM_SID *sid)
1309 {
1310         struct pdb_context *pdb_context = pdb_get_static_context(False);
1311
1312         if (!pdb_context) {
1313                 return False;
1314         }
1315
1316         return NT_STATUS_IS_OK(pdb_context->pdb_delete_alias(pdb_context,
1317                                                              sid));
1318                                                             
1319 }
1320
1321 BOOL pdb_get_aliasinfo(const DOM_SID *sid, struct acct_info *info)
1322 {
1323         struct pdb_context *pdb_context = pdb_get_static_context(False);
1324
1325         if (!pdb_context) {
1326                 return False;
1327         }
1328
1329         return NT_STATUS_IS_OK(pdb_context->pdb_get_aliasinfo(pdb_context, sid,
1330                                                               info));
1331 }
1332
1333 BOOL pdb_set_aliasinfo(const DOM_SID *sid, struct acct_info *info)
1334 {
1335         struct pdb_context *pdb_context = pdb_get_static_context(False);
1336
1337         if (!pdb_context) {
1338                 return False;
1339         }
1340
1341         return NT_STATUS_IS_OK(pdb_context->pdb_set_aliasinfo(pdb_context, sid,
1342                                                               info));
1343 }
1344
1345 BOOL pdb_add_aliasmem(const DOM_SID *alias, const DOM_SID *member)
1346 {
1347         struct pdb_context *pdb_context = pdb_get_static_context(False);
1348
1349         if (!pdb_context) {
1350                 return False;
1351         }
1352
1353         return NT_STATUS_IS_OK(pdb_context->
1354                                pdb_add_aliasmem(pdb_context, alias, member));
1355 }
1356
1357 BOOL pdb_del_aliasmem(const DOM_SID *alias, const DOM_SID *member)
1358 {
1359         struct pdb_context *pdb_context = pdb_get_static_context(False);
1360
1361         if (!pdb_context) {
1362                 return False;
1363         }
1364
1365         return NT_STATUS_IS_OK(pdb_context->
1366                                pdb_del_aliasmem(pdb_context, alias, member));
1367 }
1368
1369 BOOL pdb_enum_aliasmem(const DOM_SID *alias,
1370                        DOM_SID **members, int *num_members)
1371 {
1372         struct pdb_context *pdb_context = pdb_get_static_context(False);
1373
1374         if (!pdb_context) {
1375                 return False;
1376         }
1377
1378         return NT_STATUS_IS_OK(pdb_context->
1379                                pdb_enum_aliasmem(pdb_context, alias,
1380                                                  members, num_members));
1381 }
1382
1383 BOOL pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid,
1384                                 const DOM_SID *members, int num_members,
1385                                 uint32 **alias_rids, int *num_alias_rids)
1386 {
1387         struct pdb_context *pdb_context = pdb_get_static_context(False);
1388
1389         if (!pdb_context) {
1390                 return False;
1391         }
1392
1393         return NT_STATUS_IS_OK(pdb_context->
1394                                pdb_enum_alias_memberships(pdb_context, mem_ctx,
1395                                                           domain_sid,
1396                                                           members, num_members,
1397                                                           alias_rids,
1398                                                           num_alias_rids));
1399 }
1400
1401 NTSTATUS pdb_lookup_rids(TALLOC_CTX *mem_ctx,
1402                          const DOM_SID *domain_sid,
1403                          int num_rids,
1404                          uint32 *rids,
1405                          const char ***names,
1406                          uint32 **attrs)
1407 {
1408         struct pdb_context *pdb_context = pdb_get_static_context(False);
1409
1410         if (!pdb_context) {
1411                 return NT_STATUS_NOT_IMPLEMENTED;
1412         }
1413
1414         return pdb_context->pdb_lookup_rids(pdb_context, mem_ctx, domain_sid,
1415                                             num_rids, rids, names, attrs);
1416 }
1417
1418 BOOL pdb_get_account_policy(int policy_index, uint32 *value)
1419 {
1420         struct pdb_context *pdb_context = pdb_get_static_context(False);
1421
1422         if (!pdb_context) {
1423                 return False;
1424         }
1425
1426         return NT_STATUS_IS_OK(pdb_context->
1427                                pdb_get_account_policy(pdb_context, policy_index, value));
1428 }
1429
1430 BOOL pdb_set_account_policy(int policy_index, uint32 value)
1431 {
1432         struct pdb_context *pdb_context = pdb_get_static_context(False);
1433
1434         if (!pdb_context) {
1435                 return False;
1436         }
1437
1438         return NT_STATUS_IS_OK(pdb_context->
1439                                pdb_set_account_policy(pdb_context, policy_index, value));
1440 }
1441
1442 BOOL pdb_get_seq_num(time_t *seq_num)
1443 {
1444         struct pdb_context *pdb_context = pdb_get_static_context(False);
1445
1446         if (!pdb_context) {
1447                 return False;
1448         }
1449
1450         return NT_STATUS_IS_OK(pdb_context->
1451                                pdb_get_seq_num(pdb_context, seq_num));
1452 }
1453 /***************************************************************
1454   Initialize the static context (at smbd startup etc). 
1455
1456   If uninitialised, context will auto-init on first use.
1457  ***************************************************************/
1458
1459 BOOL initialize_password_db(BOOL reload)
1460 {       
1461         return (pdb_get_static_context(reload) != NULL);
1462 }
1463
1464
1465 /***************************************************************************
1466   Default implementations of some functions.
1467  ****************************************************************************/
1468
1469 static NTSTATUS pdb_default_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname)
1470 {
1471         return NT_STATUS_NO_SUCH_USER;
1472 }
1473
1474 static NTSTATUS pdb_default_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid)
1475 {
1476         return NT_STATUS_NO_SUCH_USER;
1477 }
1478
1479 static NTSTATUS pdb_default_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd)
1480 {
1481         DEBUG(0,("this backend (%s) should not be listed as the first passdb backend! You can't add users to it.\n", methods->name));
1482         return NT_STATUS_NOT_IMPLEMENTED;
1483 }
1484
1485 static NTSTATUS pdb_default_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd)
1486 {
1487         return NT_STATUS_NOT_IMPLEMENTED;
1488 }
1489
1490 static NTSTATUS pdb_default_delete_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *pwd)
1491 {
1492         return NT_STATUS_NOT_IMPLEMENTED;
1493 }
1494
1495 static NTSTATUS pdb_default_rename_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *pwd, const char *newname)
1496 {
1497         return NT_STATUS_NOT_IMPLEMENTED;
1498 }
1499
1500 static NTSTATUS pdb_default_update_login_attempts (struct pdb_methods *methods, SAM_ACCOUNT *newpwd, BOOL success)
1501 {
1502         return NT_STATUS_OK;
1503 }
1504
1505 static NTSTATUS pdb_default_setsampwent(struct pdb_methods *methods, BOOL update, uint16 acb_mask)
1506 {
1507         return NT_STATUS_NOT_IMPLEMENTED;
1508 }
1509
1510 static NTSTATUS pdb_default_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user)
1511 {
1512         return NT_STATUS_NOT_IMPLEMENTED;
1513 }
1514
1515 static void pdb_default_endsampwent(struct pdb_methods *methods)
1516 {
1517         return; /* NT_STATUS_NOT_IMPLEMENTED; */
1518 }
1519
1520 static NTSTATUS pdb_default_get_account_policy(struct pdb_methods *methods, int policy_index, uint32 *value)
1521 {
1522         return account_policy_get(policy_index, value) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1523 }
1524
1525 static NTSTATUS pdb_default_set_account_policy(struct pdb_methods *methods, int policy_index, uint32 value)
1526 {
1527         return account_policy_set(policy_index, value) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
1528 }
1529
1530 static NTSTATUS pdb_default_get_seq_num(struct pdb_methods *methods, time_t *seq_num)
1531 {
1532         *seq_num = time(NULL);
1533         return NT_STATUS_OK;
1534 }
1535
1536 static void add_uid_to_array_unique(TALLOC_CTX *mem_ctx,
1537                                     uid_t uid, uid_t **uids, int *num)
1538 {
1539         int i;
1540
1541         for (i=0; i<*num; i++) {
1542                 if ((*uids)[i] == uid)
1543                         return;
1544         }
1545         
1546         *uids = TALLOC_REALLOC_ARRAY(mem_ctx, *uids, uid_t, *num+1);
1547
1548         if (*uids == NULL)
1549                 return;
1550
1551         (*uids)[*num] = uid;
1552         *num += 1;
1553 }
1554
1555 static BOOL get_memberuids(TALLOC_CTX *mem_ctx, gid_t gid, uid_t **uids,
1556                            int *num)
1557 {
1558         struct group *grp;
1559         char **gr;
1560         struct sys_pwent *userlist, *user;
1561  
1562         *uids = NULL;
1563         *num = 0;
1564
1565         /* We only look at our own sam, so don't care about imported stuff */
1566
1567         winbind_off();
1568
1569         if ((grp = getgrgid(gid)) == NULL) {
1570                 winbind_on();
1571                 return False;
1572         }
1573
1574         /* Primary group members */
1575
1576         userlist = getpwent_list();
1577
1578         for (user = userlist; user != NULL; user = user->next) {
1579                 if (user->pw_gid != gid)
1580                         continue;
1581                 add_uid_to_array_unique(mem_ctx, user->pw_uid, uids, num);
1582         }
1583
1584         pwent_free(userlist);
1585
1586         /* Secondary group members */
1587
1588         for (gr = grp->gr_mem; (*gr != NULL) && ((*gr)[0] != '\0'); gr += 1) {
1589                 struct passwd *pw = getpwnam(*gr);
1590
1591                 if (pw == NULL)
1592                         continue;
1593                 add_uid_to_array_unique(mem_ctx, pw->pw_uid, uids, num);
1594         }
1595
1596         winbind_on();
1597
1598         return True;
1599 }
1600
1601 NTSTATUS pdb_default_enum_group_members(struct pdb_methods *methods,
1602                                         TALLOC_CTX *mem_ctx,
1603                                         const DOM_SID *group,
1604                                         uint32 **member_rids,
1605                                         int *num_members)
1606 {
1607         gid_t gid;
1608         uid_t *uids;
1609         int i, num_uids;
1610
1611         *member_rids = NULL;
1612         *num_members = 0;
1613
1614         if (!NT_STATUS_IS_OK(sid_to_gid(group, &gid)))
1615                 return NT_STATUS_NO_SUCH_GROUP;
1616
1617         if(!get_memberuids(mem_ctx, gid, &uids, &num_uids))
1618                 return NT_STATUS_NO_SUCH_GROUP;
1619
1620         if (num_uids == 0)
1621                 return NT_STATUS_OK;
1622
1623         *member_rids = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_uids);
1624
1625         for (i=0; i<num_uids; i++) {
1626                 DOM_SID sid;
1627
1628                 if (!NT_STATUS_IS_OK(uid_to_sid(&sid, uids[i]))) {
1629                         DEBUG(1, ("Could not map member uid to SID\n"));
1630                         continue;
1631                 }
1632
1633                 if (!sid_check_is_in_our_domain(&sid)) {
1634                         DEBUG(1, ("Inconsistent SAM -- group member uid not "
1635                                   "in our domain\n"));
1636                         continue;
1637                 }
1638
1639                 sid_peek_rid(&sid, &(*member_rids)[*num_members]);
1640                 *num_members += 1;
1641         }
1642
1643         return NT_STATUS_OK;
1644 }
1645
1646 NTSTATUS pdb_default_lookup_rids(struct pdb_methods *methods,
1647                                  TALLOC_CTX *mem_ctx,
1648                                  const DOM_SID *domain_sid,
1649                                  int num_rids,
1650                                  uint32 *rids,
1651                                  const char ***names,
1652                                  uint32 **attrs)
1653 {
1654         int i;
1655         NTSTATUS result;
1656         BOOL have_mapped = False;
1657         BOOL have_unmapped = False;
1658
1659         (*names) = TALLOC_ZERO_ARRAY(mem_ctx, const char *, num_rids);
1660         (*attrs) = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_rids);
1661
1662         if ((num_rids != 0) && (((*names) == NULL) || ((*attrs) == NULL)))
1663                 return NT_STATUS_NO_MEMORY;
1664
1665         if (!sid_equal(domain_sid, get_global_sam_sid())) {
1666                 /* TODO: Sooner or later we need to look up BUILTIN rids as
1667                  * well. -- vl */
1668                 goto done;
1669         }
1670
1671         for (i = 0; i < num_rids; i++) {
1672                 fstring tmpname;
1673                 fstring domname;
1674                 DOM_SID sid;
1675                 enum SID_NAME_USE type;
1676
1677                 (*attrs)[i] = SID_NAME_UNKNOWN;
1678
1679                 sid_copy(&sid, domain_sid);
1680                 sid_append_rid(&sid, rids[i]);
1681
1682                 if (lookup_sid(&sid, domname, tmpname, &type)) {
1683                         (*attrs)[i] = (uint32)type;
1684                         (*names)[i] = talloc_strdup(mem_ctx, tmpname);
1685                         if ((*names)[i] == NULL)
1686                                 return NT_STATUS_NO_MEMORY;
1687                         DEBUG(5,("lookup_rids: %s:%d\n", (*names)[i],
1688                                  (*attrs)[i]));
1689                         have_mapped = True;
1690                 } else {
1691                         have_unmapped = True;
1692                 }
1693         }
1694
1695  done:
1696
1697         result = NT_STATUS_NONE_MAPPED;
1698
1699         if (have_mapped)
1700                 result = have_unmapped ? STATUS_SOME_UNMAPPED : NT_STATUS_OK;
1701
1702         return result;
1703 }
1704
1705 static struct pdb_search *pdb_search_init(enum pdb_search_type type)
1706 {
1707         TALLOC_CTX *mem_ctx;
1708         struct pdb_search *result;
1709
1710         mem_ctx = talloc_init("pdb_search");
1711         if (mem_ctx == NULL) {
1712                 DEBUG(0, ("talloc_init failed\n"));
1713                 return NULL;
1714         }
1715
1716         result = TALLOC_P(mem_ctx, struct pdb_search);
1717         if (result == NULL) {
1718                 DEBUG(0, ("talloc failed\n"));
1719                 return NULL;
1720         }
1721
1722         result->mem_ctx = mem_ctx;
1723         result->type = type;
1724         result->cache = NULL;
1725         result->num_entries = 0;
1726         result->cache_size = 0;
1727         result->search_ended = False;
1728
1729         /* Segfault appropriately if not initialized */
1730         result->next_entry = NULL;
1731         result->search_end = NULL;
1732
1733         return result;
1734 }
1735
1736 static void fill_displayentry(TALLOC_CTX *mem_ctx, uint32 rid,
1737                               uint16 acct_flags,
1738                               const char *account_name,
1739                               const char *fullname,
1740                               const char *description,
1741                               struct samr_displayentry *entry)
1742 {
1743         entry->rid = rid;
1744         entry->acct_flags = acct_flags;
1745
1746         if (account_name != NULL)
1747                 entry->account_name = talloc_strdup(mem_ctx, account_name);
1748         else
1749                 entry->account_name = "";
1750
1751         if (fullname != NULL)
1752                 entry->fullname = talloc_strdup(mem_ctx, fullname);
1753         else
1754                 entry->fullname = "";
1755
1756         if (description != NULL)
1757                 entry->description = talloc_strdup(mem_ctx, description);
1758         else
1759                 entry->description = "";
1760 }
1761
1762 static BOOL user_search_in_progress = False;
1763 struct user_search {
1764         uint16 acct_flags;
1765 };
1766
1767 static BOOL next_entry_users(struct pdb_search *s,
1768                              struct samr_displayentry *entry)
1769 {
1770         struct user_search *state = s->private_data;
1771         SAM_ACCOUNT *user = NULL;
1772         NTSTATUS status;
1773
1774  next:
1775         status = pdb_init_sam(&user);
1776         if (!NT_STATUS_IS_OK(status)) {
1777                 DEBUG(0, ("Could not pdb_init_sam\n"));
1778                 return False;
1779         }
1780
1781         if (!pdb_getsampwent(user)) {
1782                 pdb_free_sam(&user);
1783                 return False;
1784         }
1785
1786         if ((state->acct_flags != 0) &&
1787             ((pdb_get_acct_ctrl(user) & state->acct_flags) == 0)) {
1788                 pdb_free_sam(&user);
1789                 goto next;
1790         }
1791
1792         fill_displayentry(s->mem_ctx, pdb_get_user_rid(user),
1793                           pdb_get_acct_ctrl(user), pdb_get_username(user),
1794                           pdb_get_fullname(user), pdb_get_acct_desc(user),
1795                           entry);
1796
1797         pdb_free_sam(&user);
1798         return True;
1799 }
1800
1801 static void search_end_users(struct pdb_search *search)
1802 {
1803         pdb_endsampwent();
1804         user_search_in_progress = False;
1805 }
1806
1807 static BOOL pdb_default_search_users(struct pdb_methods *methods,
1808                                      struct pdb_search *search,
1809                                      uint16 acct_flags)
1810 {
1811         struct user_search *state;
1812
1813         if (user_search_in_progress) {
1814                 DEBUG(1, ("user search in progress\n"));
1815                 return False;
1816         }
1817
1818         if (!pdb_setsampwent(False, acct_flags)) {
1819                 DEBUG(5, ("Could not start search\n"));
1820                 return False;
1821         }
1822
1823         user_search_in_progress = True;
1824
1825         state = TALLOC_P(search->mem_ctx, struct user_search);
1826         if (state == NULL) {
1827                 DEBUG(0, ("talloc failed\n"));
1828                 return False;
1829         }
1830
1831         state->acct_flags = acct_flags;
1832
1833         search->private_data = state;
1834         search->next_entry = next_entry_users;
1835         search->search_end = search_end_users;
1836         return True;
1837 }
1838
1839 struct group_search {
1840         GROUP_MAP *groups;
1841         int num_groups, current_group;
1842 };
1843
1844 static BOOL next_entry_groups(struct pdb_search *s,
1845                               struct samr_displayentry *entry)
1846 {
1847         struct group_search *state = s->private_data;
1848         uint32 rid;
1849         GROUP_MAP *map = &state->groups[state->current_group];
1850
1851         if (state->current_group == state->num_groups)
1852                 return False;
1853
1854         sid_peek_rid(&map->sid, &rid);
1855
1856         fill_displayentry(s->mem_ctx, rid, 0, map->nt_name, NULL, map->comment,
1857                           entry);
1858
1859         state->current_group += 1;
1860         return True;
1861 }
1862
1863 static void search_end_groups(struct pdb_search *search)
1864 {
1865         struct group_search *state = search->private_data;
1866         SAFE_FREE(state->groups);
1867 }
1868
1869 static BOOL pdb_search_grouptype(struct pdb_search *search,
1870                                  enum SID_NAME_USE type)
1871 {
1872         struct group_search *state;
1873
1874         state = TALLOC_P(search->mem_ctx, struct group_search);
1875         if (state == NULL) {
1876                 DEBUG(0, ("talloc failed\n"));
1877                 return False;
1878         }
1879
1880         if (!pdb_enum_group_mapping(type, &state->groups, &state->num_groups,
1881                                     True)) {
1882                 DEBUG(0, ("Could not enum groups\n"));
1883                 return False;
1884         }
1885
1886         state->current_group = 0;
1887         search->private_data = state;
1888         search->next_entry = next_entry_groups;
1889         search->search_end = search_end_groups;
1890         return True;
1891 }
1892
1893 static BOOL pdb_default_search_groups(struct pdb_methods *methods,
1894                                       struct pdb_search *search)
1895 {
1896         return pdb_search_grouptype(search, SID_NAME_DOM_GRP);
1897 }
1898
1899 static BOOL pdb_default_search_aliases(struct pdb_methods *methods,
1900                                        struct pdb_search *search,
1901                                        const DOM_SID *sid)
1902 {
1903
1904         if (sid_equal(sid, get_global_sam_sid()))
1905                 return pdb_search_grouptype(search, SID_NAME_ALIAS);
1906
1907         if (sid_equal(sid, &global_sid_Builtin))
1908                 return pdb_search_grouptype(search, SID_NAME_WKN_GRP);
1909
1910         DEBUG(3, ("unknown domain sid: %s\n", sid_string_static(sid)));
1911         return False;
1912 }
1913
1914 static struct samr_displayentry *pdb_search_getentry(struct pdb_search *search,
1915                                                      uint32 idx)
1916 {
1917         if (idx < search->num_entries)
1918                 return &search->cache[idx];
1919
1920         if (search->search_ended)
1921                 return NULL;
1922
1923         while (idx >= search->num_entries) {
1924                 struct samr_displayentry entry;
1925
1926                 if (!search->next_entry(search, &entry)) {
1927                         search->search_end(search);
1928                         search->search_ended = True;
1929                         break;
1930                 }
1931
1932                 ADD_TO_LARGE_ARRAY(search->mem_ctx, struct samr_displayentry,
1933                                    entry, &search->cache, &search->num_entries,
1934                                    &search->cache_size);
1935         }
1936
1937         return (search->num_entries > idx) ? &search->cache[idx] : NULL;
1938 }
1939
1940 struct pdb_search *pdb_search_users(uint16 acct_flags)
1941 {
1942         struct pdb_context *pdb_context = pdb_get_static_context(False);
1943         struct pdb_search *result;
1944
1945         if (pdb_context == NULL) return NULL;
1946
1947         result = pdb_search_init(PDB_USER_SEARCH);
1948         if (result == NULL) return NULL;
1949
1950         if (!pdb_context->pdb_search_users(pdb_context, result, acct_flags)) {
1951                 talloc_destroy(result->mem_ctx);
1952                 return NULL;
1953         }
1954         return result;
1955 }
1956
1957 struct pdb_search *pdb_search_groups(void)
1958 {
1959         struct pdb_context *pdb_context = pdb_get_static_context(False);
1960         struct pdb_search *result;
1961
1962         if (pdb_context == NULL) return NULL;
1963
1964         result = pdb_search_init(PDB_GROUP_SEARCH);
1965         if (result == NULL) return NULL;
1966
1967         if (!pdb_context->pdb_search_groups(pdb_context, result)) {
1968                 talloc_destroy(result->mem_ctx);
1969                 return NULL;
1970         }
1971         return result;
1972 }
1973
1974 struct pdb_search *pdb_search_aliases(const DOM_SID *sid)
1975 {
1976         struct pdb_context *pdb_context = pdb_get_static_context(False);
1977         struct pdb_search *result;
1978
1979         if (pdb_context == NULL) return NULL;
1980
1981         result = pdb_search_init(PDB_ALIAS_SEARCH);
1982         if (result == NULL) return NULL;
1983
1984         if (!pdb_context->pdb_search_aliases(pdb_context, result, sid)) {
1985                 talloc_destroy(result->mem_ctx);
1986                 return NULL;
1987         }
1988         return result;
1989 }
1990
1991 uint32 pdb_search_entries(struct pdb_search *search,
1992                           uint32 start_idx, uint32 max_entries,
1993                           struct samr_displayentry **result)
1994 {
1995         struct samr_displayentry *end_entry;
1996         uint32 end_idx = start_idx+max_entries-1;
1997
1998         /* The first entry needs to be searched after the last. Otherwise the
1999          * first entry might have moved due to a realloc during the search for
2000          * the last entry. */
2001
2002         end_entry = pdb_search_getentry(search, end_idx);
2003         *result = pdb_search_getentry(search, start_idx);
2004
2005         if (end_entry != NULL)
2006                 return max_entries;
2007
2008         if (start_idx >= search->num_entries)
2009                 return 0;
2010
2011         return search->num_entries - start_idx;
2012 }
2013
2014 void pdb_search_destroy(struct pdb_search *search)
2015 {
2016         if (search == NULL)
2017                 return;
2018
2019         if (!search->search_ended)
2020                 search->search_end(search);
2021
2022         talloc_destroy(search->mem_ctx);
2023 }
2024
2025 NTSTATUS make_pdb_methods(TALLOC_CTX *mem_ctx, PDB_METHODS **methods) 
2026 {
2027         *methods = TALLOC_P(mem_ctx, struct pdb_methods);
2028
2029         if (!*methods) {
2030                 return NT_STATUS_NO_MEMORY;
2031         }
2032
2033         ZERO_STRUCTP(*methods);
2034
2035         (*methods)->setsampwent = pdb_default_setsampwent;
2036         (*methods)->endsampwent = pdb_default_endsampwent;
2037         (*methods)->getsampwent = pdb_default_getsampwent;
2038         (*methods)->getsampwnam = pdb_default_getsampwnam;
2039         (*methods)->getsampwsid = pdb_default_getsampwsid;
2040         (*methods)->add_sam_account = pdb_default_add_sam_account;
2041         (*methods)->update_sam_account = pdb_default_update_sam_account;
2042         (*methods)->delete_sam_account = pdb_default_delete_sam_account;
2043         (*methods)->rename_sam_account = pdb_default_rename_sam_account;
2044         (*methods)->update_login_attempts = pdb_default_update_login_attempts;
2045
2046         (*methods)->getgrsid = pdb_default_getgrsid;
2047         (*methods)->getgrgid = pdb_default_getgrgid;
2048         (*methods)->getgrnam = pdb_default_getgrnam;
2049         (*methods)->add_group_mapping_entry = pdb_default_add_group_mapping_entry;
2050         (*methods)->update_group_mapping_entry = pdb_default_update_group_mapping_entry;
2051         (*methods)->delete_group_mapping_entry = pdb_default_delete_group_mapping_entry;
2052         (*methods)->enum_group_mapping = pdb_default_enum_group_mapping;
2053         (*methods)->enum_group_members = pdb_default_enum_group_members;
2054         (*methods)->enum_group_memberships = pdb_default_enum_group_memberships;
2055         (*methods)->find_alias = pdb_default_find_alias;
2056         (*methods)->create_alias = pdb_default_create_alias;
2057         (*methods)->delete_alias = pdb_default_delete_alias;
2058         (*methods)->get_aliasinfo = pdb_default_get_aliasinfo;
2059         (*methods)->set_aliasinfo = pdb_default_set_aliasinfo;
2060         (*methods)->add_aliasmem = pdb_default_add_aliasmem;
2061         (*methods)->del_aliasmem = pdb_default_del_aliasmem;
2062         (*methods)->enum_aliasmem = pdb_default_enum_aliasmem;
2063         (*methods)->enum_alias_memberships = pdb_default_alias_memberships;
2064         (*methods)->lookup_rids = pdb_default_lookup_rids;
2065         (*methods)->get_account_policy = pdb_default_get_account_policy;
2066         (*methods)->set_account_policy = pdb_default_set_account_policy;
2067         (*methods)->get_seq_num = pdb_default_get_seq_num;
2068
2069         (*methods)->search_users = pdb_default_search_users;
2070         (*methods)->search_groups = pdb_default_search_groups;
2071         (*methods)->search_aliases = pdb_default_search_aliases;
2072
2073         return NT_STATUS_OK;
2074 }