#include <sys/param.h>
#include <sys/mount.h>
#include <asl.h>
#include <NetFS/NetFSPlugin.h>
#include <NetFS/NetFSUtil.h>
#include <NetFS/NetFSPrivate.h>
#include <NetFS/NetFSUtilPrivate.h>
#include <smbclient/smbclient.h>
#include <smbclient/smbclient_netfs.h>
#include <smbclient/smbclient_internal.h>
#include "smb_netfs.h"
#include "netshareenum.h"
#include "SetNetworkAccountSID.h"
static char *SMB_GetTraceMessageScheme(CFDictionaryRef options)
{
CFStringRef schemeRef;
if (!options) {
return NULL;
}
schemeRef = CFDictionaryGetValue(options, kNetFSTraceMessageSchemeKey);
if (!schemeRef) {
return NULL;
}
return NetFSCFStringtoCString(schemeRef);
}
static netfsError SMB_CreateSessionRef(void **outConnection)
{
int error = SMBNetFsCreateSessionRef((SMBHANDLE *)outConnection);
if (*outConnection == NULL) {
SMBLogInfo("%s: creating smb handle failed, syserr = %s",
ASL_LEVEL_ERR, __FUNCTION__, strerror(error));
}
return error;
}
static netfsError SMB_Cancel(void *inConnection)
{
return SMBNetFsCancel(inConnection);
}
static netfsError SMB_CloseSession(void *inConnection)
{
return SMBNetFsCloseSession(inConnection);
}
static netfsError SMB_ParseURL(CFURLRef url, CFDictionaryRef *urlParms)
{
return SMBNetFsParseURL(url, urlParms);
}
static netfsError SMB_CreateURL(CFDictionaryRef urlParms, CFURLRef *url)
{
return SMBNetFsCreateURL(urlParms, url);
}
static netfsError SMB_OpenSession(CFURLRef url, void *inConnection,
CFDictionaryRef openOptions,
CFDictionaryRef *sessionInfo)
{
int error = 0;
char *tmscheme = SMB_GetTraceMessageScheme(openOptions);
if ((inConnection == NULL) || (url == NULL)) {
error = EINVAL;
NetFSLogToMessageTracer(tmscheme, "checking parameters in SMB_OpenSession", error);
goto done;
}
SMBNetFsLockSession(inConnection);
error = SMBNetFsOpenSession(url, inConnection, openOptions, sessionInfo);
if (error) {
SMBLogInfo("%s: - error = %d!", ASL_LEVEL_DEBUG, __FUNCTION__, error);
}
SMBNetFsUnlockSession(inConnection);
done:
if (tmscheme) {
free(tmscheme);
}
return error;
}
static netfsError SMB_GetServerInfo(CFURLRef url, void *inConnection,
CFDictionaryRef openOptions,
CFDictionaryRef *serverParms)
{
int error;
if ((inConnection == NULL) || (url == NULL)) {
return EINVAL;
}
SMBNetFsLockSession(inConnection);
error = SMBNetFsGetServerInfo(url, inConnection, openOptions, serverParms);
if (error) {
SMBLogInfo("%s: - error = %d!", ASL_LEVEL_DEBUG, __FUNCTION__, error);
}
SMBNetFsUnlockSession(inConnection);
return error;
}
static netfsError SMB_EnumerateShares(void *inConnection,
CFDictionaryRef enumerateOptions,
CFDictionaryRef *sharePoints )
{
#pragma unused(enumerateOptions)
int error;
if (inConnection == NULL) {
return EINVAL;
}
SMBNetFsLockSession(inConnection);
error = SMBNetFsTreeConnectForEnumerateShares(inConnection);
if (!error) {
error = smb_netshareenum(inConnection, sharePoints, TRUE);
}
if (error) {
SMBLogInfo("%s: - error = %d!", ASL_LEVEL_DEBUG, __FUNCTION__, error);
}
SMBNetFsUnlockSession(inConnection);
return error;
}
static netfsError SMB_Mount(void *inConnection, CFURLRef url, CFStringRef mPoint,
CFDictionaryRef mOptions, CFDictionaryRef *mInfo)
{
int error;
char *tmscheme = SMB_GetTraceMessageScheme(mOptions);
if ((inConnection == NULL) || (mPoint == NULL) || (url == NULL)) {
error = EINVAL;
NetFSLogToMessageTracer(tmscheme, "checking parameters in SMB_Mount", error);
goto done;
}
SMBNetFsLockSession(inConnection);
error = SMBNetFsMount(inConnection,url, mPoint, mOptions, mInfo, setNetworkAccountSID, NULL);
if (error) {
SMBLogInfo("%s: - error = %d!", ASL_LEVEL_DEBUG, __FUNCTION__, error);
}
SMBNetFsUnlockSession(inConnection);
done:
if (tmscheme) {
free(tmscheme);
}
return error;
}
static netfsError SMB_GetMountInfo(CFStringRef in_Mountpath, CFDictionaryRef *out_MountInfo)
{
return SMBNetFsGetMountInfo(in_Mountpath, out_MountInfo);
}
#define kCIFSNetFSInterfaceFactoryID (CFUUIDGetConstantUUIDWithBytes(NULL, 0x92, 0xd4, 0xef, 0xef, 0xf5, 0xaa, 0x11, 0xd5, 0xa1, 0xee, 0x00, 0x30, 0x65, 0xa0, 0xe6, 0xde))
static NetFSMountInterface_V1 gCIFSNetFSMountInterfaceFTbl = {
NULL,
NetFSQueryInterface,
NetFSInterface_AddRef,
NetFSInterface_Release,
SMB_CreateSessionRef,
SMB_GetServerInfo,
SMB_ParseURL,
SMB_CreateURL,
SMB_OpenSession,
SMB_EnumerateShares,
SMB_Mount,
SMB_Cancel,
SMB_CloseSession,
SMB_GetMountInfo,
};
void * CIFSNetFSInterfaceFactory(CFAllocatorRef allocator, CFUUIDRef typeID);
void *CIFSNetFSInterfaceFactory(CFAllocatorRef allocator, CFUUIDRef typeID)
{
#pragma unused(allocator)
if (CFEqual(typeID, kNetFSTypeID)) {
return NetFS_CreateInterface(kCIFSNetFSInterfaceFactoryID, &gCIFSNetFSMountInterfaceFTbl);
} else {
return NULL;
}
}