Skip to content

Commit

Permalink
Some clean up and a new connect method with an explicit domain argument
Browse files Browse the repository at this point in the history
  • Loading branch information
schamar committed Apr 25, 2018
1 parent eb1e3ee commit 82dfd47
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 53 deletions.
6 changes: 5 additions & 1 deletion SMBClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
452A27CA1CF89E65004456E5 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0900;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Naxos Software Solutions GmbH";
TargetAttributes = {
452A27D21CF89E65004456E5 = {
Expand Down Expand Up @@ -444,12 +444,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -500,12 +502,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SMBClient/SMBFile.m"
timestampString = "487768335.48244"
timestampString = "546348935.632665"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "417"
endingLineNumber = "417"
landmarkName = "-moveTo:completion:"
landmarkType = "5">
landmarkType = "7">
<Locations>
<Location
shouldBeEnabled = "Yes"
Expand All @@ -26,7 +26,7 @@
moduleName = "SMBClient"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/masc/Workspace/10_Projects/_GitHub/_SMBCLient/SMBClient/SMBFile.m"
timestampString = "532011284.470134"
timestampString = "546348892.991431"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "417"
Expand All @@ -41,13 +41,28 @@
moduleName = "SMBClient"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/masc/Workspace/10_Projects/_GitHub/_SMBCLient/SMBClient/SMBFile.m"
timestampString = "532011284.471887"
timestampString = "546348892.993958"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "418"
endingLineNumber = "418"
offsetFromSymbolStart = "78">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "__destroy_helper_block_.197"
moduleName = "SMBClient"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/masc/Workspace/10_Projects/_GitHub/_SMBCLient/SMBClient/SMBFile.m"
timestampString = "546348892.997396"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "417"
endingLineNumber = "417"
offsetFromSymbolStart = "16">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -58,13 +73,13 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SMBClient/SMBShare.m"
timestampString = "487768376.992753"
timestampString = "546348935.632973"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "397"
endingLineNumber = "397"
landmarkName = "-moveFile:to:completion:"
landmarkType = "5">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -74,13 +89,13 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SMBClient/SMBShare.m"
timestampString = "487768646.5074"
timestampString = "546348935.633019"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "403"
endingLineNumber = "403"
landmarkName = "-moveFile:to:completion:"
landmarkType = "5">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -56,7 +55,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -37,7 +36,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
30 changes: 15 additions & 15 deletions SMBClient/SMBFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ - (void)open:(SMBFileMode)mode completion:(nullable void (^)(NSError *_Nullable)

[self.share openFile:self.path mode:mode completion:^(SMBFile *file, smb_fd fileID, NSError *error) {
if (error == nil) {
_fileID = fileID;
_smbStat = file.smbStat;
self->_fileID = fileID;
self->_smbStat = file.smbStat;
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -140,15 +140,15 @@ - (void)close:(nullable void (^)(NSError *_Nullable))completion {

dispatch_async(_serialQueue, ^{

if (_fileID == 0) {
if (self->_fileID == 0) {
dispatch_async(dispatch_get_main_queue(), ^{
completion([SMBError notOpenError]);
});
} else {
[self.share closeFile:_fileID path:self.path completion:^(SMBFile *file, NSError * _Nullable error) {
[self.share closeFile:self->_fileID path:self.path completion:^(SMBFile *file, NSError * _Nullable error) {
if (error == nil) {
_fileID = 0;
_smbStat = file.smbStat;
self->_fileID = 0;
self->_smbStat = file.smbStat;
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -175,7 +175,7 @@ - (void)seek:(unsigned long long)offset absolute:(BOOL)absolute completion:(null
if (self.share.server.smbSession) {
if ([self isOpen]) {

off_t pos = smb_fseek(self.share.server.smbSession, _fileID, offset, absolute ? SMB_SEEK_SET : SMB_SEEK_CUR);
off_t pos = smb_fseek(self.share.server.smbSession, self->_fileID, offset, absolute ? SMB_SEEK_SET : SMB_SEEK_CUR);

position = MAX(0L, pos);

Expand Down Expand Up @@ -229,7 +229,7 @@ - (void)read:(NSUInteger)bufferSize maxBytes:(unsigned long long)maxBytes progre
while (!finished) {

NSUInteger bytesToRead = maxBytes == 0 ? bufferSize : MIN(bufferSize, (NSUInteger)(maxBytes - bytesReadTotal));
long bytesRead = smb_fread(self.share.server.smbSession, _fileID, buf, bytesToRead);
long bytesRead = smb_fread(self.share.server.smbSession, self->_fileID, buf, bytesToRead);

if (bytesRead < 0) {
finished = YES;
Expand Down Expand Up @@ -300,7 +300,7 @@ - (void)write:(nonnull NSData *_Nullable (^)(unsigned long long))dataHandler pro
finished = YES;
} else {
long bytesToWrite = data.length;
long bytesWritten = smb_fwrite(self.share.server.smbSession, _fileID, (void *)data.bytes, bytesToWrite);
long bytesWritten = smb_fwrite(self.share.server.smbSession, self->_fileID, (void *)data.bytes, bytesToWrite);

offset += MAX(0, bytesWritten);

Expand Down Expand Up @@ -362,7 +362,7 @@ - (void)listFilesUsingFilter:(nullable BOOL (^)(SMBFile *_Nonnull file))filter c
- (void)updateStatus:(nullable void (^)(NSError *_Nullable))completion {
[self.share getStatusOfFile:self.path completion:^(SMBStat * _Nullable smbStat, NSError * _Nullable error) {
if (error == nil) {
_smbStat = smbStat;
self->_smbStat = smbStat;
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -375,7 +375,7 @@ - (void)updateStatus:(nullable void (^)(NSError *_Nullable))completion {
- (void)createDirectory:(nullable void (^)(NSError *_Nullable))completion {
[self.share createDirectory:self.path completion:^(SMBFile * _Nullable file, NSError * _Nullable error) {
if (error == nil) {
_smbStat = file.smbStat;
self->_smbStat = file.smbStat;
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -388,7 +388,7 @@ - (void)createDirectory:(nullable void (^)(NSError *_Nullable))completion {
- (void)createDirectories:(nullable void (^)(NSError *_Nullable))completion {
[self.share createDirectories:self.path completion:^(SMBFile * _Nullable file, NSError * _Nullable error) {
if (error == nil) {
_smbStat = file.smbStat;
self->_smbStat = file.smbStat;
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -401,7 +401,7 @@ - (void)createDirectories:(nullable void (^)(NSError *_Nullable))completion {
- (void)delete:(nullable void (^)(NSError *_Nullable))completion {
[self.share deleteFile:self.path completion:^(NSError * _Nullable error) {
if (error == nil) {
_smbStat = [SMBStat statForNonExistingFile];
self->_smbStat = [SMBStat statForNonExistingFile];
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -416,8 +416,8 @@ - (void)moveTo:(nonnull NSString *)path completion:(nullable void (^)(NSError *_

[self.share moveFile:self.path to:f.path completion:^(SMBFile *_Nullable newFile, NSError * _Nullable error) {
if (error == nil) {
_smbStat = newFile.smbStat;
_path = newFile.path;
self->_smbStat = newFile.smbStat;
self->_path = newFile.path;
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down
1 change: 1 addition & 0 deletions SMBClient/SMBFileServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

- (void)disconnect:(nullable void (^)(void))completion;
- (void)connectAsUser:(nullable NSString *)username password:(nullable NSString *)password completion:(nullable void (^)(BOOL guest, NSError *_Nullable error))completion;
- (void)connectAsUser:(nullable NSString *)username password:(nullable NSString *)password domain:(nullable NSString *)domain completion:(nullable void (^)(BOOL guest, NSError *_Nullable error))completion;
- (void)listShares:(nullable void (^)(NSArray<SMBShare *> *_Nullable shares, NSError *_Nullable error))completion;
- (void)findShare:(nonnull NSString *)name completion:(nullable void (^)(SMBShare *_Nullable share, NSError *_Nullable error))completion;

Expand Down
27 changes: 16 additions & 11 deletions SMBClient/SMBFileServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@ - (void)dealloc {
}

- (void)connectAsUser:(NSString *)username password:(NSString *)password completion:(void (^)(BOOL, NSError *))completion {
[self connectAsUser:username password:password domain:nil completion:completion];
}

- (void)connectAsUser:(NSString *)username password:(NSString *)password domain:(NSString *)domain completion:(void (^)(BOOL, NSError *))completion {
[self disconnect:^{

dispatch_async(_serialQueue, ^{
dispatch_async(self->_serialQueue, ^{

const char *name = self.netbiosName.UTF8String;
const char *host = self.host.UTF8String;
const char *user = username.length > 0 ? username.UTF8String : " ";
const char *pass = password.length > 0 ? password.UTF8String : " ";
const char *domn = domain.length > 0 ? domain.UTF8String : " ";
NSError *error = nil;
BOOL guest = NO;
const struct hostent *host_entry = gethostbyname(host);
Expand All @@ -75,27 +80,27 @@ - (void)connectAsUser:(NSString *)username password:(NSString *)password complet
error = [SMBError noIPAddressError];
} else {

_smbSession = smb_session_new();
self->_smbSession = smb_session_new();

if (_smbSession) {
if (self->_smbSession) {
const struct in_addr addr = *(struct in_addr *)host_entry->h_addr_list[0];

smb_session_set_creds(_smbSession, name, user, pass);
smb_session_set_creds(self->_smbSession, domn, user, pass);

// Connect to the host
int result = smb_session_connect(_smbSession, name, addr.s_addr, SMB_TRANSPORT_TCP);
int result = smb_session_connect(self->_smbSession, name, addr.s_addr, SMB_TRANSPORT_TCP);

if (result == 0) {
// Login
result = smb_session_login(_smbSession);
result = smb_session_login(self->_smbSession);
}

if (result == 0) {
if (smb_session_is_guest(_smbSession) > 0) {
if (smb_session_is_guest(self->_smbSession) > 0) {
guest = YES;
}
} else {
error = [SMBError dsmError:result session:_smbSession];
error = [SMBError dsmError:result session:self->_smbSession];

[self disconnect:nil];
}
Expand All @@ -117,9 +122,9 @@ - (void)connectAsUser:(NSString *)username password:(NSString *)password complet
- (void)disconnect:(nullable void (^)(void))completion {

dispatch_async(_serialQueue, ^{
if (_smbSession) {
smb_session_destroy(_smbSession);
_smbSession = nil;
if (self->_smbSession) {
smb_session_destroy(self->_smbSession);
self->_smbSession = nil;
}

if (completion) {
Expand Down
Loading

0 comments on commit 82dfd47

Please sign in to comment.