2004-09-24 01:20:30 +00:00
/*
Unix SMB / CIFS implementation .
Get NT ACLs from UNIX files .
2005-04-30 08:38:32 +00:00
Copyright ( C ) Tim Potter < tpot @ samba . org > 2005
2004-09-24 01:20:30 +00: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-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2004-09-24 01:20:30 +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/>.
2004-09-24 01:20:30 +00:00
*/
# include "includes.h"
2004-11-05 12:06:36 +00:00
# include "system/filesys.h"
2005-04-30 08:38:32 +00:00
# include "librpc/gen_ndr/ndr_xattr.h"
2008-10-11 21:05:38 +02:00
# include "../lib/util/wrap_xattr.h"
2007-12-13 22:46:27 +01:00
# include "param/param.h"
2005-04-30 08:38:32 +00:00
2005-06-17 06:13:47 +00:00
static void ntacl_print_debug_helper ( struct ndr_print * ndr , const char * format , . . . ) PRINTF_ATTRIBUTE ( 2 , 3 ) ;
static void ntacl_print_debug_helper ( struct ndr_print * ndr , const char * format , . . . )
2004-09-24 04:49:45 +00:00
{
2005-04-30 08:38:32 +00:00
va_list ap ;
char * s = NULL ;
int i ;
va_start ( ap , format ) ;
vasprintf ( & s , format , ap ) ;
va_end ( ap ) ;
for ( i = 0 ; i < ndr - > depth ; i + + ) {
printf ( " " ) ;
}
printf ( " %s \n " , s ) ;
free ( s ) ;
}
2007-11-02 08:49:23 +01:00
static NTSTATUS get_ntacl ( TALLOC_CTX * mem_ctx ,
char * filename ,
struct xattr_NTACL * * ntacl ,
2005-04-30 08:38:32 +00:00
ssize_t * ntacl_len )
{
DATA_BLOB blob ;
ssize_t size ;
2007-11-09 19:24:51 +01:00
enum ndr_err_code ndr_err ;
2005-04-30 08:38:32 +00:00
struct ndr_pull * ndr ;
2007-11-02 08:49:23 +01:00
* ntacl = talloc ( mem_ctx , struct xattr_NTACL ) ;
2005-04-30 08:38:32 +00:00
2006-06-05 21:48:29 +00:00
size = wrap_getxattr ( filename , XATTR_NTACL_NAME , NULL , 0 ) ;
2005-04-30 08:38:32 +00:00
if ( size < 0 ) {
fprintf ( stderr , " get_ntacl: %s \n " , strerror ( errno ) ) ;
return NT_STATUS_INTERNAL_ERROR ;
}
2007-09-08 13:27:14 +00:00
blob . data = talloc_array ( * ntacl , uint8_t , size ) ;
2006-06-05 21:48:29 +00:00
size = wrap_getxattr ( filename , XATTR_NTACL_NAME , blob . data , size ) ;
2006-04-02 11:18:34 +00:00
if ( size < 0 ) {
2005-04-30 08:38:32 +00:00
fprintf ( stderr , " get_ntacl: %s \n " , strerror ( errno ) ) ;
return NT_STATUS_INTERNAL_ERROR ;
}
2006-04-02 11:18:34 +00:00
blob . length = size ;
2005-04-30 08:38:32 +00:00
2007-12-13 23:23:25 +01:00
ndr = ndr_pull_init_blob ( & blob , NULL , NULL ) ;
2005-04-30 08:38:32 +00:00
2007-11-09 19:24:51 +01:00
ndr_err = ndr_pull_xattr_NTACL ( ndr , NDR_SCALARS | NDR_BUFFERS , * ntacl ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
return ndr_map_error2ntstatus ( ndr_err ) ;
2005-04-30 08:38:32 +00:00
}
2007-11-02 08:49:23 +01:00
return NT_STATUS_OK ;
2005-04-30 08:38:32 +00:00
}
2007-11-02 08:49:23 +01:00
static void print_ntacl ( TALLOC_CTX * mem_ctx ,
const char * fname ,
struct xattr_NTACL * ntacl )
2005-04-30 08:38:32 +00:00
{
2007-11-02 08:49:23 +01:00
struct ndr_print * pr ;
pr = talloc_zero ( mem_ctx , struct ndr_print ) ;
if ( ! pr ) return ;
pr - > print = ntacl_print_debug_helper ;
ndr_print_xattr_NTACL ( pr , fname , ntacl ) ;
talloc_free ( pr ) ;
2005-04-30 08:38:32 +00:00
}
int main ( int argc , char * argv [ ] )
{
2007-11-02 08:49:23 +01:00
NTSTATUS status ;
2005-04-30 08:38:32 +00:00
struct xattr_NTACL * ntacl ;
ssize_t ntacl_len ;
if ( argc ! = 2 ) {
fprintf ( stderr , " Usage: getntacl FILENAME \n " ) ;
return 1 ;
}
2007-11-02 08:49:23 +01:00
status = get_ntacl ( NULL , argv [ 1 ] , & ntacl , & ntacl_len ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
fprintf ( stderr , " get_ntacl failed: %s \n " , nt_errstr ( status ) ) ;
return 1 ;
}
2005-04-30 08:38:32 +00:00
2007-11-02 08:49:23 +01:00
print_ntacl ( ntacl , argv [ 1 ] , ntacl ) ;
2005-04-30 08:38:32 +00:00
2007-11-02 08:49:23 +01:00
talloc_free ( ntacl ) ;
2005-04-30 08:38:32 +00:00
return 0 ;
}