2008-05-14 11:01:53 +04:00
/*
Samba Unix / Linux SMB client library
net afs commands
Copyright ( C ) 2003 Volker Lendecke ( vl @ samba . org )
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 3 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 , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "utils/net.h"
2011-07-21 16:47:38 +04:00
# include "utils/net_afs.h"
2011-07-15 17:27:07 +04:00
# include "secrets.h"
# include "system/filesys.h"
2008-05-14 11:01:53 +04:00
int net_afs_usage ( struct net_context * c , int argc , const char * * argv )
{
2009-07-30 01:59:39 +04:00
d_printf ( _ ( " net afs key filename \n "
" \t Imports a OpenAFS KeyFile into our secrets.tdb \n \n " ) ) ;
d_printf ( _ ( " net afs impersonate <user> <cell> \n "
" \t Creates a token for user@cell \n \n " ) ) ;
2008-05-14 11:01:53 +04:00
return - 1 ;
}
int net_afs_key ( struct net_context * c , int argc , const char * * argv )
{
int fd ;
struct afs_keyfile keyfile ;
if ( argc ! = 2 ) {
2011-07-15 17:44:36 +04:00
d_printf ( " %s net afs key <keyfile> cell \n " , _ ( " Usage: " ) ) ;
2008-05-14 11:01:53 +04:00
return - 1 ;
}
if ( ! secrets_init ( ) ) {
2009-07-30 01:59:39 +04:00
d_fprintf ( stderr , _ ( " Could not open secrets.tdb \n " ) ) ;
2008-05-14 11:01:53 +04:00
return - 1 ;
}
if ( ( fd = open ( argv [ 0 ] , O_RDONLY , 0 ) ) < 0 ) {
2010-03-06 14:57:35 +03:00
d_fprintf ( stderr , _ ( " Could not open %s \n " ) , argv [ 0 ] ) ;
2008-05-14 11:01:53 +04:00
return - 1 ;
}
if ( read ( fd , & keyfile , sizeof ( keyfile ) ) ! = sizeof ( keyfile ) ) {
2009-07-30 01:59:39 +04:00
d_fprintf ( stderr , _ ( " Could not read keyfile \n " ) ) ;
2011-01-20 01:15:21 +03:00
close ( fd ) ;
2008-05-14 11:01:53 +04:00
return - 1 ;
}
2011-01-20 01:15:21 +03:00
close ( fd ) ;
2008-05-14 11:01:53 +04:00
if ( ! secrets_store_afs_keyfile ( argv [ 1 ] , & keyfile ) ) {
2009-07-30 01:59:39 +04:00
d_fprintf ( stderr , _ ( " Could not write keyfile to secrets.tdb \n " ) ) ;
2008-05-14 11:01:53 +04:00
return - 1 ;
}
return 0 ;
}
int net_afs_impersonate ( struct net_context * c , int argc ,
const char * * argv )
{
char * token ;
if ( argc ! = 2 ) {
2011-07-15 17:44:36 +04:00
d_fprintf ( stderr , " %s net afs impersonate <user> <cell> \n " ,
_ ( " Usage: " ) ) ;
2008-05-14 11:01:53 +04:00
exit ( 1 ) ;
}
token = afs_createtoken_str ( argv [ 0 ] , argv [ 1 ] ) ;
if ( token = = NULL ) {
2009-07-30 01:59:39 +04:00
fprintf ( stderr , _ ( " Could not create token \n " ) ) ;
2008-05-14 11:01:53 +04:00
exit ( 1 ) ;
}
if ( ! afs_settoken_str ( token ) ) {
2009-07-30 01:59:39 +04:00
fprintf ( stderr , _ ( " Could not set token into kernel \n " ) ) ;
2008-05-14 11:01:53 +04:00
exit ( 1 ) ;
}
2009-07-30 01:59:39 +04:00
printf ( _ ( " Success: %s@%s \n " ) , argv [ 0 ] , argv [ 1 ] ) ;
2008-05-14 11:01:53 +04:00
return 0 ;
}
int net_afs ( struct net_context * c , int argc , const char * * argv )
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-19 17:35:36 +04:00
{
" key " ,
net_afs_key ,
NET_TRANSPORT_LOCAL ,
2009-07-30 01:59:39 +04:00
N_ ( " Import an OpenAFS keyfile " ) ,
N_ ( " net afs key <filename> \n "
" Import kefile from <filename>. " )
2008-05-19 17:35:36 +04:00
} ,
{
" impersonate " ,
net_afs_impersonate ,
NET_TRANSPORT_LOCAL ,
2009-07-30 01:59:39 +04:00
N_ ( " Get a user token " ) ,
N_ ( " net afs impersonate <user> <cell> \n "
" Create token for user@cell " )
2008-05-19 17:35:36 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2008-05-14 11:01:53 +04:00
} ;
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net afs " , func ) ;
2008-05-14 11:01:53 +04:00
}