Import startup script and pass key in environment variable

This commit is contained in:
Keith Winstein
2012-02-03 02:10:04 -05:00
parent ecb45b6d93
commit ec89d17a8a
2 changed files with 88 additions and 7 deletions
+23 -7
View File
@@ -1,8 +1,9 @@
#include <stdlib.h>
#include <string.h>
#include "stmclient.hpp"
#include "crypto.hpp"
#include <iostream>
int main( int argc, char *argv[] )
{
/* Get arguments */
@@ -17,10 +18,23 @@ int main( int argc, char *argv[] )
ip = argv[ 1 ];
port = myatoi( argv[ 2 ] );
/* Read key from standard input */
cout << "Key: ";
string key;
cin >> key;
/* Read key from environment */
char *env_key = getenv( "MOSH_KEY" );
if ( env_key == NULL ) {
fprintf( stderr, "MOSH_KEY environment variable not found.\n" );
exit( 1 );
}
char *key = strdup( env_key );
if ( key == NULL ) {
perror( "strdup" );
exit( 1 );
}
if ( unsetenv( "MOSH_KEY" ) < 0 ) {
perror( "unsetenv" );
exit( 1 );
}
/* Adopt native locale */
if ( NULL == setlocale( LC_ALL, "" ) ) {
@@ -28,7 +42,7 @@ int main( int argc, char *argv[] )
exit( 1 );
}
STMClient client( ip, port, key.c_str() );
STMClient client( ip, port, key );
client.init();
@@ -38,5 +52,7 @@ int main( int argc, char *argv[] )
printf( "\n[mosh is exiting.]\n" );
free( key );
return 0;
}