2000-05-09 15:43:00 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-05-09 15:43:00 +04:00
Winbind daemon for ntdom nss module
Copyright ( C ) Tim Potter 2000
2001-11-28 01:39:57 +03:00
Copyright ( C ) Jeremy Allison 2001.
2003-06-30 21:24:59 +04:00
Copyright ( C ) Gerald ( Jerry ) Carter 2003.
2005-01-15 22:00:18 +03:00
Copyright ( C ) Volker Lendecke 2005
2000-05-09 15:43:00 +04:00
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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2000-05-09 15:43:00 +04:00
( 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
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2000-05-09 15:43:00 +04:00
*/
2003-11-12 04:51:10 +03:00
# include "includes.h"
2000-05-09 15:43:00 +04:00
# include "winbindd.h"
2002-07-15 14:35:28 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_WINBIND
2000-05-09 15:43:00 +04:00
/* Fill a grent structure from various other information */
2009-08-16 14:08:52 +04:00
bool fill_grent ( TALLOC_CTX * mem_ctx , struct winbindd_gr * gr ,
const char * dom_name , const char * gr_name , gid_t unix_gid )
2000-05-09 15:43:00 +04:00
{
2002-01-20 04:24:59 +03:00
fstring full_group_name ;
2008-09-16 00:50:15 +04:00
char * mapped_name = NULL ;
2012-09-04 16:30:38 +04:00
struct winbindd_domain * domain ;
2008-09-16 00:50:15 +04:00
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL ;
2006-03-15 03:10:38 +03:00
2012-09-04 16:30:38 +04:00
domain = find_domain_from_name_noinit ( dom_name ) ;
if ( domain = = NULL ) {
DEBUG ( 0 , ( " Failed to find domain '%s'. "
" Check connection to trusted domains! \n " ,
dom_name ) ) ;
return false ;
}
2008-09-16 00:50:15 +04:00
nt_status = normalize_name_map ( mem_ctx , domain , gr_name ,
& mapped_name ) ;
/* Basic whitespace replacement */
if ( NT_STATUS_IS_OK ( nt_status ) ) {
fill_domain_username ( full_group_name , dom_name ,
mapped_name , true ) ;
}
/* Mapped to an aliase */
else if ( NT_STATUS_EQUAL ( nt_status , NT_STATUS_FILE_RENAMED ) ) {
fstrcpy ( full_group_name , mapped_name ) ;
}
/* no change */
else {
fill_domain_username ( full_group_name , dom_name ,
gr_name , True ) ;
}
2000-05-09 15:43:00 +04:00
2001-05-07 08:32:40 +04:00
gr - > gr_gid = unix_gid ;
2008-07-06 20:55:07 +04:00
2001-05-07 08:32:40 +04:00
/* Group name and password */
2008-07-06 20:55:07 +04:00
2011-05-04 00:10:01 +04:00
strlcpy ( gr - > gr_name , full_group_name , sizeof ( gr - > gr_name ) ) ;
strlcpy ( gr - > gr_passwd , " x " , sizeof ( gr - > gr_passwd ) ) ;
2000-05-09 15:43:00 +04:00
2001-05-07 08:32:40 +04:00
return True ;
2000-05-09 15:43:00 +04:00
}
2009-08-16 14:09:37 +04:00
struct getgr_countmem {
int num ;
size_t len ;
} ;
static int getgr_calc_memberlen ( DATA_BLOB key , void * data , void * priv )
{
2009-08-23 14:38:35 +04:00
struct wbint_Principal * m = talloc_get_type_abort (
data , struct wbint_Principal ) ;
2009-08-16 14:09:37 +04:00
struct getgr_countmem * buf = ( struct getgr_countmem * ) priv ;
2009-02-11 00:59:10 +03:00
2009-08-16 14:09:37 +04:00
buf - > num + = 1 ;
buf - > len + = strlen ( m - > name ) + 1 ;
return 0 ;
}
struct getgr_stringmem {
size_t ofs ;
char * buf ;
} ;
static int getgr_unparse_members ( DATA_BLOB key , void * data , void * priv )
{
2009-08-23 14:38:35 +04:00
struct wbint_Principal * m = talloc_get_type_abort (
data , struct wbint_Principal ) ;
2009-08-16 14:09:37 +04:00
struct getgr_stringmem * buf = ( struct getgr_stringmem * ) priv ;
int len ;
len = strlen ( m - > name ) ;
memcpy ( buf - > buf + buf - > ofs , m - > name , len ) ;
buf - > ofs + = len ;
buf - > buf [ buf - > ofs ] = ' , ' ;
buf - > ofs + = 1 ;
return 0 ;
}
NTSTATUS winbindd_print_groupmembers ( struct talloc_dict * members ,
TALLOC_CTX * mem_ctx ,
int * num_members , char * * result )
{
struct getgr_countmem c ;
struct getgr_stringmem m ;
int res ;
c . num = 0 ;
c . len = 0 ;
res = talloc_dict_traverse ( members , getgr_calc_memberlen , & c ) ;
2011-08-24 18:21:37 +04:00
if ( res = = - 1 ) {
2009-08-16 14:09:37 +04:00
DEBUG ( 5 , ( " talloc_dict_traverse failed \n " ) ) ;
return NT_STATUS_INTERNAL_ERROR ;
}
m . ofs = 0 ;
m . buf = talloc_array ( mem_ctx , char , c . len ) ;
if ( m . buf = = NULL ) {
DEBUG ( 5 , ( " talloc failed \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
res = talloc_dict_traverse ( members , getgr_unparse_members , & m ) ;
2011-08-24 18:21:37 +04:00
if ( res = = - 1 ) {
2009-08-16 14:09:37 +04:00
DEBUG ( 5 , ( " talloc_dict_traverse failed \n " ) ) ;
TALLOC_FREE ( m . buf ) ;
return NT_STATUS_INTERNAL_ERROR ;
}
m . buf [ c . len - 1 ] = ' \0 ' ;
* num_members = c . num ;
* result = m . buf ;
return NT_STATUS_OK ;
}