1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-15 05:57:49 +03:00

For a number of months now, support for being a domain member without also

running winbind has been broken.  This fixes that, by removing assumptions
about being able to call sid_to_uid() at will.  This whole area needs
revising when we get groups into the PDB.

Andrew Bartlett
This commit is contained in:
Andrew Bartlett -
parent 4071ed06a0
commit 980eda74b7

View File

@ -641,12 +641,11 @@ NT_USER_TOKEN *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups,
* of groups. * of groups.
******************************************************************************/ ******************************************************************************/
static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid, static NTSTATUS get_user_groups_from_local_sam(SAM_ACCOUNT *sampass,
int *n_groups, DOM_SID **groups, gid_t **unix_groups) int *n_groups, DOM_SID **groups, gid_t **unix_groups)
{ {
uid_t uid; uid_t uid;
enum SID_NAME_USE snu; gid_t gid;
fstring str;
int n_unix_groups; int n_unix_groups;
int i; int i;
struct passwd *usr; struct passwd *usr;
@ -654,21 +653,13 @@ static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid,
*n_groups = 0; *n_groups = 0;
*groups = NULL; *groups = NULL;
if (!sid_to_uid(user_sid, &uid, &snu)) { if (!IS_SAM_UNIX_USER(sampass)) {
DEBUG(2, ("get_user_groups_from_local_sam: Failed to convert user SID %s to a uid!\n", DEBUG(1, ("user %s does not have a unix identity!\n", pdb_get_username(sampass)));
sid_to_string(str, user_sid))); return NT_STATUS_NO_SUCH_USER;
/* This might be a non-unix account */
return NT_STATUS_OK;
} }
/* uid = pdb_get_uid(sampass);
* This is _essential_ to prevent occasional segfaults when gid = pdb_get_gid(sampass);
* winbind can't find uid -> username mapping
*/
if (!(usr = getpwuid_alloc(uid))) {
DEBUG(0, ("Couldn't find passdb structure for UID = %d ! Aborting.\n", uid));
return NT_STATUS_NO_SUCH_USER;
};
n_unix_groups = groups_max(); n_unix_groups = groups_max();
if ((*unix_groups = malloc( sizeof(gid_t) * n_unix_groups ) ) == NULL) { if ((*unix_groups = malloc( sizeof(gid_t) * n_unix_groups ) ) == NULL) {
@ -677,7 +668,7 @@ static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid,
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
if (sys_getgrouplist(usr->pw_name, usr->pw_gid, *unix_groups, &n_unix_groups) == -1) { if (sys_getgrouplist(pdb_get_username(sampass), gid, *unix_groups, &n_unix_groups) == -1) {
gid_t *groups_tmp; gid_t *groups_tmp;
groups_tmp = Realloc(*unix_groups, sizeof(gid_t) * n_unix_groups); groups_tmp = Realloc(*unix_groups, sizeof(gid_t) * n_unix_groups);
if (!groups_tmp) { if (!groups_tmp) {
@ -687,7 +678,7 @@ static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid,
} }
*unix_groups = groups_tmp; *unix_groups = groups_tmp;
if (sys_getgrouplist(usr->pw_name, usr->pw_gid, *unix_groups, &n_unix_groups) == -1) { if (sys_getgrouplist(pdb_get_username(sampass), gid, *unix_groups, &n_unix_groups) == -1) {
DEBUG(0, ("get_user_groups_from_local_sam: failed to get the unix group list\n")); DEBUG(0, ("get_user_groups_from_local_sam: failed to get the unix group list\n"));
SAFE_FREE(*unix_groups); SAFE_FREE(*unix_groups);
passwd_free(&usr); passwd_free(&usr);
@ -695,9 +686,7 @@ static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid,
} }
} }
debug_unix_user_token(DBGC_CLASS, 5, usr->pw_uid, usr->pw_gid, n_unix_groups, *unix_groups); debug_unix_user_token(DBGC_CLASS, 5, uid, gid, n_unix_groups, *unix_groups);
passwd_free(&usr);
if (n_unix_groups > 0) { if (n_unix_groups > 0) {
*groups = malloc(sizeof(DOM_SID) * n_unix_groups); *groups = malloc(sizeof(DOM_SID) * n_unix_groups);
@ -763,7 +752,7 @@ NTSTATUS make_server_info_sam(auth_serversupplied_info **server_info,
} }
if (!NT_STATUS_IS_OK(nt_status if (!NT_STATUS_IS_OK(nt_status
= get_user_groups_from_local_sam(pdb_get_user_sid(sampass), = get_user_groups_from_local_sam(sampass,
&n_groupSIDs, &groupSIDs, &unix_groups))) &n_groupSIDs, &groupSIDs, &unix_groups)))
{ {
DEBUG(4,("get_user_groups_from_local_sam failed\n")); DEBUG(4,("get_user_groups_from_local_sam failed\n"));
@ -998,7 +987,7 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
returned to the caller. */ returned to the caller. */
if (!NT_STATUS_IS_OK(nt_status if (!NT_STATUS_IS_OK(nt_status
= get_user_groups_from_local_sam(&user_sid, = get_user_groups_from_local_sam(sam_account,
&n_lgroupSIDs, &n_lgroupSIDs,
&lgroupSIDs, &lgroupSIDs,
&unix_groups))) &unix_groups)))