2006-07-11 22:01:26 +04:00
/*
Unix SMB / CIFS implementation .
RPC pipe client
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-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2006-07-11 22:01:26 +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/>.
2006-07-11 22:01:26 +04:00
*/
# include "includes.h"
# include "rpcclient.h"
static NTSTATUS cmd_unixinfo_uid2sid ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
uid_t uid ;
2006-11-23 00:40:23 +03:00
DOM_SID sid ;
2006-07-11 22:01:26 +04:00
NTSTATUS result ;
if ( argc ! = 2 ) {
printf ( " Usage: %s uid \n " , argv [ 0 ] ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
uid = atoi ( argv [ 1 ] ) ;
2006-09-06 22:32:20 +04:00
result = rpccli_unixinfo_UidToSid ( cli , mem_ctx , uid , & sid ) ;
2006-07-11 22:01:26 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
2006-11-23 00:40:23 +03:00
printf ( " %s \n " , sid_string_static ( & sid ) ) ;
2006-07-11 22:01:26 +04:00
done :
return result ;
}
static NTSTATUS cmd_unixinfo_sid2uid ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
2006-09-06 22:32:20 +04:00
uint64_t uid ;
2006-07-11 22:01:26 +04:00
DOM_SID sid ;
NTSTATUS result ;
if ( argc ! = 2 ) {
printf ( " Usage: %s sid \n " , argv [ 0 ] ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
if ( ! string_to_sid ( & sid , argv [ 1 ] ) ) {
result = NT_STATUS_INVALID_SID ;
goto done ;
}
2006-09-06 22:32:20 +04:00
result = rpccli_unixinfo_SidToUid ( cli , mem_ctx , sid , & uid ) ;
2006-07-11 22:01:26 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
2006-09-30 21:32:26 +04:00
printf ( " %llu \n " , ( unsigned long long ) uid ) ;
2006-07-11 22:01:26 +04:00
done :
return result ;
}
static NTSTATUS cmd_unixinfo_gid2sid ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
gid_t gid ;
2006-11-23 00:40:23 +03:00
DOM_SID sid ;
2006-07-11 22:01:26 +04:00
NTSTATUS result ;
if ( argc ! = 2 ) {
printf ( " Usage: %s gid \n " , argv [ 0 ] ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
gid = atoi ( argv [ 1 ] ) ;
2006-09-06 22:32:20 +04:00
result = rpccli_unixinfo_GidToSid ( cli , mem_ctx , gid , & sid ) ;
2006-07-11 22:01:26 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
2006-11-23 00:40:23 +03:00
printf ( " %s \n " , sid_string_static ( & sid ) ) ;
2006-07-11 22:01:26 +04:00
done :
return result ;
}
static NTSTATUS cmd_unixinfo_sid2gid ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
2006-09-06 22:32:20 +04:00
uint64_t gid ;
2006-07-11 22:01:26 +04:00
DOM_SID sid ;
NTSTATUS result ;
if ( argc ! = 2 ) {
printf ( " Usage: %s sid \n " , argv [ 0 ] ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
if ( ! string_to_sid ( & sid , argv [ 1 ] ) ) {
result = NT_STATUS_INVALID_SID ;
goto done ;
}
2006-09-06 22:32:20 +04:00
result = rpccli_unixinfo_SidToGid ( cli , mem_ctx , sid , & gid ) ;
2006-07-11 22:01:26 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
2006-09-30 21:32:26 +04:00
printf ( " %llu \n " , ( unsigned long long ) gid ) ;
2006-07-11 22:01:26 +04:00
done :
return result ;
}
static NTSTATUS cmd_unixinfo_getpwuid ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
2006-09-06 22:32:20 +04:00
uint64_t * uids ;
unsigned int i , num_uids ;
struct unixinfo_GetPWUidInfo * info ;
2006-07-11 22:01:26 +04:00
NTSTATUS result ;
if ( argc < 2 ) {
printf ( " Usage: %s uid [uid2 uid3 ...] \n " , argv [ 0 ] ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
num_uids = argc - 1 ;
2006-09-06 22:32:20 +04:00
uids = TALLOC_ARRAY ( mem_ctx , uint64_t , num_uids ) ;
2006-07-11 22:01:26 +04:00
if ( uids = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < num_uids ; i + + ) {
uids [ i ] = atoi ( argv [ i + 1 ] ) ;
}
2007-01-16 18:42:03 +03:00
info = TALLOC_ARRAY ( mem_ctx , struct unixinfo_GetPWUidInfo , num_uids ) ;
if ( info = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2006-11-19 20:56:35 +03:00
result = rpccli_unixinfo_GetPWUid ( cli , mem_ctx , & num_uids , uids ,
2007-01-16 18:42:03 +03:00
info ) ;
2006-07-11 22:01:26 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
for ( i = 0 ; i < num_uids ; i + + ) {
if ( NT_STATUS_IS_OK ( info [ i ] . status ) ) {
2006-09-30 21:32:26 +04:00
printf ( " %llu:%s:%s \n " , ( unsigned long long ) uids [ i ] ,
info [ i ] . homedir , info [ i ] . shell ) ;
2006-07-11 22:01:26 +04:00
} else {
2006-09-30 21:32:26 +04:00
printf ( " %llu:%s \n " , ( unsigned long long ) uids [ i ] ,
nt_errstr ( info [ i ] . status ) ) ;
2006-07-11 22:01:26 +04:00
}
}
return NT_STATUS_OK ;
}
/* List of commands exported by this module */
struct cmd_set unixinfo_commands [ ] = {
{ " UNIXINFO " } ,
{ " uid2sid " , RPC_RTYPE_NTSTATUS , cmd_unixinfo_uid2sid , NULL ,
PI_UNIXINFO , NULL , " Convert a uid to a sid " , " " } ,
{ " sid2uid " , RPC_RTYPE_NTSTATUS , cmd_unixinfo_sid2uid , NULL ,
PI_UNIXINFO , NULL , " Convert a sid to a uid " , " " } ,
{ " gid2sid " , RPC_RTYPE_NTSTATUS , cmd_unixinfo_gid2sid , NULL ,
PI_UNIXINFO , NULL , " Convert a gid to a sid " , " " } ,
{ " sid2gid " , RPC_RTYPE_NTSTATUS , cmd_unixinfo_sid2gid , NULL ,
PI_UNIXINFO , NULL , " Convert a sid to a gid " , " " } ,
{ " getpwuid " , RPC_RTYPE_NTSTATUS , cmd_unixinfo_getpwuid , NULL ,
PI_UNIXINFO , NULL , " Get passwd info " , " " } ,
{ NULL }
} ;