Skip to content

Commit

Permalink
SSH session with hosts configuration
Browse files Browse the repository at this point in the history
Apply settings from hosts object in case it exists to the options for
the ssh session.
  • Loading branch information
Carlos Cabanero committed Aug 23, 2016
1 parent 2ea9b1a commit 08964f5
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions Sessions/SSHSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <stdlib.h>
#include <sys/socket.h>

#import "BKHosts.h"
#import "BKPubKey.h"
#import "SSHSession.h"

Expand All @@ -63,6 +64,7 @@
const char *user;
int request_tty;
const char *identity_file;
const char *pwd_key;
} Options;


Expand Down Expand Up @@ -203,12 +205,13 @@ - (int)main:(int)argc argv:(char **)argv

NSArray *chunks = [userhost componentsSeparatedByString:@"@"];
if ([chunks count] != 2) {
optind = 0;
return [self dieMsg:@"Could not parse user@host info"];
_options.hostname = [userhost UTF8String];
} else {
_options.user = [chunks[0] UTF8String];
_options.hostname = [chunks[1] UTF8String];
}

_options.user = [chunks[0] UTF8String];
_options.hostname = [chunks[1] UTF8String];

[self processHostSettings];

NSMutableArray *command_args = [[NSMutableArray alloc] init];

Expand Down Expand Up @@ -279,6 +282,20 @@ - (void)debugMsg:(NSString *)msg
}
}

- (void)processHostSettings
{
BKHosts *host;

if (!(host = [BKHosts withHost:[NSString stringWithUTF8String:_options.hostname]])) {
return;
}

_options.hostname = host.hostName ? [host.hostName UTF8String] : _options.hostname;
_options.port = _options.port ? _options.port : [host.port intValue];
_options.user = _options.user ? _options.user : [host.user UTF8String];
_options.identity_file = _options.identity_file ? _options.identity_file : [host.key UTF8String];
_options.pwd_key = host.password ? [host.password UTF8String] : NULL;
}

- (void)load_identity_files
{
Expand Down

0 comments on commit 08964f5

Please sign in to comment.