3 * THIS CODE IS OUT-OF-DATE BY TWO YEARS, IS LEGACY DESIGN AND VERY, VERY,
4 * INCOMPLETE. PLEASE DO NOT MAKE ANY FURTHER ENHANCEMENTS TO THIS CODE
5 * UNLESS THEY ARE ALSO CARRIED OUT IN THE SAMBA_TNG BRANCH.
7 * PLEASE DO NOT TREAT THIS CODE AS AUTHORITATIVE IN *ANY* WAY.
9 * REPEAT, PLEASE DO NOT MAKE ANY MODIFICATIONS TO THIS CODE WITHOUT
10 * FIRST CHECKING THE EQUIVALENT MODULE IN SAMBA_TNG, UPDATING THAT
11 * FIRST, *THEN* CONSIDER MAKING THE SAME MODIFICATION IN THIS BRANCH
13 * YOU WILL, ALMOST GUARANTEED, FIND THAT THE BUG-FIX OR ENHANCEMENT THAT
14 * YOU THINK IS NECESSARY, HAS ALREADY BEEN IMPLEMENTED IN SAMBA_TNG.
15 * IF IT HAS NOT, YOUR BUG-FIX OR ENHANCEMENT *MUST* GO INTO SAMBA_TNG
16 * AS THE SAMBA_TNG CODE WILL REPLACE THIS MODULE WITHOUT REFERENCE TO
17 * ANYTHING IN IT, WITH THE POSSIBLE RISK THAT THE BUG-FIX OR ENHANCEMENT
20 * PLEASE OBSERVE AND RESPECT THIS SIMPLE REQUEST.
28 * Unix SMB/Netbios implementation.
30 * RPC Pipe client / server routines
31 * Copyright (C) Andrew Tridgell 1992-1998
32 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
33 * Copyright (C) Paul Ashton 1997-1998.
35 * This program is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation; either version 2 of the License, or
38 * (at your option) any later version.
40 * This program is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * GNU General Public License for more details.
45 * You should have received a copy of the GNU General Public License
46 * along with this program; if not, write to the Free Software
47 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
50 /* this module apparently provides an implementation of DCE/RPC over a
51 * named pipe (IPC$ connection using SMBtrans). details of DCE/RPC
52 * documentation are available (in on-line form) from the X-Open group.
54 * this module should provide a level of abstraction between SMB
55 * and DCE/RPC, while minimising the amount of mallocs, unnecessary
56 * data copies, and network traffic.
58 * in this version, which takes a "let's learn what's going on and
59 * get something running" approach, there is additional network
60 * traffic generated, but the code should be easier to understand...
62 * ... if you read the docs. or stare at packets for weeks on end.
69 extern int DEBUGLEVEL;
72 * A list of the rids of well known BUILTIN and Domain users
76 rid_name builtin_alias_rids[] =
78 { BUILTIN_ALIAS_RID_ADMINS , "Administrators" },
79 { BUILTIN_ALIAS_RID_USERS , "Users" },
80 { BUILTIN_ALIAS_RID_GUESTS , "Guests" },
81 { BUILTIN_ALIAS_RID_POWER_USERS , "Power Users" },
83 { BUILTIN_ALIAS_RID_ACCOUNT_OPS , "Account Operators" },
84 { BUILTIN_ALIAS_RID_SYSTEM_OPS , "System Operators" },
85 { BUILTIN_ALIAS_RID_PRINT_OPS , "Print Operators" },
86 { BUILTIN_ALIAS_RID_BACKUP_OPS , "Backup Operators" },
87 { BUILTIN_ALIAS_RID_REPLICATOR , "Replicator" },
91 /* array lookup of well-known Domain RID users. */
92 rid_name domain_user_rids[] =
94 { DOMAIN_USER_RID_ADMIN , "Administrator" },
95 { DOMAIN_USER_RID_GUEST , "Guest" },
99 /* array lookup of well-known Domain RID groups. */
100 rid_name domain_group_rids[] =
102 { DOMAIN_GROUP_RID_ADMINS , "Domain Admins" },
103 { DOMAIN_GROUP_RID_USERS , "Domain Users" },
104 { DOMAIN_GROUP_RID_GUESTS , "Domain Guests" },
108 int make_dom_gids(char *gids_str, DOM_GID **ppgids)
117 DEBUG(4,("make_dom_gids: %s\n", gids_str));
119 if (gids_str == NULL || *gids_str == 0)
122 for (count = 0, ptr = gids_str;
123 next_token(&ptr, s2, NULL, sizeof(s2));
127 gids = (DOM_GID *)malloc( sizeof(DOM_GID) * count );
130 DEBUG(0,("make_dom_gids: malloc fail !\n"));
134 for (count = 0, ptr = gids_str;
135 next_token(&ptr, s2, NULL, sizeof(s2)) &&
136 count < LSA_MAX_GROUPS;
139 /* the entries are of the form GID/ATTR, ATTR being optional.*/
144 attr = strchr(s2,'/');
149 attr = "7"; /* default value for attribute is 7 */
151 /* look up the RID string and see if we can turn it into a rid number */
152 for (i = 0; builtin_alias_rids[i].name != NULL; i++)
154 if (strequal(builtin_alias_rids[i].name, s2))
156 rid = builtin_alias_rids[i].rid;
166 DEBUG(1,("make_dom_gids: unknown well-known alias RID %s/%s\n", s2, attr));
171 gids[count].g_rid = rid;
172 gids[count].attr = atoi(attr);
174 DEBUG(5,("group id: %d attr: %d\n", gids[count].g_rid, gids[count].attr));
183 /*******************************************************************
184 gets a domain user's groups
185 ********************************************************************/
186 void get_domain_user_groups(char *domain_groups, char *user)
190 if (domain_groups == NULL || user == NULL) return;
192 /* any additional groups this user is in. e.g power users */
193 pstrcpy(domain_groups, lp_domain_groups());
195 /* can only be a user or a guest. cannot be guest _and_ admin */
196 if (user_in_list(user, lp_domain_guest_group()))
198 slprintf(tmp, sizeof(tmp) - 1, " %ld/7 ", DOMAIN_GROUP_RID_GUESTS);
199 pstrcat(domain_groups, tmp);
201 DEBUG(3,("domain guest group access %s granted\n", tmp));
205 slprintf(tmp, sizeof(tmp) -1, " %ld/7 ", DOMAIN_GROUP_RID_USERS);
206 pstrcat(domain_groups, tmp);
208 DEBUG(3,("domain group access %s granted\n", tmp));
210 if (user_in_list(user, lp_domain_admin_group()))
212 slprintf(tmp, sizeof(tmp) - 1, " %ld/7 ", DOMAIN_GROUP_RID_ADMINS);
213 pstrcat(domain_groups, tmp);
215 DEBUG(3,("domain admin group access %s granted\n", tmp));
221 /*******************************************************************
223 ********************************************************************/
224 uint32 lookup_group_name(uint32 rid, char *group_name, uint32 *type)
227 (*type) = SID_NAME_DOM_GRP;
229 DEBUG(5,("lookup_group_name: rid: %d", rid));
231 while (domain_group_rids[i].rid != rid && domain_group_rids[i].rid != 0)
236 if (domain_group_rids[i].rid != 0)
238 fstrcpy(group_name, domain_group_rids[i].name);
239 DEBUG(5,(" = %s\n", group_name));
243 DEBUG(5,(" none mapped\n"));
244 return 0xC0000000 | NT_STATUS_NONE_MAPPED;
247 /*******************************************************************
249 ********************************************************************/
250 uint32 lookup_alias_name(uint32 rid, char *alias_name, uint32 *type)
253 (*type) = SID_NAME_WKN_GRP;
255 DEBUG(5,("lookup_alias_name: rid: %d", rid));
257 while (builtin_alias_rids[i].rid != rid && builtin_alias_rids[i].rid != 0)
262 if (builtin_alias_rids[i].rid != 0)
264 fstrcpy(alias_name, builtin_alias_rids[i].name);
265 DEBUG(5,(" = %s\n", alias_name));
269 DEBUG(5,(" none mapped\n"));
270 return 0xC0000000 | NT_STATUS_NONE_MAPPED;
273 /*******************************************************************
275 ********************************************************************/
276 uint32 lookup_user_name(uint32 rid, char *user_name, uint32 *type)
278 struct sam_disp_info *disp_info;
280 (*type) = SID_NAME_USER;
282 DEBUG(5,("lookup_user_name: rid: %d", rid));
284 /* look up the well-known domain user rids first */
285 while (domain_user_rids[i].rid != rid && domain_user_rids[i].rid != 0)
290 if (domain_user_rids[i].rid != 0)
292 fstrcpy(user_name, domain_user_rids[i].name);
293 DEBUG(5,(" = %s\n", user_name));
297 /* ok, it's a user. find the user account */
299 disp_info = getsamdisprid(rid);
302 if (disp_info != NULL)
304 fstrcpy(user_name, disp_info->smb_name);
305 DEBUG(5,(" = %s\n", user_name));
309 DEBUG(5,(" none mapped\n"));
310 return 0xC0000000 | NT_STATUS_NONE_MAPPED;
313 /*******************************************************************
315 ********************************************************************/
316 uint32 lookup_group_rid(char *group_name, uint32 *rid)
319 int i = -1; /* start do loop at -1 */
321 do /* find, if it exists, a group rid for the group name*/
324 (*rid) = domain_group_rids[i].rid;
325 grp_name = domain_group_rids[i].name;
327 } while (grp_name != NULL && !strequal(grp_name, group_name));
329 return (grp_name != NULL) ? 0 : 0xC0000000 | NT_STATUS_NONE_MAPPED;
332 /*******************************************************************
334 ********************************************************************/
335 uint32 lookup_alias_rid(char *alias_name, uint32 *rid)
338 int i = -1; /* start do loop at -1 */
340 do /* find, if it exists, a alias rid for the alias name*/
343 (*rid) = builtin_alias_rids[i].rid;
344 als_name = builtin_alias_rids[i].name;
346 } while (als_name != NULL && !strequal(als_name, alias_name));
348 return (als_name != NULL) ? 0 : 0xC0000000 | NT_STATUS_NONE_MAPPED;
351 /*******************************************************************
353 ********************************************************************/
354 uint32 lookup_user_rid(char *user_name, uint32 *rid)
356 struct sam_passwd *sam_pass;
359 /* find the user account */
361 sam_pass = getsam21pwnam(user_name);
364 if (sam_pass != NULL)
366 (*rid) = sam_pass->user_rid;
370 return 0xC0000000 | NT_STATUS_NONE_MAPPED;