Hi. I am trying to connect to a Mac via remote login using only the password for the authentication method on an iPhone. I want to establish a connection to the computer and then authenticate using the password and username. Then if this is successfull, I want the user to be presented with a new UIView where they can execute only one command. Thats it. Now, I used a source somebody made and it works obviously but the password and username authentication has not been implemented. I have been trying to implement it but could not do so. I get so many errors. Heres the code:
Code:
//
// Request.m
// Port Scanner
//
// Created by Matthew Wilkinson on 18/11/2009.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "Request.h"
#import "Port_ScannerAppDelegate.h"
// SSH Librarys
#include "libssh2_config.h"
#include "libssh2.h"
#include "libssh2_sftp.h"
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
# ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
@implementation Request
@synthesize userName;
@synthesize password;
@synthesize ip;
- (id)initWithUserName:(NSString *)someUserName andPassword:(NSString *)somePassword andIp:(NSString *)someIp {
[super init];
self.userName = someUserName;
self.password = somePassword;
self.ip = someIp;
return self;
}
- (void)connect {
Port_ScannerAppDelegate *delegate = (Port_ScannerAppDelegate *)[[UIApplication sharedApplication] delegate];
const char *username = [self.userName UTF8String];
const char *password = [self.password UTF8String];
const char *host = [self.ip UTF8String];
unsigned long hostaddr;
int sock, i, auth_pw = 0;
struct sockaddr_in sin;
const char *fingerprint;
char *userauthlist;
LIBSSH2_SESSION *session;
LIBSSH2_CHANNEL *channel;
hostaddr = inet_addr(host);
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_family = AF_INET;
sin.sin_port = htons(22);
sin.sin_addr.s_addr = hostaddr;
if (connect(sock, (struct sockaddr*)(&sin),
sizeof(struct sockaddr_in)) != 0) {
[delegate sendText:@"Connection Failed"];
}
else {
/* We could authenticate via password */
if (libssh2_userauth_password(session, username, password)) {
printf("\tAuthentication by password failed!\n");
} else {
printf("\tAuthentication by password succeeded.\n");
}
[delegate sendText:@"Connection to IP success, username/password check not implemented (yet)"];
}
NSLog(@"All done!");
}
@end
The error I get is:
"_libssh2_userauth_password_ex", referenced from:
-[Request connect] in Request.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Please help!