2005-12-29 23:14:33 +00:00
/*
Unix SMB / CIFS implementation .
Credentials popt routines
Copyright ( C ) Jelmer Vernooij 2002 , 2003 , 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-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-12-29 23:14:33 +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/>.
2005-12-29 23:14:33 +00:00
*/
# include "includes.h"
# include "lib/cmdline/popt_common.h"
2006-03-07 13:36:26 +00:00
# include "lib/cmdline/credentials.h"
2006-11-07 00:48:36 +00:00
# include "auth/credentials/credentials.h"
2006-01-28 12:15:24 +00:00
# include "auth/gensec/gensec.h"
2007-09-08 12:42:09 +00:00
# include "param/param.h"
2005-12-29 23:14:33 +00:00
/* Handle command line options:
* - U , - - user
* - A , - - authentication - file
* - k , - - use - kerberos
* - N , - - no - pass
* - S , - - signing
2006-01-28 12:15:24 +00:00
* - P - - machine - pass
* - - simple - bind - dn
* - - password
2005-12-29 23:14:33 +00:00
*/
2007-10-01 18:52:55 +00:00
static bool dont_ask ;
2005-12-29 23:14:33 +00:00
2010-03-24 19:26:02 +11:00
enum opt { OPT_SIMPLE_BIND_DN , OPT_PASSWORD , OPT_KERBEROS , OPT_SIGN , OPT_ENCRYPT } ;
2005-12-29 23:14:33 +00:00
/*
disable asking for a password
*/
void popt_common_dont_ask ( void )
{
2007-10-05 18:03:01 +00:00
dont_ask = true ;
2005-12-29 23:14:33 +00:00
}
static void popt_common_credentials_callback ( poptContext con ,
enum poptCallbackReason reason ,
const struct poptOption * opt ,
const char * arg , const void * data )
{
if ( reason = = POPT_CALLBACK_REASON_PRE ) {
cmdline_credentials = cli_credentials_init ( talloc_autofree_context ( ) ) ;
return ;
}
if ( reason = = POPT_CALLBACK_REASON_POST ) {
2008-11-02 19:33:34 +01:00
cli_credentials_guess ( cmdline_credentials , cmdline_lp_ctx ) ;
2005-12-29 23:14:33 +00:00
if ( ! dont_ask ) {
cli_credentials_set_cmdline_callbacks ( cmdline_credentials ) ;
}
return ;
2010-03-24 19:26:02 +11:00
2005-12-29 23:14:33 +00:00
}
switch ( opt - > val ) {
case ' U ' :
2007-05-22 05:22:18 +00:00
{
char * lp ;
cli_credentials_parse_string ( cmdline_credentials , arg , CRED_SPECIFIED ) ;
/* This breaks the abstraction, including the const above */
if ( ( lp = strchr_m ( arg , ' % ' ) ) ) {
lp [ 0 ] = ' \0 ' ;
lp + + ;
/* Try to prevent this showing up in ps */
memset ( lp , 0 , strlen ( lp ) ) ;
2005-12-29 23:14:33 +00:00
}
2007-05-22 05:22:18 +00:00
}
break ;
2005-12-29 23:14:33 +00:00
2006-01-28 12:15:24 +00:00
case OPT_PASSWORD :
cli_credentials_set_password ( cmdline_credentials , arg , CRED_SPECIFIED ) ;
/* Try to prevent this showing up in ps */
2006-02-22 09:48:35 +00:00
memset ( discard_const ( arg ) , 0 , strlen ( arg ) ) ;
2006-01-28 12:15:24 +00:00
break ;
2005-12-29 23:14:33 +00:00
case ' A ' :
cli_credentials_parse_file ( cmdline_credentials , arg , CRED_SPECIFIED ) ;
break ;
case ' P ' :
/* Later, after this is all over, get the machine account details from the secrets.ldb */
2007-12-13 22:46:17 +01:00
cli_credentials_set_machine_account_pending ( cmdline_credentials , cmdline_lp_ctx ) ;
2006-01-28 12:15:24 +00:00
break ;
case OPT_KERBEROS :
{
2007-10-05 18:03:01 +00:00
bool use_kerberos = true ;
2010-05-21 15:04:36 +10:00
/* Force us to only use kerberos */
if ( arg ) {
if ( ! set_boolean ( arg , & use_kerberos ) ) {
2010-05-21 10:35:22 -07:00
fprintf ( stderr , " Error parsing -k %s. Should be "
2010-05-21 11:40:54 -07:00
" -k [yes|no] \n " , arg ) ;
2010-05-21 15:04:36 +10:00
exit ( 1 ) ;
break ;
}
}
2006-01-28 12:15:24 +00:00
cli_credentials_set_kerberos_state ( cmdline_credentials ,
use_kerberos
? CRED_MUST_USE_KERBEROS
: CRED_DONT_USE_KERBEROS ) ;
2005-12-29 23:14:33 +00:00
break ;
2006-01-28 12:15:24 +00:00
}
2005-12-29 23:14:33 +00:00
case OPT_SIMPLE_BIND_DN :
2010-03-24 19:26:02 +11:00
{
2005-12-29 23:14:33 +00:00
cli_credentials_set_bind_dn ( cmdline_credentials , arg ) ;
break ;
}
2010-03-24 19:26:02 +11:00
case OPT_SIGN :
{
uint32_t gensec_features ;
gensec_features = cli_credentials_get_gensec_features ( cmdline_credentials ) ;
gensec_features | = GENSEC_FEATURE_SIGN ;
cli_credentials_set_gensec_features ( cmdline_credentials ,
gensec_features ) ;
break ;
}
case OPT_ENCRYPT :
{
uint32_t gensec_features ;
gensec_features = cli_credentials_get_gensec_features ( cmdline_credentials ) ;
gensec_features | = GENSEC_FEATURE_SEAL ;
cli_credentials_set_gensec_features ( cmdline_credentials ,
gensec_features ) ;
break ;
}
}
2005-12-29 23:14:33 +00:00
}
struct poptOption popt_common_credentials [ ] = {
2007-04-17 13:14:33 +00:00
{ NULL , 0 , POPT_ARG_CALLBACK | POPT_CBFLAG_PRE | POPT_CBFLAG_POST , ( void * ) popt_common_credentials_callback } ,
2007-07-17 05:40:36 +00:00
{ " user " , ' U ' , POPT_ARG_STRING , NULL , ' U ' , " Set the network username " , " [DOMAIN/]USERNAME[%PASSWORD] " } ,
2007-08-11 18:31:27 +00:00
{ " no-pass " , ' N ' , POPT_ARG_NONE , & dont_ask , ' N ' , " Don't ask for a password " } ,
2006-01-28 12:15:24 +00:00
{ " password " , 0 , POPT_ARG_STRING , NULL , OPT_PASSWORD , " Password " } ,
2005-12-29 23:14:33 +00:00
{ " authentication-file " , ' A ' , POPT_ARG_STRING , NULL , ' A ' , " Get the credentials from a file " , " FILE " } ,
{ " machine-pass " , ' P ' , POPT_ARG_NONE , NULL , ' P ' , " Use stored machine account password (implies -k) " } ,
{ " simple-bind-dn " , 0 , POPT_ARG_STRING , NULL , OPT_SIMPLE_BIND_DN , " DN to use for a simple bind " } ,
2010-05-21 11:40:54 -07:00
{ " kerberos " , ' k ' , POPT_ARG_STRING , NULL , OPT_KERBEROS , " Use Kerberos, -k [yes|no] " } ,
2010-03-24 19:26:02 +11:00
{ " sign " , ' S ' , POPT_ARG_NONE , NULL , OPT_SIGN , " Sign connection to prevent modification in transit " } ,
{ " encrypt " , ' e ' , POPT_ARG_NONE , NULL , OPT_ENCRYPT , " Encrypt connection for privacy " } ,
2006-09-06 12:28:01 +00:00
{ NULL }
2005-12-29 23:14:33 +00:00
} ;