2006-07-11 18:01:26 +00:00
/*
* Unix SMB / CIFS implementation .
* RPC Pipe client / server routines for 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
* 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 .
*/
/* This is the interface to the rpcunixinfo pipe. */
# include "includes.h"
# include "nterr.h"
2006-09-14 14:51:16 +00:00
2006-07-11 18:01:26 +00:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_SRV
/* Map a sid to a uid */
2007-01-18 10:18:59 +00:00
NTSTATUS _unixinfo_SidToUid ( pipes_struct * p , struct unixinfo_SidToUid * r )
2006-07-11 18:01:26 +00:00
{
2006-09-14 14:51:16 +00:00
uid_t real_uid ;
NTSTATUS status ;
2007-01-18 10:18:59 +00:00
* r - > out . uid = 0 ;
2006-07-11 18:01:26 +00:00
2007-01-18 10:18:59 +00:00
status = sid_to_uid ( & r - > in . sid , & real_uid ) ? NT_STATUS_OK : NT_STATUS_NONE_MAPPED ;
2006-09-14 14:51:16 +00:00
if ( NT_STATUS_IS_OK ( status ) )
2007-01-18 10:18:59 +00:00
* r - > out . uid = real_uid ;
2006-07-11 18:01:26 +00:00
2006-09-14 14:51:16 +00:00
return status ;
2006-07-11 18:01:26 +00:00
}
/* Map a uid to a sid */
2007-01-18 10:18:59 +00:00
NTSTATUS _unixinfo_UidToSid ( pipes_struct * p , struct unixinfo_UidToSid * r )
2006-07-11 18:01:26 +00:00
{
2006-09-14 14:51:16 +00:00
NTSTATUS status = NT_STATUS_NO_SUCH_USER ;
2006-07-11 18:01:26 +00:00
2007-01-18 10:18:59 +00:00
uid_to_sid ( r - > out . sid , ( uid_t ) r - > in . uid ) ;
2006-09-14 14:51:16 +00:00
status = NT_STATUS_OK ;
2006-07-11 18:01:26 +00:00
2006-09-14 14:51:16 +00:00
return status ;
2006-07-11 18:01:26 +00:00
}
/* Map a sid to a gid */
2007-01-18 10:18:59 +00:00
NTSTATUS _unixinfo_SidToGid ( pipes_struct * p , struct unixinfo_SidToGid * r )
2006-07-11 18:01:26 +00:00
{
2006-09-14 14:51:16 +00:00
gid_t real_gid ;
NTSTATUS status ;
2006-07-11 18:01:26 +00:00
2007-01-18 10:18:59 +00:00
* r - > out . gid = 0 ;
2006-07-11 18:01:26 +00:00
2007-01-18 10:18:59 +00:00
status = sid_to_gid ( & r - > in . sid , & real_gid ) ? NT_STATUS_OK : NT_STATUS_NONE_MAPPED ;
2006-09-14 14:51:16 +00:00
if ( NT_STATUS_IS_OK ( status ) )
2007-01-18 10:18:59 +00:00
* r - > out . gid = real_gid ;
2006-07-11 18:01:26 +00:00
2006-09-14 14:51:16 +00:00
return status ;
2006-07-11 18:01:26 +00:00
}
/* Map a gid to a sid */
2007-01-18 10:18:59 +00:00
NTSTATUS _unixinfo_GidToSid ( pipes_struct * p , struct unixinfo_GidToSid * r )
2006-07-11 18:01:26 +00:00
{
2006-09-14 14:51:16 +00:00
NTSTATUS status = NT_STATUS_NO_SUCH_GROUP ;
2006-07-11 18:01:26 +00:00
2007-01-18 10:18:59 +00:00
gid_to_sid ( r - > out . sid , ( gid_t ) r - > in . gid ) ;
2006-09-14 14:51:16 +00:00
status = NT_STATUS_OK ;
2006-07-11 18:01:26 +00:00
2006-09-14 14:51:16 +00:00
return status ;
2006-07-11 18:01:26 +00:00
}
/* Get unix struct passwd information */
2007-01-18 10:18:59 +00:00
NTSTATUS _unixinfo_GetPWUid ( pipes_struct * p , struct unixinfo_GetPWUid * r )
2006-07-11 18:01:26 +00:00
{
int i ;
2006-09-14 14:51:16 +00:00
NTSTATUS status ;
2006-07-11 18:01:26 +00:00
2007-01-18 10:18:59 +00:00
if ( * r - > in . count > 1023 )
2006-07-11 18:01:26 +00:00
return NT_STATUS_INVALID_PARAMETER ;
2006-09-14 14:51:16 +00:00
status = NT_STATUS_OK ;
2006-07-11 18:01:26 +00:00
2007-01-18 10:18:59 +00:00
for ( i = 0 ; i < * r - > in . count ; i + + ) {
2006-07-11 18:01:26 +00:00
struct passwd * pw ;
char * homedir , * shell ;
ssize_t len1 , len2 ;
2007-01-18 10:18:59 +00:00
r - > out . infos [ i ] . status = NT_STATUS_NO_SUCH_USER ;
r - > out . infos [ i ] . homedir = " " ;
r - > out . infos [ i ] . shell = " " ;
2006-07-11 18:01:26 +00:00
2007-01-18 10:18:59 +00:00
pw = getpwuid ( r - > in . uids [ i ] ) ;
2006-07-11 18:01:26 +00:00
if ( pw = = NULL ) {
2006-09-25 04:52:30 +00:00
DEBUG ( 10 , ( " Did not find uid %lld \n " ,
2007-01-18 10:18:59 +00:00
( long long int ) r - > in . uids [ i ] ) ) ;
2006-07-11 18:01:26 +00:00
continue ;
}
len1 = push_utf8_talloc ( p - > mem_ctx , & homedir , pw - > pw_dir ) ;
len2 = push_utf8_talloc ( p - > mem_ctx , & shell , pw - > pw_shell ) ;
if ( ( len1 < 0 ) | | ( len2 < 0 ) | | ( homedir = = NULL ) | |
( shell = = NULL ) ) {
DEBUG ( 3 , ( " push_utf8_talloc failed \n " ) ) ;
2007-01-18 10:18:59 +00:00
r - > out . infos [ i ] . status = NT_STATUS_NO_MEMORY ;
2006-07-11 18:01:26 +00:00
continue ;
}
2007-01-18 10:18:59 +00:00
r - > out . infos [ i ] . status = NT_STATUS_OK ;
r - > out . infos [ i ] . homedir = homedir ;
r - > out . infos [ i ] . shell = shell ;
2006-07-11 18:01:26 +00:00
}
2006-09-14 14:51:16 +00:00
return status ;
2006-07-11 18:01:26 +00:00
}