preparing for release of 3.0-alpha7
[Samba/ekacnet.git] / source / passdb / smbpassgroup.c
blob808abde66175bdcbb11b49e5ecccf87e3bb954fe
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_SMBPASS_DB
24 static int grp_file_lock_depth = 0;
26 /***************************************************************
27 Start to enumerate the smbpasswd list. Returns a void pointer
28 to ensure no modification outside this module.
29 ****************************************************************/
31 static void *startsmbfilegrpent(BOOL update)
33 static char s_readbuf[1024];
34 return startfilepwent(lp_smb_passgrp_file(), s_readbuf, sizeof(s_readbuf),
35 &grp_file_lock_depth, update);
38 /***************************************************************
39 End enumeration of the smbpasswd list.
40 ****************************************************************/
42 static void endsmbfilegrpent(void *vp)
44 endfilepwent(vp, &grp_file_lock_depth);
47 /*************************************************************************
48 Return the current position in the smbpasswd list as an SMB_BIG_UINT.
49 This must be treated as an opaque token.
50 *************************************************************************/
52 static SMB_BIG_UINT getsmbfilegrppos(void *vp)
54 return getfilepwpos(vp);
57 /*************************************************************************
58 Set the current position in the smbpasswd list from an SMB_BIG_UINT.
59 This must be treated as an opaque token.
60 *************************************************************************/
62 static BOOL setsmbfilegrppos(void *vp, SMB_BIG_UINT tok)
64 return setfilepwpos(vp, tok);
67 /*************************************************************************
68 Routine to return the next entry in the smbpasswd list.
69 *************************************************************************/
70 static struct smb_passwd *getsmbfilegrpent(void *vp,
71 uint32 **grp_rids, int *num_grps,
72 uint32 **als_rids, int *num_alss)
74 /* Static buffers we will return. */
75 static struct smb_passwd pw_buf;
76 static pstring user_name;
77 struct passwd *pwfile;
78 pstring linebuf;
79 unsigned char *p;
80 int uidval;
81 size_t linebuf_len;
83 if (vp == NULL)
85 DEBUG(0,("getsmbfilegrpent: Bad password file pointer.\n"));
86 return NULL;
89 pwdb_init_smb(&pw_buf);
92 * Scan the file, a line at a time.
94 while ((linebuf_len = getfileline(vp, linebuf, sizeof(linebuf))) > 0)
97 * The line we have should be of the form :-
99 * username:uid:domainrid1,domainrid2..:aliasrid1,aliasrid2..:
103 * As 256 is shorter than a pstring we don't need to check
104 * length here - if this ever changes....
106 p = strncpyn(user_name, linebuf, sizeof(user_name), ':');
108 /* Go past ':' */
109 p++;
111 /* Get smb uid. */
113 p = Atoic((char *) p, &uidval, ":");
115 pw_buf.smb_name = user_name;
116 pw_buf.smb_userid = uidval;
119 * Now get the password value - this should be 32 hex digits
120 * which are the ascii representations of a 16 byte string.
121 * Get two at a time and put them into the password.
124 /* Skip the ':' */
125 p++;
127 if (grp_rids != NULL && num_grps != NULL)
129 int i;
130 p = get_numlist(p, grp_rids, num_grps);
131 if (p == NULL)
133 DEBUG(0,("getsmbfilegrpent: invalid line\n"));
134 return NULL;
136 for (i = 0; i < (*num_grps); i++)
138 (*grp_rids)[i] = pwdb_gid_to_group_rid((*grp_rids)[i]);
142 /* Skip the ':' */
143 p++;
145 if (als_rids != NULL && num_alss != NULL)
147 int i;
148 p = get_numlist(p, als_rids, num_alss);
149 if (p == NULL)
151 DEBUG(0,("getsmbfilegrpent: invalid line\n"));
152 return NULL;
154 for (i = 0; i < (*num_alss); i++)
156 (*als_rids)[i] = pwdb_gid_to_alias_rid((*als_rids)[i]);
160 pwfile = Get_Pwnam(pw_buf.smb_name);
161 if (pwfile == NULL)
163 DEBUG(0,("getsmbfilegrpent: smbpasswd database is corrupt!\n"));
164 DEBUG(0,("getsmbfilegrpent: username %s not in unix passwd database!\n", pw_buf.smb_name));
165 return NULL;
168 return &pw_buf;
171 DEBUG(5,("getsmbfilegrpent: end of file reached.\n"));
172 return NULL;
175 static struct passgrp_ops file_ops =
177 startsmbfilegrpent,
178 endsmbfilegrpent,
179 getsmbfilegrppos,
180 setsmbfilegrppos,
181 iterate_getsmbgrpnam, /* In passgrp.c */
182 iterate_getsmbgrpuid, /* In passgrp.c */
183 iterate_getsmbgrprid, /* In passgrp.c */
184 getsmbfilegrpent,
187 struct passgrp_ops *file_initialise_password_grp(void)
189 return &file_ops;
192 #else
193 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
194 void smbpass_dummy_function(void) { } /* stop some compilers complaining */
195 #endif /* USE_SMBPASS_DB */