2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
Common popt routines
Copyright ( C ) Tim Potter 2001 , 2002
2005-03-22 22:11:50 +00:00
Copyright ( C ) Jelmer Vernooij 2002 , 2003 , 2005
2003-08-13 01:53:07 +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
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 .
*/
# include "includes.h"
2005-01-18 09:30:43 +00:00
# include "version.h"
2004-11-02 02:57:18 +00:00
# include "lib/cmdline/popt_common.h"
2003-08-13 01:53:07 +00:00
/* Handle command line options:
* - d , - - debuglevel
* - s , - - configfile
* - O , - - socket - options
* - V , - - version
* - l , - - log - base
* - n , - - netbios - name
* - W , - - workgroup
* - i , - - scope
*/
2005-12-29 23:14:33 +00:00
enum { OPT_OPTION = 1 , OPT_LEAK_REPORT , OPT_LEAK_REPORT_FULL , OPT_DEBUG_STDERR } ;
2004-09-13 01:27:37 +00:00
2005-03-21 02:08:38 +00:00
struct cli_credentials * cmdline_credentials = NULL ;
2003-08-13 01:53:07 +00:00
static void popt_common_callback ( poptContext con ,
enum poptCallbackReason reason ,
const struct poptOption * opt ,
const char * arg , const void * data )
{
const char * pname ;
2005-07-21 12:11:52 +00:00
2005-06-13 08:12:39 +00:00
if ( reason = = POPT_CALLBACK_REASON_POST ) {
/* Hook any 'every Samba program must do this, after
* the smb . conf is setup ' functions here */
2005-07-20 10:07:48 +00:00
lp_load ( ) ;
2005-06-13 08:12:39 +00:00
return ;
}
2003-08-13 01:53:07 +00:00
/* Find out basename of current program */
pname = strrchr_m ( poptGetInvocationName ( con ) , ' / ' ) ;
if ( ! pname )
pname = poptGetInvocationName ( con ) ;
else
pname + + ;
if ( reason = = POPT_CALLBACK_REASON_PRE ) {
2005-07-21 12:20:18 +00:00
/* setup for panics */
fault_setup ( poptGetInvocationName ( con ) ) ;
/* and logging */
2005-06-13 08:12:39 +00:00
setup_logging ( pname , DEBUG_STDOUT ) ;
2003-08-13 01:53:07 +00:00
return ;
}
switch ( opt - > val ) {
case ' d ' :
lp_set_cmdline ( " log level " , arg ) ;
break ;
2005-06-13 08:12:39 +00:00
case OPT_DEBUG_STDERR :
setup_logging ( pname , DEBUG_STDERR ) ;
break ;
2003-08-13 01:53:07 +00:00
case ' V ' :
2004-01-28 12:47:52 +00:00
printf ( " Version %s \n " , SAMBA_VERSION_STRING ) ;
2003-08-13 01:53:07 +00:00
exit ( 0 ) ;
break ;
2004-08-19 12:16:48 +00:00
case ' O ' :
if ( arg ) {
lp_set_cmdline ( " socket options " , arg ) ;
}
break ;
2003-08-13 01:53:07 +00:00
case ' s ' :
if ( arg ) {
2005-07-20 10:07:48 +00:00
lp_set_cmdline ( " config file " , arg ) ;
2003-08-13 01:53:07 +00:00
}
break ;
case ' l ' :
if ( arg ) {
2004-09-13 01:27:37 +00:00
char * logfile = talloc_asprintf ( NULL , " %s/log.%s " , arg , pname ) ;
2003-08-13 01:53:07 +00:00
lp_set_cmdline ( " log file " , logfile ) ;
2004-09-13 01:27:37 +00:00
talloc_free ( logfile ) ;
2003-08-13 01:53:07 +00:00
}
break ;
case ' W ' :
lp_set_cmdline ( " workgroup " , arg ) ;
break ;
case ' n ' :
lp_set_cmdline ( " netbios name " , arg ) ;
break ;
case ' i ' :
lp_set_cmdline ( " netbios scope " , arg ) ;
break ;
2003-11-27 04:00:21 +00:00
case ' m ' :
lp_set_cmdline ( " max protocol " , arg ) ;
break ;
2004-08-19 12:16:48 +00:00
case ' R ' :
lp_set_cmdline ( " name resolve order " , arg ) ;
break ;
2004-09-13 01:27:37 +00:00
case OPT_OPTION :
if ( ! lp_set_option ( arg ) ) {
fprintf ( stderr , " Error setting option '%s' \n " , arg ) ;
exit ( 1 ) ;
}
break ;
2004-09-26 01:14:26 +00:00
2004-09-27 04:20:18 +00:00
case OPT_LEAK_REPORT :
talloc_enable_leak_report ( ) ;
break ;
case OPT_LEAK_REPORT_FULL :
talloc_enable_leak_report_full ( ) ;
2004-09-26 01:14:26 +00:00
break ;
2005-06-13 08:12:39 +00:00
2003-08-13 01:53:07 +00:00
}
}
struct poptOption popt_common_connection [ ] = {
{ NULL , 0 , POPT_ARG_CALLBACK , popt_common_callback } ,
2004-08-19 12:16:48 +00:00
{ " name-resolve " , ' R ' , POPT_ARG_STRING , NULL , ' R ' , " Use these name resolution services only " , " NAME-RESOLVE-ORDER " } ,
{ " socket-options " , ' O ' , POPT_ARG_STRING , NULL , ' O ' , " socket options to use " , " SOCKETOPTIONS " } ,
2003-08-13 01:53:07 +00:00
{ " netbiosname " , ' n ' , POPT_ARG_STRING , NULL , ' n ' , " Primary netbios name " , " NETBIOSNAME " } ,
{ " workgroup " , ' W ' , POPT_ARG_STRING , NULL , ' W ' , " Set the workgroup name " , " WORKGROUP " } ,
{ " scope " , ' i ' , POPT_ARG_STRING , NULL , ' i ' , " Use this Netbios scope " , " SCOPE " } ,
2003-11-27 04:00:21 +00:00
{ " maxprotocol " , ' m ' , POPT_ARG_STRING , NULL , ' m ' , " Set max protocol level " , " MAXPROTOCOL " } ,
2003-08-13 01:53:07 +00:00
POPT_TABLEEND
} ;
struct poptOption popt_common_samba [ ] = {
2005-06-13 08:12:39 +00:00
{ NULL , 0 , POPT_ARG_CALLBACK | POPT_CBFLAG_PRE | POPT_CBFLAG_POST , popt_common_callback } ,
2004-09-26 01:14:26 +00:00
{ " debuglevel " , ' d ' , POPT_ARG_STRING , NULL , ' d ' , " Set debug level " , " DEBUGLEVEL " } ,
2005-06-13 08:12:39 +00:00
{ " debug-stderr " , 0 , POPT_ARG_NONE , NULL , OPT_DEBUG_STDERR , " Send debug output to STDERR " , NULL } ,
2004-09-26 01:14:26 +00:00
{ " configfile " , ' s ' , POPT_ARG_STRING , NULL , ' s ' , " Use alternative configuration file " , " CONFIGFILE " } ,
{ " option " , 0 , POPT_ARG_STRING , NULL , OPT_OPTION , " Set smb.conf option from command line " , " name=value " } ,
2003-08-13 01:53:07 +00:00
{ " log-basename " , ' l ' , POPT_ARG_STRING , NULL , ' l ' , " Basename for log/debug files " , " LOGFILEBASE " } ,
2004-09-27 04:20:18 +00:00
{ " leak-report " , 0 , POPT_ARG_NONE , NULL , OPT_LEAK_REPORT , " enable talloc leak reporting on exit " , NULL } ,
{ " leak-report-full " , 0 , POPT_ARG_NONE , NULL , OPT_LEAK_REPORT_FULL , " enable full talloc leak reporting on exit " , NULL } ,
2003-08-13 01:53:07 +00:00
POPT_TABLEEND
} ;
struct poptOption popt_common_version [ ] = {
{ NULL , 0 , POPT_ARG_CALLBACK , popt_common_callback } ,
{ " version " , ' V ' , POPT_ARG_NONE , NULL , ' V ' , " Print version " } ,
POPT_TABLEEND
} ;