/* * Unix SMB/Netbios implementation. * Version 1.9. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-1998 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998, * Copyright (C) Paul Ashton 1997-1998. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* this module apparently provides an implementation of DCE/RPC over a * named pipe (IPC$ connection using SMBtrans). details of DCE/RPC * documentation are available (in on-line form) from the X-Open group. * * this module should provide a level of abstraction between SMB * and DCE/RPC, while minimising the amount of mallocs, unnecessary * data copies, and network traffic. * * in this version, which takes a "let's learn what's going on and * get something running" approach, there is additional network * traffic generated, but the code should be easier to understand... * * ... if you read the docs. or stare at packets for weeks on end. * */ #include "includes.h" /* * A list of the rids of well known BUILTIN and Domain users * and groups. */ rid_name builtin_alias_rids[] = { { BUILTIN_ALIAS_RID_ADMINS , "Administrators" }, { BUILTIN_ALIAS_RID_USERS , "Users" }, { BUILTIN_ALIAS_RID_GUESTS , "Guests" }, { BUILTIN_ALIAS_RID_POWER_USERS , "Power Users" }, { BUILTIN_ALIAS_RID_ACCOUNT_OPS , "Account Operators" }, { BUILTIN_ALIAS_RID_SYSTEM_OPS , "System Operators" }, { BUILTIN_ALIAS_RID_PRINT_OPS , "Print Operators" }, { BUILTIN_ALIAS_RID_BACKUP_OPS , "Backup Operators" }, { BUILTIN_ALIAS_RID_REPLICATOR , "Replicator" }, { 0 , NULL } }; /* array lookup of well-known Domain RID users. */ rid_name domain_user_rids[] = { { DOMAIN_USER_RID_ADMIN , "Administrator" }, { DOMAIN_USER_RID_GUEST , "Guest" }, { 0 , NULL } }; /* array lookup of well-known Domain RID groups. */ rid_name domain_group_rids[] = { { DOMAIN_GROUP_RID_ADMINS , "Domain Admins" }, { DOMAIN_GROUP_RID_USERS , "Domain Users" }, { DOMAIN_GROUP_RID_GUESTS , "Domain Guests" }, { 0 , NULL } }; int make_dom_gids(TALLOC_CTX *ctx, char *gids_str, DOM_GID **ppgids) { char *ptr; pstring s2; int count; DOM_GID *gids; *ppgids = NULL; DEBUG(4,("make_dom_gids: %s\n", gids_str)); if (gids_str == NULL || *gids_str == 0) return 0; for (count = 0, ptr = gids_str; next_token(&ptr, s2, NULL, sizeof(s2)); count++) ; gids = (DOM_GID *)talloc(ctx, sizeof(DOM_GID) * count ); if(!gids) { DEBUG(0,("make_dom_gids: talloc fail !\n")); return 0; } for (count = 0, ptr = gids_str; next_token(&ptr, s2, NULL, sizeof(s2)) && count < LSA_MAX_GROUPS; count++) { /* the entries are of the form GID/ATTR, ATTR being optional.*/ char *attr; uint32 rid = 0; int i; attr = strchr_m(s2,'/'); if (attr) *attr++ = 0; if (!attr || !*attr) attr = "7"; /* default value for attribute is 7 */ /* look up the RID string and see if we can turn it into a rid number */ for (i = 0; builtin_alias_rids[i].name != NULL; i++) { if (strequal(builtin_alias_rids[i].name, s2)) { rid = builtin_alias_rids[i].rid; break; } } if (rid == 0) rid = atoi(s2); if (rid == 0) { DEBUG(1,("make_dom_gids: unknown well-known alias RID %s/%s\n", s2, attr)); count--; } else { gids[count].g_rid = rid; gids[count].attr = atoi(attr); DEBUG(5,("group id: %d attr: %d\n", gids[count].g_rid, gids[count].attr)); } } *ppgids = gids; return count; } /******************************************************************* gets a domain user's groups ********************************************************************/ BOOL new_get_domain_user_groups(TALLOC_CTX *ctx, int *numgroups, DOM_GID **pgids, SAM_ACCOUNT *sam_pass) { GROUP_MAP *map=NULL; int i, num, num_entries, cur_gid=0; struct group *grp; DOM_GID *gids; fstring user_name; uint32 grid; uint32 tmp_rid; fstrcpy(user_name, pdb_get_username(sam_pass)); grid=pdb_get_group_rid(sam_pass); DEBUG(10,("new_get_domain_user_groups: searching domain groups [%s] is a member of\n", user_name)); /* first get the list of the domain groups */ if (!enum_group_mapping(SID_NAME_DOM_GRP, &map, &num_entries, ENUM_ONLY_MAPPED, MAPPING_WITHOUT_PRIV)) return False; DEBUG(10,("new_get_domain_user_groups: there are %d mapped groups\n", num_entries)); /* * alloc memory. In the worse case, we alloc memory for nothing. * but I prefer to alloc for nothing * than reallocing everytime. */ gids = (DOM_GID *)talloc(ctx, sizeof(DOM_GID) * num_entries); /* for each group, check if the user is a member of*/ for(i=0; igr_mem[num]!=NULL; num++) { if(strcmp(grp->gr_mem[num], user_name)==0) { /* we found the user, add the group to the list */ sid_peek_rid(&map[i].sid, &(gids[cur_gid].g_rid)); gids[cur_gid].attr=map[i].sid_name_use; DEBUG(10,("new_get_domain_user_groups: user found in group %s\n", map[i].nt_name)); cur_gid++; break; } } } /* we have checked the groups */ /* we must now check the gid of the user or the primary group rid, that's the same */ for (i=0; i