3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1998
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
8 * Copyright (C) Paul Ashton 1997-1998.
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 2 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, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /* this module apparently provides an implementation of DCE/RPC over a
26 * named pipe (IPC$ connection using SMBtrans). details of DCE/RPC
27 * documentation are available (in on-line form) from the X-Open group.
29 * this module should provide a level of abstraction between SMB
30 * and DCE/RPC, while minimising the amount of mallocs, unnecessary
31 * data copies, and network traffic.
33 * in this version, which takes a "let's learn what's going on and
34 * get something running" approach, there is additional network
35 * traffic generated, but the code should be easier to understand...
37 * ... if you read the docs. or stare at packets for weeks on end.
44 extern int DEBUGLEVEL;
47 * A list of the rids of well known BUILTIN and Domain users
51 rid_name builtin_alias_rids[] =
53 { BUILTIN_ALIAS_RID_ADMINS , "Administrators" },
54 { BUILTIN_ALIAS_RID_USERS , "Users" },
55 { BUILTIN_ALIAS_RID_GUESTS , "Guests" },
56 { BUILTIN_ALIAS_RID_POWER_USERS , "Power Users" },
58 { BUILTIN_ALIAS_RID_ACCOUNT_OPS , "Account Operators" },
59 { BUILTIN_ALIAS_RID_SYSTEM_OPS , "System Operators" },
60 { BUILTIN_ALIAS_RID_PRINT_OPS , "Print Operators" },
61 { BUILTIN_ALIAS_RID_BACKUP_OPS , "Backup Operators" },
62 { BUILTIN_ALIAS_RID_REPLICATOR , "Replicator" },
66 /* array lookup of well-known Domain RID users. */
67 rid_name domain_user_rids[] =
69 { DOMAIN_USER_RID_ADMIN , "Administrator" },
70 { DOMAIN_USER_RID_GUEST , "Guest" },
74 /* array lookup of well-known Domain RID groups. */
75 rid_name domain_group_rids[] =
77 { DOMAIN_GROUP_RID_ADMINS , "Domain Admins" },
78 { DOMAIN_GROUP_RID_USERS , "Domain Users" },
79 { DOMAIN_GROUP_RID_GUESTS , "Domain Guests" },
83 int make_dom_gids(char *gids_str, DOM_GID **ppgids)
92 DEBUG(4,("make_dom_gids: %s\n", gids_str));
94 if (gids_str == NULL || *gids_str == 0)
97 for (count = 0, ptr = gids_str;
98 next_token(&ptr, s2, NULL, sizeof(s2));
102 gids = (DOM_GID *)malloc( sizeof(DOM_GID) * count );
105 DEBUG(0,("make_dom_gids: malloc fail !\n"));
109 for (count = 0, ptr = gids_str;
110 next_token(&ptr, s2, NULL, sizeof(s2)) &&
111 count < LSA_MAX_GROUPS;
114 /* the entries are of the form GID/ATTR, ATTR being optional.*/
119 attr = strchr(s2,'/');
124 attr = "7"; /* default value for attribute is 7 */
126 /* look up the RID string and see if we can turn it into a rid number */
127 for (i = 0; builtin_alias_rids[i].name != NULL; i++)
129 if (strequal(builtin_alias_rids[i].name, s2))
131 rid = builtin_alias_rids[i].rid;
141 DEBUG(1,("make_dom_gids: unknown well-known alias RID %s/%s\n", s2, attr));
146 gids[count].g_rid = rid;
147 gids[count].attr = atoi(attr);
149 DEBUG(5,("group id: %d attr: %d\n", gids[count].g_rid, gids[count].attr));
158 /*******************************************************************
159 gets a domain user's groups
160 ********************************************************************/
161 void get_domain_user_groups(char *domain_groups, char *user)
165 if (domain_groups == NULL || user == NULL) return;
167 /* any additional groups this user is in. e.g power users */
168 pstrcpy(domain_groups, lp_domain_groups());
170 /* can only be a user or a guest. cannot be guest _and_ admin */
171 if (user_in_list(user, lp_domain_guest_group()))
173 slprintf(tmp, sizeof(tmp) - 1, " %ld/7 ", DOMAIN_GROUP_RID_GUESTS);
174 pstrcat(domain_groups, tmp);
176 DEBUG(3,("domain guest group access %s granted\n", tmp));
180 slprintf(tmp, sizeof(tmp) -1, " %ld/7 ", DOMAIN_GROUP_RID_USERS);
181 pstrcat(domain_groups, tmp);
183 DEBUG(3,("domain group access %s granted\n", tmp));
185 if (user_in_list(user, lp_domain_admin_group()))
187 slprintf(tmp, sizeof(tmp) - 1, " %ld/7 ", DOMAIN_GROUP_RID_ADMINS);
188 pstrcat(domain_groups, tmp);
190 DEBUG(3,("domain admin group access %s granted\n", tmp));
196 /*******************************************************************
198 ********************************************************************/
199 uint32 lookup_group_name(uint32 rid, char *group_name, uint32 *type)
202 (*type) = SID_NAME_DOM_GRP;
204 DEBUG(5,("lookup_group_name: rid: %d", rid));
206 while (domain_group_rids[i].rid != rid && domain_group_rids[i].rid != 0)
211 if (domain_group_rids[i].rid != 0)
213 fstrcpy(group_name, domain_group_rids[i].name);
214 DEBUG(5,(" = %s\n", group_name));
218 DEBUG(5,(" none mapped\n"));
219 return 0xC0000000 | NT_STATUS_NONE_MAPPED;
222 /*******************************************************************
224 ********************************************************************/
225 uint32 lookup_alias_name(uint32 rid, char *alias_name, uint32 *type)
228 (*type) = SID_NAME_WKN_GRP;
230 DEBUG(5,("lookup_alias_name: rid: %d", rid));
232 while (builtin_alias_rids[i].rid != rid && builtin_alias_rids[i].rid != 0)
237 if (builtin_alias_rids[i].rid != 0)
239 fstrcpy(alias_name, builtin_alias_rids[i].name);
240 DEBUG(5,(" = %s\n", alias_name));
244 DEBUG(5,(" none mapped\n"));
245 return 0xC0000000 | NT_STATUS_NONE_MAPPED;
248 /*******************************************************************
250 ********************************************************************/
251 uint32 lookup_user_name(uint32 rid, char *user_name, uint32 *type)
253 struct sam_disp_info *disp_info;
255 (*type) = SID_NAME_USER;
257 DEBUG(5,("lookup_user_name: rid: %d", rid));
259 /* look up the well-known domain user rids first */
260 while (domain_user_rids[i].rid != rid && domain_user_rids[i].rid != 0)
265 if (domain_user_rids[i].rid != 0)
267 fstrcpy(user_name, domain_user_rids[i].name);
268 DEBUG(5,(" = %s\n", user_name));
272 /* ok, it's a user. find the user account */
274 disp_info = getsamdisprid(rid);
277 if (disp_info != NULL)
279 fstrcpy(user_name, disp_info->smb_name);
280 DEBUG(5,(" = %s\n", user_name));
284 DEBUG(5,(" none mapped\n"));
285 return 0xC0000000 | NT_STATUS_NONE_MAPPED;
288 /*******************************************************************
290 ********************************************************************/
291 uint32 lookup_group_rid(char *group_name, uint32 *rid)
294 int i = -1; /* start do loop at -1 */
296 do /* find, if it exists, a group rid for the group name*/
299 (*rid) = domain_group_rids[i].rid;
300 grp_name = domain_group_rids[i].name;
302 } while (grp_name != NULL && !strequal(grp_name, group_name));
304 return (grp_name != NULL) ? 0 : 0xC0000000 | NT_STATUS_NONE_MAPPED;
307 /*******************************************************************
309 ********************************************************************/
310 uint32 lookup_alias_rid(char *alias_name, uint32 *rid)
313 int i = -1; /* start do loop at -1 */
315 do /* find, if it exists, a alias rid for the alias name*/
318 (*rid) = builtin_alias_rids[i].rid;
319 als_name = builtin_alias_rids[i].name;
321 } while (als_name != NULL && !strequal(als_name, alias_name));
323 return (als_name != NULL) ? 0 : 0xC0000000 | NT_STATUS_NONE_MAPPED;
326 /*******************************************************************
328 ********************************************************************/
329 uint32 lookup_user_rid(char *user_name, uint32 *rid)
331 struct sam_passwd *sam_pass;
334 /* find the user account */
336 sam_pass = getsam21pwnam(user_name);
339 if (sam_pass != NULL)
341 (*rid) = sam_pass->user_rid;
345 return 0xC0000000 | NT_STATUS_NONE_MAPPED;