r7454: couple of winbindd fixes
[bbaumbach/samba-autobuild/.git] / source3 / nsswitch / winbindd_user.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Winbind daemon - user related functions
5
6    Copyright (C) Tim Potter 2000
7    Copyright (C) Jeremy Allison 2001.
8    Copyright (C) Gerald (Jerry) Carter 2003.
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 #include "includes.h"
26 #include "winbindd.h"
27
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_WINBIND
30
31 extern userdom_struct current_user_info;
32
33 /* Fill a pwent structure with information we have obtained */
34
35 static BOOL winbindd_fill_pwent(char *dom_name, char *user_name, 
36                                 DOM_SID *user_sid, DOM_SID *group_sid,
37                                 char *full_name, struct winbindd_pw *pw)
38 {
39         fstring output_username;
40         char *homedir;
41         char *shell;
42         fstring sid_string;
43         
44         if (!pw || !dom_name || !user_name)
45                 return False;
46         
47         /* Resolve the uid number */
48
49         if (!NT_STATUS_IS_OK(idmap_sid_to_uid(user_sid, &pw->pw_uid, 0))) {
50                 DEBUG(1, ("error getting user id for sid %s\n", sid_to_string(sid_string, user_sid)));
51                 return False;
52         }
53         
54         /* Resolve the gid number */   
55
56         if (!NT_STATUS_IS_OK(idmap_sid_to_gid(group_sid, &pw->pw_gid, 0))) {
57                 DEBUG(1, ("error getting group id for sid %s\n", sid_to_string(sid_string, group_sid)));
58                 return False;
59         }
60
61         strlower_m(user_name);
62
63         /* Username */
64
65         fill_domain_username(output_username, dom_name, user_name); 
66
67         safe_strcpy(pw->pw_name, output_username, sizeof(pw->pw_name) - 1);
68         
69         /* Full name (gecos) */
70         
71         safe_strcpy(pw->pw_gecos, full_name, sizeof(pw->pw_gecos) - 1);
72
73         /* Home directory and shell - use template config parameters.  The
74            defaults are /tmp for the home directory and /bin/false for
75            shell. */
76         
77         /* The substitution of %U and %D in the 'template homedir' is done
78            by alloc_sub_specified() below. */
79
80         fstrcpy(current_user_info.domain, dom_name);
81
82         homedir = alloc_sub_specified(lp_template_homedir(), user_name, dom_name, pw->pw_uid, pw->pw_gid);
83
84         if (!homedir)
85                 return False;
86         
87         safe_strcpy(pw->pw_dir, homedir, sizeof(pw->pw_dir) - 1);
88         
89         SAFE_FREE(homedir);
90         
91         shell = alloc_sub_specified(lp_template_shell(), user_name, dom_name, pw->pw_uid, pw->pw_gid);
92
93         if (!shell)
94                 return False;
95
96         safe_strcpy(pw->pw_shell, shell, 
97                     sizeof(pw->pw_shell) - 1);
98         
99         SAFE_FREE(shell);
100
101         /* Password - set to "x" as we can't generate anything useful here.
102            Authentication can be done using the pam_winbind module. */
103
104         safe_strcpy(pw->pw_passwd, "x", sizeof(pw->pw_passwd) - 1);
105
106         return True;
107 }
108
109 /* Wrapper for domain->methods->query_user, only on the parent->child pipe */
110
111 enum winbindd_result winbindd_dual_userinfo(struct winbindd_domain *domain,
112                                             struct winbindd_cli_state *state)
113 {
114         DOM_SID sid;
115         WINBIND_USERINFO user_info;
116         NTSTATUS status;
117
118         /* Ensure null termination */
119         state->request.data.sid[sizeof(state->request.data.sid)-1]='\0';
120
121         DEBUG(3, ("[%5lu]: lookupsid %s\n", (unsigned long)state->pid, 
122                   state->request.data.sid));
123
124         if (!string_to_sid(&sid, state->request.data.sid)) {
125                 DEBUG(5, ("%s not a SID\n", state->request.data.sid));
126                 return WINBINDD_ERROR;
127         }
128
129         status = domain->methods->query_user(domain, state->mem_ctx,
130                                              &sid, &user_info);
131         if (!NT_STATUS_IS_OK(status)) {
132                 DEBUG(1, ("error getting user info for sid %s\n",
133                           sid_string_static(&sid)));
134                 return WINBINDD_ERROR;
135         }
136
137         fstrcpy(state->response.data.user_info.acct_name, user_info.acct_name);
138         fstrcpy(state->response.data.user_info.full_name, user_info.full_name);
139         if (!sid_peek_check_rid(&domain->sid, &user_info.group_sid,
140                                 &state->response.data.user_info.group_rid)) {
141                 DEBUG(1, ("Could not extract group rid out of %s\n",
142                           sid_string_static(&sid)));
143                 return WINBINDD_ERROR;
144         }
145
146         return WINBINDD_OK;
147 }
148
149 struct getpwsid_state {
150         struct winbindd_cli_state *state;
151         struct winbindd_domain *domain;
152         char *username;
153         char *fullname;
154         DOM_SID user_sid;
155         uid_t uid;
156         DOM_SID group_sid;
157         gid_t gid;
158 };
159
160 static void getpwsid_queryuser_recv(void *private, BOOL success,
161                                     const char *acct_name,
162                                     const char *full_name, uint32 group_rid);
163 static void getpwsid_sid2uid_recv(void *private, BOOL success, uid_t uid);
164 static void getpwsid_sid2gid_recv(void *private, BOOL success, gid_t gid);
165
166 static void winbindd_getpwsid(struct winbindd_cli_state *state,
167                               const DOM_SID *sid)
168 {
169         struct getpwsid_state *s;
170
171         s = TALLOC_P(state->mem_ctx, struct getpwsid_state);
172         if (s == NULL) {
173                 DEBUG(0, ("talloc failed\n"));
174                 goto error;
175         }
176
177         s->state = state;
178         s->domain = find_domain_from_sid_noinit(sid);
179         if (s->domain == NULL) {
180                 DEBUG(3, ("Could not find domain for sid %s\n",
181                           sid_string_static(sid)));
182                 goto error;
183         }
184
185         sid_copy(&s->user_sid, sid);
186
187         query_user_async(s->state->mem_ctx, s->domain, sid,
188                          getpwsid_queryuser_recv, s);
189         return;
190
191  error:
192         s->state->response.result = WINBINDD_ERROR;
193         request_finished(state);
194 }
195         
196 static void getpwsid_queryuser_recv(void *private, BOOL success,
197                                     const char *acct_name,
198                                     const char *full_name, uint32 group_rid)
199 {
200         struct getpwsid_state *s =
201                 talloc_get_type_abort(private, struct getpwsid_state);
202
203         if (!success) {
204                 DEBUG(5, ("Could not query user %s\\%s\n", s->domain->name,
205                           s->username));
206                 s->state->response.result = WINBINDD_ERROR;
207                 request_finished(s->state);
208                 return;
209         }
210
211         s->username = talloc_strdup(s->state->mem_ctx, acct_name);
212         s->fullname = talloc_strdup(s->state->mem_ctx, full_name);
213         sid_copy(&s->group_sid, &s->domain->sid);
214         sid_append_rid(&s->group_sid, group_rid);
215
216         winbindd_sid2uid_async(s->state->mem_ctx, &s->user_sid,
217                                getpwsid_sid2uid_recv, s);
218 }
219
220 static void getpwsid_sid2uid_recv(void *private, BOOL success, uid_t uid)
221 {
222         struct getpwsid_state *s =
223                 talloc_get_type_abort(private, struct getpwsid_state);
224
225         if (!success) {
226                 DEBUG(5, ("Could not query user's %s\\%s uid\n",
227                           s->domain->name, s->username));
228                 s->state->response.result = WINBINDD_ERROR;
229                 request_finished(s->state);
230                 return;
231         }
232
233         s->uid = uid;
234         winbindd_sid2gid_async(s->state->mem_ctx, &s->group_sid,
235                                getpwsid_sid2gid_recv, s);
236 }
237
238 static void getpwsid_sid2gid_recv(void *private, BOOL success, gid_t gid)
239 {
240         struct getpwsid_state *s =
241                 talloc_get_type_abort(private, struct getpwsid_state);
242         struct winbindd_pw *pw;
243         fstring output_username;
244         char *homedir;
245         char *shell;
246
247         s->state->response.result = WINBINDD_ERROR;
248
249         if (!success) {
250                 DEBUG(5, ("Could not query user's %s\\%s\n gid",
251                           s->domain->name, s->username));
252                 goto done;
253         }
254
255         s->gid = gid;
256
257         pw = &s->state->response.data.pw;
258         pw->pw_uid = s->uid;
259         pw->pw_gid = s->gid;
260         fill_domain_username(output_username, s->domain->name, s->username); 
261         safe_strcpy(pw->pw_name, output_username, sizeof(pw->pw_name) - 1);
262         safe_strcpy(pw->pw_gecos, s->fullname, sizeof(pw->pw_gecos) - 1);
263
264         /* Home directory and shell - use template config parameters.  The
265            defaults are /tmp for the home directory and /bin/false for
266            shell. */
267         
268         /* The substitution of %U and %D in the 'template homedir' is done
269            by alloc_sub_specified() below. */
270
271         fstrcpy(current_user_info.domain, s->domain->name);
272
273         homedir = alloc_sub_specified(lp_template_homedir(), s->username,
274                                       s->domain->name, pw->pw_uid, pw->pw_gid);
275         if (homedir == NULL) {
276                 DEBUG(5, ("Could not compose homedir\n"));
277                 goto done;
278         }
279         safe_strcpy(pw->pw_dir, homedir, sizeof(pw->pw_dir) - 1);
280         SAFE_FREE(homedir);
281         
282         shell = alloc_sub_specified(lp_template_shell(), s->username,
283                                     s->domain->name, pw->pw_uid, pw->pw_gid);
284         if (shell == NULL) {
285                 DEBUG(5, ("Could not compose shell\n"));
286                 goto done;
287         }
288         safe_strcpy(pw->pw_shell, shell, sizeof(pw->pw_shell) - 1);
289         SAFE_FREE(shell);
290
291         /* Password - set to "x" as we can't generate anything useful here.
292            Authentication can be done using the pam_winbind module. */
293
294         safe_strcpy(pw->pw_passwd, "x", sizeof(pw->pw_passwd) - 1);
295
296         s->state->response.result = WINBINDD_OK;
297
298  done:
299         request_finished(s->state);
300 }
301
302 /* Return a password structure from a username.  */
303
304 static void getpwnam_name2sid_recv(void *private, BOOL success,
305                                    const DOM_SID *sid, enum SID_NAME_USE type);
306
307 enum winbindd_result winbindd_getpwnam(struct winbindd_cli_state *state)
308 {
309         struct winbindd_domain *domain;
310         fstring domname, username;
311
312         /* Ensure null termination */
313         state->request.data.username[sizeof(state->request.data.username)-1]='\0';
314
315         DEBUG(3, ("[%5lu]: getpwnam %s\n", (unsigned long)state->pid,
316                   state->request.data.username));
317
318         if (!parse_domain_user(state->request.data.username, domname,
319                                username)) {
320                 DEBUG(0, ("Could not parse domain user: %s\n",
321                           state->request.data.username));
322                 return WINBINDD_ERROR;
323         }
324         
325         /* Get info for the domain */
326
327         domain = find_domain_from_name(domname);
328
329         if (domain == NULL) {
330                 DEBUG(7, ("could not find domain entry for domain %s\n",
331                           domname));
332                 return WINBINDD_ERROR;
333         }
334
335         if ( strequal(domname, lp_workgroup()) && lp_winbind_trusted_domains_only() ) {
336                 DEBUG(7,("winbindd_getpwnam: My domain -- rejecting getpwnam() for %s\\%s.\n", 
337                         domname, username));
338                 return WINBINDD_ERROR;
339         }       
340
341         /* Get rid and name type from name.  The following costs 1 packet */
342
343         winbindd_lookupname_async(state->mem_ctx, domname, username,
344                                   getpwnam_name2sid_recv, state);
345         return WINBINDD_PENDING;
346 }
347
348 static void getpwnam_name2sid_recv(void *private, BOOL success,
349                                    const DOM_SID *sid, enum SID_NAME_USE type)
350 {
351         struct winbindd_cli_state *state = private;
352
353         if (!success) {
354                 DEBUG(5, ("Could not lookup name for user %s\n",
355                           state->request.data.username));
356                 state->response.result = WINBINDD_ERROR;
357                 request_finished(state);
358                 return;
359         }
360
361         if ((type != SID_NAME_USER) && (type != SID_NAME_COMPUTER)) {
362                 DEBUG(5, ("%s is not a user\n", state->request.data.username));
363                 state->response.result = WINBINDD_ERROR;
364                 request_finished(state);
365                 return;
366         }
367
368         winbindd_getpwsid(state, sid);
369 }
370
371 /* Return a password structure given a uid number */
372
373 enum winbindd_result winbindd_getpwuid(struct winbindd_cli_state *state)
374 {
375         DOM_SID user_sid;
376         NTSTATUS status;
377         
378         /* Bug out if the uid isn't in the winbind range */
379
380         if ((state->request.data.uid < server_state.uid_low ) ||
381             (state->request.data.uid > server_state.uid_high))
382                 return WINBINDD_ERROR;
383
384         DEBUG(3, ("[%5lu]: getpwuid %lu\n", (unsigned long)state->pid, 
385                   (unsigned long)state->request.data.uid));
386
387         status = idmap_uid_to_sid(&user_sid, state->request.data.uid,
388                                   ID_QUERY_ONLY | ID_CACHE_ONLY);
389
390         if (!NT_STATUS_IS_OK(status)) {
391                 DEBUG(5, ("Could not find SID for uid %lu\n",
392                           (unsigned long)state->request.data.uid));
393                 return WINBINDD_ERROR;
394         }
395
396         winbindd_getpwsid(state, &user_sid);
397         return WINBINDD_PENDING;
398 }
399
400 /*
401  * set/get/endpwent functions
402  */
403
404 /* Rewind file pointer for ntdom passwd database */
405
406 enum winbindd_result winbindd_setpwent(struct winbindd_cli_state *state)
407 {
408         struct winbindd_domain *domain;
409         
410         DEBUG(3, ("[%5lu]: setpwent\n", (unsigned long)state->pid));
411         
412         /* Check user has enabled this */
413         
414         if (!lp_winbind_enum_users())
415                 return WINBINDD_ERROR;
416
417         /* Free old static data if it exists */
418         
419         if (state->getpwent_state != NULL) {
420                 free_getent_state(state->getpwent_state);
421                 state->getpwent_state = NULL;
422         }
423
424 #if 0   /* JERRY */
425         /* add any local users we have */
426                 
427         if ( (domain_state = (struct getent_state *)malloc(sizeof(struct getent_state))) == NULL )
428                 return WINBINDD_ERROR;
429                 
430         ZERO_STRUCTP(domain_state);
431
432         /* Add to list of open domains */
433                 
434         DLIST_ADD(state->getpwent_state, domain_state);
435 #endif
436         
437         /* Create sam pipes for each domain we know about */
438         
439         for(domain = domain_list(); domain != NULL; domain = domain->next) {
440                 struct getent_state *domain_state;
441                 
442                 
443                 /* don't add our domaina if we are a PDC or if we 
444                    are a member of a Samba domain */
445                 
446                 if ( (IS_DC || lp_winbind_trusted_domains_only())
447                         && strequal(domain->name, lp_workgroup()) )
448                 {
449                         continue;
450                 }
451                                                 
452                 /* Create a state record for this domain */
453                 
454                 if ((domain_state = SMB_MALLOC_P(struct getent_state)) == NULL)
455                         return WINBINDD_ERROR;
456                 
457                 ZERO_STRUCTP(domain_state);
458
459                 fstrcpy(domain_state->domain_name, domain->name);
460
461                 /* Add to list of open domains */
462                 
463                 DLIST_ADD(state->getpwent_state, domain_state);
464         }
465         
466         state->getpwent_initialized = True;
467         
468         return WINBINDD_OK;
469 }
470
471 /* Close file pointer to ntdom passwd database */
472
473 enum winbindd_result winbindd_endpwent(struct winbindd_cli_state *state)
474 {
475         DEBUG(3, ("[%5lu]: endpwent\n", (unsigned long)state->pid));
476
477         free_getent_state(state->getpwent_state);    
478         state->getpwent_initialized = False;
479         state->getpwent_state = NULL;
480         
481         return WINBINDD_OK;
482 }
483
484 /* Get partial list of domain users for a domain.  We fill in the sam_entries,
485    and num_sam_entries fields with domain user information.  The dispinfo_ndx
486    field is incremented to the index of the next user to fetch.  Return True if
487    some users were returned, False otherwise. */
488
489 static BOOL get_sam_user_entries(struct getent_state *ent, TALLOC_CTX *mem_ctx)
490 {
491         NTSTATUS status;
492         uint32 num_entries;
493         WINBIND_USERINFO *info;
494         struct getpwent_user *name_list = NULL;
495         BOOL result = False;
496         struct winbindd_domain *domain;
497         struct winbindd_methods *methods;
498         unsigned int i;
499
500         if (ent->num_sam_entries)
501                 return False;
502
503         if (!(domain = find_domain_from_name(ent->domain_name))) {
504                 DEBUG(3, ("no such domain %s in get_sam_user_entries\n",
505                           ent->domain_name));
506                 return False;
507         }
508
509         methods = domain->methods;
510
511         /* Free any existing user info */
512
513         SAFE_FREE(ent->sam_entries);
514         ent->num_sam_entries = 0;
515         
516         /* Call query_user_list to get a list of usernames and user rids */
517
518         num_entries = 0;
519
520         status = methods->query_user_list(domain, mem_ctx, &num_entries, 
521                                           &info);
522                 
523         if (num_entries) {
524                 struct getpwent_user *tnl;
525                 
526                 tnl = SMB_REALLOC_ARRAY(name_list, struct getpwent_user, ent->num_sam_entries + num_entries);
527                 
528                 if (!tnl) {
529                         DEBUG(0,("get_sam_user_entries realloc failed.\n"));
530                         SAFE_FREE(name_list);
531                         goto done;
532                 } else
533                         name_list = tnl;
534         }
535
536         for (i = 0; i < num_entries; i++) {
537                 /* Store account name and gecos */
538                 if (!info[i].acct_name) {
539                         fstrcpy(name_list[ent->num_sam_entries + i].name, "");
540                 } else {
541                         fstrcpy(name_list[ent->num_sam_entries + i].name, 
542                                 info[i].acct_name); 
543                 }
544                 if (!info[i].full_name) {
545                         fstrcpy(name_list[ent->num_sam_entries + i].gecos, "");
546                 } else {
547                         fstrcpy(name_list[ent->num_sam_entries + i].gecos, 
548                                 info[i].full_name); 
549                 }
550                 
551                 /* User and group ids */
552                 sid_copy(&name_list[ent->num_sam_entries+i].user_sid,
553                          &info[i].user_sid);
554                 sid_copy(&name_list[ent->num_sam_entries+i].group_sid,
555                          &info[i].group_sid);
556         }
557                 
558         ent->num_sam_entries += num_entries;
559         
560         /* Fill in remaining fields */
561         
562         ent->sam_entries = name_list;
563         ent->sam_entry_index = 0;
564         result = ent->num_sam_entries > 0;
565
566  done:
567
568         return result;
569 }
570
571 /* Fetch next passwd entry from ntdom database */
572
573 #define MAX_GETPWENT_USERS 500
574
575 enum winbindd_result winbindd_getpwent(struct winbindd_cli_state *state)
576 {
577         struct getent_state *ent;
578         struct winbindd_pw *user_list;
579         int num_users, user_list_ndx = 0, i;
580
581         DEBUG(3, ("[%5lu]: getpwent\n", (unsigned long)state->pid));
582
583         /* Check user has enabled this */
584
585         if (!lp_winbind_enum_users())
586                 return WINBINDD_ERROR;
587
588         /* Allocate space for returning a chunk of users */
589
590         num_users = MIN(MAX_GETPWENT_USERS, state->request.data.num_entries);
591         
592         if ((state->response.extra_data = SMB_MALLOC_ARRAY(struct winbindd_pw, num_users)) == NULL)
593                 return WINBINDD_ERROR;
594
595         memset(state->response.extra_data, 0, num_users * 
596                sizeof(struct winbindd_pw));
597
598         user_list = (struct winbindd_pw *)state->response.extra_data;
599
600         if (!state->getpwent_initialized)
601                 winbindd_setpwent(state);
602         
603         if (!(ent = state->getpwent_state))
604                 return WINBINDD_ERROR;
605
606         /* Start sending back users */
607
608         for (i = 0; i < num_users; i++) {
609                 struct getpwent_user *name_list = NULL;
610                 uint32 result;
611
612                 /* Do we need to fetch another chunk of users? */
613
614                 if (ent->num_sam_entries == ent->sam_entry_index) {
615
616                         while(ent &&
617                               !get_sam_user_entries(ent, state->mem_ctx)) {
618                                 struct getent_state *next_ent;
619
620                                 /* Free state information for this domain */
621
622                                 SAFE_FREE(ent->sam_entries);
623
624                                 next_ent = ent->next;
625                                 DLIST_REMOVE(state->getpwent_state, ent);
626
627                                 SAFE_FREE(ent);
628                                 ent = next_ent;
629                         }
630  
631                         /* No more domains */
632
633                         if (!ent) 
634                                 break;
635                 }
636
637                 name_list = ent->sam_entries;
638
639                 /* Lookup user info */
640                 
641                 result = winbindd_fill_pwent(
642                         ent->domain_name, 
643                         name_list[ent->sam_entry_index].name,
644                         &name_list[ent->sam_entry_index].user_sid,
645                         &name_list[ent->sam_entry_index].group_sid,
646                         name_list[ent->sam_entry_index].gecos,
647                         &user_list[user_list_ndx]);
648                 
649                 ent->sam_entry_index++;
650                 
651                 /* Add user to return list */
652                 
653                 if (result) {
654                                 
655                         user_list_ndx++;
656                         state->response.data.num_entries++;
657                         state->response.length += 
658                                 sizeof(struct winbindd_pw);
659
660                 } else
661                         DEBUG(1, ("could not lookup domain user %s\n",
662                                   name_list[ent->sam_entry_index].name));
663         }
664
665         /* Out of domains */
666
667         return (user_list_ndx > 0) ? WINBINDD_OK : WINBINDD_ERROR;
668 }
669
670 /* List domain users without mapping to unix ids */
671
672 enum winbindd_result winbindd_list_users(struct winbindd_cli_state *state)
673 {
674         struct winbindd_domain *domain;
675         WINBIND_USERINFO *info;
676         const char *which_domain;
677         uint32 num_entries = 0, total_entries = 0;
678         char *ted, *extra_data = NULL;
679         int extra_data_len = 0;
680         enum winbindd_result rv = WINBINDD_ERROR;
681
682         DEBUG(3, ("[%5lu]: list users\n", (unsigned long)state->pid));
683
684         /* Ensure null termination */
685         state->request.domain_name[sizeof(state->request.domain_name)-1]='\0';  
686         which_domain = state->request.domain_name;
687         
688         /* Enumerate over trusted domains */
689
690         for (domain = domain_list(); domain; domain = domain->next) {
691                 NTSTATUS status;
692                 struct winbindd_methods *methods;
693                 unsigned int i;
694                 
695                 /* if we have a domain name restricting the request and this
696                    one in the list doesn't match, then just bypass the remainder
697                    of the loop */
698                    
699                 if ( *which_domain && !strequal(which_domain, domain->name) )
700                         continue;
701                         
702                 methods = domain->methods;
703
704                 /* Query display info */
705                 status = methods->query_user_list(domain, state->mem_ctx, 
706                                                   &num_entries, &info);
707
708                 if (num_entries == 0)
709                         continue;
710
711                 /* Allocate some memory for extra data */
712                 total_entries += num_entries;
713                         
714                 ted = SMB_REALLOC(extra_data, sizeof(fstring) * total_entries);
715                         
716                 if (!ted) {
717                         DEBUG(0,("failed to enlarge buffer!\n"));
718                         SAFE_FREE(extra_data);
719                         goto done;
720                 } else 
721                         extra_data = ted;
722                         
723                 /* Pack user list into extra data fields */
724                         
725                 for (i = 0; i < num_entries; i++) {
726                         fstring acct_name, name;
727                         
728                         if (!info[i].acct_name) {
729                                 fstrcpy(acct_name, "");
730                         } else {
731                                 fstrcpy(acct_name, info[i].acct_name);
732                         }
733                         
734                         fill_domain_username(name, domain->name, acct_name);
735                         
736                                 /* Append to extra data */
737                         memcpy(&extra_data[extra_data_len], name, 
738                                strlen(name));
739                         extra_data_len += strlen(name);
740                         extra_data[extra_data_len++] = ',';
741                 }   
742         }
743
744         /* Assign extra_data fields in response structure */
745
746         if (extra_data) {
747                 extra_data[extra_data_len - 1] = '\0';
748                 state->response.extra_data = extra_data;
749                 state->response.length += extra_data_len;
750         }
751
752         /* No domains responded but that's still OK so don't return an
753            error. */
754
755         rv = WINBINDD_OK;
756
757  done:
758
759         return rv;
760 }