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.
23 #ifdef USE_SMBGROUP_DB
25 static int gp_file_lock_depth
= 0;
26 extern int DEBUGLEVEL
;
28 static char s_readbuf
[1024];
30 /***************************************************************
31 Start to enumerate the grppasswd list. Returns a void pointer
32 to ensure no modification outside this module.
33 ****************************************************************/
35 static void *startgrpfilepwent(BOOL update
)
37 return startfileent(lp_smb_group_file(),
38 s_readbuf
, sizeof(s_readbuf
),
39 &gp_file_lock_depth
, update
);
42 /***************************************************************
43 End enumeration of the grppasswd list.
44 ****************************************************************/
46 static void endgrpfilepwent(void *vp
)
48 endfileent(vp
, &gp_file_lock_depth
);
51 /*************************************************************************
52 Return the current position in the grppasswd list as an SMB_BIG_UINT.
53 This must be treated as an opaque token.
54 *************************************************************************/
55 static SMB_BIG_UINT
getgrpfilepwpos(void *vp
)
57 return getfilepwpos(vp
);
60 /*************************************************************************
61 Set the current position in the grppasswd list from an SMB_BIG_UINT.
62 This must be treated as an opaque token.
63 *************************************************************************/
64 static BOOL
setgrpfilepwpos(void *vp
, SMB_BIG_UINT tok
)
66 return setfilepwpos(vp
, tok
);
70 /*************************************************************************
71 Routine to return the next entry in the smbdomaingroup list.
72 *************************************************************************/
73 static char *get_group_members(char *p
, int *num_mem
, DOMAIN_GRP_MEMBER
**members
)
77 if (num_mem
== NULL
|| members
== NULL
)
85 while (next_token(&p
, name
, ",", sizeof(fstring
)))
93 uint32 rid
= get_number(name
);
94 sid_copy(&sid
, &global_sam_sid
);
95 sid_append_rid(&sid
, rid
);
97 found
= lookup_sid(&sid
, name
, &type
) == 0x0;
101 found
= lookup_name(name
, &sid
, &type
) == 0x0;
106 DEBUG(0,("group database: could not resolve name %s in domain %s\n",
107 name
, global_sam_name
));
111 (*members
) = Realloc((*members
), ((*num_mem
)+1) * sizeof(DOMAIN_GRP_MEMBER
));
112 if ((*members
) == NULL
)
117 fstrcpy((*members
)[(*num_mem
)].name
, name
);
118 (*members
)[(*num_mem
)].attr
= 0x07;
124 /*************************************************************************
125 Routine to return the next entry in the smbdomaingroup list.
126 *************************************************************************/
127 static DOMAIN_GRP
*getgrpfilepwent(void *vp
, DOMAIN_GRP_MEMBER
**mem
, int *num_mem
)
129 /* Static buffers we will return. */
130 static DOMAIN_GRP gp_buf
;
138 gpdb_init_grp(&gp_buf
);
141 * Scan the file, a line at a time and check if the name matches.
143 while (getfileline(vp
, linebuf
, sizeof(linebuf
)) > 0)
147 p
= strncpyn(gp_buf
.name
, linebuf
, sizeof(gp_buf
.name
), ':');
150 DEBUG(0, ("getgrpfilepwent: malformed group entry (no :)\n"));
157 /* get group comment */
159 p
= strncpyn(gp_buf
.comment
, p
, sizeof(gp_buf
.comment
), ':');
162 DEBUG(0, ("getgrpfilepwent: malformed group entry (no :)\n"));
171 p
= Atoic(p
, &gidval
, ":");
175 DEBUG(0, ("getgrpfilepwent: malformed group entry (no : after uid)\n"));
182 /* now get the user's groups. there are a maximum of 32 */
184 if (mem
!= NULL
&& num_mem
!= NULL
)
189 p
= get_group_members(p
, num_mem
, mem
);
192 DEBUG(0, ("getgrpfilepwent: malformed group entry (no : after members)\n"));
196 /* ok, set up the static data structure and return it */
198 if (!lookupsmbgrpgid((gid_t
)gidval
, &gmep
))
202 if (gmep
.type
!= SID_NAME_DOM_GRP
&&
203 gmep
.type
!= SID_NAME_WKN_GRP
))
208 sid_split_rid(&gmep
.sid
, &gp_buf
.rid
);
209 if (!sid_equal(&gmep
.sid
, &global_sam_sid
))
216 make_group_line(linebuf
, sizeof(linebuf
), &gp_buf
, mem
, num_mem
);
217 DEBUG(10,("line: '%s'\n", linebuf
));
222 DEBUG(5,("getgrpfilepwent: end of file reached.\n"));
226 /************************************************************************
227 Routine to add an entry to the grppasswd file.
228 *************************************************************************/
230 static BOOL
add_grpfilegrp_entry(DOMAIN_GRP
*newgrp
)
232 DEBUG(0, ("add_grpfilegrp_entry: NOT IMPLEMENTED\n"));
236 /************************************************************************
237 Routine to search the grppasswd file for an entry matching the groupname.
238 and then modify its group entry.
239 ************************************************************************/
241 static BOOL
mod_grpfilegrp_entry(DOMAIN_GRP
* grp
)
243 DEBUG(0, ("mod_grpfilegrp_entry: NOT IMPLEMENTED\n"));
248 static struct groupdb_ops file_ops
=
255 iterate_getgroupntnam
, /* In groupdb.c */
256 iterate_getgroupgid
, /* In groupdb.c */
257 iterate_getgrouprid
, /* In groupdb.c */
260 add_grpfilegrp_entry
,
261 mod_grpfilegrp_entry
,
263 iterate_getusergroupntnam
/* in groupdb.c */
266 struct groupdb_ops
*file_initialise_group_db(void)
272 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
273 void grppass_dummy_function(void) { } /* stop some compilers complaining */
274 #endif /* USE_SMBPASS_DB */