2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-1998
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
7 * Copyright (C) Paul Ashton 1997-1998.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 /* this module apparently provides an implementation of DCE/RPC over a
25 * named pipe (IPC$ connection using SMBtrans). details of DCE/RPC
26 * documentation are available (in on-line form) from the X-Open group.
28 * this module should provide a level of abstraction between SMB
29 * and DCE/RPC, while minimising the amount of mallocs, unnecessary
30 * data copies, and network traffic.
32 * in this version, which takes a "let's learn what's going on and
33 * get something running" approach, there is additional network
34 * traffic generated, but the code should be easier to understand...
36 * ... if you read the docs. or stare at packets for weeks on end.
42 extern int DEBUGLEVEL
;
45 * A list of the rids of well known BUILTIN and Domain users
49 rid_name builtin_alias_rids
[] =
51 { BUILTIN_ALIAS_RID_ADMINS
, "Administrators" },
52 { BUILTIN_ALIAS_RID_USERS
, "Users" },
53 { BUILTIN_ALIAS_RID_GUESTS
, "Guests" },
54 { BUILTIN_ALIAS_RID_POWER_USERS
, "Power Users" },
56 { BUILTIN_ALIAS_RID_ACCOUNT_OPS
, "Account Operators" },
57 { BUILTIN_ALIAS_RID_SYSTEM_OPS
, "System Operators" },
58 { BUILTIN_ALIAS_RID_PRINT_OPS
, "Print Operators" },
59 { BUILTIN_ALIAS_RID_BACKUP_OPS
, "Backup Operators" },
60 { BUILTIN_ALIAS_RID_REPLICATOR
, "Replicator" },
64 /* array lookup of well-known Domain RID users. */
65 rid_name domain_user_rids
[] =
67 { DOMAIN_USER_RID_ADMIN
, "Administrator" },
68 { DOMAIN_USER_RID_GUEST
, "Guest" },
72 /* array lookup of well-known Domain RID groups. */
73 rid_name domain_group_rids
[] =
75 { DOMAIN_GROUP_RID_ADMINS
, "Domain Admins" },
76 { DOMAIN_GROUP_RID_USERS
, "Domain Users" },
77 { DOMAIN_GROUP_RID_GUESTS
, "Domain Guests" },
81 int make_dom_gids(TALLOC_CTX
*ctx
, char *gids_str
, DOM_GID
**ppgids
)
90 DEBUG(4,("make_dom_gids: %s\n", gids_str
));
92 if (gids_str
== NULL
|| *gids_str
== 0)
95 for (count
= 0, ptr
= gids_str
;
96 next_token(&ptr
, s2
, NULL
, sizeof(s2
));
100 gids
= (DOM_GID
*)talloc(ctx
, sizeof(DOM_GID
) * count
);
103 DEBUG(0,("make_dom_gids: talloc fail !\n"));
107 for (count
= 0, ptr
= gids_str
;
108 next_token(&ptr
, s2
, NULL
, sizeof(s2
)) &&
109 count
< LSA_MAX_GROUPS
;
112 /* the entries are of the form GID/ATTR, ATTR being optional.*/
117 attr
= strchr(s2
,'/');
122 attr
= "7"; /* default value for attribute is 7 */
124 /* look up the RID string and see if we can turn it into a rid number */
125 for (i
= 0; builtin_alias_rids
[i
].name
!= NULL
; i
++)
127 if (strequal(builtin_alias_rids
[i
].name
, s2
))
129 rid
= builtin_alias_rids
[i
].rid
;
139 DEBUG(1,("make_dom_gids: unknown well-known alias RID %s/%s\n", s2
, attr
));
144 gids
[count
].g_rid
= rid
;
145 gids
[count
].attr
= atoi(attr
);
147 DEBUG(5,("group id: %d attr: %d\n", gids
[count
].g_rid
, gids
[count
].attr
));
156 /*******************************************************************
157 gets a domain user's groups
158 ********************************************************************/
159 void get_domain_user_groups(char *domain_groups
, char *user
)
163 if (domain_groups
== NULL
|| user
== NULL
) return;
165 /* can only be a user or a guest. cannot be guest _and_ admin */
166 if (user_in_list(user
, lp_domain_guest_group()))
168 slprintf(tmp
, sizeof(tmp
) - 1, " %ld/7 ", DOMAIN_GROUP_RID_GUESTS
);
169 pstrcat(domain_groups
, tmp
);
171 DEBUG(3,("domain guest group access %s granted\n", tmp
));
175 slprintf(tmp
, sizeof(tmp
) -1, " %ld/7 ", DOMAIN_GROUP_RID_USERS
);
176 pstrcat(domain_groups
, tmp
);
178 DEBUG(3,("domain group access %s granted\n", tmp
));
180 if (user_in_list(user
, lp_domain_admin_group()))
182 slprintf(tmp
, sizeof(tmp
) - 1, " %ld/7 ", DOMAIN_GROUP_RID_ADMINS
);
183 pstrcat(domain_groups
, tmp
);
185 DEBUG(3,("domain admin group access %s granted\n", tmp
));
190 /*******************************************************************
191 Look up a local (domain) rid and return a name and type.
192 ********************************************************************/
193 uint32
local_lookup_group_name(uint32 rid
, char *group_name
, uint32
*type
)
196 (*type
) = SID_NAME_DOM_GRP
;
198 DEBUG(5,("lookup_group_name: rid: %d", rid
));
200 while (domain_group_rids
[i
].rid
!= rid
&& domain_group_rids
[i
].rid
!= 0)
205 if (domain_group_rids
[i
].rid
!= 0)
207 fstrcpy(group_name
, domain_group_rids
[i
].name
);
208 DEBUG(5,(" = %s\n", group_name
));
212 DEBUG(5,(" none mapped\n"));
213 return NT_STATUS_NONE_MAPPED
;
216 /*******************************************************************
217 Look up a local alias rid and return a name and type.
218 ********************************************************************/
219 uint32
local_lookup_alias_name(uint32 rid
, char *alias_name
, uint32
*type
)
222 (*type
) = SID_NAME_WKN_GRP
;
224 DEBUG(5,("lookup_alias_name: rid: %d", rid
));
226 while (builtin_alias_rids
[i
].rid
!= rid
&& builtin_alias_rids
[i
].rid
!= 0)
231 if (builtin_alias_rids
[i
].rid
!= 0)
233 fstrcpy(alias_name
, builtin_alias_rids
[i
].name
);
234 DEBUG(5,(" = %s\n", alias_name
));
238 DEBUG(5,(" none mapped\n"));
239 return NT_STATUS_NONE_MAPPED
;
242 /*******************************************************************
243 Look up a local user rid and return a name and type.
244 ********************************************************************/
245 uint32
local_lookup_user_name(uint32 rid
, char *user_name
, uint32
*type
)
247 SAM_ACCOUNT
*sampwd
=NULL
;
251 (*type
) = SID_NAME_USER
;
253 DEBUG(5,("lookup_user_name: rid: %d", rid
));
255 /* look up the well-known domain user rids first */
256 while (domain_user_rids
[i
].rid
!= rid
&& domain_user_rids
[i
].rid
!= 0)
261 if (domain_user_rids
[i
].rid
!= 0) {
262 fstrcpy(user_name
, domain_user_rids
[i
].name
);
263 DEBUG(5,(" = %s\n", user_name
));
267 pdb_init_sam(&sampwd
);
269 /* ok, it's a user. find the user account */
271 ret
= pdb_getsampwrid(sampwd
, rid
);
275 fstrcpy(user_name
, pdb_get_username(sampwd
) );
276 DEBUG(5,(" = %s\n", user_name
));
277 pdb_free_sam(sampwd
);
281 DEBUG(5,(" none mapped\n"));
282 pdb_free_sam(sampwd
);
283 return NT_STATUS_NONE_MAPPED
;
286 /*******************************************************************
287 Look up a local (domain) group name and return a rid
288 ********************************************************************/
289 uint32
local_lookup_group_rid(char *group_name
, uint32
*rid
)
292 int i
= -1; /* start do loop at -1 */
294 do /* find, if it exists, a group rid for the group name*/
297 (*rid
) = domain_group_rids
[i
].rid
;
298 grp_name
= domain_group_rids
[i
].name
;
300 } while (grp_name
!= NULL
&& !strequal(grp_name
, group_name
));
302 return (grp_name
!= NULL
) ? 0 : NT_STATUS_NONE_MAPPED
;
305 /*******************************************************************
306 Look up a local (BUILTIN) alias name and return a rid
307 ********************************************************************/
308 uint32
local_lookup_alias_rid(char *alias_name
, uint32
*rid
)
311 int i
= -1; /* start do loop at -1 */
313 do /* find, if it exists, a alias rid for the alias name*/
316 (*rid
) = builtin_alias_rids
[i
].rid
;
317 als_name
= builtin_alias_rids
[i
].name
;
319 } while (als_name
!= NULL
&& !strequal(als_name
, alias_name
));
321 return (als_name
!= NULL
) ? 0 : NT_STATUS_NONE_MAPPED
;
324 /*******************************************************************
325 Look up a local user name and return a rid
326 ********************************************************************/
327 uint32
local_lookup_user_rid(char *user_name
, uint32
*rid
)
329 SAM_ACCOUNT
*sampass
=NULL
;
334 pdb_init_sam(&sampass
);
336 /* find the user account */
338 ret
= pdb_getsampwnam(sampass
, user_name
);
342 (*rid
) = pdb_get_user_rid(sampass
);
343 pdb_free_sam(sampass
);
347 pdb_free_sam(sampass
);
348 return NT_STATUS_NONE_MAPPED
;