2003-11-13 00:46:39 +03:00
# include <stdlib.h>
# include <string.h>
# include <errno.h>
# include <popt.h>
# include "libsmbclient.h"
2005-03-31 09:06:04 +04:00
# include "get_auth_data_fn.h"
2003-11-13 00:46:39 +03:00
enum acl_mode
{
2008-01-14 01:10:06 +03:00
SMB_ACL_LIST ,
2003-11-13 00:46:39 +03:00
SMB_ACL_GET ,
SMB_ACL_SET ,
SMB_ACL_DELETE ,
SMB_ACL_MODIFY ,
SMB_ACL_ADD ,
SMB_ACL_CHOWN ,
SMB_ACL_CHGRP
} ;
int main ( int argc , const char * argv [ ] )
{
int opt ;
2015-02-25 15:19:44 +03:00
int flags = 0 ;
2003-11-13 00:46:39 +03:00
int debug = 0 ;
int numeric = 0 ;
2008-05-30 18:38:35 +04:00
int stat_and_retry = 0 ;
r18009: Fixes bug 4026.
This completes the work Jeremy began last week, disambiguating the meaning of
c_time. (In POSIX terminology, c_time means "status Change time", not "create
time".) All uses of c_time, a_time and m_time have now been replaced with
change_time, access_time, and write_time, and when creation time is intended,
create_time is used.
Additionally, the capability of setting and retrieving the create time have
been added to the smbc_setxattr() and smbc_getxattr() functions. An example
of setting all four times can be seen with the program
examples/libsmbclient/testacl
with the following command line similar to:
testacl -f -S "system.*:CREATE_TIME:1000000000,ACCESS_TIME:1000000060,WRITE_TIME:1000000120,CHANGE_TIME:1000000180" 'smb://server/share/testfile.txt'
The -f option turns on the new mode which uses full time names in the
attribute specification (e.g. ACCESS_TIME vs A_TIME).
(This used to be commit 8e119b64f1d92026dda855d904be09912a40601c)
2006-09-03 01:47:56 +04:00
int full_time_names = 0 ;
2008-01-14 01:10:06 +03:00
enum acl_mode mode = SMB_ACL_LIST ;
2011-10-20 01:52:41 +04:00
static const char * the_acl = NULL ;
2003-11-13 00:46:39 +03:00
int ret ;
char * p ;
2011-10-20 01:52:41 +04:00
const char * debugstr ;
2003-11-13 00:46:39 +03:00
char path [ 1024 ] ;
char value [ 1024 ] ;
poptContext pc ;
2008-05-30 18:38:35 +04:00
struct stat st ;
2003-11-13 00:46:39 +03:00
struct poptOption long_options [ ] =
{
POPT_AUTOHELP
{
" numeric " , ' n ' , POPT_ARG_NONE , & numeric ,
1 , " Don't resolve sids or masks to names "
} ,
{
" debug " , ' d ' , POPT_ARG_INT , & debug ,
0 , " Set debug level (0-100) "
} ,
r18009: Fixes bug 4026.
This completes the work Jeremy began last week, disambiguating the meaning of
c_time. (In POSIX terminology, c_time means "status Change time", not "create
time".) All uses of c_time, a_time and m_time have now been replaced with
change_time, access_time, and write_time, and when creation time is intended,
create_time is used.
Additionally, the capability of setting and retrieving the create time have
been added to the smbc_setxattr() and smbc_getxattr() functions. An example
of setting all four times can be seen with the program
examples/libsmbclient/testacl
with the following command line similar to:
testacl -f -S "system.*:CREATE_TIME:1000000000,ACCESS_TIME:1000000060,WRITE_TIME:1000000120,CHANGE_TIME:1000000180" 'smb://server/share/testfile.txt'
The -f option turns on the new mode which uses full time names in the
attribute specification (e.g. ACCESS_TIME vs A_TIME).
(This used to be commit 8e119b64f1d92026dda855d904be09912a40601c)
2006-09-03 01:47:56 +04:00
{
" full_time_names " , ' f ' , POPT_ARG_NONE , & full_time_names ,
1 ,
" Use new style xattr names, which include CREATE_TIME "
} ,
2003-11-13 00:46:39 +03:00
{
" delete " , ' D ' , POPT_ARG_STRING , NULL ,
' D ' , " Delete an acl " , " ACL "
} ,
{
" modify " , ' M ' , POPT_ARG_STRING , NULL ,
' M ' , " Modify an acl " , " ACL "
} ,
{
" add " , ' a ' , POPT_ARG_STRING , NULL ,
' a ' , " Add an acl " , " ACL "
} ,
{
" set " , ' S ' , POPT_ARG_STRING , NULL ,
' S ' , " Set acls " , " ACLS "
} ,
{
" chown " , ' C ' , POPT_ARG_STRING , NULL ,
' C ' , " Change ownership of a file " , " USERNAME "
} ,
{
" chgrp " , ' G ' , POPT_ARG_STRING , NULL ,
' G ' , " Change group ownership of a file " , " GROUPNAME "
} ,
{
" get " , ' g ' , POPT_ARG_STRING , NULL ,
' g ' , " Get a specific acl attribute " , " ACL "
} ,
2008-05-30 18:38:35 +04:00
{
" stat_and_retry " , ' R ' , POPT_ARG_NONE , & stat_and_retry ,
1 , " After 'get' do 'stat' and another 'get' "
} ,
2003-11-13 00:46:39 +03:00
{
NULL
}
} ;
setbuf ( stdout , NULL ) ;
pc = poptGetContext ( " smbcacls " , argc , argv , long_options , 0 ) ;
poptSetOtherOptionHelp ( pc , " smb://server1/share1/filename " ) ;
while ( ( opt = poptGetNextOpt ( pc ) ) ! = - 1 ) {
switch ( opt ) {
case ' S ' :
the_acl = strdup ( poptGetOptArg ( pc ) ) ;
mode = SMB_ACL_SET ;
break ;
case ' D ' :
the_acl = strdup ( poptGetOptArg ( pc ) ) ;
mode = SMB_ACL_DELETE ;
break ;
case ' M ' :
the_acl = strdup ( poptGetOptArg ( pc ) ) ;
mode = SMB_ACL_MODIFY ;
break ;
case ' a ' :
the_acl = strdup ( poptGetOptArg ( pc ) ) ;
mode = SMB_ACL_ADD ;
break ;
case ' g ' :
the_acl = strdup ( poptGetOptArg ( pc ) ) ;
mode = SMB_ACL_GET ;
break ;
case ' C ' :
the_acl = strdup ( poptGetOptArg ( pc ) ) ;
mode = SMB_ACL_CHOWN ;
break ;
case ' G ' :
the_acl = strdup ( poptGetOptArg ( pc ) ) ;
mode = SMB_ACL_CHGRP ;
break ;
}
}
/* Make connection to server */
if ( ! poptPeekArg ( pc ) ) {
poptPrintUsage ( pc , stderr , 0 ) ;
return 1 ;
}
2016-03-17 01:09:12 +03:00
strncpy ( path , poptGetArg ( pc ) , sizeof ( path ) ) ;
path [ sizeof ( path ) - 1 ] = ' \0 ' ;
2003-11-13 00:46:39 +03:00
if ( smbc_init ( get_auth_data_fn , debug ) ! = 0 )
{
printf ( " Could not initialize smbc_ library \n " ) ;
return 1 ;
}
r18009: Fixes bug 4026.
This completes the work Jeremy began last week, disambiguating the meaning of
c_time. (In POSIX terminology, c_time means "status Change time", not "create
time".) All uses of c_time, a_time and m_time have now been replaced with
change_time, access_time, and write_time, and when creation time is intended,
create_time is used.
Additionally, the capability of setting and retrieving the create time have
been added to the smbc_setxattr() and smbc_getxattr() functions. An example
of setting all four times can be seen with the program
examples/libsmbclient/testacl
with the following command line similar to:
testacl -f -S "system.*:CREATE_TIME:1000000000,ACCESS_TIME:1000000060,WRITE_TIME:1000000120,CHANGE_TIME:1000000180" 'smb://server/share/testfile.txt'
The -f option turns on the new mode which uses full time names in the
attribute specification (e.g. ACCESS_TIME vs A_TIME).
(This used to be commit 8e119b64f1d92026dda855d904be09912a40601c)
2006-09-03 01:47:56 +04:00
if ( full_time_names ) {
SMBCCTX * context = smbc_set_context ( NULL ) ;
2008-03-03 00:21:48 +03:00
smbc_setOptionFullTimeNames ( context , 1 ) ;
r18009: Fixes bug 4026.
This completes the work Jeremy began last week, disambiguating the meaning of
c_time. (In POSIX terminology, c_time means "status Change time", not "create
time".) All uses of c_time, a_time and m_time have now been replaced with
change_time, access_time, and write_time, and when creation time is intended,
create_time is used.
Additionally, the capability of setting and retrieving the create time have
been added to the smbc_setxattr() and smbc_getxattr() functions. An example
of setting all four times can be seen with the program
examples/libsmbclient/testacl
with the following command line similar to:
testacl -f -S "system.*:CREATE_TIME:1000000000,ACCESS_TIME:1000000060,WRITE_TIME:1000000120,CHANGE_TIME:1000000180" 'smb://server/share/testfile.txt'
The -f option turns on the new mode which uses full time names in the
attribute specification (e.g. ACCESS_TIME vs A_TIME).
(This used to be commit 8e119b64f1d92026dda855d904be09912a40601c)
2006-09-03 01:47:56 +04:00
}
2003-11-13 00:46:39 +03:00
/* Perform requested action */
switch ( mode )
{
2008-01-14 01:10:06 +03:00
case SMB_ACL_LIST :
ret = smbc_listxattr ( path , value , sizeof ( value ) - 2 ) ;
if ( ret < 0 )
{
printf ( " Could not get attribute list for [%s] %d: %s \n " ,
path , errno , strerror ( errno ) ) ;
return 1 ;
}
/*
* The list of attributes has a series of null - terminated strings .
* The list of strings terminates with an extra null byte , thus two in
* a row . Ensure that our buffer , which is conceivably shorter than
* the list of attributes , actually ends with two null bytes in a row .
*/
value [ sizeof ( value ) - 2 ] = ' \0 ' ;
value [ sizeof ( value ) - 1 ] = ' \0 ' ;
printf ( " Supported attributes: \n " ) ;
for ( p = value ; * p ; p + = strlen ( p ) + 1 )
{
printf ( " \t %s \n " , p ) ;
}
break ;
2003-11-13 00:46:39 +03:00
case SMB_ACL_GET :
2008-05-30 18:38:35 +04:00
do
2003-11-13 00:46:39 +03:00
{
2008-05-30 18:38:35 +04:00
if ( the_acl = = NULL )
2003-11-13 00:46:39 +03:00
{
2008-05-30 18:38:35 +04:00
if ( numeric )
{
the_acl = " system.* " ;
}
else
{
the_acl = " system.*+ " ;
}
2003-11-13 00:46:39 +03:00
}
2008-05-30 18:38:35 +04:00
ret = smbc_getxattr ( path , the_acl , value , sizeof ( value ) ) ;
if ( ret < 0 )
2003-11-13 00:46:39 +03:00
{
2008-05-30 18:38:35 +04:00
printf ( " Could not get attributes for [%s] %d: %s \n " ,
path , errno , strerror ( errno ) ) ;
return 1 ;
2003-11-13 00:46:39 +03:00
}
2008-05-30 18:38:35 +04:00
printf ( " Attributes for [%s] are: \n %s \n " , path , value ) ;
if ( stat_and_retry )
{
if ( smbc_stat ( path , & st ) < 0 )
{
perror ( " smbc_stat " ) ;
return 1 ;
}
}
- - stat_and_retry ;
} while ( stat_and_retry > = 0 ) ;
2003-11-13 00:46:39 +03:00
break ;
case SMB_ACL_ADD :
flags = SMBC_XATTR_FLAG_CREATE ;
debugstr = " add attributes " ;
goto do_set ;
case SMB_ACL_MODIFY :
flags = SMBC_XATTR_FLAG_REPLACE ;
debugstr = " modify attributes " ;
goto do_set ;
case SMB_ACL_CHOWN :
snprintf ( value , sizeof ( value ) ,
" system.nt_sec_desc.owner%s:%s " ,
numeric ? " " : " + " , the_acl ) ;
the_acl = value ;
debugstr = " chown owner " ;
goto do_set ;
case SMB_ACL_CHGRP :
snprintf ( value , sizeof ( value ) ,
" system.nt_sec_desc.group%s:%s " ,
numeric ? " " : " + " , the_acl ) ;
the_acl = value ;
debugstr = " change group " ;
goto do_set ;
case SMB_ACL_SET :
flags = 0 ;
debugstr = " set attributes " ;
do_set :
if ( ( p = strchr ( the_acl , ' : ' ) ) = = NULL )
{
printf ( " Missing value. ACL must be name:value pair \n " ) ;
return 1 ;
}
* p + + = ' \0 ' ;
ret = smbc_setxattr ( path , the_acl , p , strlen ( p ) , flags ) ;
if ( ret < 0 )
{
printf ( " Could not %s for [%s] %d: %s \n " ,
debugstr , path , errno , strerror ( errno ) ) ;
return 1 ;
}
break ;
case SMB_ACL_DELETE :
ret = smbc_removexattr ( path , the_acl ) ;
if ( ret < 0 )
{
printf ( " Could not remove attribute %s for [%s] %d:%s \n " ,
the_acl , path , errno , strerror ( errno ) ) ;
return 1 ;
}
break ;
default :
printf ( " operation not yet implemented \n " ) ;
break ;
}
return 0 ;
}