1998-11-05 19:54:07 +03:00
/*
* Unix SMB / Netbios implementation . Version 1.9 . SMB parameters and setup
* Copyright ( C ) Andrew Tridgell 1992 - 1998 Modified by Jeremy Allison 1995.
*
* This program is free software ; you can redistribute it and / or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation ; either version 2 of the License , or ( at your option )
* any later version .
*
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License for
* more details .
*
* You should have received a copy of the GNU General Public License along with
* this program ; if not , write to the Free Software Foundation , Inc . , 675
* Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
1999-12-13 16:27:58 +03:00
# ifdef USE_SMBPASS_DB
1998-11-05 19:54:07 +03:00
static int grp_file_lock_depth = 0 ;
extern int DEBUGLEVEL ;
/***************************************************************
Start to enumerate the smbpasswd list . Returns a void pointer
to ensure no modification outside this module .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void * startsmbfilegrpent ( BOOL update )
{
static char s_readbuf [ 1024 ] ;
1999-12-13 16:27:58 +03:00
return startfilepwent ( lp_smb_passgrp_file ( ) , s_readbuf , sizeof ( s_readbuf ) ,
1998-11-05 19:54:07 +03:00
& grp_file_lock_depth , update ) ;
}
/***************************************************************
End enumeration of the smbpasswd list .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void endsmbfilegrpent ( void * vp )
{
1999-12-13 16:27:58 +03:00
endfilepwent ( vp , & grp_file_lock_depth ) ;
1998-11-05 19:54:07 +03:00
}
/*************************************************************************
Return the current position in the smbpasswd list as an SMB_BIG_UINT .
This must be treated as an opaque token .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static SMB_BIG_UINT getsmbfilegrppos ( void * vp )
{
return getfilepwpos ( vp ) ;
}
/*************************************************************************
Set the current position in the smbpasswd list from an SMB_BIG_UINT .
This must be treated as an opaque token .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static BOOL setsmbfilegrppos ( void * vp , SMB_BIG_UINT tok )
{
return setfilepwpos ( vp , tok ) ;
}
/*************************************************************************
Routine to return the next entry in the smbpasswd list .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct smb_passwd * getsmbfilegrpent ( void * vp ,
uint32 * * grp_rids , int * num_grps ,
uint32 * * als_rids , int * num_alss )
{
/* Static buffers we will return. */
static struct smb_passwd pw_buf ;
static pstring user_name ;
struct passwd * pwfile ;
pstring linebuf ;
1999-12-13 16:27:58 +03:00
unsigned char * p ;
1998-11-05 19:54:07 +03:00
int uidval ;
1999-12-13 16:27:58 +03:00
size_t linebuf_len ;
1998-11-05 19:54:07 +03:00
if ( vp = = NULL )
{
DEBUG ( 0 , ( " getsmbfilegrpent: Bad password file pointer. \n " ) ) ;
return NULL ;
}
pwdb_init_smb ( & pw_buf ) ;
/*
* Scan the file , a line at a time .
*/
1999-12-13 16:27:58 +03:00
while ( ( linebuf_len = getfileline ( vp , linebuf , sizeof ( linebuf ) ) ) > 0 )
1998-11-05 19:54:07 +03:00
{
/*
* The line we have should be of the form : -
*
1999-12-13 16:27:58 +03:00
* username : uid : domainrid1 , domainrid2 . . : aliasrid1 , aliasrid2 . . :
1998-11-05 19:54:07 +03:00
*/
/*
* As 256 is shorter than a pstring we don ' t need to check
* length here - if this ever changes . . . .
*/
p = strncpyn ( user_name , linebuf , sizeof ( user_name ) , ' : ' ) ;
/* Go past ':' */
p + + ;
/* Get smb uid. */
p = Atoic ( ( char * ) p , & uidval , " : " ) ;
pw_buf . smb_name = user_name ;
1999-12-13 16:27:58 +03:00
pw_buf . smb_userid = uidval ;
1998-11-05 19:54:07 +03:00
/*
1999-12-13 16:27:58 +03:00
* Now get the password value - this should be 32 hex digits
* which are the ascii representations of a 16 byte string .
* Get two at a time and put them into the password .
1998-11-05 19:54:07 +03:00
*/
/* Skip the ':' */
p + + ;
1999-12-13 16:27:58 +03:00
if ( grp_rids ! = NULL & & num_grps ! = NULL )
1998-11-05 19:54:07 +03:00
{
int i ;
1999-12-13 16:27:58 +03:00
p = get_numlist ( p , grp_rids , num_grps ) ;
1998-11-05 19:54:07 +03:00
if ( p = = NULL )
{
DEBUG ( 0 , ( " getsmbfilegrpent: invalid line \n " ) ) ;
return NULL ;
}
1999-12-13 16:27:58 +03:00
for ( i = 0 ; i < ( * num_grps ) ; i + + )
{
( * grp_rids ) [ i ] = pwdb_gid_to_group_rid ( ( * grp_rids ) [ i ] ) ;
}
1998-11-05 19:54:07 +03:00
}
/* Skip the ':' */
p + + ;
1999-12-13 16:27:58 +03:00
if ( als_rids ! = NULL & & num_alss ! = NULL )
1998-11-05 19:54:07 +03:00
{
int i ;
1999-12-13 16:27:58 +03:00
p = get_numlist ( p , als_rids , num_alss ) ;
1998-11-05 19:54:07 +03:00
if ( p = = NULL )
{
DEBUG ( 0 , ( " getsmbfilegrpent: invalid line \n " ) ) ;
return NULL ;
}
1999-12-13 16:27:58 +03:00
for ( i = 0 ; i < ( * num_alss ) ; i + + )
{
( * als_rids ) [ i ] = pwdb_gid_to_alias_rid ( ( * als_rids ) [ i ] ) ;
}
1998-11-05 19:54:07 +03:00
}
pwfile = Get_Pwnam ( pw_buf . smb_name , False ) ;
if ( pwfile = = NULL )
{
DEBUG ( 0 , ( " getsmbfilegrpent: smbpasswd database is corrupt! \n " ) ) ;
DEBUG ( 0 , ( " getsmbfilegrpent: username %s not in unix passwd database! \n " , pw_buf . smb_name ) ) ;
return NULL ;
}
return & pw_buf ;
}
DEBUG ( 5 , ( " getsmbfilegrpent: end of file reached. \n " ) ) ;
return NULL ;
}
static struct passgrp_ops file_ops =
{
startsmbfilegrpent ,
endsmbfilegrpent ,
getsmbfilegrppos ,
setsmbfilegrppos ,
iterate_getsmbgrpnam , /* In passgrp.c */
iterate_getsmbgrpuid , /* In passgrp.c */
iterate_getsmbgrprid , /* In passgrp.c */
getsmbfilegrpent ,
} ;
struct passgrp_ops * file_initialise_password_grp ( void )
{
return & file_ops ;
}
# else
/* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
1999-12-13 16:27:58 +03:00
void smbpass_dummy_function ( void ) { } /* stop some compilers complaining */
1998-11-05 19:54:07 +03:00
# endif /* USE_SMBPASS_DB */