preparing for release of alpha.1.4
[Samba.git] / source / groupdb / aliasfile.c
blobc09d6cc23ed613d869c5036f96f6d7ac84649b30
1 /*
2 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
3 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
4 *
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)
8 * any later version.
9 *
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
13 * more details.
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.
20 #include "includes.h"
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)
74 fstring name;
76 if (num_mem == NULL || members == NULL)
78 return NULL;
81 (*num_mem) = 0;
82 (*members) = NULL;
84 while (next_token(&p, name, ",", sizeof(fstring)))
86 DOM_SID sid;
87 uint8 type;
88 BOOL found = False;
90 if (strnequal(name, "S-", 2))
92 /* sid entered directly */
93 string_to_sid(&sid, name);
94 found = lookup_sid(&sid, name, &type) == 0x0;
96 else
98 found = lookup_name(name, &sid, &type) == 0x0;
101 if (!found)
103 DEBUG(0,("alias database: could not resolve alias named %s\n", name));
104 continue;
107 (*members) = Realloc((*members), ((*num_mem)+1) * sizeof(LOCAL_GRP_MEMBER));
109 if ((*members) == NULL)
111 return NULL;
114 fstrcpy((*members)[*num_mem].name, name);
115 (*members)[*num_mem].sid_use = type;
116 sid_copy(&(*members)[*num_mem].sid, &sid);
117 (*num_mem)++;
119 return p;
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;
130 int gidval;
132 pstring linebuf;
133 char *p;
134 uint8 type;
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)
143 DOM_NAME_MAP gmep;
145 /* get alias name */
147 p = strncpyn(al_buf.name, linebuf, sizeof(al_buf.name), ':');
148 if (p == NULL)
150 DEBUG(0, ("getalsfilepwent: malformed alias entry (no :)\n"));
151 continue;
154 /* Go past ':' */
155 p++;
157 /* get alias comment */
159 p = strncpyn(al_buf.comment, p, sizeof(al_buf.comment), ':');
160 if (p == NULL)
162 DEBUG(0, ("getalsfilepwent: malformed alias entry (no :)\n"));
163 continue;
166 /* Go past ':' */
167 p++;
169 /* Get alias gid. */
171 p = Atoic(p, &gidval, ":");
173 if (p == NULL)
175 DEBUG(0, ("getalsfilepwent: malformed alias entry (no : after uid)\n"));
176 continue;
179 /* Go past ':' */
180 p++;
182 /* now get the user's aliases. there are a maximum of 32 */
184 if (mem != NULL && num_mem != NULL)
186 (*mem) = NULL;
187 (*num_mem) = 0;
189 p = get_alias_members(p, num_mem, mem);
190 if (p == NULL)
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))
202 continue;
204 if (gmep.type != SID_NAME_DOM_GRP &&
205 gmep.type != SID_NAME_WKN_GRP))
207 continue;
210 sid_split_rid(&gmep.sid, &gp_buf.rid);
211 if (!sid_equal(&gmep.sid, &global_sam_sid))
213 continue;
216 make_alias_line(linebuf, sizeof(linebuf), &al_buf, mem, num_mem);
217 DEBUG(10,("line: '%s'\n", linebuf));
219 return &al_buf;
222 DEBUG(5,("getalsfilepwent: end of file reached.\n"));
223 return NULL;
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"));
233 return False;
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"));
244 return False;
248 static struct aliasdb_ops file_ops =
250 startalsfilepwent,
251 endalsfilepwent,
252 getalsfilepwpos,
253 setalsfilepwpos,
255 iterate_getaliasntnam, /* In aliasdb.c */
256 iterate_getaliasgid, /* In aliasdb.c */
257 iterate_getaliasrid, /* In aliasdb.c */
258 getalsfilepwent,
260 add_alsfileals_entry,
261 mod_alsfileals_entry,
263 iterate_getuseraliasntnam /* in aliasdb.c */
266 struct aliasdb_ops *file_initialise_alias_db(void)
268 return &file_ops;
271 #else
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 */