s3:winbind: Move fillup_pw_field() as static to wb_fill_pwent.c
[ira/wip.git] / source3 / winbindd / 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 3 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, see <http://www.gnu.org/licenses/>.
22 */
23
24 #include "includes.h"
25 #include "winbindd.h"
26
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_WINBIND
29
30 /* Wrapper for domain->methods->query_user, only on the parent->child pipe */
31
32 enum winbindd_result winbindd_dual_userinfo(struct winbindd_domain *domain,
33                                             struct winbindd_cli_state *state)
34 {
35         DOM_SID sid;
36         struct wbint_userinfo user_info;
37         NTSTATUS status;
38
39         /* Ensure null termination */
40         state->request->data.sid[sizeof(state->request->data.sid)-1]='\0';
41
42         DEBUG(3, ("[%5lu]: lookupsid %s\n", (unsigned long)state->pid,
43                   state->request->data.sid));
44
45         if (!string_to_sid(&sid, state->request->data.sid)) {
46                 DEBUG(5, ("%s not a SID\n", state->request->data.sid));
47                 return WINBINDD_ERROR;
48         }
49
50         status = domain->methods->query_user(domain, state->mem_ctx,
51                                              &sid, &user_info);
52         if (!NT_STATUS_IS_OK(status)) {
53                 DEBUG(1, ("error getting user info for sid %s\n",
54                           sid_string_dbg(&sid)));
55                 return WINBINDD_ERROR;
56         }
57
58         fstrcpy(state->response->data.user_info.acct_name,
59                 user_info.acct_name);
60         fstrcpy(state->response->data.user_info.full_name,
61                 user_info.full_name);
62         fstrcpy(state->response->data.user_info.homedir, user_info.homedir);
63         fstrcpy(state->response->data.user_info.shell, user_info.shell);
64         state->response->data.user_info.primary_gid = user_info.primary_gid;
65         if (!sid_peek_check_rid(&domain->sid, &user_info.group_sid,
66                                 &state->response->data.user_info.group_rid)) {
67                 DEBUG(1, ("Could not extract group rid out of %s\n",
68                           sid_string_dbg(&sid)));
69                 return WINBINDD_ERROR;
70         }
71
72         return WINBINDD_OK;
73 }