2005-05-19 15:45:25 +00:00
/*
Unix SMB / CIFS implementation .
endpoint server for the unixinfo pipe
Copyright ( C ) Volker Lendecke 2005
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-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-05-19 15:45:25 +00: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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-05-19 15:45:25 +00:00
*/
# include "includes.h"
# include "rpc_server/dcerpc_server.h"
# include "librpc/gen_ndr/ndr_unixinfo.h"
2008-03-19 19:34:32 +01:00
# include "libcli/wbclient/wbclient.h"
2006-09-09 02:12:09 +00:00
# include "system/passwd.h"
2005-05-19 15:45:25 +00:00
2007-01-17 14:49:36 +00:00
static NTSTATUS dcesrv_unixinfo_SidToUid ( struct dcesrv_call_state * dce_call ,
2005-05-19 15:45:25 +00:00
TALLOC_CTX * mem_ctx ,
struct unixinfo_SidToUid * r )
{
2006-05-07 21:56:26 +00:00
NTSTATUS status ;
2009-04-23 16:37:11 +02:00
struct id_map * ids ;
2005-05-19 15:45:25 +00:00
2008-03-19 19:34:32 +01:00
DEBUG ( 5 , ( " dcesrv_unixinfo_SidToUid called \n " ) ) ;
2009-04-23 16:37:11 +02:00
ids = talloc ( mem_ctx , struct id_map ) ;
2008-03-19 19:34:32 +01:00
NT_STATUS_HAVE_NO_MEMORY ( ids ) ;
2005-05-19 15:45:25 +00:00
2008-03-19 19:34:32 +01:00
ids - > sid = & r - > in . sid ;
2009-04-23 16:37:11 +02:00
ids - > status = ID_UNKNOWN ;
2010-05-24 10:16:34 +10:00
ZERO_STRUCT ( ids - > xid ) ;
2016-09-18 14:03:33 +02:00
status = wbc_sids_to_xids ( ids , 1 ) ;
2006-05-07 21:56:26 +00:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
2005-05-19 15:45:25 +00:00
2010-05-24 10:16:34 +10:00
if ( ids - > xid . type = = ID_TYPE_BOTH | |
ids - > xid . type = = ID_TYPE_UID ) {
* r - > out . uid = ids - > xid . id ;
2008-03-19 19:34:32 +01:00
return NT_STATUS_OK ;
} else {
return NT_STATUS_INVALID_SID ;
}
2005-05-19 15:45:25 +00:00
}
2007-01-17 14:49:36 +00:00
static NTSTATUS dcesrv_unixinfo_UidToSid ( struct dcesrv_call_state * dce_call ,
2005-05-19 15:45:25 +00:00
TALLOC_CTX * mem_ctx ,
struct unixinfo_UidToSid * r )
{
2009-04-23 16:37:11 +02:00
struct id_map * ids ;
2008-03-19 19:34:32 +01:00
uint32_t uid ;
NTSTATUS status ;
2005-05-19 15:45:25 +00:00
2008-03-19 19:34:32 +01:00
DEBUG ( 5 , ( " dcesrv_unixinfo_UidToSid called \n " ) ) ;
2005-05-19 15:45:25 +00:00
2008-03-19 19:34:32 +01:00
uid = r - > in . uid ; /* This cuts uid to 32 bit */
2005-05-19 15:45:25 +00:00
if ( ( uint64_t ) uid ! = r - > in . uid ) {
DEBUG ( 10 , ( " uid out of range \n " ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
2009-04-23 16:37:11 +02:00
ids = talloc ( mem_ctx , struct id_map ) ;
2008-03-19 19:34:32 +01:00
NT_STATUS_HAVE_NO_MEMORY ( ids ) ;
ids - > sid = NULL ;
2009-04-23 16:37:11 +02:00
ids - > status = ID_UNKNOWN ;
2008-03-19 19:34:32 +01:00
2010-05-24 10:16:34 +10:00
ids - > xid . id = uid ;
ids - > xid . type = ID_TYPE_UID ;
2008-03-19 19:34:32 +01:00
2016-09-18 14:06:24 +02:00
status = wbc_xids_to_sids ( ids , 1 ) ;
2008-03-19 19:34:32 +01:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
r - > out . sid = ids - > sid ;
return NT_STATUS_OK ;
2005-05-19 15:45:25 +00:00
}
2007-01-17 14:49:36 +00:00
static NTSTATUS dcesrv_unixinfo_SidToGid ( struct dcesrv_call_state * dce_call ,
2005-05-19 15:45:25 +00:00
TALLOC_CTX * mem_ctx ,
struct unixinfo_SidToGid * r )
{
2006-05-07 21:56:26 +00:00
NTSTATUS status ;
2009-04-23 16:37:11 +02:00
struct id_map * ids ;
2005-05-19 15:45:25 +00:00
2008-03-19 19:34:32 +01:00
DEBUG ( 5 , ( " dcesrv_unixinfo_SidToGid called \n " ) ) ;
2005-05-19 15:45:25 +00:00
2009-04-23 16:37:11 +02:00
ids = talloc ( mem_ctx , struct id_map ) ;
2008-03-19 19:34:32 +01:00
NT_STATUS_HAVE_NO_MEMORY ( ids ) ;
ids - > sid = & r - > in . sid ;
2009-04-23 16:37:11 +02:00
ids - > status = ID_UNKNOWN ;
2010-05-24 10:16:34 +10:00
ZERO_STRUCT ( ids - > xid ) ;
2016-09-18 14:03:33 +02:00
status = wbc_sids_to_xids ( ids , 1 ) ;
2006-05-07 21:56:26 +00:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
2005-05-19 15:45:25 +00:00
2010-05-24 10:16:34 +10:00
if ( ids - > xid . type = = ID_TYPE_BOTH | |
ids - > xid . type = = ID_TYPE_GID ) {
* r - > out . gid = ids - > xid . id ;
2008-03-19 19:34:32 +01:00
return NT_STATUS_OK ;
} else {
return NT_STATUS_INVALID_SID ;
}
2005-05-19 15:45:25 +00:00
}
2007-01-17 14:49:36 +00:00
static NTSTATUS dcesrv_unixinfo_GidToSid ( struct dcesrv_call_state * dce_call ,
2005-05-19 15:45:25 +00:00
TALLOC_CTX * mem_ctx ,
struct unixinfo_GidToSid * r )
{
2009-04-23 16:37:11 +02:00
struct id_map * ids ;
2008-03-19 19:34:32 +01:00
uint32_t gid ;
NTSTATUS status ;
2005-05-19 15:45:25 +00:00
2008-03-19 19:34:32 +01:00
DEBUG ( 5 , ( " dcesrv_unixinfo_GidToSid called \n " ) ) ;
2005-05-19 15:45:25 +00:00
2008-03-19 19:34:32 +01:00
gid = r - > in . gid ; /* This cuts gid to 32 bit */
2005-05-19 15:45:25 +00:00
if ( ( uint64_t ) gid ! = r - > in . gid ) {
DEBUG ( 10 , ( " gid out of range \n " ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
2009-04-23 16:37:11 +02:00
ids = talloc ( mem_ctx , struct id_map ) ;
2008-03-19 19:34:32 +01:00
NT_STATUS_HAVE_NO_MEMORY ( ids ) ;
ids - > sid = NULL ;
2009-04-23 16:37:11 +02:00
ids - > status = ID_UNKNOWN ;
2008-03-19 19:34:32 +01:00
2010-05-24 10:16:34 +10:00
ids - > xid . id = gid ;
ids - > xid . type = ID_TYPE_GID ;
2008-03-19 19:34:32 +01:00
2016-09-18 14:06:24 +02:00
status = wbc_xids_to_sids ( ids , 1 ) ;
2008-03-19 19:34:32 +01:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
r - > out . sid = ids - > sid ;
return NT_STATUS_OK ;
2005-05-19 15:45:25 +00:00
}
2007-01-17 14:49:36 +00:00
static NTSTATUS dcesrv_unixinfo_GetPWUid ( struct dcesrv_call_state * dce_call ,
2005-05-19 15:45:25 +00:00
TALLOC_CTX * mem_ctx ,
struct unixinfo_GetPWUid * r )
{
2009-11-21 19:03:59 +01:00
unsigned int i ;
2005-05-19 15:45:25 +00:00
2006-05-07 21:56:26 +00:00
* r - > out . count = 0 ;
2005-05-19 15:45:25 +00:00
2006-05-07 21:56:26 +00:00
r - > out . infos = talloc_zero_array ( mem_ctx , struct unixinfo_GetPWUidInfo ,
* r - > in . count ) ;
NT_STATUS_HAVE_NO_MEMORY ( r - > out . infos ) ;
* r - > out . count = * r - > in . count ;
2005-05-19 15:45:25 +00:00
2006-05-07 21:56:26 +00:00
for ( i = 0 ; i < * r - > in . count ; i + + ) {
2005-05-19 15:45:25 +00:00
uid_t uid ;
struct passwd * pwd ;
uid = r - > in . uids [ i ] ;
pwd = getpwuid ( uid ) ;
if ( pwd = = NULL ) {
DEBUG ( 10 , ( " uid %d not found \n " , uid ) ) ;
r - > out . infos [ i ] . homedir = " " ;
r - > out . infos [ i ] . shell = " " ;
r - > out . infos [ i ] . status = NT_STATUS_NO_SUCH_USER ;
continue ;
}
r - > out . infos [ i ] . homedir = talloc_strdup ( mem_ctx , pwd - > pw_dir ) ;
r - > out . infos [ i ] . shell = talloc_strdup ( mem_ctx , pwd - > pw_shell ) ;
if ( ( r - > out . infos [ i ] . homedir = = NULL ) | |
( r - > out . infos [ i ] . shell = = NULL ) ) {
r - > out . infos [ i ] . homedir = " " ;
r - > out . infos [ i ] . shell = " " ;
r - > out . infos [ i ] . status = NT_STATUS_NO_MEMORY ;
continue ;
}
r - > out . infos [ i ] . status = NT_STATUS_OK ;
}
return NT_STATUS_OK ;
}
/* include the generated boilerplate */
# include "librpc/gen_ndr/ndr_unixinfo_s.c"