2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* what user is current? */
24 extern struct current_user current_user
;
26 /****************************************************************************
27 Become the guest user without changing the security context stack.
28 ****************************************************************************/
30 BOOL
change_to_guest(void)
32 static struct passwd
*pass
=NULL
;
35 /* Don't need to free() this as its stored in a static */
36 pass
= getpwnam_alloc(lp_guestaccount());
42 /* MWW: From AIX FAQ patch to WU-ftpd: call initgroups before
44 initgroups(pass
->pw_name
, pass
->pw_gid
);
47 set_sec_ctx(pass
->pw_uid
, pass
->pw_gid
, 0, NULL
, NULL
);
49 current_user
.conn
= NULL
;
50 current_user
.vuid
= UID_FIELD_INVALID
;
57 /*******************************************************************
58 Check if a username is OK.
59 ********************************************************************/
61 static BOOL
check_user_ok(connection_struct
*conn
, user_struct
*vuser
,int snum
)
64 for (i
=0;i
<conn
->vuid_cache
.entries
&& i
< VUID_CACHE_SIZE
;i
++)
65 if (conn
->vuid_cache
.list
[i
] == vuser
->vuid
)
68 if ((conn
->force_user
|| conn
->force_group
)
69 && (conn
->vuid
!= vuser
->vuid
)) {
73 if (!user_ok(vuser
->user
.unix_name
,snum
))
76 if (!share_access_check(conn
, snum
, vuser
, conn
->read_only
? FILE_READ_DATA
: FILE_WRITE_DATA
)) {
80 i
= conn
->vuid_cache
.entries
% VUID_CACHE_SIZE
;
81 conn
->vuid_cache
.list
[i
] = vuser
->vuid
;
83 conn
->vuid_cache
.entries
++;
88 /****************************************************************************
89 Become the user of a connection number without changing the security context
90 stack, but modify the currnet_user entries.
91 ****************************************************************************/
93 BOOL
change_to_user(connection_struct
*conn
, uint16 vuid
)
95 user_struct
*vuser
= get_valid_user_struct(vuid
);
100 BOOL must_free_token
= False
;
101 NT_USER_TOKEN
*token
= NULL
;
104 DEBUG(2,("change_to_user: Connection not open\n"));
109 * We need a separate check in security=share mode due to vuid
110 * always being UID_FIELD_INVALID. If we don't do this then
111 * in share mode security we are *always* changing uid's between
112 * SMB's - this hurts performance - Badly.
115 if((lp_security() == SEC_SHARE
) && (current_user
.conn
== conn
) &&
116 (current_user
.uid
== conn
->uid
)) {
117 DEBUG(4,("change_to_user: Skipping user change - already user\n"));
119 } else if ((current_user
.conn
== conn
) &&
120 (vuser
!= 0) && (current_user
.vuid
== vuid
) &&
121 (current_user
.uid
== vuser
->uid
)) {
122 DEBUG(4,("change_to_user: Skipping user change - already user\n"));
128 if (conn
->force_user
) /* security = share sets this too */ {
131 current_user
.groups
= conn
->groups
;
132 current_user
.ngroups
= conn
->ngroups
;
133 token
= conn
->nt_user_token
;
134 } else if ((vuser
) && check_user_ok(conn
, vuser
, snum
)) {
137 current_user
.ngroups
= vuser
->n_groups
;
138 current_user
.groups
= vuser
->groups
;
139 token
= vuser
->nt_user_token
;
141 DEBUG(2,("change_to_user: Invalid vuid used %d or vuid not permitted access to share.\n",vuid
));
146 * See if we should force group for this service.
147 * If so this overrides any group set in the force
151 if((group_c
= *lp_force_group(snum
))) {
152 BOOL is_guest
= False
;
157 * Only force group if the user is a member of
158 * the service group. Check the group memberships for
159 * this user (we already have this) to
160 * see if we should force the group.
164 for (i
= 0; i
< current_user
.ngroups
; i
++) {
165 if (current_user
.groups
[i
] == conn
->gid
) {
175 * We've changed the group list in the token - we must
179 if (vuser
&& vuser
->guest
)
182 token
= create_nt_token(uid
, gid
, current_user
.ngroups
, current_user
.groups
, is_guest
);
184 DEBUG(1, ("change_to_user: create_nt_token failed!\n"));
187 must_free_token
= True
;
190 set_sec_ctx(uid
, gid
, current_user
.ngroups
, current_user
.groups
, token
);
193 * Free the new token (as set_sec_ctx copies it).
197 delete_nt_token(&token
);
199 current_user
.conn
= conn
;
200 current_user
.vuid
= vuid
;
202 DEBUG(5,("change_to_user uid=(%d,%d) gid=(%d,%d)\n",
203 (int)getuid(),(int)geteuid(),(int)getgid(),(int)getegid()));
208 /****************************************************************************
209 Go back to being root without changing the security context stack,
210 but modify the current_user entries.
211 ****************************************************************************/
213 BOOL
change_to_root_user(void)
217 DEBUG(5,("change_to_root_user: now uid=(%d,%d) gid=(%d,%d)\n",
218 (int)getuid(),(int)geteuid(),(int)getgid(),(int)getegid()));
220 current_user
.conn
= NULL
;
221 current_user
.vuid
= UID_FIELD_INVALID
;
226 /****************************************************************************
227 Become the user of an authenticated connected named pipe.
228 When this is called we are currently running as the connection
229 user. Doesn't modify current_user.
230 ****************************************************************************/
232 BOOL
become_authenticated_pipe_user(pipes_struct
*p
)
237 set_sec_ctx(p
->pipe_user
.uid
, p
->pipe_user
.gid
,
238 p
->pipe_user
.ngroups
, p
->pipe_user
.groups
, p
->pipe_user
.nt_user_token
);
243 /****************************************************************************
244 Unbecome the user of an authenticated connected named pipe.
245 When this is called we are running as the authenticated pipe
246 user and need to go back to being the connection user. Doesn't modify
248 ****************************************************************************/
250 BOOL
unbecome_authenticated_pipe_user(void)
252 return pop_sec_ctx();
255 /****************************************************************************
256 Utility functions used by become_xxx/unbecome_xxx.
257 ****************************************************************************/
260 connection_struct
*conn
;
264 /* A stack of current_user connection contexts. */
266 static struct conn_ctx conn_ctx_stack
[MAX_SEC_CTX_DEPTH
];
267 static int conn_ctx_stack_ndx
;
269 static void push_conn_ctx(void)
271 struct conn_ctx
*ctx_p
;
273 /* Check we don't overflow our stack */
275 if (conn_ctx_stack_ndx
== MAX_SEC_CTX_DEPTH
) {
276 DEBUG(0, ("Connection context stack overflow!\n"));
277 smb_panic("Connection context stack overflow!\n");
280 /* Store previous user context */
281 ctx_p
= &conn_ctx_stack
[conn_ctx_stack_ndx
];
283 ctx_p
->conn
= current_user
.conn
;
284 ctx_p
->vuid
= current_user
.vuid
;
286 DEBUG(3, ("push_conn_ctx(%u) : conn_ctx_stack_ndx = %d\n",
287 (unsigned int)ctx_p
->vuid
, conn_ctx_stack_ndx
));
289 conn_ctx_stack_ndx
++;
292 static void pop_conn_ctx(void)
294 struct conn_ctx
*ctx_p
;
296 /* Check for stack underflow. */
298 if (conn_ctx_stack_ndx
== 0) {
299 DEBUG(0, ("Connection context stack underflow!\n"));
300 smb_panic("Connection context stack underflow!\n");
303 conn_ctx_stack_ndx
--;
304 ctx_p
= &conn_ctx_stack
[conn_ctx_stack_ndx
];
306 current_user
.conn
= ctx_p
->conn
;
307 current_user
.vuid
= ctx_p
->vuid
;
310 ctx_p
->vuid
= UID_FIELD_INVALID
;
313 void init_conn_ctx(void)
317 /* Initialise connection context stack */
318 for (i
= 0; i
< MAX_SEC_CTX_DEPTH
; i
++) {
319 conn_ctx_stack
[i
].conn
= NULL
;
320 conn_ctx_stack
[i
].vuid
= UID_FIELD_INVALID
;
324 /****************************************************************************
325 Temporarily become a root user. Must match with unbecome_root(). Saves and
326 restores the connection context.
327 ****************************************************************************/
329 void become_root(void)
336 /* Unbecome the root user */
338 void unbecome_root(void)
344 /****************************************************************************
345 Push the current security context then force a change via change_to_user().
346 Saves and restores the connection context.
347 ****************************************************************************/
349 BOOL
become_user(connection_struct
*conn
, uint16 vuid
)
356 if (!change_to_user(conn
, vuid
)) {
365 BOOL
unbecome_user(void)
372 /*****************************************************************
373 Convert the suplimentary SIDs returned in a netlogon into UNIX
374 group gid_t's. Add to the total group array.
375 *****************************************************************/
377 void add_supplementary_nt_login_groups(int *n_groups
, gid_t
**pp_groups
, NT_USER_TOKEN
**pptok
)
380 int current_n_groups
= *n_groups
;
381 gid_t
*final_groups
= NULL
;
383 NT_USER_TOKEN
*ptok
= *pptok
;
384 NT_USER_TOKEN
*new_tok
= NULL
;
386 if (!ptok
|| (ptok
->num_sids
== 0))
389 new_tok
= dup_nt_token(ptok
);
391 DEBUG(0,("add_supplementary_nt_login_groups: Failed to malloc new token\n"));
394 /* Leave the allocated space but empty the number of SIDs. */
395 new_tok
->num_sids
= 0;
397 total_groups
= current_n_groups
+ ptok
->num_sids
;
399 final_groups
= (gid_t
*)malloc(total_groups
* sizeof(gid_t
));
401 DEBUG(0,("add_supplementary_nt_login_groups: Failed to malloc new groups.\n"));
402 delete_nt_token(&new_tok
);
406 memcpy(final_groups
, *pp_groups
, current_n_groups
* sizeof(gid_t
));
407 for (i
= 0; i
< ptok
->num_sids
; i
++) {
408 enum SID_NAME_USE sid_type
;
411 if (sid_to_gid(&ptok
->user_sids
[i
], &new_grp
, &sid_type
)) {
413 * Don't add the gid_t if it is already in the current group
414 * list. Some UNIXen don't like the same group more than once.
418 for (j
= 0; j
< current_n_groups
; j
++)
419 if (final_groups
[j
] == new_grp
)
422 if ( j
== current_n_groups
) {
423 /* Group not already present. */
424 final_groups
[current_n_groups
++] = new_grp
;
427 /* SID didn't map. Copy to the new token to be saved. */
428 sid_copy(&new_tok
->user_sids
[new_tok
->num_sids
++], &ptok
->user_sids
[i
]);
432 SAFE_FREE(*pp_groups
);
433 *pp_groups
= final_groups
;
434 *n_groups
= current_n_groups
;
436 /* Replace the old token with the truncated one. */
437 delete_nt_token(&ptok
);
441 /*****************************************************************
442 *THE CANONICAL* convert name to SID function.
443 Tries local lookup first - for local domains - then uses winbind.
444 *****************************************************************/
446 BOOL
lookup_name(const char *domain
, const char *name
, DOM_SID
*psid
, enum SID_NAME_USE
*name_type
)
449 BOOL local_lookup
= False
;
451 *name_type
= SID_NAME_UNKNOWN
;
453 /* If we are looking up a domain user, make sure it is
454 for the local machine only */
456 if (strequal(global_myname(), domain
)) {
458 } else if (lp_server_role() == ROLE_DOMAIN_PDC
||
459 lp_server_role() == ROLE_DOMAIN_BDC
) {
460 if (strequal(domain
, lp_workgroup())) {
466 if (local_lookup_name(name
, psid
, name_type
)) {
468 ("lookup_name: (local) [%s]\\[%s] -> SID %s (type %s: %u)\n",
469 domain
, name
, sid_to_string(sid
,psid
),
470 sid_type_lookup(*name_type
), (unsigned int)*name_type
));
475 if (winbind_lookup_name(domain
, name
, psid
, name_type
)) {
477 DEBUG(10,("lookup_name (winbindd): [%s]\\[%s] -> SID %s (type %u)\n",
478 domain
, name
, sid_to_string(sid
, psid
),
479 (unsigned int)*name_type
));
484 DEBUG(10, ("lookup_name: %s lookup for [%s]\\[%s] failed\n",
485 local_lookup
? "local" : "winbind", domain
, name
));
490 /*****************************************************************
491 *THE CANONICAL* convert SID to name function.
492 Tries local lookup first - for local sids, then tries winbind.
493 *****************************************************************/
495 BOOL
lookup_sid(DOM_SID
*sid
, fstring dom_name
, fstring name
, enum SID_NAME_USE
*name_type
)
500 *name_type
= SID_NAME_UNKNOWN
;
502 /* Check if this is our own sid. This should perhaps be done by
503 winbind? For the moment handle it here. */
505 if (sid
->num_auths
== 5) {
509 sid_copy(&tmp_sid
, sid
);
510 sid_split_rid(&tmp_sid
, &rid
);
512 if (sid_equal(get_global_sam_sid(), &tmp_sid
)) {
514 return map_domain_sid_to_name(&tmp_sid
, dom_name
) &&
515 local_lookup_sid(sid
, name
, name_type
);
519 if (!winbind_lookup_sid(sid
, dom_name
, name
, name_type
)) {
524 DEBUG(10,("lookup_sid: winbind lookup for SID %s failed - trying local.\n", sid_to_string(sid_str
, sid
) ));
526 sid_copy(&tmp_sid
, sid
);
527 sid_split_rid(&tmp_sid
, &rid
);
528 return map_domain_sid_to_name(&tmp_sid
, dom_name
) &&
529 lookup_known_rid(&tmp_sid
, rid
, name
, name_type
);
534 /*****************************************************************
535 Id mapping cache. This is to avoid Winbind mappings already
536 seen by smbd to be queried too frequently, keeping winbindd
537 busy, and blocking smbd while winbindd is busy with other
538 stuff. Written by Michael Steffens <michael.steffens@hp.com>,
539 modified to use linked lists by jra.
540 *****************************************************************/
542 #define MAX_UID_SID_CACHE_SIZE 100
543 #define TURNOVER_UID_SID_CACHE_SIZE 10
544 #define MAX_GID_SID_CACHE_SIZE 100
545 #define TURNOVER_GID_SID_CACHE_SIZE 10
547 static size_t n_uid_sid_cache
= 0;
548 static size_t n_gid_sid_cache
= 0;
550 static struct uid_sid_cache
{
551 struct uid_sid_cache
*next
, *prev
;
554 } *uid_sid_cache_head
;
556 static struct gid_sid_cache
{
557 struct gid_sid_cache
*next
, *prev
;
560 } *gid_sid_cache_head
;
562 /*****************************************************************
563 Find a SID given a uid.
564 *****************************************************************/
566 static BOOL
fetch_sid_from_uid_cache(DOM_SID
*psid
, uid_t uid
)
568 struct uid_sid_cache
*pc
;
570 for (pc
= uid_sid_cache_head
; pc
; pc
= pc
->next
) {
571 if (pc
->uid
== uid
) {
574 DEBUG(3,("fetch sid from uid cache %u -> %s\n",
575 (unsigned int)uid
, sid_to_string(sid
, psid
)));
576 DLIST_PROMOTE(uid_sid_cache_head
, pc
);
583 /*****************************************************************
584 Find a uid given a SID.
585 *****************************************************************/
587 static BOOL
fetch_uid_from_cache(uid_t
*puid
, const DOM_SID
*psid
)
589 struct uid_sid_cache
*pc
;
591 for (pc
= uid_sid_cache_head
; pc
; pc
= pc
->next
) {
592 if (sid_compare(&pc
->sid
, psid
) == 0) {
595 DEBUG(3,("fetch uid from cache %u -> %s\n",
596 (unsigned int)*puid
, sid_to_string(sid
, psid
)));
597 DLIST_PROMOTE(uid_sid_cache_head
, pc
);
604 /*****************************************************************
605 Store uid to SID mapping in cache.
606 *****************************************************************/
608 static void store_uid_sid_cache(const DOM_SID
*psid
, uid_t uid
)
610 struct uid_sid_cache
*pc
;
612 if (n_uid_sid_cache
>= MAX_UID_SID_CACHE_SIZE
&& n_uid_sid_cache
> TURNOVER_UID_SID_CACHE_SIZE
) {
613 /* Delete the last TURNOVER_UID_SID_CACHE_SIZE entries. */
614 struct uid_sid_cache
*pc_next
;
617 for (i
= 0, pc
= uid_sid_cache_head
; i
< (n_uid_sid_cache
- TURNOVER_UID_SID_CACHE_SIZE
); i
++, pc
= pc
->next
)
619 for(; pc
; pc
= pc_next
) {
621 DLIST_REMOVE(uid_sid_cache_head
,pc
);
627 pc
= (struct uid_sid_cache
*)malloc(sizeof(struct uid_sid_cache
));
631 sid_copy(&pc
->sid
, psid
);
632 DLIST_ADD(uid_sid_cache_head
, pc
);
636 /*****************************************************************
637 Find a SID given a gid.
638 *****************************************************************/
640 static BOOL
fetch_sid_from_gid_cache(DOM_SID
*psid
, gid_t gid
)
642 struct gid_sid_cache
*pc
;
644 for (pc
= gid_sid_cache_head
; pc
; pc
= pc
->next
) {
645 if (pc
->gid
== gid
) {
648 DEBUG(3,("fetch sid from gid cache %u -> %s\n",
649 (unsigned int)gid
, sid_to_string(sid
, psid
)));
650 DLIST_PROMOTE(gid_sid_cache_head
, pc
);
657 /*****************************************************************
658 Find a gid given a SID.
659 *****************************************************************/
661 static BOOL
fetch_gid_from_cache(gid_t
*pgid
, const DOM_SID
*psid
)
663 struct gid_sid_cache
*pc
;
665 for (pc
= gid_sid_cache_head
; pc
; pc
= pc
->next
) {
666 if (sid_compare(&pc
->sid
, psid
) == 0) {
669 DEBUG(3,("fetch uid from cache %u -> %s\n",
670 (unsigned int)*pgid
, sid_to_string(sid
, psid
)));
671 DLIST_PROMOTE(gid_sid_cache_head
, pc
);
678 /*****************************************************************
679 Store gid to SID mapping in cache.
680 *****************************************************************/
682 static void store_gid_sid_cache(const DOM_SID
*psid
, gid_t gid
)
684 struct gid_sid_cache
*pc
;
686 if (n_gid_sid_cache
>= MAX_GID_SID_CACHE_SIZE
&& n_gid_sid_cache
> TURNOVER_GID_SID_CACHE_SIZE
) {
687 /* Delete the last TURNOVER_GID_SID_CACHE_SIZE entries. */
688 struct gid_sid_cache
*pc_next
;
691 for (i
= 0, pc
= gid_sid_cache_head
; i
< (n_gid_sid_cache
- TURNOVER_GID_SID_CACHE_SIZE
); i
++, pc
= pc
->next
)
693 for(; pc
; pc
= pc_next
) {
695 DLIST_REMOVE(gid_sid_cache_head
,pc
);
701 pc
= (struct gid_sid_cache
*)malloc(sizeof(struct gid_sid_cache
));
705 sid_copy(&pc
->sid
, psid
);
706 DLIST_ADD(gid_sid_cache_head
, pc
);
711 /*****************************************************************
712 *THE CANONICAL* convert uid_t to SID function.
713 Tries winbind first - then uses local lookup.
715 *****************************************************************/
717 DOM_SID
*uid_to_sid(DOM_SID
*psid
, uid_t uid
)
722 if (fetch_sid_from_uid_cache(psid
, uid
))
725 if (lp_winbind_uid(&low
, &high
) && uid
>= low
&& uid
<= high
) {
726 if (winbind_uid_to_sid(psid
, uid
)) {
728 DEBUG(10,("uid_to_sid: winbindd %u -> %s\n",
729 (unsigned int)uid
, sid_to_string(sid
, psid
)));
732 store_uid_sid_cache(psid
, uid
);
737 /* Make sure we report failure, (when psid == NULL) */
739 psid
= local_uid_to_sid(psid
, uid
);
742 DEBUG(10,("uid_to_sid: local %u -> %s\n", (unsigned int)uid
, sid_to_string(sid
, psid
)));
744 store_uid_sid_cache(psid
, uid
);
749 /*****************************************************************
750 *THE CANONICAL* convert gid_t to SID function.
751 Tries winbind first - then uses local lookup.
753 *****************************************************************/
755 DOM_SID
*gid_to_sid(DOM_SID
*psid
, gid_t gid
)
760 if (fetch_sid_from_gid_cache(psid
, gid
))
763 if (lp_winbind_gid(&low
, &high
) && gid
>= low
&& gid
<= high
) {
764 if (winbind_gid_to_sid(psid
, gid
)) {
766 DEBUG(10,("gid_to_sid: winbindd %u -> %s\n",
767 (unsigned int)gid
, sid_to_string(sid
, psid
)));
770 store_gid_sid_cache(psid
, gid
);
775 /* Make sure we report failure, (when psid == NULL) */
776 psid
= local_gid_to_sid(psid
, gid
);
777 DEBUG(10,("gid_to_sid: local %u -> %s\n", (unsigned int)gid
, sid_to_string(sid
, psid
)));
779 store_gid_sid_cache(psid
, gid
);
784 /*****************************************************************
785 *THE CANONICAL* convert SID to uid function.
786 Tries winbind first - then uses local lookup.
787 Returns True if this name is a user sid and the conversion
788 was done correctly, False if not. sidtype is set by this function.
789 *****************************************************************/
791 BOOL
sid_to_uid(const DOM_SID
*psid
, uid_t
*puid
, enum SID_NAME_USE
*sidtype
)
795 if (fetch_uid_from_cache(puid
, psid
))
798 /* if we know its local then don't try winbindd */
799 if (sid_compare_domain(get_global_sam_sid(), psid
) == 0) {
802 result
= local_sid_to_uid(puid
, psid
, sidtype
);
805 store_uid_sid_cache(psid
, *puid
);
809 /* (tridge) I commented out the slab of code below in order to support foreign SIDs
810 Do we really need to validate the type of SID we have in this case?
813 fstring dom_name
, name
;
814 enum SID_NAME_USE name_type
;
816 *sidtype
= SID_NAME_UNKNOWN
;
818 * First we must look up the name and decide if this is a user sid.
821 if ( (!winbind_lookup_sid(psid
, dom_name
, name
, &name_type
)) || (name_type
!= SID_NAME_USER
) ) {
823 DEBUG(10,("sid_to_uid: winbind lookup for sid %s failed - trying local.\n",
824 sid_to_string(sid_str
, psid
) ));
827 result
= local_sid_to_uid(puid
, psid
, sidtype
);
833 * Ensure this is a user sid.
836 if (name_type
!= SID_NAME_USER
) {
837 DEBUG(10,("sid_to_uid: winbind lookup succeeded but SID is not a uid (%u)\n",
838 (unsigned int)name_type
));
842 *sidtype
= SID_NAME_USER
;
845 * Get the uid for this SID.
848 if (!winbind_sid_to_uid(puid
, psid
)) {
850 DEBUG(10,("sid_to_uid: winbind lookup for sid %s failed.\n",
851 sid_to_string(sid_str
, psid
) ));
853 result
= local_sid_to_uid(puid
, psid
, sidtype
);
856 store_uid_sid_cache(psid
, *puid
);
860 DEBUG(10,("sid_to_uid: winbindd %s -> %u\n",
861 sid_to_string(sid_str
, psid
),
862 (unsigned int)*puid
));
864 store_uid_sid_cache(psid
, *puid
);
868 /*****************************************************************
869 *THE CANONICAL* convert SID to gid function.
870 Tries winbind first - then uses local lookup.
871 Returns True if this name is a user sid and the conversion
872 was done correctly, False if not.
873 *****************************************************************/
875 BOOL
sid_to_gid(const DOM_SID
*psid
, gid_t
*pgid
, enum SID_NAME_USE
*sidtype
)
877 fstring dom_name
, name
, sid_str
;
878 enum SID_NAME_USE name_type
;
880 *sidtype
= SID_NAME_UNKNOWN
;
882 if (fetch_gid_from_cache(pgid
, psid
))
886 * First we must look up the name and decide if this is a group sid.
889 /* if we know its local then don't try winbindd */
890 if (sid_compare_domain(get_global_sam_sid(), psid
) == 0) {
893 result
= local_sid_to_gid(pgid
, psid
, sidtype
);
896 store_gid_sid_cache(psid
, *pgid
);
900 if (!winbind_lookup_sid(psid
, dom_name
, name
, &name_type
)) {
901 DEBUG(10,("sid_to_gid: winbind lookup for sid %s failed.\n",
902 sid_to_string(sid_str
, psid
) ));
903 /* this was probably a foreign sid - assume its a group rid
905 name_type
= SID_NAME_DOM_GRP
;
909 * Ensure this is a group sid.
912 if ((name_type
!= SID_NAME_DOM_GRP
) && (name_type
!= SID_NAME_ALIAS
) && (name_type
!= SID_NAME_WKN_GRP
)) {
913 DEBUG(10,("sid_to_gid: winbind lookup succeeded but SID is not a known group (%u)\n",
914 (unsigned int)name_type
));
919 *sidtype
= name_type
;
922 * Get the gid for this SID.
925 if (!winbind_sid_to_gid(pgid
, psid
)) {
926 DEBUG(10,("sid_to_gid: winbind lookup for sid %s failed.\n",
927 sid_to_string(sid_str
, psid
) ));
931 DEBUG(10,("sid_to_gid: winbindd %s -> %u\n",
932 sid_to_string(sid_str
, psid
),
933 (unsigned int)*pgid
));
935 store_gid_sid_cache(psid
, *pgid
);