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.
22 #ifdef USE_SMBGROUP_DB
24 static int al_file_lock_depth
= 0;
25 extern int DEBUGLEVEL
;
27 static char s_readbuf
[1024];
29 /***************************************************************
30 Start to enumerate the aliasdb list. Returns a void pointer
31 to ensure no modification outside this module.
32 ****************************************************************/
34 static void *startalsfilepwent(BOOL update
)
36 return startfileent(lp_smb_alias_file(),
37 s_readbuf
, sizeof(s_readbuf
),
38 &al_file_lock_depth
, update
);
41 /***************************************************************
42 End enumeration of the aliasdb list.
43 ****************************************************************/
45 static void endalsfilepwent(void *vp
)
47 endfileent(vp
, &al_file_lock_depth
);
50 /*************************************************************************
51 Return the current position in the aliasdb list as an SMB_BIG_UINT.
52 This must be treated as an opaque token.
53 *************************************************************************/
54 static SMB_BIG_UINT
getalsfilepwpos(void *vp
)
56 return getfilepwpos(vp
);
59 /*************************************************************************
60 Set the current position in the aliasdb list from an SMB_BIG_UINT.
61 This must be treated as an opaque token.
62 *************************************************************************/
63 static BOOL
setalsfilepwpos(void *vp
, SMB_BIG_UINT tok
)
65 return setfilepwpos(vp
, tok
);
69 /*************************************************************************
70 Routine to return the next entry in the smbdomainalias list.
71 *************************************************************************/
72 static char *get_alias_members(char *p
, int *num_mem
, LOCAL_GRP_MEMBER
**members
)
76 if (num_mem
== NULL
|| members
== NULL
)
84 while (next_token(&p
, name
, ",", sizeof(fstring
)))
90 if (strnequal(name
, "S-", 2))
92 /* sid entered directly */
93 string_to_sid(&sid
, name
);
94 found
= lookup_sid(&sid
, name
, &type
) == 0x0;
98 found
= lookup_name(name
, &sid
, &type
) == 0x0;
103 DEBUG(0,("alias database: could not resolve alias named %s\n", name
));
107 (*members
) = Realloc((*members
), ((*num_mem
)+1) * sizeof(LOCAL_GRP_MEMBER
));
109 if ((*members
) == NULL
)
114 fstrcpy((*members
)[*num_mem
].name
, name
);
115 (*members
)[*num_mem
].sid_use
= type
;
116 sid_copy(&(*members
)[*num_mem
].sid
, &sid
);
122 /*************************************************************************
123 Routine to return the next entry in the smbdomainalias list.
124 *************************************************************************/
125 static LOCAL_GRP
*getalsfilepwent(void *vp
, LOCAL_GRP_MEMBER
**mem
, int *num_mem
)
127 /* Static buffers we will return. */
128 static LOCAL_GRP al_buf
;
136 aldb_init_als(&al_buf
);
139 * Scan the file, a line at a time and check if the name matches.
141 while (getfileline(vp
, linebuf
, sizeof(linebuf
)) > 0)
147 p
= strncpyn(al_buf
.name
, linebuf
, sizeof(al_buf
.name
), ':');
150 DEBUG(0, ("getalsfilepwent: malformed alias entry (no :)\n"));
157 /* get alias comment */
159 p
= strncpyn(al_buf
.comment
, p
, sizeof(al_buf
.comment
), ':');
162 DEBUG(0, ("getalsfilepwent: malformed alias entry (no :)\n"));
171 p
= Atoic(p
, &gidval
, ":");
175 DEBUG(0, ("getalsfilepwent: malformed alias entry (no : after uid)\n"));
182 /* now get the user's aliases. there are a maximum of 32 */
184 if (mem
!= NULL
&& num_mem
!= NULL
)
189 p
= get_alias_members(p
, num_mem
, mem
);
192 DEBUG(0, ("getalsfilepwent: malformed alias entry (no : after members)\n"));
197 * look up the gid, turn it into a rid. the _correct_ type of rid */
200 if (!lookupsmbgrpgid((gid_t
)gidval
, &gmep
))
204 if (gmep
.type
!= SID_NAME_DOM_GRP
&&
205 gmep
.type
!= SID_NAME_WKN_GRP
))
210 sid_split_rid(&gmep
.sid
, &gp_buf
.rid
);
211 if (!sid_equal(&gmep
.sid
, &global_sam_sid
))
216 make_alias_line(linebuf
, sizeof(linebuf
), &al_buf
, mem
, num_mem
);
217 DEBUG(10,("line: '%s'\n", linebuf
));
222 DEBUG(5,("getalsfilepwent: end of file reached.\n"));
226 /************************************************************************
227 Routine to add an entry to the aliasdb file.
228 *************************************************************************/
230 static BOOL
add_alsfileals_entry(LOCAL_GRP
*newals
)
232 DEBUG(0, ("add_alsfileals_entry: NOT IMPLEMENTED\n"));
236 /************************************************************************
237 Routine to search the aliasdb file for an entry matching the aliasname.
238 and then modify its alias entry.
239 ************************************************************************/
241 static BOOL
mod_alsfileals_entry(LOCAL_GRP
* als
)
243 DEBUG(0, ("mod_alsfileals_entry: NOT IMPLEMENTED\n"));
248 static struct aliasdb_ops file_ops
=
255 iterate_getaliasntnam
, /* In aliasdb.c */
256 iterate_getaliasgid
, /* In aliasdb.c */
257 iterate_getaliasrid
, /* In aliasdb.c */
260 add_alsfileals_entry
,
261 mod_alsfileals_entry
,
263 iterate_getuseraliasntnam
/* in aliasdb.c */
266 struct aliasdb_ops
*file_initialise_alias_db(void)
272 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
273 void als_dummy_function(void) { } /* stop some compilers complaining */
274 #endif /* USE_SMBPASS_DB */