2 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
3 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 675
17 * Mass Ave, Cambridge, MA 02139, USA.
25 extern int DEBUGLEVEL
;
34 /***************************************************************
35 Start to enumerate the bltpasswd list. Returns a void pointer
36 to ensure no modification outside this module.
37 ****************************************************************/
39 static void *startbltunixpwent(BOOL update
)
41 struct unix_entries
*grps
;
42 grps
= (struct unix_entries
*)malloc(sizeof(struct unix_entries
));
49 if (!get_unix_grps(&grps
->num_grps
, &grps
->grps
))
60 /***************************************************************
61 End enumeration of the bltpasswd list.
62 ****************************************************************/
64 static void endbltunixpwent(void *vp
)
66 struct unix_entries
*grps
= (struct unix_entries
*)vp
;
70 free_unix_grps(grps
->num_grps
, grps
->grps
);
75 /*************************************************************************
76 Return the current position in the bltpasswd list as an SMB_BIG_UINT.
77 This must be treated as an opaque token.
78 *************************************************************************/
79 static SMB_BIG_UINT
getbltunixpwpos(void *vp
)
81 return (SMB_BIG_UINT
)0;
84 /*************************************************************************
85 Set the current position in the bltpasswd list from an SMB_BIG_UINT.
86 This must be treated as an opaque token.
87 *************************************************************************/
88 static BOOL
setbltunixpwpos(void *vp
, SMB_BIG_UINT tok
)
93 /*************************************************************************
94 Routine to return the next entry in the smbdomainbuiltin list.
95 *************************************************************************/
96 BOOL
get_unixbuiltin_members(struct group
*grp
,
97 int *num_mem
, LOCAL_GRP_MEMBER
**members
)
102 if (num_mem
== NULL
|| members
== NULL
)
110 for (i
= 0; (unix_name
= grp
->gr_mem
[i
]) != NULL
; i
++)
114 LOCAL_GRP_MEMBER
*mem
;
116 fstrcpy(name
, unix_name
);
118 if (!lookupsmbpwnam (name
, &gmep
) &&
119 !lookupsmbgrpnam(name
, &gmep
))
124 if (!sid_front_equal(&global_sam_sid
, &gmep
.sid
))
126 DEBUG(0,("builtin database: could not resolve name %s (wrong Domain SID)\n",
132 (*members
) = Realloc((*members
), (*num_mem
) * sizeof(LOCAL_GRP_MEMBER
));
133 if ((*members
) == NULL
)
135 DEBUG(0,("get_unixbuiltin_members: could not realloc LOCAL_GRP_MEMBERs\n"));
139 mem
= &(*members
)[(*num_mem
)-1];
140 slprintf(mem
->name
, sizeof(mem
->name
)-1, "%s\\%s",
141 gmep
.nt_domain
, gmep
.nt_name
);
142 sid_copy(&mem
->sid
, &gmep
.sid
);
143 mem
->sid_use
= gmep
.type
;
145 DEBUG(10,("get_unixbuiltin_members: adding to builtin alias %s\n",
151 /*************************************************************************
152 Routine to return the next entry in the domain builtin list.
154 when we are a PDC or BDC, then unix groups that are explicitly NOT mapped
155 to builtin aliases are treated as DOMAIN groups (see groupunix.c).
157 when we are a member of a domain (not a PDC or BDC) then unix groups
158 that are explicitly NOT mapped to builtin aliases are treated
161 the reasoning behind this is to make it as simple as possible (not an easy
162 task) for people to set up a domain-aware samba server, in each role that
165 *************************************************************************/
166 static LOCAL_GRP
*getbltunixpwent(void *vp
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
168 /* Static buffers we will return. */
169 static LOCAL_GRP gp_buf
;
170 struct group unix_grp
;
171 struct unix_entries
*grps
= (struct unix_entries
*)vp
;
178 if (lp_server_role() == ROLE_DOMAIN_NONE
)
181 * no domain role, no domain aliases (or domain groups,
182 * but that's dealt with by groupdb...).
188 bidb_init_blt(&gp_buf
);
190 /* get array of unix names + gids. this function does NOT
191 get a copy of the unix group members
194 /* cycle through unix groups */
195 for (; grps
->grp_idx
< grps
->num_grps
; grps
->grp_idx
++)
200 memcpy(&unix_grp
, &grps
->grps
[grps
->grp_idx
], sizeof(unix_grp
));
202 DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
205 if (!lookupsmbgrpgid(unix_grp
.gr_gid
, &gmep
))
210 sid_to_string(sid_str
, &gmep
.sid
);
211 DEBUG(10,("group %s found, sid %s type %d\n",
212 gmep
.nt_name
, sid_str
, gmep
.type
));
214 if (gmep
.type
!= SID_NAME_ALIAS
)
219 sid_split_rid(&gmep
.sid
, &gp_buf
.rid
);
220 if (!sid_equal(global_sid_builtin
, &gmep
.sid
))
225 fstrcpy(gp_buf
.name
, gmep
.nt_name
);
229 if (grps
->grp_idx
>= grps
->num_grps
)
234 /* get the user's domain aliases. there are a maximum of 32 */
236 if (mem
!= NULL
&& num_mem
!= NULL
)
241 memcpy(&unix_grp
, getgrgid(unix_grp
.gr_gid
), sizeof(unix_grp
));
242 get_unixbuiltin_members(&unix_grp
, num_mem
, mem
);
247 make_alias_line(linebuf
, sizeof(linebuf
), &gp_buf
, mem
, num_mem
);
248 DEBUG(10,("line: '%s'\n", linebuf
));
251 grps
->grp_idx
++; /* advance so next enum gets next entry */
255 /************************************************************************
256 Routine to add an entry to the bltpasswd file.
257 *************************************************************************/
259 static BOOL
add_bltunixgrp_entry(LOCAL_GRP
*newblt
)
261 DEBUG(0, ("add_bltunixgrp_entry: NOT IMPLEMENTED\n"));
265 /************************************************************************
266 Routine to search the bltpasswd file for an entry matching the builtinname.
267 and then modify its builtin entry.
268 ************************************************************************/
270 static BOOL
mod_bltunixgrp_entry(LOCAL_GRP
* blt
)
272 DEBUG(0, ("mod_bltunixgrp_entry: NOT IMPLEMENTED\n"));
276 /************************************************************************
277 Routine to add a member to an entry to the bltpasswd file.
278 *************************************************************************/
279 static BOOL
add_bltunixgrp_member(uint32 rid
, const DOM_SID
*member_sid
)
281 DEBUG(0, ("add_bltunixgrp_member: NOT IMPLEMENTED\n"));
285 /************************************************************************
286 Routine to delete a member from an entry to the bltpasswd file.
287 *************************************************************************/
288 static BOOL
del_bltunixgrp_member(uint32 rid
, const DOM_SID
*member_sid
)
290 DEBUG(0, ("del_bltunixgrp_member: NOT IMPLEMENTED\n"));
294 static struct aliasdb_ops unix_ops
=
301 iterate_getbuiltinntnam
, /* In builtindb.c */
302 iterate_getbuiltingid
, /* In builtindb.c */
303 iterate_getbuiltinrid
, /* In builtindb.c */
306 add_bltunixgrp_entry
,
307 mod_bltunixgrp_entry
,
308 NULL
, /* deliberately NULL: you can't delete builtin aliases */
310 add_bltunixgrp_member
,
311 del_bltunixgrp_member
,
313 iterate_getuserbuiltinntnam
/* in builtindb.c */
316 struct aliasdb_ops
*unix_initialise_builtin_db(void)
322 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
323 void unix_bltpass_dummy_function(void) { } /* stop some compilers complaining */
324 #endif /* USE_SMBPASS_DB */