s3:winbind: Convert the GETPWENT routines to the new API
[Samba/aatanasov.git] / source3 / winbindd / winbindd_user.c
blobd72aaeff745ddac3f36a3e76b4425a04a9e82d05
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind daemon - user related functions
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Jeremy Allison 2001.
8 Copyright (C) Gerald (Jerry) Carter 2003.
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.
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.
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/>.
24 #include "includes.h"
25 #include "winbindd.h"
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_WINBIND
30 bool fillup_pw_field(const char *lp_template,
31 const char *username,
32 const char *domname,
33 uid_t uid,
34 gid_t gid,
35 const char *in,
36 fstring out)
38 char *templ;
40 if (out == NULL)
41 return False;
43 /* The substitution of %U and %D in the 'template
44 homedir' is done by talloc_sub_specified() below.
45 If we have an in string (which means the value has already
46 been set in the nss_info backend), then use that.
47 Otherwise use the template value passed in. */
49 if ( in && !strequal(in,"") && lp_security() == SEC_ADS ) {
50 templ = talloc_sub_specified(NULL, in,
51 username, domname,
52 uid, gid);
53 } else {
54 templ = talloc_sub_specified(NULL, lp_template,
55 username, domname,
56 uid, gid);
59 if (!templ)
60 return False;
62 safe_strcpy(out, templ, sizeof(fstring) - 1);
63 TALLOC_FREE(templ);
65 return True;
69 /* Wrapper for domain->methods->query_user, only on the parent->child pipe */
71 enum winbindd_result winbindd_dual_userinfo(struct winbindd_domain *domain,
72 struct winbindd_cli_state *state)
74 DOM_SID sid;
75 struct wbint_userinfo user_info;
76 NTSTATUS status;
78 /* Ensure null termination */
79 state->request->data.sid[sizeof(state->request->data.sid)-1]='\0';
81 DEBUG(3, ("[%5lu]: lookupsid %s\n", (unsigned long)state->pid,
82 state->request->data.sid));
84 if (!string_to_sid(&sid, state->request->data.sid)) {
85 DEBUG(5, ("%s not a SID\n", state->request->data.sid));
86 return WINBINDD_ERROR;
89 status = domain->methods->query_user(domain, state->mem_ctx,
90 &sid, &user_info);
91 if (!NT_STATUS_IS_OK(status)) {
92 DEBUG(1, ("error getting user info for sid %s\n",
93 sid_string_dbg(&sid)));
94 return WINBINDD_ERROR;
97 fstrcpy(state->response->data.user_info.acct_name,
98 user_info.acct_name);
99 fstrcpy(state->response->data.user_info.full_name,
100 user_info.full_name);
101 fstrcpy(state->response->data.user_info.homedir, user_info.homedir);
102 fstrcpy(state->response->data.user_info.shell, user_info.shell);
103 state->response->data.user_info.primary_gid = user_info.primary_gid;
104 if (!sid_peek_check_rid(&domain->sid, &user_info.group_sid,
105 &state->response->data.user_info.group_rid)) {
106 DEBUG(1, ("Could not extract group rid out of %s\n",
107 sid_string_dbg(&sid)));
108 return WINBINDD_ERROR;
111 return WINBINDD_OK;
114 /* List domain users without mapping to unix ids */
115 void winbindd_list_users(struct winbindd_cli_state *state)
117 winbindd_list_ent(state, LIST_USERS);