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 alspasswd list. Returns a void pointer
36 to ensure no modification outside this module.
37 ****************************************************************/
39 static void *startalsunixpwent(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 alspasswd list.
62 ****************************************************************/
64 static void endalsunixpwent(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 alspasswd list as an SMB_BIG_UINT.
77 This must be treated as an opaque token.
78 *************************************************************************/
79 static SMB_BIG_UINT
getalsunixpwpos(void *vp
)
81 return (SMB_BIG_UINT
)0;
84 /*************************************************************************
85 Set the current position in the alspasswd list from an SMB_BIG_UINT.
86 This must be treated as an opaque token.
87 *************************************************************************/
88 static BOOL
setalsunixpwpos(void *vp
, SMB_BIG_UINT tok
)
93 /*************************************************************************
94 Routine to return the next entry in the smbdomainalias list.
95 *************************************************************************/
96 BOOL
get_unixalias_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,("alias 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_unixalias_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_unixalias_members: adding alias %s\n",
151 /*************************************************************************
152 Routine to return the next entry in the domain alias list.
154 when we are a PDC or BDC, then unix groups that are explicitly NOT mapped
155 to 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 aliases (map_alias_gid) 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
*getalsunixpwent(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
;
173 aldb_init_als(&gp_buf
);
175 /* get array of unix names + gids. this function does NOT
176 get a copy of the unix group members
179 /* cycle through unix groups */
180 for (; grps
->grp_idx
< grps
->num_grps
; grps
->grp_idx
++)
185 memcpy(&unix_grp
, &grps
->grps
[grps
->grp_idx
], sizeof(unix_grp
));
187 DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
190 if (!lookupsmbgrpgid(unix_grp
.gr_gid
, &gmep
))
195 sid_to_string(sid_str
, &gmep
.sid
);
196 DEBUG(10,("group %s found, sid %s type %d\n",
197 gmep
.nt_name
, sid_str
, gmep
.type
));
199 if (gmep
.type
!= SID_NAME_ALIAS
)
204 sid_split_rid(&gmep
.sid
, &gp_buf
.rid
);
205 if (!sid_equal(&global_sam_sid
, &gmep
.sid
))
210 fstrcpy(gp_buf
.name
, gmep
.nt_name
);
214 if (grps
->grp_idx
>= grps
->num_grps
)
219 /* get the user's domain aliases. there are a maximum of 32 */
221 if (mem
!= NULL
&& num_mem
!= NULL
)
226 memcpy(&unix_grp
, getgrgid(unix_grp
.gr_gid
), sizeof(unix_grp
));
227 get_unixalias_members(&unix_grp
, num_mem
, mem
);
232 make_alias_line(linebuf
, sizeof(pstring
), &gp_buf
, mem
, num_mem
);
233 DEBUG(10,("line: '%s'\n", linebuf
));
236 grps
->grp_idx
++; /* advance so next enum gets next entry */
240 /************************************************************************
241 Routine to add an entry to the alspasswd file.
242 *************************************************************************/
244 static BOOL
add_alsunixgrp_entry(LOCAL_GRP
*newals
)
246 DEBUG(0, ("add_alsunixgrp_entry: NOT IMPLEMENTED\n"));
250 /************************************************************************
251 Routine to search the alspasswd file for an entry matching the aliasname.
252 and then modify its alias entry.
253 ************************************************************************/
255 static BOOL
mod_alsunixgrp_entry(LOCAL_GRP
* als
)
257 DEBUG(0, ("mod_alsunixgrp_entry: NOT IMPLEMENTED\n"));
261 /************************************************************************
262 Routine to search the grppasswd file for an entry matching the rid.
264 ************************************************************************/
266 static BOOL
del_alsunixgrp_entry(uint32 rid
)
268 DEBUG(0, ("del_alsunixgrp_entry: NOT IMPLEMENTED\n"));
272 /************************************************************************
273 Routine to add a member to an entry to the grppasswd file.
274 *************************************************************************/
275 static BOOL
add_alsunixgrp_member(uint32 rid
, const DOM_SID
*member_sid
)
277 DEBUG(0, ("add_alsunixgrp_member: NOT IMPLEMENTED\n"));
281 /************************************************************************
282 Routine to delete a member from an entry to the grppasswd file.
283 *************************************************************************/
284 static BOOL
del_alsunixgrp_member(uint32 rid
, const DOM_SID
*member_sid
)
286 DEBUG(0, ("del_alsunixgrp_member: NOT IMPLEMENTED\n"));
291 static struct aliasdb_ops unix_ops
=
298 iterate_getaliasntnam
, /* In aliasdb.c */
299 iterate_getaliasgid
, /* In aliasdb.c */
300 iterate_getaliasrid
, /* In aliasdb.c */
303 add_alsunixgrp_entry
,
304 mod_alsunixgrp_entry
,
305 del_alsunixgrp_entry
,
307 add_alsunixgrp_member
,
308 del_alsunixgrp_member
,
310 iterate_getuseraliasntnam
/* in aliasdb.c */
313 struct aliasdb_ops
*unix_initialise_alias_db(void)
319 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
320 void unix_alspass_dummy_function(void) { } /* stop some compilers complaining */
321 #endif /* USE_SMBPASS_DB */