2008-06-23 13:00:20 +04:00
# include <stdlib.h>
2005-06-01 03:42:29 +04:00
static void
get_auth_data_fn ( const char * pServer ,
const char * pShare ,
char * pWorkgroup ,
int maxLenWorkgroup ,
char * pUsername ,
int maxLenUsername ,
char * pPassword ,
int maxLenPassword )
{
2008-01-16 17:35:44 +03:00
char temp [ 128 ] ;
char server [ 256 ] = { ' \0 ' } ;
char share [ 256 ] = { ' \0 ' } ;
char workgroup [ 256 ] = { ' \0 ' } ;
char username [ 256 ] = { ' \0 ' } ;
char password [ 256 ] = { ' \0 ' } ;
2015-06-30 21:41:55 +03:00
char * ret ;
2008-01-16 17:35:44 +03:00
2008-06-23 13:00:20 +04:00
static int krb5_set = 1 ;
2008-01-16 17:35:44 +03:00
if ( strcmp ( server , pServer ) = = 0 & &
strcmp ( share , pShare ) = = 0 & &
* workgroup ! = ' \0 ' & &
* username ! = ' \0 ' )
{
strncpy ( pWorkgroup , workgroup , maxLenWorkgroup - 1 ) ;
strncpy ( pUsername , username , maxLenUsername - 1 ) ;
strncpy ( pPassword , password , maxLenPassword - 1 ) ;
return ;
}
2008-06-23 13:00:20 +04:00
if ( krb5_set & & getenv ( " KRB5CCNAME " ) ) {
krb5_set = 0 ;
return ;
}
2005-06-01 03:42:29 +04:00
fprintf ( stdout , " Workgroup: [%s] " , pWorkgroup ) ;
2015-06-30 21:41:55 +03:00
ret = fgets ( temp , sizeof ( temp ) , stdin ) ;
if ( ret = = NULL ) {
return ;
}
2005-06-01 03:42:29 +04:00
if ( temp [ strlen ( temp ) - 1 ] = = ' \n ' ) /* A new line? */
{
temp [ strlen ( temp ) - 1 ] = ' \0 ' ;
}
if ( temp [ 0 ] ! = ' \0 ' )
{
strncpy ( pWorkgroup , temp , maxLenWorkgroup - 1 ) ;
}
fprintf ( stdout , " Username: [%s] " , pUsername ) ;
2015-06-30 21:41:55 +03:00
ret = fgets ( temp , sizeof ( temp ) , stdin ) ;
if ( ret = = NULL ) {
return ;
}
2005-06-01 03:42:29 +04:00
if ( temp [ strlen ( temp ) - 1 ] = = ' \n ' ) /* A new line? */
{
temp [ strlen ( temp ) - 1 ] = ' \0 ' ;
}
if ( temp [ 0 ] ! = ' \0 ' )
{
strncpy ( pUsername , temp , maxLenUsername - 1 ) ;
}
fprintf ( stdout , " Password: " ) ;
2015-06-30 21:41:55 +03:00
ret = fgets ( temp , sizeof ( temp ) , stdin ) ;
if ( ret = = NULL ) {
return ;
}
2005-06-01 03:42:29 +04:00
if ( temp [ strlen ( temp ) - 1 ] = = ' \n ' ) /* A new line? */
{
temp [ strlen ( temp ) - 1 ] = ' \0 ' ;
}
if ( temp [ 0 ] ! = ' \0 ' )
{
strncpy ( pPassword , temp , maxLenPassword - 1 ) ;
}
2008-01-16 17:35:44 +03:00
strncpy ( workgroup , pWorkgroup , sizeof ( workgroup ) - 1 ) ;
strncpy ( username , pUsername , sizeof ( username ) - 1 ) ;
strncpy ( password , pPassword , sizeof ( password ) - 1 ) ;
2008-06-23 13:00:20 +04:00
krb5_set = 1 ;
2005-06-01 03:42:29 +04:00
}