2003-04-11 23:32:00 +00:00
/*
Unix SMB / CIFS implementation .
QUOTA get / set utility
Copyright ( C ) Andrew Tridgell 2000
Copyright ( C ) Tim Potter 2000
Copyright ( C ) Jeremy Allison 2000
Copyright ( C ) Stefan ( metze ) Metzmacher 2003
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 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-04-11 23:32:00 +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 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-04-11 23:32:00 +00:00
*/
# include "includes.h"
2007-12-03 18:48:41 -08:00
static char * server ;
2003-04-11 23:32:00 +00:00
/* numeric is set when the user wants numeric SIDs and ACEs rather
than going via LSA calls to resolve them */
2007-10-18 17:40:25 -07:00
static bool numeric ;
static bool verbose ;
2003-04-11 23:32:00 +00:00
enum todo_values { NOOP_QUOTA = 0 , FS_QUOTA , USER_QUOTA , LIST_QUOTA , SET_QUOTA } ;
enum exit_values { EXIT_OK , EXIT_FAILED , EXIT_PARSE_ERROR } ;
2005-09-30 17:13:37 +00:00
static struct cli_state * cli_ipc ;
static struct rpc_pipe_client * global_pipe_hnd ;
2003-04-11 23:32:00 +00:00
static POLICY_HND pol ;
2007-10-18 17:40:25 -07:00
static bool got_policy_hnd ;
2003-04-11 23:32:00 +00:00
static struct cli_state * connect_one ( const char * share ) ;
/* Open cli connection and policy handle */
2007-10-18 17:40:25 -07:00
static bool cli_open_policy_hnd ( void )
2003-04-11 23:32:00 +00:00
{
/* Initialise cli LSA connection */
if ( ! cli_ipc ) {
2005-09-30 17:13:37 +00:00
NTSTATUS ret ;
2003-04-11 23:32:00 +00:00
cli_ipc = connect_one ( " IPC$ " ) ;
2005-09-30 17:13:37 +00:00
global_pipe_hnd = cli_rpc_pipe_open_noauth ( cli_ipc , PI_LSARPC , & ret ) ;
if ( ! global_pipe_hnd ) {
2003-04-11 23:32:00 +00:00
return False ;
}
}
2007-12-03 18:48:41 -08:00
2003-04-11 23:32:00 +00:00
/* Open policy handle */
if ( ! got_policy_hnd ) {
/* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED,
but NT sends 0x2000000 so we might as well do it too . */
2007-11-29 13:24:54 -08:00
if ( ! NT_STATUS_IS_OK ( rpccli_lsa_open_policy ( global_pipe_hnd , talloc_tos ( ) , True ,
2003-04-11 23:32:00 +00:00
GENERIC_EXECUTE_ACCESS , & pol ) ) ) {
return False ;
}
got_policy_hnd = True ;
}
return True ;
}
/* convert a SID to a string, either numeric or username/group */
2007-10-18 17:40:25 -07:00
static void SidToString ( fstring str , DOM_SID * sid , bool _numeric )
2003-04-11 23:32:00 +00:00
{
char * * domains = NULL ;
char * * names = NULL ;
2006-09-08 14:28:06 +00:00
enum lsa_SidType * types = NULL ;
2003-04-11 23:32:00 +00:00
sid_to_string ( str , sid ) ;
if ( _numeric ) return ;
/* Ask LSA to convert the sid to a name */
if ( ! cli_open_policy_hnd ( ) | |
2007-11-29 13:24:54 -08:00
! NT_STATUS_IS_OK ( rpccli_lsa_lookup_sids ( global_pipe_hnd , talloc_tos ( ) ,
2003-04-11 23:32:00 +00:00
& pol , 1 , sid , & domains ,
& names , & types ) ) | |
! domains | | ! domains [ 0 ] | | ! names | | ! names [ 0 ] ) {
return ;
}
/* Converted OK */
slprintf ( str , sizeof ( fstring ) - 1 , " %s%s%s " ,
domains [ 0 ] , lp_winbind_separator ( ) ,
names [ 0 ] ) ;
}
/* convert a string to a SID, either numeric or username/group */
2007-10-18 17:40:25 -07:00
static bool StringToSid ( DOM_SID * sid , const char * str )
2003-04-11 23:32:00 +00:00
{
2006-09-08 14:28:06 +00:00
enum lsa_SidType * types = NULL ;
2003-04-11 23:32:00 +00:00
DOM_SID * sids = NULL ;
2007-10-18 17:40:25 -07:00
bool result = True ;
2003-04-11 23:32:00 +00:00
if ( strncmp ( str , " S- " , 2 ) = = 0 ) {
return string_to_sid ( sid , str ) ;
}
if ( ! cli_open_policy_hnd ( ) | |
2007-11-29 13:24:54 -08:00
! NT_STATUS_IS_OK ( rpccli_lsa_lookup_names ( global_pipe_hnd , talloc_tos ( ) ,
2007-06-27 11:42:17 +00:00
& pol , 1 , & str , NULL , 1 , & sids ,
2003-04-11 23:32:00 +00:00
& types ) ) ) {
result = False ;
goto done ;
}
sid_copy ( sid , & sids [ 0 ] ) ;
done :
return result ;
}
# define QUOTA_GET 1
# define QUOTA_SETLIM 2
# define QUOTA_SETFLAGS 3
# define QUOTA_LIST 4
enum { PARSE_FLAGS , PARSE_LIM } ;
2007-12-03 18:48:41 -08:00
static int parse_quota_set ( TALLOC_CTX * ctx ,
char * set_str ,
char * * pp_username_str ,
enum SMB_QUOTA_TYPE * qtype ,
int * cmd ,
SMB_NTQUOTA_STRUCT * pqt )
2003-04-11 23:32:00 +00:00
{
char * p = set_str , * p2 ;
int todo ;
2007-10-18 17:40:25 -07:00
bool stop = False ;
bool enable = False ;
bool deny = False ;
2007-12-03 18:48:41 -08:00
* pp_username_str = NULL ;
2003-10-22 23:38:20 +00:00
if ( strnequal ( set_str , " UQLIM: " , 6 ) ) {
2003-04-11 23:32:00 +00:00
p + = 6 ;
* qtype = SMB_USER_QUOTA_TYPE ;
* cmd = QUOTA_SETLIM ;
todo = PARSE_LIM ;
if ( ( p2 = strstr ( p , " : " ) ) = = NULL ) {
return - 1 ;
}
2007-12-03 18:48:41 -08:00
2003-04-11 23:32:00 +00:00
* p2 = ' \0 ' ;
p2 + + ;
2007-12-03 18:48:41 -08:00
* pp_username_str = talloc_strdup ( ctx , p ) ;
2003-04-11 23:32:00 +00:00
p = p2 ;
2003-10-22 23:38:20 +00:00
} else if ( strnequal ( set_str , " FSQLIM: " , 7 ) ) {
2003-04-11 23:32:00 +00:00
p + = 7 ;
* qtype = SMB_USER_FS_QUOTA_TYPE ;
* cmd = QUOTA_SETLIM ;
todo = PARSE_LIM ;
2003-10-22 23:38:20 +00:00
} else if ( strnequal ( set_str , " FSQFLAGS: " , 9 ) ) {
2003-04-11 23:32:00 +00:00
p + = 9 ;
todo = PARSE_FLAGS ;
* qtype = SMB_USER_FS_QUOTA_TYPE ;
* cmd = QUOTA_SETFLAGS ;
} else {
return - 1 ;
}
switch ( todo ) {
case PARSE_LIM :
# if defined(HAVE_LONGLONG)
if ( sscanf ( p , " %llu/%llu " , & pqt - > softlim , & pqt - > hardlim ) ! = 2 ) {
# else
if ( sscanf ( p , " %lu/%lu " , & pqt - > softlim , & pqt - > hardlim ) ! = 2 ) {
# endif
return - 1 ;
}
2007-12-03 18:48:41 -08:00
2003-04-11 23:32:00 +00:00
break ;
case PARSE_FLAGS :
while ( ! stop ) {
if ( ( p2 = strstr ( p , " / " ) ) = = NULL ) {
stop = True ;
} else {
* p2 = ' \0 ' ;
p2 + + ;
}
2003-10-22 23:38:20 +00:00
if ( strnequal ( p , " QUOTA_ENABLED " , 13 ) ) {
2003-04-11 23:32:00 +00:00
enable = True ;
2003-10-22 23:38:20 +00:00
} else if ( strnequal ( p , " DENY_DISK " , 9 ) ) {
2003-04-11 23:32:00 +00:00
deny = True ;
2003-10-22 23:38:20 +00:00
} else if ( strnequal ( p , " LOG_SOFTLIMIT " , 13 ) ) {
2003-04-11 23:32:00 +00:00
pqt - > qflags | = QUOTAS_LOG_THRESHOLD ;
2003-10-22 23:38:20 +00:00
} else if ( strnequal ( p , " LOG_HARDLIMIT " , 13 ) ) {
2003-04-11 23:32:00 +00:00
pqt - > qflags | = QUOTAS_LOG_LIMIT ;
} else {
return - 1 ;
}
p = p2 ;
}
if ( deny ) {
pqt - > qflags | = QUOTAS_DENY_DISK ;
} else if ( enable ) {
pqt - > qflags | = QUOTAS_ENABLED ;
}
2007-12-03 18:48:41 -08:00
break ;
2003-04-11 23:32:00 +00:00
}
return 0 ;
}
2007-12-03 18:48:41 -08:00
static int do_quota ( struct cli_state * cli ,
enum SMB_QUOTA_TYPE qtype ,
uint16 cmd ,
const char * username_str ,
SMB_NTQUOTA_STRUCT * pqt )
2003-04-11 23:32:00 +00:00
{
uint32 fs_attrs = 0 ;
int quota_fnum = 0 ;
SMB_NTQUOTA_LIST * qtl = NULL ;
SMB_NTQUOTA_STRUCT qt ;
ZERO_STRUCT ( qt ) ;
if ( ! cli_get_fs_attr_info ( cli , & fs_attrs ) ) {
d_printf ( " Failed to get the filesystem attributes %s. \n " ,
cli_errstr ( cli ) ) ;
return - 1 ;
}
if ( ! ( fs_attrs & FILE_VOLUME_QUOTAS ) ) {
d_printf ( " Quotas are not supported by the server. \n " ) ;
2007-12-03 18:48:41 -08:00
return 0 ;
2003-04-11 23:32:00 +00:00
}
if ( ! cli_get_quota_handle ( cli , & quota_fnum ) ) {
2004-09-17 15:09:20 +00:00
d_printf ( " Quotas are not enabled on this share. \n " ) ;
d_printf ( " Failed to open %s %s. \n " ,
FAKE_FILE_NAME_QUOTA_WIN32 , cli_errstr ( cli ) ) ;
2003-04-11 23:32:00 +00:00
return - 1 ;
}
switch ( qtype ) {
case SMB_USER_QUOTA_TYPE :
if ( ! StringToSid ( & qt . sid , username_str ) ) {
d_printf ( " StringToSid() failed for [%s] \n " , username_str ) ;
return - 1 ;
}
2007-12-03 18:48:41 -08:00
2003-04-11 23:32:00 +00:00
switch ( cmd ) {
case QUOTA_GET :
if ( ! cli_get_user_quota ( cli , quota_fnum , & qt ) ) {
d_printf ( " %s cli_get_user_quota %s \n " ,
cli_errstr ( cli ) , username_str ) ;
return - 1 ;
}
dump_ntquota ( & qt , verbose , numeric , SidToString ) ;
break ;
case QUOTA_SETLIM :
pqt - > sid = qt . sid ;
if ( ! cli_set_user_quota ( cli , quota_fnum , pqt ) ) {
d_printf ( " %s cli_set_user_quota %s \n " ,
cli_errstr ( cli ) , username_str ) ;
return - 1 ;
}
if ( ! cli_get_user_quota ( cli , quota_fnum , & qt ) ) {
d_printf ( " %s cli_get_user_quota %s \n " ,
cli_errstr ( cli ) , username_str ) ;
return - 1 ;
}
dump_ntquota ( & qt , verbose , numeric , SidToString ) ;
break ;
case QUOTA_LIST :
if ( ! cli_list_user_quota ( cli , quota_fnum , & qtl ) ) {
d_printf ( " %s cli_set_user_quota %s \n " ,
cli_errstr ( cli ) , username_str ) ;
return - 1 ;
}
dump_ntquota_list ( & qtl , verbose , numeric , SidToString ) ;
2007-12-03 18:48:41 -08:00
free_ntquota_list ( & qtl ) ;
2003-04-11 23:32:00 +00:00
break ;
default :
d_printf ( " Unknown Error \n " ) ;
return - 1 ;
2007-12-03 18:48:41 -08:00
}
2003-04-11 23:32:00 +00:00
break ;
case SMB_USER_FS_QUOTA_TYPE :
switch ( cmd ) {
case QUOTA_GET :
if ( ! cli_get_fs_quota_info ( cli , quota_fnum , & qt ) ) {
d_printf ( " %s cli_get_fs_quota_info \n " ,
cli_errstr ( cli ) ) ;
return - 1 ;
}
dump_ntquota ( & qt , True , numeric , NULL ) ;
break ;
case QUOTA_SETLIM :
if ( ! cli_get_fs_quota_info ( cli , quota_fnum , & qt ) ) {
d_printf ( " %s cli_get_fs_quota_info \n " ,
cli_errstr ( cli ) ) ;
return - 1 ;
}
qt . softlim = pqt - > softlim ;
qt . hardlim = pqt - > hardlim ;
if ( ! cli_set_fs_quota_info ( cli , quota_fnum , & qt ) ) {
d_printf ( " %s cli_set_fs_quota_info \n " ,
cli_errstr ( cli ) ) ;
return - 1 ;
}
if ( ! cli_get_fs_quota_info ( cli , quota_fnum , & qt ) ) {
d_printf ( " %s cli_get_fs_quota_info \n " ,
cli_errstr ( cli ) ) ;
return - 1 ;
}
dump_ntquota ( & qt , True , numeric , NULL ) ;
break ;
case QUOTA_SETFLAGS :
if ( ! cli_get_fs_quota_info ( cli , quota_fnum , & qt ) ) {
d_printf ( " %s cli_get_fs_quota_info \n " ,
cli_errstr ( cli ) ) ;
return - 1 ;
}
qt . qflags = pqt - > qflags ;
if ( ! cli_set_fs_quota_info ( cli , quota_fnum , & qt ) ) {
d_printf ( " %s cli_set_fs_quota_info \n " ,
cli_errstr ( cli ) ) ;
return - 1 ;
}
if ( ! cli_get_fs_quota_info ( cli , quota_fnum , & qt ) ) {
d_printf ( " %s cli_get_fs_quota_info \n " ,
cli_errstr ( cli ) ) ;
return - 1 ;
}
dump_ntquota ( & qt , True , numeric , NULL ) ;
break ;
default :
d_printf ( " Unknown Error \n " ) ;
return - 1 ;
2007-12-03 18:48:41 -08:00
}
2003-04-11 23:32:00 +00:00
break ;
default :
d_printf ( " Unknown Error \n " ) ;
return - 1 ;
}
cli_close ( cli , quota_fnum ) ;
return 0 ;
}
2007-10-24 14:16:54 -07:00
/*****************************************************
Return a connection to a server .
2003-04-11 23:32:00 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-24 14:16:54 -07:00
2003-04-11 23:32:00 +00:00
static struct cli_state * connect_one ( const char * share )
{
struct cli_state * c ;
2007-10-24 14:16:54 -07:00
struct sockaddr_storage ss ;
2003-04-11 23:32:00 +00:00
NTSTATUS nt_status ;
2007-10-27 20:29:36 -07:00
zero_addr ( & ss ) ;
2007-10-24 14:16:54 -07:00
2007-12-06 18:58:01 -08:00
if ( ! get_cmdline_auth_info_got_pass ( ) ) {
2003-04-11 23:32:00 +00:00
char * pass = getpass ( " Password: " ) ;
if ( pass ) {
2007-12-06 18:58:01 -08:00
set_cmdline_auth_info_password ( pass ) ;
2003-04-11 23:32:00 +00:00
}
}
if ( NT_STATUS_IS_OK ( nt_status = cli_full_connection ( & c , global_myname ( ) , server ,
2007-12-06 18:58:01 -08:00
& ss , 0 ,
share , " ????? " ,
get_cmdline_auth_info_username ( ) ,
lp_workgroup ( ) ,
get_cmdline_auth_info_password ( ) ,
0 ,
get_cmdline_auth_info_signing_state ( ) ,
NULL ) ) ) {
2003-04-11 23:32:00 +00:00
return c ;
} else {
DEBUG ( 0 , ( " cli_full_connection failed! (%s) \n " , nt_errstr ( nt_status ) ) ) ;
return NULL ;
}
}
/****************************************************************************
main program
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int main ( int argc , const char * argv [ ] )
{
char * share ;
int opt ;
int result ;
int todo = 0 ;
2007-12-03 18:48:41 -08:00
char * username_str = NULL ;
char * path = NULL ;
char * set_str = NULL ;
2005-12-03 06:58:54 +00:00
enum SMB_QUOTA_TYPE qtype = SMB_INVALID_QUOTA_TYPE ;
2003-04-11 23:32:00 +00:00
int cmd = 0 ;
2007-10-18 17:40:25 -07:00
static bool test_args = False ;
2003-04-11 23:32:00 +00:00
struct cli_state * cli ;
2007-10-18 17:40:25 -07:00
bool fix_user = False ;
2003-04-11 23:32:00 +00:00
SMB_NTQUOTA_STRUCT qt ;
2007-09-04 05:39:06 +00:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2003-04-11 23:32:00 +00:00
poptContext pc ;
struct poptOption long_options [ ] = {
POPT_AUTOHELP
{ " user " , ' u ' , POPT_ARG_STRING , NULL , ' u ' , " Show quotas for user " , " user " } ,
{ " list " , ' L ' , POPT_ARG_NONE , NULL , ' L ' , " List user quotas " } ,
{ " fs " , ' F ' , POPT_ARG_NONE , NULL , ' F ' , " Show filesystem quotas " } ,
{ " set " , ' S ' , POPT_ARG_STRING , NULL , ' S ' , " Set acls \n \
SETSTRING : \ n \
UQLIM : < username > / < softlimit > / < hardlimit > for user quotas \ n \
FSQLIM : < softlimit > / < hardlimit > for filesystem defaults \ n \
FSQFLAGS : QUOTA_ENABLED / DENY_DISK / LOG_SOFTLIMIT / LOG_HARD_LIMIT " , " SETSTRING " },
2007-10-19 11:38:36 -07:00
{ " numeric " , ' n ' , POPT_ARG_NONE , NULL , ' n ' , " Don't resolve sids or limits to names " } ,
{ " verbose " , ' v ' , POPT_ARG_NONE , NULL , ' v ' , " be verbose " } ,
{ " test-args " , ' t ' , POPT_ARG_NONE , NULL , ' r ' , " Test arguments " } ,
2003-04-11 23:32:00 +00:00
POPT_COMMON_SAMBA
POPT_COMMON_CREDENTIALS
{ NULL }
} ;
2005-12-28 22:48:54 +00:00
load_case_tables ( ) ;
2003-04-11 23:32:00 +00:00
ZERO_STRUCT ( qt ) ;
2004-09-15 13:57:33 +00:00
/* set default debug level to 1 regardless of what smb.conf sets */
setup_logging ( " smbcquotas " , True ) ;
DEBUGLEVEL_CLASS [ DBGC_ALL ] = 1 ;
2003-04-11 23:32:00 +00:00
dbf = x_stderr ;
2004-09-15 13:57:33 +00:00
x_setbuf ( x_stderr , NULL ) ;
2003-04-11 23:32:00 +00:00
2004-09-15 13:57:33 +00:00
setlinebuf ( stdout ) ;
2003-04-11 23:32:00 +00:00
2004-09-15 13:57:33 +00:00
fault_setup ( NULL ) ;
2003-04-11 23:32:00 +00:00
2006-01-28 22:53:04 +00:00
lp_load ( dyn_CONFIGFILE , True , False , False , True ) ;
2003-04-11 23:32:00 +00:00
load_interfaces ( ) ;
pc = poptGetContext ( " smbcquotas " , argc , argv , long_options , 0 ) ;
2007-12-03 18:48:41 -08:00
2003-04-11 23:32:00 +00:00
poptSetOtherOptionHelp ( pc , " //server1/share1 " ) ;
while ( ( opt = poptGetNextOpt ( pc ) ) ! = - 1 ) {
switch ( opt ) {
2007-10-19 11:38:36 -07:00
case ' n ' :
numeric = true ;
break ;
case ' v ' :
verbose = true ;
break ;
case ' t ' :
test_args = true ;
break ;
2003-04-11 23:32:00 +00:00
case ' L ' :
if ( todo ! = 0 ) {
d_printf ( " Please specify only one option of <-L|-F|-S|-u> \n " ) ;
exit ( EXIT_PARSE_ERROR ) ;
}
todo = LIST_QUOTA ;
break ;
case ' F ' :
if ( todo ! = 0 ) {
d_printf ( " Please specify only one option of <-L|-F|-S|-u> \n " ) ;
exit ( EXIT_PARSE_ERROR ) ;
}
todo = FS_QUOTA ;
break ;
2007-12-03 18:48:41 -08:00
2003-04-11 23:32:00 +00:00
case ' u ' :
if ( todo ! = 0 ) {
d_printf ( " Please specify only one option of <-L|-F|-S|-u> \n " ) ;
exit ( EXIT_PARSE_ERROR ) ;
}
2007-12-03 18:48:41 -08:00
username_str = talloc_strdup ( frame , poptGetOptArg ( pc ) ) ;
if ( ! username_str ) {
exit ( EXIT_PARSE_ERROR ) ;
}
2003-04-11 23:32:00 +00:00
todo = USER_QUOTA ;
fix_user = True ;
break ;
2007-12-03 18:48:41 -08:00
2003-04-11 23:32:00 +00:00
case ' S ' :
if ( todo ! = 0 ) {
d_printf ( " Please specify only one option of <-L|-F|-S|-u> \n " ) ;
exit ( EXIT_PARSE_ERROR ) ;
}
2007-12-03 18:48:41 -08:00
set_str = talloc_strdup ( frame , poptGetOptArg ( pc ) ) ;
if ( ! set_str ) {
exit ( EXIT_PARSE_ERROR ) ;
}
2003-04-11 23:32:00 +00:00
todo = SET_QUOTA ;
break ;
}
}
if ( todo = = 0 )
todo = USER_QUOTA ;
2007-12-03 18:48:41 -08:00
if ( ! fix_user ) {
2007-12-06 18:58:01 -08:00
username_str = talloc_strdup ( frame , get_cmdline_auth_info_username ( ) ) ;
2007-12-03 18:48:41 -08:00
if ( ! username_str ) {
exit ( EXIT_PARSE_ERROR ) ;
}
}
2003-04-11 23:32:00 +00:00
/* Make connection to server */
2007-12-03 18:48:41 -08:00
if ( ! poptPeekArg ( pc ) ) {
2003-04-11 23:32:00 +00:00
poptPrintUsage ( pc , stderr , 0 ) ;
exit ( EXIT_PARSE_ERROR ) ;
}
2007-12-03 18:48:41 -08:00
path = talloc_strdup ( frame , poptGetArg ( pc ) ) ;
if ( ! path ) {
printf ( " Out of memory \n " ) ;
exit ( EXIT_PARSE_ERROR ) ;
}
string_replace ( path , ' / ' , ' \\ ' ) ;
2003-04-11 23:32:00 +00:00
2007-12-03 18:48:41 -08:00
server = SMB_STRDUP ( path + 2 ) ;
if ( ! server ) {
printf ( " Out of memory \n " ) ;
exit ( EXIT_PARSE_ERROR ) ;
}
2003-04-11 23:32:00 +00:00
share = strchr_m ( server , ' \\ ' ) ;
if ( ! share ) {
2007-05-19 04:23:04 +00:00
printf ( " Invalid argument: %s \n " , share ) ;
exit ( EXIT_PARSE_ERROR ) ;
2003-04-11 23:32:00 +00:00
}
* share = 0 ;
share + + ;
if ( todo = = SET_QUOTA ) {
2007-12-03 18:48:41 -08:00
if ( parse_quota_set ( talloc_tos ( ) , set_str , & username_str , & qtype , & cmd , & qt ) ) {
2003-04-11 23:32:00 +00:00
printf ( " Invalid argument: -S %s \n " , set_str ) ;
exit ( EXIT_PARSE_ERROR ) ;
}
}
if ( ! test_args ) {
cli = connect_one ( share ) ;
if ( ! cli ) {
exit ( EXIT_FAILED ) ;
}
} else {
exit ( EXIT_OK ) ;
}
/* Perform requested action */
switch ( todo ) {
case FS_QUOTA :
result = do_quota ( cli , SMB_USER_FS_QUOTA_TYPE , QUOTA_GET , username_str , NULL ) ;
break ;
case LIST_QUOTA :
result = do_quota ( cli , SMB_USER_QUOTA_TYPE , QUOTA_LIST , username_str , NULL ) ;
break ;
case USER_QUOTA :
result = do_quota ( cli , SMB_USER_QUOTA_TYPE , QUOTA_GET , username_str , NULL ) ;
break ;
case SET_QUOTA :
result = do_quota ( cli , qtype , cmd , username_str , & qt ) ;
break ;
default :
result = EXIT_FAILED ;
break ;
}
2007-09-04 05:39:06 +00:00
talloc_free ( frame ) ;
2003-04-11 23:32:00 +00:00
return result ;
}